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

Commit f8c2e115 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Allow system modes to be manually invoked" into main

parents ec30de26 97bdf07d
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -49,9 +49,14 @@ public final class SystemZenRules {
    @FlaggedApi(Flags.FLAG_MODES_API)
    public static void maybeUpgradeRules(Context context, ZenModeConfig config) {
        for (ZenRule rule : config.automaticRules.values()) {
            if (isSystemOwnedRule(rule) && rule.type == AutomaticZenRule.TYPE_UNKNOWN) {
            if (isSystemOwnedRule(rule)) {
                if (rule.type == AutomaticZenRule.TYPE_UNKNOWN) {
                    upgradeSystemProviderRule(context, rule);
                }
                if (Flags.modesUi()) {
                    rule.allowManualInvocation = true;
                }
            }
        }
    }

+13 −1
Original line number Diff line number Diff line
@@ -16,13 +16,17 @@

package com.android.server.notification;

import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT;
import static android.service.notification.SystemZenRules.getTriggerDescriptionForScheduleTime;

import static com.google.common.truth.Truth.assertThat;

import android.app.AutomaticZenRule;
import android.app.Flags;
import android.content.res.Configuration;
import android.os.LocaleList;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.service.notification.SystemZenRules;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenModeConfig.EventInfo;
@@ -33,6 +37,7 @@ import com.android.internal.R;
import com.android.server.UiServiceTestCase;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import java.util.Calendar;
@@ -40,6 +45,8 @@ import java.util.Locale;

public class SystemZenRulesTest extends UiServiceTestCase {

    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(DEVICE_DEFAULT);
    private static final ScheduleInfo SCHEDULE_INFO;
    private static final EventInfo EVENT_INFO;

@@ -65,6 +72,7 @@ public class SystemZenRulesTest extends UiServiceTestCase {
    }

    @Test
    @EnableFlags(Flags.FLAG_MODES_UI)
    public void maybeUpgradeRules_oldSystemRules_upgraded() {
        ZenModeConfig config = new ZenModeConfig();
        ZenRule timeRule = new ZenRule();
@@ -82,9 +90,12 @@ public class SystemZenRulesTest extends UiServiceTestCase {
        assertThat(timeRule.triggerDescription).isNotEmpty();
        assertThat(calendarRule.type).isEqualTo(AutomaticZenRule.TYPE_SCHEDULE_CALENDAR);
        assertThat(timeRule.triggerDescription).isNotEmpty();
        assertThat(timeRule.allowManualInvocation).isTrue();
        assertThat(calendarRule.allowManualInvocation).isTrue();
    }

    @Test
    @EnableFlags(Flags.FLAG_MODES_UI)
    public void maybeUpgradeRules_newSystemRules_untouched() {
        ZenModeConfig config = new ZenModeConfig();
        ZenRule timeRule = new ZenRule();
@@ -96,7 +107,8 @@ public class SystemZenRulesTest extends UiServiceTestCase {

        SystemZenRules.maybeUpgradeRules(mContext, config);

        assertThat(timeRule).isEqualTo(original);
        assertThat(timeRule.triggerDescription).isEqualTo(original.triggerDescription);
        assertThat(timeRule.allowManualInvocation).isTrue();
    }

    @Test