[DO NOT MERGE] Revert "Fix system zen rules by using owner package name if caller is system"

This reverts commit 0b262d0ae5.

Reason for revert: broke DND schedules in multi-user mode b/257477671

Change-Id: I6f89dd0406b6815a94e6b37c029601dfc315b1f8
This commit is contained in:
Yuri Lin
2022-11-07 19:05:55 +00:00
committed by Android (Google) Code Review
parent 0b262d0ae5
commit 8de098ee2f
2 changed files with 1 additions and 47 deletions

View File

@@ -4471,16 +4471,7 @@ public class NotificationManagerService extends SystemService {
} }
enforcePolicyAccess(Binder.getCallingUid(), "addAutomaticZenRule"); enforcePolicyAccess(Binder.getCallingUid(), "addAutomaticZenRule");
// If the caller is system, take the package name from the rule's owner rather than return mZenModeHelper.addAutomaticZenRule(pkg, automaticZenRule,
// from the caller's package.
String rulePkg = pkg;
if (isCallingUidSystem()) {
if (automaticZenRule.getOwner() != null) {
rulePkg = automaticZenRule.getOwner().getPackageName();
}
}
return mZenModeHelper.addAutomaticZenRule(rulePkg, automaticZenRule,
"addAutomaticZenRule"); "addAutomaticZenRule");
} }

View File

@@ -5913,43 +5913,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mBinderService.addAutomaticZenRule(rule, mContext.getPackageName()); mBinderService.addAutomaticZenRule(rule, mContext.getPackageName());
} }
@Test
public void testAddAutomaticZenRule_systemCallTakesPackageFromOwner() throws Exception {
mService.isSystemUid = true;
ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class);
when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt()))
.thenReturn(true);
mService.setZenHelper(mockZenModeHelper);
ComponentName owner = new ComponentName("android", "ProviderName");
ZenPolicy zenPolicy = new ZenPolicy.Builder().allowAlarms(true).build();
boolean isEnabled = true;
AutomaticZenRule rule = new AutomaticZenRule("test", owner, owner, mock(Uri.class),
zenPolicy, NotificationManager.INTERRUPTION_FILTER_PRIORITY, isEnabled);
mBinderService.addAutomaticZenRule(rule, "com.android.settings");
// verify that zen mode helper gets passed in a package name of "android"
verify(mockZenModeHelper).addAutomaticZenRule(eq("android"), eq(rule), anyString());
}
@Test
public void testAddAutomaticZenRule_nonSystemCallTakesPackageFromArg() throws Exception {
mService.isSystemUid = false;
ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class);
when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt()))
.thenReturn(true);
mService.setZenHelper(mockZenModeHelper);
ComponentName owner = new ComponentName("android", "ProviderName");
ZenPolicy zenPolicy = new ZenPolicy.Builder().allowAlarms(true).build();
boolean isEnabled = true;
AutomaticZenRule rule = new AutomaticZenRule("test", owner, owner, mock(Uri.class),
zenPolicy, NotificationManager.INTERRUPTION_FILTER_PRIORITY, isEnabled);
mBinderService.addAutomaticZenRule(rule, "another.package");
// verify that zen mode helper gets passed in the package name from the arg, not the owner
verify(mockZenModeHelper).addAutomaticZenRule(
eq("another.package"), eq(rule), anyString());
}
@Test @Test
public void testAreNotificationsEnabledForPackage_crossUser() throws Exception { public void testAreNotificationsEnabledForPackage_crossUser() throws Exception {
try { try {