Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2f7592df authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Add cross user perm check - areBubblesAllowedForPackage

Test: atest
Bug: 129068779
Change-Id: I3ecb608e525206a698484e9cf35f770dc7609d54
parent 657d1641
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2424,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);
        }

+16 −0
Original line number Diff line number Diff line
@@ -4340,4 +4340,20 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        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);
    }
}