Loading core/java/android/app/SharedPreferencesImpl.java +34 −9 Original line number Diff line number Diff line Loading @@ -71,6 +71,8 @@ final class SharedPreferencesImpl implements SharedPreferences { @GuardedBy("mLock") private Map<String, Object> mMap; @GuardedBy("mLock") private Throwable mThrowable; @GuardedBy("mLock") private int mDiskWritesInFlight = 0; Loading Loading @@ -107,6 +109,7 @@ final class SharedPreferencesImpl implements SharedPreferences { mMode = mode; mLoaded = false; mMap = null; mThrowable = null; startLoadFromDisk(); } Loading Loading @@ -139,6 +142,7 @@ final class SharedPreferencesImpl implements SharedPreferences { Map<String, Object> map = null; StructStat stat = null; Throwable thrown = null; try { stat = Os.stat(mFile.getPath()); if (mFile.canRead()) { Loading @@ -154,11 +158,21 @@ final class SharedPreferencesImpl implements SharedPreferences { } } } catch (ErrnoException e) { /* ignore */ // An errno exception means the stat failed. Treat as empty/non-existing by // ignoring. } catch (Throwable t) { thrown = t; } synchronized (mLock) { mLoaded = true; mThrowable = thrown; // It's important that we always signal waiters, even if we'll make // them fail with an exception. The try-finally is pretty wide, but // better safe than sorry. try { if (thrown == null) { if (map != null) { mMap = map; mStatTimestamp = stat.st_mtim; Loading @@ -166,9 +180,16 @@ final class SharedPreferencesImpl implements SharedPreferences { } else { mMap = new HashMap<>(); } } // In case of a thrown exception, we retain the old map. That allows // any open editors to commit and store updates. } catch (Throwable t) { mThrowable = t; } finally { mLock.notifyAll(); } } } static File makeBackupFile(File prefsFile) { return new File(prefsFile.getPath() + ".bak"); Loading Loading @@ -226,6 +247,7 @@ final class SharedPreferencesImpl implements SharedPreferences { } } @GuardedBy("mLock") private void awaitLoadedLocked() { if (!mLoaded) { // Raise an explicit StrictMode onReadFromDisk for this Loading @@ -239,6 +261,9 @@ final class SharedPreferencesImpl implements SharedPreferences { } catch (InterruptedException unused) { } } if (mThrowable != null) { throw new IllegalStateException(mThrowable); } } @Override Loading Loading
core/java/android/app/SharedPreferencesImpl.java +34 −9 Original line number Diff line number Diff line Loading @@ -71,6 +71,8 @@ final class SharedPreferencesImpl implements SharedPreferences { @GuardedBy("mLock") private Map<String, Object> mMap; @GuardedBy("mLock") private Throwable mThrowable; @GuardedBy("mLock") private int mDiskWritesInFlight = 0; Loading Loading @@ -107,6 +109,7 @@ final class SharedPreferencesImpl implements SharedPreferences { mMode = mode; mLoaded = false; mMap = null; mThrowable = null; startLoadFromDisk(); } Loading Loading @@ -139,6 +142,7 @@ final class SharedPreferencesImpl implements SharedPreferences { Map<String, Object> map = null; StructStat stat = null; Throwable thrown = null; try { stat = Os.stat(mFile.getPath()); if (mFile.canRead()) { Loading @@ -154,11 +158,21 @@ final class SharedPreferencesImpl implements SharedPreferences { } } } catch (ErrnoException e) { /* ignore */ // An errno exception means the stat failed. Treat as empty/non-existing by // ignoring. } catch (Throwable t) { thrown = t; } synchronized (mLock) { mLoaded = true; mThrowable = thrown; // It's important that we always signal waiters, even if we'll make // them fail with an exception. The try-finally is pretty wide, but // better safe than sorry. try { if (thrown == null) { if (map != null) { mMap = map; mStatTimestamp = stat.st_mtim; Loading @@ -166,9 +180,16 @@ final class SharedPreferencesImpl implements SharedPreferences { } else { mMap = new HashMap<>(); } } // In case of a thrown exception, we retain the old map. That allows // any open editors to commit and store updates. } catch (Throwable t) { mThrowable = t; } finally { mLock.notifyAll(); } } } static File makeBackupFile(File prefsFile) { return new File(prefsFile.getPath() + ".bak"); Loading Loading @@ -226,6 +247,7 @@ final class SharedPreferencesImpl implements SharedPreferences { } } @GuardedBy("mLock") private void awaitLoadedLocked() { if (!mLoaded) { // Raise an explicit StrictMode onReadFromDisk for this Loading @@ -239,6 +261,9 @@ final class SharedPreferencesImpl implements SharedPreferences { } catch (InterruptedException unused) { } } if (mThrowable != null) { throw new IllegalStateException(mThrowable); } } @Override Loading