[conflict] Merge "Use rule package name in addAutomaticZenRule; specify "android" for all system apps" into tm-dev am: 0232c797eb
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20506676 Change-Id: I20a759905063d95e44cc5e65c09f43407175cddb Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -4932,10 +4932,10 @@ public class NotificationManagerService extends SystemService {
|
||||
}
|
||||
enforcePolicyAccess(Binder.getCallingUid(), "addAutomaticZenRule");
|
||||
|
||||
// If the caller is system, take the package name from the rule's owner rather than
|
||||
// from the caller's package.
|
||||
// If the calling app is the system (from any user), take the package name from the
|
||||
// rule's owner rather than from the caller's package.
|
||||
String rulePkg = pkg;
|
||||
if (isCallingUidSystem()) {
|
||||
if (isCallingAppIdSystem()) {
|
||||
if (automaticZenRule.getOwner() != null) {
|
||||
rulePkg = automaticZenRule.getOwner().getPackageName();
|
||||
}
|
||||
@@ -9667,6 +9667,12 @@ public class NotificationManagerService extends SystemService {
|
||||
return uid == Process.SYSTEM_UID;
|
||||
}
|
||||
|
||||
protected boolean isCallingAppIdSystem() {
|
||||
final int uid = Binder.getCallingUid();
|
||||
final int appid = UserHandle.getAppId(uid);
|
||||
return appid == Process.SYSTEM_UID;
|
||||
}
|
||||
|
||||
protected boolean isUidSystemOrPhone(int uid) {
|
||||
final int appid = UserHandle.getAppId(uid);
|
||||
return (appid == Process.SYSTEM_UID || appid == Process.PHONE_UID
|
||||
|
||||
@@ -7406,9 +7406,31 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
verify(mockZenModeHelper).addAutomaticZenRule(eq("android"), eq(rule), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAutomaticZenRule_systemAppIdCallTakesPackageFromOwner() throws Exception {
|
||||
// The multi-user case: where the calling uid doesn't match the system uid, but the calling
|
||||
// *appid* is the system.
|
||||
mService.isSystemUid = false;
|
||||
mService.isSystemAppId = 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;
|
||||
mService.isSystemAppId = false;
|
||||
ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class);
|
||||
when(mConditionProviders.isPackageOrComponentAllowed(anyString(), anyInt()))
|
||||
.thenReturn(true);
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.Set;
|
||||
public class TestableNotificationManagerService extends NotificationManagerService {
|
||||
int countSystemChecks = 0;
|
||||
boolean isSystemUid = true;
|
||||
boolean isSystemAppId = true;
|
||||
int countLogSmartSuggestionsVisible = 0;
|
||||
Set<Integer> mChannelToastsSent = new HashSet<>();
|
||||
|
||||
@@ -57,6 +58,12 @@ public class TestableNotificationManagerService extends NotificationManagerServi
|
||||
return isSystemUid;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCallingAppIdSystem() {
|
||||
countSystemChecks++;
|
||||
return isSystemUid || isSystemAppId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCallerSystemOrPhone() {
|
||||
countSystemChecks++;
|
||||
|
||||
Reference in New Issue
Block a user