From 8878a3be1a1f8d104833d138d5720a2c7f934e5e Mon Sep 17 00:00:00 2001 From: Oasis Feng Date: Mon, 31 Aug 2020 02:53:45 +0000 Subject: [PATCH] Fix CDM.requestNotificationAccess() in profile. If invoked by app running in managed profile, CompanionDeviceManager .requestNotificationAccess() is actually trying to grant access to that app in parent profile, which may not even exist. Notification listener may not need to be running in managed profile, but in order to access and control media sessions in managed profile, notification listener must be granted access in that managed profile. Test: Run test cases of CompanionDeviceManager in managed profile. Signed-off-by: Oasis Feng Change-Id: Id33c4956097300c5ec1c6c50ebee91dee9a49c33 --- .../server/companion/CompanionDeviceManagerService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java index d6759b3e2cca..a704c58a9b70 100644 --- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java +++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java @@ -391,12 +391,14 @@ public PendingIntent requestNotificationAccess(ComponentName component) .toString()); long identity = Binder.clearCallingIdentity(); try { - return PendingIntent.getActivity(getContext(), + return PendingIntent.getActivityAsUser(getContext(), 0 /* request code */, NotificationAccessConfirmationActivityContract.launcherIntent( userId, component, packageTitle), PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT - | PendingIntent.FLAG_CANCEL_CURRENT); + | PendingIntent.FLAG_CANCEL_CURRENT, + null /* options */, + new UserHandle(userId)); } finally { Binder.restoreCallingIdentity(identity); }