From 73c647513bfbb376eee7b156fe4777b2a4333b70 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Thu, 18 Apr 2019 14:45:14 -0400 Subject: [PATCH] Non-blockable whitelist should only control importance fields Sounds, etc. should still be modifiable Test: robotests Fixes: 130086523 Change-Id: I1a95a73b299bb3afd169b249a3dabae3583a448a --- .../AllowSoundPreferenceController.java | 2 +- .../notification/BadgePreferenceController.java | 2 +- .../notification/BubblePreferenceController.java | 2 +- .../notification/DndPreferenceController.java | 2 +- .../HighImportancePreferenceController.java | 4 ++-- .../ImportancePreferenceController.java | 4 ++-- .../notification/LightsPreferenceController.java | 2 +- .../MinImportancePreferenceController.java | 4 ++-- .../NotificationPreferenceController.java | 2 +- .../notification/SoundPreferenceController.java | 2 +- .../notification/VibrationPreferenceController.java | 2 +- .../NotificationPreferenceControllerTest.java | 13 ++++++------- 12 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/com/android/settings/notification/AllowSoundPreferenceController.java b/src/com/android/settings/notification/AllowSoundPreferenceController.java index cbabd2d6e1d..7862f4bb9c2 100644 --- a/src/com/android/settings/notification/AllowSoundPreferenceController.java +++ b/src/com/android/settings/notification/AllowSoundPreferenceController.java @@ -62,7 +62,7 @@ public class AllowSoundPreferenceController extends NotificationPreferenceContro if (mChannel != null) { RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference; pref.setDisabledByAdmin(mAdmin); - pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin()); + pref.setEnabled(!pref.isDisabledByAdmin()); pref.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT || mChannel.getImportance() == IMPORTANCE_UNSPECIFIED); } else { Log.i(TAG, "tried to updatestate on a null channel?!"); } diff --git a/src/com/android/settings/notification/BadgePreferenceController.java b/src/com/android/settings/notification/BadgePreferenceController.java index 67332a44bb4..e40324e4f84 100644 --- a/src/com/android/settings/notification/BadgePreferenceController.java +++ b/src/com/android/settings/notification/BadgePreferenceController.java @@ -72,7 +72,7 @@ public class BadgePreferenceController extends NotificationPreferenceController pref.setDisabledByAdmin(mAdmin); if (mChannel != null) { pref.setChecked(mChannel.canShowBadge()); - pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin()); + pref.setEnabled(!pref.isDisabledByAdmin()); } else { pref.setChecked(mAppRow.showBadge); } diff --git a/src/com/android/settings/notification/BubblePreferenceController.java b/src/com/android/settings/notification/BubblePreferenceController.java index e5a1a6244e9..f373752ed94 100644 --- a/src/com/android/settings/notification/BubblePreferenceController.java +++ b/src/com/android/settings/notification/BubblePreferenceController.java @@ -81,7 +81,7 @@ public class BubblePreferenceController extends NotificationPreferenceController pref.setDisabledByAdmin(mAdmin); if (mChannel != null) { pref.setChecked(mChannel.canBubble()); - pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin()); + pref.setEnabled(!pref.isDisabledByAdmin()); } else { pref.setChecked(mAppRow.allowBubbles && Settings.Secure.getInt(mContext.getContentResolver(), diff --git a/src/com/android/settings/notification/DndPreferenceController.java b/src/com/android/settings/notification/DndPreferenceController.java index a615221dff9..4ec76f1c6d6 100644 --- a/src/com/android/settings/notification/DndPreferenceController.java +++ b/src/com/android/settings/notification/DndPreferenceController.java @@ -50,7 +50,7 @@ public class DndPreferenceController extends NotificationPreferenceController if (mChannel != null) { RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference; pref.setDisabledByAdmin(mAdmin); - pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin()); + pref.setEnabled(!pref.isDisabledByAdmin()); pref.setChecked(mChannel.canBypassDnd()); } } diff --git a/src/com/android/settings/notification/HighImportancePreferenceController.java b/src/com/android/settings/notification/HighImportancePreferenceController.java index fe843fd5078..b82cb1facc2 100644 --- a/src/com/android/settings/notification/HighImportancePreferenceController.java +++ b/src/com/android/settings/notification/HighImportancePreferenceController.java @@ -61,8 +61,8 @@ public class HighImportancePreferenceController extends NotificationPreferenceCo @Override public void updateState(Preference preference) { - if (mAppRow!= null && mChannel != null) { - preference.setEnabled(mAdmin == null && isChannelConfigurable()); + if (mAppRow != null && mChannel != null) { + preference.setEnabled(mAdmin == null && isChannelBlockable()); RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference; pref.setChecked(mChannel.getImportance() >= IMPORTANCE_HIGH); diff --git a/src/com/android/settings/notification/ImportancePreferenceController.java b/src/com/android/settings/notification/ImportancePreferenceController.java index 6fde9aa67ef..708fc15bf38 100644 --- a/src/com/android/settings/notification/ImportancePreferenceController.java +++ b/src/com/android/settings/notification/ImportancePreferenceController.java @@ -59,9 +59,9 @@ public class ImportancePreferenceController extends NotificationPreferenceContro @Override public void updateState(Preference preference) { if (mAppRow!= null && mChannel != null) { - preference.setEnabled(mAdmin == null && isChannelConfigurable()); + preference.setEnabled(mAdmin == null && isChannelBlockable()); ImportancePreference pref = (ImportancePreference) preference; - pref.setConfigurable(isChannelConfigurable()); + pref.setConfigurable(isChannelBlockable()); pref.setImportance(mChannel.getImportance()); pref.setDisplayInStatusBar(mBackend.showSilentInStatusBar(mContext.getPackageName())); // TODO: b/128445911 pass along lock screen setting diff --git a/src/com/android/settings/notification/LightsPreferenceController.java b/src/com/android/settings/notification/LightsPreferenceController.java index 04f25510c2e..21dabbf74a9 100644 --- a/src/com/android/settings/notification/LightsPreferenceController.java +++ b/src/com/android/settings/notification/LightsPreferenceController.java @@ -56,7 +56,7 @@ public class LightsPreferenceController extends NotificationPreferenceController if (mChannel != null) { RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference; pref.setDisabledByAdmin(mAdmin); - pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin()); + pref.setEnabled(!pref.isDisabledByAdmin()); pref.setChecked(mChannel.shouldShowLights()); } } diff --git a/src/com/android/settings/notification/MinImportancePreferenceController.java b/src/com/android/settings/notification/MinImportancePreferenceController.java index 771ac609fc5..84cead13f1d 100644 --- a/src/com/android/settings/notification/MinImportancePreferenceController.java +++ b/src/com/android/settings/notification/MinImportancePreferenceController.java @@ -61,8 +61,8 @@ public class MinImportancePreferenceController extends NotificationPreferenceCon @Override public void updateState(Preference preference) { - if (mAppRow!= null && mChannel != null) { - preference.setEnabled(mAdmin == null && isChannelConfigurable()); + if (mAppRow != null && mChannel != null) { + preference.setEnabled(mAdmin == null && isChannelBlockable()); RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference; pref.setChecked(mChannel.getImportance() == IMPORTANCE_MIN); diff --git a/src/com/android/settings/notification/NotificationPreferenceController.java b/src/com/android/settings/notification/NotificationPreferenceController.java index 99f7e208871..1bfe47ecf96 100644 --- a/src/com/android/settings/notification/NotificationPreferenceController.java +++ b/src/com/android/settings/notification/NotificationPreferenceController.java @@ -110,7 +110,7 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc } } - protected boolean isChannelConfigurable() { + private boolean isChannelConfigurable() { if (mAppRow != null && mAppRow.lockedImportance) { return false; } diff --git a/src/com/android/settings/notification/SoundPreferenceController.java b/src/com/android/settings/notification/SoundPreferenceController.java index 73cbad3d142..566f3f28452 100644 --- a/src/com/android/settings/notification/SoundPreferenceController.java +++ b/src/com/android/settings/notification/SoundPreferenceController.java @@ -77,7 +77,7 @@ public class SoundPreferenceController extends NotificationPreferenceController public void updateState(Preference preference) { if (mAppRow!= null && mChannel != null) { NotificationSoundPreference pref = (NotificationSoundPreference) preference; - pref.setEnabled(mAdmin == null && isChannelConfigurable()); + pref.setEnabled(mAdmin == null); pref.setRingtone(mChannel.getSound()); } } diff --git a/src/com/android/settings/notification/VibrationPreferenceController.java b/src/com/android/settings/notification/VibrationPreferenceController.java index ec5554a9d45..e6024d0ea9d 100644 --- a/src/com/android/settings/notification/VibrationPreferenceController.java +++ b/src/com/android/settings/notification/VibrationPreferenceController.java @@ -56,7 +56,7 @@ public class VibrationPreferenceController extends NotificationPreferenceControl if (mChannel != null) { RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference; pref.setDisabledByAdmin(mAdmin); - pref.setEnabled(!pref.isDisabledByAdmin() && isChannelConfigurable()); + pref.setEnabled(!pref.isDisabledByAdmin()); pref.setChecked(mChannel.shouldVibrate()); } } diff --git a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java index 626d2e39846..8c743348875 100644 --- a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java @@ -83,7 +83,6 @@ public class NotificationPreferenceControllerTest { mController.updateState(mock(Preference.class)); assertFalse(mController.checkCanBeVisible(IMPORTANCE_UNSPECIFIED)); mController.saveChannel(); - assertFalse(mController.isChannelConfigurable()); assertFalse(mController.isChannelBlockable()); assertFalse(mController.isChannelGroupBlockable()); } @@ -204,7 +203,7 @@ public class NotificationPreferenceControllerTest { } @Test - public void testIsConfigurable() { + public void testIsBlockable_channelLevelWhitelist() { String sameId = "bananas"; NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); appRow.lockedChannelId = sameId; @@ -212,25 +211,25 @@ public class NotificationPreferenceControllerTest { when(channel.getId()).thenReturn(sameId); mController.onResume(appRow, channel, null, null); - assertFalse(mController.isChannelConfigurable()); + assertFalse(mController.isChannelBlockable()); when(channel.getId()).thenReturn("something new"); mController.onResume(appRow, channel, null, null); - assertTrue(mController.isChannelConfigurable()); + assertTrue(mController.isChannelBlockable()); } @Test - public void testIsConfigurable_appLevel() { + public void testIsBlockable_appLevelWhitelist() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); appRow.lockedChannelId = "something"; appRow.lockedImportance = true; mController.onResume(appRow, mock(NotificationChannel.class), null, null); - assertFalse(mController.isChannelConfigurable()); + assertFalse(mController.isChannelBlockable()); appRow.lockedImportance = false; mController.onResume(appRow, mock(NotificationChannel.class), null, null); - assertTrue(mController.isChannelConfigurable()); + assertTrue(mController.isChannelBlockable()); } @Test