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

Commit 915e9f26 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Catch RejectedExecutionException in BatteryExternalStatsWorker" into main

parents 688c113f 035db058
Loading
Loading
Loading
Loading
+27 −15
Original line number Diff line number Diff line
@@ -342,6 +342,7 @@ public class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStat
    @Override
    public Future<?> scheduleCleanupDueToRemovedUser(int userId) {
        synchronized (BatteryExternalStatsWorker.this) {
            try {
                // Initial quick clean-up after a user removal
                mExecutorService.schedule(() -> {
                    synchronized (mStats) {
@@ -349,13 +350,16 @@ public class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStat
                    }
                }, UID_QUICK_REMOVAL_AFTER_USER_REMOVAL_DELAY_MILLIS, TimeUnit.MILLISECONDS);

            // Final clean-up after a user removal, to take care of UIDs that were running longer
            // than expected
                // Final clean-up after a user removal, to take care of UIDs that were running
                // longer than expected
                return mExecutorService.schedule(() -> {
                    synchronized (mStats) {
                        mStats.clearRemovedUserUidsLocked(userId);
                    }
                }, UID_FINAL_REMOVAL_AFTER_USER_REMOVAL_DELAY_MILLIS, TimeUnit.MILLISECONDS);
            } catch (RejectedExecutionException e) {
                return CompletableFuture.failedFuture(e);
            }
        }
    }

@@ -401,7 +405,11 @@ public class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStat
        scheduleSyncLocked("write", UPDATE_ALL);
        // Since we use a single threaded executor, we can assume the next scheduled task's
        // Future finishes after the sync.
        try {
            return mExecutorService.submit(mWriteTask);
        } catch (RejectedExecutionException e) {
            return CompletableFuture.failedFuture(e);
        }
    }

    /**
@@ -429,7 +437,11 @@ public class BatteryExternalStatsWorker implements BatteryStatsImpl.ExternalStat
        if (mCurrentFuture == null) {
            mUpdateFlags = flags;
            mCurrentReason = reason;
            try {
                mCurrentFuture = mExecutorService.submit(mSyncTask);
            } catch (RejectedExecutionException e) {
                return CompletableFuture.failedFuture(e);
            }
        }
        mUpdateFlags |= flags;
        return mCurrentFuture;