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

Commit 33a432a3 authored by Vinit Nayak's avatar Vinit Nayak
Browse files

Pass through both the widget's pendingIntent and remoteView intent

* Both may be necessary to correctly launch a widget
* We pass it through as the second app's Bundle instead
of adding a new parameter.

Bug: 311263727
Test: Tested w/ 2 fresh launches, app + widget.
Also with existing task + widget.
Was not able to accurately test multiple tasks launched by the
widget since there are some issues with the allowlist check.
And the working case for multiple instances of Chrome didn't
work because none of the chrome widgets rely on the secondary
intent to launch any of the app's activities.
Flag: None, technically this code isn't reachable since widgets
are unsupported, but didn't seem worthwhile to add a separate flag
in the short duration we will begin supporting them again.
To run replace the early return in QuickstepInteractionHandler with
the call:
mLauncher.getSplitToWorkspaceController()
	.handleSecondWidgetSelectionForSplit(view, pendingIntent, options.first)

Change-Id: I1ebcb385b140d42a6a84368f589aba06c4bed2bd
parent 7056e2d2
Loading
Loading
Loading
Loading
+15 −1
Original line number Original line Diff line number Diff line
@@ -93,6 +93,7 @@ class SplitSelectDataHolder(
    private var secondTaskId: Int = INVALID_TASK_ID
    private var secondTaskId: Int = INVALID_TASK_ID
    private var initialIntent: Intent? = null
    private var initialIntent: Intent? = null
    private var secondIntent: Intent? = null
    private var secondIntent: Intent? = null
    private var widgetSecondIntent: Intent? = null
    private var initialUser: UserHandle? = null
    private var initialUser: UserHandle? = null
    private var secondUser: UserHandle? = null
    private var secondUser: UserHandle? = null
    private var initialPendingIntent: PendingIntent? = null
    private var initialPendingIntent: PendingIntent? = null
@@ -167,6 +168,16 @@ class SplitSelectDataHolder(
        secondUser = pendingIntent.creatorUserHandle
        secondUser = pendingIntent.creatorUserHandle
    }
    }


    /**
     * Similar to [setSecondTask] except this is to be called for widgets which can pass through
     * an extra intent from their RemoteResponse.
     * See [android.widget.RemoteViews.RemoteResponse.getLaunchOptions].first
     */
    fun setSecondWidget(pendingIntent: PendingIntent, widgetIntent: Intent?) {
        setSecondTask(pendingIntent)
        widgetSecondIntent = widgetIntent
    }

    private fun getShortcutInfo(intent: Intent?, user: UserHandle?): ShortcutInfo? {
    private fun getShortcutInfo(intent: Intent?, user: UserHandle?): ShortcutInfo? {
        val intentPackage = intent?.getPackage() ?: return null
        val intentPackage = intent?.getPackage() ?: return null
        val shortcutId = intent.getStringExtra(ShortcutKey.EXTRA_SHORTCUT_ID)
        val shortcutId = intent.getStringExtra(ShortcutKey.EXTRA_SHORTCUT_ID)
@@ -241,6 +252,7 @@ class SplitSelectDataHolder(
                secondTaskId,
                secondTaskId,
                initialPendingIntent,
                initialPendingIntent,
                secondPendingIntent,
                secondPendingIntent,
                widgetSecondIntent,
                initialUser?.identifier ?: -1,
                initialUser?.identifier ?: -1,
                secondUser?.identifier ?: -1,
                secondUser?.identifier ?: -1,
                initialShortcut,
                initialShortcut,
@@ -257,7 +269,8 @@ class SplitSelectDataHolder(
     * Note that both [initialIntent] and [secondIntent] will be nullified on method return
     * Note that both [initialIntent] and [secondIntent] will be nullified on method return
     *
     *
     * One caveat is that if [secondPendingIntent] is set, we will use that and *not* attempt to
     * One caveat is that if [secondPendingIntent] is set, we will use that and *not* attempt to
     * convert [secondIntent]
     * convert [secondIntent].
     * This also leaves [widgetSecondIntent] untouched.
     */
     */
    private fun convertIntentsToFinalTypes() {
    private fun convertIntentsToFinalTypes() {
        initialShortcut = getShortcutInfo(initialIntent, initialUser)
        initialShortcut = getShortcutInfo(initialIntent, initialUser)
@@ -343,6 +356,7 @@ class SplitSelectDataHolder(
            var secondTaskId: Int = INVALID_TASK_ID,
            var secondTaskId: Int = INVALID_TASK_ID,
            var initialPendingIntent: PendingIntent? = null,
            var initialPendingIntent: PendingIntent? = null,
            var secondPendingIntent: PendingIntent? = null,
            var secondPendingIntent: PendingIntent? = null,
            var widgetSecondIntent: Intent? = null,
            var initialUserId: Int = -1,
            var initialUserId: Int = -1,
            var secondUserId: Int = -1,
            var secondUserId: Int = -1,
            var initialShortcut: ShortcutInfo? = null,
            var initialShortcut: ShortcutInfo? = null,
+12 −5
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ import static com.android.quickstep.util.SplitSelectDataHolder.SPLIT_TASK_PENDIN
import static com.android.quickstep.util.SplitSelectDataHolder.SPLIT_TASK_SHORTCUT;
import static com.android.quickstep.util.SplitSelectDataHolder.SPLIT_TASK_SHORTCUT;
import static com.android.quickstep.util.SplitSelectDataHolder.SPLIT_TASK_TASK;
import static com.android.quickstep.util.SplitSelectDataHolder.SPLIT_TASK_TASK;
import static com.android.quickstep.views.DesktopTaskView.isDesktopModeSupported;
import static com.android.quickstep.views.DesktopTaskView.isDesktopModeSupported;
import static com.android.wm.shell.common.split.SplitScreenConstants.KEY_EXTRA_WIDGET_INTENT;
import static com.android.wm.shell.common.split.SplitScreenConstants.SNAP_TO_50_50;
import static com.android.wm.shell.common.split.SplitScreenConstants.SNAP_TO_50_50;


import android.animation.Animator;
import android.animation.Animator;
@@ -355,6 +356,10 @@ public class SplitSelectStateController {
        mSplitSelectDataHolder.setSecondTask(pendingIntent);
        mSplitSelectDataHolder.setSecondTask(pendingIntent);
    }
    }


    public void setSecondWidget(PendingIntent pendingIntent, Intent widgetIntent) {
        mSplitSelectDataHolder.setSecondWidget(pendingIntent, widgetIntent);
    }

    /**
    /**
     * To be called when we want to launch split pairs from Overview. Split can be initiated from
     * To be called when we want to launch split pairs from Overview. Split can be initiated from
     * either Overview or home, or all apps. Either both taskIds are set, or a pending intent + a
     * either Overview or home, or all apps. Either both taskIds are set, or a pending intent + a
@@ -380,11 +385,13 @@ public class SplitSelectStateController {
        ShortcutInfo secondShortcut = launchData.getSecondShortcut();
        ShortcutInfo secondShortcut = launchData.getSecondShortcut();
        PendingIntent firstPI = launchData.getInitialPendingIntent();
        PendingIntent firstPI = launchData.getInitialPendingIntent();
        PendingIntent secondPI = launchData.getSecondPendingIntent();
        PendingIntent secondPI = launchData.getSecondPendingIntent();
        Intent widgetIntent = launchData.getWidgetSecondIntent();
        int firstUserId = launchData.getInitialUserId();
        int firstUserId = launchData.getInitialUserId();
        int secondUserId = launchData.getSecondUserId();
        int secondUserId = launchData.getSecondUserId();
        int initialStagePosition = launchData.getInitialStagePosition();
        int initialStagePosition = launchData.getInitialStagePosition();
        Bundle optionsBundle = options1.toBundle();
        Bundle optionsBundle = options1.toBundle();

        Bundle extrasBundle = new Bundle(1);
        extrasBundle.putParcelable(KEY_EXTRA_WIDGET_INTENT, widgetIntent);
        if (TaskAnimationManager.ENABLE_SHELL_TRANSITIONS) {
        if (TaskAnimationManager.ENABLE_SHELL_TRANSITIONS) {
            final RemoteTransition remoteTransition = getShellRemoteTransition(firstTaskId,
            final RemoteTransition remoteTransition = getShellRemoteTransition(firstTaskId,
                    secondTaskId, callback, "LaunchSplitPair");
                    secondTaskId, callback, "LaunchSplitPair");
@@ -396,7 +403,7 @@ public class SplitSelectStateController {


                case SPLIT_TASK_PENDINGINTENT ->
                case SPLIT_TASK_PENDINGINTENT ->
                        mSystemUiProxy.startIntentAndTask(secondPI, secondUserId, optionsBundle,
                        mSystemUiProxy.startIntentAndTask(secondPI, secondUserId, optionsBundle,
                                firstTaskId, null /*options2*/, initialStagePosition, snapPosition,
                                firstTaskId, extrasBundle, initialStagePosition, snapPosition,
                                remoteTransition, shellInstanceId);
                                remoteTransition, shellInstanceId);


                case SPLIT_TASK_SHORTCUT ->
                case SPLIT_TASK_SHORTCUT ->
@@ -411,9 +418,9 @@ public class SplitSelectStateController {


                case SPLIT_PENDINGINTENT_PENDINGINTENT ->
                case SPLIT_PENDINGINTENT_PENDINGINTENT ->
                        mSystemUiProxy.startIntents(firstPI, firstUserId, firstShortcut,
                        mSystemUiProxy.startIntents(firstPI, firstUserId, firstShortcut,
                                optionsBundle, secondPI, secondUserId, secondShortcut,
                                optionsBundle, secondPI, secondUserId, secondShortcut, extrasBundle,
                                null /*options2*/, initialStagePosition, snapPosition,
                                initialStagePosition, snapPosition, remoteTransition,
                                remoteTransition, shellInstanceId);
                                shellInstanceId);


                case SPLIT_SHORTCUT_TASK ->
                case SPLIT_SHORTCUT_TASK ->
                        mSystemUiProxy.startShortcutAndTask(firstShortcut, optionsBundle,
                        mSystemUiProxy.startShortcutAndTask(firstShortcut, optionsBundle,
+3 −2
Original line number Original line Diff line number Diff line
@@ -75,7 +75,8 @@ public class SplitToWorkspaceController {
     * @return {@code true} if we can attempt launch the widget into split, {@code false} otherwise
     * @return {@code true} if we can attempt launch the widget into split, {@code false} otherwise
     *         to allow launcher to handle the click
     *         to allow launcher to handle the click
     */
     */
    public boolean handleSecondWidgetSelectionForSplit(View view, PendingIntent pendingIntent) {
    public boolean handleSecondWidgetSelectionForSplit(View view, PendingIntent pendingIntent,
            Intent remoteResponseIntent) {
        if (shouldIgnoreSecondSplitLaunch()) {
        if (shouldIgnoreSecondSplitLaunch()) {
            return false;
            return false;
        }
        }
@@ -89,7 +90,7 @@ public class SplitToWorkspaceController {
            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);


            view.post(() -> {
            view.post(() -> {
                mController.setSecondTask(pendingIntent);
                mController.setSecondWidget(pendingIntent, remoteResponseIntent);
                // Convert original widgetView into bitmap to use for animation
                // Convert original widgetView into bitmap to use for animation
                Canvas canvas = new Canvas(bitmap);
                Canvas canvas = new Canvas(bitmap);
                view.draw(canvas);
                view.draw(canvas);