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

Commit daf8921d authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Make default orientation of window container unset

The UNSPECIFIED is also a kind of provided orientation. If a
window container doesn't provide orientation, it should return
UNSET instead. As the implementation getOrientation of various
container, e.g. ActivityRecord, TaskFragment, DisplayArea, which
return UNSET if it can not decide the orientation. And the
UNSET will be reported as UNSPECIFIED in DisplayContent.

This could speed up a bit when traversing WindowContainer#
getOrientation that skips UNSET directly.

Bug: 163976519
Test: testGetOrientation_childSpecified
Change-Id: Iec067673e48dab559f5976f15d3e6524e0657b44
parent b9406495
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE_DEPRECATED;
import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
import static android.view.Display.DEFAULT_DISPLAY;
@@ -640,8 +639,6 @@ class Task extends TaskFragment {
        mLastTaskSnapshotData = _lastSnapshotData != null
                ? _lastSnapshotData
                : new PersistedTaskSnapshotData();
        // Tasks have no set orientation value (including SCREEN_ORIENTATION_UNSPECIFIED).
        setOrientation(SCREEN_ORIENTATION_UNSET);
        affinityIntent = _affinityIntent;
        affinity = _affinity;
        rootAffinity = _rootAffinity;
+2 −4
Original line number Diff line number Diff line
@@ -186,7 +186,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
    // The specified orientation for this window container.
    // Shouldn't be accessed directly since subclasses can override getOverrideOrientation.
    @ScreenOrientation
    private int mOverrideOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
    private int mOverrideOrientation = SCREEN_ORIENTATION_UNSET;

    /**
     * The window container which decides its orientation since the last time
@@ -1683,8 +1683,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
        for (int i = mChildren.size() - 1; i >= 0; --i) {
            final WindowContainer wc = mChildren.get(i);

            // TODO: Maybe mOverrideOrientation should default to SCREEN_ORIENTATION_UNSET vs.
            // SCREEN_ORIENTATION_UNSPECIFIED?
            final int orientation = wc.getOrientation(candidate == SCREEN_ORIENTATION_BEHIND
                    ? SCREEN_ORIENTATION_BEHIND : SCREEN_ORIENTATION_UNSET);
            if (orientation == SCREEN_ORIENTATION_BEHIND) {
@@ -1700,7 +1698,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
                continue;
            }

            if (wc.providesOrientation() || orientation != SCREEN_ORIENTATION_UNSPECIFIED) {
            if (orientation != SCREEN_ORIENTATION_UNSPECIFIED || wc.providesOrientation()) {
                // Use the orientation if the container can provide or requested an explicit
                // orientation that isn't SCREEN_ORIENTATION_UNSPECIFIED.
                ProtoLog.v(WM_DEBUG_ORIENTATION, "%s is requesting orientation %d (%s)",
+1 −0
Original line number Diff line number Diff line
@@ -1071,6 +1071,7 @@ public class DisplayContentTests extends WindowTestsBase {
    @Test
    public void testAllowsTopmostFullscreenOrientation() {
        final DisplayContent dc = createNewDisplay();
        assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, dc.getOrientation());
        dc.getDisplayRotation().setFixedToUserRotation(
                IWindowManager.FIXED_TO_USER_ROTATION_DISABLED);

+7 −26
Original line number Diff line number Diff line
@@ -565,36 +565,17 @@ public class WindowContainerTests extends WindowTestsBase {

    @Test
    public void testGetOrientation_childSpecified() {
        testGetOrientation_childSpecifiedConfig(false, SCREEN_ORIENTATION_LANDSCAPE,
                SCREEN_ORIENTATION_LANDSCAPE);
        testGetOrientation_childSpecifiedConfig(false, SCREEN_ORIENTATION_UNSET,
                SCREEN_ORIENTATION_UNSPECIFIED);
    }

    private void testGetOrientation_childSpecifiedConfig(boolean childVisible, int childOrientation,
            int expectedOrientation) {
        final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm);
        final TestWindowContainer root = builder.setLayer(0).build();
        final TestWindowContainer root = builder.build();
        root.setFillsParent(true);
        assertEquals(SCREEN_ORIENTATION_UNSET, root.getOrientation());

        builder.setIsVisible(childVisible);

        if (childOrientation != SCREEN_ORIENTATION_UNSET) {
            builder.setOrientation(childOrientation);
        }

        final TestWindowContainer child1 = root.addChildWindow(builder);
        child1.setFillsParent(true);

        assertEquals(expectedOrientation, root.getOrientation());
    }
        final TestWindowContainer child = root.addChildWindow();
        child.setFillsParent(true);
        assertEquals(SCREEN_ORIENTATION_UNSET, root.getOrientation());

    @Test
    public void testGetOrientation_Unset() {
        final TestWindowContainerBuilder builder = new TestWindowContainerBuilder(mWm);
        final TestWindowContainer root = builder.setLayer(0).setIsVisible(true).build();
        // Unspecified well because we didn't specify anything...
        assertEquals(SCREEN_ORIENTATION_UNSPECIFIED, root.getOrientation());
        child.setOverrideOrientation(SCREEN_ORIENTATION_LANDSCAPE);
        assertEquals(SCREEN_ORIENTATION_LANDSCAPE, root.getOrientation());
    }

    @Test