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

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

Reduce method invocation when checking orientation

This also prevents rotationForActivityInDifferentOrientation from
returning unexpected rotation if AR#getOverrideOrientation returns
a different orientation than getRequestedOrientation.

Bug: 159103089
Flag: EXEMPT simple refactor
Test: atest DisplayContentTests
Change-Id: I64a3f92ff6d83a0797b95d5656e15ad5f603959a
parent 4cc6b39f
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -1835,7 +1835,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        if (mTransitionController.useShellTransitionsRotation()) {
            return ROTATION_UNDEFINED;
        }
        final int activityOrientation = r.getOverrideOrientation();
        int activityOrientation = r.getOverrideOrientation();
        if (!WindowManagerService.ENABLE_FIXED_ROTATION_TRANSFORM
                || shouldIgnoreOrientationRequest(activityOrientation)) {
            return ROTATION_UNDEFINED;
@@ -1846,14 +1846,15 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                    r /* boundary */, false /* includeBoundary */, true /* traverseTopToBottom */);
            if (nextCandidate != null) {
                r = nextCandidate;
                activityOrientation = r.getOverrideOrientation();
            }
        }
        if (r.inMultiWindowMode() || r.getRequestedConfigurationOrientation(true /* forDisplay */)
                == getConfiguration().orientation) {
        if (r.inMultiWindowMode() || r.getRequestedConfigurationOrientation(true /* forDisplay */,
                activityOrientation) == getConfiguration().orientation) {
            return ROTATION_UNDEFINED;
        }
        final int currentRotation = getRotation();
        final int rotation = mDisplayRotation.rotationForOrientation(r.getRequestedOrientation(),
        final int rotation = mDisplayRotation.rotationForOrientation(activityOrientation,
                currentRotation);
        if (rotation == currentRotation) {
            return ROTATION_UNDEFINED;
+7 −7
Original line number Diff line number Diff line
@@ -1733,13 +1733,13 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
     *         last time {@link #getOrientation(int) was called.
     */
    @Nullable
    WindowContainer getLastOrientationSource() {
        final WindowContainer source = mLastOrientationSource;
        if (source != null && source != this) {
            final WindowContainer nextSource = source.getLastOrientationSource();
            if (nextSource != null) {
                return nextSource;
    final WindowContainer<?> getLastOrientationSource() {
        if (mLastOrientationSource == null) {
            return null;
        }
        WindowContainer<?> source = this;
        while (source != source.mLastOrientationSource && source.mLastOrientationSource != null) {
            source = source.mLastOrientationSource;
        }
        return source;
    }
+1 −0
Original line number Diff line number Diff line
@@ -1144,6 +1144,7 @@ public class DisplayContentTests extends WindowTestsBase {

    @Test
    public void testOrientationBehind() {
        assertNull(mDisplayContent.getLastOrientationSource());
        final ActivityRecord prev = new ActivityBuilder(mAtm).setCreateTask(true)
                .setScreenOrientation(getRotatedOrientation(mDisplayContent)).build();
        prev.setVisibleRequested(false);