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

Commit edcd72a5 authored by Jonas Larsson's avatar Jonas Larsson Committed by Steve Kondik
Browse files

Configurable 0, 90, 180 and 270 degree rotation (framework part)

This is similar to my previous CM contributions. Requires settings
UI to configure (not done yet). The rationale is to be able to
have automatic rotation always enabled, but only for desired
angles.

Change-Id: I19d3d2cb91249ba2cdee310e6ff7b0978e9bfde0
parent e4052534
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -1804,6 +1804,19 @@ public final class Settings {
         */
        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
+29 −3
Original line number Diff line number Diff line
@@ -329,6 +329,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
    int mUserRotation = Surface.ROTATION_0;
    int mUserRotationAngles = -1;

    int mAllowAllRotations = -1;
    boolean mCarDockEnablesAccelerometer;
@@ -497,6 +498,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    "fancy_rotation_anim"), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.ACCELEROMETER_ROTATION_ANGLES), false, this);
            updateSettings();
        }

@@ -966,6 +969,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mUserRotation = Settings.System.getInt(resolver,
                    Settings.System.USER_ROTATION,
                    Surface.ROTATION_0);
            mUserRotationAngles = Settings.System.getInt(resolver,
                    Settings.System.ACCELEROMETER_ROTATION_ANGLES, -1);

            if (mAccelerometerDefault != accelerometerDefault) {
                mAccelerometerDefault = accelerometerDefault;
@@ -3276,9 +3281,30 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    mAllowAllRotations = mContext.getResources().getBoolean(
                            com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
                }
                if (sensorRotation != Surface.ROTATION_180
                        || mAllowAllRotations == 1
                        || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR) {
                // Rotation setting bitmask
                // 1=0 2=90 4=180 8=270
                boolean allowed = true;
                if (mUserRotationAngles < 0) {
                    // Not set by user so use these defaults
                    mUserRotationAngles = mAllowAllRotations == 1 ?
                        (1 | 2 | 4 | 8) : // All angles
                        (1 | 2 | 8); // All except 180
                }
                switch (sensorRotation) {
                    case Surface.ROTATION_0:
                      allowed = (mUserRotationAngles & 1) != 0;
                      break;
                    case Surface.ROTATION_90:
                      allowed = (mUserRotationAngles & 2) != 0;
                      break;
                    case Surface.ROTATION_180:
                      allowed = (mUserRotationAngles & 4) != 0;
                      break;
                    case Surface.ROTATION_270:
                      allowed = (mUserRotationAngles & 8) != 0;
                      break;
                }
                if (allowed) {
                    preferredRotation = sensorRotation;
                } else {
                    preferredRotation = lastRotation;