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] -->
|
<!-- Zen Modes: Option to add an automatic schedule for a mode. [CHAR_LIMIT=40] -->
|
||||||
<string name="zen_mode_select_schedule">Select activation type</string>
|
<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>
|
<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>
|
<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>
|
<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>
|
<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]-->
|
<!-- Subtitle for the Do not Disturb slice. [CHAR LIMIT=50]-->
|
||||||
<string name="zen_mode_slice_subtitle">Limit interruptions</string>
|
<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.ShapeDrawable;
|
||||||
import android.graphics.drawable.shapes.OvalShape;
|
import android.graphics.drawable.shapes.OvalShape;
|
||||||
|
|
||||||
|
import androidx.annotation.AttrRes;
|
||||||
import androidx.annotation.DrawableRes;
|
import androidx.annotation.DrawableRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
@@ -32,10 +33,18 @@ import com.android.settingslib.Utils;
|
|||||||
|
|
||||||
class IconUtil {
|
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 = icon.mutate();
|
||||||
icon.setTintList(
|
icon.setTintList(Utils.getColorAttr(context, colorAttr));
|
||||||
Utils.getColorAttr(context, android.R.attr.colorControlNormal));
|
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -27,7 +27,7 @@ import com.android.settingslib.notification.modes.ZenMode;
|
|||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settingslib.widget.LayoutPreference;
|
||||||
|
|
||||||
public class ZenModeButtonPreferenceController extends AbstractZenModePreferenceController {
|
class ZenModeButtonPreferenceController extends AbstractZenModePreferenceController {
|
||||||
|
|
||||||
private Button mZenButton;
|
private Button mZenButton;
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@ import androidx.preference.TwoStatePreference;
|
|||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
public class ZenModeDisplayEffectPreferenceController extends AbstractZenModePreferenceController
|
class ZenModeDisplayEffectPreferenceController extends AbstractZenModePreferenceController
|
||||||
implements Preference.OnPreferenceChangeListener {
|
implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
public ZenModeDisplayEffectPreferenceController(Context context, String key,
|
public ZenModeDisplayEffectPreferenceController(Context context, String key,
|
||||||
@@ -37,24 +37,20 @@ public class ZenModeDisplayEffectPreferenceController extends AbstractZenModePre
|
|||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
public void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
||||||
TwoStatePreference pref = (TwoStatePreference) preference;
|
TwoStatePreference pref = (TwoStatePreference) preference;
|
||||||
ZenDeviceEffects effects = zenMode.getRule().getDeviceEffects();
|
ZenDeviceEffects effects = zenMode.getDeviceEffects();
|
||||||
if (effects == null) {
|
switch (getPreferenceKey()) {
|
||||||
pref.setChecked(false);
|
case "effect_greyscale":
|
||||||
} else {
|
pref.setChecked(effects.shouldDisplayGrayscale());
|
||||||
switch (getPreferenceKey()) {
|
break;
|
||||||
case "effect_greyscale":
|
case "effect_aod":
|
||||||
pref.setChecked(effects.shouldDisplayGrayscale());
|
pref.setChecked(effects.shouldSuppressAmbientDisplay());
|
||||||
break;
|
break;
|
||||||
case "effect_aod":
|
case "effect_wallpaper":
|
||||||
pref.setChecked(effects.shouldSuppressAmbientDisplay());
|
pref.setChecked(effects.shouldDimWallpaper());
|
||||||
break;
|
break;
|
||||||
case "effect_wallpaper":
|
case "effect_dark_theme":
|
||||||
pref.setChecked(effects.shouldDimWallpaper());
|
pref.setChecked(effects.shouldUseNightMode());
|
||||||
break;
|
break;
|
||||||
case "effect_dark_theme":
|
|
||||||
pref.setChecked(effects.shouldUseNightMode());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -66,7 +66,7 @@ class ZenModeHeaderController extends AbstractZenModePreferenceController {
|
|||||||
|
|
||||||
FutureUtil.whenDone(
|
FutureUtil.whenDone(
|
||||||
zenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
zenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
||||||
icon -> mHeaderController.setIcon(IconUtil.applyTint(mContext, icon))
|
icon -> mHeaderController.setIcon(IconUtil.applyNormalTint(mContext, icon))
|
||||||
.done(/* rebindActions= */ false),
|
.done(/* rebindActions= */ false),
|
||||||
mContext.getMainExecutor());
|
mContext.getMainExecutor());
|
||||||
}
|
}
|
||||||
|
@@ -55,7 +55,7 @@ class ZenModeIconPickerIconPreferenceController extends AbstractZenModePreferenc
|
|||||||
|
|
||||||
FutureUtil.whenDone(
|
FutureUtil.whenDone(
|
||||||
zenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
zenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
||||||
icon -> mHeaderController.setIcon(IconUtil.applyTint(mContext, icon))
|
icon -> mHeaderController.setIcon(IconUtil.applyNormalTint(mContext, icon))
|
||||||
.done(/* rebindActions= */ false),
|
.done(/* rebindActions= */ false),
|
||||||
mContext.getMainExecutor());
|
mContext.getMainExecutor());
|
||||||
}
|
}
|
||||||
|
@@ -16,18 +16,31 @@
|
|||||||
package com.android.settings.notification.modes;
|
package com.android.settings.notification.modes;
|
||||||
|
|
||||||
import android.content.Context;
|
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.RestrictedPreference;
|
||||||
|
import com.android.settingslib.Utils;
|
||||||
import com.android.settingslib.notification.modes.ZenIconLoader;
|
import com.android.settingslib.notification.modes.ZenIconLoader;
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
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 representing a single mode item on the modes aggregator page. Clicking on this
|
||||||
* preference leads to an individual mode's configuration page.
|
* preference leads to an individual mode's configuration page.
|
||||||
*/
|
*/
|
||||||
class ZenModesListItemPreference extends RestrictedPreference {
|
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) {
|
ZenModesListItemPreference(Context context, ZenMode zenMode) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -36,6 +49,18 @@ class ZenModesListItemPreference extends RestrictedPreference {
|
|||||||
setKey(zenMode.getId());
|
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
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
ZenSubSettingLauncher.forMode(mContext, mZenMode.getId()).launch();
|
ZenSubSettingLauncher.forMode(mContext, mZenMode.getId()).launch();
|
||||||
@@ -43,13 +68,47 @@ class ZenModesListItemPreference extends RestrictedPreference {
|
|||||||
|
|
||||||
public void setZenMode(ZenMode zenMode) {
|
public void setZenMode(ZenMode zenMode) {
|
||||||
mZenMode = zenMode;
|
mZenMode = zenMode;
|
||||||
setTitle(mZenMode.getRule().getName());
|
setTitle(mZenMode.getName());
|
||||||
setSummary(mZenMode.getRule().getTriggerDescription());
|
CharSequence statusText = switch (mZenMode.getStatus()) {
|
||||||
setIconSize(ICON_SIZE_SMALL);
|
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(
|
FutureUtil.whenDone(
|
||||||
mZenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
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());
|
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.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenPolicy;
|
import android.service.notification.ZenPolicy;
|
||||||
@@ -71,12 +69,9 @@ public final class InterruptionFilterPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_all() {
|
public void testUpdateState_all() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setInterruptionFilter(INTERRUPTION_FILTER_ALL)
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.build();
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_ALL)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
|
||||||
.build(), true);
|
|
||||||
mController.updateZenMode(preference, zenMode);
|
mController.updateZenMode(preference, zenMode);
|
||||||
|
|
||||||
verify(preference).setChecked(false);
|
verify(preference).setChecked(false);
|
||||||
@@ -85,12 +80,9 @@ public final class InterruptionFilterPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceChange_fromAll() {
|
public void testOnPreferenceChange_fromAll() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setInterruptionFilter(INTERRUPTION_FILTER_ALL)
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.build();
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_ALL)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(false).build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mController.updateZenMode(preference, zenMode);
|
mController.updateZenMode(preference, zenMode);
|
||||||
|
|
||||||
@@ -107,12 +99,10 @@ public final class InterruptionFilterPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_priority() {
|
public void testUpdateState_priority() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build();
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
|
||||||
.build(), true);
|
|
||||||
mController.updateZenMode(preference, zenMode);
|
mController.updateZenMode(preference, zenMode);
|
||||||
|
|
||||||
verify(preference).setChecked(true);
|
verify(preference).setChecked(true);
|
||||||
@@ -121,12 +111,10 @@ public final class InterruptionFilterPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceChange_fromPriority() {
|
public void testOnPreferenceChange_fromPriority() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(false).build())
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build();
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(false).build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mController.updateZenMode(preference, zenMode);
|
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.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
@@ -103,14 +101,13 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ZenMode createPriorityChannelsZenMode() {
|
private ZenMode createPriorityChannelsZenMode() {
|
||||||
return new ZenMode("id", new AutomaticZenRule.Builder("Bedtime",
|
return new TestModeBuilder()
|
||||||
Uri.parse("bed"))
|
.setId("id")
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||||
.build())
|
.build())
|
||||||
.build(), true);
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -26,10 +26,8 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenPolicy;
|
import android.service.notification.ZenPolicy;
|
||||||
@@ -107,13 +105,12 @@ public final class ZenModeAppsPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_None() {
|
public void testUpdateState_None() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build())
|
||||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
.build();
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
mNoneController.updateZenMode(preference, zenMode);
|
mNoneController.updateZenMode(preference, zenMode);
|
||||||
|
|
||||||
verify(preference).setChecked(true);
|
verify(preference).setChecked(true);
|
||||||
@@ -122,13 +119,12 @@ public final class ZenModeAppsPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_None_Unchecked() {
|
public void testUpdateState_None_Unchecked() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build())
|
||||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
.build();
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
mNoneController.updateZenMode(preference, zenMode);
|
mNoneController.updateZenMode(preference, zenMode);
|
||||||
|
|
||||||
verify(preference).setChecked(false);
|
verify(preference).setChecked(false);
|
||||||
@@ -137,13 +133,12 @@ public final class ZenModeAppsPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_Priority() {
|
public void testUpdateState_Priority() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build())
|
||||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
.build();
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
mPriorityController.updateZenMode(preference, zenMode);
|
mPriorityController.updateZenMode(preference, zenMode);
|
||||||
|
|
||||||
verify(preference).setChecked(true);
|
verify(preference).setChecked(true);
|
||||||
@@ -152,13 +147,12 @@ public final class ZenModeAppsPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_Priority_Unchecked() {
|
public void testUpdateState_Priority_Unchecked() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build())
|
||||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
.build();
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
mPriorityController.updateZenMode(preference, zenMode);
|
mPriorityController.updateZenMode(preference, zenMode);
|
||||||
|
|
||||||
verify(preference).setChecked(false);
|
verify(preference).setChecked(false);
|
||||||
@@ -166,21 +160,19 @@ public final class ZenModeAppsPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPreferenceClick_passesCorrectCheckedState_None() {
|
public void testPreferenceClick_passesCorrectCheckedState_None() {
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build())
|
||||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
.build();
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mNoneController.updateZenMode(mNonePref, zenMode);
|
mNoneController.updateZenMode(mNonePref, zenMode);
|
||||||
mPriorityController.updateZenMode(mPriorityPref, zenMode);
|
mPriorityController.updateZenMode(mPriorityPref, zenMode);
|
||||||
|
|
||||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||||
.isChecked());
|
.isChecked()).isFalse();
|
||||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||||
.isChecked());
|
.isChecked()).isTrue();
|
||||||
|
|
||||||
// Click on NONE
|
// Click on NONE
|
||||||
mPrefCategory.findPreference(KEY_NONE).performClick();
|
mPrefCategory.findPreference(KEY_NONE).performClick();
|
||||||
@@ -192,30 +184,31 @@ public final class ZenModeAppsPreferenceControllerTest {
|
|||||||
// See AbstractZenModePreferenceController.
|
// See AbstractZenModePreferenceController.
|
||||||
assertThat(captor.getValue().getRule().getInterruptionFilter())
|
assertThat(captor.getValue().getRule().getInterruptionFilter())
|
||||||
.isEqualTo(INTERRUPTION_FILTER_PRIORITY);
|
.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))
|
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||||
.isChecked());
|
.isChecked()).isTrue();
|
||||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||||
.isChecked());
|
.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPreferenceClick_passesCorrectCheckedState_Priority() {
|
public void testPreferenceClick_passesCorrectCheckedState_Priority() {
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build())
|
||||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
.build();
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mNoneController.updateZenMode(mNonePref, zenMode);
|
mNoneController.updateZenMode(mNonePref, zenMode);
|
||||||
mPriorityController.updateZenMode(mPriorityPref, zenMode);
|
mPriorityController.updateZenMode(mPriorityPref, zenMode);
|
||||||
|
|
||||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||||
.isChecked());
|
.isChecked()).isTrue();
|
||||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||||
.isChecked());
|
.isChecked()).isFalse();
|
||||||
|
|
||||||
// Click on PRIORITY
|
// Click on PRIORITY
|
||||||
mPrefCategory.findPreference(KEY_PRIORITY).performClick();
|
mPrefCategory.findPreference(KEY_PRIORITY).performClick();
|
||||||
@@ -225,11 +218,13 @@ public final class ZenModeAppsPreferenceControllerTest {
|
|||||||
// Checks the policy value for PRIORITY is propagated to the backend.
|
// Checks the policy value for PRIORITY is propagated to the backend.
|
||||||
assertThat(captor.getValue().getRule().getInterruptionFilter())
|
assertThat(captor.getValue().getRule().getInterruptionFilter())
|
||||||
.isEqualTo(INTERRUPTION_FILTER_PRIORITY);
|
.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;
|
package com.android.settings.notification.modes;
|
||||||
|
|
||||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
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.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenPolicy;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
@@ -73,43 +68,34 @@ public final class ZenModeButtonPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_notIfAppOptsOut() {
|
public void isAvailable_notIfAppOptsOut() {
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
|
||||||
.setManualInvocationAllowed(false)
|
.setManualInvocationAllowed(false)
|
||||||
.setEnabled(true)
|
.build();
|
||||||
.build(), false);
|
|
||||||
mController.setZenMode(zenMode);
|
mController.setZenMode(zenMode);
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_notIfModeDisabled() {
|
public void isAvailable_notIfModeDisabled() {
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setManualInvocationAllowed(true)
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setEnabled(false)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build();
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
|
||||||
.setManualInvocationAllowed(true)
|
|
||||||
.setEnabled(false)
|
|
||||||
.build(), false);
|
|
||||||
mController.setZenMode(zenMode);
|
mController.setZenMode(zenMode);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_appOptedIn_modeEnabled() {
|
public void isAvailable_appOptedIn_modeEnabled() {
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setManualInvocationAllowed(true)
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setEnabled(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build();
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
|
||||||
.setManualInvocationAllowed(true)
|
|
||||||
.setEnabled(true)
|
|
||||||
.build(), false);
|
|
||||||
mController.setZenMode(zenMode);
|
mController.setZenMode(zenMode);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,15 +104,13 @@ public final class ZenModeButtonPreferenceControllerTest {
|
|||||||
Button button = new Button(mContext);
|
Button button = new Button(mContext);
|
||||||
LayoutPreference pref = mock(LayoutPreference.class);
|
LayoutPreference pref = mock(LayoutPreference.class);
|
||||||
when(pref.findViewById(anyInt())).thenReturn(button);
|
when(pref.findViewById(anyInt())).thenReturn(button);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setManualInvocationAllowed(true)
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setActive(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build();
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
|
||||||
.setManualInvocationAllowed(true)
|
|
||||||
.setEnabled(true)
|
|
||||||
.build(), true);
|
|
||||||
mController.updateZenMode(pref, zenMode);
|
mController.updateZenMode(pref, zenMode);
|
||||||
|
|
||||||
assertThat(button.getText().toString()).contains("off");
|
assertThat(button.getText().toString()).contains("off");
|
||||||
assertThat(button.hasOnClickListeners()).isTrue();
|
assertThat(button.hasOnClickListeners()).isTrue();
|
||||||
}
|
}
|
||||||
@@ -136,15 +120,13 @@ public final class ZenModeButtonPreferenceControllerTest {
|
|||||||
Button button = new Button(mContext);
|
Button button = new Button(mContext);
|
||||||
LayoutPreference pref = mock(LayoutPreference.class);
|
LayoutPreference pref = mock(LayoutPreference.class);
|
||||||
when(pref.findViewById(anyInt())).thenReturn(button);
|
when(pref.findViewById(anyInt())).thenReturn(button);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setManualInvocationAllowed(true)
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setActive(false)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build();
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
|
||||||
.setManualInvocationAllowed(true)
|
|
||||||
.setEnabled(true)
|
|
||||||
.build(), false);
|
|
||||||
mController.updateZenMode(pref, zenMode);
|
mController.updateZenMode(pref, zenMode);
|
||||||
|
|
||||||
assertThat(button.getText().toString()).contains("on");
|
assertThat(button.getText().toString()).contains("on");
|
||||||
assertThat(button.hasOnClickListeners()).isTrue();
|
assertThat(button.hasOnClickListeners()).isTrue();
|
||||||
}
|
}
|
||||||
@@ -154,14 +136,11 @@ public final class ZenModeButtonPreferenceControllerTest {
|
|||||||
Button button = new Button(mContext);
|
Button button = new Button(mContext);
|
||||||
LayoutPreference pref = mock(LayoutPreference.class);
|
LayoutPreference pref = mock(LayoutPreference.class);
|
||||||
when(pref.findViewById(anyInt())).thenReturn(button);
|
when(pref.findViewById(anyInt())).thenReturn(button);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setManualInvocationAllowed(true)
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setActive(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build();
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
|
||||||
.setManualInvocationAllowed(true)
|
|
||||||
.setEnabled(true)
|
|
||||||
.build(), true);
|
|
||||||
mController.updateZenMode(pref, zenMode);
|
mController.updateZenMode(pref, zenMode);
|
||||||
|
|
||||||
button.callOnClick();
|
button.callOnClick();
|
||||||
@@ -173,14 +152,11 @@ public final class ZenModeButtonPreferenceControllerTest {
|
|||||||
Button button = new Button(mContext);
|
Button button = new Button(mContext);
|
||||||
LayoutPreference pref = mock(LayoutPreference.class);
|
LayoutPreference pref = mock(LayoutPreference.class);
|
||||||
when(pref.findViewById(anyInt())).thenReturn(button);
|
when(pref.findViewById(anyInt())).thenReturn(button);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setManualInvocationAllowed(true)
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setActive(false)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build();
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
|
||||||
.setManualInvocationAllowed(true)
|
|
||||||
.setEnabled(true)
|
|
||||||
.build(), false);
|
|
||||||
mController.updateZenMode(pref, zenMode);
|
mController.updateZenMode(pref, zenMode);
|
||||||
|
|
||||||
button.callOnClick();
|
button.callOnClick();
|
||||||
|
@@ -16,23 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.modes;
|
package com.android.settings.notification.modes;
|
||||||
|
|
||||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenPolicy;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -70,13 +64,7 @@ public final class ZenModeCallsLinkPreferenceControllerTest {
|
|||||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||||
public void testHasSummary() {
|
public void testHasSummary() {
|
||||||
Preference pref = mock(Preference.class);
|
Preference pref = mock(Preference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
mController.updateZenMode(pref, TestModeBuilder.EXAMPLE);
|
||||||
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);
|
|
||||||
verify(pref).setSummary(any());
|
verify(pref).setSummary(any());
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -16,21 +16,16 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.modes;
|
package com.android.settings.notification.modes;
|
||||||
|
|
||||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenDeviceEffects;
|
import android.service.notification.ZenDeviceEffects;
|
||||||
import android.service.notification.ZenPolicy;
|
|
||||||
|
|
||||||
import androidx.preference.TwoStatePreference;
|
import androidx.preference.TwoStatePreference;
|
||||||
|
|
||||||
@@ -67,15 +62,11 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_grayscale() {
|
public void testUpdateState_grayscale() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setShouldDisplayGrayscale(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build())
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
.build();
|
||||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
|
||||||
.setShouldDisplayGrayscale(true)
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeDisplayEffectPreferenceController controller =
|
ZenModeDisplayEffectPreferenceController controller =
|
||||||
new ZenModeDisplayEffectPreferenceController(
|
new ZenModeDisplayEffectPreferenceController(
|
||||||
@@ -89,15 +80,11 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceChange_grayscale() {
|
public void testOnPreferenceChange_grayscale() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setShouldDisplayGrayscale(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build())
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(false).build())
|
.build();
|
||||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
|
||||||
.setShouldDisplayGrayscale(true)
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeDisplayEffectPreferenceController controller =
|
ZenModeDisplayEffectPreferenceController controller =
|
||||||
new ZenModeDisplayEffectPreferenceController(mContext, "effect_greyscale", mBackend);
|
new ZenModeDisplayEffectPreferenceController(mContext, "effect_greyscale", mBackend);
|
||||||
@@ -108,22 +95,18 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
|||||||
|
|
||||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||||
verify(mBackend).updateMode(captor.capture());
|
verify(mBackend).updateMode(captor.capture());
|
||||||
assertThat(captor.getValue().getRule().getDeviceEffects().shouldDisplayGrayscale())
|
assertThat(captor.getValue().getDeviceEffects().shouldDisplayGrayscale())
|
||||||
.isFalse();
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_aod() {
|
public void testUpdateState_aod() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setShouldSuppressAmbientDisplay(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build())
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowMedia(true).build())
|
.build();
|
||||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
|
||||||
.setShouldSuppressAmbientDisplay(true)
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeDisplayEffectPreferenceController controller =
|
ZenModeDisplayEffectPreferenceController controller =
|
||||||
new ZenModeDisplayEffectPreferenceController(mContext, "effect_aod", mBackend);
|
new ZenModeDisplayEffectPreferenceController(mContext, "effect_aod", mBackend);
|
||||||
@@ -136,15 +119,11 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceChange_aod() {
|
public void testOnPreferenceChange_aod() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setShouldSuppressAmbientDisplay(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build())
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowMedia(false).build())
|
.build();
|
||||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
|
||||||
.setShouldSuppressAmbientDisplay(true)
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeDisplayEffectPreferenceController controller =
|
ZenModeDisplayEffectPreferenceController controller =
|
||||||
new ZenModeDisplayEffectPreferenceController(mContext, "effect_aod", mBackend);
|
new ZenModeDisplayEffectPreferenceController(mContext, "effect_aod", mBackend);
|
||||||
@@ -155,22 +134,18 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
|||||||
|
|
||||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||||
verify(mBackend).updateMode(captor.capture());
|
verify(mBackend).updateMode(captor.capture());
|
||||||
assertThat(captor.getValue().getRule().getDeviceEffects().shouldSuppressAmbientDisplay())
|
assertThat(captor.getValue().getDeviceEffects().shouldSuppressAmbientDisplay())
|
||||||
.isFalse();
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_wallpaper() {
|
public void testUpdateState_wallpaper() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setShouldDimWallpaper(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build())
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowSystem(true).build())
|
.build();
|
||||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
|
||||||
.setShouldDimWallpaper(true)
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeDisplayEffectPreferenceController controller =
|
ZenModeDisplayEffectPreferenceController controller =
|
||||||
new ZenModeDisplayEffectPreferenceController(
|
new ZenModeDisplayEffectPreferenceController(
|
||||||
@@ -184,15 +159,11 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceChange_wallpaper() {
|
public void testOnPreferenceChange_wallpaper() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setShouldDimWallpaper(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build())
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowSystem(false).build())
|
.build();
|
||||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
|
||||||
.setShouldDimWallpaper(true)
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeDisplayEffectPreferenceController controller =
|
ZenModeDisplayEffectPreferenceController controller =
|
||||||
new ZenModeDisplayEffectPreferenceController(
|
new ZenModeDisplayEffectPreferenceController(
|
||||||
@@ -204,21 +175,17 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
|||||||
|
|
||||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||||
verify(mBackend).updateMode(captor.capture());
|
verify(mBackend).updateMode(captor.capture());
|
||||||
assertThat(captor.getValue().getRule().getDeviceEffects().shouldDimWallpaper()).isFalse();
|
assertThat(captor.getValue().getDeviceEffects().shouldDimWallpaper()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_darkTheme() {
|
public void testUpdateState_darkTheme() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setShouldUseNightMode(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build())
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowReminders(true).build())
|
.build();
|
||||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
|
||||||
.setShouldUseNightMode(true)
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeDisplayEffectPreferenceController controller =
|
ZenModeDisplayEffectPreferenceController controller =
|
||||||
new ZenModeDisplayEffectPreferenceController(mContext, "effect_dark_theme",
|
new ZenModeDisplayEffectPreferenceController(mContext, "effect_dark_theme",
|
||||||
@@ -232,15 +199,11 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceChange_darkTheme() {
|
public void testOnPreferenceChange_darkTheme() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.setShouldUseNightMode(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build())
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowReminders(false).build())
|
.build();
|
||||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
|
||||||
.setShouldUseNightMode(true)
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeDisplayEffectPreferenceController controller =
|
ZenModeDisplayEffectPreferenceController controller =
|
||||||
new ZenModeDisplayEffectPreferenceController(mContext, "effect_dark_theme",
|
new ZenModeDisplayEffectPreferenceController(mContext, "effect_dark_theme",
|
||||||
@@ -252,6 +215,6 @@ public final class ZenModeDisplayEffectPreferenceControllerTest {
|
|||||||
|
|
||||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||||
verify(mBackend).updateMode(captor.capture());
|
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;
|
package com.android.settings.notification.modes;
|
||||||
|
|
||||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenPolicy;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -70,13 +64,7 @@ public final class ZenModeDisplayLinkPreferenceControllerTest {
|
|||||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||||
public void testHasSummary() {
|
public void testHasSummary() {
|
||||||
Preference pref = mock(Preference.class);
|
Preference pref = mock(Preference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
mController.updateZenMode(pref, TestModeBuilder.EXAMPLE);
|
||||||
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);
|
|
||||||
verify(pref).setSummary(any());
|
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.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.service.notification.ZenModeConfig;
|
import android.service.notification.ZenModeConfig;
|
||||||
|
|
||||||
@@ -68,10 +67,9 @@ public class ZenModeExitAtAlarmPreferenceControllerTest {
|
|||||||
scheduleInfo.endHour = 2;
|
scheduleInfo.endHour = 2;
|
||||||
scheduleInfo.exitAtAlarm = false;
|
scheduleInfo.exitAtAlarm = false;
|
||||||
|
|
||||||
ZenMode mode = new ZenMode("id",
|
ZenMode mode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("name",
|
.setConditionId(ZenModeConfig.toScheduleConditionId(scheduleInfo))
|
||||||
ZenModeConfig.toScheduleConditionId(scheduleInfo)).build(),
|
.build();
|
||||||
true); // is active
|
|
||||||
|
|
||||||
// need to call updateZenMode for the first call
|
// need to call updateZenMode for the first call
|
||||||
mPrefController.updateZenMode(preference, mode);
|
mPrefController.updateZenMode(preference, mode);
|
||||||
@@ -97,10 +95,9 @@ public class ZenModeExitAtAlarmPreferenceControllerTest {
|
|||||||
scheduleInfo.endHour = 2;
|
scheduleInfo.endHour = 2;
|
||||||
scheduleInfo.exitAtAlarm = true;
|
scheduleInfo.exitAtAlarm = true;
|
||||||
|
|
||||||
ZenMode mode = new ZenMode("id",
|
ZenMode mode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("name",
|
.setConditionId(ZenModeConfig.toScheduleConditionId(scheduleInfo))
|
||||||
ZenModeConfig.toScheduleConditionId(scheduleInfo)).build(),
|
.build();
|
||||||
true); // is active
|
|
||||||
mPrefController.updateZenMode(preference, mode);
|
mPrefController.updateZenMode(preference, mode);
|
||||||
|
|
||||||
// turn off exit at alarm
|
// 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.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -49,10 +47,7 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class ZenModeIconPickerListPreferenceControllerTest {
|
public class ZenModeIconPickerListPreferenceControllerTest {
|
||||||
|
|
||||||
private static final ZenMode ZEN_MODE = new ZenMode(
|
private static final ZenMode ZEN_MODE = TestModeBuilder.EXAMPLE;
|
||||||
"mode_id",
|
|
||||||
new AutomaticZenRule.Builder("mode name", Uri.parse("mode")).build(),
|
|
||||||
/* isActive= */ false);
|
|
||||||
|
|
||||||
private ZenModesBackend mBackend;
|
private ZenModesBackend mBackend;
|
||||||
private ZenModeIconPickerListPreferenceController mController;
|
private ZenModeIconPickerListPreferenceController mController;
|
||||||
|
@@ -16,23 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.modes;
|
package com.android.settings.notification.modes;
|
||||||
|
|
||||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenPolicy;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -70,13 +64,7 @@ public final class ZenModeMessagesLinkPreferenceControllerTest {
|
|||||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||||
public void testHasSummary() {
|
public void testHasSummary() {
|
||||||
Preference pref = mock(Preference.class);
|
Preference pref = mock(Preference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
mController.updateZenMode(pref, TestModeBuilder.EXAMPLE);
|
||||||
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);
|
|
||||||
verify(pref).setSummary(any());
|
verify(pref).setSummary(any());
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -16,23 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.modes;
|
package com.android.settings.notification.modes;
|
||||||
|
|
||||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenPolicy;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -70,13 +64,7 @@ public final class ZenModeNotifVisLinkPreferenceControllerTest {
|
|||||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||||
public void testHasSummary() {
|
public void testHasSummary() {
|
||||||
Preference pref = mock(Preference.class);
|
Preference pref = mock(Preference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
mController.updateZenMode(pref, TestModeBuilder.EXAMPLE);
|
||||||
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);
|
|
||||||
verify(pref).setSummary(any());
|
verify(pref).setSummary(any());
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.modes;
|
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_ALLOW;
|
||||||
import static android.service.notification.ZenPolicy.STATE_DISALLOW;
|
import static android.service.notification.ZenPolicy.STATE_DISALLOW;
|
||||||
import static android.service.notification.ZenPolicy.VISUAL_EFFECT_LIGHTS;
|
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.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenPolicy;
|
import android.service.notification.ZenPolicy;
|
||||||
@@ -99,15 +96,12 @@ public final class ZenModeNotifVisPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void updateState_notChecked() {
|
public void updateState_notChecked() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowAlarms(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.showAllVisualEffects()
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build())
|
||||||
.allowAlarms(true)
|
.build();
|
||||||
.showAllVisualEffects()
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mController.updateZenMode(preference, zenMode);
|
mController.updateZenMode(preference, zenMode);
|
||||||
|
|
||||||
@@ -118,15 +112,12 @@ public final class ZenModeNotifVisPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void updateState_checked() {
|
public void updateState_checked() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowAlarms(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.showVisualEffect(VISUAL_EFFECT_PEEK, false)
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build())
|
||||||
.allowAlarms(true)
|
.build();
|
||||||
.showVisualEffect(VISUAL_EFFECT_PEEK, false)
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mController.updateZenMode(preference, zenMode);
|
mController.updateZenMode(preference, zenMode);
|
||||||
|
|
||||||
@@ -141,16 +132,13 @@ public final class ZenModeNotifVisPreferenceControllerTest {
|
|||||||
"zen_effect_status", VISUAL_EFFECT_STATUS_BAR,
|
"zen_effect_status", VISUAL_EFFECT_STATUS_BAR,
|
||||||
new int[]{VISUAL_EFFECT_NOTIFICATION_LIST}, mBackend);
|
new int[]{VISUAL_EFFECT_NOTIFICATION_LIST}, mBackend);
|
||||||
|
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowAlarms(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.showVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, false)
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.showVisualEffect(VISUAL_EFFECT_STATUS_BAR, true)
|
||||||
.allowAlarms(true)
|
.build())
|
||||||
.showVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, false)
|
.build();
|
||||||
.showVisualEffect(VISUAL_EFFECT_STATUS_BAR, true)
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mController.updateZenMode(preference, zenMode);
|
mController.updateZenMode(preference, zenMode);
|
||||||
|
|
||||||
@@ -171,15 +159,12 @@ public final class ZenModeNotifVisPreferenceControllerTest {
|
|||||||
"zen_effect_status", VISUAL_EFFECT_STATUS_BAR,
|
"zen_effect_status", VISUAL_EFFECT_STATUS_BAR,
|
||||||
new int[]{VISUAL_EFFECT_NOTIFICATION_LIST}, mBackend);
|
new int[]{VISUAL_EFFECT_NOTIFICATION_LIST}, mBackend);
|
||||||
|
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowAlarms(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.showAllVisualEffects()
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build())
|
||||||
.allowAlarms(true)
|
.build();
|
||||||
.showAllVisualEffects()
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mController.updateZenMode(preference, zenMode);
|
mController.updateZenMode(preference, zenMode);
|
||||||
|
|
||||||
@@ -191,15 +176,12 @@ public final class ZenModeNotifVisPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onPreferenceChanged_checkedFalse() {
|
public void onPreferenceChanged_checkedFalse() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowAlarms(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.hideAllVisualEffects()
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build())
|
||||||
.allowAlarms(true)
|
.build();
|
||||||
.hideAllVisualEffects()
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mController.updateZenMode(preference, zenMode);
|
mController.updateZenMode(preference, zenMode);
|
||||||
|
|
||||||
@@ -216,15 +198,12 @@ public final class ZenModeNotifVisPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onPreferenceChanged_checkedTrue() {
|
public void onPreferenceChanged_checkedTrue() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowAlarms(true)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.showAllVisualEffects()
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build())
|
||||||
.allowAlarms(true)
|
.build();
|
||||||
.showAllVisualEffects()
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mController.updateZenMode(preference, zenMode);
|
mController.updateZenMode(preference, zenMode);
|
||||||
|
|
||||||
|
@@ -16,23 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.modes;
|
package com.android.settings.notification.modes;
|
||||||
|
|
||||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenPolicy;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -71,13 +65,7 @@ public final class ZenModeOtherLinkPreferenceControllerTest {
|
|||||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||||
public void testHasSummary() {
|
public void testHasSummary() {
|
||||||
Preference pref = mock(Preference.class);
|
Preference pref = mock(Preference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
mController.updateZenMode(pref, TestModeBuilder.EXAMPLE);
|
||||||
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);
|
|
||||||
verify(pref).setSummary(any());
|
verify(pref).setSummary(any());
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.modes;
|
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_ALLOW;
|
||||||
import static android.service.notification.ZenPolicy.STATE_UNSET;
|
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.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenPolicy;
|
import android.service.notification.ZenPolicy;
|
||||||
@@ -68,12 +65,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_alarms() {
|
public void testUpdateState_alarms() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.build();
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeOtherPreferenceController controller =
|
ZenModeOtherPreferenceController controller =
|
||||||
new ZenModeOtherPreferenceController(mContext, "modes_category_alarm", mBackend);
|
new ZenModeOtherPreferenceController(mContext, "modes_category_alarm", mBackend);
|
||||||
@@ -86,12 +80,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceChange_alarms() {
|
public void testOnPreferenceChange_alarms() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(false).build())
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.build();
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(false).build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeOtherPreferenceController controller =
|
ZenModeOtherPreferenceController controller =
|
||||||
new ZenModeOtherPreferenceController(mContext, "modes_category_alarm", mBackend);
|
new ZenModeOtherPreferenceController(mContext, "modes_category_alarm", mBackend);
|
||||||
@@ -111,12 +102,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_media() {
|
public void testUpdateState_media() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder().allowMedia(true).build())
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.build();
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowMedia(true).build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeOtherPreferenceController controller =
|
ZenModeOtherPreferenceController controller =
|
||||||
new ZenModeOtherPreferenceController(mContext, "modes_category_media", mBackend);
|
new ZenModeOtherPreferenceController(mContext, "modes_category_media", mBackend);
|
||||||
@@ -129,12 +117,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceChange_media() {
|
public void testOnPreferenceChange_media() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder().allowMedia(false).build())
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.build();
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowMedia(false).build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeOtherPreferenceController controller =
|
ZenModeOtherPreferenceController controller =
|
||||||
new ZenModeOtherPreferenceController(mContext, "modes_category_media", mBackend);
|
new ZenModeOtherPreferenceController(mContext, "modes_category_media", mBackend);
|
||||||
@@ -154,12 +139,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_system() {
|
public void testUpdateState_system() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder().allowSystem(true).build())
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.build();
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowSystem(true).build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeOtherPreferenceController controller =
|
ZenModeOtherPreferenceController controller =
|
||||||
new ZenModeOtherPreferenceController(mContext, "modes_category_system", mBackend);
|
new ZenModeOtherPreferenceController(mContext, "modes_category_system", mBackend);
|
||||||
@@ -172,12 +154,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceChange_system() {
|
public void testOnPreferenceChange_system() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder().allowSystem(false).build())
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.build();
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowSystem(false).build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeOtherPreferenceController controller =
|
ZenModeOtherPreferenceController controller =
|
||||||
new ZenModeOtherPreferenceController(mContext, "modes_category_system", mBackend);
|
new ZenModeOtherPreferenceController(mContext, "modes_category_system", mBackend);
|
||||||
@@ -197,12 +176,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_reminders() {
|
public void testUpdateState_reminders() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder().allowReminders(true).build())
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.build();
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowReminders(true).build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeOtherPreferenceController controller =
|
ZenModeOtherPreferenceController controller =
|
||||||
new ZenModeOtherPreferenceController(mContext, "modes_category_reminders",
|
new ZenModeOtherPreferenceController(mContext, "modes_category_reminders",
|
||||||
@@ -216,12 +192,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceChange_reminders() {
|
public void testOnPreferenceChange_reminders() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder().allowReminders(false).build())
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.build();
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowReminders(false).build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeOtherPreferenceController controller =
|
ZenModeOtherPreferenceController controller =
|
||||||
new ZenModeOtherPreferenceController(mContext, "modes_category_reminders",
|
new ZenModeOtherPreferenceController(mContext, "modes_category_reminders",
|
||||||
@@ -242,12 +215,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_events() {
|
public void testUpdateState_events() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder().allowEvents(true).build())
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.build();
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowEvents(true).build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeOtherPreferenceController controller =
|
ZenModeOtherPreferenceController controller =
|
||||||
new ZenModeOtherPreferenceController(mContext, "modes_category_events", mBackend);
|
new ZenModeOtherPreferenceController(mContext, "modes_category_events", mBackend);
|
||||||
@@ -260,12 +230,9 @@ public final class ZenModeOtherPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceChange_events() {
|
public void testOnPreferenceChange_events() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder().allowEvents(false).build())
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.build();
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowEvents(false).build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeOtherPreferenceController controller =
|
ZenModeOtherPreferenceController controller =
|
||||||
new ZenModeOtherPreferenceController(mContext, "modes_category_events", mBackend);
|
new ZenModeOtherPreferenceController(mContext, "modes_category_events", mBackend);
|
||||||
|
@@ -16,23 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.modes;
|
package com.android.settings.notification.modes;
|
||||||
|
|
||||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenPolicy;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
|
||||||
import com.android.settingslib.notification.modes.ZenModesBackend;
|
import com.android.settingslib.notification.modes.ZenModesBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -72,13 +66,7 @@ public final class ZenModePeopleLinkPreferenceControllerTest {
|
|||||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||||
public void testHasSummary() {
|
public void testHasSummary() {
|
||||||
Preference pref = mock(Preference.class);
|
Preference pref = mock(Preference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
mController.updateZenMode(pref, TestModeBuilder.EXAMPLE);
|
||||||
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);
|
|
||||||
verify(pref).setSummary(any());
|
verify(pref).setSummary(any());
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.modes;
|
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_ANYONE;
|
||||||
import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_IMPORTANT;
|
import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_IMPORTANT;
|
||||||
import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_NONE;
|
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.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenPolicy;
|
import android.service.notification.ZenPolicy;
|
||||||
@@ -441,20 +438,17 @@ public final class ZenModePrioritySendersPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPreferenceClick_passesCorrectCheckedState_startingUnchecked_messages() {
|
public void testPreferenceClick_passesCorrectCheckedState_startingUnchecked_messages() {
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.disallowAllSounds()
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build())
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build();
|
||||||
.disallowAllSounds()
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mMessagesController.displayPreference(mPreferenceScreen);
|
mMessagesController.displayPreference(mPreferenceScreen);
|
||||||
mMessagesController.updateZenMode(mMessagesPrefCategory, zenMode);
|
mMessagesController.updateZenMode(mMessagesPrefCategory, zenMode);
|
||||||
|
|
||||||
assertThat(((SelectorWithWidgetPreference) mMessagesPrefCategory.findPreference(KEY_NONE))
|
assertThat(((SelectorWithWidgetPreference) mMessagesPrefCategory.findPreference(KEY_NONE))
|
||||||
.isChecked());
|
.isChecked()).isTrue();
|
||||||
|
|
||||||
mMessagesPrefCategory.findPreference(KEY_STARRED).performClick();
|
mMessagesPrefCategory.findPreference(KEY_STARRED).performClick();
|
||||||
|
|
||||||
@@ -466,14 +460,11 @@ public final class ZenModePrioritySendersPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPreferenceClick_passesCorrectCheckedState_startingChecked_messages() {
|
public void testPreferenceClick_passesCorrectCheckedState_startingChecked_messages() {
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowAllSounds()
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build())
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build();
|
||||||
.allowAllSounds()
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mMessagesController.displayPreference(mPreferenceScreen);
|
mMessagesController.displayPreference(mPreferenceScreen);
|
||||||
mMessagesController.updateZenMode(mMessagesPrefCategory, zenMode);
|
mMessagesController.updateZenMode(mMessagesPrefCategory, zenMode);
|
||||||
@@ -492,14 +483,11 @@ public final class ZenModePrioritySendersPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPreferenceClick_passesCorrectCheckedState_startingUnchecked_calls() {
|
public void testPreferenceClick_passesCorrectCheckedState_startingUnchecked_calls() {
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.disallowAllSounds()
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build())
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build();
|
||||||
.disallowAllSounds()
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mCallsController.displayPreference(mPreferenceScreen);
|
mCallsController.displayPreference(mPreferenceScreen);
|
||||||
mCallsController.updateZenMode(mCallsPrefCategory, zenMode);
|
mCallsController.updateZenMode(mCallsPrefCategory, zenMode);
|
||||||
@@ -517,14 +505,11 @@ public final class ZenModePrioritySendersPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPreferenceClick_passesCorrectCheckedState_startingChecked_calls() {
|
public void testPreferenceClick_passesCorrectCheckedState_startingChecked_calls() {
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.disallowAllSounds()
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build())
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build();
|
||||||
.disallowAllSounds()
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
mCallsController.displayPreference(mPreferenceScreen);
|
mCallsController.displayPreference(mPreferenceScreen);
|
||||||
mCallsController.updateZenMode(mCallsPrefCategory, zenMode);
|
mCallsController.updateZenMode(mCallsPrefCategory, zenMode);
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.modes;
|
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_ANYONE;
|
||||||
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_STARRED;
|
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_STARRED;
|
||||||
import static android.service.notification.ZenPolicy.STATE_DISALLOW;
|
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.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.ZenPolicy;
|
import android.service.notification.ZenPolicy;
|
||||||
@@ -70,14 +67,11 @@ public final class ZenModeRepeatCallersPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_allCalls() {
|
public void testUpdateState_allCalls() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowCalls(PEOPLE_TYPE_ANYONE)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.build())
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build();
|
||||||
.allowCalls(PEOPLE_TYPE_ANYONE)
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeRepeatCallersPreferenceController controller =
|
ZenModeRepeatCallersPreferenceController controller =
|
||||||
new ZenModeRepeatCallersPreferenceController(mContext, "repeat", mBackend, 1);
|
new ZenModeRepeatCallersPreferenceController(mContext, "repeat", mBackend, 1);
|
||||||
@@ -91,15 +85,12 @@ public final class ZenModeRepeatCallersPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_someCalls() {
|
public void testUpdateState_someCalls() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.allowCalls(PEOPLE_TYPE_STARRED)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.allowRepeatCallers(true)
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.build())
|
||||||
.allowCalls(PEOPLE_TYPE_STARRED)
|
.build();
|
||||||
.allowRepeatCallers(true)
|
|
||||||
.build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeRepeatCallersPreferenceController controller =
|
ZenModeRepeatCallersPreferenceController controller =
|
||||||
new ZenModeRepeatCallersPreferenceController(mContext, "repeat", mBackend, 1);
|
new ZenModeRepeatCallersPreferenceController(mContext, "repeat", mBackend, 1);
|
||||||
@@ -113,12 +104,9 @@ public final class ZenModeRepeatCallersPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceChange() {
|
public void testOnPreferenceChange() {
|
||||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
.setZenPolicy(new ZenPolicy.Builder().allowRepeatCallers(true).build())
|
||||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
.build();
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowRepeatCallers(true).build())
|
|
||||||
.build(), true);
|
|
||||||
|
|
||||||
ZenModeRepeatCallersPreferenceController controller =
|
ZenModeRepeatCallersPreferenceController controller =
|
||||||
new ZenModeRepeatCallersPreferenceController(mContext, "repeat", mBackend, 1);
|
new ZenModeRepeatCallersPreferenceController(mContext, "repeat", mBackend, 1);
|
||||||
@@ -136,4 +124,4 @@ public final class ZenModeRepeatCallersPreferenceControllerTest {
|
|||||||
assertThat(captor.getValue().getPolicy().getPriorityCallSenders())
|
assertThat(captor.getValue().getPolicy().getPriorityCallSenders())
|
||||||
.isEqualTo(STATE_UNSET);
|
.isEqualTo(STATE_UNSET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,10 +28,8 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.SystemZenRules;
|
import android.service.notification.SystemZenRules;
|
||||||
@@ -88,11 +86,9 @@ public class ZenModeSetCalendarPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
@EnableFlags({Flags.FLAG_MODES_API, Flags.FLAG_MODES_UI})
|
@EnableFlags({Flags.FLAG_MODES_API, Flags.FLAG_MODES_UI})
|
||||||
public void updateEventMode_updatesConditionAndTriggerDescription() {
|
public void updateEventMode_updatesConditionAndTriggerDescription() {
|
||||||
ZenMode mode = new ZenMode("id",
|
ZenMode mode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("name", Uri.parse("condition"))
|
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
.build();
|
||||||
.build(),
|
|
||||||
true); // is active
|
|
||||||
|
|
||||||
// Explicitly update preference controller with mode info first, which will also call
|
// Explicitly update preference controller with mode info first, which will also call
|
||||||
// updateState()
|
// updateState()
|
||||||
@@ -118,10 +114,9 @@ public class ZenModeSetCalendarPreferenceControllerTest {
|
|||||||
eventInfo.calName = "Definitely A Calendar";
|
eventInfo.calName = "Definitely A Calendar";
|
||||||
eventInfo.reply = REPLY_YES;
|
eventInfo.reply = REPLY_YES;
|
||||||
|
|
||||||
ZenMode mode = new ZenMode("id",
|
ZenMode mode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("name",
|
.setConditionId(ZenModeConfig.toEventConditionId(eventInfo))
|
||||||
ZenModeConfig.toEventConditionId(eventInfo)).build(),
|
.build();
|
||||||
true); // is active
|
|
||||||
mPrefController.updateZenMode(mPrefCategory, mode);
|
mPrefController.updateZenMode(mPrefCategory, mode);
|
||||||
|
|
||||||
// We should see mCalendar, mReply have their values set
|
// 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.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.app.Flags;
|
import android.app.Flags;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.SystemZenRules;
|
import android.service.notification.SystemZenRules;
|
||||||
@@ -83,11 +81,9 @@ public class ZenModeSetSchedulePreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
@EnableFlags({Flags.FLAG_MODES_API, Flags.FLAG_MODES_UI})
|
@EnableFlags({Flags.FLAG_MODES_API, Flags.FLAG_MODES_UI})
|
||||||
public void updateScheduleRule_updatesConditionAndTriggerDescription() {
|
public void updateScheduleRule_updatesConditionAndTriggerDescription() {
|
||||||
ZenMode mode = new ZenMode("id",
|
ZenMode mode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("name", Uri.parse("condition"))
|
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
.build();
|
||||||
.build(),
|
|
||||||
true); // is active
|
|
||||||
|
|
||||||
ZenModeConfig.ScheduleInfo scheduleInfo = new ZenModeConfig.ScheduleInfo();
|
ZenModeConfig.ScheduleInfo scheduleInfo = new ZenModeConfig.ScheduleInfo();
|
||||||
scheduleInfo.days = new int[] { Calendar.MONDAY };
|
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.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.service.notification.SystemZenRules;
|
import android.service.notification.SystemZenRules;
|
||||||
import android.service.notification.ZenModeConfig;
|
import android.service.notification.ZenModeConfig;
|
||||||
import android.service.notification.ZenPolicy;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
@@ -102,26 +101,13 @@ public class ZenModeSetTriggerLinkPreferenceControllerTest {
|
|||||||
assertThat(mPrefController.isAvailable()).isFalse();
|
assertThat(mPrefController.isAvailable()).isFalse();
|
||||||
|
|
||||||
// should be available for other modes
|
// should be available for other modes
|
||||||
ZenMode zenMode = new ZenMode("id",
|
mPrefController.updateZenMode(mPrefCategory, TestModeBuilder.EXAMPLE);
|
||||||
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);
|
|
||||||
assertThat(mPrefController.isAvailable()).isTrue();
|
assertThat(mPrefController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState() {
|
public void testUpdateState() {
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder().setEnabled(false).build();
|
||||||
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);
|
|
||||||
|
|
||||||
// Update preference controller with a zen mode that is not enabled
|
// Update preference controller with a zen mode that is not enabled
|
||||||
mPrefController.updateZenMode(mPrefCategory, zenMode);
|
mPrefController.updateZenMode(mPrefCategory, zenMode);
|
||||||
@@ -135,13 +121,7 @@ public class ZenModeSetTriggerLinkPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceChange() {
|
public void testOnPreferenceChange() {
|
||||||
ZenMode zenMode = new ZenMode("id",
|
ZenMode zenMode = new TestModeBuilder().setEnabled(false).build();
|
||||||
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);
|
|
||||||
|
|
||||||
// start with disabled rule
|
// start with disabled rule
|
||||||
mPrefController.updateZenMode(mPrefCategory, zenMode);
|
mPrefController.updateZenMode(mPrefCategory, zenMode);
|
||||||
@@ -160,13 +140,12 @@ public class ZenModeSetTriggerLinkPreferenceControllerTest {
|
|||||||
ZenModeConfig.EventInfo eventInfo = new ZenModeConfig.EventInfo();
|
ZenModeConfig.EventInfo eventInfo = new ZenModeConfig.EventInfo();
|
||||||
eventInfo.calendarId = 1L;
|
eventInfo.calendarId = 1L;
|
||||||
eventInfo.calName = "My events";
|
eventInfo.calName = "My events";
|
||||||
ZenMode mode = new ZenMode("id", new AutomaticZenRule.Builder("name",
|
ZenMode mode = new TestModeBuilder()
|
||||||
ZenModeConfig.toEventConditionId(eventInfo))
|
|
||||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||||
|
.setConditionId(ZenModeConfig.toEventConditionId(eventInfo))
|
||||||
.setType(TYPE_SCHEDULE_CALENDAR)
|
.setType(TYPE_SCHEDULE_CALENDAR)
|
||||||
.setTriggerDescription("My events")
|
.setTriggerDescription("My events")
|
||||||
.build(),
|
.build();
|
||||||
true); // is active
|
|
||||||
mPrefController.updateZenMode(mPrefCategory, mode);
|
mPrefController.updateZenMode(mPrefCategory, mode);
|
||||||
|
|
||||||
assertThat(mPreference.getTitle()).isNotNull();
|
assertThat(mPreference.getTitle()).isNotNull();
|
||||||
@@ -188,13 +167,12 @@ public class ZenModeSetTriggerLinkPreferenceControllerTest {
|
|||||||
scheduleInfo.days = new int[] { Calendar.MONDAY, Calendar.TUESDAY, Calendar.THURSDAY };
|
scheduleInfo.days = new int[] { Calendar.MONDAY, Calendar.TUESDAY, Calendar.THURSDAY };
|
||||||
scheduleInfo.startHour = 1;
|
scheduleInfo.startHour = 1;
|
||||||
scheduleInfo.endHour = 15;
|
scheduleInfo.endHour = 15;
|
||||||
ZenMode mode = new ZenMode("id", new AutomaticZenRule.Builder("name",
|
ZenMode mode = new TestModeBuilder()
|
||||||
ZenModeConfig.toScheduleConditionId(scheduleInfo))
|
.setConditionId(ZenModeConfig.toScheduleConditionId(scheduleInfo))
|
||||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||||
.setType(TYPE_SCHEDULE_TIME)
|
.setType(TYPE_SCHEDULE_TIME)
|
||||||
.setTriggerDescription("some schedule")
|
.setTriggerDescription("some schedule")
|
||||||
.build(),
|
.build();
|
||||||
true); // is active
|
|
||||||
mPrefController.updateZenMode(mPrefCategory, mode);
|
mPrefController.updateZenMode(mPrefCategory, mode);
|
||||||
|
|
||||||
assertThat(mPreference.getTitle()).isNotNull();
|
assertThat(mPreference.getTitle()).isNotNull();
|
||||||
@@ -212,13 +190,12 @@ public class ZenModeSetTriggerLinkPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRuleLink_manual() {
|
public void testRuleLink_manual() {
|
||||||
ZenMode mode = new ZenMode("id", new AutomaticZenRule.Builder("name",
|
ZenMode mode = new TestModeBuilder()
|
||||||
ZenModeConfig.toCustomManualConditionId())
|
.setConditionId(ZenModeConfig.toCustomManualConditionId())
|
||||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||||
.setType(TYPE_OTHER)
|
.setType(TYPE_OTHER)
|
||||||
.setTriggerDescription("Will not be shown")
|
.setTriggerDescription("Will not be shown")
|
||||||
.build(),
|
.build();
|
||||||
true); // is active
|
|
||||||
mPrefController.updateZenMode(mPrefCategory, mode);
|
mPrefController.updateZenMode(mPrefCategory, mode);
|
||||||
|
|
||||||
assertThat(mPreference.getTitle()).isNotNull();
|
assertThat(mPreference.getTitle()).isNotNull();
|
||||||
@@ -234,13 +211,12 @@ public class ZenModeSetTriggerLinkPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onScheduleChosen_updatesMode() {
|
public void onScheduleChosen_updatesMode() {
|
||||||
ZenMode originalMode = new ZenMode("id",
|
ZenMode originalMode = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder("name", ZenModeConfig.toCustomManualConditionId())
|
.setConditionId(ZenModeConfig.toCustomManualConditionId())
|
||||||
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
.setPackage(SystemZenRules.PACKAGE_ANDROID)
|
||||||
.setType(TYPE_OTHER)
|
.setType(TYPE_OTHER)
|
||||||
.setTriggerDescription("")
|
.setTriggerDescription("")
|
||||||
.build(),
|
.build();
|
||||||
false);
|
|
||||||
mPrefController.updateZenMode(mPrefCategory, originalMode);
|
mPrefController.updateZenMode(mPrefCategory, originalMode);
|
||||||
|
|
||||||
ZenModeConfig.ScheduleInfo scheduleInfo = new ZenModeConfig.ScheduleInfo();
|
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 {
|
public class ZenModesListPreferenceControllerTest {
|
||||||
private static final String TEST_MODE_ID = "test_mode";
|
private static final String TEST_MODE_ID = "test_mode";
|
||||||
private static final String TEST_MODE_NAME = "Test Mode";
|
private static final String TEST_MODE_NAME = "Test Mode";
|
||||||
private static final ZenMode TEST_MODE = new ZenMode(
|
|
||||||
TEST_MODE_ID,
|
private static final ZenMode TEST_MODE = new TestModeBuilder()
|
||||||
new AutomaticZenRule.Builder(TEST_MODE_NAME, Uri.parse("test_uri"))
|
.setId(TEST_MODE_ID)
|
||||||
|
.setAzr(new AutomaticZenRule.Builder(TEST_MODE_NAME, Uri.parse("test_uri"))
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||||
.build(),
|
.build())
|
||||||
false);
|
.build();
|
||||||
|
|
||||||
private static final ZenMode TEST_MANUAL_MODE = ZenMode.manualDndMode(
|
private static final ZenMode TEST_MANUAL_MODE = ZenMode.manualDndMode(
|
||||||
new AutomaticZenRule.Builder("Do Not Disturb", Uri.EMPTY)
|
new AutomaticZenRule.Builder("Do Not Disturb", Uri.EMPTY)
|
||||||
@@ -112,14 +113,9 @@ public class ZenModesListPreferenceControllerTest {
|
|||||||
|
|
||||||
assertThat(mPreference.getPreferenceCount()).isEqualTo(5);
|
assertThat(mPreference.getPreferenceCount()).isEqualTo(5);
|
||||||
List<ZenModesListItemPreference> itemPreferences = getModeListItems(mPreference);
|
List<ZenModesListItemPreference> itemPreferences = getModeListItems(mPreference);
|
||||||
assertThat(itemPreferences.stream().map(pref -> pref.mZenMode).toList())
|
assertThat(itemPreferences.stream().map(ZenModesListItemPreference::getZenMode).toList())
|
||||||
.containsExactlyElementsIn(modes)
|
.containsExactlyElementsIn(modes)
|
||||||
.inOrder();
|
.inOrder();
|
||||||
|
|
||||||
for (int i = 0; i < modes.size(); i++) {
|
|
||||||
assertThat(((ZenModesListItemPreference) (mPreference.getPreference(i))).mZenMode)
|
|
||||||
.isEqualTo(modes.get(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -140,7 +136,7 @@ public class ZenModesListPreferenceControllerTest {
|
|||||||
mPrefController.updateState(mPreference);
|
mPrefController.updateState(mPreference);
|
||||||
|
|
||||||
List<ZenModesListItemPreference> newPreferences = getModeListItems(mPreference);
|
List<ZenModesListItemPreference> newPreferences = getModeListItems(mPreference);
|
||||||
assertThat(newPreferences.stream().map(pref -> pref.mZenMode).toList())
|
assertThat(newPreferences.stream().map(ZenModesListItemPreference::getZenMode).toList())
|
||||||
.containsExactlyElementsIn(updatedModes)
|
.containsExactlyElementsIn(updatedModes)
|
||||||
.inOrder();
|
.inOrder();
|
||||||
|
|
||||||
@@ -196,7 +192,7 @@ public class ZenModesListPreferenceControllerTest {
|
|||||||
assertThat(newData).hasSize(1);
|
assertThat(newData).hasSize(1);
|
||||||
|
|
||||||
SearchIndexableRaw newItem = newData.get(0);
|
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
|
assertThat(newItem.title).isEqualTo("Do Not Disturb"); // set above
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +207,7 @@ public class ZenModesListPreferenceControllerTest {
|
|||||||
|
|
||||||
// Should keep the order presented by getModes()
|
// Should keep the order presented by getModes()
|
||||||
SearchIndexableRaw item0 = data.get(0);
|
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
|
assertThat(item0.title).isEqualTo("Do Not Disturb"); // set above
|
||||||
|
|
||||||
SearchIndexableRaw item1 = data.get(1);
|
SearchIndexableRaw item1 = data.get(1);
|
||||||
@@ -220,13 +216,7 @@ public class ZenModesListPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ZenMode newMode(String id) {
|
private static ZenMode newMode(String id) {
|
||||||
return new ZenMode(
|
return new TestModeBuilder().setId(id).setName("Mode " + id).build();
|
||||||
id,
|
|
||||||
new AutomaticZenRule.Builder("Mode " + id, Uri.parse("test_uri"))
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
|
||||||
.build(),
|
|
||||||
false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.modes;
|
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_ANYONE;
|
||||||
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_ANYONE;
|
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_ANYONE;
|
||||||
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_CONTACTS;
|
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 static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.service.notification.ZenDeviceEffects;
|
import android.service.notification.ZenDeviceEffects;
|
||||||
import android.service.notification.ZenPolicy;
|
import android.service.notification.ZenPolicy;
|
||||||
|
|
||||||
@@ -59,50 +56,38 @@ public class ZenModesSummaryHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPeopleSummary_noOne() {
|
public void getPeopleSummary_noOne() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().disallowAllSounds().build())
|
.setZenPolicy(new ZenPolicy.Builder().disallowAllSounds().build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getPeopleSummary(zenMode)).isEqualTo("No one can interrupt");
|
assertThat(mSummaryHelper.getPeopleSummary(zenMode)).isEqualTo("No one can interrupt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPeopleSummary_some() {
|
public void getPeopleSummary_some() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowCalls(PEOPLE_TYPE_CONTACTS).build())
|
.setZenPolicy(new ZenPolicy.Builder().allowCalls(PEOPLE_TYPE_CONTACTS).build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getPeopleSummary(zenMode)).isEqualTo("Some people can interrupt");
|
assertThat(mSummaryHelper.getPeopleSummary(zenMode)).isEqualTo("Some people can interrupt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPeopleSummary_all() {
|
public void getPeopleSummary_all() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowCalls(PEOPLE_TYPE_ANYONE).
|
.setZenPolicy(new ZenPolicy.Builder().allowCalls(PEOPLE_TYPE_ANYONE).
|
||||||
allowConversations(CONVERSATION_SENDERS_ANYONE)
|
allowConversations(CONVERSATION_SENDERS_ANYONE)
|
||||||
.allowMessages(PEOPLE_TYPE_ANYONE).build())
|
.allowMessages(PEOPLE_TYPE_ANYONE).build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getPeopleSummary(zenMode)).isEqualTo("All people can interrupt");
|
assertThat(mSummaryHelper.getPeopleSummary(zenMode)).isEqualTo("All people can interrupt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getOtherSoundCategoriesSummary_single() {
|
public void getOtherSoundCategoriesSummary_single() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
||||||
"Alarms can interrupt");
|
"Alarms can interrupt");
|
||||||
@@ -110,12 +95,9 @@ public class ZenModesSummaryHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getOtherSoundCategoriesSummary_duo() {
|
public void getOtherSoundCategoriesSummary_duo() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).allowMedia(true).build())
|
.setZenPolicy(new ZenPolicy.Builder().allowAlarms(true).allowMedia(true).build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
||||||
"Alarms and media can interrupt");
|
"Alarms and media can interrupt");
|
||||||
@@ -123,16 +105,13 @@ public class ZenModesSummaryHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getOtherSoundCategoriesSummary_trio() {
|
public void getOtherSoundCategoriesSummary_trio() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.allowAlarms(true)
|
.allowAlarms(true)
|
||||||
.allowMedia(true)
|
.allowMedia(true)
|
||||||
.allowSystem(true)
|
.allowSystem(true)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
||||||
"Alarms, media, and touch sounds can interrupt");
|
"Alarms, media, and touch sounds can interrupt");
|
||||||
@@ -140,9 +119,7 @@ public class ZenModesSummaryHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getOtherSoundCategoriesSummary_quad() {
|
public void getOtherSoundCategoriesSummary_quad() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.allowAlarms(true)
|
.allowAlarms(true)
|
||||||
.allowMedia(true)
|
.allowMedia(true)
|
||||||
@@ -150,7 +127,6 @@ public class ZenModesSummaryHelperTest {
|
|||||||
.allowReminders(true)
|
.allowReminders(true)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
||||||
"Alarms, media, and 2 more can interrupt");
|
"Alarms, media, and 2 more can interrupt");
|
||||||
@@ -158,9 +134,7 @@ public class ZenModesSummaryHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getOtherSoundCategoriesSummary_all() {
|
public void getOtherSoundCategoriesSummary_all() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.allowAlarms(true)
|
.allowAlarms(true)
|
||||||
.allowMedia(true)
|
.allowMedia(true)
|
||||||
@@ -169,7 +143,6 @@ public class ZenModesSummaryHelperTest {
|
|||||||
.allowEvents(true)
|
.allowEvents(true)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
assertThat(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode)).isEqualTo(
|
||||||
"Alarms, media, and 3 more can interrupt");
|
"Alarms, media, and 3 more can interrupt");
|
||||||
@@ -177,61 +150,52 @@ public class ZenModesSummaryHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getBlockedEffectsSummary_none() {
|
public void getBlockedEffectsSummary_none() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.showAllVisualEffects()
|
.showAllVisualEffects()
|
||||||
.allowAlarms(true)
|
.allowAlarms(true)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
assertThat(mSummaryHelper.getBlockedEffectsSummary(zenMode))
|
assertThat(mSummaryHelper.getBlockedEffectsSummary(zenMode))
|
||||||
.isEqualTo("Notifications shown");
|
.isEqualTo("Notifications shown");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getBlockedEffectsSummary_some() {
|
public void getBlockedEffectsSummary_some() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.allowAlarms(true)
|
.allowAlarms(true)
|
||||||
.showAllVisualEffects()
|
.showAllVisualEffects()
|
||||||
.showVisualEffect(VISUAL_EFFECT_AMBIENT, false)
|
.showVisualEffect(VISUAL_EFFECT_AMBIENT, false)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
assertThat(mSummaryHelper.getBlockedEffectsSummary(zenMode))
|
assertThat(mSummaryHelper.getBlockedEffectsSummary(zenMode))
|
||||||
.isEqualTo("Notifications partially hidden");
|
.isEqualTo("Notifications partially hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getBlockedEffectsSummary_all() {
|
public void getBlockedEffectsSummary_all() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.allowAlarms(true)
|
.allowAlarms(true)
|
||||||
.hideAllVisualEffects()
|
.hideAllVisualEffects()
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
assertThat(mSummaryHelper.getBlockedEffectsSummary(zenMode))
|
assertThat(mSummaryHelper.getBlockedEffectsSummary(zenMode))
|
||||||
.isEqualTo("Notifications hidden");
|
.isEqualTo("Notifications hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDisplayEffectsSummary_single_notifVis() {
|
public void getDisplayEffectsSummary_single_notifVis() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.showAllVisualEffects()
|
.showAllVisualEffects()
|
||||||
.showVisualEffect(VISUAL_EFFECT_AMBIENT, false)
|
.showVisualEffect(VISUAL_EFFECT_AMBIENT, false)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
||||||
"Notifications partially hidden");
|
"Notifications partially hidden");
|
||||||
@@ -239,15 +203,12 @@ public class ZenModesSummaryHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDisplayEffectsSummary_single_notifVis_unusedEffect() {
|
public void getDisplayEffectsSummary_single_notifVis_unusedEffect() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.showAllVisualEffects()
|
.showAllVisualEffects()
|
||||||
.showVisualEffect(VISUAL_EFFECT_LIGHTS, false)
|
.showVisualEffect(VISUAL_EFFECT_LIGHTS, false)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
||||||
"Notifications shown");
|
"Notifications shown");
|
||||||
@@ -255,15 +216,12 @@ public class ZenModesSummaryHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDisplayEffectsSummary_single_displayEffect() {
|
public void getDisplayEffectsSummary_single_displayEffect() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().showAllVisualEffects().build())
|
.setZenPolicy(new ZenPolicy.Builder().showAllVisualEffects().build())
|
||||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||||
.setShouldDimWallpaper(true)
|
.setShouldDimWallpaper(true)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
||||||
"Dim the wallpaper");
|
"Dim the wallpaper");
|
||||||
@@ -271,16 +229,13 @@ public class ZenModesSummaryHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDisplayEffectsSummary_duo() {
|
public void getDisplayEffectsSummary_duo() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder().showAllVisualEffects().build())
|
.setZenPolicy(new ZenPolicy.Builder().showAllVisualEffects().build())
|
||||||
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
.setDeviceEffects(new ZenDeviceEffects.Builder()
|
||||||
.setShouldDimWallpaper(true)
|
.setShouldDimWallpaper(true)
|
||||||
.setShouldDisplayGrayscale(true)
|
.setShouldDisplayGrayscale(true)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
||||||
"Grayscale and dim the wallpaper");
|
"Grayscale and dim the wallpaper");
|
||||||
@@ -288,9 +243,7 @@ public class ZenModesSummaryHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDisplayEffectsSummary_trio() {
|
public void getDisplayEffectsSummary_trio() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.hideAllVisualEffects()
|
.hideAllVisualEffects()
|
||||||
.allowAlarms(true)
|
.allowAlarms(true)
|
||||||
@@ -302,7 +255,6 @@ public class ZenModesSummaryHelperTest {
|
|||||||
.setShouldDimWallpaper(true)
|
.setShouldDimWallpaper(true)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
||||||
"Notifications hidden, grayscale, and dim the wallpaper");
|
"Notifications hidden, grayscale, and dim the wallpaper");
|
||||||
@@ -310,9 +262,7 @@ public class ZenModesSummaryHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDisplayEffectsSummary_quad() {
|
public void getDisplayEffectsSummary_quad() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.showAllVisualEffects()
|
.showAllVisualEffects()
|
||||||
.showVisualEffect(VISUAL_EFFECT_AMBIENT, false)
|
.showVisualEffect(VISUAL_EFFECT_AMBIENT, false)
|
||||||
@@ -326,7 +276,6 @@ public class ZenModesSummaryHelperTest {
|
|||||||
.setShouldUseNightMode(true)
|
.setShouldUseNightMode(true)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
||||||
"Notifications partially hidden, grayscale, and 2 more");
|
"Notifications partially hidden, grayscale, and 2 more");
|
||||||
@@ -334,28 +283,22 @@ public class ZenModesSummaryHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAppsSummary_none() {
|
public void getAppsSummary_none() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getAppsSummary(zenMode, new LinkedHashSet<>())).isEqualTo("None");
|
assertThat(mSummaryHelper.getAppsSummary(zenMode, new LinkedHashSet<>())).isEqualTo("None");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAppsSummary_priorityAppsNoList() {
|
public void getAppsSummary_priorityAppsNoList() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getAppsSummary(zenMode, null)).isEqualTo("Selected apps");
|
assertThat(mSummaryHelper.getAppsSummary(zenMode, null)).isEqualTo("Selected apps");
|
||||||
}
|
}
|
||||||
@@ -397,19 +340,15 @@ public class ZenModesSummaryHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAppsSummary_priorityApps() {
|
public void getAppsSummary_priorityApps() {
|
||||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
ZenMode zenMode = new TestModeBuilder()
|
||||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
|
||||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
|
||||||
.setZenPolicy(new ZenPolicy.Builder()
|
.setZenPolicy(new ZenPolicy.Builder()
|
||||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
|
||||||
Set<String> apps = Set.of("My App", "SecondApp", "ThirdApp", "FourthApp",
|
Set<String> apps = Set.of("My App", "SecondApp", "ThirdApp", "FourthApp",
|
||||||
"FifthApp", "SixthApp");
|
"FifthApp", "SixthApp");
|
||||||
|
|
||||||
assertThat(mSummaryHelper.getAppsSummary(zenMode, apps)).isEqualTo("FifthApp, FourthApp, "
|
assertThat(mSummaryHelper.getAppsSummary(zenMode, apps)).isEqualTo("FifthApp, FourthApp, "
|
||||||
+ "and 4 more can interrupt");
|
+ "and 4 more can interrupt");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user