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

Commit c171da79 authored by Matías Hernández's avatar Matías Hernández Committed by Android (Google) Code Review
Browse files

Merge "Add ZenMode.isCustomManual()" into main

parents 2ce4cf27 5c720acf
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settingslib.notification.modes;

import static android.app.AutomaticZenRule.TYPE_SCHEDULE_CALENDAR;
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_TIME;
import static android.app.NotificationManager.INTERRUPTION_FILTER_ALL;
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
import static android.service.notification.SystemZenRules.getTriggerDescriptionForScheduleEvent;
@@ -298,6 +300,17 @@ public class ZenMode implements Parcelable {
        return mIsManualDnd;
    }

    /**
     * A <em>custom manual</em> mode is a mode created by the user, and not yet assigned an
     * automatic trigger condition (neither time schedule nor a calendar).
     */
    public boolean isCustomManual() {
        return isSystemOwned()
                && getType() != TYPE_SCHEDULE_TIME
                && getType() != TYPE_SCHEDULE_CALENDAR
                && !isManualDnd();
    }

    public boolean isEnabled() {
        return mRule.isEnabled();
    }
+56 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.app.AutomaticZenRule;
import android.net.Uri;
import android.os.Parcel;
import android.service.notification.Condition;
import android.service.notification.SystemZenRules;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenPolicy;

@@ -108,6 +109,61 @@ public class ZenModeTest {
        assertThat(mode.getStatus()).isEqualTo(ZenMode.Status.DISABLED_BY_OTHER);
    }

    @Test
    public void isCustomManual_customManualMode() {
        AutomaticZenRule rule = new AutomaticZenRule.Builder("Mode", Uri.parse("x"))
                .setPackage(SystemZenRules.PACKAGE_ANDROID)
                .setType(AutomaticZenRule.TYPE_OTHER)
                .build();
        ZenMode mode = new ZenMode("id", rule, zenConfigRuleFor(rule, false));

        assertThat(mode.isCustomManual()).isTrue();
    }

    @Test
    public void isCustomManual_scheduleTime_false() {
        AutomaticZenRule rule = new AutomaticZenRule.Builder("Mode", Uri.parse("x"))
                .setPackage(SystemZenRules.PACKAGE_ANDROID)
                .setType(AutomaticZenRule.TYPE_SCHEDULE_TIME)
                .build();
        ZenMode mode = new ZenMode("id", rule, zenConfigRuleFor(rule, false));

        assertThat(mode.isCustomManual()).isFalse();
    }

    @Test
    public void isCustomManual_scheduleCalendar_false() {
        AutomaticZenRule rule = new AutomaticZenRule.Builder("Mode", Uri.parse("x"))
                .setPackage(SystemZenRules.PACKAGE_ANDROID)
                .setType(AutomaticZenRule.TYPE_SCHEDULE_CALENDAR)
                .build();
        ZenMode mode = new ZenMode("id", rule, zenConfigRuleFor(rule, false));

        assertThat(mode.isCustomManual()).isFalse();
    }

    @Test
    public void isCustomManual_appProvidedMode_false() {
        AutomaticZenRule rule = new AutomaticZenRule.Builder("Mode", Uri.parse("x"))
                .setPackage("com.some.package")
                .setType(AutomaticZenRule.TYPE_OTHER)
                .build();
        ZenMode mode = new ZenMode("id", rule, zenConfigRuleFor(rule, false));

        assertThat(mode.isCustomManual()).isFalse();
    }

    @Test
    public void isCustomManual_manualDnd_false() {
        AutomaticZenRule dndRule = new AutomaticZenRule.Builder("Mode", Uri.parse("x"))
                .setPackage(SystemZenRules.PACKAGE_ANDROID)
                .setType(AutomaticZenRule.TYPE_OTHER)
                .build();
        ZenMode mode = ZenMode.manualDndMode(dndRule, false);

        assertThat(mode.isCustomManual()).isFalse();
    }

    @Test
    public void getPolicy_interruptionFilterPriority_returnsZenPolicy() {
        AutomaticZenRule azr = new AutomaticZenRule.Builder("Rule", Uri.EMPTY)