From 17f7c255e9bff310b38f2d6bd6a322dc7a547906 Mon Sep 17 00:00:00 2001 From: Achim Thesmann Date: Sat, 24 Jun 2023 00:30:03 +0000 Subject: [PATCH] Opt in systemui for BAL We see some calls from android.uid.systemui being blocked in our logs. Unfortunately we cannot exactly identify the source of these calls, but in a manual review we identified some invocations that may be affected. To avoid activities being blocked and functionality regression, this change will revert those code paths back to T behavior by opting into allowing the launch if the PI sender (systemUI) is in the foreground. Maybe not all these changes are required, but any missed change might cause functionality to break, while extra changes have no functional impact. The change is relatively safe since it won't block anything, only allow the launch, as it was allowed by default in T. Change-Id: Ide20c906e9852ac49abbc8af8570313a8f5f965e Test: compile + presubmit Bug: 284486752 --- .../systemui/media/controls/pipeline/MediaDataManager.kt | 3 +++ .../systemui/media/controls/ui/MediaControlPanel.java | 8 +++++++- .../android/systemui/screenshot/ActionProxyReceiver.java | 2 ++ .../android/systemui/screenshot/OverlayActionChip.java | 2 ++ .../android/systemui/screenshot/SmartActionsReceiver.java | 3 ++- .../statusbar/NotificationLockscreenUserManagerImpl.java | 7 ++++++- .../systemui/statusbar/phone/CentralSurfacesImpl.java | 6 +++++- .../statusbar/policy/RemoteInputViewController.kt | 6 +++++- .../systemui/statusbar/policy/SmartReplyStateInflater.kt | 7 ++++++- .../statusbar/tv/notifications/TvNotificationAdapter.java | 2 ++ .../systemui/media/controls/ui/MediaControlPanelTest.kt | 2 +- 11 files changed, 41 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt index 6b993ce9e7bf6..a2bb950220307 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt @@ -1253,6 +1253,9 @@ class MediaDataManager( return try { val options = BroadcastOptions.makeBasic() options.setInteractive(true) + options.setPendingIntentBackgroundActivityStartMode( + BroadcastOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED + ) intent.send(options.toBundle()) true } catch (e: PendingIntent.CanceledException) { 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 35082fd5122a3..a978b92cb2343 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 @@ -23,6 +23,7 @@ import static com.android.systemui.media.controls.models.recommendation.Smartspa import android.animation.Animator; import android.animation.AnimatorInflater; import android.animation.AnimatorSet; +import android.app.ActivityOptions; import android.app.BroadcastOptions; import android.app.PendingIntent; import android.app.WallpaperColors; @@ -535,7 +536,10 @@ public class MediaControlPanel { mLockscreenUserManager.getCurrentUserId()); if (showOverLockscreen) { try { - clickIntent.send(); + ActivityOptions opts = ActivityOptions.makeBasic(); + opts.setPendingIntentBackgroundActivityStartMode( + ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED); + clickIntent.send(opts.toBundle()); } catch (PendingIntent.CanceledException e) { Log.e(TAG, "Pending intent for " + key + " was cancelled"); } @@ -684,6 +688,8 @@ public class MediaControlPanel { try { BroadcastOptions options = BroadcastOptions.makeBasic(); options.setInteractive(true); + options.setPendingIntentBackgroundActivityStartMode( + ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED); deviceIntent.send(options.toBundle()); } catch (PendingIntent.CanceledException e) { Log.e(TAG, "Device pending intent was canceled"); diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ActionProxyReceiver.java b/packages/SystemUI/src/com/android/systemui/screenshot/ActionProxyReceiver.java index 3aefcb3d29763..7e234aeed0aa1 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ActionProxyReceiver.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ActionProxyReceiver.java @@ -71,6 +71,8 @@ public class ActionProxyReceiver extends BroadcastReceiver { ActivityOptions opts = ActivityOptions.makeBasic(); opts.setDisallowEnterPictureInPictureWhileLaunching( intent.getBooleanExtra(EXTRA_DISALLOW_ENTER_PIP, false)); + opts.setPendingIntentBackgroundActivityStartMode( + ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED); try { actionIntent.send(context, 0, null, null, null, null, opts.toBundle()); if (intent.getBooleanExtra(ScreenshotController.EXTRA_OVERRIDE_TRANSITION, false)) { diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/OverlayActionChip.java b/packages/SystemUI/src/com/android/systemui/screenshot/OverlayActionChip.java index 13678b0e71874..9e8ea3aaec56a 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/OverlayActionChip.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/OverlayActionChip.java @@ -99,6 +99,8 @@ public class OverlayActionChip extends FrameLayout { try { BroadcastOptions options = BroadcastOptions.makeBasic(); options.setInteractive(true); + options.setPendingIntentBackgroundActivityStartMode( + BroadcastOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED); intent.send(options.toBundle()); finisher.run(); } catch (PendingIntent.CanceledException e) { diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/SmartActionsReceiver.java b/packages/SystemUI/src/com/android/systemui/screenshot/SmartActionsReceiver.java index 9761f5931193d..ef58b9d6a1eef 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/SmartActionsReceiver.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/SmartActionsReceiver.java @@ -55,7 +55,8 @@ public class SmartActionsReceiver extends BroadcastReceiver { Log.d(TAG, "Executing smart action [" + actionType + "]:" + pendingIntent.getIntent()); } ActivityOptions opts = ActivityOptions.makeBasic(); - + opts.setPendingIntentBackgroundActivityStartMode( + ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED); try { pendingIntent.send(context, 0, fillIn, null, null, null, opts.toBundle()); } catch (PendingIntent.CanceledException e) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java index e6e3e7e4fe4c0..ea5ca276a8cf2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java @@ -19,6 +19,7 @@ import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER import static com.android.systemui.DejankUtils.whitelistIpcs; +import android.app.ActivityOptions; import android.app.KeyguardManager; import android.app.Notification; import android.app.admin.DevicePolicyManager; @@ -158,7 +159,11 @@ public class NotificationLockscreenUserManagerImpl implements final String notificationKey = intent.getStringExtra(Intent.EXTRA_INDEX); if (intentSender != null) { try { - mContext.startIntentSender(intentSender, null, 0, 0, 0); + ActivityOptions options = ActivityOptions.makeBasic(); + options.setPendingIntentBackgroundActivityStartMode( + ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED); + mContext.startIntentSender(intentSender, null, 0, 0, 0, + options.toBundle()); } catch (IntentSender.SendIntentException e) { /* ignore */ } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java index 0d3dfaeb85b87..8902a186c43ae 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java @@ -42,6 +42,7 @@ import static com.android.systemui.statusbar.phone.BarTransitions.TransitionMode import android.annotation.Nullable; import android.app.ActivityManager; +import android.app.ActivityOptions; import android.app.IWallpaperManager; import android.app.KeyguardManager; import android.app.Notification; @@ -1773,7 +1774,10 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { EventLog.writeEvent(EventLogTags.SYSUI_HEADS_UP_ESCALATION, sbn.getKey()); wakeUpForFullScreenIntent(); - notification.fullScreenIntent.send(); + ActivityOptions opts = ActivityOptions.makeBasic(); + opts.setPendingIntentBackgroundActivityStartMode( + ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED); + notification.fullScreenIntent.send(opts.toBundle()); entry.notifyFullScreenIntentLaunched(); } catch (PendingIntent.CanceledException e) { } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputViewController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputViewController.kt index 22b4c9d81d256..736b14574da08 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputViewController.kt @@ -16,6 +16,7 @@ package com.android.systemui.statusbar.policy +import android.app.ActivityOptions import android.app.Notification import android.app.PendingIntent import android.app.RemoteInput @@ -275,7 +276,10 @@ class RemoteInputViewControllerImpl @Inject constructor( entry.sbn.instanceId) try { - pendingIntent.send(view.context, 0, intent) + val options = ActivityOptions.makeBasic() + options.setPendingIntentBackgroundActivityStartMode( + ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED) + pendingIntent.send(view.context, 0, intent, null, null, null, options.toBundle()) } catch (e: PendingIntent.CanceledException) { Log.i(TAG, "Unable to send remote input result", e) uiEventLogger.logWithInstanceId( diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyStateInflater.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyStateInflater.kt index cac5e3290a262..1776e5b76e55a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyStateInflater.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyStateInflater.kt @@ -16,6 +16,7 @@ package com.android.systemui.statusbar.policy +import android.app.ActivityOptions import android.app.Notification import android.app.Notification.Action.SEMANTIC_ACTION_MARK_CONVERSATION_AS_PRIORITY import android.app.PendingIntent @@ -491,7 +492,11 @@ class SmartReplyInflaterImpl @Inject constructor( entry.setHasSentReply() try { val intent = createRemoteInputIntent(smartReplies, choice) - smartReplies.pendingIntent.send(context, 0, intent) + val opts = ActivityOptions.makeBasic() + opts.setPendingIntentBackgroundActivityStartMode( + ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED) + smartReplies.pendingIntent.send(context, 0, intent, /* onFinished */null, + /* handler */ null, /* requiredPermission */ null, opts.toBundle()) } catch (e: PendingIntent.CanceledException) { Log.w(TAG, "Unable to send smart reply", e) } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tv/notifications/TvNotificationAdapter.java b/packages/SystemUI/src/com/android/systemui/statusbar/tv/notifications/TvNotificationAdapter.java index 33620979d681e..fd7c30f39693f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tv/notifications/TvNotificationAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tv/notifications/TvNotificationAdapter.java @@ -103,6 +103,8 @@ public class TvNotificationAdapter extends RecyclerView.Adapter