Non-blockable whitelist should only control importance fields
Sounds, etc. should still be modifiable Test: robotests Fixes: 130086523 Change-Id: I1a95a73b299bb3afd169b249a3dabae3583a448a
This commit is contained in:
@@ -62,7 +62,7 @@ public class AllowSoundPreferenceController extends NotificationPreferenceContro
|
|||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||||
pref.setDisabledByAdmin(mAdmin);
|
pref.setDisabledByAdmin(mAdmin);
|
||||||
pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin());
|
pref.setEnabled(!pref.isDisabledByAdmin());
|
||||||
pref.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT
|
pref.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT
|
||||||
|| mChannel.getImportance() == IMPORTANCE_UNSPECIFIED);
|
|| mChannel.getImportance() == IMPORTANCE_UNSPECIFIED);
|
||||||
} else { Log.i(TAG, "tried to updatestate on a null channel?!"); }
|
} else { Log.i(TAG, "tried to updatestate on a null channel?!"); }
|
||||||
|
@@ -72,7 +72,7 @@ public class BadgePreferenceController extends NotificationPreferenceController
|
|||||||
pref.setDisabledByAdmin(mAdmin);
|
pref.setDisabledByAdmin(mAdmin);
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
pref.setChecked(mChannel.canShowBadge());
|
pref.setChecked(mChannel.canShowBadge());
|
||||||
pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin());
|
pref.setEnabled(!pref.isDisabledByAdmin());
|
||||||
} else {
|
} else {
|
||||||
pref.setChecked(mAppRow.showBadge);
|
pref.setChecked(mAppRow.showBadge);
|
||||||
}
|
}
|
||||||
|
@@ -81,7 +81,7 @@ public class BubblePreferenceController extends NotificationPreferenceController
|
|||||||
pref.setDisabledByAdmin(mAdmin);
|
pref.setDisabledByAdmin(mAdmin);
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
pref.setChecked(mChannel.canBubble());
|
pref.setChecked(mChannel.canBubble());
|
||||||
pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin());
|
pref.setEnabled(!pref.isDisabledByAdmin());
|
||||||
} else {
|
} else {
|
||||||
pref.setChecked(mAppRow.allowBubbles
|
pref.setChecked(mAppRow.allowBubbles
|
||||||
&& Settings.Secure.getInt(mContext.getContentResolver(),
|
&& Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
@@ -50,7 +50,7 @@ public class DndPreferenceController extends NotificationPreferenceController
|
|||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||||
pref.setDisabledByAdmin(mAdmin);
|
pref.setDisabledByAdmin(mAdmin);
|
||||||
pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin());
|
pref.setEnabled(!pref.isDisabledByAdmin());
|
||||||
pref.setChecked(mChannel.canBypassDnd());
|
pref.setChecked(mChannel.canBypassDnd());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -61,8 +61,8 @@ public class HighImportancePreferenceController extends NotificationPreferenceCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow!= null && mChannel != null) {
|
if (mAppRow != null && mChannel != null) {
|
||||||
preference.setEnabled(mAdmin == null && isChannelConfigurable());
|
preference.setEnabled(mAdmin == null && isChannelBlockable());
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||||
pref.setChecked(mChannel.getImportance() >= IMPORTANCE_HIGH);
|
pref.setChecked(mChannel.getImportance() >= IMPORTANCE_HIGH);
|
||||||
|
@@ -59,9 +59,9 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
|
|||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow!= null && mChannel != null) {
|
if (mAppRow!= null && mChannel != null) {
|
||||||
preference.setEnabled(mAdmin == null && isChannelConfigurable());
|
preference.setEnabled(mAdmin == null && isChannelBlockable());
|
||||||
ImportancePreference pref = (ImportancePreference) preference;
|
ImportancePreference pref = (ImportancePreference) preference;
|
||||||
pref.setConfigurable(isChannelConfigurable());
|
pref.setConfigurable(isChannelBlockable());
|
||||||
pref.setImportance(mChannel.getImportance());
|
pref.setImportance(mChannel.getImportance());
|
||||||
pref.setDisplayInStatusBar(mBackend.showSilentInStatusBar(mContext.getPackageName()));
|
pref.setDisplayInStatusBar(mBackend.showSilentInStatusBar(mContext.getPackageName()));
|
||||||
// TODO: b/128445911 pass along lock screen setting
|
// TODO: b/128445911 pass along lock screen setting
|
||||||
|
@@ -56,7 +56,7 @@ public class LightsPreferenceController extends NotificationPreferenceController
|
|||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||||
pref.setDisabledByAdmin(mAdmin);
|
pref.setDisabledByAdmin(mAdmin);
|
||||||
pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin());
|
pref.setEnabled(!pref.isDisabledByAdmin());
|
||||||
pref.setChecked(mChannel.shouldShowLights());
|
pref.setChecked(mChannel.shouldShowLights());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -61,8 +61,8 @@ public class MinImportancePreferenceController extends NotificationPreferenceCon
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow!= null && mChannel != null) {
|
if (mAppRow != null && mChannel != null) {
|
||||||
preference.setEnabled(mAdmin == null && isChannelConfigurable());
|
preference.setEnabled(mAdmin == null && isChannelBlockable());
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||||
pref.setChecked(mChannel.getImportance() == IMPORTANCE_MIN);
|
pref.setChecked(mChannel.getImportance() == IMPORTANCE_MIN);
|
||||||
|
@@ -110,7 +110,7 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isChannelConfigurable() {
|
private boolean isChannelConfigurable() {
|
||||||
if (mAppRow != null && mAppRow.lockedImportance) {
|
if (mAppRow != null && mAppRow.lockedImportance) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -77,7 +77,7 @@ public class SoundPreferenceController extends NotificationPreferenceController
|
|||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow!= null && mChannel != null) {
|
if (mAppRow!= null && mChannel != null) {
|
||||||
NotificationSoundPreference pref = (NotificationSoundPreference) preference;
|
NotificationSoundPreference pref = (NotificationSoundPreference) preference;
|
||||||
pref.setEnabled(mAdmin == null && isChannelConfigurable());
|
pref.setEnabled(mAdmin == null);
|
||||||
pref.setRingtone(mChannel.getSound());
|
pref.setRingtone(mChannel.getSound());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -56,7 +56,7 @@ public class VibrationPreferenceController extends NotificationPreferenceControl
|
|||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||||
pref.setDisabledByAdmin(mAdmin);
|
pref.setDisabledByAdmin(mAdmin);
|
||||||
pref.setEnabled(!pref.isDisabledByAdmin() && isChannelConfigurable());
|
pref.setEnabled(!pref.isDisabledByAdmin());
|
||||||
pref.setChecked(mChannel.shouldVibrate());
|
pref.setChecked(mChannel.shouldVibrate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -83,7 +83,6 @@ public class NotificationPreferenceControllerTest {
|
|||||||
mController.updateState(mock(Preference.class));
|
mController.updateState(mock(Preference.class));
|
||||||
assertFalse(mController.checkCanBeVisible(IMPORTANCE_UNSPECIFIED));
|
assertFalse(mController.checkCanBeVisible(IMPORTANCE_UNSPECIFIED));
|
||||||
mController.saveChannel();
|
mController.saveChannel();
|
||||||
assertFalse(mController.isChannelConfigurable());
|
|
||||||
assertFalse(mController.isChannelBlockable());
|
assertFalse(mController.isChannelBlockable());
|
||||||
assertFalse(mController.isChannelGroupBlockable());
|
assertFalse(mController.isChannelGroupBlockable());
|
||||||
}
|
}
|
||||||
@@ -204,7 +203,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsConfigurable() {
|
public void testIsBlockable_channelLevelWhitelist() {
|
||||||
String sameId = "bananas";
|
String sameId = "bananas";
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.lockedChannelId = sameId;
|
appRow.lockedChannelId = sameId;
|
||||||
@@ -212,25 +211,25 @@ public class NotificationPreferenceControllerTest {
|
|||||||
when(channel.getId()).thenReturn(sameId);
|
when(channel.getId()).thenReturn(sameId);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null);
|
mController.onResume(appRow, channel, null, null);
|
||||||
assertFalse(mController.isChannelConfigurable());
|
assertFalse(mController.isChannelBlockable());
|
||||||
|
|
||||||
when(channel.getId()).thenReturn("something new");
|
when(channel.getId()).thenReturn("something new");
|
||||||
mController.onResume(appRow, channel, null, null);
|
mController.onResume(appRow, channel, null, null);
|
||||||
assertTrue(mController.isChannelConfigurable());
|
assertTrue(mController.isChannelBlockable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsConfigurable_appLevel() {
|
public void testIsBlockable_appLevelWhitelist() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.lockedChannelId = "something";
|
appRow.lockedChannelId = "something";
|
||||||
appRow.lockedImportance = true;
|
appRow.lockedImportance = true;
|
||||||
|
|
||||||
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
|
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
|
||||||
assertFalse(mController.isChannelConfigurable());
|
assertFalse(mController.isChannelBlockable());
|
||||||
|
|
||||||
appRow.lockedImportance = false;
|
appRow.lockedImportance = false;
|
||||||
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
|
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
|
||||||
assertTrue(mController.isChannelConfigurable());
|
assertTrue(mController.isChannelBlockable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user