diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitLayout.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitLayout.java index 040fffae3e848..b8ac87fa5d4cf 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitLayout.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitLayout.java @@ -93,7 +93,7 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange private final InsetsState mInsetsState = new InsetsState(); private Context mContext; - private DividerSnapAlgorithm mDividerSnapAlgorithm; + @VisibleForTesting DividerSnapAlgorithm mDividerSnapAlgorithm; private WindowContainerToken mWinToken1; private WindowContainerToken mWinToken2; private int mDividePosition; @@ -294,20 +294,22 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange mSplitLayoutHandler.onLayoutSizeChanging(this); } - void setDividePosition(int position) { + void setDividePosition(int position, boolean applyLayoutChange) { mDividePosition = position; updateBounds(mDividePosition); - mSplitLayoutHandler.onLayoutSizeChanged(this); + if (applyLayoutChange) { + mSplitLayoutHandler.onLayoutSizeChanged(this); + } } - /** Sets divide position base on the ratio within root bounds. */ + /** Updates divide position and split bounds base on the ratio within root bounds. */ public void setDivideRatio(float ratio) { final int position = isLandscape() ? mRootBounds.left + (int) (mRootBounds.width() * ratio) : mRootBounds.top + (int) (mRootBounds.height() * ratio); - DividerSnapAlgorithm.SnapTarget snapTarget = + final DividerSnapAlgorithm.SnapTarget snapTarget = mDividerSnapAlgorithm.calculateNonDismissingSnapTarget(position); - setDividePosition(snapTarget.position); + setDividePosition(snapTarget.position, false /* applyLayoutChange */); } /** Resets divider position. */ @@ -336,7 +338,7 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange break; default: flingDividePosition(currentPosition, snapTarget.position, - () -> setDividePosition(snapTarget.position)); + () -> setDividePosition(snapTarget.position, true /* applyLayoutChange */)); break; } } @@ -389,7 +391,7 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange @Override public void onAnimationCancel(Animator animation) { - setDividePosition(to); + setDividePosition(to, true /* applyLayoutChange */); } }); animator.start(); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java index d1feee4803c19..9eef09bbe43dc 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java @@ -341,12 +341,12 @@ class StageCoordinator implements SplitLayout.SplitLayoutHandler, sideOptions = sideOptions != null ? sideOptions : new Bundle(); setSideStagePosition(sidePosition, wct); + mSplitLayout.setDivideRatio(splitRatio); // Build a request WCT that will launch both apps such that task 0 is on the main stage // while task 1 is on the side stage. mMainStage.activate(getMainStageBounds(), wct, false /* reparent */); mSideStage.setBounds(getSideStageBounds(), wct); - mSplitLayout.setDivideRatio(splitRatio); // Make sure the launch options will put tasks in the corresponding split roots addActivityOptions(mainOptions, mMainStage); addActivityOptions(sideOptions, mSideStage); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/split/SplitLayoutTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/split/SplitLayoutTests.java index 453050fcfab4f..83d5f04b7cdb9 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/split/SplitLayoutTests.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/split/SplitLayoutTests.java @@ -24,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -101,14 +102,21 @@ public class SplitLayoutTests extends ShellTestCase { @Test public void testSetDividePosition() { - mSplitLayout.setDividePosition(anyInt()); + mSplitLayout.setDividePosition(100, false /* applyLayoutChange */); + assertThat(mSplitLayout.getDividePosition()).isEqualTo(100); + verify(mSplitLayoutHandler, never()).onLayoutSizeChanged(any(SplitLayout.class)); + + mSplitLayout.setDividePosition(200, true /* applyLayoutChange */); + assertThat(mSplitLayout.getDividePosition()).isEqualTo(200); verify(mSplitLayoutHandler).onLayoutSizeChanged(any(SplitLayout.class)); } @Test public void testSetDivideRatio() { + mSplitLayout.setDividePosition(200, false /* applyLayoutChange */); mSplitLayout.setDivideRatio(0.5f); - verify(mSplitLayoutHandler).onLayoutSizeChanged(any(SplitLayout.class)); + assertThat(mSplitLayout.getDividePosition()).isEqualTo( + mSplitLayout.mDividerSnapAlgorithm.getMiddleTarget().position); } @Test