diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index c6886da55dfc4..d5b2ee3461872 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -98,6 +98,8 @@ import android.app.NotificationManager; import android.app.NotificationManager.Policy; import android.app.PendingIntent; import android.app.StatusBarManager; +import android.app.admin.DeviceAdminInfo; +import android.app.admin.DevicePolicyManagerInternal; import android.app.backup.BackupManager; import android.app.usage.UsageEvents; import android.app.usage.UsageStatsManagerInternal; @@ -366,6 +368,7 @@ public class NotificationManagerService extends SystemService { private AppOpsManager mAppOps; private UsageStatsManagerInternal mAppUsageStats; + private DevicePolicyManagerInternal mDpm; private Archive mArchive; @@ -1355,7 +1358,7 @@ public class NotificationManagerService extends SystemService { ICompanionDeviceManager companionManager, SnoozeHelper snoozeHelper, NotificationUsageStats usageStats, AtomicFile policyFile, ActivityManager activityManager, GroupHelper groupHelper, IActivityManager am, - UsageStatsManagerInternal appUsageStats) { + UsageStatsManagerInternal appUsageStats, DevicePolicyManagerInternal dpm) { Resources resources = getContext().getResources(); mMaxPackageEnqueueRate = Settings.Global.getFloat(getContext().getContentResolver(), Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE, @@ -1374,6 +1377,8 @@ public class NotificationManagerService extends SystemService { mActivityManager = activityManager; mDeviceIdleController = IDeviceIdleController.Stub.asInterface( ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); + mDpm = dpm; + try { mPermissionOwner = mAm.newUriPermissionOwner("notification"); } catch (RemoteException e) { @@ -1512,7 +1517,8 @@ public class NotificationManagerService extends SystemService { new AtomicFile(new File(systemDir, "notification_policy.xml"), "notification-policy"), (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE), getGroupHelper(), ActivityManager.getService(), - LocalServices.getService(UsageStatsManagerInternal.class)); + LocalServices.getService(UsageStatsManagerInternal.class), + LocalServices.getService(DevicePolicyManagerInternal.class)); // register for various Intents IntentFilter filter = new IntentFilter(); @@ -3090,8 +3096,8 @@ public class NotificationManagerService extends SystemService { private boolean checkPolicyAccess(String pkg) { try { - int uid = getContext().getPackageManager().getPackageUidAsUser( - pkg, UserHandle.getCallingUserId()); + int uid = getContext().getPackageManager().getPackageUidAsUser(pkg, + UserHandle.getCallingUserId()); if (PackageManager.PERMISSION_GRANTED == ActivityManager.checkComponentPermission( android.Manifest.permission.MANAGE_NOTIFICATIONS, uid, -1, true)) { @@ -3100,7 +3106,11 @@ public class NotificationManagerService extends SystemService { } catch (NameNotFoundException e) { return false; } - return checkPackagePolicyAccess(pkg) || mListeners.isComponentEnabledForPackage(pkg); + return checkPackagePolicyAccess(pkg) + || mListeners.isComponentEnabledForPackage(pkg) + || (mDpm != null && + mDpm.isActiveAdminWithPolicy(Binder.getCallingUid(), + DeviceAdminInfo.USES_POLICY_PROFILE_OWNER)); } @Override diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index 14f84b1feca22..9d5d263ad5afc 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -68,6 +68,8 @@ import android.app.Notification.MessagingStyle.Message; import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.app.NotificationManager; +import android.app.admin.DeviceAdminInfo; +import android.app.admin.DevicePolicyManagerInternal; import android.app.usage.UsageStatsManagerInternal; import android.companion.ICompanionDeviceManager; import android.content.ComponentName; @@ -265,7 +267,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mPackageManager, mPackageManagerClient, mockLightsManager, mListeners, mAssistants, mConditionProviders, mCompanionMgr, mSnoozeHelper, mUsageStats, mPolicyFile, mActivityManager, - mGroupHelper, mAm, mock(UsageStatsManagerInternal.class)); + mGroupHelper, mAm, mock(UsageStatsManagerInternal.class), + mock(DevicePolicyManagerInternal.class)); } catch (SecurityException e) { if (!e.getMessage().contains("Permission Denial: not allowed to send broadcast")) { throw e;