diff options
| author | 2018-01-22 17:45:16 -0500 | |
|---|---|---|
| committer | 2018-01-23 09:04:30 -0500 | |
| commit | fc9767b8457cac6da10a938c71c0f1f29853d8f8 (patch) | |
| tree | 7a6f0ce8dc972281fc8e9f34f9894aa4dc69ada3 | |
| parent | c128c86481682f92ba005332b7e456b0b8a762c3 (diff) | |
Add broadcast when notification block state changes
At the app level, to match channel and group broadcasts.
Test: runtest systemui-notification
Bug: 63927402
Change-Id: If6bf8b468f90fe5ed225ea136425104a418d4974
5 files changed, 55 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index eaa35711d30f..2e6d706fb5dc 100644 --- a/api/current.txt +++ b/api/current.txt @@ -5693,6 +5693,7 @@ package android.app { method public final void setInterruptionFilter(int); method public void setNotificationPolicy(android.app.NotificationManager.Policy); method public boolean updateAutomaticZenRule(java.lang.String, android.app.AutomaticZenRule); + field public static final java.lang.String ACTION_APP_BLOCK_STATE_CHANGED = "android.app.action.APP_BLOCK_STATE_CHANGED"; field public static final java.lang.String ACTION_INTERRUPTION_FILTER_CHANGED = "android.app.action.INTERRUPTION_FILTER_CHANGED"; field public static final java.lang.String ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED = "android.app.action.NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED"; field public static final java.lang.String ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED = "android.app.action.NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED"; diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java index 659cf169e994..f9857f700c8d 100644 --- a/core/java/android/app/NotificationManager.java +++ b/core/java/android/app/NotificationManager.java @@ -93,6 +93,18 @@ public class NotificationManager { private static boolean localLOGV = false; /** + * Intent that is broadcast when an application is blocked or unblocked. + * + * This broadcast is only sent to the app whose block state has changed. + * + * Input: nothing + * Output: nothing + */ + @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_APP_BLOCK_STATE_CHANGED = + "android.app.action.APP_BLOCK_STATE_CHANGED"; + + /** * Intent that is broadcast when a {@link NotificationChannel} is blocked * (when {@link NotificationChannel#getImportance()} is {@link #IMPORTANCE_NONE}) or unblocked * (when {@link NotificationChannel#getImportance()} is anything other than diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 93d852ca1326..15c80f393e8a 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -510,6 +510,7 @@ <protected-broadcast android:name="android.os.action.ACTION_EFFECTS_SUPPRESSOR_CHANGED" /> <protected-broadcast android:name="android.app.action.NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED" /> <protected-broadcast android:name="android.app.action.NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED" /> + <protected-broadcast android:name="android.app.action.APP_BLOCK_STATE_CHANGED" /> <protected-broadcast android:name="android.permission.GET_APP_GRANTED_URI_PERMISSIONS" /> <protected-broadcast android:name="android.permission.CLEAR_APP_GRANTED_URI_PERMISSIONS" /> diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 39b7c7c310fe..d0ded029d45f 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -16,6 +16,7 @@ package com.android.server.notification; +import static android.app.NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED; import static android.app.NotificationManager.ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED; import static android.app.NotificationManager.ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED; import static android.app.NotificationManager.IMPORTANCE_LOW; @@ -1881,6 +1882,18 @@ public class NotificationManagerService extends SystemService { cancelAllNotificationsInt(MY_UID, MY_PID, pkg, null, 0, 0, true, UserHandle.getUserId(uid), REASON_PACKAGE_BANNED, null); } + + try { + getContext().sendBroadcastAsUser( + new Intent(ACTION_APP_BLOCK_STATE_CHANGED) + .putExtra(NotificationManager.EXTRA_BLOCKED_STATE, !enabled) + .addFlags(Intent.FLAG_RECEIVER_FOREGROUND) + .setPackage(pkg), + UserHandle.of(UserHandle.getUserId(uid)), null); + } catch (SecurityException e) { + Slog.w(TAG, "Can't notify app about app block change", e); + } + savePolicyFile(); } 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 e0bebee2475e..9ae6f00f44ca 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -1179,6 +1179,34 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test + public void testUpdateAppNotifyCreatorBlock() throws Exception { + mService.setRankingHelper(mRankingHelper); + + mBinderService.setNotificationsEnabledForPackage(PKG, 0, false); + 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)); + } + + @Test + public void testUpdateAppNotifyCreatorUnblock() throws Exception { + mService.setRankingHelper(mRankingHelper); + + 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()); + assertFalse(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true)); + } + + @Test public void testUpdateChannelNotifyCreatorBlock() throws Exception { mService.setRankingHelper(mRankingHelper); when(mRankingHelper.getNotificationChannel(eq(PKG), anyInt(), |