Fix concurrent modification crash in onAlarm

Change-Id: Idfd094f3c9ea59356440d6851ccd5abda36ca6ba
Fixes: 35640585
Test: manual; after boot, opened the power menu to force
system_server to spin up a ThreadedRenderer instance
(and thus register itself as a callback on GraphicsStatsService).
Then manually set the date forward by a day to trigger onAlarm
and verified the system didn't reboot/crash. A systrace capture
verified that the alarm fired and package:android (system_server)
had a log rotation event.
This commit is contained in:
John Reck
2017-02-22 17:01:30 -08:00
parent f9bd294469
commit 37dfb42992

View File

@@ -137,16 +137,21 @@ public class GraphicsStatsService extends IGraphicsStats.Stub {
}
private void onAlarm() {
// We need to make a copy since some of the callbacks won't be proxy and thus
// can result in a re-entrant acquisition of mLock that would result in a modification
// of mActive during iteration.
ActiveBuffer[] activeCopy;
synchronized (mLock) {
mRotateIsScheduled = false;
scheduleRotateLocked();
for (ActiveBuffer active : mActive) {
try {
active.mCallback.onRotateGraphicsStatsBuffer();
} catch (RemoteException e) {
Log.w(TAG, String.format("Failed to notify '%s' (pid=%d) to rotate buffers",
active.mInfo.packageName, active.mPid), e);
}
activeCopy = mActive.toArray(new ActiveBuffer[0]);
}
for (ActiveBuffer active : activeCopy) {
try {
active.mCallback.onRotateGraphicsStatsBuffer();
} catch (RemoteException e) {
Log.w(TAG, String.format("Failed to notify '%s' (pid=%d) to rotate buffers",
active.mInfo.packageName, active.mPid), e);
}
}
// Give a few seconds for everyone to rotate before doing the cleanup