Merge changes I3ecb608e,I13a0ca75
* changes: Add cross user perm check - areBubblesAllowedForPackage Add cross user permission check - areNotificationsEnabledForPackage
This commit is contained in:
committed by
Android (Google) Code Review
commit
e295c17e46
@@ -2406,6 +2406,11 @@ public class NotificationManagerService extends SystemService {
|
||||
@Override
|
||||
public boolean areNotificationsEnabledForPackage(String pkg, int uid) {
|
||||
checkCallerIsSystemOrSameApp(pkg);
|
||||
if (UserHandle.getCallingUserId() != UserHandle.getUserId(uid)) {
|
||||
getContext().enforceCallingPermission(
|
||||
android.Manifest.permission.INTERACT_ACROSS_USERS,
|
||||
"canNotifyAsPackage for uid " + uid);
|
||||
}
|
||||
|
||||
return mPreferencesHelper.getImportance(pkg, uid) != IMPORTANCE_NONE;
|
||||
}
|
||||
@@ -2419,6 +2424,13 @@ public class NotificationManagerService extends SystemService {
|
||||
public boolean areBubblesAllowedForPackage(String pkg, int uid) {
|
||||
enforceSystemOrSystemUIOrSamePackage(pkg,
|
||||
"Caller not system or systemui or same package");
|
||||
|
||||
if (UserHandle.getCallingUserId() != UserHandle.getUserId(uid)) {
|
||||
getContext().enforceCallingPermission(
|
||||
android.Manifest.permission.INTERACT_ACROSS_USERS,
|
||||
"canNotifyAsPackage for uid " + uid);
|
||||
}
|
||||
|
||||
return mPreferencesHelper.areBubblesAllowed(pkg, uid);
|
||||
}
|
||||
|
||||
|
||||
@@ -4324,4 +4324,36 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
assertEquals(IMPORTANCE_LOW, r.getAssistantImportance());
|
||||
assertEquals(USER_SENTIMENT_NEUTRAL, r.getUserSentiment());
|
||||
}
|
||||
|
||||
public void testAreNotificationsEnabledForPackage_crossUser() throws Exception {
|
||||
try {
|
||||
mBinderService.areNotificationsEnabledForPackage(mContext.getPackageName(),
|
||||
mUid + UserHandle.PER_USER_RANGE);
|
||||
fail("Cannot call cross user without permission");
|
||||
} catch (SecurityException e) {
|
||||
// pass
|
||||
}
|
||||
|
||||
// cross user, with permission, no problem
|
||||
TestablePermissions perms = mContext.getTestablePermissions();
|
||||
perms.setPermission(android.Manifest.permission.INTERACT_ACROSS_USERS, PERMISSION_GRANTED);
|
||||
mBinderService.areNotificationsEnabledForPackage(mContext.getPackageName(),
|
||||
mUid + UserHandle.PER_USER_RANGE);
|
||||
}
|
||||
|
||||
public void testAreBubblesAllowedForPackage_crossUser() throws Exception {
|
||||
try {
|
||||
mBinderService.areBubblesAllowedForPackage(mContext.getPackageName(),
|
||||
mUid + UserHandle.PER_USER_RANGE);
|
||||
fail("Cannot call cross user without permission");
|
||||
} catch (SecurityException e) {
|
||||
// pass
|
||||
}
|
||||
|
||||
// cross user, with permission, no problem
|
||||
TestablePermissions perms = mContext.getTestablePermissions();
|
||||
perms.setPermission(android.Manifest.permission.INTERACT_ACROSS_USERS, PERMISSION_GRANTED);
|
||||
mBinderService.areBubblesAllowedForPackage(mContext.getPackageName(),
|
||||
mUid + UserHandle.PER_USER_RANGE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user