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

Commit 3fdf9549 authored by Evan Chen's avatar Evan Chen Committed by Android Build Coastguard Worker
Browse files

Do not allow setting notification access across users.

For mutil user case, make sure the calling userid
matching the passing userid

Test: test it on sample app
Bug: 298635078
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:15eec4872d7b0fdfead3a8f5b4a1bb4d9ad82a0c)
Merged-In: I6c478ebcc1d981faf2d125a4b41909c3b6a30a2a
Change-Id: I6c478ebcc1d981faf2d125a4b41909c3b6a30a2a
parent a3047b59
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -540,8 +540,7 @@ public class CompanionDeviceManagerService extends SystemService {
        public PendingIntent requestNotificationAccess(ComponentName component, int userId)
                throws RemoteException {
            String callingPackage = component.getPackageName();
            checkCanCallNotificationApi(callingPackage);
            // TODO: check userId.
            checkCanCallNotificationApi(callingPackage, userId);
            if (component.flattenToString().length() > MAX_CN_LENGTH) {
                throw new IllegalArgumentException("Component name is too long.");
            }
@@ -567,7 +566,7 @@ public class CompanionDeviceManagerService extends SystemService {
        @Deprecated
        @Override
        public boolean hasNotificationAccess(ComponentName component) throws RemoteException {
            checkCanCallNotificationApi(component.getPackageName());
            checkCanCallNotificationApi(component.getPackageName(), getCallingUserId());
            NotificationManager nm = getContext().getSystemService(NotificationManager.class);
            return nm.isNotificationListenerAccessGranted(component);
        }
@@ -724,8 +723,7 @@ public class CompanionDeviceManagerService extends SystemService {
            legacyCreateAssociation(userId, macAddress, packageName, null);
        }

        private void checkCanCallNotificationApi(String callingPackage) {
            final int userId = getCallingUserId();
        private void checkCanCallNotificationApi(String callingPackage, int userId) {
            enforceCallerIsSystemOr(userId, callingPackage);

            if (getCallingUid() == SYSTEM_UID) return;