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

Commit 544ca85d authored by Robert Burns's avatar Robert Burns
Browse files

Configurable 0, 90, 180 and 270 degree rotation

Change-Id: Ia1859c51d71ef9d01cec2d13c6468ed89c6ac53e
Contributor: jonasl
parent b205431f
Loading
Loading
Loading
Loading
+31 −3
Original line number Diff line number Diff line
@@ -304,6 +304,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {

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

    int mAllowAllRotations = -1;
@@ -560,6 +561,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.EXPANDED_DESKTOP_STATE), false, this,
                    UserHandle.USER_ALL);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.ACCELEROMETER_ROTATION_ANGLES), false, this,
                    UserHandle.USER_ALL);

            updateSettings();
        }
@@ -1159,6 +1163,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                updateOrientationListenerLp();
            }

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

            if (mSystemReady) {
                int pointerLocation = Settings.System.getIntForUser(resolver,
                        Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
@@ -4084,9 +4091,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;