Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 73442221 authored by Alison Cichowlas's avatar Alison Cichowlas
Browse files

RONs: Perform AppOps update as NoManService, not SysUI.

Test: NotificationManagerServiceTest
Flag: android.app.ui_rich_ongoing
Bug: 417258670
Change-Id: I0abc8b7b38f645d89e0d1f035f3b2a10a2bf93b3
parent cedaea13
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -17,10 +17,8 @@
package com.android.server.notification;
import static android.Manifest.permission.CONTROL_KEYGUARD_SECURE_NOTIFICATIONS;
import static android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS;
import static android.Manifest.permission.POST_PROMOTED_NOTIFICATIONS;
import static android.Manifest.permission.RECEIVE_SENSITIVE_NOTIFICATIONS;
import static android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS;
import static android.Manifest.permission.STATUS_BAR_SERVICE;
import static android.Manifest.permission.UPDATE_APP_OPS_STATS;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_CACHED;
@@ -4731,9 +4729,9 @@ public class NotificationManagerService extends SystemService {
         */
        @Override
        @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING)
        @RequiresPermission(anyOf = {GRANT_RUNTIME_PERMISSIONS, REVOKE_RUNTIME_PERMISSIONS})
        public void setCanBePromoted(
                String pkg, int uid, boolean promote, boolean fromUser) {
            // Only the OS is allowed to change this permission
            checkCallerIsSystemOrSystemUiOrShell();
            if (!android.app.Flags.apiRichOngoing()) {
                return;
@@ -4753,14 +4751,19 @@ public class NotificationManagerService extends SystemService {
                boolean wasPromoted = checkPostPromotedNotificationPermission(pkg, uid);
                int mode = promote ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED;
                mAppOps.setUidMode(OP_POST_PROMOTED_NOTIFICATIONS, uid, mode);
                final long identity = Binder.clearCallingIdentity();
                try {
                    mAppOps.setUidMode(OP_POST_PROMOTED_NOTIFICATIONS, uid, mode);
                    mPackageManagerClient.updatePermissionFlags(POST_PROMOTED_NOTIFICATIONS, pkg,
                            FLAG_PERMISSION_USER_SET, FLAG_PERMISSION_USER_SET,
                            getUserHandleForUid(uid));
                    Log.i(TAG, "Set promoted permission: " + pkg + ", " + uid + "," + mode);
                    changed = wasPromoted != promote;
                } finally {
                    Binder.restoreCallingIdentity(identity);
                }
            } else {
                // Use preferences backend for allowing promotion per app
                changed = mPreferencesHelper.setCanBePromoted(pkg, uid, promote, fromUser);