Merge "Fix issue with saving protos to disk during shutdown." am: 68e0de029a am: 26fcba8c97 am: 32d142933e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1492076 Change-Id: I49f5241d403b5f2b959a2967612e0c5790076c29
This commit is contained in:
@@ -185,23 +185,24 @@ 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) {
|
||||||
|
synchronized (this) {
|
||||||
mScheduledFileDataMap.put(fileName, data);
|
mScheduledFileDataMap.put(fileName, data);
|
||||||
|
}
|
||||||
triggerScheduledFlushEarly();
|
triggerScheduledFlushEarly();
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainThread
|
@MainThread
|
||||||
private synchronized void triggerScheduledFlushEarly() {
|
private void triggerScheduledFlushEarly() {
|
||||||
|
synchronized (this) {
|
||||||
if (mScheduledFileDataMap.isEmpty() || mScheduledExecutorService.isShutdown()) {
|
if (mScheduledFileDataMap.isEmpty() || mScheduledExecutorService.isShutdown()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Cancel existing future.
|
// Cancel existing future.
|
||||||
if (mScheduledFuture != null) {
|
if (mScheduledFuture != null) {
|
||||||
|
|
||||||
// We shouldn't need to interrupt as this method and threaded task
|
|
||||||
// #flushScheduledData are both synchronized.
|
|
||||||
mScheduledFuture.cancel(true);
|
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
|
||||||
// shutting down before flushing completes.
|
// shutting down before flushing completes.
|
||||||
|
|||||||
Reference in New Issue
Block a user