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

Commit c3b63c86 authored by Ricardo Cerqueira's avatar Ricardo Cerqueira Committed by Sam Mortimer
Browse files

Configurable 0, 90, 180 and 270 degree rotation

Change-Id: Ia1859c51d71ef9d01cec2d13c6468ed89c6ac53e
Contributor: jonasl

- Add system setting

Change-Id: Ia7bf8cb64258e1d602230a8f9ea227d3b56a4dab
parent cd85262c
Loading
Loading
Loading
Loading
+32 −4
Original line number Diff line number Diff line
@@ -596,6 +596,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {

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

    boolean mSupportAutoRotation;
    int mAllowAllRotations = -1;
@@ -1025,6 +1026,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.Secure.getUriFor(
                    Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED), false, this,
                    UserHandle.USER_ALL);

            resolver.registerContentObserver(LineageSettings.System.getUriFor(
                    LineageSettings.System.ACCELEROMETER_ROTATION_ANGLES), false, this,
                    UserHandle.USER_ALL);

            updateSettings();
        }

@@ -2531,6 +2537,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                updateOrientationListenerLp();
            }

            mUserRotationAngles = LineageSettings.System.getInt(resolver,
                    LineageSettings.System.ACCELEROMETER_ROTATION_ANGLES, -1);

            if (mSystemReady) {
                int pointerLocation = Settings.System.getIntForUser(resolver,
                        Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
@@ -7396,10 +7405,29 @@ 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
                        || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
                // 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;