From ffb189773c0cdae08c8f5d88bac8a70f1b9a2136 Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Wed, 12 Feb 2020 19:39:40 -0500 Subject: [PATCH] Broadcast screenshot intents in the foreground By default, intents are broadcast on a background queue, which can accrue a lot of backed-up tasks especially when the phone was recently rebooted. In the case of the screenshot action shade, this causes a long pause (up to ~minutes!) between tapping on an action chip and seeing the app actually open. This change adds a flag to the intents to cause them to be queued in the foreground. In the notifications flow, this flag gets added in NotificationManagerService (so this is preserving behavior). In addition, these intents are user-generated (by tapping on the chip or screenshot preview), so it's reasonable to send them in the foreground. Bug: 149481318 Test: manual Change-Id: Idfcb8ade3fee232b140299585296e85093eeb1fe --- .../screenshot/SaveImageInBackgroundTask.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java b/packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java index 92236ae0f0fa7..12d0892a4b618 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java @@ -286,7 +286,8 @@ class SaveImageInBackgroundTask extends AsyncTask { .putExtra(GlobalScreenshot.EXTRA_ID, mScreenshotId) .putExtra(GlobalScreenshot.EXTRA_SMART_ACTIONS_ENABLED, mSmartActionsEnabled) - .setAction(Intent.ACTION_SEND), + .setAction(Intent.ACTION_SEND) + .addFlags(Intent.FLAG_RECEIVER_FOREGROUND), PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.SYSTEM); Notification.Action.Builder shareActionBuilder = new Notification.Action.Builder( @@ -315,7 +316,8 @@ class SaveImageInBackgroundTask extends AsyncTask { .putExtra(GlobalScreenshot.EXTRA_ID, mScreenshotId) .putExtra(GlobalScreenshot.EXTRA_SMART_ACTIONS_ENABLED, mSmartActionsEnabled) - .setAction(Intent.ACTION_EDIT), + .setAction(Intent.ACTION_EDIT) + .addFlags(Intent.FLAG_RECEIVER_FOREGROUND), PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.SYSTEM); Notification.Action.Builder editActionBuilder = new Notification.Action.Builder( Icon.createWithResource(r, R.drawable.ic_screenshot_edit), @@ -329,7 +331,8 @@ class SaveImageInBackgroundTask extends AsyncTask { .putExtra(GlobalScreenshot.SCREENSHOT_URI_ID, uri.toString()) .putExtra(GlobalScreenshot.EXTRA_ID, mScreenshotId) .putExtra(GlobalScreenshot.EXTRA_SMART_ACTIONS_ENABLED, - mSmartActionsEnabled), + mSmartActionsEnabled) + .addFlags(Intent.FLAG_RECEIVER_FOREGROUND), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT); Notification.Action.Builder deleteActionBuilder = new Notification.Action.Builder( Icon.createWithResource(r, R.drawable.ic_screenshot_delete), @@ -366,9 +369,9 @@ class SaveImageInBackgroundTask extends AsyncTask { String actionType = extras.getString( ScreenshotNotificationSmartActionsProvider.ACTION_TYPE, ScreenshotNotificationSmartActionsProvider.DEFAULT_ACTION_TYPE); - Intent intent = new Intent(context, - GlobalScreenshot.SmartActionsReceiver.class).putExtra( - GlobalScreenshot.EXTRA_ACTION_INTENT, action.actionIntent); + Intent intent = new Intent(context, GlobalScreenshot.SmartActionsReceiver.class) + .putExtra(GlobalScreenshot.EXTRA_ACTION_INTENT, action.actionIntent) + .addFlags(Intent.FLAG_RECEIVER_FOREGROUND); addIntentExtras(mScreenshotId, intent, actionType, mSmartActionsEnabled); PendingIntent broadcastIntent = PendingIntent.getBroadcast(context, mRandom.nextInt(),