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

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

Merge "Report app component used to all users for broadcasts" into main

parents d08a8dd7 aa78d46f
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -73,6 +73,18 @@ public abstract class UsageStatsManagerInternal {
     */
    public abstract void reportEvent(String packageName, @UserIdInt int userId, int eventType);

    /**
     * Reports an event to the UsageStatsManager for all users. <br/>
     * <em>Note: Starting from {@link android.os.Build.VERSION_CODES#R Android R}, if the user's
     * device is not in an unlocked state (as defined by {@link UserManager#isUserUnlocked()}),
     * then this event will be added to a queue and processed once the device is unlocked.</em>
     *
     * @param packageName The package for which this event occurred.
     * @param eventType The event that occurred. Valid values can be found at
     * {@link UsageEvents}
     */
    public abstract void reportEventForAllUsers(String packageName, int eventType);

    /**
     * Reports a configuration change to the UsageStatsManager. <br/>
     * <em>Note: Starting from {@link android.os.Build.VERSION_CODES#R Android R}, if the user's
+7 −2
Original line number Diff line number Diff line
@@ -2135,9 +2135,14 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
        final boolean targetedBroadcast = r.intent.getComponent() != null;
        final boolean targetedSelf = Objects.equals(r.callerPackage, receiverPackageName);
        if (targetedBroadcast && !targetedSelf) {
            if (r.userId == UserHandle.USER_ALL) {
                mService.mUsageStatsService.reportEventForAllUsers(
                        receiverPackageName, Event.APP_COMPONENT_USED);
            } else {
                mService.mUsageStatsService.reportEvent(receiverPackageName,
                        r.userId, Event.APP_COMPONENT_USED);
            }
        }

        mService.notifyPackageUse(receiverPackageName,
                PackageManager.NOTIFY_PACKAGE_USE_BROADCAST_RECEIVER);
+14 −4
Original line number Diff line number Diff line
@@ -1064,10 +1064,8 @@ 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.
                // Callers of this API should verify that the userId passed to this method exists.
                // 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.
@@ -3238,6 +3236,18 @@ public class UsageStatsService extends SystemService implements
            reportEventOrAddToQueue(userId, event);
        }

        @Override
        public void reportEventForAllUsers(String packageName, int eventType) {
            if (packageName == null) {
                Slog.w(TAG, "Event reported without a package name, eventType:" + eventType);
                return;
            }

            Event event = new Event(eventType, SystemClock.elapsedRealtime());
            event.mPackage = packageName;
            reportEventToAllUserId(event);
        }

        @Override
        public void reportConfigurationChange(Configuration config, int userId) {
            if (config == null) {