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

Commit 91be20a2 authored by Matías Hernández's avatar Matías Hernández
Browse files

Reintroduce the "until XX:XX" summary for Do Not Disturb with countdown

Bug: 357889514
Test: manual, unfortunately the ZenModeConfig methods don't allow supplying a TimeSource, Clock or anything similar that would allow a reliable test :(
Flag: android.app.modes_ui
Change-Id: I3ca4a0c6f3671bccba308471716ab8aa98bcbd83
parent c639af8e
Loading
Loading
Loading
Loading
+11 −12
Original line number Diff line number Diff line
@@ -40,18 +40,17 @@ public class TestModeBuilder {
    private ZenModeConfig.ZenRule mConfigZenRule;

    public static final ZenMode EXAMPLE = new TestModeBuilder().build();
    public static final ZenMode MANUAL_DND_ACTIVE = ZenMode.manualDndMode(
            new AutomaticZenRule.Builder("Do Not Disturb", Uri.parse("rule://dnd"))
                    .setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY)
                    .setZenPolicy(new ZenPolicy.Builder().disallowAllSounds().build())
                    .build(),
            /* isActive= */ true);
    public static final ZenMode MANUAL_DND_INACTIVE = ZenMode.manualDndMode(
            new AutomaticZenRule.Builder("Do Not Disturb", Uri.parse("rule://dnd"))
    public static final ZenMode MANUAL_DND_ACTIVE = manualDnd(Uri.EMPTY, true);
    public static final ZenMode MANUAL_DND_INACTIVE = manualDnd(Uri.EMPTY, false);

    public static ZenMode manualDnd(Uri conditionId, boolean isActive) {
        return ZenMode.manualDndMode(
                new AutomaticZenRule.Builder("Do Not Disturb", conditionId)
                        .setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY)
                        .setZenPolicy(new ZenPolicy.Builder().disallowAllSounds().build())
                        .build(),
            /* isActive= */ false);
                isActive);
    }

    public TestModeBuilder() {
        // Reasonable defaults
+27 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.app.NotificationManager.INTERRUPTION_FILTER_ALL;
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
import static android.service.notification.SystemZenRules.getTriggerDescriptionForScheduleEvent;
import static android.service.notification.SystemZenRules.getTriggerDescriptionForScheduleTime;
import static android.service.notification.ZenModeConfig.tryParseCountdownConditionId;
import static android.service.notification.ZenModeConfig.tryParseEventConditionId;
import static android.service.notification.ZenModeConfig.tryParseScheduleConditionId;

@@ -188,11 +189,37 @@ public class ZenMode implements Parcelable {
        return mRule.getType();
    }

    /** Returns the trigger description of the mode. */
    @Nullable
    public String getTriggerDescription() {
        return mRule.getTriggerDescription();
    }

    /**
     * Returns a "dynamic" trigger description. For some modes (such as manual Do Not Disturb)
     * when activated, we know when (and if) the mode is expected to end on its own; this dynamic
     * description reflects that. In other cases, returns {@link #getTriggerDescription}.
     */
    @Nullable
    public String getDynamicDescription(Context context) {
        if (isManualDnd() && isActive()) {
            long countdownEndTime = tryParseCountdownConditionId(mRule.getConditionId());
            if (countdownEndTime > 0) {
                CharSequence formattedTime = ZenModeConfig.getFormattedTime(context,
                        countdownEndTime, ZenModeConfig.isToday(countdownEndTime),
                        context.getUserId());
                return context.getString(com.android.internal.R.string.zen_mode_until,
                        formattedTime);
            }
        }
        // TODO: b/333527800 - For TYPE_SCHEDULE_TIME rules we could do the same; however
        //   according to the snoozing discussions the mode may or may not end at the scheduled
        //   time if manually activated. When we resolve that point, we could calculate end time
        //   for these modes as well.

        return getTriggerDescription();
    }

    @NonNull
    public ListenableFuture<Drawable> getIcon(@NonNull Context context,
            @NonNull ZenIconLoader iconLoader) {
+1 −2
Original line number Diff line number Diff line
@@ -116,7 +116,6 @@ public class ZenModesBackend {

    private ZenMode getManualDndMode(ZenModeConfig config) {
        ZenModeConfig.ZenRule manualRule = config.manualRule;
        // TODO: b/333682392 - Replace with final strings for name & trigger description
        AutomaticZenRule manualDndRule = new AutomaticZenRule.Builder(
                mContext.getString(R.string.zen_mode_settings_title), manualRule.conditionId)
                .setType(manualRule.type)
@@ -127,7 +126,7 @@ public class ZenModesBackend {
                .setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY)
                .build();

        return ZenMode.manualDndMode(manualDndRule, config != null && config.isManualActive());
        return ZenMode.manualDndMode(manualDndRule, config.isManualActive());
    }

    public void updateMode(ZenMode mode) {
+1 −1
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ constructor(

        val on = context.resources.getString(R.string.zen_mode_on)
        val off = context.resources.getString(R.string.zen_mode_off)
        return mode.rule.triggerDescription ?: if (mode.isActive) on else off
        return mode.getDynamicDescription(context) ?: if (mode.isActive) on else off
    }

    private fun makeZenModeDialog(): Dialog {