summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Varun Shah <varunshah@google.com> 2024-06-18 00:01:00 +0000
committer Varun Shah <varunshah@google.com> 2024-06-28 20:35:41 +0000
commita7162938d98304bc90bf6978d918e1cfadeb0e4c (patch)
tree129291484a97272b314aaa40a73e0f346faef143
parentaf52873b6627b45ac392ec75f719ea483bc54937 (diff)
Ensure reported events belong to existent users.
Bug: 347644400 Test: atest CtsUsageStatsTestCases Change-Id: I0d11abefc00af405c56f6a356ff4770a436f4b13
-rw-r--r--services/usage/java/com/android/server/usage/UsageStatsService.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java
index 27c383c283a1..bf46154caf3e 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsService.java
@@ -113,6 +113,7 @@ import com.android.internal.util.IndentingPrintWriter;
import com.android.server.IoThread;
import com.android.server.LocalServices;
import com.android.server.SystemService;
+import com.android.server.pm.UserManagerInternal;
import com.android.server.usage.AppStandbyInternal.AppIdleStateChangeListener;
import com.android.server.utils.AlarmQueue;
@@ -1063,6 +1064,18 @@ public class UsageStatsService extends SystemService implements
synchronized (mReportedEvents) {
LinkedList<Event> events = mReportedEvents.get(userId);
if (events == null) {
+ // TODO (b/347644400): callers of this API should verify that the userId passed to
+ // this method exists - there is currently a known case where USER_ALL is passed
+ // here and it would be added to the queue, never to be flushed correctly. The logic
+ // below should only remain as a last-resort catch-all fix.
+ final UserManagerInternal umi = LocalServices.getService(UserManagerInternal.class);
+ if (umi == null || (umi != null && !umi.exists(userId))) {
+ // The userId passed is a non-existent user so don't report the event.
+ Slog.wtf(TAG, "Attempted to report event for non-existent user " + userId
+ + " (" + event.mPackage + "/" + event.mClass
+ + " eventType:" + event.mEventType + ")");
+ return;
+ }
events = new LinkedList<>();
mReportedEvents.put(userId, events);
}