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

Commit e59d85ae authored by Nick Chameyev's avatar Nick Chameyev
Browse files

Update display size before updating 'ignore orientation request'

When folding/unfolding a foldable device 'ignore orientation request'
flag might be updated in DisplayContent because different displays
might have different properties. This might result into updated
display rotation.

This flag is updated in 'applySettingsToDisplayLocked' and the new
rotation might be applied in the same method. But DisplayRotation is
not updated with the new display size when applySettingsToDisplayLocked
is invoked. This caused calculation of incorrect rotation
(using old display dimensions).

Fixed by updating display rotation settings only after
updating the size of the display.

Fixes: 203844967
Test: open portrait only app on the unfolded screen,
  fold the device => app is still in portrait orientation
Test: open rotatable app on the unfolded screen,
  fold the device => app is in portrait orientation
Test: rotate screen on inner/outer screen of a foldable device
Change-Id: Ie408ebe7e5913b4a1f97d46581d693e56efaf46c
parent f4039ba2
Loading
Loading
Loading
Loading
+10 −16
Original line number Diff line number Diff line
@@ -1995,23 +1995,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    }

    void configureDisplayPolicy() {
        final int width = mBaseDisplayWidth;
        final int height = mBaseDisplayHeight;
        final int shortSize;
        final int longSize;
        if (width > height) {
            shortSize = height;
            longSize = width;
        } else {
            shortSize = width;
            longSize = height;
        }

        final int shortSizeDp = shortSize * DENSITY_DEFAULT / mBaseDisplayDensity;
        final int longSizeDp = longSize * DENSITY_DEFAULT / mBaseDisplayDensity;

        mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors();
        mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);
        mDisplayRotation.configure(mBaseDisplayWidth, mBaseDisplayHeight);
    }

    /**
@@ -2794,6 +2779,15 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                    mIsSizeForced ? mBaseDisplayHeight : newHeight,
                    mIsDensityForced ? mBaseDisplayDensity : newDensity);

            configureDisplayPolicy();

            if (physicalDisplayChanged) {
                // Reapply the rotation window settings, we are doing this after updating
                // the screen size and configuring display policy as the rotation depends
                // on the display size
                mWmService.mDisplayWindowSettings.applyRotationSettingsToDisplayLocked(this);
            }

            // Real display metrics changed, so we should also update initial values.
            mInitialDisplayWidth = newWidth;
            mInitialDisplayHeight = newHeight;
+1 −1
Original line number Diff line number Diff line
@@ -293,7 +293,7 @@ public class DisplayRotation {
                currentUserRes.getBoolean(R.bool.config_allowSeamlessRotationDespiteNavBarMoving);
    }

    void configure(int width, int height, int shortSizeDp, int longSizeDp) {
    void configure(int width, int height) {
        final Resources res = mContext.getResources();
        if (width > height) {
            mLandscapeRotation = Surface.ROTATION_0;
+9 −4
Original line number Diff line number Diff line
@@ -265,10 +265,6 @@ class DisplayWindowSettings {
        dc.mIsDensityForced = hasDensityOverride;
        dc.mIsSizeForced = hasSizeOverride;

        final boolean ignoreOrientationRequest = settings.mIgnoreOrientationRequest != null
                ? settings.mIgnoreOrientationRequest : false;
        dc.setIgnoreOrientationRequest(ignoreOrientationRequest);

        final boolean ignoreDisplayCutout = settings.mIgnoreDisplayCutout != null
                ? settings.mIgnoreDisplayCutout : false;
        dc.mIgnoreDisplayCutout = ignoreDisplayCutout;
@@ -288,6 +284,15 @@ class DisplayWindowSettings {
        dc.mDontMoveToTop = dontMoveToTop;
    }

    void applyRotationSettingsToDisplayLocked(DisplayContent dc) {
        final DisplayInfo displayInfo = dc.getDisplayInfo();
        final SettingsProvider.SettingsEntry settings = mSettingsProvider.getSettings(displayInfo);

        final boolean ignoreOrientationRequest = settings.mIgnoreOrientationRequest != null
                ? settings.mIgnoreOrientationRequest : false;
        dc.setIgnoreOrientationRequest(ignoreOrientationRequest);
    }

    /**
     * Updates settings for the given display after system features are loaded into window manager
     * service, e.g. if this device is PC and if this device supports freeform.
+1 −8
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.server.wm;

import static android.util.DisplayMetrics.DENSITY_DEFAULT;
import static android.view.DisplayCutout.BOUNDS_POSITION_BOTTOM;
import static android.view.DisplayCutout.BOUNDS_POSITION_LEFT;
import static android.view.DisplayCutout.BOUNDS_POSITION_RIGHT;
@@ -56,7 +55,6 @@ public class DisplayPolicyTestsBase extends WindowTestsBase {

    static final int DISPLAY_WIDTH = 500;
    static final int DISPLAY_HEIGHT = 1000;
    static final int DISPLAY_DENSITY = 320;

    static final int DISPLAY_CUTOUT_HEIGHT = 8;
    static final int IME_HEIGHT = 415;
@@ -85,12 +83,7 @@ public class DisplayPolicyTestsBase extends WindowTestsBase {
        doReturn(true).when(mDisplayPolicy).hasNavigationBar();
        doReturn(true).when(mDisplayPolicy).hasStatusBar();

        final int shortSizeDp =
                Math.min(DISPLAY_WIDTH, DISPLAY_HEIGHT) * DENSITY_DEFAULT / DISPLAY_DENSITY;
        final int longSizeDp =
                Math.min(DISPLAY_WIDTH, DISPLAY_HEIGHT) * DENSITY_DEFAULT / DISPLAY_DENSITY;
        mDisplayContent.getDisplayRotation().configure(
                DISPLAY_WIDTH, DISPLAY_HEIGHT, shortSizeDp, longSizeDp);
        mDisplayContent.getDisplayRotation().configure(DISPLAY_WIDTH, DISPLAY_HEIGHT);
        mDisplayPolicy.onConfigurationChanged();

        addWindow(mStatusBarWindow);
+2 −4
Original line number Diff line number Diff line
@@ -681,7 +681,7 @@ public class DisplayRotationTests {
    }

    /**
     * Call {@link DisplayRotation#configure(int, int, int, int)} to configure {@link #mTarget}
     * Call {@link DisplayRotation#configure(int, int)} to configure {@link #mTarget}
     * according to given parameters.
     */
    private void configureDisplayRotation(int displayOrientation, boolean isCar, boolean isTv) {
@@ -709,9 +709,7 @@ public class DisplayRotationTests {
        when(mockPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK))
                .thenReturn(isTv);

        final int shortSizeDp = (isCar || isTv) ? 540 : 720;
        final int longSizeDp = 960;
        mTarget.configure(width, height, shortSizeDp, longSizeDp);
        mTarget.configure(width, height);
    }

    private void freezeRotation(int rotation) {