Merge "Fix system zen rules by using owner package name if caller is system" into qt-dev am: 3fe8fdc4dc
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19868480 Change-Id: Ibcf7736667abc27920b1b86fab2499ee0f723628 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -3588,7 +3588,16 @@ public class NotificationManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
enforcePolicyAccess(Binder.getCallingUid(), "addAutomaticZenRule");
|
enforcePolicyAccess(Binder.getCallingUid(), "addAutomaticZenRule");
|
||||||
|
|
||||||
return mZenModeHelper.addAutomaticZenRule(pkg, automaticZenRule,
|
// If the caller is system, take the package name from the rule's owner rather than
|
||||||
|
// 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5120,6 +5120,43 @@ 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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user