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

Unverified Commit 7ebc3133 authored by eray orçunus's avatar eray orçunus Committed by Michael Bestas
Browse files

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.

Change-Id: I8f1b468249c68e7b6514d1a96bdb3fc638af84fd
Signed-off-by: default avatareray orçunus <erayorcunus@gmail.com>
parent 1df67ed3
Loading
Loading
Loading
Loading
+40 −6
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ 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;
@@ -41,7 +42,8 @@ import com.android.internal.R;
public final class RotationPolicy {
    private static final String TAG = "RotationPolicy";
    private static final int CURRENT_ROTATION = -1;
    private static final int NATURAL_ROTATION = Surface.ROTATION_0;
    private static final int NATURAL_ROTATION =
            SystemProperties.getInt("persist.panel.orientation", Surface.ROTATION_0) / 90;

    private RotationPolicy() {
    }
@@ -72,7 +74,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 {
@@ -112,7 +114,8 @@ public final class RotationPolicy {
                Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0,
                UserHandle.USER_CURRENT);

        final int rotation = areAllRotationsAllowed(context) ? CURRENT_ROTATION : NATURAL_ROTATION;
        final int rotation = isCurrentRotationAllowed(context)
                ? CURRENT_ROTATION : NATURAL_ROTATION;
        setRotationLock(enabled, rotation);
    }

@@ -129,8 +132,39 @@ public final class RotationPolicy {
        setRotationLock(enabled, NATURAL_ROTATION);
    }

    private static boolean areAllRotationsAllowed(Context context) {
        return context.getResources().getBoolean(R.bool.config_allowAllRotations);
    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 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 void setRotationLock(final boolean enabled, final int rotation) {
+5 −21
Original line number Diff line number Diff line
@@ -154,6 +154,7 @@ import com.android.internal.policy.IKeyguardService;
import com.android.internal.policy.IShortcutService;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.util.ScreenShapeHelper;
import com.android.internal.view.RotationPolicy;
import com.android.internal.widget.PointerLocationView;
import com.android.server.GestureLauncherService;
import com.android.server.LocalServices;
@@ -7418,28 +7419,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    mAllowAllRotations = mContext.getResources().getBoolean(
                            com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
                }
                // 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 (orientation != ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
                        && orientation != ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
                   allowed = RotationPolicy.isRotationAllowed(sensorRotation,
                           mUserRotationAngles, mAllowAllRotations != 0);
                }
                if (allowed) {
                    preferredRotation = sensorRotation;