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

Commit bc865c16 authored by Dan Pasanen's avatar Dan Pasanen Committed by Bruno Martins
Browse files

SystemUI: Fix toggling lockscreen rotation [1/3]

Change-Id: I28fea0124c91b8efc206a940761e77fa61d1fefc
parent aa262423
Loading
Loading
Loading
Loading
+42 −2
Original line number Diff line number Diff line
@@ -25,10 +25,13 @@ 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.provider.Settings;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
@@ -50,6 +53,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;
import java.io.PrintWriter;
@@ -73,7 +78,7 @@ public class StatusBarWindowController implements Callback, Dumpable, Configurat
    private final IActivityManager mActivityManager;
    private final DozeParameters mDozeParameters;
    private final WindowManager.LayoutParams mLpChanged;
    private final boolean mKeyguardScreenRotation;
    private boolean mKeyguardScreenRotation;
    private ViewGroup mStatusBarView;
    private WindowManager.LayoutParams mLp;
    private boolean mHasTopUi;
@@ -124,8 +129,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));
    }

    /**
@@ -159,6 +171,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();
    }

@@ -656,4 +670,30 @@ public class StatusBarWindowController implements Callback, Dumpable, Configurat
    public interface OtherwisedCollapsedListener {
        void setWouldOtherwiseCollapse(boolean otherwiseCollapse);
    }

    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);
        }
    }
}