Merge "System gets its own dnd toggle" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1e9268b52e
@@ -7549,10 +7549,10 @@
|
|||||||
<string name="zen_mode_alarms">Alarms</string>
|
<string name="zen_mode_alarms">Alarms</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=50] Zen mode settings: Media option -->
|
<!-- [CHAR LIMIT=50] Zen mode settings: Media option -->
|
||||||
<string name="zen_mode_media_system_other">Media</string>
|
<string name="zen_mode_media">Media</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=120] Zen mode settings: Media secondary text explaining sounds include system feedback such as system tapping sounds, haptic feedback, etc. -->
|
<!-- [CHAR LIMIT=50] Zen mode settings: System option which includes sounds such as touch and charging sounds -->
|
||||||
<string name="zen_mode_media_system_other_secondary_text">Includes system feedback like touch and charging sounds</string>
|
<string name="zen_mode_system">Touch and charging sounds</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=50] Zen mode settings: Reminders option -->
|
<!-- [CHAR LIMIT=50] Zen mode settings: Reminders option -->
|
||||||
<string name="zen_mode_reminders">Reminders</string>
|
<string name="zen_mode_reminders">Reminders</string>
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
android:key="zen_mode_behavior_settings_page"
|
android:key="zen_mode_behavior_settings_page"
|
||||||
android:title="@string/zen_mode_behavior_settings_title"
|
android:title="@string/zen_mode_behavior_settings_title"
|
||||||
settings:initialExpandedChildrenCount="7">
|
settings:initialExpandedChildrenCount="8">
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="@string/zen_mode_behavior_allow_title"
|
android:title="@string/zen_mode_behavior_allow_title"
|
||||||
@@ -34,8 +34,12 @@
|
|||||||
<!-- Media -->
|
<!-- Media -->
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="zen_mode_media"
|
android:key="zen_mode_media"
|
||||||
android:title="@string/zen_mode_media_system_other"
|
android:title="@string/zen_mode_media"/>
|
||||||
android:summary="@string/zen_mode_media_system_other_secondary_text"/>
|
|
||||||
|
<!-- System -->
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="zen_mode_system"
|
||||||
|
android:title="@string/zen_mode_system"/>
|
||||||
|
|
||||||
<!-- Reminders -->
|
<!-- Reminders -->
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
|
@@ -40,7 +40,8 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
|
|||||||
Lifecycle lifecycle) {
|
Lifecycle lifecycle) {
|
||||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle));
|
controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle));
|
||||||
controllers.add(new ZenModeMediaSystemOtherPreferenceController(context, lifecycle));
|
controllers.add(new ZenModeMediaPreferenceController(context, lifecycle));
|
||||||
|
controllers.add(new ZenModeSystemPreferenceController(context, lifecycle));
|
||||||
controllers.add(new ZenModeEventsPreferenceController(context, lifecycle));
|
controllers.add(new ZenModeEventsPreferenceController(context, lifecycle));
|
||||||
controllers.add(new ZenModeRemindersPreferenceController(context, lifecycle));
|
controllers.add(new ZenModeRemindersPreferenceController(context, lifecycle));
|
||||||
controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle));
|
controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle));
|
||||||
@@ -85,7 +86,7 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
|
|||||||
public List<String> getNonIndexableKeys(Context context) {
|
public List<String> getNonIndexableKeys(Context context) {
|
||||||
final List<String> keys = super.getNonIndexableKeys(context);
|
final List<String> keys = super.getNonIndexableKeys(context);
|
||||||
keys.add(ZenModeAlarmsPreferenceController.KEY);
|
keys.add(ZenModeAlarmsPreferenceController.KEY);
|
||||||
keys.add(ZenModeMediaSystemOtherPreferenceController.KEY);
|
keys.add(ZenModeMediaPreferenceController.KEY);
|
||||||
keys.add(ZenModeEventsPreferenceController.KEY);
|
keys.add(ZenModeEventsPreferenceController.KEY);
|
||||||
keys.add(ZenModeRemindersPreferenceController.KEY);
|
keys.add(ZenModeRemindersPreferenceController.KEY);
|
||||||
keys.add(ZenModeMessagesPreferenceController.KEY);
|
keys.add(ZenModeMessagesPreferenceController.KEY);
|
||||||
|
@@ -25,13 +25,13 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
public class ZenModeMediaSystemOtherPreferenceController extends AbstractZenModePreferenceController
|
public class ZenModeMediaPreferenceController extends AbstractZenModePreferenceController
|
||||||
implements Preference.OnPreferenceChangeListener {
|
implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
protected static final String KEY = "zen_mode_media";
|
protected static final String KEY = "zen_mode_media";
|
||||||
private final ZenModeBackend mBackend;
|
private final ZenModeBackend mBackend;
|
||||||
|
|
||||||
public ZenModeMediaSystemOtherPreferenceController(Context context, Lifecycle lifecycle) {
|
public ZenModeMediaPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
super(context, KEY, lifecycle);
|
super(context, KEY, lifecycle);
|
||||||
mBackend = ZenModeBackend.getInstance(context);
|
mBackend = ZenModeBackend.getInstance(context);
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ public class ZenModeMediaSystemOtherPreferenceController extends AbstractZenMode
|
|||||||
default:
|
default:
|
||||||
pref.setEnabled(true);
|
pref.setEnabled(true);
|
||||||
pref.setChecked(mBackend.isPriorityCategoryEnabled(
|
pref.setChecked(mBackend.isPriorityCategoryEnabled(
|
||||||
Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER));
|
Policy.PRIORITY_CATEGORY_MEDIA));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,9 +71,9 @@ public class ZenModeMediaSystemOtherPreferenceController extends AbstractZenMode
|
|||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final boolean allowMedia = (Boolean) newValue;
|
final boolean allowMedia = (Boolean) newValue;
|
||||||
if (ZenModeSettingsBase.DEBUG) {
|
if (ZenModeSettingsBase.DEBUG) {
|
||||||
Log.d(TAG, "onPrefChange allowMediaSystemOther=" + allowMedia);
|
Log.d(TAG, "onPrefChange allowMedia=" + allowMedia);
|
||||||
}
|
}
|
||||||
mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER, allowMedia);
|
mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_MEDIA, allowMedia);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -77,9 +77,11 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// these should match NotificationManager.Policy#ALL_PRIORITY_CATEGORIES
|
||||||
private static final int[] ALL_PRIORITY_CATEGORIES = {
|
private static final int[] ALL_PRIORITY_CATEGORIES = {
|
||||||
Policy.PRIORITY_CATEGORY_ALARMS,
|
Policy.PRIORITY_CATEGORY_ALARMS,
|
||||||
Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER,
|
Policy.PRIORITY_CATEGORY_MEDIA,
|
||||||
|
Policy.PRIORITY_CATEGORY_SYSTEM,
|
||||||
Policy.PRIORITY_CATEGORY_REMINDERS,
|
Policy.PRIORITY_CATEGORY_REMINDERS,
|
||||||
Policy.PRIORITY_CATEGORY_EVENTS,
|
Policy.PRIORITY_CATEGORY_EVENTS,
|
||||||
Policy.PRIORITY_CATEGORY_MESSAGES,
|
Policy.PRIORITY_CATEGORY_MESSAGES,
|
||||||
@@ -104,10 +106,10 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
|||||||
return mContext.getString(R.string.zen_mode_behavior_total_silence);
|
return mContext.getString(R.string.zen_mode_behavior_total_silence);
|
||||||
}
|
}
|
||||||
|
|
||||||
// only alarms and media/system can bypass dnd
|
// only alarms and media can bypass dnd
|
||||||
if (numCategories == 2 &&
|
if (numCategories == 2 &&
|
||||||
isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_ALARMS) &&
|
isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_ALARMS) &&
|
||||||
isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER)) {
|
isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_MEDIA)) {
|
||||||
return mContext.getString(R.string.zen_mode_behavior_alarms_only);
|
return mContext.getString(R.string.zen_mode_behavior_alarms_only);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,9 +166,12 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
|||||||
if (isCategoryEnabled(policy, category)) {
|
if (isCategoryEnabled(policy, category)) {
|
||||||
if (category == Policy.PRIORITY_CATEGORY_ALARMS) {
|
if (category == Policy.PRIORITY_CATEGORY_ALARMS) {
|
||||||
enabledCategories.add(mContext.getString(R.string.zen_mode_alarms));
|
enabledCategories.add(mContext.getString(R.string.zen_mode_alarms));
|
||||||
} else if (category == Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER) {
|
} else if (category == Policy.PRIORITY_CATEGORY_MEDIA) {
|
||||||
enabledCategories.add(mContext.getString(
|
enabledCategories.add(mContext.getString(
|
||||||
R.string.zen_mode_media_system_other));
|
R.string.zen_mode_media));
|
||||||
|
} else if (category == Policy.PRIORITY_CATEGORY_SYSTEM) {
|
||||||
|
enabledCategories.add(mContext.getString(
|
||||||
|
R.string.zen_mode_system));
|
||||||
} else if (category == Policy.PRIORITY_CATEGORY_REMINDERS) {
|
} else if (category == Policy.PRIORITY_CATEGORY_REMINDERS) {
|
||||||
enabledCategories.add(mContext.getString(R.string.zen_mode_reminders));
|
enabledCategories.add(mContext.getString(R.string.zen_mode_reminders));
|
||||||
} else if (category == Policy.PRIORITY_CATEGORY_EVENTS) {
|
} else if (category == Policy.PRIORITY_CATEGORY_EVENTS) {
|
||||||
|
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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;
|
||||||
|
|
||||||
|
import android.app.NotificationManager.Policy;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.v14.preference.SwitchPreference;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
public class ZenModeSystemPreferenceController extends
|
||||||
|
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
|
protected static final String KEY = "zen_mode_system";
|
||||||
|
|
||||||
|
public ZenModeSystemPreferenceController(Context context, Lifecycle lifecycle) {
|
||||||
|
super(context, KEY, lifecycle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
|
||||||
|
SwitchPreference pref = (SwitchPreference) preference;
|
||||||
|
switch (getZenMode()) {
|
||||||
|
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||||
|
pref.setEnabled(false);
|
||||||
|
pref.setChecked(false);
|
||||||
|
break;
|
||||||
|
case Settings.Global.ZEN_MODE_ALARMS:
|
||||||
|
pref.setEnabled(false);
|
||||||
|
pref.setChecked(false);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
pref.setEnabled(true);
|
||||||
|
pref.setChecked(mBackend.isPriorityCategoryEnabled(
|
||||||
|
Policy.PRIORITY_CATEGORY_SYSTEM));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
final boolean allowSystem = (Boolean) newValue;
|
||||||
|
if (ZenModeSettingsBase.DEBUG) {
|
||||||
|
Log.d(TAG, "onPrefChange allowSystem=" + allowSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
mMetricsFeatureProvider.action(mContext, MetricsProto.MetricsEvent.ACTION_ZEN_ALLOW_SYSTEM,
|
||||||
|
allowSystem);
|
||||||
|
mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_SYSTEM, allowSystem);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@@ -46,10 +46,7 @@ import org.robolectric.util.ReflectionHelpers;
|
|||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
public class ZenModeMediaPreferenceControllerTest {
|
public class ZenModeMediaPreferenceControllerTest {
|
||||||
|
private ZenModeMediaPreferenceController mController;
|
||||||
private static final boolean MEDIA_SETTINGS = true;
|
|
||||||
|
|
||||||
private ZenModeMediaSystemOtherPreferenceController mController;
|
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@@ -75,7 +72,7 @@ public class ZenModeMediaPreferenceControllerTest {
|
|||||||
mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
||||||
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
|
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
|
||||||
|
|
||||||
mController = new ZenModeMediaSystemOtherPreferenceController(mContext,
|
mController = new ZenModeMediaPreferenceController(mContext,
|
||||||
mock(Lifecycle.class));
|
mock(Lifecycle.class));
|
||||||
ReflectionHelpers.setField(mController, "mBackend", mBackend);
|
ReflectionHelpers.setField(mController, "mBackend", mBackend);
|
||||||
|
|
||||||
@@ -111,13 +108,13 @@ public class ZenModeMediaPreferenceControllerTest {
|
|||||||
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||||
|
|
||||||
when(mBackend.isPriorityCategoryEnabled(
|
when(mBackend.isPriorityCategoryEnabled(
|
||||||
NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER)).
|
NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA)).
|
||||||
thenReturn(MEDIA_SETTINGS);
|
thenReturn(true);
|
||||||
|
|
||||||
mController.updateState(mockPref);
|
mController.updateState(mockPref);
|
||||||
|
|
||||||
verify(mockPref).setEnabled(true);
|
verify(mockPref).setEnabled(true);
|
||||||
verify(mockPref).setChecked(MEDIA_SETTINGS);
|
verify(mockPref).setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -126,7 +123,7 @@ public class ZenModeMediaPreferenceControllerTest {
|
|||||||
mController.onPreferenceChange(mockPref, allow);
|
mController.onPreferenceChange(mockPref, allow);
|
||||||
|
|
||||||
verify(mBackend).saveSoundPolicy(
|
verify(mBackend).saveSoundPolicy(
|
||||||
NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER, allow);
|
NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA, allow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -135,6 +132,6 @@ public class ZenModeMediaPreferenceControllerTest {
|
|||||||
mController.onPreferenceChange(mockPref, allow);
|
mController.onPreferenceChange(mockPref, allow);
|
||||||
|
|
||||||
verify(mBackend).saveSoundPolicy(
|
verify(mBackend).saveSoundPolicy(
|
||||||
NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER, allow);
|
NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA, allow);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -52,7 +52,7 @@ public class ZenModeSettingsTest {
|
|||||||
NotificationManager.Policy.PRIORITY_CATEGORY_EVENTS
|
NotificationManager.Policy.PRIORITY_CATEGORY_EVENTS
|
||||||
| NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS
|
| NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS
|
||||||
| NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS
|
| NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS
|
||||||
| NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER,
|
| NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA,
|
||||||
0, 0);
|
0, 0);
|
||||||
final String result = mBuilder.getBehaviorSettingSummary(policy,
|
final String result = mBuilder.getBehaviorSettingSummary(policy,
|
||||||
Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||||
@@ -75,7 +75,7 @@ public class ZenModeSettingsTest {
|
|||||||
public void testGetBehaviorSettingSummary_alarmsAndMedia() {
|
public void testGetBehaviorSettingSummary_alarmsAndMedia() {
|
||||||
NotificationManager.Policy policy = new NotificationManager.Policy(
|
NotificationManager.Policy policy = new NotificationManager.Policy(
|
||||||
NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS
|
NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS
|
||||||
| NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER,
|
| NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA,
|
||||||
0, 0);
|
0, 0);
|
||||||
final String result = mBuilder.getBehaviorSettingSummary(policy,
|
final String result = mBuilder.getBehaviorSettingSummary(policy,
|
||||||
Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||||
|
@@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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;
|
||||||
|
|
||||||
|
import static android.provider.Settings.Global.ZEN_MODE;
|
||||||
|
import static android.provider.Settings.Global.ZEN_MODE_ALARMS;
|
||||||
|
import static android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
|
||||||
|
import static android.provider.Settings.Global.ZEN_MODE_NO_INTERRUPTIONS;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.v14.preference.SwitchPreference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
public class ZenModeSystemPreferenceControllerTest {
|
||||||
|
private ZenModeSystemPreferenceController mController;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ZenModeBackend mBackend;
|
||||||
|
@Mock
|
||||||
|
private NotificationManager mNotificationManager;
|
||||||
|
@Mock
|
||||||
|
private SwitchPreference mockPref;
|
||||||
|
@Mock
|
||||||
|
private NotificationManager.Policy mPolicy;
|
||||||
|
@Mock
|
||||||
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private ContentResolver mContentResolver;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||||
|
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
||||||
|
|
||||||
|
mContext = shadowApplication.getApplicationContext();
|
||||||
|
mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
||||||
|
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
|
||||||
|
mController = new ZenModeSystemPreferenceController(mContext, mock(Lifecycle.class));
|
||||||
|
ReflectionHelpers.setField(mController, "mBackend", mBackend);
|
||||||
|
|
||||||
|
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
|
||||||
|
mockPref);
|
||||||
|
mController.displayPreference(mPreferenceScreen);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_TotalSilence() {
|
||||||
|
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_NO_INTERRUPTIONS);
|
||||||
|
|
||||||
|
final SwitchPreference mockPref = mock(SwitchPreference.class);
|
||||||
|
mController.updateState(mockPref);
|
||||||
|
|
||||||
|
verify(mockPref).setEnabled(false);
|
||||||
|
verify(mockPref).setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_AlarmsOnly() {
|
||||||
|
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS);
|
||||||
|
|
||||||
|
final SwitchPreference mockPref = mock(SwitchPreference.class);
|
||||||
|
mController.updateState(mockPref);
|
||||||
|
|
||||||
|
verify(mockPref).setEnabled(false);
|
||||||
|
verify(mockPref).setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_Priority() {
|
||||||
|
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||||
|
|
||||||
|
when(mBackend.isPriorityCategoryEnabled(
|
||||||
|
NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM)).thenReturn(true);
|
||||||
|
|
||||||
|
mController.updateState(mockPref);
|
||||||
|
|
||||||
|
verify(mockPref).setEnabled(true);
|
||||||
|
verify(mockPref).setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onPreferenceChanged_EnableSystem() {
|
||||||
|
mController.onPreferenceChange(mockPref, true);
|
||||||
|
|
||||||
|
verify(mBackend).saveSoundPolicy(NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onPreferenceChanged_DisableSystem() {
|
||||||
|
mController.onPreferenceChange(mockPref, false);
|
||||||
|
|
||||||
|
verify(mBackend).saveSoundPolicy(NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user