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

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

Fix not able to launch multi-instance with drag and drop gesture

There are apps using alias activity name, result to wm-shell not able to
determine whether it's launching the same component or not. Update to
check the component name in the intent that created the task instead to
prevent affected by alias component name.

Fix: 224901460
Fix: 234304765
Fix: 233922245
Fix: 233174334
Fix: 232034346
Test: atest WMShellUnitTests
Test: manual check drag to launch multi-instance or drag to switch
      split position with reported apps work
Change-Id: I924120134bb3ce6abe582251e3afdc7a0825a6a5
parent 2e83cb0c
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import com.android.internal.logging.InstanceId;
import com.android.internal.protolog.common.ProtoLog;
import com.android.wm.shell.R;
import com.android.wm.shell.common.DisplayLayout;
import com.android.wm.shell.common.split.SplitLayout;
import com.android.wm.shell.common.split.SplitScreenConstants.SplitPosition;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
import com.android.wm.shell.splitscreen.SplitScreenController;
@@ -75,6 +76,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * The policy for handling drag and drop operations to shell.
@@ -289,18 +291,15 @@ public class DragAndDropPolicy {
        final ComponentName currentActivity;
        if (!inSplitScreen) {
            currentActivity = mSession.runningTaskInfo != null
                    ? mSession.runningTaskInfo.baseActivity
                    ? mSession.runningTaskInfo.baseIntent.getComponent()
                    : null;
        } else {
            final int nonReplacedSplitPosition = position == SPLIT_POSITION_TOP_OR_LEFT
                    ? SPLIT_POSITION_BOTTOM_OR_RIGHT
                    : SPLIT_POSITION_TOP_OR_LEFT;
            ActivityManager.RunningTaskInfo nonReplacedTaskInfo =
                    mSplitScreen.getTaskInfo(nonReplacedSplitPosition);
            currentActivity = nonReplacedTaskInfo.baseActivity;
            final ActivityManager.RunningTaskInfo nonReplacedTaskInfo =
                    mSplitScreen.getTaskInfo(SplitLayout.reversePosition(position));
            currentActivity = nonReplacedTaskInfo.baseIntent.getComponent();
        }

        if (currentActivity.equals(dragIntentActivity)) {
        if (Objects.equals(currentActivity, dragIntentActivity)) {
            // Only apply MULTIPLE_TASK if we are dragging the same activity
            final Intent fillInIntent = new Intent();
            fillInIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
+7 −5
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.Executor;

@@ -366,11 +367,12 @@ public class SplitScreenController implements DragAndDropPolicy.Starter,
                if (apps == null || apps.length == 0) {
                    final ActivityManager.RunningTaskInfo pairedTaskInfo =
                            getTaskInfo(SplitLayout.reversePosition(position));
                    final ComponentName pairedActivity =
                            pairedTaskInfo != null ? pairedTaskInfo.baseActivity : null;
                    final ComponentName intentActivity =
                            intent.getIntent() != null ? intent.getIntent().getComponent() : null;
                    if (pairedActivity != null && pairedActivity.equals(intentActivity)) {
                    final ComponentName pairedActivity = pairedTaskInfo != null
                            ? pairedTaskInfo.baseIntent.getComponent() : null;
                    final ComponentName intentActivity = intent.getIntent() != null
                            ? intent.getIntent().getComponent() : null;

                    if (Objects.equals(pairedActivity, intentActivity)) {
                        // Switch split position if dragging the same activity to another side.
                        setSideStagePosition(SplitLayout.reversePosition(
                                mStageCoordinator.getSideStagePosition()));
+3 −1
Original line number Diff line number Diff line
@@ -182,8 +182,10 @@ public class DragAndDropPolicyTest {
        info.configuration.windowConfiguration.setActivityType(actType);
        info.configuration.windowConfiguration.setWindowingMode(winMode);
        info.isResizeable = true;
        info.baseActivity = new ComponentName(getInstrumentation().getContext().getPackageName(),
        info.baseActivity = new ComponentName(getInstrumentation().getContext(),
                ".ActivityWithMode" + winMode);
        info.baseIntent = new Intent();
        info.baseIntent.setComponent(info.baseActivity);
        ActivityInfo activityInfo = new ActivityInfo();
        activityInfo.packageName = info.baseActivity.getPackageName();
        activityInfo.name = info.baseActivity.getClassName();