Fix visibility and editability of importance fields

- Block field should always be visible
- Locked by OEM: cannot block or change importance
- Locked by default app: cannot block, can change importance
- Locked by system app: cannot block, can change importance
- system app but blockable: can block, can change importance

Test: robotests
Fixes: 131248127
Change-Id: Ifa718c84573dd5125aefa4f672a79dc4f267d515
This commit is contained in:
Julia Reynolds
2019-04-26 12:56:50 -04:00
parent 2f2a3c4055
commit a540fa56d4
24 changed files with 293 additions and 194 deletions

View File

@@ -101,23 +101,23 @@ public class BlockPreferenceControllerTest {
}
@Test
public void testIsAvailable_notIfChannelNotBlockable() {
public void testIsAvailable_channelNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
assertFalse(mController.isAvailable());
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_notIfChannelNonDefault() {
public void testIsAvailable_channelNonDefault() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
assertFalse(mController.isAvailable());
assertTrue(mController.isAvailable());
}
@Test
@@ -131,19 +131,19 @@ public class BlockPreferenceControllerTest {
}
@Test
public void testIsAvailable_notIfGroupNotBlockable() {
public void testIsAvailable_GroupNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null);
assertFalse(mController.isAvailable());
assertTrue(mController.isAvailable());
}
@Test
public void testIsAvailable_notIfAppNotBlockable() {
public void testIsAvailable_AppNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
mController.onResume(appRow, null, null, null);
assertFalse(mController.isAvailable());
assertTrue(mController.isAvailable());
}
@Test
@@ -160,13 +160,99 @@ public class BlockPreferenceControllerTest {
public void testIsAvailable_nonSystemApp() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = false;
appRow.lockedChannelId = "not this";
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
assertTrue(mController.isAvailable());
}
@Test
public void testIsEnabled_lockedApp() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedImportance = true;
appRow.systemApp = true;
mController.onResume(appRow, null, null, null);
mController.updateState(mPreference);
assertFalse(mSwitch.isEnabled());
}
@Test
public void testIsEnabled_GroupNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null);
mController.updateState(mPreference);
assertFalse(mSwitch.isEnabled());
}
@Test
public void testIsEnabled_systemAppNotBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
mController.onResume(appRow, null, null, null);
mController.updateState(mPreference);
assertFalse(mSwitch.isEnabled());
}
@Test
public void testIsEnabled_systemAppBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
channel.setBlockableSystem(true);
mController.onResume(appRow, channel, null, null);
mController.updateState(mPreference);
assertTrue(mSwitch.isEnabled());
}
@Test
public void testIsEnabled_lockedChannel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.updateState(mPreference);
assertFalse(mSwitch.isEnabled());
}
@Test
public void testIsEnabled_defaultAppChannel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.updateState(mPreference);
assertFalse(mSwitch.isEnabled());
}
@Test
public void testIsEnabled_channel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
mController.updateState(mPreference);
assertTrue(mSwitch.isEnabled());
}
@Test
public void testIsEnabled_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null);
mController.updateState(mPreference);
assertTrue(mSwitch.isEnabled());
}
@Test
public void testUpdateState_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();