Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aa8ed4fe authored by Adam Lesinski's avatar Adam Lesinski Committed by android-build-merger
Browse files

Merge "BatteryStats: Don't schedule work when shutting down" into oc-mr1-dev

am: 4a8f95ba

Change-Id: Ia71160c03ec0859cdf93082fc6ced121452a3ad6
parents b3240c2b 4a8f95ba
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -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,14 +132,20 @@ 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) {
        if (!mExecutorService.isShutdown()) {
            mExecutorService.submit(runnable);
        }
    }

    public void shutdown() {
        mExecutorService.shutdownNow();
    }

    private Future<?> scheduleSyncLocked(String reason, int flags) {
        if (mExecutorService.isShutdown()) {
            return CompletableFuture.failedFuture(new IllegalStateException("worker shutdown"));
        }

        if (mCurrentFuture == null) {
            mUpdateFlags = flags;
            mCurrentReason = reason;