diff options
3 files changed, 9 insertions, 30 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index d65dc13b72e3..265ad7dee388 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -1623,18 +1623,6 @@ public class NotificationManagerService extends SystemService { } }; - @VisibleForTesting - final IAppOpsCallback mAppOpsCallback = new IAppOpsCallback.Stub() { - @Override public void opChanged(int op, int uid, String packageName) { - if (mEnableAppSettingMigration) { - int opValue = mAppOps.checkOpNoThrow( - AppOpsManager.OP_POST_NOTIFICATION, uid, packageName); - boolean blocked = op != MODE_ALLOWED; - sendAppBlockStateChangedBroadcast(packageName, uid, blocked); - } - } - }; - private final BroadcastReceiver mPackageIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -2133,12 +2121,6 @@ public class NotificationManagerService extends SystemService { mUsageStatsManagerInternal = usageStatsManagerInternal; mAppOps = appOps; mAppOpsService = iAppOps; - try { - mAppOpsService.startWatchingMode( - AppOpsManager.OP_POST_NOTIFICATION, null, mAppOpsCallback); - } catch (RemoteException e) { - Slog.e(TAG, "Could not register OP_POST_NOTIFICATION listener"); - } mAppUsageStats = appUsageStats; mAlarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE); mCompanionManager = companionManager; @@ -3409,6 +3391,7 @@ public class NotificationManagerService extends SystemService { } mPermissionHelper.setNotificationPermission( pkg, UserHandle.getUserId(uid), enabled, true); + sendAppBlockStateChangedBroadcast(pkg, uid, !enabled); } else { synchronized (mNotificationLock) { boolean wasEnabled = mPreferencesHelper.getImportance(pkg, uid) 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 d752322f567a..67382bfacab4 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -2705,13 +2705,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testUpdateAppNotifyCreatorBlock() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - - // should not trigger a broadcast - when(mAppOpsManager.checkOpNoThrow(anyInt(), eq(mUid), eq(PKG))).thenReturn(MODE_IGNORED); - mService.mAppOpsCallback.opChanged(0, mUid, PKG); + when(mPreferencesHelper.getImportance(PKG, mUid)).thenReturn(IMPORTANCE_DEFAULT); // should trigger a broadcast - mBinderService.setNotificationsEnabledForPackage(PKG, 0, true); + mBinderService.setNotificationsEnabledForPackage(PKG, mUid, false); Thread.sleep(500); waitForIdle(); ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); @@ -2720,7 +2717,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertEquals(NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED, captor.getValue().getAction()); assertEquals(PKG, captor.getValue().getPackage()); - assertFalse(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true)); + assertTrue(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true)); } @Test @@ -2737,7 +2734,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // should not trigger a broadcast when(mAppOpsManager.checkOpNoThrow(anyInt(), eq(mUid), eq(PKG))).thenReturn(MODE_ALLOWED); - mService.mAppOpsCallback.opChanged(0, mUid, PKG); // should trigger a broadcast mBinderService.setNotificationsEnabledForPackage(PKG, 0, true); diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java index a83887202a7d..2ba587d21163 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java @@ -606,9 +606,9 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { @Test public void testUpdateAppNotifyCreatorBlock() throws Exception { - when(mAppOpsManager.checkOpNoThrow(anyInt(), eq(mUid), eq(PKG))).thenReturn(MODE_IGNORED); + when(mPermissionHelper.hasPermission(mUid)).thenReturn(true); - mService.mAppOpsCallback.opChanged(0, mUid, PKG); + mBinderService.setNotificationsEnabledForPackage(PKG, mUid, false); Thread.sleep(500); waitForIdle(); @@ -618,14 +618,14 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { assertEquals(NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED, captor.getValue().getAction()); assertEquals(PKG, captor.getValue().getPackage()); - assertFalse(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true)); + assertTrue(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true)); } @Test public void testUpdateAppNotifyCreatorUnblock() throws Exception { - when(mAppOpsManager.checkOpNoThrow(anyInt(), eq(mUid), eq(PKG))).thenReturn(MODE_ALLOWED); + when(mPermissionHelper.hasPermission(mUid)).thenReturn(false); - mService.mAppOpsCallback.opChanged(0, mUid, PKG); + mBinderService.setNotificationsEnabledForPackage(PKG, mUid, true); Thread.sleep(500); waitForIdle(); |