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

Commit a241d434 authored by Dan Pasanen's avatar Dan Pasanen Committed by Steve Kondik
Browse files

SystemUI: fix toggling lockscreen rotation [1/3]

Change-Id: I28fea0124c91b8efc206a940761e77fa61d1fefc
parent f98a7ac5
Loading
Loading
Loading
Loading
+39 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.graphics.PixelFormat;
import android.os.SystemProperties;
import android.provider.Settings;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
@@ -47,7 +48,7 @@ public class StatusBarWindowManager implements RemoteInputController.Callback {
    private WindowManager.LayoutParams mLp;
    private WindowManager.LayoutParams mLpChanged;
    private int mBarHeight;
    private final boolean mKeyguardScreenRotation;
    private boolean mKeyguardScreenRotation;
    private final float mScreenBrightnessDoze;
    private final State mCurrentState = new State();

@@ -61,8 +62,13 @@ public class StatusBarWindowManager implements RemoteInputController.Callback {

    private boolean shouldEnableKeyguardScreenRotation() {
        Resources res = mContext.getResources();
        boolean enableAccelerometerRotation = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.ACCELEROMETER_ROTATION, 1) != 0;
        boolean enableLockScreenRotation = CMSettings.System.getInt(mContext.getContentResolver(),
                CMSettings.System.LOCKSCREEN_ROTATION, 0) != 0;
        return SystemProperties.getBoolean("lockscreen.rot_override", false)
                || res.getBoolean(R.bool.config_enableLockScreenRotation);
                || (res.getBoolean(R.bool.config_enableLockScreenRotation)
                && (enableLockScreenRotation && enableAccelerometerRotation));
    }

    /**
@@ -96,6 +102,9 @@ public class StatusBarWindowManager implements RemoteInputController.Callback {
        mWindowManager.addView(mStatusBarView, mLp);
        mLpChanged = new WindowManager.LayoutParams();
        mLpChanged.copyFrom(mLp);

        SettingsObserver observer = new SettingsObserver(new Handler());
        observer.observe(mContext);
    }

    private void applyKeyguardFlags(State state) {
@@ -391,4 +400,32 @@ public class StatusBarWindowManager implements RemoteInputController.Callback {
            return result.toString();
        }
    }

    private class SettingsObserver extends ContentObserver {
        public SettingsObserver(Handler handler) {
            super(handler);
        }

        public void observe(Context context) {
            context.getContentResolver().registerContentObserver(
                    Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION),
                    false,
                    this);
            context.getContentResolver().registerContentObserver(
                    CMSettings.System.getUriFor(CMSettings.System.LOCKSCREEN_ROTATION),
                    false,
                    this);
        }

        public void unobserve(Context context) {
            context.getContentResolver().unregisterContentObserver(this);
        }

        @Override
        public void onChange(boolean selfChange) {
            mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
            // update the state
            apply(mCurrentState);
        }
    }
}