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

Unverified Commit e2c77618 authored by Ricardo Cerqueira's avatar Ricardo Cerqueira Committed by Michael Bestas
Browse files

Configurable 0, 90, 180 and 270 degree rotation



Change-Id: Ia1859c51d71ef9d01cec2d13c6468ed89c6ac53e
Contributor: jonasl

- Add system setting

Author: Tim Schumacher <timschumi@gmx.de>
Date:   Wed Nov 28 21:44:18 2018 +0100

    Add back ACCELEROMETER_ROTATION_ANGLES and update references

    This needed to move back into fw/b, because it needs to be
    accessed from inside the RotationPolicy. Previously
    (when this constant and Setting were located in lineage-sdk),
    the settings for the display rotation had no effect, because we
    couldn't query the correct set of settings.

    Change-Id: Icce249925a578c328db3884e5d332b20d6e7db6c
    Fixes: BUGBASH-2042

Author: eray orçunus <erayorcunus@gmail.com>
Date:   Mon Jun 22 22:47:40 2015 +0300

    Rotation related corrections

    - There are some conditions deleted while placing rotation angles code, I added them.

    - Rotation lock was screwed up since CM 12. Fixed it by fetching allowed rotations from CM's
    allowed rotations setting.

    - Also, a CAF commit had killed rotation lock ability.

    [port to 15.1]:
     - ACCELEROMETER_ROTATION_ANGLES moved to LineageSDK
     - Slight change of the WindowManager API

    [port to 16.0]:
     - adjust context
     - ACCELEROMETER_ROTATION_ANGLES moved to Settings
     - Use the configstore API

    Change-Id: I8f1b468249c68e7b6514d1a96bdb3fc638af84fd
    Signed-off-by: default avatareray orçunus <erayorcunus@gmail.com>
    (cherry picked from commit a62720d5)

Author: Tim Schumacher <timschumi@gmx.de>
Date:   Thu May 2 19:48:39 2019 +0200

    RotationPolicy: Don't crash if configstore 1.1 isn't available

    Change-Id: I77301ec8c72393daa0003ca310eee07b767d4e69

