Don't create unnecessary objects.
Only create a new LinkedList if one doesn't exist already for the user.
Bug: n/a
Test: atest UsageStatsTest
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java
index 2fd6c42..78556ef 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsService.java
@@ -763,11 +763,12 @@
return;
}
- final LinkedList<Event> events = mReportedEvents.get(userId, new LinkedList<>());
- events.add(event);
- if (mReportedEvents.get(userId) == null) {
+ LinkedList<Event> events = mReportedEvents.get(userId);
+ if (events == null) {
+ events = new LinkedList<>();
mReportedEvents.put(userId, events);
}
+ events.add(event);
if (events.size() == 1) {
// Every time a file is persisted to disk, mReportedEvents is cleared for this user
// so trigger a flush to disk every time the first event has been added.