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

Commit be2d4a12 authored by Roman Birg's avatar Roman Birg Committed by Gerrit Code Review
Browse files

RotationPolicy: fix rotation toggle logic



The toggle should always lock to the current orientation regardless of
whether it is explicitly deemed as allowed by the user.

Ref: CYNGNOS-1163

Change-Id: I60613568c17ab182a9f2e90d0e341ffff6d522a6
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
(cherry picked from commit 9a21f884)
parent 94412aa8
Loading
Loading
Loading
Loading
+4 −14
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public final class RotationPolicy {
     * otherwise Configuration.ORIENTATION_UNDEFINED if any orientation is lockable.
     */
    public static int getRotationLockOrientation(Context context) {
        if (!isCurrentRotationAllowed(context)) {
        if (!areAllRotationsAllowed(context)) {
            final Point size = new Point();
            final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
            try {
@@ -114,7 +114,7 @@ public final class RotationPolicy {
                Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0,
                UserHandle.USER_CURRENT);

        final int rotation = isCurrentRotationAllowed(context)
        final int rotation = areAllRotationsAllowed(context)
                ? CURRENT_ROTATION : NATURAL_ROTATION;
        setRotationLock(enabled, rotation);
    }
@@ -153,18 +153,8 @@ public final class RotationPolicy {
        return false;
    }

    private static boolean isCurrentRotationAllowed(Context context) {
        int userRotationAngles = Settings.System.getInt(context.getContentResolver(),
                Settings.System.ACCELEROMETER_ROTATION_ANGLES, -1);
        boolean allowAllRotations = context.getResources().getBoolean(
                com.android.internal.R.bool.config_allowAllRotations);
        final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
        try {
            return isRotationAllowed(wm.getRotation(), userRotationAngles, allowAllRotations);
        } catch (RemoteException exc) {
            Log.w(TAG, "Unable to getWindowManagerService.getRotation()");
        }
        return false;
    private static boolean areAllRotationsAllowed(Context context) {
        return context.getResources().getBoolean(R.bool.config_allowAllRotations);
    }

    private static void setRotationLock(final boolean enabled, final int rotation) {