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

Commit 5a950e86 authored by Matías Hernández's avatar Matías Hernández
Browse files

Create broadcast to be used by the (restored) DND slice

(And which could potentially replace observing the ZEN_MODE_CONFIG_ETAG setting).

Bug: 406238205
Test: atest NotificationManagerServiceTest
Flag: android.app.modes_ui_dnd_slice
Change-Id: Id805bb4b84c6f8d61f66610736555a232e9ca3b5
parent 1caf584c
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -287,6 +287,21 @@ public class NotificationManager {
    public static final String ACTION_AUTOMATIC_ZEN_RULE_STATUS_CHANGED =
            "android.app.action.AUTOMATIC_ZEN_RULE_STATUS_CHANGED";

    /**
     * Intent that is broadcast when the Zen configuration has changed. This includes any
     * modification to a {@code ZenRule}, including creation, modification, deletion, or activation
     * status change of {@link AutomaticZenRule} instances or the manual DND rule.
     *
     * <p>This broadcast is only sent to packages holding the
     * {@link android.Manifest.permission#MANAGE_NOTIFICATIONS} permission (which is only allowed
     * for system processes).
     *
     * @hide
     */
    @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_ZEN_CONFIGURATION_CHANGED_INTERNAL =
            "android.app.action.ZEN_CONFIGURATION_CHANGED_INTERNAL";

    /**
     * Integer extra for {@link #ACTION_AUTOMATIC_ZEN_RULE_STATUS_CHANGED} containing the state of
     * the {@link AutomaticZenRule}.
+10 −0
Original line number Diff line number Diff line
@@ -82,6 +82,16 @@ flag {
  }
}

flag {
  name: "modes_ui_dnd_slice"
  namespace: "systemui"
  description: "Restores a (tweaked) DND slice in Settings; dependent on modes_ui"
  bug: "406238205"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "modes_cleanup_implicit"
  namespace: "systemui"
+2 −1
Original line number Diff line number Diff line
@@ -67,7 +67,8 @@ public class ZenMode implements Parcelable {

    private static final String TAG = "ZenMode";

    static final String MANUAL_DND_MODE_ID = ZenModeConfig.MANUAL_RULE_ID;
    public static final String MANUAL_DND_MODE_ID = ZenModeConfig.MANUAL_RULE_ID;

    static final String TEMP_NEW_MODE_ID = "temp_new_mode";

    private static final Comparator<Integer> PRIORITIZED_TYPE_COMPARATOR = new Comparator<>() {
+7 −0
Original line number Diff line number Diff line
@@ -2733,6 +2733,13 @@ public class NotificationManagerService extends SystemService {
            @Override
            public void onConfigChanged() {
                handleSavePolicyFile();
                if (android.app.Flags.modesUiDndSlice()) {
                    getContext().sendBroadcastAsUser(
                            new Intent(
                                    NotificationManager.ACTION_ZEN_CONFIGURATION_CHANGED_INTERNAL)
                                    .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT),
                            UserHandle.ALL, android.Manifest.permission.MANAGE_NOTIFICATIONS);
                }
            }
            @Override
+12 −0
Original line number Diff line number Diff line
@@ -11401,6 +11401,18 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        verify(mContext).sendBroadcastAsUser(eqIntent(expected), eq(UserHandle.of(mUserId)));
    }
    @Test
    @EnableFlags(android.app.Flags.FLAG_MODES_UI_DND_SLICE)
    public void onConfigChanged_sendsInternalZenChangedBroadcast() throws Exception {
        mService.mZenModeHelper.getCallbacks().forEach(c -> c.onConfigChanged());
        Intent expected = new Intent(NotificationManager.ACTION_ZEN_CONFIGURATION_CHANGED_INTERNAL)
                .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
        verify(mContext).sendBroadcastAsUser(eqIntent(expected), eq(UserHandle.ALL),
                eq(android.Manifest.permission.MANAGE_NOTIFICATIONS));
    }
    private static Intent isIntentWithAction(String wantedAction) {
        return argThat(
                intent -> intent != null && wantedAction.equals(intent.getAction())