diff options
| author | 2022-05-03 17:26:44 -0700 | |
|---|---|---|
| committer | 2022-05-03 17:26:44 -0700 | |
| commit | 33c832e34bfdcaffba4cf6e277f93c93ab9f74a4 (patch) | |
| tree | 1f0ee8c56575ac912dafe6aa6c665b91156c4bdb | |
| parent | e48afc4089e11756854dad66370295c4ba98ef08 (diff) | |
Don't consider PACKAGE_USAGE_STATS permission.
When we added the new ACCESS_BROADCAST_RESPONSE_STATS
permission, we updated the new broadcast response
related APIs to check both PACKAGE_USAGE_STATS and
ACCESS_BROADCAST_RESPONSE_STATS permissions until clients
are udpated to use the new permission. We can now remove
the logic for checking PACKAGE_USAGE_STATS permission and
only consider ACCESS_BROADCAST_RESPONSE_STATS.
Bug: 225039700
Test: atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Change-Id: I5b8e8565b936b26463110ce1f0368122c322e632
| -rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 9 | ||||
| -rw-r--r-- | services/usage/java/com/android/server/usage/UsageStatsService.java | 45 |
2 files changed, 11 insertions, 43 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 2ceb00d1ac02..fc2ef0fe5f6e 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -13546,13 +13546,8 @@ public class ActivityManagerService extends IActivityManager.Stub } if (brOptions.getIdForResponseEvent() > 0) { - // STOPSHIP (206518114): Temporarily check for PACKAGE_USAGE_STATS permission as - // well until the clients switch to using the new permission. - if (checkPermission(android.Manifest.permission.ACCESS_BROADCAST_RESPONSE_STATS, - callingPid, callingUid) != PERMISSION_GRANTED) { - enforceUsageStatsPermission(callerPackage, callingUid, callingPid, - "recordResponseEventWhileInBackground()"); - } + enforcePermission(android.Manifest.permission.ACCESS_BROADCAST_RESPONSE_STATS, + callingPid, callingUid, "recordResponseEventWhileInBackground"); } } diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java index 6f89bb25e2ca..078177b3a89f 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UsageStatsService.java @@ -2768,18 +2768,9 @@ public class UsageStatsService extends SystemService implements throw new IllegalArgumentException("id needs to be >=0"); } - final int result = getContext().checkCallingOrSelfPermission( - android.Manifest.permission.ACCESS_BROADCAST_RESPONSE_STATS); - // STOPSHIP (206518114): Temporarily check for PACKAGE_USAGE_STATS permission as well - // until the clients switch to using the new permission. - if (result != PackageManager.PERMISSION_GRANTED) { - if (!hasPermission(callingPackage)) { - throw new SecurityException( - "Caller does not have the permission needed to call this API; " - + "callingPackage=" + callingPackage - + ", callingUid=" + Binder.getCallingUid()); - } - } + getContext().enforceCallingOrSelfPermission( + android.Manifest.permission.ACCESS_BROADCAST_RESPONSE_STATS, + "queryBroadcastResponseStats"); final int callingUid = Binder.getCallingUid(); userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), callingUid, userId, false /* allowAll */, false /* requireFull */, @@ -2801,18 +2792,9 @@ public class UsageStatsService extends SystemService implements } - final int result = getContext().checkCallingOrSelfPermission( - android.Manifest.permission.ACCESS_BROADCAST_RESPONSE_STATS); - // STOPSHIP (206518114): Temporarily check for PACKAGE_USAGE_STATS permission as well - // until the clients switch to using the new permission. - if (result != PackageManager.PERMISSION_GRANTED) { - if (!hasPermission(callingPackage)) { - throw new SecurityException( - "Caller does not have the permission needed to call this API; " - + "callingPackage=" + callingPackage - + ", callingUid=" + Binder.getCallingUid()); - } - } + getContext().enforceCallingOrSelfPermission( + android.Manifest.permission.ACCESS_BROADCAST_RESPONSE_STATS, + "clearBroadcastResponseStats"); final int callingUid = Binder.getCallingUid(); userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), callingUid, userId, false /* allowAll */, false /* requireFull */, @@ -2825,18 +2807,9 @@ public class UsageStatsService extends SystemService implements public void clearBroadcastEvents(@NonNull String callingPackage, @UserIdInt int userId) { Objects.requireNonNull(callingPackage); - final int result = getContext().checkCallingOrSelfPermission( - android.Manifest.permission.ACCESS_BROADCAST_RESPONSE_STATS); - // STOPSHIP (206518114): Temporarily check for PACKAGE_USAGE_STATS permission as well - // until the clients switch to using the new permission. - if (result != PackageManager.PERMISSION_GRANTED) { - if (!hasPermission(callingPackage)) { - throw new SecurityException( - "Caller does not have the permission needed to call this API; " - + "callingPackage=" + callingPackage - + ", callingUid=" + Binder.getCallingUid()); - } - } + getContext().enforceCallingOrSelfPermission( + android.Manifest.permission.ACCESS_BROADCAST_RESPONSE_STATS, + "clearBroadcastEvents"); final int callingUid = Binder.getCallingUid(); userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), callingUid, userId, false /* allowAll */, false /* requireFull */, |