Skip to content

Commit e0bf51a

Browse files
Yuri LinAndroid Build Coastguard Worker
authored andcommitted
Revert "Fix system zen rules by using owner package name if caller is system"
This reverts commit e5e5111. Reason for revert: broke DND schedules in multi-user mode b/257477671 Change-Id: Ic5126e4c95c8ef8c17b339a6fb0f08ca9cc97323 (cherry picked from commit 3535f5c) Merged-In: Ic5126e4c95c8ef8c17b339a6fb0f08ca9cc97323
1 parent b1ad676 commit e0bf51a

2 files changed

Lines changed: 1 addition & 47 deletions

File tree

services/core/java/com/android/server/notification/NotificationManagerService.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4958,16 +4958,7 @@ public String addAutomaticZenRule(AutomaticZenRule automaticZenRule, String pkg)
49584958
}
49594959
enforcePolicyAccess(Binder.getCallingUid(), "addAutomaticZenRule");
49604960

4961-
// If the caller is system, take the package name from the rule's owner rather than
4962-
// from the caller's package.
4963-
String rulePkg = pkg;
4964-
if (isCallingUidSystem()) {
4965-
if (automaticZenRule.getOwner() != null) {
4966-
rulePkg = automaticZenRule.getOwner().getPackageName();
4967-
}
4968-
}
4969-
4970-
return mZenModeHelper.addAutomaticZenRule(rulePkg, automaticZenRule,
4961+
return mZenModeHelper.addAutomaticZenRule(pkg, automaticZenRule,
49714962
"addAutomaticZenRule");
49724963
}
49734964

services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7548,43 +7548,6 @@ public void testAutomaticZenRuleValidation_policyFilterAgreement() throws Except
75487548
mBinderService.addAutomaticZenRule(rule, mContext.getPackageName());
75497549
}
75507550

7551-
@Test
7552-
public void testAddAutomaticZenRule_systemCallTakesPackageFromOwner() throws Exception {
7553-
mService.isSystemUid = true;
7554-
ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class);
7555-
when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt()))
7556-
.thenReturn(true);
7557-
mService.setZenHelper(mockZenModeHelper);
7558-
ComponentName owner = new ComponentName("android", "ProviderName");
7559-
ZenPolicy zenPolicy = new ZenPolicy.Builder().allowAlarms(true).build();
7560-
boolean isEnabled = true;
7561-
AutomaticZenRule rule = new AutomaticZenRule("test", owner, owner, mock(Uri.class),
7562-
zenPolicy, NotificationManager.INTERRUPTION_FILTER_PRIORITY, isEnabled);
7563-
mBinderService.addAutomaticZenRule(rule, "com.android.settings");
7564-
7565-
// verify that zen mode helper gets passed in a package name of "android"
7566-
verify(mockZenModeHelper).addAutomaticZenRule(eq("android"), eq(rule), anyString());
7567-
}
7568-
7569-
@Test
7570-
public void testAddAutomaticZenRule_nonSystemCallTakesPackageFromArg() throws Exception {
7571-
mService.isSystemUid = false;
7572-
ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class);
7573-
when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt()))
7574-
.thenReturn(true);
7575-
mService.setZenHelper(mockZenModeHelper);
7576-
ComponentName owner = new ComponentName("android", "ProviderName");
7577-
ZenPolicy zenPolicy = new ZenPolicy.Builder().allowAlarms(true).build();
7578-
boolean isEnabled = true;
7579-
AutomaticZenRule rule = new AutomaticZenRule("test", owner, owner, mock(Uri.class),
7580-
zenPolicy, NotificationManager.INTERRUPTION_FILTER_PRIORITY, isEnabled);
7581-
mBinderService.addAutomaticZenRule(rule, "another.package");
7582-
7583-
// verify that zen mode helper gets passed in the package name from the arg, not the owner
7584-
verify(mockZenModeHelper).addAutomaticZenRule(
7585-
eq("another.package"), eq(rule), anyString());
7586-
}
7587-
75887551
@Test
75897552
public void testAreNotificationsEnabledForPackage() throws Exception {
75907553
mBinderService.areNotificationsEnabledForPackage(mContext.getPackageName(),

0 commit comments

Comments
 (0)