Merge "Add broadcast when notification block state changes"
This commit is contained in:
committed by
Android (Google) Code Review
commit
d12ad36399
@@ -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";
|
||||
|
||||
@@ -92,6 +92,18 @@ public class NotificationManager {
|
||||
private static String TAG = "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
|
||||
|
||||
@@ -514,6 +514,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" />
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -1178,6 +1178,34 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
anyString(), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean());
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
Reference in New Issue
Block a user