From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Beth Thibodeau Date: Tue, 14 Mar 2023 22:43:54 -0500 Subject: [PATCH 10/10] Fix issues with setRemotePlaybackInfo - Check permissions when building DecoratedMediaCustomViewStyle if it includes the extras from this API - Send device intent as a regular PendingIntent if it can open over lockscreen Bug: 271846393 Test: atest NotificationManagerServiceTest MediaControlPanelTest Test: manual using test app (cherry picked from commit 335a3cb7b413fc178f0b190491b870b3327bd7b0) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:3c3056c16970d561175192e7a8909a9de784ae54) Merged-In: Ida43bb4acc34d666e354c16c4344d5c5eb6b333b Change-Id: Ida43bb4acc34d666e354c16c4344d5c5eb6b333b --- .../media/controls/ui/MediaControlPanel.java | 11 ++++-- .../NotificationManagerService.java | 3 +- .../NotificationManagerServiceTest.java | 37 +++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaControlPanel.java b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaControlPanel.java index 5cdfe73ad3aa..e9d8029a1aad 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaControlPanel.java +++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaControlPanel.java @@ -620,12 +620,15 @@ public class MediaControlPanel { } else { mLogger.logOpenOutputSwitcher(mUid, mPackageName, mInstanceId); if (device.getIntent() != null) { - if (device.getIntent().isActivity()) { - mActivityStarter.startActivity( - device.getIntent().getIntent(), true); + PendingIntent deviceIntent = device.getIntent(); + boolean showOverLockscreen = mKeyguardStateController.isShowing() + && mActivityIntentHelper.wouldPendingShowOverLockscreen( + deviceIntent, mLockscreenUserManager.getCurrentUserId()); + if (device.getIntent().isActivity() && !showOverLockscreen) { + mActivityStarter.postStartActivityDismissingKeyguard(deviceIntent); } else { try { - device.getIntent().send(); + deviceIntent.send(); } catch (PendingIntent.CanceledException e) { Log.e(TAG, "Device pending intent was canceled"); } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index d16f856376bf..3999c117d40d 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -6747,7 +6747,8 @@ public class NotificationManagerService extends SystemService { } // Ensure MediaStyle has correct permissions for remote device extras - if (notification.isStyle(Notification.MediaStyle.class)) { + if (notification.isStyle(Notification.MediaStyle.class) + || notification.isStyle(Notification.DecoratedMediaCustomViewStyle.class)) { int hasMediaContentControlPermission = mPackageManager.checkPermission( android.Manifest.permission.MEDIA_CONTENT_CONTROL, pkg, userId); if (hasMediaContentControlPermission != PERMISSION_GRANTED) { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index 3f3b052931ab..9f0a0b2f7628 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -4245,6 +4245,43 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertFalse(posted.getNotification().extras .containsKey(Notification.EXTRA_MEDIA_REMOTE_DEVICE)); + assertFalse(posted.getNotification().extras + .containsKey(Notification.EXTRA_MEDIA_REMOTE_ICON)); + assertFalse(posted.getNotification().extras + .containsKey(Notification.EXTRA_MEDIA_REMOTE_INTENT)); + } + + @Test + public void testCustomMediaStyleRemote_noPermission() throws RemoteException { + String deviceName = "device"; + when(mPackageManager.checkPermission( + eq(android.Manifest.permission.MEDIA_CONTENT_CONTROL), any(), anyInt())) + .thenReturn(PERMISSION_DENIED); + Notification.DecoratedMediaCustomViewStyle style = + new Notification.DecoratedMediaCustomViewStyle(); + style.setRemotePlaybackInfo(deviceName, 0, null); + Notification.Builder nb = new Notification.Builder(mContext, + mTestNotificationChannel.getId()) + .setStyle(style); + + StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + "testCustomMediaStyleRemoteNoPermission", mUid, 0, + nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); + NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel); + + mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), + nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); + waitForIdle(); + + NotificationRecord posted = mService.findNotificationLocked( + PKG, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getUserId()); + + assertFalse(posted.getNotification().extras + .containsKey(Notification.EXTRA_MEDIA_REMOTE_DEVICE)); + assertFalse(posted.getNotification().extras + .containsKey(Notification.EXTRA_MEDIA_REMOTE_ICON)); + assertFalse(posted.getNotification().extras + .containsKey(Notification.EXTRA_MEDIA_REMOTE_INTENT)); } @Test