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

Unverified Commit 4668026e 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 5a874090
Loading
Loading
Loading
Loading
+44 −1
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.Configuration;
import android.database.ContentObserver;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.Trace;
import android.provider.Settings;
import android.util.Log;
import android.view.Display;
import android.view.IWindow;
@@ -76,6 +79,8 @@ import com.android.systemui.user.domain.interactor.SelectedUserInteractor;

import dagger.Lazy;

import lineageos.providers.LineageSettings;

import java.io.PrintWriter;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
@@ -274,6 +279,17 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
        }
    }

    private boolean shouldEnableKeyguardScreenRotation() {
        boolean enableAccelerometerRotation =
                Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.ACCELEROMETER_ROTATION, 0) != 0;
        boolean enableLockScreenRotation =
                LineageSettings.System.getInt(mContext.getContentResolver(),
                LineageSettings.System.LOCKSCREEN_ROTATION, 0) != 0;
        return mKeyguardStateController.isKeyguardScreenRotationAllowed()
                && (enableLockScreenRotation && enableAccelerometerRotation);
    }

    /**
     * Adds the notification shade view to the window manager.
     */
@@ -296,6 +312,8 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
        }

        mLpChanged.copyFrom(mLp);
        SettingsObserver observer = new SettingsObserver(new Handler());
        observer.observe(mContext);
        onThemeChanged();

        // Make the state consistent with KeyguardViewMediator#setupLocked during initialization.
@@ -433,7 +451,7 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW

    private void adjustScreenOrientation(NotificationShadeWindowState state) {
        if (state.bouncerShowing || state.isKeyguardShowingAndNotOccluded() || state.dozing) {
            if (mKeyguardStateController.isKeyguardScreenRotationAllowed()) {
            if (shouldEnableKeyguardScreenRotation()) {
                mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
            } else {
                mLpChanged.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
@@ -1075,4 +1093,29 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
            apply(mCurrentState);
        }
    };

    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) {
            // update the state
            apply(mCurrentState);
        }
    }
}