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

Commit bf9ce9c0 authored by Jerry Chang's avatar Jerry Chang
Browse files

Support launching a shortcut and a task to split screen

Fix: 243101552
Test: long press on a shortcut to enter split screen works
Change-Id: Icaabf2e1c8be086bd1b79e0a2cf05878767caa15
parent f6b78234
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo;
import android.graphics.Insets;
import android.graphics.Rect;
import android.os.Bundle;
@@ -602,7 +603,21 @@ public class SystemUiProxy implements ISystemUiProxy, DisplayController.DisplayI
                mSplitScreen.startIntentAndTaskWithLegacyTransition(pendingIntent, fillInIntent,
                        taskId, mainOptions, sideOptions, sidePosition, splitRatio, adapter);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed call startTasksWithLegacyTransition");
                Log.w(TAG, "Failed call startIntentAndTaskWithLegacyTransition");
            }
        }
    }

    public void startShortcutAndTaskWithLegacyTransition(ShortcutInfo shortcutInfo, int taskId,
            Bundle mainOptions, Bundle sideOptions,
            @SplitConfigurationOptions.StagePosition int sidePosition, float splitRatio,
            RemoteAnimationAdapter adapter) {
        if (mSystemUiProxy != null) {
            try {
                mSplitScreen.startShortcutAndTaskWithLegacyTransition(shortcutInfo, taskId,
                        mainOptions, sideOptions, sidePosition, splitRatio, adapter);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed call startShortcutAndTaskWithLegacyTransition");
            }
        }
    }
+39 −4
Original line number Diff line number Diff line
@@ -31,16 +31,20 @@ import android.app.ActivityThread;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo;
import android.os.Handler;
import android.os.IBinder;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
import android.view.RemoteAnimationAdapter;
import android.view.SurfaceControl;
import android.window.TransitionInfo;

import androidx.annotation.Nullable;

import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.statehandlers.DepthController;
import com.android.launcher3.statemanager.StateManager;
import com.android.launcher3.testing.TestLogging;
@@ -66,6 +70,7 @@ import java.util.function.Consumer;
 * and is in the process of either a) selecting a second app or b) exiting intention to invoke split
 */
public class SplitSelectStateController {
    private static final String TAG = "SplitSelectStateCtor";

    private final Context mContext;
    private final Handler mHandler;
@@ -196,7 +201,7 @@ public class SplitSelectStateController {
                    null /* sideOptions */, STAGE_POSITION_BOTTOM_OR_RIGHT, splitRatio,
                    new RemoteTransitionCompat(animationRunner, MAIN_EXECUTOR,
                            ActivityThread.currentActivityThread().getApplicationThread()));
            // TODO: handle intent + task with shell transition
            // TODO(b/237635859): handle intent/shortcut + task with shell transition
        } else {
            RemoteSplitLaunchAnimationRunner animationRunner =
                    new RemoteSplitLaunchAnimationRunner(taskId1, taskPendingIntent, taskId2,
@@ -214,6 +219,13 @@ public class SplitSelectStateController {
                mSystemUiProxy.startTasksWithLegacyTransition(taskIds[0], mainOpts.toBundle(),
                        taskIds[1], null /* sideOptions */, STAGE_POSITION_BOTTOM_OR_RIGHT,
                        splitRatio, adapter);
            } else {
                final ShortcutInfo shortcutInfo = getShortcutInfo(mInitialTaskIntent,
                        taskPendingIntent.getCreatorUserHandle());
                if (shortcutInfo != null) {
                    mSystemUiProxy.startShortcutAndTaskWithLegacyTransition(shortcutInfo, taskId2,
                            mainOpts.toBundle(), null /* sideOptions */, stagePosition, splitRatio,
                            adapter);
                } else {
                    mSystemUiProxy.startIntentAndTaskWithLegacyTransition(taskPendingIntent,
                            fillInIntent, taskId2, mainOpts.toBundle(), null /* sideOptions */,
@@ -221,6 +233,7 @@ public class SplitSelectStateController {
                }
            }
        }
    }

    public @StagePosition int getActiveSplitStagePosition() {
        return mStagePosition;
@@ -230,6 +243,28 @@ public class SplitSelectStateController {
        this.mRecentsAnimationRunning = running;
    }

    @Nullable
    private ShortcutInfo getShortcutInfo(Intent intent, UserHandle userHandle) {
        if (intent == null || intent.getPackage() == null) {
            return null;
        }

        final String shortcutId = intent.getStringExtra(ShortcutKey.EXTRA_SHORTCUT_ID);
        if (shortcutId == null) {
            return null;
        }

        try {
            final Context context = mContext.createPackageContextAsUser(
                    intent.getPackage(), 0 /* flags */, userHandle);
            return new ShortcutInfo.Builder(context, shortcutId).build();
        } catch (PackageManager.NameNotFoundException e) {
            Log.w(TAG, "Failed to create a ShortcutInfo for " + intent.getPackage());
        }

        return null;
    }

    /**
     * Requires Shell Transitions
     */