Merge "Update channel DND setting" into pi-dev am: e06a4abb5c
am: 98be07d793
Change-Id: Iba9f10aa37541d29fa83c817dd728c588f55f352
This commit is contained in:
@@ -7662,7 +7662,7 @@
|
|||||||
<string name="app_notification_override_dnd_title">Override Do Not Disturb</string>
|
<string name="app_notification_override_dnd_title">Override Do Not Disturb</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=NONE] App notification settings: Override DND option description-->
|
<!-- [CHAR LIMIT=NONE] App notification settings: Override DND option description-->
|
||||||
<string name="app_notification_override_dnd_summary">Let these notifications continue to interrupt when Do Not Disturb is set to Priority Only</string>
|
<string name="app_notification_override_dnd_summary">Let these notifications continue to interrupt when Do Not Disturb is on</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=NONE] App notification settings: Visibility override option title -->
|
<!-- [CHAR LIMIT=NONE] App notification settings: Visibility override option title -->
|
||||||
<string name="app_notification_visibility_override_title">On lock screen</string>
|
<string name="app_notification_visibility_override_title">On lock screen</string>
|
||||||
|
@@ -29,10 +29,9 @@ import com.android.settingslib.core.lifecycle.events.OnResume;
|
|||||||
|
|
||||||
public class DndPreferenceController extends NotificationPreferenceController
|
public class DndPreferenceController extends NotificationPreferenceController
|
||||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
|
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
|
||||||
LifecycleObserver, OnResume {
|
LifecycleObserver {
|
||||||
|
|
||||||
private static final String KEY_BYPASS_DND = "bypass_dnd";
|
private static final String KEY_BYPASS_DND = "bypass_dnd";
|
||||||
private boolean mVisualEffectsSuppressed;
|
|
||||||
|
|
||||||
public DndPreferenceController(Context context, Lifecycle lifecycle,
|
public DndPreferenceController(Context context, Lifecycle lifecycle,
|
||||||
NotificationBackend backend) {
|
NotificationBackend backend) {
|
||||||
@@ -42,12 +41,6 @@ public class DndPreferenceController extends NotificationPreferenceController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
NotificationManager.Policy policy = mNm.getNotificationPolicy();
|
|
||||||
mVisualEffectsSuppressed = policy != null && policy.suppressedVisualEffects != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return KEY_BYPASS_DND;
|
return KEY_BYPASS_DND;
|
||||||
@@ -55,12 +48,10 @@ public class DndPreferenceController extends NotificationPreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
if (!super.isAvailable()) {
|
if (!super.isAvailable() || mChannel == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
|
return true;
|
||||||
|| (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW)
|
|
||||||
&& mVisualEffectsSuppressed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
@@ -82,5 +73,4 @@ public class DndPreferenceController extends NotificationPreferenceController
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -80,50 +80,19 @@ public class DndPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoCrashIfNoOnResume() {
|
public void testIsAvailable_app() {
|
||||||
mController.isAvailable();
|
|
||||||
mController.updateState(mock(RestrictedSwitchPreference.class));
|
|
||||||
mController.onPreferenceChange(mock(RestrictedSwitchPreference.class), true);
|
|
||||||
mController.onResume();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsAvailable_notIfNotImportant_noVisEffects() {
|
|
||||||
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 0));
|
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 0));
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
|
mController.onResume(appRow, null, null, null);
|
||||||
mController.onResume();
|
|
||||||
mController.onResume(appRow, channel, null, null);
|
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfNotImportant_visEffects() {
|
public void testIsAvailable_channel() {
|
||||||
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 1));
|
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 1));
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_MIN);
|
NotificationChannel channel =
|
||||||
mController.onResume();
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_MIN);
|
||||||
mController.onResume(appRow, channel, null, null);
|
|
||||||
assertFalse(mController.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsAvailable_importance_noVisEffects() {
|
|
||||||
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 0));
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
|
||||||
mController.onResume();
|
|
||||||
mController.onResume(appRow, channel, null, null);
|
|
||||||
assertTrue(mController.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsAvailable_important_visEffects() {
|
|
||||||
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 1));
|
|
||||||
assertTrue(mNm.getNotificationPolicy().suppressedVisualEffects != 0);
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
|
|
||||||
mController.onResume();
|
|
||||||
mController.onResume(appRow, channel, null, null);
|
mController.onResume(appRow, channel, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user