Change-Id: Ia7bf8cb64258e1d602230a8f9ea227d3b56a4dab
parent eb370815
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -231,6 +231,7 @@ java_library {
        "android.hardware.cas-V1.0-java",
        "android.hardware.cas-V1.1-java",
        "android.hardware.cas-V1.2-java",
        "android.hardware.configstore-V1.1-java",
        "android.hardware.contexthub-V1.0-java",
        "android.hardware.contexthub-V1.1-java",
        "android.hardware.contexthub-V1.2-java",
+13 −0
Original line number Diff line number Diff line
@@ -4818,6 +4818,19 @@ public final class Settings {
        @Readable
        public static final String ACCELEROMETER_ROTATION = "accelerometer_rotation";
        /**
         * Control the type of rotation which can be performed using the accelerometer
         * if ACCELEROMETER_ROTATION is enabled.
         * Value is a bitwise combination of
         * 1 = 0 degrees (portrait)
         * 2 = 90 degrees (left)
         * 4 = 180 degrees (inverted portrait)
         * 8 = 270 degrees (right)
         * Setting to 0 is effectively orientation lock
         * @hide
         */
        public static final String ACCELEROMETER_ROTATION_ANGLES = "accelerometer_rotation_angles";
        /**
         * Default screen rotation when no other policy applies.
         * When {@link #ACCELEROMETER_ROTATION} is zero and no on-screen Activity expresses a
+85 −6
Original line number Diff line number Diff line
@@ -21,10 +21,14 @@ import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.graphics.Point;
import android.hardware.configstore.V1_1.DisplayOrientation;
import android.hardware.configstore.V1_1.ISurfaceFlingerConfigs;
import android.hardware.configstore.V1_1.OptionalDisplayOrientation;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
@@ -35,6 +39,8 @@ import android.view.WindowManagerGlobal;

import com.android.internal.R;

import java.util.NoSuchElementException;

/**
 * Provides helper functions for configuring the display rotation policy.
 */
@@ -42,7 +48,7 @@ public final class RotationPolicy {
    private static final String TAG = "RotationPolicy";
    private static final int CURRENT_ROTATION = -1;

    public static final int NATURAL_ROTATION = Surface.ROTATION_0;
    private static int sNaturalRotation = -1;

    private RotationPolicy() {
    }
@@ -73,7 +79,7 @@ public final class RotationPolicy {
     * otherwise Configuration.ORIENTATION_UNDEFINED if any orientation is lockable.
     */
    public static int getRotationLockOrientation(Context context) {
        if (!areAllRotationsAllowed(context)) {
        if (!isCurrentRotationAllowed(context)) {
            final Point size = new Point();
            final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
            try {
@@ -110,7 +116,8 @@ public final class RotationPolicy {
     * Enables or disables rotation lock from the system UI toggle.
     */
    public static void setRotationLock(Context context, final boolean enabled) {
        final int rotation = areAllRotationsAllowed(context) ? CURRENT_ROTATION : NATURAL_ROTATION;
        final int rotation = isCurrentRotationAllowed(context)
                ? CURRENT_ROTATION : getNaturalRotation();
        setRotationLockAtAngle(context, enabled, rotation);
    }

@@ -136,11 +143,43 @@ public final class RotationPolicy {
                Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, enabled ? 1 : 0,
                        UserHandle.USER_CURRENT);

        setRotationLock(enabled, NATURAL_ROTATION);
        setRotationLock(enabled, getNaturalRotation());
    }

    public static boolean isRotationAllowed(int rotation,
            int userRotationAngles, boolean allowAllRotations) {
        if (userRotationAngles < 0) {
            // Not set by user so use these defaults
            userRotationAngles = allowAllRotations ?
                    (1 | 2 | 4 | 8) : // All angles
                    (1 | 2 | 8); // All except 180
        }
        switch (rotation) {
            case Surface.ROTATION_0:
                return (userRotationAngles & 1) != 0;
            case Surface.ROTATION_90:
                return (userRotationAngles & 2) != 0;
            case Surface.ROTATION_180:
                return (userRotationAngles & 4) != 0;
            case Surface.ROTATION_270:
                return (userRotationAngles & 8) != 0;
        }
        return false;
    }

    private static boolean areAllRotationsAllowed(Context context) {
        return context.getResources().getBoolean(R.bool.config_allowAllRotations);
    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.getDefaultDisplayRotation(), userRotationAngles,
                    allowAllRotations);
        } catch (RemoteException exc) {
            Log.w(TAG, "Unable to getWindowManagerService.getDefaultDisplayRotation()");
        }
        return false;
    }

    private static void setRotationLock(final boolean enabled, final int rotation) {
@@ -191,6 +230,46 @@ public final class RotationPolicy {
        context.getContentResolver().unregisterContentObserver(listener.mObserver);
    }

    public static int getNaturalRotation() {
        if (sNaturalRotation == -1) {
            sNaturalRotation = getNaturalRotationConfig();
        }
        return sNaturalRotation;
    }

    private static int getNaturalRotationConfig() {
        String primaryDisplayOrientation =
                SystemProperties.get("ro.surface_flinger.primary_display_orientation");
        if (primaryDisplayOrientation == "ORIENTATION_90") {
            return Surface.ROTATION_90;
        }
        if (primaryDisplayOrientation == "ORIENTATION_180") {
            return Surface.ROTATION_180;
        }
        if (primaryDisplayOrientation == "ORIENTATION_270") {
            return Surface.ROTATION_270;
        }

        OptionalDisplayOrientation orientation;

        try {
            orientation =
                    ISurfaceFlingerConfigs.getService().primaryDisplayOrientation();
            switch (orientation.value) {
                case DisplayOrientation.ORIENTATION_90:
                    return Surface.ROTATION_90;
                case DisplayOrientation.ORIENTATION_180:
                    return Surface.ROTATION_180;
                case DisplayOrientation.ORIENTATION_270:
                    return Surface.ROTATION_270;
            }
        } catch (RemoteException | NoSuchElementException e) {
            // do nothing
        }

        return Surface.ROTATION_0;
    }

    /**
     * Listener that is invoked whenever a change occurs that might affect the rotation policy.
     */
+1 −0
Original line number Diff line number Diff line
@@ -202,5 +202,6 @@ public class SystemSettingsValidators {
        VALIDATORS.put(System.WIFI_STATIC_DNS2, LENIENT_IP_ADDRESS_VALIDATOR);
        VALIDATORS.put(System.SHOW_BATTERY_PERCENT, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.NOTIFICATION_LIGHT_PULSE, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.ACCELEROMETER_ROTATION_ANGLES, NON_NEGATIVE_INTEGER_VALIDATOR);
    }
}
+2 −3
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.systemui.navigationbar;

import static com.android.internal.view.RotationPolicy.NATURAL_ROTATION;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
@@ -43,6 +41,7 @@ import android.view.accessibility.AccessibilityManager;
import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.UiEventLoggerImpl;
import com.android.internal.view.RotationPolicy;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.animation.Interpolators;
@@ -428,7 +427,7 @@ public class RotationButtonController {
        }
        // Only override user prefs when returning to the natural rotation (normally portrait).
        // Don't let apps that force landscape or 180 alter user lock.
        return rotation == NATURAL_ROTATION;
        return rotation == RotationPolicy.getNaturalRotation();
    }

    private boolean isRotationAnimationCCW(int from, int to) {
Loading