Fix potential race condition due to missing lock

Bug: 194991626
Test: atest ProcStatsValidationTests
Test: atest ProcessStatsDumpsysTest
Test: CtsIncidentHostTestCases:ProcStatsProtoTest
Change-Id: I1dc7c03d031248fb945dc2cf9dd47ad590ec672c
This commit is contained in:
Jing Ji
2021-09-15 14:47:47 -07:00
parent 2173726505
commit 402cd20162

View File

@@ -5221,7 +5221,9 @@ public final class ActiveServices {
sr.setProcess(null, null, 0, null);
sr.isolatedProc = null;
sr.executeNesting = 0;
sr.forceClearTracker();
synchronized (mAm.mProcessStats.mLock) {
sr.forceClearTracker();
}
if (mDestroyingServices.remove(sr)) {
if (DEBUG_SERVICE) Slog.v(TAG_SERVICE, "killServices remove destroying " + sr);
}
@@ -5371,7 +5373,9 @@ public final class ActiveServices {
i--;
ServiceRecord sr = mDestroyingServices.get(i);
if (sr.app == app) {
sr.forceClearTracker();
synchronized (mAm.mProcessStats.mLock) {
sr.forceClearTracker();
}
mDestroyingServices.remove(i);
if (DEBUG_SERVICE) Slog.v(TAG_SERVICE, "killServices remove destroying " + sr);
}