Skip to content

Commit da5efbf

Browse files
authored
Catch OverlappingFilelockException to prevent app crashes in some (#2036)
specific Android 7 & 8 devices.
1 parent f9519f2 commit da5efbf

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

firebase-installations/src/main/java/com/google/firebase/installations/CrossProcessLock.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.RandomAccessFile;
2222
import java.nio.channels.FileChannel;
2323
import java.nio.channels.FileLock;
24+
import java.nio.channels.OverlappingFileLockException;
2425

2526
/** Use file locking to acquire a lock that will also block other processes. */
2627
class CrossProcessLock {
@@ -51,11 +52,13 @@ static CrossProcessLock acquire(Context appContext, String lockName) {
5152
// This method blocks until it can retrieve the lock.
5253
lock = channel.lock();
5354
return new CrossProcessLock(channel, lock);
54-
} catch (IOException | Error e) {
55+
} catch (IOException | Error | OverlappingFileLockException e) {
5556
// Certain conditions can cause file locking to fail, such as out of disk or bad permissions.
5657
// In any case, the acquire will fail and return null instead of a held lock.
5758
// NOTE: In Java 7 & 8, FileKey creation failure might wrap IOException into Error. See
5859
// https://bugs.openjdk.java.net/browse/JDK-8025619 for details.
60+
// Sometimes, an attempt to acquire the lock might throw an OverlappingFileLockException if a
61+
// lock already exists on Android 7 & 8.
5962
Log.e(TAG, "encountered error while creating and acquiring the lock, ignoring", e);
6063

6164
// Clean up any dangling resources

0 commit comments

Comments
 (0)