Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d753c88 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents 9e009bb0 ed376a36
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -318,6 +318,11 @@
            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"
+39 −9
Original line number Diff line number Diff line
@@ -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,
@@ -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.
     */
+1 −0
Original line number Diff line number Diff line
@@ -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";
+0 −7
Original line number Diff line number Diff line
@@ -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;
    }

+0 −13
Original line number Diff line number Diff line
@@ -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++) {
Loading