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

Commit 035db058 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Catch RejectedExecutionException in BatteryExternalStatsWorker

Bug: 296805223
Test: monitor crash cluster 1030343958128424937
Change-Id: I58361832dd50ca7e67cddc4b578ba46adcb9407c
parent 1fc9dac6
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;