Merge "Alternative fix for preventing PiP from screenshot sharing." into oc-mr1-dev

am: 6d753c88d9

Change-Id: Iffd473679aab7ca6f92852b664074b82d5198b17
This commit is contained in:
Winson Chung
2017-09-08 05:58:59 +00:00
committed by android-build-merger
6 changed files with 50 additions and 33 deletions

View File

@@ -318,15 +318,20 @@
android:exported="false">
</activity>
<!-- Springboard for launching the share activity -->
<receiver android:name=".screenshot.GlobalScreenshot$ShareReceiver"
android:process=":screenshot"
android:exported="false" />
<!-- Callback for dismissing screenshot notification after a share target is picked -->
<receiver android:name=".screenshot.GlobalScreenshot$TargetChosenReceiver"
android:process=":screenshot"
android:exported="false" />
android:process=":screenshot"
android:exported="false" />
<!-- Callback for deleting screenshot notification -->
<receiver android:name=".screenshot.GlobalScreenshot$DeleteScreenshotReceiver"
android:process=":screenshot"
android:exported="false" />
android:process=":screenshot"
android:exported="false" />
<!-- started from UsbDeviceSettingsManager -->
<activity android:name=".usb.UsbConfirmActivity"

View File

@@ -16,11 +16,16 @@
package com.android.systemui.screenshot;
import static com.android.systemui.screenshot.GlobalScreenshot.SHARING_INTENT;
import static com.android.systemui.statusbar.phone.StatusBar.SYSTEM_DIALOG_REASON_SCREENSHOT;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.admin.DevicePolicyManager;
import android.app.Notification;
import android.app.Notification.BigPictureStyle;
@@ -48,6 +53,7 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.MediaStore;
import android.util.DisplayMetrics;
@@ -277,14 +283,13 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
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<Void, Void, Void> {
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<Uri, Void, Void> {
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.
*/

View File

@@ -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";

View File

@@ -3007,13 +3007,6 @@ class ActivityStack<T extends StackWindowController> 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;
}

View File

@@ -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++) {

View File

@@ -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