diff options
| author | 2024-04-08 13:17:34 +1000 | |
|---|---|---|
| committer | 2024-04-08 13:38:30 +1000 | |
| commit | 617181cb398a15667555db1f05218cfb0f85f979 (patch) | |
| tree | d809af36b703187b57bc8f9ad5e5b6202abc2280 | |
| parent | ac45efa0f07b7e961b7f91227efb84847fd07827 (diff) | |
Accept MODE_DEFAULT for ACCESS_NOTIFICATIONS
In commit 8dfdb4f9358e55b7c06004b3af58951607c16613, the mode for
ACCESS_NOTIFICATIONS was changed from MODE_ALLOWED to MODE_DEFAULT. It
means that when noteOp is called, it may now return MODE_DEFAULT.
Change the check on the return value to also accept MODE_DEFAULT. The
actual permission check is done earlier in the three methods, with a
call to the _enforcePermission method.
Also clean up the @EnforcePermission annotations to clarify their scope.
This is a purely esthetic change.
Bug: 332787465
Test: boot & check Notification History
Test: confirm b/329409825 remains fixed
Change-Id: I75a83cc42ab265ad381254c7ecafeb2088e665cc
| -rwxr-xr-x | services/core/java/com/android/server/notification/NotificationManagerService.java | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 956e10c79246..13404013333b 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -22,6 +22,7 @@ import static android.Manifest.permission.STATUS_BAR_SERVICE; import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND; import static android.app.ActivityManagerInternal.ServiceNotificationPolicy.NOT_FOREGROUND_SERVICE; import static android.app.AppOpsManager.MODE_ALLOWED; +import static android.app.AppOpsManager.MODE_DEFAULT; import static android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR; import static android.app.Flags.lifetimeExtensionRefactor; import static android.app.Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION; @@ -3597,8 +3598,8 @@ public class NotificationManagerService extends SystemService { } } - @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_TOAST_RATE_LIMITING) @Override + @EnforcePermission(android.Manifest.permission.MANAGE_TOAST_RATE_LIMITING) public void setToastRateLimitingEnabled(boolean enable) { super.setToastRateLimitingEnabled_enforcePermission(); @@ -4523,7 +4524,6 @@ public class NotificationManagerService extends SystemService { return getActiveNotificationsWithAttribution(callingPkg, null); } - @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_NOTIFICATIONS) /** * System-only API for getting a list of current (i.e. not cleared) notifications. * @@ -4531,6 +4531,7 @@ public class NotificationManagerService extends SystemService { * @returns A list of all the notifications, in natural order. */ @Override + @EnforcePermission(android.Manifest.permission.ACCESS_NOTIFICATIONS) public StatusBarNotification[] getActiveNotificationsWithAttribution(String callingPkg, String callingAttributionTag) { // enforce() will ensure the calling uid has the correct permission @@ -4548,9 +4549,9 @@ public class NotificationManagerService extends SystemService { }); // noteOp will check to make sure the callingPkg matches the uid - if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg, - callingAttributionTag, null) - == MODE_ALLOWED) { + int mode = mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg, + callingAttributionTag, null); + if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) { synchronized (mNotificationLock) { final int N = mNotificationList.size(); for (int i = 0; i < N; i++) { @@ -4650,12 +4651,12 @@ public class NotificationManagerService extends SystemService { includeSnoozed); } - @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_NOTIFICATIONS) /** * System-only API for getting a list of recent (cleared, no longer shown) notifications. */ @Override @RequiresPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS) + @EnforcePermission(android.Manifest.permission.ACCESS_NOTIFICATIONS) public StatusBarNotification[] getHistoricalNotificationsWithAttribution(String callingPkg, String callingAttributionTag, int count, boolean includeSnoozed) { // enforce() will ensure the calling uid has the correct permission @@ -4665,9 +4666,9 @@ public class NotificationManagerService extends SystemService { int uid = Binder.getCallingUid(); // noteOp will check to make sure the callingPkg matches the uid - if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg, - callingAttributionTag, null) - == MODE_ALLOWED) { + int mode = mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg, + callingAttributionTag, null); + if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) { synchronized (mArchive) { tmp = mArchive.getArray(mUm, count, includeSnoozed); } @@ -4675,7 +4676,6 @@ public class NotificationManagerService extends SystemService { return tmp; } - @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_NOTIFICATIONS) /** * System-only API for getting a list of historical notifications. May contain multiple days * of notifications. @@ -4683,6 +4683,7 @@ public class NotificationManagerService extends SystemService { @Override @WorkerThread @RequiresPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS) + @EnforcePermission(android.Manifest.permission.ACCESS_NOTIFICATIONS) public NotificationHistory getNotificationHistory(String callingPkg, String callingAttributionTag) { // enforce() will ensure the calling uid has the correct permission @@ -4690,9 +4691,9 @@ public class NotificationManagerService extends SystemService { int uid = Binder.getCallingUid(); // noteOp will check to make sure the callingPkg matches the uid - if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg, - callingAttributionTag, null) - == MODE_ALLOWED) { + int mode = mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg, + callingAttributionTag, null); + if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) { IntArray currentUserIds = mUserProfiles.getCurrentProfileIds(); Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "notifHistoryReadHistory"); try { |