Updates main page for Do Not Disturb
Settings > Sound > Do Not Disturb - Update strings, more descriptive summary for DND Apps summary - Move top-level ordering of preferences - Remove old unused DND strings Test: make RunSettingsRoboTests7 Test: make ROBOTEST_FILTER=ZenModeBypassingAppsPreferenceControllerTest RunSettingsRoboTests Test: manual Bug: 151845457 Merged-In: I9c23c558a9d764702e966d22e5c6e5c5425e4d32 Change-Id: I9c23c558a9d764702e966d22e5c6e5c5425e4d32
This commit is contained in:
@@ -18,16 +18,23 @@ package com.android.settings.notification.zen;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
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 android.provider.Settings;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settings.notification.zen.ZenModeBypassingAppsPreferenceController;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -37,6 +44,9 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ZenModeBypassingAppsPreferenceControllerTest {
|
||||
|
||||
@@ -45,30 +55,156 @@ public class ZenModeBypassingAppsPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private NotificationBackend mBackend;
|
||||
private int mPreviousZenSetting;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mController = new ZenModeBypassingAppsPreferenceController(mContext, mock(Lifecycle.class));
|
||||
mController = new ZenModeBypassingAppsPreferenceController(
|
||||
mContext, null, mock(Fragment.class), mock(Lifecycle.class));
|
||||
mController.mPreference = new Preference(mContext);
|
||||
mPreviousZenSetting =
|
||||
Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.ZEN_MODE,
|
||||
Settings.Global.ZEN_MODE_OFF);
|
||||
ReflectionHelpers.setField(mController, "mNotificationBackend", mBackend);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.ZEN_MODE,
|
||||
mPreviousZenSetting);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
when(mBackend.getNumAppsBypassingDnd(anyInt())).thenReturn(5);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotAvailable() {
|
||||
when(mBackend.getNumAppsBypassingDnd(anyInt())).thenReturn(0);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
public void testUpdateBypassingApps() {
|
||||
// GIVEN DND is off
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.ZEN_MODE,
|
||||
Settings.Global.ZEN_MODE_OFF);
|
||||
|
||||
// mock app list
|
||||
ApplicationsState.AppEntry entry = mock(ApplicationsState.AppEntry.class);
|
||||
entry.info = new ApplicationInfo();
|
||||
entry.info.packageName = "test";
|
||||
entry.label = "test";
|
||||
entry.info.uid = 0;
|
||||
|
||||
List<ApplicationsState.AppEntry> appEntries = new ArrayList<>();
|
||||
appEntries.add(entry);
|
||||
|
||||
List<NotificationChannel> channelsBypassing = new ArrayList<>();
|
||||
channelsBypassing.add(mock(NotificationChannel.class));
|
||||
|
||||
when(mBackend.getNotificationChannelsBypassingDnd(entry.info.packageName,
|
||||
entry.info.uid)).thenReturn(new ParceledListSlice<>(channelsBypassing));
|
||||
|
||||
// WHEN a single app is passed to the controller
|
||||
mController.updateAppsBypassingDndSummaryText(appEntries);
|
||||
|
||||
// THEN the preference is enabled and the summary contains the app name from the list
|
||||
assertThat(mController.mPreference.isEnabled()).isTrue();
|
||||
assertThat(mController.getSummary().contains(entry.label)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasSummary() {
|
||||
assertThat(mController.getSummary()).isNotNull();
|
||||
public void testUpdateBypassingApps_multipleApps() {
|
||||
// GIVEN DND is off
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.ZEN_MODE,
|
||||
Settings.Global.ZEN_MODE_OFF);
|
||||
|
||||
// mock app list
|
||||
ApplicationsState.AppEntry entry1 = mock(ApplicationsState.AppEntry.class);
|
||||
entry1.info = new ApplicationInfo();
|
||||
entry1.info.packageName = "test1";
|
||||
entry1.label = "test1";
|
||||
entry1.info.uid = 1;
|
||||
ApplicationsState.AppEntry entry2 = mock(ApplicationsState.AppEntry.class);
|
||||
entry2.info = new ApplicationInfo();
|
||||
entry2.info.packageName = "test2";
|
||||
entry2.label = "test2";
|
||||
entry2.info.uid = 2;
|
||||
|
||||
List<ApplicationsState.AppEntry> appEntries = new ArrayList<>();
|
||||
appEntries.add(entry1);
|
||||
appEntries.add(entry2);
|
||||
|
||||
List<NotificationChannel> channelsBypassing = new ArrayList<>();
|
||||
channelsBypassing.add(mock(NotificationChannel.class));
|
||||
|
||||
when(mBackend.getNotificationChannelsBypassingDnd(entry1.info.packageName,
|
||||
entry1.info.uid)).thenReturn(new ParceledListSlice<>(channelsBypassing));
|
||||
when(mBackend.getNotificationChannelsBypassingDnd(entry2.info.packageName,
|
||||
entry2.info.uid)).thenReturn(new ParceledListSlice<>(channelsBypassing));
|
||||
|
||||
// WHEN a list of apps is passed to the controller
|
||||
mController.updateAppsBypassingDndSummaryText(appEntries);
|
||||
|
||||
// THEN the preference is enabled and the summary contains the app names from the list
|
||||
assertThat(mController.mPreference.isEnabled()).isTrue();
|
||||
assertThat(mController.getSummary().contains(entry1.label)).isTrue();
|
||||
assertThat(mController.getSummary().contains(entry2.label)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAppsBypassingDnd_nullAppsList() {
|
||||
// GIVEN DND is off
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.ZEN_MODE,
|
||||
Settings.Global.ZEN_MODE_OFF);
|
||||
|
||||
// WHEN the list of apps is null
|
||||
mController.updateAppsBypassingDndSummaryText(null);
|
||||
|
||||
// THEN the preference is enabled and summary is unchanged (in this case, null)
|
||||
assertThat(mController.mPreference.isEnabled()).isTrue();
|
||||
assertThat(mController.getSummary()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAppsBypassingDnd_emptyAppsList() {
|
||||
// GIVEN the DND is off
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.ZEN_MODE,
|
||||
Settings.Global.ZEN_MODE_OFF);
|
||||
|
||||
// WHEN the list of apps is an empty list
|
||||
mController.updateAppsBypassingDndSummaryText(new ArrayList<>());
|
||||
|
||||
// THEN the preference is enabled and summary is updated
|
||||
assertThat(mController.mPreference.isEnabled()).isTrue();
|
||||
assertThat(mController.getSummary().contains("No apps")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAppsBypassingDnd_alarmsOnly() {
|
||||
// GIVEN alarms only DND mode
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.ZEN_MODE,
|
||||
Settings.Global.ZEN_MODE_ALARMS);
|
||||
|
||||
// mock app entries
|
||||
ApplicationsState.AppEntry entry = mock(ApplicationsState.AppEntry.class);
|
||||
entry.info = new ApplicationInfo();
|
||||
entry.info.packageName = "test";
|
||||
entry.label = "test";
|
||||
entry.info.uid = 0;
|
||||
|
||||
List<ApplicationsState.AppEntry> appEntries = new ArrayList<>();
|
||||
appEntries.add(entry);
|
||||
|
||||
List<NotificationChannel> channelsBypassing = new ArrayList<>();
|
||||
channelsBypassing.add(mock(NotificationChannel.class));
|
||||
when(mBackend.getNotificationChannelsBypassingDnd(entry.info.packageName,
|
||||
entry.info.uid)).thenReturn(new ParceledListSlice<>(channelsBypassing));
|
||||
|
||||
// WHEN we update apps bypassing dnd summary text
|
||||
mController.updateAppsBypassingDndSummaryText(appEntries);
|
||||
|
||||
// THEN the preference is disabled and the summary says no apps can bypass
|
||||
assertThat(mController.mPreference.isEnabled()).isFalse();
|
||||
assertThat(mController.getSummary().contains("No apps")).isTrue();
|
||||
}
|
||||
}
|
||||
|
@@ -97,34 +97,6 @@ public class ZenModeSettingsTest {
|
||||
.isEqualTo("Allow from starred contacts and repeat callers");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoundSettingSummary_allOff() {
|
||||
Policy policy = new Policy(0, 0, 0, 0);
|
||||
assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoundSettingSummary_allOn() {
|
||||
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_SYSTEM
|
||||
| Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
|
||||
assertThat(mBuilder.getSoundSettingSummary(policy))
|
||||
.isEqualTo("Muted, but allow alarms, media, and touch sounds");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoundSettingSummary_allOffButOne() {
|
||||
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
|
||||
assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted, but allow media");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoundSettingSummary_allOffButTwo() {
|
||||
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_SYSTEM
|
||||
| Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
|
||||
assertThat(mBuilder.getSoundSettingSummary(policy))
|
||||
.isEqualTo("Muted, but allow media and touch sounds");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchProvider_shouldIndexDefaultXml() {
|
||||
final List<SearchIndexableResource> sir = ZenModeSettings.SEARCH_INDEX_DATA_PROVIDER
|
||||
|
Reference in New Issue
Block a user