Style priority modes items in aggregator
* Different color if active. * Trigger description / "ON" / "Paused" / "Tap to set up" depending on enabled and active status (strings may be revised later). This CL also adds a helper class to create ZenModes, reducing boilerplate in unit tests. Bug: 346575288 Test: atest com.android.settings.notification.modes Flag: android.app.modes_ui Change-Id: Ia0e16b8be5284d13bed4366cbee0f92748bf2f85
This commit is contained in:
@@ -7930,16 +7930,28 @@
|
||||
<!-- Zen Modes: Option to add an automatic schedule for a mode. [CHAR_LIMIT=40] -->
|
||||
<string name="zen_mode_select_schedule">Select activation type</string>
|
||||
|
||||
<!-- Zen Modes: Option to choose a time-based schedule for a mode. [CHAR_LIMIT=40] -->
|
||||
<!-- Priority Modes: Option to choose a time-based schedule for a mode. [CHAR_LIMIT=40] -->
|
||||
<string name="zen_mode_select_schedule_time">Time</string>
|
||||
<!-- Zen Modes: Example text for the option to choose a time-based schedule for a mode. [CHAR_LIMIT=60] -->
|
||||
<!-- Priority Modes: Example text for the option to choose a time-based schedule for a mode. [CHAR_LIMIT=60] -->
|
||||
<string name="zen_mode_select_schedule_time_example">Ex. \"9:30 – 5:00 PM\"</string>
|
||||
|
||||
<!-- Zen Modes: Option to choose a calendar-events-based schedule for a mode. [CHAR_LIMIT=40] -->
|
||||
<!-- Priority Modes: Option to choose a calendar-events-based schedule for a mode. [CHAR_LIMIT=40] -->
|
||||
<string name="zen_mode_select_schedule_calendar">Calendar</string>
|
||||
<!-- Zen Modes: Example text for the option to choose a calendar-events-based schedule for a mode. [CHAR_LIMIT=60] -->
|
||||
<!-- Priority Modes: Example text for the option to choose a calendar-events-based schedule for a mode. [CHAR_LIMIT=60] -->
|
||||
<string name="zen_mode_select_schedule_calendar_example">Ex. \"Personal calendar\"</string>
|
||||
|
||||
<!-- Priority Modes: Short text that indicates that a mode is currently on (active). [CHAR_LIMIT=10] -->
|
||||
<string name="zen_mode_active_text">ON</string>
|
||||
|
||||
<!-- Priority Modes: Format string for the "current state + trigger description summary for rules in the list. [CHAR_LIMIT=10] -->
|
||||
<string name="zen_mode_format_status_and_trigger" translatable="false"><xliff:g id="current_status" example="ON">%1$s</xliff:g> • <xliff:g id="trigger_description" example="Mon-Fri, 23:00-7:00">%2$s</xliff:g></string>
|
||||
|
||||
<!-- Priority Modes: Call to action for a mode that is disabled and needs to be configured. [CHAR_LIMIT=40] -->
|
||||
<string name="zen_mode_disabled_tap_to_set_up">Tap to set up</string>
|
||||
|
||||
<!-- Priority Modes: Indicates that a mode is disabled by the user. [CHAR_LIMIT=40] -->
|
||||
<string name="zen_mode_disabled_by_user">Paused</string>
|
||||
|
||||
<!-- Subtitle for the Do not Disturb slice. [CHAR LIMIT=50]-->
|
||||
<string name="zen_mode_slice_subtitle">Limit interruptions</string>
|
||||
|
||||
|
@@ -24,6 +24,7 @@ import android.graphics.drawable.LayerDrawable;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.graphics.drawable.shapes.OvalShape;
|
||||
|
||||
import androidx.annotation.AttrRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -32,10 +33,18 @@ import com.android.settingslib.Utils;
|
||||
|
||||
class IconUtil {
|
||||
|
||||
static Drawable applyTint(@NonNull Context context, @NonNull Drawable icon) {
|
||||
static Drawable applyNormalTint(@NonNull Context context, @NonNull Drawable icon) {
|
||||
return applyTint(context, icon, android.R.attr.colorControlNormal);
|
||||
}
|
||||
|
||||
static Drawable applyAccentTint(@NonNull Context context, @NonNull Drawable icon) {
|
||||
return applyTint(context, icon, android.R.attr.colorAccent);
|
||||
}
|
||||
|
||||
private static Drawable applyTint(@NonNull Context context, @NonNull Drawable icon,
|
||||
@AttrRes int colorAttr) {
|
||||
icon = icon.mutate();
|
||||
icon.setTintList(
|
||||
Utils.getColorAttr(context, android.R.attr.colorControlNormal));
|
||||
icon.setTintList(Utils.getColorAttr(context, colorAttr));
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,7 @@ import com.android.settingslib.notification.modes.ZenMode;
|
||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
public class ZenModeButtonPreferenceController extends AbstractZenModePreferenceController {
|
||||
class ZenModeButtonPreferenceController extends AbstractZenModePreferenceController {
|
||||
|
||||
private Button mZenButton;
|
||||
|
||||
|
@@ -26,7 +26,7 @@ import androidx.preference.TwoStatePreference;
|
||||
import com.android.settingslib.notification.modes.ZenMode;
|
||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||
|
||||
public class ZenModeDisplayEffectPreferenceController extends AbstractZenModePreferenceController
|
||||
class ZenModeDisplayEffectPreferenceController extends AbstractZenModePreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
public ZenModeDisplayEffectPreferenceController(Context context, String key,
|
||||
@@ -37,10 +37,7 @@ public class ZenModeDisplayEffectPreferenceController extends AbstractZenModePre
|
||||
@Override
|
||||
public void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
||||
TwoStatePreference pref = (TwoStatePreference) preference;
|
||||
ZenDeviceEffects effects = zenMode.getRule().getDeviceEffects();
|
||||
if (effects == null) {
|
||||
pref.setChecked(false);
|
||||
} else {
|
||||
ZenDeviceEffects effects = zenMode.getDeviceEffects();
|
||||
switch (getPreferenceKey()) {
|
||||
case "effect_greyscale":
|
||||
pref.setChecked(effects.shouldDisplayGrayscale());
|
||||
@@ -56,7 +53,6 @@ public class ZenModeDisplayEffectPreferenceController extends AbstractZenModePre
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
|
||||
|
@@ -66,7 +66,7 @@ class ZenModeHeaderController extends AbstractZenModePreferenceController {
|
||||
|
||||
FutureUtil.whenDone(
|
||||
zenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
||||
icon -> mHeaderController.setIcon(IconUtil.applyTint(mContext, icon))
|
||||
icon -> mHeaderController.setIcon(IconUtil.applyNormalTint(mContext, icon))
|
||||
.done(/* rebindActions= */ false),
|
||||
mContext.getMainExecutor());
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ class ZenModeIconPickerIconPreferenceController extends AbstractZenModePreferenc
|
||||
|
||||
FutureUtil.whenDone(
|
||||
zenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
||||
icon -> mHeaderController.setIcon(IconUtil.applyTint(mContext, icon))
|
||||
icon -> mHeaderController.setIcon(IconUtil.applyNormalTint(mContext, icon))
|
||||
.done(/* rebindActions= */ false),
|
||||
mContext.getMainExecutor());
|
||||
}
|
||||
|
@@ -16,18 +16,31 @@
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.notification.modes.ZenIconLoader;
|
||||
import com.android.settingslib.notification.modes.ZenMode;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
/**
|
||||
* Preference representing a single mode item on the modes aggregator page. Clicking on this
|
||||
* preference leads to an individual mode's configuration page.
|
||||
*/
|
||||
class ZenModesListItemPreference extends RestrictedPreference {
|
||||
final Context mContext;
|
||||
ZenMode mZenMode;
|
||||
|
||||
private final Context mContext;
|
||||
private ZenMode mZenMode;
|
||||
|
||||
private TextView mTitleView;
|
||||
private TextView mSummaryView;
|
||||
|
||||
ZenModesListItemPreference(Context context, ZenMode zenMode) {
|
||||
super(context);
|
||||
@@ -36,6 +49,18 @@ class ZenModesListItemPreference extends RestrictedPreference {
|
||||
setKey(zenMode.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
if (holder.findViewById(android.R.id.title) instanceof TextView titleView) {
|
||||
mTitleView = titleView;
|
||||
}
|
||||
if (holder.findViewById(android.R.id.summary) instanceof TextView summaryView) {
|
||||
mSummaryView = summaryView;
|
||||
}
|
||||
updateTextColor(mZenMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick() {
|
||||
ZenSubSettingLauncher.forMode(mContext, mZenMode.getId()).launch();
|
||||
@@ -43,13 +68,47 @@ class ZenModesListItemPreference extends RestrictedPreference {
|
||||
|
||||
public void setZenMode(ZenMode zenMode) {
|
||||
mZenMode = zenMode;
|
||||
setTitle(mZenMode.getRule().getName());
|
||||
setSummary(mZenMode.getRule().getTriggerDescription());
|
||||
setIconSize(ICON_SIZE_SMALL);
|
||||
setTitle(mZenMode.getName());
|
||||
CharSequence statusText = switch (mZenMode.getStatus()) {
|
||||
case ENABLED_AND_ACTIVE ->
|
||||
Strings.isNullOrEmpty(mZenMode.getTriggerDescription())
|
||||
? mContext.getString(R.string.zen_mode_active_text)
|
||||
: mContext.getString(
|
||||
R.string.zen_mode_format_status_and_trigger,
|
||||
mContext.getString(R.string.zen_mode_active_text),
|
||||
mZenMode.getRule().getTriggerDescription());
|
||||
case ENABLED -> mZenMode.getRule().getTriggerDescription();
|
||||
case DISABLED_BY_USER -> mContext.getString(R.string.zen_mode_disabled_by_user);
|
||||
case DISABLED_BY_OTHER -> mContext.getString(R.string.zen_mode_disabled_tap_to_set_up);
|
||||
};
|
||||
setSummary(statusText);
|
||||
|
||||
setIconSize(ICON_SIZE_SMALL);
|
||||
FutureUtil.whenDone(
|
||||
mZenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
||||
icon -> setIcon(IconUtil.applyTint(mContext, icon)),
|
||||
icon -> setIcon(
|
||||
zenMode.isActive()
|
||||
? IconUtil.applyAccentTint(mContext, icon)
|
||||
: IconUtil.applyNormalTint(mContext, icon)),
|
||||
mContext.getMainExecutor());
|
||||
|
||||
updateTextColor(zenMode);
|
||||
}
|
||||
|
||||
private void updateTextColor(@Nullable ZenMode zenMode) {
|
||||
boolean isActive = zenMode != null && zenMode.isActive();
|
||||
if (mTitleView != null) {
|
||||
mTitleView.setTextColor(Utils.getColorAttr(mContext,
|
||||
isActive ? android.R.attr.colorAccent : android.R.attr.textColorPrimary));
|
||||
}
|
||||
if (mSummaryView != null) {
|
||||
mSummaryView.setTextColor(Utils.getColorAttr(mContext,
|
||||
isActive ? android.R.attr.colorAccent : android.R.attr.textColorSecondary));
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
ZenMode getZenMode() {
|
||||
return mZenMode;
|
||||
}
|
||||
}
|
||||
|
@@ -25,10 +25,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
@@ -71,12 +69,9 @@ public final class InterruptionFilterPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_all() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_ALL)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
mController.updateZenMode(preference, zenMode);
|
||||
|
||||
verify(preference).setChecked(false);
|
||||
@@ -85,12 +80,9 @@ public final class InterruptionFilterPreferenceControllerTest {
|
||||
@Test
|
||||
public void testOnPreferenceChange_fromAll() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_ALL)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(false).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mController.updateZenMode(preference, zenMode);
|
||||
|
||||
@@ -107,12 +99,10 @@ public final class InterruptionFilterPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_priority() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
mController.updateZenMode(preference, zenMode);
|
||||
|
||||
verify(preference).setChecked(true);
|
||||
@@ -121,12 +111,10 @@ public final class InterruptionFilterPreferenceControllerTest {
|
||||
@Test
|
||||
public void testOnPreferenceChange_fromPriority() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(false).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mController.updateZenMode(preference, zenMode);
|
||||
|
||||
|
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.NotificationManager;
|
||||
import android.net.Uri;
|
||||
import android.service.notification.Condition;
|
||||
import android.service.notification.ZenDeviceEffects;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settingslib.notification.modes.ZenMode;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
class TestModeBuilder {
|
||||
|
||||
private String mId;
|
||||
private AutomaticZenRule mRule;
|
||||
private ZenModeConfig.ZenRule mConfigZenRule;
|
||||
|
||||
public static final ZenMode EXAMPLE = new TestModeBuilder().build();
|
||||
|
||||
TestModeBuilder() {
|
||||
// Reasonable defaults
|
||||
int id = new Random().nextInt(1000);
|
||||
mId = "rule_" + id;
|
||||
mRule = new AutomaticZenRule.Builder("Test Rule #" + id, Uri.parse("rule://" + id))
|
||||
.setPackage("some_package")
|
||||
.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().disallowAllSounds().build())
|
||||
.build();
|
||||
mConfigZenRule = new ZenModeConfig.ZenRule();
|
||||
mConfigZenRule.enabled = true;
|
||||
mConfigZenRule.pkg = "some_package";
|
||||
}
|
||||
|
||||
TestModeBuilder setId(String id) {
|
||||
mId = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
TestModeBuilder setAzr(AutomaticZenRule rule) {
|
||||
mRule = rule;
|
||||
mConfigZenRule.pkg = rule.getPackageName();
|
||||
mConfigZenRule.conditionId = rule.getConditionId();
|
||||
mConfigZenRule.enabled = rule.isEnabled();
|
||||
return this;
|
||||
}
|
||||
|
||||
TestModeBuilder setConfigZenRule(ZenModeConfig.ZenRule configZenRule) {
|
||||
mConfigZenRule = configZenRule;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestModeBuilder setName(String name) {
|
||||
mRule.setName(name);
|
||||
mConfigZenRule.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestModeBuilder setPackage(String pkg) {
|
||||
mRule.setPackageName(pkg);
|
||||
mConfigZenRule.pkg = pkg;
|
||||
return this;
|
||||
}
|
||||
|
||||
TestModeBuilder setConditionId(Uri conditionId) {
|
||||
mRule.setConditionId(conditionId);
|
||||
mConfigZenRule.conditionId = conditionId;
|
||||
return this;
|
||||
}
|
||||
|
||||
TestModeBuilder setType(@AutomaticZenRule.Type int type) {
|
||||
mRule.setType(type);
|
||||
mConfigZenRule.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
TestModeBuilder setInterruptionFilter(
|
||||
@NotificationManager.InterruptionFilter int interruptionFilter) {
|
||||
mRule.setInterruptionFilter(interruptionFilter);
|
||||
mConfigZenRule.zenMode = NotificationManager.zenModeFromInterruptionFilter(
|
||||
interruptionFilter, NotificationManager.INTERRUPTION_FILTER_PRIORITY);
|
||||
return this;
|
||||
}
|
||||
|
||||
TestModeBuilder setZenPolicy(@Nullable ZenPolicy policy) {
|
||||
mRule.setZenPolicy(policy);
|
||||
mConfigZenRule.zenPolicy = policy;
|
||||
return this;
|
||||
}
|
||||
|
||||
TestModeBuilder setDeviceEffects(@Nullable ZenDeviceEffects deviceEffects) {
|
||||
mRule.setDeviceEffects(deviceEffects);
|
||||
mConfigZenRule.zenDeviceEffects = deviceEffects;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestModeBuilder setEnabled(boolean enabled) {
|
||||
mRule.setEnabled(enabled);
|
||||
mConfigZenRule.enabled = enabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
TestModeBuilder setManualInvocationAllowed(boolean allowed) {
|
||||
mRule.setManualInvocationAllowed(allowed);
|
||||
mConfigZenRule.allowManualInvocation = allowed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestModeBuilder setTriggerDescription(@Nullable String triggerDescription) {
|
||||
mRule.setTriggerDescription(triggerDescription);
|
||||
mConfigZenRule.triggerDescription = triggerDescription;
|
||||
return this;
|
||||
}
|
||||
|
||||
TestModeBuilder setActive(boolean active) {
|
||||
if (active) {
|
||||
mConfigZenRule.enabled = true;
|
||||
mConfigZenRule.condition = new Condition(mRule.getConditionId(), "...",
|
||||
Condition.STATE_TRUE);
|
||||
} else {
|
||||
mConfigZenRule.condition = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
ZenMode build() {
|
||||
return new ZenMode(mId, mRule, mConfigZenRule);
|
||||
}
|
||||
}
|
@@ -28,12 +28,10 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
@@ -103,14 +101,13 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
}
|
||||
|
||||
private ZenMode createPriorityChannelsZenMode() {
|
||||
return new ZenMode("id", new AutomaticZenRule.Builder("Bedtime",
|
||||
Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
return new TestModeBuilder()
|
||||
.setId("id")
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -26,10 +26,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
@@ -107,13 +105,12 @@ public final class ZenModeAppsPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_None() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mNoneController.updateZenMode(preference, zenMode);
|
||||
|
||||
verify(preference).setChecked(true);
|
||||
@@ -122,13 +119,12 @@ public final class ZenModeAppsPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_None_Unchecked() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mNoneController.updateZenMode(preference, zenMode);
|
||||
|
||||
verify(preference).setChecked(false);
|
||||
@@ -137,13 +133,12 @@ public final class ZenModeAppsPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_Priority() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mPriorityController.updateZenMode(preference, zenMode);
|
||||
|
||||
verify(preference).setChecked(true);
|
||||
@@ -152,13 +147,12 @@ public final class ZenModeAppsPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_Priority_Unchecked() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mPriorityController.updateZenMode(preference, zenMode);
|
||||
|
||||
verify(preference).setChecked(false);
|
||||
@@ -166,21 +160,19 @@ public final class ZenModeAppsPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testPreferenceClick_passesCorrectCheckedState_None() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mNoneController.updateZenMode(mNonePref, zenMode);
|
||||
mPriorityController.updateZenMode(mPriorityPref, zenMode);
|
||||
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked());
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||
.isChecked()).isFalse();
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked()).isTrue();
|
||||
|
||||
// Click on NONE
|
||||
mPrefCategory.findPreference(KEY_NONE).performClick();
|
||||
@@ -192,30 +184,31 @@ public final class ZenModeAppsPreferenceControllerTest {
|
||||
// See AbstractZenModePreferenceController.
|
||||
assertThat(captor.getValue().getRule().getInterruptionFilter())
|
||||
.isEqualTo(INTERRUPTION_FILTER_PRIORITY);
|
||||
// NONE is now checked; others are unchecked.
|
||||
|
||||
// After screen is refreshed, NONE is now checked; others are unchecked.
|
||||
mNoneController.updateZenMode(mNonePref, captor.getValue());
|
||||
mPriorityController.updateZenMode(mPriorityPref, captor.getValue());
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked());
|
||||
.isChecked()).isTrue();
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreferenceClick_passesCorrectCheckedState_Priority() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mNoneController.updateZenMode(mNonePref, zenMode);
|
||||
mPriorityController.updateZenMode(mPriorityPref, zenMode);
|
||||
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked());
|
||||
.isChecked()).isTrue();
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked()).isFalse();
|
||||
|
||||
// Click on PRIORITY
|
||||
mPrefCategory.findPreference(KEY_PRIORITY).performClick();
|
||||
@@ -225,11 +218,13 @@ public final class ZenModeAppsPreferenceControllerTest {
|
||||
// Checks the policy value for PRIORITY is propagated to the backend.
|
||||
assertThat(captor.getValue().getRule().getInterruptionFilter())
|
||||
.isEqualTo(INTERRUPTION_FILTER_PRIORITY);
|
||||
// PRIORITY is now checked; others are unchecked.
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||
.isChecked());
|
||||
}
|
||||
|
||||
// After screen is refreshed, PRIORITY is now checked; others are unchecked.
|
||||
mNoneController.updateZenMode(mNonePref, captor.getValue());
|
||||
mPriorityController.updateZenMode(mPriorityPref, captor.getValue());
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked()).isTrue();
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||
.isChecked()).isFalse();
|
||||
}
|
||||
}
|
||||
|
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
@@ -25,13 +23,10 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.settingslib.notification.modes.ZenMode;
|
||||
@@ -73,43 +68,34 @@ public final class ZenModeButtonPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void isAvailable_notIfAppOptsOut() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setManualInvocationAllowed(false)
|
||||
.setEnabled(true)
|
||||
.build(), false);
|
||||
.build();
|
||||
mController.setZenMode(zenMode);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_notIfModeDisabled() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setManualInvocationAllowed(true)
|
||||
.setEnabled(false)
|
||||
.build(), false);
|
||||
.build();
|
||||
|
||||
mController.setZenMode(zenMode);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_appOptedIn_modeEnabled() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setManualInvocationAllowed(true)
|
||||
.setEnabled(true)
|
||||
.build(), false);
|
||||
.build();
|
||||
|
||||
mController.setZenMode(zenMode);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@@ -118,15 +104,13 @@ public final class ZenModeButtonPreferenceControllerTest {
|
||||
Button button = new Button(mContext);
|
||||
LayoutPreference pref = mock(LayoutPreference.class);
|
||||
when(pref.findViewById(anyInt())).thenReturn(button);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setManualInvocationAllowed(true)
|
||||
.setEnabled(true)
|
||||
.build(), true);
|
||||
.setActive(true)
|
||||
.build();
|
||||
|
||||
mController.updateZenMode(pref, zenMode);
|
||||
|
||||
assertThat(button.getText().toString()).contains("off");
|
||||
assertThat(button.hasOnClickListeners()).isTrue();
|
||||
}
|
||||
@@ -136,15 +120,13 @@ public final class ZenModeButtonPreferenceControllerTest {
|
||||
Button button = new Button(mContext);
|
||||
LayoutPreference pref = mock(LayoutPreference.class);
|
||||
when(pref.findViewById(anyInt())).thenReturn(button);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setManualInvocationAllowed(true)
|
||||
.setEnabled(true)
|
||||
.build(), false);
|
||||
.setActive(false)
|
||||
.build();
|
||||
|
||||
mController.updateZenMode(pref, zenMode);
|
||||
|
||||
assertThat(button.getText().toString()).contains("on");
|
||||
assertThat(button.hasOnClickListeners()).isTrue();
|
||||
}
|
||||
@@ -154,14 +136,11 @@ public final class ZenModeButtonPreferenceControllerTest {
|
||||
Button button = new Button(mContext);
|
||||
LayoutPreference pref = mock(LayoutPreference.class);
|
||||
when(pref.findViewById(anyInt())).thenReturn(button);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setManualInvocationAllowed(true)
|
||||
.setEnabled(true)
|
||||
.build(), true);
|
||||
.setActive(true)
|
||||
.build();
|
||||
|
||||
mController.updateZenMode(pref, zenMode);
|
||||
|
||||
button.callOnClick();
|
||||
@@ -173,14 +152,11 @@ public final class ZenModeButtonPreferenceControllerTest {
|
||||
Button button = new Button(mContext);
|
||||
LayoutPreference pref = mock(LayoutPreference.class);
|
||||
when(pref.findViewById(anyInt())).thenReturn(button);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setManualInvocationAllowed(true)
|
||||
.setEnabled(true)
|
||||
.build(), false);
|
||||
.setActive(false)
|
||||
.build();
|
||||
|
||||
mController.updateZenMode(pref, zenMode);
|
||||
|
||||
button.callOnClick();
|
||||
|
@@ -16,23 +16,17 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settingslib.notification.modes.ZenMode;
|
||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -70,13 +64,7 @@ public final class ZenModeCallsLinkPreferenceControllerTest {
|
||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||
public void testHasSummary() {
|
||||
Preference pref = mock(Preference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
.build(), true);
|
||||
mController.updateZenMode(pref, zenMode);
|
||||
mController.updateZenMode(pref, TestModeBuilder.EXAMPLE);
|
||||
verify(pref).setSummary(any());
|
||||
}
|
||||
}
|
@@ -16,21 +16,16 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenDeviceEffects;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
@@ -67,15 +62,11 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_grayscale() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||
.setShouldDisplayGrayscale(true)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeDisplayEffectPreferenceController controller =
|
||||
new ZenModeDisplayEffectPreferenceController(
|
||||
@@ -89,15 +80,11 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
||||
@Test
|
||||
public void testOnPreferenceChange_grayscale() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(false).build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||
.setShouldDisplayGrayscale(true)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeDisplayEffectPreferenceController controller =
|
||||
new ZenModeDisplayEffectPreferenceController(mContext, "effect_greyscale", mBackend);
|
||||
@@ -108,22 +95,18 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
||||
|
||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||
verify(mBackend).updateMode(captor.capture());
|
||||
assertThat(captor.getValue().getRule().getDeviceEffects().shouldDisplayGrayscale())
|
||||
assertThat(captor.getValue().getDeviceEffects().shouldDisplayGrayscale())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_aod() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowMedia(true).build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||
.setShouldSuppressAmbientDisplay(true)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeDisplayEffectPreferenceController controller =
|
||||
new ZenModeDisplayEffectPreferenceController(mContext, "effect_aod", mBackend);
|
||||
@@ -136,15 +119,11 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
||||
@Test
|
||||
public void testOnPreferenceChange_aod() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowMedia(false).build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||
.setShouldSuppressAmbientDisplay(true)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeDisplayEffectPreferenceController controller =
|
||||
new ZenModeDisplayEffectPreferenceController(mContext, "effect_aod", mBackend);
|
||||
@@ -155,22 +134,18 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
||||
|
||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||
verify(mBackend).updateMode(captor.capture());
|
||||
assertThat(captor.getValue().getRule().getDeviceEffects().shouldSuppressAmbientDisplay())
|
||||
assertThat(captor.getValue().getDeviceEffects().shouldSuppressAmbientDisplay())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_wallpaper() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowSystem(true).build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||
.setShouldDimWallpaper(true)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeDisplayEffectPreferenceController controller =
|
||||
new ZenModeDisplayEffectPreferenceController(
|
||||
@@ -184,15 +159,11 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
||||
@Test
|
||||
public void testOnPreferenceChange_wallpaper() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowSystem(false).build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||
.setShouldDimWallpaper(true)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeDisplayEffectPreferenceController controller =
|
||||
new ZenModeDisplayEffectPreferenceController(
|
||||
@@ -204,21 +175,17 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
||||
|
||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||
verify(mBackend).updateMode(captor.capture());
|
||||
assertThat(captor.getValue().getRule().getDeviceEffects().shouldDimWallpaper()).isFalse();
|
||||
assertThat(captor.getValue().getDeviceEffects().shouldDimWallpaper()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_darkTheme() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowReminders(true).build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||
.setShouldUseNightMode(true)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeDisplayEffectPreferenceController controller =
|
||||
new ZenModeDisplayEffectPreferenceController(mContext, "effect_dark_theme",
|
||||
@@ -232,15 +199,11 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
||||
@Test
|
||||
public void testOnPreferenceChange_darkTheme() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowReminders(false).build())
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||
.setShouldUseNightMode(true)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeDisplayEffectPreferenceController controller =
|
||||
new ZenModeDisplayEffectPreferenceController(mContext, "effect_dark_theme",
|
||||
@@ -252,6 +215,6 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
||||
|
||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||
verify(mBackend).updateMode(captor.capture());
|
||||
assertThat(captor.getValue().getRule().getDeviceEffects().shouldUseNightMode()).isFalse();
|
||||
assertThat(captor.getValue().getDeviceEffects().shouldUseNightMode()).isFalse();
|
||||
}
|
||||
}
|
@@ -16,23 +16,17 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settingslib.notification.modes.ZenMode;
|
||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -70,13 +64,7 @@ public final class ZenModeDisplayLinkPreferenceControllerTest {
|
||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||
public void testHasSummary() {
|
||||
Preference pref = mock(Preference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
.build(), true);
|
||||
mController.updateZenMode(pref, zenMode);
|
||||
mController.updateZenMode(pref, TestModeBuilder.EXAMPLE);
|
||||
verify(pref).setSummary(any());
|
||||
}
|
||||
}
|
@@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.content.Context;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
|
||||
@@ -68,10 +67,9 @@ public class ZenModeExitAtAlarmPreferenceControllerTest {
|
||||
scheduleInfo.endHour = 2;
|
||||
scheduleInfo.exitAtAlarm = false;
|
||||
|
||||
ZenMode mode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("name",
|
||||
ZenModeConfig.toScheduleConditionId(scheduleInfo)).build(),
|
||||
true); // is active
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setConditionId(ZenModeConfig.toScheduleConditionId(scheduleInfo))
|
||||
.build();
|
||||
|
||||
// need to call updateZenMode for the first call
|
||||
mPrefController.updateZenMode(preference, mode);
|
||||
@@ -97,10 +95,9 @@ public class ZenModeExitAtAlarmPreferenceControllerTest {
|
||||
scheduleInfo.endHour = 2;
|
||||
scheduleInfo.exitAtAlarm = true;
|
||||
|
||||
ZenMode mode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("name",
|
||||
ZenModeConfig.toScheduleConditionId(scheduleInfo)).build(),
|
||||
true); // is active
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setConditionId(ZenModeConfig.toScheduleConditionId(scheduleInfo))
|
||||
.build();
|
||||
mPrefController.updateZenMode(preference, mode);
|
||||
|
||||
// turn off exit at alarm
|
||||
|
@@ -23,9 +23,7 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -49,10 +47,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ZenModeIconPickerListPreferenceControllerTest {
|
||||
|
||||
private static final ZenMode ZEN_MODE = new ZenMode(
|
||||
"mode_id",
|
||||
new AutomaticZenRule.Builder("mode name", Uri.parse("mode")).build(),
|
||||
/* isActive= */ false);
|
||||
private static final ZenMode ZEN_MODE = TestModeBuilder.EXAMPLE;
|
||||
|
||||
private ZenModesBackend mBackend;
|
||||
private ZenModeIconPickerListPreferenceController mController;
|
||||
|
@@ -16,23 +16,17 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settingslib.notification.modes.ZenMode;
|
||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -70,13 +64,7 @@ public final class ZenModeMessagesLinkPreferenceControllerTest {
|
||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||
public void testHasSummary() {
|
||||
Preference pref = mock(Preference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
.build(), true);
|
||||
mController.updateZenMode(pref, zenMode);
|
||||
mController.updateZenMode(pref, TestModeBuilder.EXAMPLE);
|
||||
verify(pref).setSummary(any());
|
||||
}
|
||||
}
|
@@ -16,23 +16,17 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settingslib.notification.modes.ZenMode;
|
||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -70,13 +64,7 @@ public final class ZenModeNotifVisLinkPreferenceControllerTest {
|
||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||
public void testHasSummary() {
|
||||
Preference pref = mock(Preference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
.build(), true);
|
||||
mController.updateZenMode(pref, zenMode);
|
||||
mController.updateZenMode(pref, TestModeBuilder.EXAMPLE);
|
||||
verify(pref).setSummary(any());
|
||||
}
|
||||
}
|
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
import static android.service.notification.ZenPolicy.STATE_ALLOW;
|
||||
import static android.service.notification.ZenPolicy.STATE_DISALLOW;
|
||||
import static android.service.notification.ZenPolicy.VISUAL_EFFECT_LIGHTS;
|
||||
@@ -32,11 +31,9 @@ import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
@@ -99,15 +96,12 @@ public final class ZenModeNotifVisPreferenceControllerTest {
|
||||
@Test
|
||||
public void updateState_notChecked() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowAlarms(true)
|
||||
.showAllVisualEffects()
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mController.updateZenMode(preference, zenMode);
|
||||
|
||||
@@ -118,15 +112,12 @@ public final class ZenModeNotifVisPreferenceControllerTest {
|
||||
@Test
|
||||
public void updateState_checked() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowAlarms(true)
|
||||
.showVisualEffect(VISUAL_EFFECT_PEEK, false)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mController.updateZenMode(preference, zenMode);
|
||||
|
||||
@@ -141,16 +132,13 @@ public final class ZenModeNotifVisPreferenceControllerTest {
|
||||
"zen_effect_status", VISUAL_EFFECT_STATUS_BAR,
|
||||
new int[]{VISUAL_EFFECT_NOTIFICATION_LIST}, mBackend);
|
||||
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowAlarms(true)
|
||||
.showVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, false)
|
||||
.showVisualEffect(VISUAL_EFFECT_STATUS_BAR, true)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mController.updateZenMode(preference, zenMode);
|
||||
|
||||
@@ -171,15 +159,12 @@ public final class ZenModeNotifVisPreferenceControllerTest {
|
||||
"zen_effect_status", VISUAL_EFFECT_STATUS_BAR,
|
||||
new int[]{VISUAL_EFFECT_NOTIFICATION_LIST}, mBackend);
|
||||
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowAlarms(true)
|
||||
.showAllVisualEffects()
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mController.updateZenMode(preference, zenMode);
|
||||
|
||||
@@ -191,15 +176,12 @@ public final class ZenModeNotifVisPreferenceControllerTest {
|
||||
@Test
|
||||
public void onPreferenceChanged_checkedFalse() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowAlarms(true)
|
||||
.hideAllVisualEffects()
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mController.updateZenMode(preference, zenMode);
|
||||
|
||||
@@ -216,15 +198,12 @@ public final class ZenModeNotifVisPreferenceControllerTest {
|
||||
@Test
|
||||
public void onPreferenceChanged_checkedTrue() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowAlarms(true)
|
||||
.showAllVisualEffects()
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mController.updateZenMode(preference, zenMode);
|
||||
|
||||
|
@@ -16,23 +16,17 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settingslib.notification.modes.ZenMode;
|
||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -71,13 +65,7 @@ public final class ZenModeOtherLinkPreferenceControllerTest {
|
||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||
public void testHasSummary() {
|
||||
Preference pref = mock(Preference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
.build(), true);
|
||||
mController.updateZenMode(pref, zenMode);
|
||||
mController.updateZenMode(pref, TestModeBuilder.EXAMPLE);
|
||||
verify(pref).setSummary(any());
|
||||
}
|
||||
}
|
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
import static android.service.notification.ZenPolicy.STATE_ALLOW;
|
||||
import static android.service.notification.ZenPolicy.STATE_UNSET;
|
||||
|
||||
@@ -25,10 +24,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
@@ -68,12 +65,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_alarms() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeOtherPreferenceController controller =
|
||||
new ZenModeOtherPreferenceController(mContext, "modes_category_alarm", mBackend);
|
||||
@@ -86,12 +80,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
||||
@Test
|
||||
public void testOnPreferenceChange_alarms() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(false).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeOtherPreferenceController controller =
|
||||
new ZenModeOtherPreferenceController(mContext, "modes_category_alarm", mBackend);
|
||||
@@ -111,12 +102,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_media() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowMedia(true).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeOtherPreferenceController controller =
|
||||
new ZenModeOtherPreferenceController(mContext, "modes_category_media", mBackend);
|
||||
@@ -129,12 +117,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
||||
@Test
|
||||
public void testOnPreferenceChange_media() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowMedia(false).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeOtherPreferenceController controller =
|
||||
new ZenModeOtherPreferenceController(mContext, "modes_category_media", mBackend);
|
||||
@@ -154,12 +139,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_system() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowSystem(true).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeOtherPreferenceController controller =
|
||||
new ZenModeOtherPreferenceController(mContext, "modes_category_system", mBackend);
|
||||
@@ -172,12 +154,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
||||
@Test
|
||||
public void testOnPreferenceChange_system() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowSystem(false).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeOtherPreferenceController controller =
|
||||
new ZenModeOtherPreferenceController(mContext, "modes_category_system", mBackend);
|
||||
@@ -197,12 +176,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_reminders() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowReminders(true).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeOtherPreferenceController controller =
|
||||
new ZenModeOtherPreferenceController(mContext, "modes_category_reminders",
|
||||
@@ -216,12 +192,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
||||
@Test
|
||||
public void testOnPreferenceChange_reminders() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowReminders(false).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeOtherPreferenceController controller =
|
||||
new ZenModeOtherPreferenceController(mContext, "modes_category_reminders",
|
||||
@@ -242,12 +215,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_events() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowEvents(true).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeOtherPreferenceController controller =
|
||||
new ZenModeOtherPreferenceController(mContext, "modes_category_events", mBackend);
|
||||
@@ -260,12 +230,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
||||
@Test
|
||||
public void testOnPreferenceChange_events() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowEvents(false).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeOtherPreferenceController controller =
|
||||
new ZenModeOtherPreferenceController(mContext, "modes_category_events", mBackend);
|
||||
|
@@ -16,23 +16,17 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settingslib.notification.modes.ZenMode;
|
||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -72,13 +66,7 @@ public final class ZenModePeopleLinkPreferenceControllerTest {
|
||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||
public void testHasSummary() {
|
||||
Preference pref = mock(Preference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
.build(), true);
|
||||
mController.updateZenMode(pref, zenMode);
|
||||
mController.updateZenMode(pref, TestModeBuilder.EXAMPLE);
|
||||
verify(pref).setSummary(any());
|
||||
}
|
||||
}
|
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_ANYONE;
|
||||
import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_IMPORTANT;
|
||||
import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_NONE;
|
||||
@@ -40,11 +39,9 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
@@ -441,20 +438,17 @@ public final class ZenModePrioritySendersPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testPreferenceClick_passesCorrectCheckedState_startingUnchecked_messages() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.disallowAllSounds()
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mMessagesController.displayPreference(mPreferenceScreen);
|
||||
mMessagesController.updateZenMode(mMessagesPrefCategory, zenMode);
|
||||
|
||||
assertThat(((SelectorWithWidgetPreference) mMessagesPrefCategory.findPreference(KEY_NONE))
|
||||
.isChecked());
|
||||
.isChecked()).isTrue();
|
||||
|
||||
mMessagesPrefCategory.findPreference(KEY_STARRED).performClick();
|
||||
|
||||
@@ -466,14 +460,11 @@ public final class ZenModePrioritySendersPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testPreferenceClick_passesCorrectCheckedState_startingChecked_messages() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowAllSounds()
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mMessagesController.displayPreference(mPreferenceScreen);
|
||||
mMessagesController.updateZenMode(mMessagesPrefCategory, zenMode);
|
||||
@@ -492,14 +483,11 @@ public final class ZenModePrioritySendersPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testPreferenceClick_passesCorrectCheckedState_startingUnchecked_calls() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.disallowAllSounds()
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mCallsController.displayPreference(mPreferenceScreen);
|
||||
mCallsController.updateZenMode(mCallsPrefCategory, zenMode);
|
||||
@@ -517,14 +505,11 @@ public final class ZenModePrioritySendersPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testPreferenceClick_passesCorrectCheckedState_startingChecked_calls() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.disallowAllSounds()
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
mCallsController.displayPreference(mPreferenceScreen);
|
||||
mCallsController.updateZenMode(mCallsPrefCategory, zenMode);
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_ANYONE;
|
||||
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_STARRED;
|
||||
import static android.service.notification.ZenPolicy.STATE_DISALLOW;
|
||||
@@ -27,10 +26,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
@@ -70,14 +67,11 @@ public final class ZenModeRepeatCallersPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_allCalls() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowCalls(PEOPLE_TYPE_ANYONE)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeRepeatCallersPreferenceController controller =
|
||||
new ZenModeRepeatCallersPreferenceController(mContext, "repeat", mBackend, 1);
|
||||
@@ -91,15 +85,12 @@ public final class ZenModeRepeatCallersPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_someCalls() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowCalls(PEOPLE_TYPE_STARRED)
|
||||
.allowRepeatCallers(true)
|
||||
.build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeRepeatCallersPreferenceController controller =
|
||||
new ZenModeRepeatCallersPreferenceController(mContext, "repeat", mBackend, 1);
|
||||
@@ -113,12 +104,9 @@ public final class ZenModeRepeatCallersPreferenceControllerTest {
|
||||
@Test
|
||||
public void testOnPreferenceChange() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowRepeatCallers(true).build())
|
||||
.build(), true);
|
||||
.build();
|
||||
|
||||
ZenModeRepeatCallersPreferenceController controller =
|
||||
new ZenModeRepeatCallersPreferenceController(mContext, "repeat", mBackend, 1);
|
||||
|
@@ -28,10 +28,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.SystemZenRules;
|
||||
@@ -88,11 +86,9 @@ public class ZenModeSetCalendarPreferenceControllerTest {
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_MODES_API, Flags.FLAG_MODES_UI})
|
||||
public void updateEventMode_updatesConditionAndTriggerDescription() {
|
||||
ZenMode mode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("name", Uri.parse("condition"))
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||
.build(),
|
||||
true); // is active
|
||||
.build();
|
||||
|
||||
// Explicitly update preference controller with mode info first, which will also call
|
||||
// updateState()
|
||||
@@ -118,10 +114,9 @@ public class ZenModeSetCalendarPreferenceControllerTest {
|
||||
eventInfo.calName = "Definitely A Calendar";
|
||||
eventInfo.reply = REPLY_YES;
|
||||
|
||||
ZenMode mode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("name",
|
||||
ZenModeConfig.toEventConditionId(eventInfo)).build(),
|
||||
true); // is active
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setConditionId(ZenModeConfig.toEventConditionId(eventInfo))
|
||||
.build();
|
||||
mPrefController.updateZenMode(mPrefCategory, mode);
|
||||
|
||||
// We should see mCalendar, mReply have their values set
|
||||
|
@@ -23,10 +23,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.SystemZenRules;
|
||||
@@ -83,11 +81,9 @@ public class ZenModeSetSchedulePreferenceControllerTest {
|
||||
@Test
|
||||
@EnableFlags({Flags.FLAG_MODES_API, Flags.FLAG_MODES_UI})
|
||||
public void updateScheduleRule_updatesConditionAndTriggerDescription() {
|
||||
ZenMode mode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("name", Uri.parse("condition"))
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||
.build(),
|
||||
true); // is active
|
||||
.build();
|
||||
|
||||
ZenModeConfig.ScheduleInfo scheduleInfo = new ZenModeConfig.ScheduleInfo();
|
||||
scheduleInfo.days = new int[] { Calendar.MONDAY };
|
||||
|
@@ -37,7 +37,6 @@ 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.ZenPolicy;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
@@ -102,26 +101,13 @@ public class ZenModeSetTriggerLinkPreferenceControllerTest {
|
||||
assertThat(mPrefController.isAvailable()).isFalse();
|
||||
|
||||
// should be available for other modes
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
||||
.setEnabled(false)
|
||||
.build(), false);
|
||||
mPrefController.updateZenMode(mPrefCategory, zenMode);
|
||||
mPrefController.updateZenMode(mPrefCategory, TestModeBuilder.EXAMPLE);
|
||||
assertThat(mPrefController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
||||
.setEnabled(false)
|
||||
.build(), false);
|
||||
ZenMode zenMode = new TestModeBuilder().setEnabled(false).build();
|
||||
|
||||
// Update preference controller with a zen mode that is not enabled
|
||||
mPrefController.updateZenMode(mPrefCategory, zenMode);
|
||||
@@ -135,13 +121,7 @@ public class ZenModeSetTriggerLinkPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
||||
.setEnabled(false)
|
||||
.build(), false);
|
||||
ZenMode zenMode = new TestModeBuilder().setEnabled(false).build();
|
||||
|
||||
// start with disabled rule
|
||||
mPrefController.updateZenMode(mPrefCategory, zenMode);
|
||||
@@ -160,13 +140,12 @@ public class ZenModeSetTriggerLinkPreferenceControllerTest {
|
||||
ZenModeConfig.EventInfo eventInfo = new ZenModeConfig.EventInfo();
|
||||
eventInfo.calendarId = 1L;
|
||||
eventInfo.calName = "My events";
|
||||
ZenMode mode = new ZenMode("id", new AutomaticZenRule.Builder("name",
|
||||
ZenModeConfig.toEventConditionId(eventInfo))
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||
.setConditionId(ZenModeConfig.toEventConditionId(eventInfo))
|
||||
.setType(TYPE_SCHEDULE_CALENDAR)
|
||||
.setTriggerDescription("My events")
|
||||
.build(),
|
||||
true); // is active
|
||||
.build();
|
||||
mPrefController.updateZenMode(mPrefCategory, mode);
|
||||
|
||||
assertThat(mPreference.getTitle()).isNotNull();
|
||||
@@ -188,13 +167,12 @@ public class ZenModeSetTriggerLinkPreferenceControllerTest {
|
||||
scheduleInfo.days = new int[] { Calendar.MONDAY, Calendar.TUESDAY, Calendar.THURSDAY };
|
||||
scheduleInfo.startHour = 1;
|
||||
scheduleInfo.endHour = 15;
|
||||
ZenMode mode = new ZenMode("id", new AutomaticZenRule.Builder("name",
|
||||
ZenModeConfig.toScheduleConditionId(scheduleInfo))
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setConditionId(ZenModeConfig.toScheduleConditionId(scheduleInfo))
|
||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||
.setType(TYPE_SCHEDULE_TIME)
|
||||
.setTriggerDescription("some schedule")
|
||||
.build(),
|
||||
true); // is active
|
||||
.build();
|
||||
mPrefController.updateZenMode(mPrefCategory, mode);
|
||||
|
||||
assertThat(mPreference.getTitle()).isNotNull();
|
||||
@@ -212,13 +190,12 @@ public class ZenModeSetTriggerLinkPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testRuleLink_manual() {
|
||||
ZenMode mode = new ZenMode("id", new AutomaticZenRule.Builder("name",
|
||||
ZenModeConfig.toCustomManualConditionId())
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setConditionId(ZenModeConfig.toCustomManualConditionId())
|
||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||
.setType(TYPE_OTHER)
|
||||
.setTriggerDescription("Will not be shown")
|
||||
.build(),
|
||||
true); // is active
|
||||
.build();
|
||||
mPrefController.updateZenMode(mPrefCategory, mode);
|
||||
|
||||
assertThat(mPreference.getTitle()).isNotNull();
|
||||
@@ -234,13 +211,12 @@ public class ZenModeSetTriggerLinkPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onScheduleChosen_updatesMode() {
|
||||
ZenMode originalMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("name", ZenModeConfig.toCustomManualConditionId())
|
||||
ZenMode originalMode = new TestModeBuilder()
|
||||
.setConditionId(ZenModeConfig.toCustomManualConditionId())
|
||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||
.setType(TYPE_OTHER)
|
||||
.setTriggerDescription("")
|
||||
.build(),
|
||||
false);
|
||||
.build();
|
||||
mPrefController.updateZenMode(mPrefCategory, originalMode);
|
||||
|
||||
ZenModeConfig.ScheduleInfo scheduleInfo = new ZenModeConfig.ScheduleInfo();
|
||||
|
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
|
||||
import com.android.settingslib.notification.modes.ZenMode;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowLooper;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ZenModesListItemPreferenceTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_setsMode() {
|
||||
ZenModesListItemPreference preference = new ZenModesListItemPreference(mContext,
|
||||
TestModeBuilder.EXAMPLE);
|
||||
|
||||
assertThat(preference.getKey()).isEqualTo(TestModeBuilder.EXAMPLE.getId());
|
||||
assertThat(preference.getZenMode()).isEqualTo(TestModeBuilder.EXAMPLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setZenMode_modeEnabled() {
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setName("Enabled mode")
|
||||
.setTriggerDescription("When the thrush knocks")
|
||||
.setEnabled(true)
|
||||
.build();
|
||||
|
||||
ZenModesListItemPreference preference = new ZenModesListItemPreference(mContext, mode);
|
||||
ShadowLooper.idleMainLooper(); // To load icon.
|
||||
|
||||
assertThat(preference.getTitle()).isEqualTo("Enabled mode");
|
||||
assertThat(preference.getSummary()).isEqualTo("When the thrush knocks");
|
||||
assertThat(preference.getIcon()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setZenMode_modeActive() {
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setName("Active mode")
|
||||
.setTriggerDescription("When Birnam forest comes to Dunsinane")
|
||||
.setEnabled(true)
|
||||
.setActive(true)
|
||||
.build();
|
||||
|
||||
ZenModesListItemPreference preference = new ZenModesListItemPreference(mContext, mode);
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(preference.getTitle()).isEqualTo("Active mode");
|
||||
assertThat(preference.getSummary()).isEqualTo("ON • When Birnam forest comes to Dunsinane");
|
||||
assertThat(preference.getIcon()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setZenMode_modeDisabledByApp() {
|
||||
ZenModeConfig.ZenRule configRule = new ZenModeConfig.ZenRule();
|
||||
configRule.enabled = false;
|
||||
configRule.disabledOrigin = ZenModeConfig.UPDATE_ORIGIN_APP;
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setName("Mode disabled by app")
|
||||
.setTriggerDescription("When the cat's away")
|
||||
.setEnabled(false)
|
||||
.setConfigZenRule(configRule)
|
||||
.build();
|
||||
|
||||
ZenModesListItemPreference preference = new ZenModesListItemPreference(mContext, mode);
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(preference.getTitle()).isEqualTo("Mode disabled by app");
|
||||
assertThat(preference.getSummary()).isEqualTo("Tap to set up");
|
||||
assertThat(preference.getIcon()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setZenMode_modeDisabledByUser() {
|
||||
ZenModeConfig.ZenRule configRule = new ZenModeConfig.ZenRule();
|
||||
configRule.enabled = false;
|
||||
configRule.disabledOrigin = ZenModeConfig.UPDATE_ORIGIN_USER;
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setName("Mode disabled by user")
|
||||
.setTriggerDescription("When the Levee Breaks")
|
||||
.setEnabled(false)
|
||||
.setConfigZenRule(configRule)
|
||||
.build();
|
||||
|
||||
ZenModesListItemPreference preference = new ZenModesListItemPreference(mContext, mode);
|
||||
ShadowLooper.idleMainLooper();
|
||||
|
||||
assertThat(preference.getTitle()).isEqualTo("Mode disabled by user");
|
||||
assertThat(preference.getSummary()).isEqualTo("Paused");
|
||||
assertThat(preference.getIcon()).isNotNull();
|
||||
}
|
||||
}
|
@@ -60,14 +60,15 @@ import java.util.List;
|
||||
public class ZenModesListPreferenceControllerTest {
|
||||
private static final String TEST_MODE_ID = "test_mode";
|
||||
private static final String TEST_MODE_NAME = "Test Mode";
|
||||
private static final ZenMode TEST_MODE = new ZenMode(
|
||||
TEST_MODE_ID,
|
||||
new AutomaticZenRule.Builder(TEST_MODE_NAME, Uri.parse("test_uri"))
|
||||
|
||||
private static final ZenMode TEST_MODE = new TestModeBuilder()
|
||||
.setId(TEST_MODE_ID)
|
||||
.setAzr(new AutomaticZenRule.Builder(TEST_MODE_NAME, Uri.parse("test_uri"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
.build(),
|
||||
false);
|
||||
.build())
|
||||
.build();
|
||||
|
||||
private static final ZenMode TEST_MANUAL_MODE = ZenMode.manualDndMode(
|
||||
new AutomaticZenRule.Builder("Do Not Disturb", Uri.EMPTY)
|
||||
@@ -112,14 +113,9 @@ public class ZenModesListPreferenceControllerTest {
|
||||
|
||||
assertThat(mPreference.getPreferenceCount()).isEqualTo(5);
|
||||
List<ZenModesListItemPreference> itemPreferences = getModeListItems(mPreference);
|
||||
assertThat(itemPreferences.stream().map(pref -> pref.mZenMode).toList())
|
||||
assertThat(itemPreferences.stream().map(ZenModesListItemPreference::getZenMode).toList())
|
||||
.containsExactlyElementsIn(modes)
|
||||
.inOrder();
|
||||
|
||||
for (int i = 0; i < modes.size(); i++) {
|
||||
assertThat(((ZenModesListItemPreference) (mPreference.getPreference(i))).mZenMode)
|
||||
.isEqualTo(modes.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,7 +136,7 @@ public class ZenModesListPreferenceControllerTest {
|
||||
mPrefController.updateState(mPreference);
|
||||
|
||||
List<ZenModesListItemPreference> newPreferences = getModeListItems(mPreference);
|
||||
assertThat(newPreferences.stream().map(pref -> pref.mZenMode).toList())
|
||||
assertThat(newPreferences.stream().map(ZenModesListItemPreference::getZenMode).toList())
|
||||
.containsExactlyElementsIn(updatedModes)
|
||||
.inOrder();
|
||||
|
||||
@@ -196,7 +192,7 @@ public class ZenModesListPreferenceControllerTest {
|
||||
assertThat(newData).hasSize(1);
|
||||
|
||||
SearchIndexableRaw newItem = newData.get(0);
|
||||
assertThat(newItem.key).isEqualTo(ZenMode.MANUAL_DND_MODE_ID);
|
||||
assertThat(newItem.key).isEqualTo(TEST_MANUAL_MODE.getId());
|
||||
assertThat(newItem.title).isEqualTo("Do Not Disturb"); // set above
|
||||
}
|
||||
|
||||
@@ -211,7 +207,7 @@ public class ZenModesListPreferenceControllerTest {
|
||||
|
||||
// Should keep the order presented by getModes()
|
||||
SearchIndexableRaw item0 = data.get(0);
|
||||
assertThat(item0.key).isEqualTo(ZenMode.MANUAL_DND_MODE_ID);
|
||||
assertThat(item0.key).isEqualTo(TEST_MANUAL_MODE.getId());
|
||||
assertThat(item0.title).isEqualTo("Do Not Disturb"); // set above
|
||||
|
||||
SearchIndexableRaw item1 = data.get(1);
|
||||
@@ -220,13 +216,7 @@ public class ZenModesListPreferenceControllerTest {
|
||||
}
|
||||
|
||||
private static ZenMode newMode(String id) {
|
||||
return new ZenMode(
|
||||
id,
|
||||
new AutomaticZenRule.Builder("Mode " + id, Uri.parse("test_uri"))
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
.build(),
|
||||
false);
|
||||
return new TestModeBuilder().setId(id).setName("Mode " + id).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_ANYONE;
|
||||
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_ANYONE;
|
||||
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_CONTACTS;
|
||||
@@ -25,9 +24,7 @@ import static android.service.notification.ZenPolicy.VISUAL_EFFECT_LIGHTS;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.service.notification.ZenDeviceEffects;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
@@ -59,50 +56,38 @@ public class ZenModesSummaryHelperTest {
|
||||
|
||||
@Test
|
||||
public void getPeopleSummary_noOne() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().disallowAllSounds().build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getPeopleSummary(zenMode)).isEqualTo("No one can interrupt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPeopleSummary_some() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowCalls(PEOPLE_TYPE_CONTACTS).build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getPeopleSummary(zenMode)).isEqualTo("Some people can interrupt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPeopleSummary_all() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowCalls(PEOPLE_TYPE_ANYONE).
|
||||
allowConversations(CONVERSATION_SENDERS_ANYONE)
|
||||
.allowMessages(PEOPLE_TYPE_ANYONE).build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getPeopleSummary(zenMode)).isEqualTo("All people can interrupt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOtherSoundCategoriesSummary_single() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
||||
"Alarms can interrupt");
|
||||
@@ -110,12 +95,9 @@ public class ZenModesSummaryHelperTest {
|
||||
|
||||
@Test
|
||||
public void getOtherSoundCategoriesSummary_duo() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).allowMedia(true).build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
||||
"Alarms and media can interrupt");
|
||||
@@ -123,16 +105,13 @@ public class ZenModesSummaryHelperTest {
|
||||
|
||||
@Test
|
||||
public void getOtherSoundCategoriesSummary_trio() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowAlarms(true)
|
||||
.allowMedia(true)
|
||||
.allowSystem(true)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
||||
"Alarms, media, and touch sounds can interrupt");
|
||||
@@ -140,9 +119,7 @@ public class ZenModesSummaryHelperTest {
|
||||
|
||||
@Test
|
||||
public void getOtherSoundCategoriesSummary_quad() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowAlarms(true)
|
||||
.allowMedia(true)
|
||||
@@ -150,7 +127,6 @@ public class ZenModesSummaryHelperTest {
|
||||
.allowReminders(true)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
||||
"Alarms, media, and 2 more can interrupt");
|
||||
@@ -158,9 +134,7 @@ public class ZenModesSummaryHelperTest {
|
||||
|
||||
@Test
|
||||
public void getOtherSoundCategoriesSummary_all() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowAlarms(true)
|
||||
.allowMedia(true)
|
||||
@@ -169,7 +143,6 @@ public class ZenModesSummaryHelperTest {
|
||||
.allowEvents(true)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
||||
"Alarms, media, and 3 more can interrupt");
|
||||
@@ -177,61 +150,52 @@ public class ZenModesSummaryHelperTest {
|
||||
|
||||
@Test
|
||||
public void getBlockedEffectsSummary_none() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.showAllVisualEffects()
|
||||
.allowAlarms(true)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getBlockedEffectsSummary(zenMode))
|
||||
.isEqualTo("Notifications shown");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBlockedEffectsSummary_some() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowAlarms(true)
|
||||
.showAllVisualEffects()
|
||||
.showVisualEffect(VISUAL_EFFECT_AMBIENT, false)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getBlockedEffectsSummary(zenMode))
|
||||
.isEqualTo("Notifications partially hidden");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBlockedEffectsSummary_all() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowAlarms(true)
|
||||
.hideAllVisualEffects()
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getBlockedEffectsSummary(zenMode))
|
||||
.isEqualTo("Notifications hidden");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDisplayEffectsSummary_single_notifVis() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.showAllVisualEffects()
|
||||
.showVisualEffect(VISUAL_EFFECT_AMBIENT, false)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
||||
"Notifications partially hidden");
|
||||
@@ -239,15 +203,12 @@ public class ZenModesSummaryHelperTest {
|
||||
|
||||
@Test
|
||||
public void getDisplayEffectsSummary_single_notifVis_unusedEffect() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.showAllVisualEffects()
|
||||
.showVisualEffect(VISUAL_EFFECT_LIGHTS, false)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
||||
"Notifications shown");
|
||||
@@ -255,15 +216,12 @@ public class ZenModesSummaryHelperTest {
|
||||
|
||||
@Test
|
||||
public void getDisplayEffectsSummary_single_displayEffect() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().showAllVisualEffects().build())
|
||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||
.setShouldDimWallpaper(true)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
||||
"Dim the wallpaper");
|
||||
@@ -271,16 +229,13 @@ public class ZenModesSummaryHelperTest {
|
||||
|
||||
@Test
|
||||
public void getDisplayEffectsSummary_duo() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder().showAllVisualEffects().build())
|
||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||
.setShouldDimWallpaper(true)
|
||||
.setShouldDisplayGrayscale(true)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
||||
"Grayscale and dim the wallpaper");
|
||||
@@ -288,9 +243,7 @@ public class ZenModesSummaryHelperTest {
|
||||
|
||||
@Test
|
||||
public void getDisplayEffectsSummary_trio() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.hideAllVisualEffects()
|
||||
.allowAlarms(true)
|
||||
@@ -302,7 +255,6 @@ public class ZenModesSummaryHelperTest {
|
||||
.setShouldDimWallpaper(true)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
||||
"Notifications hidden, grayscale, and dim the wallpaper");
|
||||
@@ -310,9 +262,7 @@ public class ZenModesSummaryHelperTest {
|
||||
|
||||
@Test
|
||||
public void getDisplayEffectsSummary_quad() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.showAllVisualEffects()
|
||||
.showVisualEffect(VISUAL_EFFECT_AMBIENT, false)
|
||||
@@ -326,7 +276,6 @@ public class ZenModesSummaryHelperTest {
|
||||
.setShouldUseNightMode(true)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
||||
"Notifications partially hidden, grayscale, and 2 more");
|
||||
@@ -334,28 +283,22 @@ public class ZenModesSummaryHelperTest {
|
||||
|
||||
@Test
|
||||
public void getAppsSummary_none() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getAppsSummary(zenMode, new LinkedHashSet<>())).isEqualTo("None");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAppsSummary_priorityAppsNoList() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getAppsSummary(zenMode, null)).isEqualTo("Selected apps");
|
||||
}
|
||||
@@ -397,19 +340,15 @@ public class ZenModesSummaryHelperTest {
|
||||
|
||||
@Test
|
||||
public void getAppsSummary_priorityApps() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
Set<String> apps = Set.of("My App", "SecondApp", "ThirdApp", "FourthApp",
|
||||
"FifthApp", "SixthApp");
|
||||
|
||||
assertThat(mSummaryHelper.getAppsSummary(zenMode, apps)).isEqualTo("FifthApp, FourthApp, "
|
||||
+ "and 4 more can interrupt");
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user