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

Commit a8302370 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Respect sensor orientation with ignore-orientation-request" into main

parents 77d7df1c 11632d2b
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -242,17 +242,24 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> {
     * @return {@value true} if we need to ignore the orientation in input.
     */
    boolean shouldIgnoreOrientationRequest(@ScreenOrientation int orientation) {
        // We always respect orientation request for ActivityInfo.SCREEN_ORIENTATION_LOCKED
        // ActivityInfo.SCREEN_ORIENTATION_NOSENSOR.
        // Main use case why this is important is Camera apps that rely on those
        // properties to ensure that they will be able to determine Camera preview
        // orientation correctly
        if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED
                || orientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
                || orientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR
                || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
                || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR) {
            // Respect "locked" and "nosensor" for the compatibility of camera apps.
            // Respect "sensor" because the main purpose of ignoring is to avoid changing
            // display rotation by fixed-orientation request.
            return false;
        } else if (getIgnoreOrientationRequest()) {
            if (orientation == SCREEN_ORIENTATION_UNSET
                    || orientation == SCREEN_ORIENTATION_UNSPECIFIED
                    || orientation == ActivityInfo.SCREEN_ORIENTATION_USER) {
                // The behavior of non-fixed orientation is the same as ignoring.
                return true;
            }
            return !shouldRespectOrientationRequestDueToPerAppOverride();
        }
        return getIgnoreOrientationRequest()
                && !shouldRespectOrientationRequestDueToPerAppOverride();
        return false;
    }

    private boolean shouldRespectOrientationRequestDueToPerAppOverride() {
+7 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.os.Build.VERSION_CODES.P;
import static android.os.Build.VERSION_CODES.Q;
@@ -1149,6 +1150,12 @@ public class DisplayContentTests extends WindowTestsBase {
        activity.setRequestedOrientation(newOrientation);

        assertEquals("The display should be rotated.", 1, dc.getRotation() % 2);

        dc.setIgnoreOrientationRequest(true);
        activity.setRequestedOrientation(SCREEN_ORIENTATION_SENSOR);

        assertEquals("Sensor orientation must be respected with ignore-orientation-request",
                SCREEN_ORIENTATION_SENSOR, dc.getLastOrientation());
    }

    @Test