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
This commit is contained in:
Kevin Han
2021-06-30 20:53:49 -07:00
parent 3835717ff9
commit 7839d2d844

View File

@@ -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);