From f62fecc458af86d2729a4bb6f19913f99f93a251 Mon Sep 17 00:00:00 2001 From: Jerry Chang Date: Wed, 1 Jun 2022 08:13:57 +0000 Subject: [PATCH] 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 --- .../wm/shell/draganddrop/DragAndDropPolicy.java | 15 +++++++-------- .../shell/splitscreen/SplitScreenController.java | 12 +++++++----- .../shell/draganddrop/DragAndDropPolicyTest.java | 4 +++- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java index 756831007c35f..6373728344a49 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java @@ -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); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java index 0d976d4a81eb7..af0e4657a9fa0 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java @@ -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())); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/DragAndDropPolicyTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/DragAndDropPolicyTest.java index bb6026c36c97f..7e6595f1abe2c 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/DragAndDropPolicyTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/DragAndDropPolicyTest.java @@ -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();