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
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user