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

Commit 5bd4965a authored by Dan Pasanen's avatar Dan Pasanen Committed by Michael Bestas
Browse files

SystemUI: Fix toggling lockscreen rotation [1/3]

Change-Id: I28fea0124c91b8efc206a940761e77fa61d1fefc
parent 36e33825
Loading
Loading
Loading
Loading
+42 −2
Original line number Diff line number Diff line
@@ -25,11 +25,14 @@ import android.app.IActivityManager;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.PixelFormat;
import android.os.Binder;
import android.os.Handler;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.Trace;
import android.provider.Settings;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
@@ -52,6 +55,8 @@ import com.android.systemui.statusbar.SysuiStatusBarStateController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;

import lineageos.providers.LineageSettings;

import com.google.android.collect.Lists;

import java.io.FileDescriptor;
@@ -77,7 +82,7 @@ public class StatusBarWindowController implements Callback, Dumpable, Configurat
    private final IActivityManager mActivityManager;
    private final DozeParameters mDozeParameters;
    private final LayoutParams mLpChanged;
    private final boolean mKeyguardScreenRotation;
    private boolean mKeyguardScreenRotation;
    private final long mLockScreenDisplayTimeout;
    private final Display.Mode mKeyguardDisplayMode;
    private final KeyguardBypassController mKeyguardBypassController;
@@ -156,8 +161,15 @@ public class StatusBarWindowController implements Callback, Dumpable, Configurat

    private boolean shouldEnableKeyguardScreenRotation() {
        Resources res = mContext.getResources();
        boolean enableAccelerometerRotation =
                Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.ACCELEROMETER_ROTATION, 1) != 0;
        boolean enableLockScreenRotation =
                LineageSettings.System.getInt(mContext.getContentResolver(),
                LineageSettings.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));
    }

    /**
@@ -191,6 +203,8 @@ public class StatusBarWindowController implements Callback, Dumpable, Configurat
        mBarHeight = barHeight;
        mWindowManager.addView(mStatusBarView, mLp);
        mLpChanged.copyFrom(mLp);
        SettingsObserver observer = new SettingsObserver(new Handler());
        observer.observe(mContext);
        onThemeChanged();
    }

@@ -745,4 +759,30 @@ public class StatusBarWindowController implements Callback, Dumpable, Configurat
         */
        void onChange(boolean forceOpen);
    }

    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(
                    LineageSettings.System.getUriFor(LineageSettings.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);
        }
    }
}