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-10 18:30:17 +0000 |
commit | 3fdf954905afc5b8414af22b112861b10ef26d53 (patch) | |
tree | a67e726e7b7ee88f67dfd30dfaf8dd54d57f4b91 | |
parent | a3047b59c453fabb5bdfb5841afdcd10de9ffc96 (diff) | |
download | base-3fdf954905afc5b8414af22b112861b10ef26d53.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:15eec4872d7b0fdfead3a8f5b4a1bb4d9ad82a0c)
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 1a651a91699f..bf1915eef79c 100644 --- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java +++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java @@ -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; |