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

Commit 835b76cb authored by Graciela Wissen Putri's avatar Graciela Wissen Putri
Browse files

Respect orientation request from any eligible activity

Flag: EXEMPT bug fix
Fix: 370878266
Test: atest AppCompatOrientationOverridesTest
      Manually with fixed orientation activity and freeform
Change-Id: I955c2f20678052d4ed2e1e76568a5bea45914a60
parent 109eb275
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.wm;

import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.content.pm.ActivityInfo.OVERRIDE_ANY_ORIENTATION;
import static android.content.pm.ActivityInfo.OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED;
import static android.content.pm.ActivityInfo.OVERRIDE_ENABLE_COMPAT_IGNORE_REQUESTED_ORIENTATION;
@@ -106,6 +107,16 @@ class AppCompatOrientationOverrides {
        return isChangeEnabled(mActivityRecord, OVERRIDE_RESPECT_REQUESTED_ORIENTATION);
    }

    boolean shouldRespectRequestedOrientationDueToOverride() {
        // Checking TaskFragment rather than ActivityRecord to ensure that transition
        // between fullscreen and PiP would work well. Checking TaskFragment rather than
        // Task to ensure that Activity Embedding is excluded.
        return mActivityRecord.isVisibleRequested() && mActivityRecord.getTaskFragment() != null
                && mActivityRecord.getTaskFragment().getWindowingMode() == WINDOWING_MODE_FULLSCREEN
                && mActivityRecord.mAppCompatController.getAppCompatOrientationOverrides()
                    .isOverrideRespectRequestedOrientationEnabled();
    }

    /**
     * Whether an app is calling {@link android.app.Activity#setRequestedOrientation}
     * in a loop and orientation request should be ignored.
+8 −10
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.server.wm;

import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
@@ -260,15 +259,14 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
        if (mDisplayContent == null) {
            return false;
        }
        ActivityRecord activity = mDisplayContent.topRunningActivity(
                /* considerKeyguardState= */ true);
        return activity != null && activity.getTaskFragment() != null
                // Checking TaskFragment rather than ActivityRecord to ensure that transition
                // between fullscreen and PiP would work well. Checking TaskFragment rather than
                // Task to ensure that Activity Embedding is excluded.
                && activity.getTaskFragment().getWindowingMode() == WINDOWING_MODE_FULLSCREEN
                && activity.mAppCompatController.getAppCompatOrientationOverrides()
                    .isOverrideRespectRequestedOrientationEnabled();

        // Top running activity can be freeform and ignore orientation request from bottom activity
        // that should be respected, Check all activities in display to make sure any eligible
        // activity should be respected.
        final ActivityRecord activity = mDisplayContent.getActivity((r) ->
                r.mAppCompatController.getAppCompatOrientationOverrides()
                    .shouldRespectRequestedOrientationDueToOverride());
        return activity != null;
    }

    boolean getIgnoreOrientationRequest() {
+38 −0
Original line number Diff line number Diff line
@@ -17,11 +17,13 @@ package com.android.server.wm;

import static android.content.pm.ActivityInfo.OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED;
import static android.content.pm.ActivityInfo.OVERRIDE_USE_DISPLAY_LANDSCAPE_NATURAL_ORIENTATION;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_DISPLAY_ORIENTATION_OVERRIDE;
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_IGNORING_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.server.wm.AppCompatOrientationOverrides.OrientationOverridesState.MIN_COUNT_TO_IGNORE_REQUEST_IN_LOOP;
import static com.android.server.wm.AppCompatOrientationOverrides.OrientationOverridesState.SET_ORIENTATION_REQUEST_COUNTER_TIMEOUT_MS;
@@ -31,6 +33,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import android.compat.testing.PlatformCompatChangeRule;
import android.content.pm.ActivityInfo.ScreenOrientation;
import android.platform.test.annotations.Presubmit;

import androidx.annotation.NonNull;
@@ -228,6 +231,25 @@ public class AppCompatOrientationOverridesTest extends WindowTestsBase {
        });
    }

    @Test
    public void testOverrideRespectRequestedOrientationIsEnabled_bottomOrientationIsRespected() {
        runTestScenario((robot) -> {
            robot.applyOnActivity((a) -> {
                a.setIgnoreOrientationRequest(true);
                a.createActivityWithComponentInNewTask();
                robot.setOverrideRespectRequestedOrientationEnabled(true);
                a.configureUnresizableTopActivity(SCREEN_ORIENTATION_LANDSCAPE);
                robot.checkDisplayShouldIgnoreOrientationRequest(SCREEN_ORIENTATION_LANDSCAPE,
                        /* expected */ false);

                a.createActivityWithComponentInNewTask();
                a.setTopActivityInFreeformWindowingMode(true);
            });
            robot.checkDisplayShouldIgnoreOrientationRequest(SCREEN_ORIENTATION_LANDSCAPE,
                    /* expected */ false);
        });
    }

    /**
     * Runs a test scenario providing a Robot.
     */
@@ -291,6 +313,22 @@ public class AppCompatOrientationOverridesTest extends WindowTestsBase {
            }
        }

        void setOverrideRespectRequestedOrientationEnabled(boolean override) {
            spyOn(getTopOrientationOverrides());
            doReturn(override).when(getTopOrientationOverrides())
                    .isOverrideRespectRequestedOrientationEnabled();
        }

        void checkDisplayShouldIgnoreOrientationRequest(@ScreenOrientation int candidate,
                boolean expected) {
            assertEquals(expected, activity().displayContent()
                    .shouldIgnoreOrientationRequest(candidate));
        }

        void checkExpectedDisplayOrientation(@ScreenOrientation int expected) {
            assertEquals(expected, activity().displayContent().getOrientation());
        }

        void checkShouldUseDisplayLandscapeNaturalOrientation(boolean expected) {
            assertEquals(expected,
                    getTopOrientationOverrides().shouldUseDisplayLandscapeNaturalOrientation());