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

Commit 10410428 authored by Bill Lin's avatar Bill Lin
Browse files

Fix OHM DA Organizer do not update display bounds by orientation

Legacy code depend on getDisplayBounds() which obtain bounds from
current WindowMetrics, unfortunately, WindowMetrics's info is not
up-to-date due to DisplayChangeController.onRotateDisplay() callback
earlier than WindowMetrics get update.

When onRotateDisplay() callback, we rotate old display bounds by
the rotation policy manually.

Test: atest WMShellUnitTests
Bug: 182342712
Change-Id: I9ff91dd7e51417ee33d57327ca07203de52dbe33
parent af8edd8e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ public class OneHandedController {
                new OneHandedBackgroundPanelOrganizer(context, windowManager, displayController,
                        mainExecutor);
        OneHandedDisplayAreaOrganizer organizer = new OneHandedDisplayAreaOrganizer(
                context, windowManager, displayController, animationController, tutorialHandler,
                context, windowManager, animationController, tutorialHandler,
                oneHandedBackgroundPanelOrganizer, mainExecutor);
        OneHandedUiEventLogger oneHandedUiEventsLogger = new OneHandedUiEventLogger(uiEventLogger);
        IOverlayManager overlayManager = IOverlayManager.Stub.asInterface(
+7 −6
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.android.wm.shell.R;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.ShellExecutor;

import java.io.PrintWriter;
@@ -67,7 +66,6 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
    private int mEnterExitAnimationDurationMs;

    private ArrayMap<WindowContainerToken, SurfaceControl> mDisplayAreaTokenMap = new ArrayMap();
    private DisplayController mDisplayController;
    private OneHandedAnimationController mAnimationController;
    private OneHandedSurfaceTransactionHelper.SurfaceControlTransactionFactory
            mSurfaceControlTransactionFactory;
@@ -111,7 +109,6 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
     */
    public OneHandedDisplayAreaOrganizer(Context context,
            WindowManager windowManager,
            DisplayController displayController,
            OneHandedAnimationController animationController,
            OneHandedTutorialHandler tutorialHandler,
            OneHandedBackgroundPanelOrganizer oneHandedBackgroundGradientOrganizer,
@@ -119,7 +116,6 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
        super(mainExecutor);
        mWindowManager = windowManager;
        mAnimationController = animationController;
        mDisplayController = displayController;
        mLastVisualDisplayBounds.set(getDisplayBounds());
        final int animationDurationConfig = context.getResources().getInteger(
                R.integer.config_one_handed_translate_animation_duration);
@@ -171,10 +167,14 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
     */
    public void onRotateDisplay(int fromRotation, int toRotation, WindowContainerTransaction wct) {
        // Stop one handed without animation and reset cropped size immediately
        final Rect newBounds = new Rect(mDefaultDisplayBounds);
        final Rect newBounds = new Rect(getDisplayBounds());
        // This diff rule will only filter the cases portrait <-> landscape
        final boolean isOrientationDiff = Math.abs(fromRotation - toRotation) % 2 == 1;

        if (isOrientationDiff) {
            // getDisplayBounds() will return window metrics bounds which dose not update to
            // corresponding display orientation yet, we have to manual rotate bounds
            newBounds.set(0, 0, newBounds.bottom, newBounds.right);
            resetWindowsOffset(wct);
            mDefaultDisplayBounds.set(newBounds);
            mLastVisualDisplayBounds.set(newBounds);
@@ -293,7 +293,8 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
    }

    @Nullable
    private Rect getDisplayBounds() {
    @VisibleForTesting
    Rect getDisplayBounds() {
        if (mWindowManager == null) {
            Slog.e(TAG, "WindowManager instance is null! Can not get display size!");
            return new Rect();
+2 −2
Original line number Diff line number Diff line
@@ -121,8 +121,8 @@ public class OneHandedControllerTest extends OneHandedTestCase {
        final OneHandedAnimationController animationController = new OneHandedAnimationController(
                mContext);
        OneHandedDisplayAreaOrganizer displayAreaOrganizer = new OneHandedDisplayAreaOrganizer(
                mContext, mWindowManager, mMockDisplayController, animationController,
                mMockTutorialHandler, mMockBackgroundOrganizer, mMockShellMainExecutor);
                mContext, mWindowManager, animationController, mMockTutorialHandler,
                mMockBackgroundOrganizer, mMockShellMainExecutor);

        assertThat(displayAreaOrganizer.isInOneHanded()).isFalse();
    }
+9 −1
Original line number Diff line number Diff line
@@ -122,7 +122,6 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {

        mSpiedDisplayAreaOrganizer = spy(new OneHandedDisplayAreaOrganizer(mContext,
                mWindowManager,
                mMockDisplayController,
                mMockAnimationController,
                mTutorialHandler,
                mMockBackgroundOrganizer,
@@ -169,6 +168,15 @@ public class OneHandedDisplayAreaOrganizerTest extends OneHandedTestCase {
                any());
    }

    @Test
    public void testRotation_getNewDisplayBounds() {
        when(mMockLeash.isValid()).thenReturn(false);
        // Rotate 0 -> 90
        mSpiedDisplayAreaOrganizer.onRotateDisplay(Surface.ROTATION_0, Surface.ROTATION_90,
                mMockWindowContainerTransaction);
        verify(mSpiedDisplayAreaOrganizer).getDisplayBounds();
    }

    @Test
    public void testRotation_portrait_0_to_landscape_90() {
        when(mMockLeash.isValid()).thenReturn(false);