Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88364c1c authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Ensure reported events belong to existent users." into main

parents b210fcdf a7162938
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -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);
            }