Merge changes from topic "b308819928-ModesSettingsAppBreakthroughPage" into main
* changes: Moves ZenModeBypassingAppsSettings into modes dir Adds modes settings page for bypassing apps
This commit is contained in:
committed by
Android (Google) Code Review
commit
4e10ac8dae
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* 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 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(
|
||||
ZenModeAddBypassingAppsPreferenceController.getKey(
|
||||
appWithChannelsNoneBypassing.info.packageName,
|
||||
appWithChannelsNoneBypassing.info.uid));
|
||||
}
|
||||
|
||||
@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(
|
||||
ZenModeAddBypassingAppsPreferenceController.KEY_NO_APPS);
|
||||
}
|
||||
|
||||
// TODO(b/331624810): Add tests to verify updateAppList() when the filter is
|
||||
// ApplicationsState.FILTER_ENABLED_NOT_QUIET
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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 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;
|
||||
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.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ZenModeAllBypassingAppsPreferenceControllerTest {
|
||||
private ZenModeAllBypassingAppsPreferenceController mController;
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private NotificationBackend mBackend;
|
||||
@Mock
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
@Mock
|
||||
private ApplicationsState mApplicationState;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mController = new ZenModeAllBypassingAppsPreferenceController(
|
||||
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() {
|
||||
// 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(entry1);
|
||||
appEntries.add(entry2);
|
||||
List<NotificationChannel> channelsBypassing = new ArrayList<>();
|
||||
channelsBypassing.add(mock(NotificationChannel.class));
|
||||
channelsBypassing.add(mock(NotificationChannel.class));
|
||||
when(mBackend.getNotificationChannelsBypassingDnd(anyString(),
|
||||
anyInt())).thenReturn(new ParceledListSlice<>(channelsBypassing));
|
||||
|
||||
// THEN there's are two preferences
|
||||
mController.updateAppList(appEntries);
|
||||
verify(mPreferenceCategory, times(2)).addPreference(any());
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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 org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
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;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||
public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
|
||||
private ZenModeAppsLinkPreferenceController mController;
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ZenModesBackend mBackend;
|
||||
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new ZenModeAppsLinkPreferenceController(
|
||||
mContext, "controller_key", mBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||
public void testHasSummary() {
|
||||
Preference pref = mock(Preference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setZenPolicy(new ZenPolicy.Builder().allowAllSounds().build())
|
||||
.build(), true);
|
||||
mController.updateZenMode(pref, zenMode);
|
||||
verify(pref).setSummary(any());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,343 @@
|
||||
/*
|
||||
* 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 android.app.NotificationManager.INTERRUPTION_FILTER_ALL;
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_NONE;
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
|
||||
import static com.android.settings.notification.modes.ZenModeAppsPreferenceController.KEY_ALL;
|
||||
import static com.android.settings.notification.modes.ZenModeAppsPreferenceController.KEY_NONE;
|
||||
import static com.android.settings.notification.modes.ZenModeAppsPreferenceController.KEY_PRIORITY;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.Flags;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
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;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@EnableFlags(Flags.FLAG_MODES_UI)
|
||||
public final class ZenModeAppsPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ZenModesBackend mBackend;
|
||||
private ZenModeAppsPreferenceController mPriorityController;
|
||||
private ZenModeAppsPreferenceController mAllController;
|
||||
private ZenModeAppsPreferenceController mNoneController;
|
||||
|
||||
private SelectorWithWidgetPreference mPriorityPref;
|
||||
private SelectorWithWidgetPreference mAllPref;
|
||||
private SelectorWithWidgetPreference mNonePref;
|
||||
private PreferenceCategory mPrefCategory;
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
|
||||
mPriorityController = new ZenModeAppsPreferenceController(mContext, KEY_PRIORITY, mBackend);
|
||||
mNoneController = new ZenModeAppsPreferenceController(mContext, KEY_NONE, mBackend);
|
||||
mAllController = new ZenModeAppsPreferenceController(mContext, KEY_ALL, mBackend);
|
||||
|
||||
mPriorityPref = makePreference(KEY_PRIORITY, mPriorityController);
|
||||
mAllPref = makePreference(KEY_ALL, mAllController);
|
||||
mNonePref = makePreference(KEY_NONE, mNoneController);
|
||||
|
||||
mPrefCategory = new PreferenceCategory(mContext);
|
||||
mPrefCategory.setKey("zen_mode_apps_category");
|
||||
|
||||
PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||
mPreferenceScreen = preferenceManager.createPreferenceScreen(mContext);
|
||||
|
||||
mPreferenceScreen.addPreference(mPrefCategory);
|
||||
mPrefCategory.addPreference(mPriorityPref);
|
||||
mPrefCategory.addPreference(mAllPref);
|
||||
mPrefCategory.addPreference(mNonePref);
|
||||
|
||||
mAllController.displayPreference(mPreferenceScreen);
|
||||
mPriorityController.displayPreference(mPreferenceScreen);
|
||||
mNoneController.displayPreference(mPreferenceScreen);
|
||||
}
|
||||
|
||||
private SelectorWithWidgetPreference makePreference(String key,
|
||||
ZenModeAppsPreferenceController controller) {
|
||||
final SelectorWithWidgetPreference pref = new SelectorWithWidgetPreference(mContext, false);
|
||||
pref.setKey(key);
|
||||
pref.setOnClickListener(controller.mSelectorClickListener);
|
||||
return pref;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_All() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenMode.CHANNEL_POLICY_ALL)
|
||||
.build())
|
||||
.build(), true);
|
||||
mAllController.updateZenMode(preference, zenMode);
|
||||
|
||||
verify(preference).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_All_Unchecked() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||
.build())
|
||||
.build(), true);
|
||||
mAllController.updateZenMode(preference, zenMode);
|
||||
|
||||
verify(preference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_None() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||
.build())
|
||||
.build(), true);
|
||||
mNoneController.updateZenMode(preference, zenMode);
|
||||
|
||||
verify(preference).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_None_Unchecked() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenMode.CHANNEL_POLICY_ALL)
|
||||
.build())
|
||||
.build(), true);
|
||||
mNoneController.updateZenMode(preference, zenMode);
|
||||
|
||||
verify(preference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_Priority() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||
.build())
|
||||
.build(), true);
|
||||
mPriorityController.updateZenMode(preference, zenMode);
|
||||
|
||||
verify(preference).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_Priority_Unchecked() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||
.build())
|
||||
.build(), true);
|
||||
mPriorityController.updateZenMode(preference, zenMode);
|
||||
|
||||
verify(preference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_All() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_NONE)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenMode.CHANNEL_POLICY_ALL)
|
||||
.build())
|
||||
.build(), true);
|
||||
|
||||
mAllController.updateZenMode(preference, zenMode);
|
||||
mAllController.onPreferenceChange(preference, true);
|
||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||
verify(mBackend).updateMode(captor.capture());
|
||||
|
||||
assertThat(captor.getValue().getPolicy().getAllowedChannels())
|
||||
.isEqualTo(ZenMode.CHANNEL_POLICY_ALL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreferenceClick_passesCorrectCheckedState_All() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||
.build())
|
||||
.build(), true);
|
||||
|
||||
|
||||
mAllController.updateZenMode(mAllPref, zenMode);
|
||||
mNoneController.updateZenMode(mNonePref, zenMode);
|
||||
mPriorityController.updateZenMode(mPriorityPref, zenMode);
|
||||
|
||||
// MPME is checked; ALL and PRIORITY are unchecked.
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_ALL))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked());
|
||||
|
||||
mPrefCategory.findPreference(KEY_ALL).performClick();
|
||||
|
||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||
verify(mBackend).updateMode(captor.capture());
|
||||
// Checks the policy value for ALL is set.
|
||||
// The important part is that the interruption filter is propagated to the backend.
|
||||
assertThat(captor.getValue().getRule().getInterruptionFilter())
|
||||
.isEqualTo(INTERRUPTION_FILTER_ALL);
|
||||
// ALL is now checked; others are unchecked.
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_ALL))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreferenceClick_passesCorrectCheckedState_None() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||
.build())
|
||||
.build(), true);
|
||||
|
||||
mAllController.updateZenMode(mAllPref, zenMode);
|
||||
mNoneController.updateZenMode(mNonePref, zenMode);
|
||||
mPriorityController.updateZenMode(mPriorityPref, zenMode);
|
||||
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_ALL))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked());
|
||||
|
||||
// Click on NONE
|
||||
mPrefCategory.findPreference(KEY_NONE).performClick();
|
||||
|
||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||
verify(mBackend).updateMode(captor.capture());
|
||||
// NONE is not actually propagated to the backend as an interruption filter;
|
||||
// the filter is set to priority, and sounds and visual effects are disallowed.
|
||||
// See AbstractZenModePreferenceController.
|
||||
assertThat(captor.getValue().getRule().getInterruptionFilter())
|
||||
.isEqualTo(INTERRUPTION_FILTER_PRIORITY);
|
||||
// NONE is now checked; others are unchecked.
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_ALL))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreferenceClick_passesCorrectCheckedState_Priority() {
|
||||
ZenMode zenMode = new ZenMode("id",
|
||||
new AutomaticZenRule.Builder("Driving", Uri.parse("drive"))
|
||||
.setType(AutomaticZenRule.TYPE_DRIVING)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||
.build())
|
||||
.build(), true);
|
||||
|
||||
mAllController.updateZenMode(mAllPref, zenMode);
|
||||
mNoneController.updateZenMode(mNonePref, zenMode);
|
||||
mPriorityController.updateZenMode(mPriorityPref, zenMode);
|
||||
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_ALL))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked());
|
||||
|
||||
// Click on PRIORITY
|
||||
mPrefCategory.findPreference(KEY_PRIORITY).performClick();
|
||||
|
||||
ArgumentCaptor<ZenMode> captor = ArgumentCaptor.forClass(ZenMode.class);
|
||||
verify(mBackend).updateMode(captor.capture());
|
||||
// Checks the policy value for PRIORITY is propagated to the backend.
|
||||
assertThat(captor.getValue().getRule().getInterruptionFilter())
|
||||
.isEqualTo(INTERRUPTION_FILTER_PRIORITY);
|
||||
// PRIORITY is now checked; others are unchecked.
|
||||
assertThat(((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_PRIORITY))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_ALL))
|
||||
.isChecked());
|
||||
assertThat(!((SelectorWithWidgetPreference) mPrefCategory.findPreference(KEY_NONE))
|
||||
.isChecked());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import static android.service.notification.ZenPolicy.PEOPLE_TYPE_ANYONE;
|
||||
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_CONTACTS;
|
||||
import static android.service.notification.ZenPolicy.VISUAL_EFFECT_AMBIENT;
|
||||
import static android.service.notification.ZenPolicy.VISUAL_EFFECT_LIGHTS;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
@@ -29,6 +30,7 @@ import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.service.notification.ZenDeviceEffects;
|
||||
import android.service.notification.ZenPolicy;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -325,4 +327,46 @@ public class ZenModesSummaryHelperTest {
|
||||
assertThat(mSummaryHelper.getDisplayEffectsSummary(zenMode)).isEqualTo(
|
||||
"Notifications partially hidden, grayscale, and 2 more");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAppsSummary_all() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenMode.CHANNEL_POLICY_ALL)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getAppsSummary(zenMode)).isEqualTo("All");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAppsSummary_none() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_NONE)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getAppsSummary(zenMode)).isEqualTo("None");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAppsSummary_priorityApps() {
|
||||
AutomaticZenRule rule = new AutomaticZenRule.Builder("Bedtime", Uri.parse("bed"))
|
||||
.setType(AutomaticZenRule.TYPE_BEDTIME)
|
||||
.setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
|
||||
.setZenPolicy(new ZenPolicy.Builder()
|
||||
.allowChannels(ZenPolicy.CHANNEL_POLICY_PRIORITY)
|
||||
.build())
|
||||
.build();
|
||||
ZenMode zenMode = new ZenMode("id", rule, true);
|
||||
|
||||
assertThat(mSummaryHelper.getAppsSummary(zenMode)).isEqualTo("Selected apps");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user