Add cross user permission check - areNotificationsEnabledForPackage

Test: atest
Fixes: 128599467
Change-Id: I13a0ca7590f8c4b44379730e0ee2088aba400c2a
This commit is contained in:
Julia Reynolds
2019-03-27 12:15:57 -04:00
parent 37c66e5e50
commit 657d164136
2 changed files with 21 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -4324,4 +4324,20 @@ 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);
}
}