Add cross user permission check - areNotificationsEnabledForPackage
Test: atest Fixes: 128599467 Change-Id: I13a0ca7590f8c4b44379730e0ee2088aba400c2a
This commit is contained in:
@@ -2406,6 +2406,11 @@ public class NotificationManagerService extends SystemService {
|
|||||||
@Override
|
@Override
|
||||||
public boolean areNotificationsEnabledForPackage(String pkg, int uid) {
|
public boolean areNotificationsEnabledForPackage(String pkg, int uid) {
|
||||||
checkCallerIsSystemOrSameApp(pkg);
|
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;
|
return mPreferencesHelper.getImportance(pkg, uid) != IMPORTANCE_NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4324,4 +4324,20 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
|||||||
assertEquals(IMPORTANCE_LOW, r.getAssistantImportance());
|
assertEquals(IMPORTANCE_LOW, r.getAssistantImportance());
|
||||||
assertEquals(USER_SENTIMENT_NEUTRAL, r.getUserSentiment());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user