Skip to content

Commit 3fdf954

Browse files
Evan ChenAndroid Build Coastguard Worker
authored andcommitted
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
1 parent a3047b5 commit 3fdf954

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,7 @@ public void disassociate(int associationId) {
540540
public PendingIntent requestNotificationAccess(ComponentName component, int userId)
541541
throws RemoteException {
542542
String callingPackage = component.getPackageName();
543-
checkCanCallNotificationApi(callingPackage);
544-
// TODO: check userId.
543+
checkCanCallNotificationApi(callingPackage, userId);
545544
if (component.flattenToString().length() > MAX_CN_LENGTH) {
546545
throw new IllegalArgumentException("Component name is too long.");
547546
}
@@ -567,7 +566,7 @@ public PendingIntent requestNotificationAccess(ComponentName component, int user
567566
@Deprecated
568567
@Override
569568
public boolean hasNotificationAccess(ComponentName component) throws RemoteException {
570-
checkCanCallNotificationApi(component.getPackageName());
569+
checkCanCallNotificationApi(component.getPackageName(), getCallingUserId());
571570
NotificationManager nm = getContext().getSystemService(NotificationManager.class);
572571
return nm.isNotificationListenerAccessGranted(component);
573572
}
@@ -724,8 +723,7 @@ public void createAssociation(String packageName, String macAddress, int userId,
724723
legacyCreateAssociation(userId, macAddress, packageName, null);
725724
}
726725

727-
private void checkCanCallNotificationApi(String callingPackage) {
728-
final int userId = getCallingUserId();
726+
private void checkCanCallNotificationApi(String callingPackage, int userId) {
729727
enforceCallerIsSystemOr(userId, callingPackage);
730728

731729
if (getCallingUid() == SYSTEM_UID) return;

0 commit comments

Comments
 (0)