From 7839d2d844c6b031c2c63df4108f210c96e68efa Mon Sep 17 00:00:00 2001 From: Kevin Han Date: Wed, 30 Jun 2021 20:53:49 -0700 Subject: [PATCH] Actually count explicit broadcasts as usage Explicit broadcasts do actually still have the FLAG_EXCLUDE_STOPPED_PACKAGES flag even though explicit broadcasts DO go to stopped packages (and unstop them). This means checking for the flag does not actually help to differentiate explicit broadcasts from implicit broadcasts for the purpose of package usage. Instead, we just check if there is a specific component name set for the broadcast. Bug: 192585331 Test: "am broadcast" an explicit broadcast to test app "adb shell dumpsys usagestats" to check last time component used Change-Id: Ib04a4398f15084d7a96daf0a621cfc468174187f --- services/core/java/com/android/server/am/BroadcastQueue.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/BroadcastQueue.java b/services/core/java/com/android/server/am/BroadcastQueue.java index de2c11b9fc2e9..503b3a93b31f8 100644 --- a/services/core/java/com/android/server/am/BroadcastQueue.java +++ b/services/core/java/com/android/server/am/BroadcastQueue.java @@ -1652,7 +1652,7 @@ public final class BroadcastQueue { maybeScheduleTempAllowlistLocked(receiverUid, r, brOptions); // Report that a component is used for explicit broadcasts. - if (!r.intent.isExcludingStopped() && r.curComponent != null + if (r.intent.getComponent() != null && r.curComponent != null && !TextUtils.equals(r.curComponent.getPackageName(), r.callerPackage)) { mService.mUsageStatsService.reportEvent( r.curComponent.getPackageName(), r.userId, Event.APP_COMPONENT_USED);