Merge "Fix issue with saving protos to disk during shutdown." am: 68e0de029a am: 26fcba8c97

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1492076

Change-Id: I0d4a3409eec94a6dd4c25b617bec0f0cff84a8e6
This commit is contained in:
Trung Lam
2020-11-10 06:08:48 +00:00
committed by Automerger Merge Worker

View File

@@ -185,22 +185,23 @@ abstract class AbstractProtoDiskReadWriter<T> {
* is useful for when device is powering off. * is useful for when device is powering off.
*/ */
@MainThread @MainThread
synchronized void saveImmediately(@NonNull String fileName, @NonNull T data) { void saveImmediately(@NonNull String fileName, @NonNull T data) {
mScheduledFileDataMap.put(fileName, data); synchronized (this) {
mScheduledFileDataMap.put(fileName, data);
}
triggerScheduledFlushEarly(); triggerScheduledFlushEarly();
} }
@MainThread @MainThread
private synchronized void triggerScheduledFlushEarly() { private void triggerScheduledFlushEarly() {
if (mScheduledFileDataMap.isEmpty() || mScheduledExecutorService.isShutdown()) { synchronized (this) {
return; if (mScheduledFileDataMap.isEmpty() || mScheduledExecutorService.isShutdown()) {
} return;
// Cancel existing future. }
if (mScheduledFuture != null) { // Cancel existing future.
if (mScheduledFuture != null) {
// We shouldn't need to interrupt as this method and threaded task mScheduledFuture.cancel(true);
// #flushScheduledData are both synchronized. }
mScheduledFuture.cancel(true);
} }
// Submit flush and blocks until it completes. Blocking will prevent the device from // Submit flush and blocks until it completes. Blocking will prevent the device from