Loading services/core/java/com/android/server/notification/NotificationManagerService.java +1 −18 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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; Loading Loading @@ -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) Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +3 −7 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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 Loading @@ -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); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java +5 −5 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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(); Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +1 −18 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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; Loading Loading @@ -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) Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +3 −7 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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 Loading @@ -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); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java +5 −5 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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(); Loading