Merge "Prevent new instance if drop on split-screen with the same app" into tm-qpr-dev
This commit is contained in:
@@ -425,7 +425,7 @@ public class SplitScreenController implements DragAndDropPolicy.Starter,
|
|||||||
|
|
||||||
// Flag with MULTIPLE_TASK if this is launching the same activity into both sides of the
|
// Flag with MULTIPLE_TASK if this is launching the same activity into both sides of the
|
||||||
// split.
|
// split.
|
||||||
if (isLaunchingAdjacently(intent.getIntent(), position)) {
|
if (shouldAddMultipleTaskFlag(intent.getIntent(), position)) {
|
||||||
fillInIntent.addFlags(FLAG_ACTIVITY_MULTIPLE_TASK);
|
fillInIntent.addFlags(FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||||
ProtoLog.v(ShellProtoLogGroup.WM_SHELL_SPLIT_SCREEN, "Adding MULTIPLE_TASK");
|
ProtoLog.v(ShellProtoLogGroup.WM_SHELL_SPLIT_SCREEN, "Adding MULTIPLE_TASK");
|
||||||
}
|
}
|
||||||
@@ -440,8 +440,7 @@ public class SplitScreenController implements DragAndDropPolicy.Starter,
|
|||||||
|
|
||||||
/** Returns {@code true} if it's launching the same component on both sides of the split. */
|
/** Returns {@code true} if it's launching the same component on both sides of the split. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean isLaunchingAdjacently(@Nullable Intent startIntent,
|
boolean shouldAddMultipleTaskFlag(@Nullable Intent startIntent, @SplitPosition int position) {
|
||||||
@SplitPosition int position) {
|
|
||||||
if (startIntent == null) {
|
if (startIntent == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -452,6 +451,16 @@ public class SplitScreenController implements DragAndDropPolicy.Starter,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isSplitScreenVisible()) {
|
if (isSplitScreenVisible()) {
|
||||||
|
// To prevent users from constantly dropping the same app to the same side resulting in
|
||||||
|
// a large number of instances in the background.
|
||||||
|
final ActivityManager.RunningTaskInfo targetTaskInfo = getTaskInfo(position);
|
||||||
|
final ComponentName targetActivity = targetTaskInfo != null
|
||||||
|
? targetTaskInfo.baseIntent.getComponent() : null;
|
||||||
|
if (Objects.equals(launchingActivity, targetActivity)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow users to start a new instance the same to adjacent side.
|
||||||
final ActivityManager.RunningTaskInfo pairedTaskInfo =
|
final ActivityManager.RunningTaskInfo pairedTaskInfo =
|
||||||
getTaskInfo(SplitLayout.reversePosition(position));
|
getTaskInfo(SplitLayout.reversePosition(position));
|
||||||
final ComponentName pairedActivity = pairedTaskInfo != null
|
final ComponentName pairedActivity = pairedTaskInfo != null
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
|
|||||||
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
|
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
|
||||||
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
|
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
|
||||||
|
|
||||||
|
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;
|
||||||
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT;
|
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -111,7 +112,7 @@ public class SplitScreenControllerTests extends ShellTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsLaunchingAdjacently_notInSplitScreen() {
|
public void testShouldAddMultipleTaskFlag_notInSplitScreen() {
|
||||||
doReturn(false).when(mSplitScreenController).isSplitScreenVisible();
|
doReturn(false).when(mSplitScreenController).isSplitScreenVisible();
|
||||||
doReturn(true).when(mSplitScreenController).isValidToEnterSplitScreen(any());
|
doReturn(true).when(mSplitScreenController).isValidToEnterSplitScreen(any());
|
||||||
|
|
||||||
@@ -120,7 +121,7 @@ public class SplitScreenControllerTests extends ShellTestCase {
|
|||||||
ActivityManager.RunningTaskInfo focusTaskInfo =
|
ActivityManager.RunningTaskInfo focusTaskInfo =
|
||||||
createTaskInfo(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, startIntent);
|
createTaskInfo(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, startIntent);
|
||||||
doReturn(focusTaskInfo).when(mSplitScreenController).getFocusingTaskInfo();
|
doReturn(focusTaskInfo).when(mSplitScreenController).getFocusingTaskInfo();
|
||||||
assertTrue(mSplitScreenController.isLaunchingAdjacently(
|
assertTrue(mSplitScreenController.shouldAddMultipleTaskFlag(
|
||||||
startIntent, SPLIT_POSITION_TOP_OR_LEFT));
|
startIntent, SPLIT_POSITION_TOP_OR_LEFT));
|
||||||
|
|
||||||
// Verify launching different activity returns false.
|
// Verify launching different activity returns false.
|
||||||
@@ -128,28 +129,40 @@ public class SplitScreenControllerTests extends ShellTestCase {
|
|||||||
focusTaskInfo =
|
focusTaskInfo =
|
||||||
createTaskInfo(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, diffIntent);
|
createTaskInfo(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, diffIntent);
|
||||||
doReturn(focusTaskInfo).when(mSplitScreenController).getFocusingTaskInfo();
|
doReturn(focusTaskInfo).when(mSplitScreenController).getFocusingTaskInfo();
|
||||||
assertFalse(mSplitScreenController.isLaunchingAdjacently(
|
assertFalse(mSplitScreenController.shouldAddMultipleTaskFlag(
|
||||||
startIntent, SPLIT_POSITION_TOP_OR_LEFT));
|
startIntent, SPLIT_POSITION_TOP_OR_LEFT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsLaunchingAdjacently_inSplitScreen() {
|
public void testShouldAddMultipleTaskFlag_inSplitScreen() {
|
||||||
doReturn(true).when(mSplitScreenController).isSplitScreenVisible();
|
doReturn(true).when(mSplitScreenController).isSplitScreenVisible();
|
||||||
|
|
||||||
// Verify launching the same activity returns true.
|
|
||||||
Intent startIntent = createStartIntent("startActivity");
|
Intent startIntent = createStartIntent("startActivity");
|
||||||
ActivityManager.RunningTaskInfo pairingTaskInfo =
|
ActivityManager.RunningTaskInfo sameTaskInfo =
|
||||||
createTaskInfo(WINDOWING_MODE_MULTI_WINDOW, ACTIVITY_TYPE_STANDARD, startIntent);
|
createTaskInfo(WINDOWING_MODE_MULTI_WINDOW, ACTIVITY_TYPE_STANDARD, startIntent);
|
||||||
doReturn(pairingTaskInfo).when(mSplitScreenController).getTaskInfo(anyInt());
|
Intent diffIntent = createStartIntent("diffActivity");
|
||||||
assertTrue(mSplitScreenController.isLaunchingAdjacently(
|
ActivityManager.RunningTaskInfo differentTaskInfo =
|
||||||
|
createTaskInfo(WINDOWING_MODE_MULTI_WINDOW, ACTIVITY_TYPE_STANDARD, diffIntent);
|
||||||
|
|
||||||
|
// Verify launching the same activity return false.
|
||||||
|
doReturn(sameTaskInfo).when(mSplitScreenController)
|
||||||
|
.getTaskInfo(SPLIT_POSITION_TOP_OR_LEFT);
|
||||||
|
assertFalse(mSplitScreenController.shouldAddMultipleTaskFlag(
|
||||||
startIntent, SPLIT_POSITION_TOP_OR_LEFT));
|
startIntent, SPLIT_POSITION_TOP_OR_LEFT));
|
||||||
|
|
||||||
// Verify launching different activity returns false.
|
// Verify launching the same activity as adjacent returns true.
|
||||||
Intent diffIntent = createStartIntent("diffActivity");
|
doReturn(differentTaskInfo).when(mSplitScreenController)
|
||||||
pairingTaskInfo =
|
.getTaskInfo(SPLIT_POSITION_TOP_OR_LEFT);
|
||||||
createTaskInfo(WINDOWING_MODE_MULTI_WINDOW, ACTIVITY_TYPE_STANDARD, diffIntent);
|
doReturn(sameTaskInfo).when(mSplitScreenController)
|
||||||
doReturn(pairingTaskInfo).when(mSplitScreenController).getTaskInfo(anyInt());
|
.getTaskInfo(SPLIT_POSITION_BOTTOM_OR_RIGHT);
|
||||||
assertFalse(mSplitScreenController.isLaunchingAdjacently(
|
assertTrue(mSplitScreenController.shouldAddMultipleTaskFlag(
|
||||||
|
startIntent, SPLIT_POSITION_TOP_OR_LEFT));
|
||||||
|
|
||||||
|
// Verify launching different activity from adjacent returns false.
|
||||||
|
doReturn(differentTaskInfo).when(mSplitScreenController)
|
||||||
|
.getTaskInfo(SPLIT_POSITION_TOP_OR_LEFT);
|
||||||
|
doReturn(differentTaskInfo).when(mSplitScreenController)
|
||||||
|
.getTaskInfo(SPLIT_POSITION_BOTTOM_OR_RIGHT);
|
||||||
|
assertFalse(mSplitScreenController.shouldAddMultipleTaskFlag(
|
||||||
startIntent, SPLIT_POSITION_TOP_OR_LEFT));
|
startIntent, SPLIT_POSITION_TOP_OR_LEFT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user