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

@@ -30,6 +30,7 @@ import static org.robolectric.Shadows.shadowOf;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.role.RoleManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
@@ -345,7 +346,7 @@ public class NotificationChannelSliceTest {
doReturn(buildNotificationChannelGroups(channels)).when(mNotificationBackend).getGroups(
any(String.class), any(int.class));
doReturn(appRow).when(mNotificationBackend).loadAppRow(any(Context.class),
any(PackageManager.class), any(PackageInfo.class));
any(PackageManager.class), any(RoleManager.class), any(PackageInfo.class));
doReturn(channelCount).when(mNotificationBackend).getChannelCount(
any(String.class), any(int.class));
}

View File

@@ -21,6 +21,7 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import android.app.role.RoleManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
@@ -65,7 +66,7 @@ public class NotificationMultiChannelAppRowTest {
mNotificationMultiChannelAppRow.call();
verify(mNotificationBackend).loadAppRow(any(Context.class), any(PackageManager.class),
any(PackageInfo.class));
any(RoleManager.class), any(PackageInfo.class));
}
@Test
@@ -76,6 +77,6 @@ public class NotificationMultiChannelAppRowTest {
mNotificationMultiChannelAppRow.call();
verify(mNotificationBackend, never()).loadAppRow(any(Context.class),
any(PackageManager.class), any(PackageInfo.class));
any(PackageManager.class), any(RoleManager.class), any(PackageInfo.class));
}
}

View File

@@ -139,12 +139,11 @@ public class AllowSoundPreferenceControllerTest {
}
@Test
public void testUpdateState_notBlockable() {
String lockedId = "locked";
public void testUpdateState_notBlockable_oem() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = lockedId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(lockedId);
when(channel.getId()).thenReturn("");
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);

View File

