diff options
| author | 2023-10-05 15:39:12 +0000 | |
|---|---|---|
| committer | 2023-10-05 15:39:12 +0000 | |
| commit | 9c03b188c9d829bd4cfff7cd893b0e513ffca54d (patch) | |
| tree | 280b4be0efe3b759e2e71381c81d23729688eeb7 | |
| parent | 551eb75ff871744ba9ea5799282cb452139ea33a (diff) | |
| parent | 7712cba78355979b5af287f9afbd0ddd178250d0 (diff) | |
Merge "Avoid holding main lock for pending event processing" into main
| -rw-r--r-- | services/usage/java/com/android/server/usage/UsageStatsService.java | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java index 18c960e3ebbc..9956faaa2eb1 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UsageStatsService.java @@ -495,9 +495,12 @@ public class UsageStatsService extends SystemService implements Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "loadPendingEvents"); loadPendingEventsLocked(userId, pendingEvents); Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); - final LinkedList<Event> eventsInMem = mReportedEvents.get(userId); - if (eventsInMem != null) { - pendingEvents.addAll(eventsInMem); + synchronized (mReportedEvents) { + final LinkedList<Event> eventsInMem = mReportedEvents.get(userId); + if (eventsInMem != null) { + pendingEvents.addAll(eventsInMem); + mReportedEvents.remove(userId); + } } boolean needToFlush = !pendingEvents.isEmpty(); @@ -518,8 +521,7 @@ public class UsageStatsService extends SystemService implements mIoHandler.obtainMessage(MSG_HANDLE_LAUNCH_TIME_ON_USER_UNLOCK, userId, 0).sendToTarget(); - // Remove all the stats stored in memory and in system DE. - mReportedEvents.remove(userId); + // Remove all the stats stored in system DE. deleteRecursively(new File(Environment.getDataSystemDeDirectory(userId), "usagestats")); // Force a flush to disk for the current user to ensure important events are persisted. @@ -916,6 +918,7 @@ public class UsageStatsService extends SystemService implements } } + @GuardedBy({"mLock", "mReportedEvents"}) private void persistPendingEventsLocked(int userId) { final LinkedList<Event> pendingEvents = mReportedEvents.get(userId); if (pendingEvents == null || pendingEvents.isEmpty()) { @@ -1019,7 +1022,7 @@ public class UsageStatsService extends SystemService implements + UserUsageStatsService.eventToString(event.mEventType); Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, traceTag); } - synchronized (mLock) { + synchronized (mReportedEvents) { LinkedList<Event> events = mReportedEvents.get(userId); if (events == null) { events = new LinkedList<>(); @@ -1943,16 +1946,19 @@ public class UsageStatsService extends SystemService implements idpw.println(); } } else { - final LinkedList<Event> pendingEvents = mReportedEvents.get(userId); - if (pendingEvents != null && !pendingEvents.isEmpty()) { - final int eventCount = pendingEvents.size(); - idpw.println("Pending events: count=" + eventCount); - idpw.increaseIndent(); - for (int idx = 0; idx < eventCount; idx++) { - UserUsageStatsService.printEvent(idpw, pendingEvents.get(idx), true); + synchronized (mReportedEvents) { + final LinkedList<Event> pendingEvents = mReportedEvents.get(userId); + if (pendingEvents != null && !pendingEvents.isEmpty()) { + final int eventCount = pendingEvents.size(); + idpw.println("Pending events: count=" + eventCount); + idpw.increaseIndent(); + for (int idx = 0; idx < eventCount; idx++) { + UserUsageStatsService.printEvent(idpw, pendingEvents.get(idx), + true); + } + idpw.decreaseIndent(); + idpw.println(); } - idpw.decreaseIndent(); - idpw.println(); } } idpw.decreaseIndent(); |