From 3862660dea42df3bbb72dd0b59d88ae866e4f7dd Mon Sep 17 00:00:00 2001 From: Jing Ji Date: Fri, 29 May 2020 21:53:02 -0700 Subject: [PATCH] Add proper lock to the dropbox throttling map Bug: 156871564 Test: Manual Change-Id: I7da4f4b9586ea33eeb66875ab312701f49b62dd3 --- .../server/am/ActivityManagerService.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index d0ad6db793a68..a4e45cd334bf2 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -10156,7 +10156,7 @@ public class ActivityManagerService extends IActivityManager.Stub } } - private volatile ArrayMap mErrorClusterRecords = new ArrayMap<>(); + private final ArrayMap mErrorClusterRecords = new ArrayMap<>(); /** * Write a description of an error (crash, WTF, ANR) to the drop box. @@ -10189,16 +10189,18 @@ public class ActivityManagerService extends IActivityManager.Stub // Rate-limit how often we're willing to do the heavy lifting below to // collect and record logs; currently 5 logs per 10 second period per eventType. final long now = SystemClock.elapsedRealtime(); - long[] errRecord = mErrorClusterRecords.get(eventType); - if (errRecord == null) { - errRecord = new long[2]; // [0]: startTime, [1]: count - mErrorClusterRecords.put(eventType, errRecord); - } - if (now - errRecord[0] > 10 * DateUtils.SECOND_IN_MILLIS) { - errRecord[0] = now; - errRecord[1] = 1L; - } else { - if (errRecord[1]++ >= 5) return; + synchronized (mErrorClusterRecords) { + long[] errRecord = mErrorClusterRecords.get(eventType); + if (errRecord == null) { + errRecord = new long[2]; // [0]: startTime, [1]: count + mErrorClusterRecords.put(eventType, errRecord); + } + if (now - errRecord[0] > 10 * DateUtils.SECOND_IN_MILLIS) { + errRecord[0] = now; + errRecord[1] = 1L; + } else { + if (errRecord[1]++ >= 5) return; + } } final StringBuilder sb = new StringBuilder(1024);