summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Adam Lesinski <adamlesinski@google.com> 2017-08-30 22:35:40 +0000
committer android-build-merger <android-build-merger@google.com> 2017-08-30 22:35:40 +0000
commitaa8ed4fe2f39b9d43f1a3566d275907ec2aa19cc (patch)
tree87931ec2e3d2d3c36ade1e6f1662085c0bf14ad2
parentb3240c2bb08790abeb78ee777f1929739de22dc2 (diff)
parent4a8f95ba5691ff85f398ddc1b6a5c5aeb8d10d6a (diff)
Merge "BatteryStats: Don't schedule work when shutting down" into oc-mr1-dev
am: 4a8f95ba56 Change-Id: Ia71160c03ec0859cdf93082fc6ced121452a3ad6
-rw-r--r--services/core/java/com/android/server/am/BatteryExternalStatsWorker.java13
1 files changed, 12 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java b/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java
index eb84adc8acd9..118484b093b0 100644
--- a/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java
+++ b/services/core/java/com/android/server/am/BatteryExternalStatsWorker.java
@@ -38,6 +38,7 @@ import com.android.internal.os.BatteryStatsImpl;
import libcore.util.EmptyArray;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@@ -116,6 +117,10 @@ class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStatsSync {
}
public synchronized Future<?> scheduleWrite() {
+ if (mExecutorService.isShutdown()) {
+ return CompletableFuture.failedFuture(new IllegalStateException("worker shutdown"));
+ }
+
scheduleSyncLocked("write", UPDATE_ALL);
// Since we use a single threaded executor, we can assume the next scheduled task's
// Future finishes after the sync.
@@ -127,7 +132,9 @@ class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStatsSync {
* within the task, never wait on the resulting Future. This will result in a deadlock.
*/
public synchronized void scheduleRunnable(Runnable runnable) {
- mExecutorService.submit(runnable);
+ if (!mExecutorService.isShutdown()) {
+ mExecutorService.submit(runnable);
+ }
}
public void shutdown() {
@@ -135,6 +142,10 @@ class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStatsSync {
}
private Future<?> scheduleSyncLocked(String reason, int flags) {
+ if (mExecutorService.isShutdown()) {
+ return CompletableFuture.failedFuture(new IllegalStateException("worker shutdown"));
+ }
+
if (mCurrentFuture == null) {
mUpdateFlags = flags;
mCurrentReason = reason;