Support (non-editable) display of DND with a filter != PRIORITY
Whenever setInterruptionFilter() is called with NONE or ALARMS, the Do Not Disturb mode now shows the current policy (nothing allowed or alarms/media allowed), instead of the normal PRIORITY policy. This policy is read-only in the UI since it cannot be customized. This should be, or at least become, pretty rare (with small exceptions, apps targeting V that call setInterruptionFilter() will use an implicit mode instead of changing the global zen mode, plus using these filters is quite nonstandard in itself). Fixes: 361586248 Test: atest & manual (toggling DND via cmd shell) Flag: android.app.modes_ui Change-Id: If2439480235d30aa310ad8925341183b9761784c
This commit is contained in:
@@ -44,8 +44,8 @@ class InterruptionFilterPreferenceController extends AbstractZenModePreferenceCo
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
||||
preference.setEnabled(zenMode.isEnabled());
|
||||
boolean allowingAll = zenMode.getRule().getInterruptionFilter() == INTERRUPTION_FILTER_ALL;
|
||||
preference.setEnabled(zenMode.isEnabled() && zenMode.canEditPolicy());
|
||||
boolean allowingAll = zenMode.getInterruptionFilter() == INTERRUPTION_FILTER_ALL;
|
||||
|
||||
((TwoStatePreference) preference).setChecked(allowingAll);
|
||||
preference.setSummary(allowingAll
|
||||
@@ -57,7 +57,7 @@ class InterruptionFilterPreferenceController extends AbstractZenModePreferenceCo
|
||||
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
|
||||
final boolean allowAll = ((Boolean) newValue);
|
||||
return saveMode(zenMode -> {
|
||||
zenMode.getRule().setInterruptionFilter(allowAll
|
||||
zenMode.setInterruptionFilter(allowAll
|
||||
? INTERRUPTION_FILTER_ALL
|
||||
: INTERRUPTION_FILTER_PRIORITY);
|
||||
return zenMode;
|
||||
|
@@ -228,7 +228,7 @@ public class SetupInterstitialActivity extends FragmentActivity {
|
||||
return false;
|
||||
}
|
||||
|
||||
modeToUpdate.getRule().setEnabled(true);
|
||||
modeToUpdate.setEnabled(true);
|
||||
mBackend.updateMode(modeToUpdate);
|
||||
return true;
|
||||
}
|
||||
|
@@ -92,7 +92,7 @@ class ZenModeAppsLinkPreferenceController extends AbstractZenModePreferenceContr
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(ZenMode zenMode) {
|
||||
return zenMode.getRule().getInterruptionFilter() != INTERRUPTION_FILTER_ALL;
|
||||
return zenMode.getInterruptionFilter() != INTERRUPTION_FILTER_ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,7 +102,7 @@ class ZenModeAppsLinkPreferenceController extends AbstractZenModePreferenceContr
|
||||
preference.setIntent(
|
||||
ZenSubSettingLauncher.forModeFragment(mContext, ZenModeAppsFragment.class,
|
||||
zenMode.getId(), SettingsEnums.ZEN_PRIORITY_MODE).toIntent());
|
||||
preference.setEnabled(zenMode.isEnabled());
|
||||
preference.setEnabled(zenMode.isEnabled() && zenMode.canEditPolicy());
|
||||
|
||||
mZenMode = zenMode;
|
||||
mPreference = (CircularIconsPreference) preference;
|
||||
|
@@ -74,7 +74,7 @@ class ZenModeDisplayEffectPreferenceController extends AbstractZenModePreference
|
||||
updatedEffects.setShouldUseNightMode(allow);
|
||||
break;
|
||||
}
|
||||
zenMode.getRule().setDeviceEffects(updatedEffects.build());
|
||||
zenMode.setDeviceEffects(updatedEffects.build());
|
||||
return zenMode;
|
||||
});
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ class ZenModeDisplayLinkPreferenceController extends AbstractZenModePreferenceCo
|
||||
preference.setIntent(
|
||||
ZenSubSettingLauncher.forModeFragment(mContext, ZenModeDisplayFragment.class,
|
||||
zenMode.getId(), SettingsEnums.ZEN_PRIORITY_MODE).toIntent());
|
||||
preference.setEnabled(zenMode.isEnabled());
|
||||
preference.setEnabled(zenMode.isEnabled() && zenMode.canEditPolicy());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -50,7 +50,8 @@ class ZenModeExitAtAlarmPreferenceController extends
|
||||
if (mSchedule.exitAtAlarm != exitAtAlarm) {
|
||||
mSchedule.exitAtAlarm = exitAtAlarm;
|
||||
return saveMode(mode -> {
|
||||
mode.getRule().setConditionId(ZenModeConfig.toScheduleConditionId(mSchedule));
|
||||
mode.setCustomModeConditionId(mContext,
|
||||
ZenModeConfig.toScheduleConditionId(mSchedule));
|
||||
return mode;
|
||||
});
|
||||
}
|
||||
|
@@ -171,7 +171,7 @@ public class ZenModeFragment extends ZenModeFragmentBase {
|
||||
} else if (menuItem.getItemId() == DELETE_MODE) {
|
||||
new AlertDialog.Builder(mContext)
|
||||
.setTitle(mContext.getString(R.string.zen_mode_delete_mode_confirmation,
|
||||
mZenMode.getRule().getName()))
|
||||
mZenMode.getName()))
|
||||
.setPositiveButton(R.string.zen_mode_schedule_delete,
|
||||
(dialog, which) -> {
|
||||
// start finishing before calling removeMode() so that we
|
||||
|
@@ -41,7 +41,7 @@ class ZenModeNotifVisLinkPreferenceController extends AbstractZenModePreferenceC
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(ZenMode zenMode) {
|
||||
return zenMode.getRule().getInterruptionFilter() != INTERRUPTION_FILTER_ALL;
|
||||
return zenMode.getInterruptionFilter() != INTERRUPTION_FILTER_ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -61,7 +61,7 @@ class ZenModeOtherLinkPreferenceController extends AbstractZenModePreferenceCont
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(ZenMode zenMode) {
|
||||
return zenMode.getRule().getInterruptionFilter() != INTERRUPTION_FILTER_ALL;
|
||||
return zenMode.getInterruptionFilter() != INTERRUPTION_FILTER_ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,7 +70,7 @@ class ZenModeOtherLinkPreferenceController extends AbstractZenModePreferenceCont
|
||||
ZenSubSettingLauncher.forModeFragment(mContext, ZenModeOtherFragment.class,
|
||||
zenMode.getId(), SettingsEnums.ZEN_PRIORITY_MODE).toIntent());
|
||||
|
||||
preference.setEnabled(zenMode.isEnabled());
|
||||
preference.setEnabled(zenMode.isEnabled() && zenMode.canEditPolicy());
|
||||
preference.setSummary(mSummaryHelper.getOtherSoundCategoriesSummary(zenMode));
|
||||
((CircularIconsPreference) preference).setIcons(getSoundIcons(zenMode.getPolicy()));
|
||||
}
|
||||
|
@@ -84,7 +84,7 @@ class ZenModePeopleLinkPreferenceController extends AbstractZenModePreferenceCon
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(ZenMode zenMode) {
|
||||
return zenMode.getRule().getInterruptionFilter() != INTERRUPTION_FILTER_ALL;
|
||||
return zenMode.getInterruptionFilter() != INTERRUPTION_FILTER_ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,7 +94,7 @@ class ZenModePeopleLinkPreferenceController extends AbstractZenModePreferenceCon
|
||||
ZenSubSettingLauncher.forModeFragment(mContext, ZenModePeopleFragment.class,
|
||||
zenMode.getId(), SettingsEnums.ZEN_PRIORITY_MODE).toIntent());
|
||||
|
||||
preference.setEnabled(zenMode.isEnabled());
|
||||
preference.setEnabled(zenMode.isEnabled() && zenMode.canEditPolicy());
|
||||
preference.setSummary(mSummaryHelper.getPeopleSummary(zenMode.getPolicy()));
|
||||
((CircularIconsPreference) preference).setIcons(getPeopleIcons(zenMode.getPolicy()),
|
||||
PEOPLE_ITEM_EQUIVALENCE);
|
||||
|
@@ -209,12 +209,11 @@ class ZenModeSummaryHelper {
|
||||
boolean isFirst = true;
|
||||
List<String> enabledEffects = new ArrayList<>();
|
||||
if (!zenMode.getPolicy().shouldShowAllVisualEffects()
|
||||
&& zenMode.getRule().getInterruptionFilter() != INTERRUPTION_FILTER_ALL) {
|
||||
&& zenMode.getInterruptionFilter() != INTERRUPTION_FILTER_ALL) {
|
||||
enabledEffects.add(getBlockedEffectsSummary(zenMode));
|
||||
isFirst = false;
|
||||
}
|
||||
ZenDeviceEffects currEffects = zenMode.getRule().getDeviceEffects();
|
||||
if (currEffects != null) {
|
||||
ZenDeviceEffects currEffects = zenMode.getDeviceEffects();
|
||||
if (currEffects.shouldDisplayGrayscale()) {
|
||||
if (isFirst) {
|
||||
enabledEffects.add(mContext.getString(R.string.mode_grayscale_title));
|
||||
@@ -251,7 +250,6 @@ class ZenModeSummaryHelper {
|
||||
}
|
||||
isFirst = false;
|
||||
}
|
||||
}
|
||||
|
||||
int numCategories = enabledEffects.size();
|
||||
MessageFormat msgFormat = new MessageFormat(
|
||||
|
@@ -87,7 +87,7 @@ class ZenModeTriggerUpdatePreferenceController extends AbstractZenModePreference
|
||||
|
||||
mModeName = zenMode.getName();
|
||||
PrimarySwitchPreference triggerPref = (PrimarySwitchPreference) preference;
|
||||
triggerPref.setChecked(zenMode.getRule().isEnabled());
|
||||
triggerPref.setChecked(zenMode.isEnabled());
|
||||
triggerPref.setOnPreferenceChangeListener(mSwitchChangeListener);
|
||||
if (zenMode.isSystemOwned()) {
|
||||
setUpForSystemOwnedTrigger(triggerPref, zenMode);
|
||||
@@ -213,7 +213,7 @@ class ZenModeTriggerUpdatePreferenceController extends AbstractZenModePreference
|
||||
|
||||
private void setModeEnabled(boolean enabled) {
|
||||
saveMode((zenMode) -> {
|
||||
if (enabled != zenMode.getRule().isEnabled()) {
|
||||
if (enabled != zenMode.isEnabled()) {
|
||||
zenMode.getRule().setEnabled(enabled);
|
||||
}
|
||||
return zenMode;
|
||||
|
@@ -118,7 +118,7 @@ class ZenModesListPreferenceController extends BasePreferenceController
|
||||
for (ZenMode mode : mBackend.getModes()) {
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(mContext);
|
||||
data.key = mode.getId();
|
||||
data.title = mode.getRule().getName();
|
||||
data.title = mode.getName();
|
||||
data.screenTitle = res.getString(R.string.zen_modes_list_title);
|
||||
rawData.add(data);
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
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 android.service.notification.ZenPolicy.STATE_DISALLOW;
|
||||
|
||||
@@ -67,6 +68,26 @@ public final class InterruptionFilterPreferenceControllerTest {
|
||||
mController = new InterruptionFilterPreferenceController(mContext, "something", mBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_dnd_enabled() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode dnd = TestModeBuilder.MANUAL_DND_ACTIVE;
|
||||
|
||||
mController.updateState(preference, dnd);
|
||||
|
||||
verify(preference).setEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_specialDnd_disabled() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
ZenMode specialDnd = TestModeBuilder.manualDnd(INTERRUPTION_FILTER_NONE, true);
|
||||
|
||||
mController.updateState(preference, specialDnd);
|
||||
|
||||
verify(preference).setEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_disabled() {
|
||||
TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_NONE;
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||
import static android.provider.Settings.EXTRA_AUTOMATIC_ZEN_RULE_ID;
|
||||
|
||||
@@ -149,6 +150,20 @@ public final class ZenModeAppsLinkPreferenceControllerTest {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_dnd_enabled() {
|
||||
ZenMode dnd = TestModeBuilder.MANUAL_DND_ACTIVE;
|
||||
mController.updateState(mPreference, dnd);
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_specialDnd_disabled() {
|
||||
ZenMode specialDnd = TestModeBuilder.manualDnd(INTERRUPTION_FILTER_NONE, true);
|
||||
mController.updateState(mPreference, specialDnd);
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_disabled() {
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_NONE;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -63,6 +65,26 @@ public final class ZenModeDisplayLinkPreferenceControllerTest {
|
||||
mContext, "something", mBackend, mHelperBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_dnd_enabled() {
|
||||
Preference preference = mock(Preference.class);
|
||||
ZenMode dnd = TestModeBuilder.MANUAL_DND_ACTIVE;
|
||||
|
||||
mController.updateState(preference, dnd);
|
||||
|
||||
verify(preference).setEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_specialDnd_disabled() {
|
||||
Preference preference = mock(Preference.class);
|
||||
ZenMode specialDnd = TestModeBuilder.manualDnd(INTERRUPTION_FILTER_NONE, true);
|
||||
|
||||
mController.updateState(preference, specialDnd);
|
||||
|
||||
verify(preference).setEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_disabled() {
|
||||
Preference preference = mock(Preference.class);
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.service.notification.SystemZenRules.PACKAGE_ANDROID;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -77,6 +79,7 @@ public class ZenModeExitAtAlarmPreferenceControllerTest {
|
||||
scheduleInfo.exitAtAlarm = false;
|
||||
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setPackage(PACKAGE_ANDROID)
|
||||
.setConditionId(ZenModeConfig.toScheduleConditionId(scheduleInfo))
|
||||
.build();
|
||||
|
||||
@@ -105,6 +108,7 @@ public class ZenModeExitAtAlarmPreferenceControllerTest {
|
||||
scheduleInfo.exitAtAlarm = true;
|
||||
|
||||
ZenMode mode = new TestModeBuilder()
|
||||
.setPackage(PACKAGE_ANDROID)
|
||||
.setConditionId(ZenModeConfig.toScheduleConditionId(scheduleInfo))
|
||||
.build();
|
||||
mPrefController.updateZenMode(preference, mode);
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_NONE;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -61,6 +63,26 @@ public final class ZenModeOtherLinkPreferenceControllerTest {
|
||||
mContext, "something", mHelperBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_dnd_enabled() {
|
||||
CircularIconsPreference preference = mock(CircularIconsPreference.class);
|
||||
ZenMode dnd = TestModeBuilder.MANUAL_DND_ACTIVE;
|
||||
|
||||
mController.updateState(preference, dnd);
|
||||
|
||||
verify(preference).setEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_specialDnd_disabled() {
|
||||
CircularIconsPreference preference = mock(CircularIconsPreference.class);
|
||||
ZenMode specialDnd = TestModeBuilder.manualDnd(INTERRUPTION_FILTER_NONE, true);
|
||||
|
||||
mController.updateState(preference, specialDnd);
|
||||
|
||||
verify(preference).setEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_disabled() {
|
||||
CircularIconsPreference pref = mock(CircularIconsPreference.class);
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import static android.app.NotificationManager.INTERRUPTION_FILTER_NONE;
|
||||
import static android.service.notification.ZenPolicy.CONVERSATION_SENDERS_IMPORTANT;
|
||||
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_ANYONE;
|
||||
import static android.service.notification.ZenPolicy.PEOPLE_TYPE_CONTACTS;
|
||||
@@ -116,6 +117,20 @@ public final class ZenModePeopleLinkPreferenceControllerTest {
|
||||
anyBoolean())).thenReturn(new ColorDrawable(Color.BLACK));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_dnd_enabled() {
|
||||
ZenMode dnd = TestModeBuilder.MANUAL_DND_ACTIVE;
|
||||
mController.updateState(mPreference, dnd);
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_specialDnd_disabled() {
|
||||
ZenMode specialDnd = TestModeBuilder.manualDnd(INTERRUPTION_FILTER_NONE, true);
|
||||
mController.updateState(mPreference, specialDnd);
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_disabled() {
|
||||
ZenMode zenMode = new TestModeBuilder()
|
||||
|
Reference in New Issue
Block a user