Loading services/core/java/android/app/usage/UsageStatsManagerInternal.java +12 −0 Original line number Diff line number Diff line Loading @@ -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 Loading services/core/java/com/android/server/am/BroadcastQueueModernImpl.java +7 −2 Original line number Diff line number Diff line Loading @@ -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); Loading services/usage/java/com/android/server/usage/UsageStatsService.java +14 −4 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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) { Loading Loading
services/core/java/android/app/usage/UsageStatsManagerInternal.java +12 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
services/core/java/com/android/server/am/BroadcastQueueModernImpl.java +7 −2 Original line number Diff line number Diff line Loading @@ -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); Loading
services/usage/java/com/android/server/usage/UsageStatsService.java +14 −4 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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) { Loading