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

Commit 92cffb3f authored by Edgar Arriaga's avatar Edgar Arriaga
Browse files

Fix for out of bounds exception in CachedAppOptimizer

The exception happens when cancelAllCompactions is called
since the size changed while iterating in the loop caused
by the inner cancelCompactionForProcess function. Changing
the iteration to a while loop fixes the issue until consumed
fixes the issue.

Bug: 242010026
Test: Manual
Change-Id: I92049ae3d06e403a37e69ee252ed993c89b6d9a7
parent 582bfc69
Loading
Loading
Loading
Loading
+3 −11
Original line number Diff line number Diff line
@@ -1392,25 +1392,17 @@ public final class CachedAppOptimizer {

    void cancelAllCompactions(CancelCompactReason reason) {
        synchronized (mProcLock) {
            int size = mPendingCompactionProcesses.size();
            ProcessRecord record;
            for (int i=0; i < size; ++i) {
                record = mPendingCompactionProcesses.get(i);
                cancelCompactionForProcess(record, reason);
                // The process record is kept alive after compactions are cleared,
                // so make sure to reset the compaction state to avoid skipping any future
                // compactions due to a stale value here.
                record.mOptRecord.setHasPendingCompact(false);
            while(!mPendingCompactionProcesses.isEmpty()) {
                cancelCompactionForProcess(mPendingCompactionProcesses.get(0), reason);
            }
            mPendingCompactionProcesses.clear();
        }
        cancelCompaction();
    }

    @GuardedBy("mProcLock")
    void cancelCompactionForProcess(ProcessRecord app, CancelCompactReason cancelReason) {
        boolean cancelled = false;
        if (!mPendingCompactionProcesses.isEmpty() && mPendingCompactionProcesses.contains(app)) {
        if (mPendingCompactionProcesses.contains(app)) {
            app.mOptRecord.setHasPendingCompact(false);
            mPendingCompactionProcesses.remove(app);
            cancelled = true;