@@ -188,11 +188,10 @@ public class BadgePreferenceControllerTest {
@Test
public void testUpdateState_channelNotBlockable() {
String lockedId = "locked";
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = lockedId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(lockedId);
when(channel.getId()).thenReturn("");
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
@@ -204,7 +203,6 @@ public class BadgePreferenceControllerTest {
@Test
public void testUpdateState_channel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = "a";
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canShowBadge()).thenReturn(true);
mController.onResume(appRow, channel, null, null);

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();

View File

@@ -203,11 +203,9 @@ public class BubblePreferenceControllerTest {
@Test
public void testUpdateState_channelNotBlockable() {
String lockedId = "locked";
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = lockedId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(lockedId);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);
@@ -219,7 +217,6 @@ public class BubblePreferenceControllerTest {
@Test
public void testUpdateState_channel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = "a";
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canBubble()).thenReturn(true);
mController.onResume(appRow, channel, null, null);

View File

@@ -111,11 +111,9 @@ public class DndPreferenceControllerTest {
@Test
public void testUpdateState_notBlockable() {
String lockedId = "locked";
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = lockedId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(lockedId);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);

View File

@@ -142,11 +142,9 @@ public class HighImportancePreferenceControllerTest {
@Test
public void testUpdateState_notConfigurable() {
String lockedId = "locked";
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = lockedId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(lockedId);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
@@ -156,6 +154,36 @@ public class HighImportancePreferenceControllerTest {
assertFalse(pref.isEnabled());
}
@Test
public void testUpdateState_systemButConfigurable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
assertTrue(pref.isEnabled());
}
@Test
public void testUpdateState_defaultApp() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
assertTrue(pref.isEnabled());
}
@Test
public void testUpdateState_high() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();

View File

@@ -159,11 +159,9 @@ public class ImportancePreferenceControllerTest {
@Test
public void testUpdateState_notConfigurable() {
String lockedId = "locked";
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = lockedId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(lockedId);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
@@ -173,6 +171,36 @@ public class ImportancePreferenceControllerTest {
assertFalse(pref.isEnabled());
}
@Test
public void testUpdateState_systemButConfigurable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
Preference pref = new ImportancePreference(mContext, null);
mController.updateState(pref);
assertTrue(pref.isEnabled());
}
@Test
public void testUpdateState_defaultApp() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
Preference pref = new ImportancePreference(mContext, null);
mController.updateState(pref);
assertTrue(pref.isEnabled());
}
@Test
public void testUpdateState() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();

View File

@@ -159,11 +159,9 @@ public class LightsPreferenceControllerTest {
@Test
public void testUpdateState_notBlockable() {
String lockedId = "locked";
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = lockedId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(lockedId);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
Preference pref = new RestrictedSwitchPreference(mContext);

View File

@@ -142,11 +142,9 @@ public class MinImportancePreferenceControllerTest {
@Test
public void testUpdateState_notConfigurable() {
String lockedId = "locked";
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = lockedId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(lockedId);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
@@ -156,6 +154,36 @@ public class MinImportancePreferenceControllerTest {
assertFalse(pref.isEnabled());
}
@Test
public void testUpdateState_systemButConfigurable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByOEM()).thenReturn(false);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
assertTrue(pref.isEnabled());
}
@Test
public void testUpdateState_defaultApp() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
Preference pref = new RestrictedSwitchPreference(mContext, null);
mController.updateState(pref);
assertTrue(pref.isEnabled());
}
@Test
public void testUpdateState_min() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();

View File

@@ -18,22 +18,28 @@ package com.android.settings.notification;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import android.app.role.RoleManager;
import android.app.usage.UsageEvents;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Parcel;
import com.android.settings.notification.NotificationBackend.AppRow;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
import java.util.List;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class NotificationBackendTest {
@@ -50,81 +56,40 @@ public class NotificationBackendTest {
// This package has a package lock but no locked channels
assertTrue(appRow.lockedImportance);
assertNull(appRow.lockedChannelId);
}
@Test
public void testMarkAppRow_unblockableChannelOrPkg() {
String channelBlockName = "foo.bar.pkgWithChannel";
String pkgBlockName = "foo.bar.pkgBlock";
String[] nonBlockablePkgs = new String[2];
nonBlockablePkgs[0] = pkgBlockName;
nonBlockablePkgs[1] = channelBlockName + ":SpecificChannel";
public void testMarkAppRow_defaultPackage() {
PackageInfo pi = new PackageInfo();
pi.packageName = "test";
pi.applicationInfo = new ApplicationInfo();
pi.applicationInfo.packageName = "test";
List<String> roles = new ArrayList<>();
roles.add(RoleManager.ROLE_DIALER);
RoleManager rm = mock(RoleManager.class);
when(rm.getHeldRolesFromController(anyString())).thenReturn(roles);
// This package has a channel level lock but no full package lock
AppRow channelBlockApp = new AppRow();
channelBlockApp.pkg = channelBlockName;
NotificationBackend.markAppRowWithBlockables(nonBlockablePkgs, channelBlockApp,
channelBlockName);
assertFalse(channelBlockApp.lockedImportance);
assertEquals("SpecificChannel", channelBlockApp.lockedChannelId);
AppRow appRow = new NotificationBackend().loadAppRow(RuntimeEnvironment.application,
mock(PackageManager.class), rm, pi);
// This other package has the reverse
AppRow pkgBlock = new AppRow();
pkgBlock.pkg = pkgBlockName;
NotificationBackend.markAppRowWithBlockables(nonBlockablePkgs, pkgBlock, pkgBlockName);
assertTrue(pkgBlock.lockedImportance);
assertNull(pkgBlock.lockedChannelId);
// This third package has no locks at all
AppRow otherAppRow = new AppRow();
otherAppRow.pkg ="foo.bar.nothingBlocked";
NotificationBackend.markAppRowWithBlockables(nonBlockablePkgs, otherAppRow,
"foo.bar.nothingBlocked");
assertFalse(otherAppRow.lockedImportance);
assertNull(otherAppRow.lockedChannelId);
assertTrue(appRow.systemApp);
}
@Test
public void testMarkAppRow_unblockableChannelAndPkg() {
AppRow appRow = new AppRow();
String packageName = "foo.bar.unblockable";
appRow.pkg = packageName;
String[] nonBlockablePkgs = new String[2];
nonBlockablePkgs[0] = "foo.bar.unblockable";
nonBlockablePkgs[1] = "foo.bar.unblockable:SpecificChannel";
NotificationBackend.markAppRowWithBlockables(nonBlockablePkgs, appRow, packageName);
public void testMarkAppRow_notDefaultPackage() {
PackageInfo pi = new PackageInfo();
pi.packageName = "test";
pi.applicationInfo = new ApplicationInfo();
pi.applicationInfo.packageName = "test";
List<String> roles = new ArrayList<>();
roles.add(RoleManager.ROLE_HOME);
RoleManager rm = mock(RoleManager.class);
when(rm.getHeldRolesFromController(anyString())).thenReturn(roles);
// This package has both a channel lock and a package lock
assertTrue(appRow.lockedImportance);
assertEquals("SpecificChannel", appRow.lockedChannelId);
}
AppRow appRow = new NotificationBackend().loadAppRow(RuntimeEnvironment.application,
mock(PackageManager.class), rm, pi);
@Test
public void testMarkAppRow_channelNameWithColons() {
AppRow appRow = new AppRow();
String packageName = "foo.bar.unblockable";
String channelName = "SpecificChannel:1234:abc:defg";
appRow.pkg = packageName;
String[] nonBlockablePkgs = new String[1];
nonBlockablePkgs[0] = packageName + ":" + channelName;
NotificationBackend.markAppRowWithBlockables(nonBlockablePkgs, appRow, packageName);
assertEquals(channelName, appRow.lockedChannelId);
}
@Test
public void testMarkAppRow_blocklistWithNullEntries() {
AppRow appRow = new AppRow();
String packageName = "foo.bar.unblockable";
appRow.pkg = packageName;
String[] nonBlockablePkgs = new String[6]; // extra long list with some entries left null
nonBlockablePkgs[2] = "foo.bar.unblockable";
nonBlockablePkgs[4] = "foo.bar.unblockable:SpecificChannel";
NotificationBackend.markAppRowWithBlockables(nonBlockablePkgs, appRow, packageName);
assertTrue(appRow.lockedImportance);
assertEquals("SpecificChannel", appRow.lockedChannelId);
assertFalse(appRow.systemApp);
}
@Test

View File

@@ -203,36 +203,29 @@ public class NotificationPreferenceControllerTest {
}
@Test
public void testIsBlockable_channelLevelWhitelist() {
String sameId = "bananas";
public void testIsBlockable_oemWhitelist() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = sameId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(sameId);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(appRow, channel, null, null);
assertFalse(mController.isChannelBlockable());
when(channel.getId()).thenReturn("something new");
when(channel.isImportanceLockedByOEM()).thenReturn(false);
mController.onResume(appRow, channel, null, null);
assertTrue(mController.isChannelBlockable());
}
@Test
public void testIsBlockable_appLevelWhitelist() {
public void testIsBlockable_defaultApp() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = "something";
appRow.lockedImportance = true;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
assertFalse(mController.isChannelBlockable());
appRow.lockedImportance = false;
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
assertTrue(mController.isChannelBlockable());
}
@Test
@@ -281,34 +274,6 @@ public class NotificationPreferenceControllerTest {
assertTrue(mController.isChannelBlockable());
}
@Test
public void testIsChannelBlockable_notConfigurable() {
String sameId = "apples";
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = false;
appRow.lockedChannelId = sameId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(sameId);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
mController.onResume(appRow, channel, null, null);
assertFalse(mController.isChannelBlockable());
}
@Test
public void testIsChannelBlockable_notConfigurableButBlocked() {
String sameId = "apples";
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.systemApp = false;
appRow.lockedChannelId = sameId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(sameId);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null);
assertTrue(mController.isChannelBlockable());
}
@Test
public void testIsChannelGroupBlockable_nonSystemBlockable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();

View File

@@ -162,11 +162,9 @@ public class SoundPreferenceControllerTest {
@Test
public void testUpdateState_notBlockable() {
String lockedId = "locked";
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = lockedId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(lockedId);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();

View File

@@ -141,11 +141,9 @@ public class VibrationPreferenceControllerTest {
@Test
public void testUpdateState_notBlockable() {
String lockedId = "locked";
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = lockedId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(lockedId);
when(channel.isImportanceLockedByOEM()).thenReturn(true);
mController.onResume(appRow, channel, null, null);
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);