diff options
author | Evan Chen <evanxinchen@google.com> | 2023-10-17 21:31:23 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-11-16 22:38:27 +0000 |
commit | c44a478c261bab320d08e04b213d185776c233ad (patch) | |
tree | cd342b496a261f881a4f43aa15e4091d305e6e0e | |
parent | d0716416646f6d14d685a03b54dd5b27bb7dfde5 (diff) | |
download | base-c44a478c261bab320d08e04b213d185776c233ad.tar.gz |
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:12bb4ed9ab46d3e42326ef1c5e7b90aae80a9bfc)
Merged-In: I6c478ebcc1d981faf2d125a4b41909c3b6a30a2a
Change-Id: I6c478ebcc1d981faf2d125a4b41909c3b6a30a2a
-rw-r--r-- | services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java index 0a617cdd2168..5c36a6b07392 100644 --- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java +++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java @@ -685,8 +685,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."); } @@ -712,7 +711,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); } @@ -908,8 +907,7 @@ public class CompanionDeviceManagerService extends SystemService { createNewAssociation(userId, packageName, macAddressObj, null, null, false); } - private void checkCanCallNotificationApi(String callingPackage) { - final int userId = getCallingUserId(); + private void checkCanCallNotificationApi(String callingPackage, int userId) { enforceCallerIsSystemOr(userId, callingPackage); if (getCallingUid() == SYSTEM_UID) return; |