Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc9767b8 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

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
parent c128c864
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -5693,6 +5693,7 @@ package android.app {
    method public final void setInterruptionFilter(int);
    method public final void setInterruptionFilter(int);
    method public void setNotificationPolicy(android.app.NotificationManager.Policy);
    method public void setNotificationPolicy(android.app.NotificationManager.Policy);
    method public boolean updateAutomaticZenRule(java.lang.String, android.app.AutomaticZenRule);
    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_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_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";
    field public static final java.lang.String ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED = "android.app.action.NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED";
+12 −0
Original line number Original line Diff line number Diff line
@@ -92,6 +92,18 @@ public class NotificationManager {
    private static String TAG = "NotificationManager";
    private static String TAG = "NotificationManager";
    private static boolean localLOGV = false;
    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
     * 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 {@link #IMPORTANCE_NONE}) or unblocked
+1 −0
Original line number Original line Diff line number Diff line
@@ -510,6 +510,7 @@
    <protected-broadcast android:name="android.os.action.ACTION_EFFECTS_SUPPRESSOR_CHANGED" />
    <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_BLOCK_STATE_CHANGED" />
    <protected-broadcast android:name="android.app.action.NOTIFICATION_CHANNEL_GROUP_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.GET_APP_GRANTED_URI_PERMISSIONS" />
    <protected-broadcast android:name="android.permission.CLEAR_APP_GRANTED_URI_PERMISSIONS" />
    <protected-broadcast android:name="android.permission.CLEAR_APP_GRANTED_URI_PERMISSIONS" />
+13 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.server.notification;
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_BLOCK_STATE_CHANGED;
import static android.app.NotificationManager.ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED;
import static android.app.NotificationManager.ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED;
import static android.app.NotificationManager.IMPORTANCE_LOW;
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,
                cancelAllNotificationsInt(MY_UID, MY_PID, pkg, null, 0, 0, true,
                        UserHandle.getUserId(uid), REASON_PACKAGE_BANNED, null);
                        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();
            savePolicyFile();
        }
        }


+28 −0
Original line number Original line Diff line number Diff line
@@ -1178,6 +1178,34 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                anyString(), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean());
                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
    @Test
    public void testUpdateChannelNotifyCreatorBlock() throws Exception {
    public void testUpdateChannelNotifyCreatorBlock() throws Exception {
        mService.setRankingHelper(mRankingHelper);
        mService.setRankingHelper(mRankingHelper);