DND Bypassing Apps redesign
- Add link in DND Conversations Page to the overall conversations list Settings page - Add custom_rule xml pages for custom schedule rule settings for messages and calls (so the UI is the same as before the message/calls redesign) - Change app exceptions to display apps with subtext indicating which notitfication channels are allowed to bypass dnd (previously, would display each channel individually) - Add individual AppBypassDnd channel pages where users can decide which channels will bypass DND for an app on a single page (AppChannelsBypassingDndSettings) - Only remove dnd bypassing apps preferences from the preference list if the list changed, else just update the preference itself to avoid the list from flashing Test: make RunSettingsRoboTests7 Bug: 151845457 Change-Id: If12d8921e1405aefb1066acc2ef5c55d216fe47a
This commit is contained in:
@@ -16,19 +16,8 @@
|
||||
|
||||
package com.android.settings.notification.app;
|
||||
|
||||
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||
import static android.app.NotificationManager.IMPORTANCE_MIN;
|
||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -37,24 +26,17 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.ConversationChannelWrapper;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
|
||||
import com.android.settings.applications.AppInfoBase;
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -67,7 +49,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ConversationListPreferenceControllerTest {
|
||||
@@ -116,8 +97,6 @@ public class ConversationListPreferenceControllerTest {
|
||||
list.add(ccw);
|
||||
|
||||
mController.populateList(list, outerContainer);
|
||||
|
||||
verify(outerContainer).setVisible(true);
|
||||
verify(outerContainer, times(1)).addPreference(any());
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.zen;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.NotificationChannel;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ParceledListSlice;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ZenModeAddBypassingAppsPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private NotificationBackend mBackend;
|
||||
@Mock
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
@Mock
|
||||
private ApplicationsState mApplicationState;
|
||||
private ZenModeAddBypassingAppsPreferenceController mController;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mController = new ZenModeAddBypassingAppsPreferenceController(
|
||||
mContext, null, mock(Fragment.class), mBackend);
|
||||
mController.mPreferenceCategory = mPreferenceCategory;
|
||||
mController.mApplicationsState = mApplicationState;
|
||||
mController.mPrefContext = mContext;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAppList() {
|
||||
// GIVEN there's an app with bypassing channels, app without any channels, and then an app
|
||||
// with notification channels but none that can bypass DND
|
||||
ApplicationsState.AppEntry appWithBypassingChannels =
|
||||
mock(ApplicationsState.AppEntry.class);
|
||||
appWithBypassingChannels.info = new ApplicationInfo();
|
||||
appWithBypassingChannels.info.packageName = "appWithBypassingChannels";
|
||||
appWithBypassingChannels.info.uid = 0;
|
||||
when(mBackend.getNotificationChannelsBypassingDnd(
|
||||
appWithBypassingChannels.info.packageName,
|
||||
appWithBypassingChannels.info.uid))
|
||||
.thenReturn(new ParceledListSlice<>(
|
||||
Arrays.asList(mock(NotificationChannel.class))));
|
||||
when(mBackend.getChannelCount(
|
||||
appWithBypassingChannels.info.packageName,
|
||||
appWithBypassingChannels.info.uid))
|
||||
.thenReturn(5);
|
||||
|
||||
ApplicationsState.AppEntry appWithoutChannels = mock(ApplicationsState.AppEntry.class);
|
||||
appWithoutChannels.info = new ApplicationInfo();
|
||||
appWithoutChannels.info.packageName = "appWithoutChannels";
|
||||
appWithoutChannels.info.uid = 0;
|
||||
when(mBackend.getChannelCount(
|
||||
appWithoutChannels.info.packageName,
|
||||
appWithoutChannels.info.uid))
|
||||
.thenReturn(0);
|
||||
when(mBackend.getNotificationChannelsBypassingDnd(
|
||||
appWithoutChannels.info.packageName,
|
||||
appWithoutChannels.info.uid))
|
||||
.thenReturn(new ParceledListSlice<>(new ArrayList<>()));
|
||||
|
||||
ApplicationsState.AppEntry appWithChannelsNoneBypassing =
|
||||
mock(ApplicationsState.AppEntry.class);
|
||||
appWithChannelsNoneBypassing.info = new ApplicationInfo();
|
||||
appWithChannelsNoneBypassing.info.packageName = "appWithChannelsNoneBypassing";
|
||||
appWithChannelsNoneBypassing.info.uid = 0;
|
||||
when(mBackend.getChannelCount(
|
||||
appWithChannelsNoneBypassing.info.packageName,
|
||||
appWithChannelsNoneBypassing.info.uid))
|
||||
.thenReturn(5);
|
||||
when(mBackend.getNotificationChannelsBypassingDnd(
|
||||
appWithChannelsNoneBypassing.info.packageName,
|
||||
appWithChannelsNoneBypassing.info.uid))
|
||||
.thenReturn(new ParceledListSlice<>(new ArrayList<>()));
|
||||
|
||||
List<ApplicationsState.AppEntry> appEntries = new ArrayList<>();
|
||||
appEntries.add(appWithBypassingChannels);
|
||||
appEntries.add(appWithoutChannels);
|
||||
appEntries.add(appWithChannelsNoneBypassing);
|
||||
|
||||
// WHEN the controller updates the app list with the app entries
|
||||
mController.updateAppList(appEntries);
|
||||
|
||||
// THEN only the appWithChannelsNoneBypassing makes it to the app list
|
||||
ArgumentCaptor<Preference> prefCaptor = ArgumentCaptor.forClass(Preference.class);
|
||||
verify(mPreferenceCategory).addPreference(prefCaptor.capture());
|
||||
|
||||
Preference pref = prefCaptor.getValue();
|
||||
assertThat(pref.getKey()).isEqualTo(
|
||||
ZenModeAllBypassingAppsPreferenceController.getKey(
|
||||
appWithChannelsNoneBypassing.info.packageName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAppList_nullApps() {
|
||||
mController.updateAppList(null);
|
||||
verify(mPreferenceCategory, never()).addPreference(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAppList_emptyAppList() {
|
||||
// WHEN there are no apps
|
||||
mController.updateAppList(new ArrayList<>());
|
||||
|
||||
// THEN only the appWithChannelsNoneBypassing makes it to the app list
|
||||
ArgumentCaptor<Preference> prefCaptor = ArgumentCaptor.forClass(Preference.class);
|
||||
verify(mPreferenceCategory).addPreference(prefCaptor.capture());
|
||||
|
||||
Preference pref = prefCaptor.getValue();
|
||||
assertThat(pref.getKey()).isEqualTo(
|
||||
ZenModeAllBypassingAppsPreferenceController.KEY_NO_APPS);
|
||||
}
|
||||
}
|
@@ -19,6 +19,8 @@ package com.android.settings.notification.zen;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -30,25 +32,25 @@ import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ParceledListSlice;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settings.notification.zen.ZenModeAllBypassingAppsPreferenceController;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ZenModeAllBypassingAppsPreferenceControllerTest {
|
||||
private ZenModeAllBypassingAppsPreferenceController mController;
|
||||
@@ -57,7 +59,7 @@ public class ZenModeAllBypassingAppsPreferenceControllerTest {
|
||||
@Mock
|
||||
private NotificationBackend mBackend;
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
@Mock
|
||||
private ApplicationsState mApplicationState;
|
||||
|
||||
@@ -67,11 +69,10 @@ public class ZenModeAllBypassingAppsPreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mController = new ZenModeAllBypassingAppsPreferenceController(
|
||||
mContext, null, mock(Fragment.class));
|
||||
mController.mPreferenceScreen = mPreferenceScreen;
|
||||
mContext, null, mock(Fragment.class), mBackend);
|
||||
mController.mPreferenceCategory = mPreferenceCategory;
|
||||
mController.mApplicationsState = mApplicationState;
|
||||
mController.mPrefContext = mContext;
|
||||
ReflectionHelpers.setField(mController, "mNotificationBackend", mBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,36 +81,49 @@ public class ZenModeAllBypassingAppsPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNotificationChannelList() {
|
||||
ApplicationsState.AppEntry entry = mock(ApplicationsState.AppEntry.class);
|
||||
entry.info = new ApplicationInfo();
|
||||
entry.info.packageName = "test";
|
||||
entry.info.uid = 0;
|
||||
public void testUpdateAppList() {
|
||||
// WHEN there's two apps with notification channels that bypass DND
|
||||
ApplicationsState.AppEntry entry1 = mock(ApplicationsState.AppEntry.class);
|
||||
entry1.info = new ApplicationInfo();
|
||||
entry1.info.packageName = "test";
|
||||
entry1.info.uid = 0;
|
||||
|
||||
ApplicationsState.AppEntry entry2 = mock(ApplicationsState.AppEntry.class);
|
||||
entry2.info = new ApplicationInfo();
|
||||
entry2.info.packageName = "test2";
|
||||
entry2.info.uid = 0;
|
||||
|
||||
List<ApplicationsState.AppEntry> appEntries = new ArrayList<>();
|
||||
appEntries.add(entry);
|
||||
|
||||
appEntries.add(entry1);
|
||||
appEntries.add(entry2);
|
||||
List<NotificationChannel> channelsBypassing = new ArrayList<>();
|
||||
channelsBypassing.add(mock(NotificationChannel.class));
|
||||
channelsBypassing.add(mock(NotificationChannel.class));
|
||||
channelsBypassing.add(mock(NotificationChannel.class));
|
||||
when(mBackend.getNotificationChannelsBypassingDnd(anyString(),
|
||||
anyInt())).thenReturn(new ParceledListSlice<>(channelsBypassing));
|
||||
|
||||
when(mBackend.getNotificationChannelsBypassingDnd(entry.info.packageName,
|
||||
entry.info.uid)).thenReturn(new ParceledListSlice<>(channelsBypassing));
|
||||
|
||||
mController.updateNotificationChannelList(appEntries);
|
||||
verify(mPreferenceScreen, times(3)).addPreference(any());
|
||||
// THEN there's are two preferences
|
||||
mController.updateAppList(appEntries);
|
||||
verify(mPreferenceCategory, times(2)).addPreference(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNotificationChannelList_nullChannels() {
|
||||
mController.updateNotificationChannelList(null);
|
||||
verify(mPreferenceScreen, never()).addPreference(any());
|
||||
public void testUpdateAppList_nullApps() {
|
||||
mController.updateAppList(null);
|
||||
verify(mPreferenceCategory, never()).addPreference(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNotificationChannelList_emptyChannelsList() {
|
||||
mController.updateNotificationChannelList(new ArrayList<>());
|
||||
verify(mPreferenceScreen, never()).addPreference(any());
|
||||
public void testUpdateAppList_emptyAppList() {
|
||||
// WHEN there are no apps
|
||||
mController.updateAppList(new ArrayList<>());
|
||||
|
||||
// THEN only the appWithChannelsNoneBypassing makes it to the app list
|
||||
ArgumentCaptor<Preference> prefCaptor = ArgumentCaptor.forClass(Preference.class);
|
||||
verify(mPreferenceCategory).addPreference(prefCaptor.capture());
|
||||
|
||||
Preference pref = prefCaptor.getValue();
|
||||
assertThat(pref.getKey()).isEqualTo(
|
||||
ZenModeAllBypassingAppsPreferenceController.KEY_NO_APPS);
|
||||
}
|
||||
}
|
||||
|
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
* 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.zen;
|
||||
|
||||
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 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 androidx.preference.ListPreference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
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.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ZenModePriorityCallsPreferenceControllerTest {
|
||||
|
||||
private ZenModePriorityCallsPreferenceController mController;
|
||||
|
||||
@Mock
|
||||
private ZenModeBackend mBackend;
|
||||
@Mock
|
||||
private NotificationManager mNotificationManager;
|
||||
@Mock
|
||||
private ListPreference mockPref;
|
||||
@Mock
|
||||
private NotificationManager.Policy mPolicy;
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
private ContentResolver mContentResolver;
|
||||
private Context mContext;
|
||||
|
||||
/**
|
||||
* Array Values Key
|
||||
* 0: anyone
|
||||
* 1: contacts
|
||||
* 2: starred
|
||||
* 3: none
|
||||
*/
|
||||
private String[] mValues;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mValues = mContext.getResources().getStringArray(R.array.zen_mode_contacts_values);
|
||||
mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
||||
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
|
||||
|
||||
when(mBackend.getPriorityCallSenders())
|
||||
.thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
|
||||
when(mBackend.getAlarmsTotalSilencePeopleSummary(
|
||||
NotificationManager.Policy.PRIORITY_CATEGORY_CALLS)).thenCallRealMethod();
|
||||
when(mBackend.getContactsSummary(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
|
||||
.thenCallRealMethod();
|
||||
|
||||
mController = new ZenModePriorityCallsPreferenceController(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);
|
||||
|
||||
when(mBackend.isPriorityCategoryEnabled(
|
||||
NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
|
||||
.thenReturn(false);
|
||||
final ListPreference mockPref = mock(ListPreference.class);
|
||||
mController.updateState(mockPref);
|
||||
|
||||
verify(mockPref).setEnabled(false);
|
||||
verify(mockPref).setSummary(R.string.zen_mode_from_none_calls);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_AlarmsOnly() {
|
||||
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS);
|
||||
|
||||
final ListPreference mockPref = mock(ListPreference.class);
|
||||
mController.updateState(mockPref);
|
||||
|
||||
verify(mockPref).setEnabled(false);
|
||||
verify(mockPref).setSummary(R.string.zen_mode_from_none_calls);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_Priority() {
|
||||
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||
|
||||
when(mBackend.isPriorityCategoryEnabled(
|
||||
NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
|
||||
.thenReturn(true);
|
||||
|
||||
mController.updateState(mockPref);
|
||||
|
||||
verify(mockPref).setEnabled(true);
|
||||
verify(mockPref).setSummary(R.string.zen_mode_from_starred);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_setSelectedContacts_any() {
|
||||
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||
when(mBackend.getPriorityCallSenders()).thenReturn(
|
||||
NotificationManager.Policy.PRIORITY_SENDERS_ANY);
|
||||
mController.updateState(mockPref);
|
||||
verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
|
||||
ZenModeBackend.ZEN_MODE_FROM_ANYONE)]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_setSelectedContacts_none() {
|
||||
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||
when(mBackend.getPriorityCallSenders()).thenReturn(ZenModeBackend.SOURCE_NONE);
|
||||
mController.updateState(mockPref);
|
||||
verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
|
||||
ZenModeBackend.ZEN_MODE_FROM_NONE)]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_setSelectedContacts_starred() {
|
||||
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||
when(mBackend.getPriorityCallSenders()).thenReturn(
|
||||
NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
|
||||
mController.updateState(mockPref);
|
||||
verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
|
||||
ZenModeBackend.ZEN_MODE_FROM_STARRED)]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_setSelectedContacts_contacts() {
|
||||
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||
when(mBackend.getPriorityCallSenders()).thenReturn(
|
||||
NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS);
|
||||
mController.updateState(mockPref);
|
||||
verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
|
||||
ZenModeBackend.ZEN_MODE_FROM_CONTACTS)]);
|
||||
}
|
||||
}
|
@@ -79,13 +79,13 @@ public class ZenModeSettingsTest {
|
||||
public void testGetCallsSettingSummary_contacts() {
|
||||
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_CALLS,
|
||||
Policy.PRIORITY_SENDERS_CONTACTS, 0, 0);
|
||||
assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("Allow from contacts");
|
||||
assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("Contacts");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCallsSettingSummary_repeatCallers() {
|
||||
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_REPEAT_CALLERS, 0, 0, 0);
|
||||
assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("Allow from repeat callers");
|
||||
assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("Repeat callers");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,7 +94,7 @@ public class ZenModeSettingsTest {
|
||||
Policy.PRIORITY_CATEGORY_REPEAT_CALLERS | Policy.PRIORITY_CATEGORY_CALLS,
|
||||
Policy.PRIORITY_SENDERS_STARRED, 0, 0);
|
||||
assertThat(mBuilder.getCallsSettingSummary(policy))
|
||||
.isEqualTo("Allow from starred contacts and repeat callers");
|
||||
.isEqualTo("Starred contacts and repeat callers");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user