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

Commit 2afc5c41 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Keep current orientation if the activity doesn't provide orientation

A translucent activity with unspecified orientation won't affect display
orientation (see WindowContainer#getOrientation(int)), so when pre-
computing target rotation (e.g. ActivityRecord#onConfigurationChanged),
it should not consider sensor rotation.

Fix: 434101837
Flag: EXEMPT bugfix
Test: DisplayContentTests#testRotationForActivityInDifferentOrientation
Test: Enable auto rotation. A translucent activity enters pip on a
      fixed portrait activity. Rotate device to landscape. Expand pip.
      The expanded activity should keep portrait appearance.
Change-Id: If951145912180fe53ef06e06911d985e6d0e75be
parent d55f80cc
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1950,6 +1950,9 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                activityOrientation = r.getOverrideOrientation();
            }
        }
        if (activityOrientation == SCREEN_ORIENTATION_UNSPECIFIED && !r.providesOrientation()) {
            return ROTATION_UNDEFINED;
        }
        if (r.inMultiWindowMode() || r.getRequestedConfigurationOrientation(true /* forDisplay */,
                activityOrientation) == getConfiguration().orientation) {
            return ROTATION_UNDEFINED;
+1 −0
Original line number Diff line number Diff line
@@ -1626,6 +1626,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
        return source;
    }

    /** Returns true if unspecified orientation should be reported to parent. */
    boolean providesOrientation() {
        return fillsParent();
    }
+20 −0
Original line number Diff line number Diff line
@@ -1756,6 +1756,26 @@ public class DisplayContentTests extends WindowTestsBase {
        assertFalse(mDisplayContent.hasTopFixedRotationLaunchingApp());
    }

    @Test
    public void testRotationForActivityInDifferentOrientation() {
        mDisplayContent.setIgnoreOrientationRequest(false);
        final ActivityRecord app = new ActivityBuilder(mAtm).setCreateTask(true).build();
        final DisplayRotation displayRotation = mDisplayContent.getDisplayRotation();
        final int rotation = displayRotation.getRotation();
        spyOn(displayRotation);
        doReturn((rotation + 1) % 4).when(displayRotation).rotationForOrientation(
                anyInt() /* orientation */, anyInt() /* lastRotation */);

        assertTrue(app.providesOrientation());
        assertNotEquals(WindowConfiguration.ROTATION_UNDEFINED,
                mDisplayContent.rotationForActivityInDifferentOrientation(app));

        doReturn(false).when(app).providesOrientation();

        assertEquals(WindowConfiguration.ROTATION_UNDEFINED,
                mDisplayContent.rotationForActivityInDifferentOrientation(app));
    }

    @Test
    public void testRespectNonTopVisibleFixedOrientation() {
        spyOn(mWm.mAppCompatConfiguration);