summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java7
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java15
2 files changed, 19 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index be6c017a2d11..7f1b25ca3ca3 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -1516,6 +1516,11 @@ public class NotificationManagerService extends SystemService {
}
@VisibleForTesting
+ void setZenHelper(ZenModeHelper zenHelper) {
+ mZenModeHelper = zenHelper;
+ }
+
+ @VisibleForTesting
void setIsAutomotive(boolean isAutomotive) {
mIsAutomotive = isAutomotive;
}
@@ -3563,7 +3568,7 @@ public class NotificationManagerService extends SystemService {
return;
}
boolean accessAllowed = false;
- String[] packages = getContext().getPackageManager().getPackagesForUid(uid);
+ String[] packages = mPackageManagerClient.getPackagesForUid(uid);
final int packageCount = packages.length;
for (int i = 0; i < packageCount; i++) {
if (mConditionProviders.isPackageOrComponentAllowed(
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 91d9078e72cc..355ff63d18f7 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -348,6 +348,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
when(mPackageManagerClient.hasSystemFeature(FEATURE_WATCH)).thenReturn(false);
when(mUgmInternal.newUriPermissionOwner(anyString())).thenReturn(mPermOwner);
when(mPackageManager.getPackagesForUid(mUid)).thenReturn(new String[]{PKG});
+ when(mPackageManagerClient.getPackagesForUid(anyInt())).thenReturn(new String[]{PKG});
// write to a test file; the system file isn't readable from tests
mFile = new File(mContext.getCacheDir(), "test.xml");
@@ -4948,6 +4949,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
assertEquals(1, mService.getNotificationRecordCount());
}
+ @Test
public void testGetAllowedAssistantAdjustments() throws Exception {
List<String> capabilities = mBinderService.getAllowedAssistantAdjustments(null);
assertNotNull(capabilities);
@@ -4962,8 +4964,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
}
}
+ @Test
public void testAdjustRestrictedKey() throws Exception {
NotificationRecord r = generateNotificationRecord(mTestNotificationChannel);
+ mService.addNotification(r);
+ when(mAssistants.isSameUser(any(), anyInt())).thenReturn(true);
when(mAssistants.isAdjustmentAllowed(KEY_IMPORTANCE)).thenReturn(true);
when(mAssistants.isAdjustmentAllowed(KEY_USER_SENTIMENT)).thenReturn(false);
@@ -4981,8 +4986,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
assertEquals(USER_SENTIMENT_NEUTRAL, r.getUserSentiment());
}
+ @Test
public void testAutomaticZenRuleValidation_policyFilterAgreement() throws Exception {
- ComponentName owner = mock(ComponentName.class);
+ when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt()))
+ .thenReturn(true);
+ mService.setZenHelper(mock(ZenModeHelper.class));
+ ComponentName owner = new ComponentName(mContext, this.getClass());
ZenPolicy zenPolicy = new ZenPolicy.Builder().allowAlarms(true).build();
boolean isEnabled = true;
AutomaticZenRule rule = new AutomaticZenRule("test", owner, owner, mock(Uri.class),
@@ -4990,7 +4999,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
try {
mBinderService.addAutomaticZenRule(rule);
- fail("Zen policy only aplies to priority only mode");
+ fail("Zen policy only applies to priority only mode");
} catch (IllegalArgumentException e) {
// yay
}
@@ -5004,6 +5013,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mBinderService.addAutomaticZenRule(rule);
}
+ @Test
public void testAreNotificationsEnabledForPackage_crossUser() throws Exception {
try {
mBinderService.areNotificationsEnabledForPackage(mContext.getPackageName(),
@@ -5020,6 +5030,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mUid + UserHandle.PER_USER_RANGE);
}
+ @Test
public void testAreBubblesAllowedForPackage_crossUser() throws Exception {
try {
mBinderService.areBubblesAllowedForPackage(mContext.getPackageName(),