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

Commit 11632d2b authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Respect sensor orientation with ignore-orientation-request

So the behavior follows the API definition of sensor orientation.
And the target to ignore is mainly for fixed-orientation.

Also optimize the cases of unset/unspecified/user that are also not
fixed-orientation. It can save hundreds of activity traversals by
shouldRespectOrientationRequestDueToPerAppOverride when launching
a regular app.

Fix: 432587525
Flag: EXEMPT bugfix
Test: DisplayContentTests#testOnDescendantOrientationRequestChanged
Change-Id: I890d539ebd8fc10d591066814f1a1de8b1f28b3d
parent ab94e59d
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