Loading services/core/java/com/android/server/am/BatteryExternalStatsWorker.java +12 −1 Original line number Original line Diff line number Diff line Loading @@ -38,6 +38,7 @@ import com.android.internal.os.BatteryStatsImpl; import libcore.util.EmptyArray; import libcore.util.EmptyArray; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.Future; Loading Loading @@ -116,6 +117,10 @@ class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStatsSync { } } public synchronized Future<?> scheduleWrite() { public synchronized Future<?> scheduleWrite() { if (mExecutorService.isShutdown()) { return CompletableFuture.failedFuture(new IllegalStateException("worker shutdown")); } scheduleSyncLocked("write", UPDATE_ALL); scheduleSyncLocked("write", UPDATE_ALL); // Since we use a single threaded executor, we can assume the next scheduled task's // Since we use a single threaded executor, we can assume the next scheduled task's // Future finishes after the sync. // Future finishes after the sync. Loading @@ -127,14 +132,20 @@ class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStatsSync { * within the task, never wait on the resulting Future. This will result in a deadlock. * within the task, never wait on the resulting Future. This will result in a deadlock. */ */ public synchronized void scheduleRunnable(Runnable runnable) { public synchronized void scheduleRunnable(Runnable runnable) { if (!mExecutorService.isShutdown()) { mExecutorService.submit(runnable); mExecutorService.submit(runnable); } } } public void shutdown() { public void shutdown() { mExecutorService.shutdownNow(); mExecutorService.shutdownNow(); } } private Future<?> scheduleSyncLocked(String reason, int flags) { private Future<?> scheduleSyncLocked(String reason, int flags) { if (mExecutorService.isShutdown()) { return CompletableFuture.failedFuture(new IllegalStateException("worker shutdown")); } if (mCurrentFuture == null) { if (mCurrentFuture == null) { mUpdateFlags = flags; mUpdateFlags = flags; mCurrentReason = reason; mCurrentReason = reason; Loading Loading
services/core/java/com/android/server/am/BatteryExternalStatsWorker.java +12 −1 Original line number Original line Diff line number Diff line Loading @@ -38,6 +38,7 @@ import com.android.internal.os.BatteryStatsImpl; import libcore.util.EmptyArray; import libcore.util.EmptyArray; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.Future; Loading Loading @@ -116,6 +117,10 @@ class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStatsSync { } } public synchronized Future<?> scheduleWrite() { public synchronized Future<?> scheduleWrite() { if (mExecutorService.isShutdown()) { return CompletableFuture.failedFuture(new IllegalStateException("worker shutdown")); } scheduleSyncLocked("write", UPDATE_ALL); scheduleSyncLocked("write", UPDATE_ALL); // Since we use a single threaded executor, we can assume the next scheduled task's // Since we use a single threaded executor, we can assume the next scheduled task's // Future finishes after the sync. // Future finishes after the sync. Loading @@ -127,14 +132,20 @@ class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStatsSync { * within the task, never wait on the resulting Future. This will result in a deadlock. * within the task, never wait on the resulting Future. This will result in a deadlock. */ */ public synchronized void scheduleRunnable(Runnable runnable) { public synchronized void scheduleRunnable(Runnable runnable) { if (!mExecutorService.isShutdown()) { mExecutorService.submit(runnable); mExecutorService.submit(runnable); } } } public void shutdown() { public void shutdown() { mExecutorService.shutdownNow(); mExecutorService.shutdownNow(); } } private Future<?> scheduleSyncLocked(String reason, int flags) { private Future<?> scheduleSyncLocked(String reason, int flags) { if (mExecutorService.isShutdown()) { return CompletableFuture.failedFuture(new IllegalStateException("worker shutdown")); } if (mCurrentFuture == null) { if (mCurrentFuture == null) { mUpdateFlags = flags; mUpdateFlags = flags; mCurrentReason = reason; mCurrentReason = reason; Loading