Merge "Fix for out of bounds exception in CachedAppOptimizer"

This commit is contained in:
TreeHugger Robot
2022-08-11 21:29:12 +00:00
committed by Android (Google) Code Review

View File

@@ -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;