From ed376a36a3b33d66f532d72e1e809757e0dde90b Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 7 Sep 2017 14:05:42 -0700 Subject: [PATCH] Alternative fix for preventing PiP from screenshot sharing. - Revert 942a85c6d608dd6a4a31937fe0b57ae43105d5b2 - Use a more specific fix for the triggering of PiP from the SysUI screenshot share intent. Bug: 63984385 Bug: 63581685 Test: android.server.cts.ActivityManagerPinnedStackTests Test: Click share on the screenshot action, ensure activity below does not enter PiP Change-Id: Id8041d50dd429030c20940dca19e5c62bbc0c6a4 --- packages/SystemUI/AndroidManifest.xml | 13 +++-- .../systemui/screenshot/GlobalScreenshot.java | 48 +++++++++++++++---- .../systemui/statusbar/phone/StatusBar.java | 1 + .../com/android/server/am/ActivityStack.java | 7 --- .../com/android/server/am/TaskRecord.java | 13 ----- .../server/policy/PhoneWindowManager.java | 1 + 6 files changed, 50 insertions(+), 33 deletions(-) diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index c99716084e380..070634b83552c 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -318,15 +318,20 @@ android:exported="false"> + + + + android:process=":screenshot" + android:exported="false" /> + android:process=":screenshot" + android:exported="false" /> { sharingIntent.putExtra(Intent.EXTRA_STREAM, uri); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, subject); - // Create a share action for the notification - PendingIntent chooseAction = PendingIntent.getBroadcast(context, 0, - new Intent(context, GlobalScreenshot.TargetChosenReceiver.class), - PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT); - Intent chooserIntent = Intent.createChooser(sharingIntent, null, - chooseAction.getIntentSender()) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); - PendingIntent shareAction = PendingIntent.getActivity(context, 0, chooserIntent, + // Create a share action for the notification. Note, we proxy the call to ShareReceiver + // because RemoteViews currently forces an activity options on the PendingIntent being + // launched, and since we don't want to trigger the share sheet in this case, we will + // start the chooser activitiy directly in ShareReceiver. + PendingIntent shareAction = PendingIntent.getBroadcast(context, 0, + new Intent(context, GlobalScreenshot.ShareReceiver.class) + .putExtra(SHARING_INTENT, sharingIntent), PendingIntent.FLAG_CANCEL_CURRENT); Notification.Action.Builder shareActionBuilder = new Notification.Action.Builder( R.drawable.ic_screenshot_share, @@ -292,7 +297,7 @@ class SaveImageInBackgroundTask extends AsyncTask { mNotificationBuilder.addAction(shareActionBuilder.build()); // Create a delete action for the notification - PendingIntent deleteAction = PendingIntent.getBroadcast(context, 0, + PendingIntent deleteAction = PendingIntent.getBroadcast(context, 0, new Intent(context, GlobalScreenshot.DeleteScreenshotReceiver.class) .putExtra(GlobalScreenshot.SCREENSHOT_URI_ID, uri.toString()), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT); @@ -403,6 +408,7 @@ class DeleteImageInBackgroundTask extends AsyncTask { class GlobalScreenshot { static final String SCREENSHOT_URI_ID = "android:screenshot_uri_id"; + static final String SHARING_INTENT = "android:screenshot_sharing_intent"; private static final int SCREENSHOT_FLASH_TO_PEAK_DURATION = 130; private static final int SCREENSHOT_DROP_IN_DURATION = 430; @@ -896,6 +902,30 @@ class GlobalScreenshot { nManager.notify(SystemMessage.NOTE_GLOBAL_SCREENSHOT, n); } + /** + * Receiver to proxy the share intent. + */ + public static class ShareReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + try { + ActivityManager.getService().closeSystemDialogs(SYSTEM_DIALOG_REASON_SCREENSHOT); + } catch (RemoteException e) { + } + + Intent sharingIntent = intent.getParcelableExtra(SHARING_INTENT); + PendingIntent chooseAction = PendingIntent.getBroadcast(context, 0, + new Intent(context, GlobalScreenshot.TargetChosenReceiver.class), + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT); + Intent chooserIntent = Intent.createChooser(sharingIntent, null, + chooseAction.getIntentSender()) + .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); + ActivityOptions opts = ActivityOptions.makeBasic(); + opts.setDisallowEnterPictureInPictureWhileLaunching(true); + context.startActivityAsUser(chooserIntent, opts.toBundle(), UserHandle.CURRENT); + } + } + /** * Removes the notification for a screenshot after a share target is chosen. */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 7aebfdc5c3bcd..7c6e886ad0a6c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -300,6 +300,7 @@ public class StatusBar extends SystemUI implements DemoMode, // Should match the values in PhoneWindowManager public static final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; public static final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; + static public final String SYSTEM_DIALOG_REASON_SCREENSHOT = "screenshot"; private static final String BANNER_ACTION_CANCEL = "com.android.systemui.statusbar.banner_action_cancel"; diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index d62d9357e43f0..791b2c066821f 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -3007,13 +3007,6 @@ class ActivityStack extends ConfigurationContai // Ensure the task/activity being brought forward is not the assistant return false; } - final boolean isFullscreen = toFrontTask != null - ? toFrontTask.containsOnlyFullscreenActivities() - : toFrontActivity.fullscreen; - if (!isFullscreen) { - // Ensure the task/activity being brought forward is fullscreen - return false; - } return true; } diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java index 1bbb06871cc2a..eadc8a6eadba2 100644 --- a/services/core/java/com/android/server/am/TaskRecord.java +++ b/services/core/java/com/android/server/am/TaskRecord.java @@ -1112,19 +1112,6 @@ final class TaskRecord extends ConfigurationContainer implements TaskWindowConta return intent != null ? intent : affinityIntent; } - /** - * @return Whether there are only fullscreen activities in this task. - */ - boolean containsOnlyFullscreenActivities() { - for (int i = 0; i < mActivities.size(); i++) { - final ActivityRecord r = mActivities.get(i); - if (!r.finishing && !r.fullscreen) { - return false; - } - } - return true; - } - /** Returns the first non-finishing activity from the root. */ ActivityRecord getRootActivity() { for (int i = 0; i < mActivities.size(); i++) { diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 27159fabf6c5c..8c1f5e422b5ff 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -335,6 +335,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; + static public final String SYSTEM_DIALOG_REASON_SCREENSHOT = "screenshot"; /** * These are the system UI flags that, when changing, can cause the layout