Loading services/core/java/com/android/server/notification/NotificationManagerService.java +9 −0 Original line number Diff line number Diff line Loading @@ -2408,6 +2408,15 @@ public class NotificationManagerService extends SystemService { public void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) { enforceSystemOrSystemUI("setNotificationsEnabledForPackage"); synchronized (mNotificationLock) { boolean wasEnabled = mPreferencesHelper.getImportance(pkg, uid) != NotificationManager.IMPORTANCE_NONE; if (wasEnabled == enabled) { return; } } mPreferencesHelper.setEnabled(pkg, uid, enabled); mMetricsLogger.write(new LogMaker(MetricsEvent.ACTION_BAN_APP_NOTES) .setType(MetricsEvent.TYPE_ACTION) Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +10 −2 Original line number Diff line number Diff line Loading @@ -1508,14 +1508,22 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testUpdateAppNotifyCreatorBlock() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); mBinderService.setNotificationsEnabledForPackage(PKG, 0, false); mBinderService.setNotificationsEnabledForPackage(PKG, 0, true); ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); verify(mContext, times(1)).sendBroadcastAsUser(captor.capture(), any(), eq(null)); assertEquals(NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED, captor.getValue().getAction()); assertEquals(PKG, captor.getValue().getPackage()); assertTrue(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, false)); assertFalse(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true)); } @Test public void testUpdateAppNotifyCreatorBlock_notIfMatchesExistingSetting() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); mBinderService.setNotificationsEnabledForPackage(PKG, 0, false); verify(mContext, never()).sendBroadcastAsUser(any(), any(), eq(null)); } @Test Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +9 −0 Original line number Diff line number Diff line Loading @@ -2408,6 +2408,15 @@ public class NotificationManagerService extends SystemService { public void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) { enforceSystemOrSystemUI("setNotificationsEnabledForPackage"); synchronized (mNotificationLock) { boolean wasEnabled = mPreferencesHelper.getImportance(pkg, uid) != NotificationManager.IMPORTANCE_NONE; if (wasEnabled == enabled) { return; } } mPreferencesHelper.setEnabled(pkg, uid, enabled); mMetricsLogger.write(new LogMaker(MetricsEvent.ACTION_BAN_APP_NOTES) .setType(MetricsEvent.TYPE_ACTION) Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +10 −2 Original line number Diff line number Diff line Loading @@ -1508,14 +1508,22 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testUpdateAppNotifyCreatorBlock() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); mBinderService.setNotificationsEnabledForPackage(PKG, 0, false); mBinderService.setNotificationsEnabledForPackage(PKG, 0, true); ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); verify(mContext, times(1)).sendBroadcastAsUser(captor.capture(), any(), eq(null)); assertEquals(NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED, captor.getValue().getAction()); assertEquals(PKG, captor.getValue().getPackage()); assertTrue(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, false)); assertFalse(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true)); } @Test public void testUpdateAppNotifyCreatorBlock_notIfMatchesExistingSetting() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); mBinderService.setNotificationsEnabledForPackage(PKG, 0, false); verify(mContext, never()).sendBroadcastAsUser(any(), any(), eq(null)); } @Test Loading