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

Unverified Commit c01cd9d4 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 e2c77618
Loading
Loading
Loading
Loading
+48 −2
Original line number Original line Diff line number Diff line
@@ -26,10 +26,13 @@ import static com.android.systemui.statusbar.NotificationRemoteInputManager.ENAB
import android.app.IActivityManager;
import android.app.IActivityManager;
import android.content.Context;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.ActivityInfo;
import android.database.ContentObserver;
import android.graphics.PixelFormat;
import android.graphics.PixelFormat;
import android.os.Binder;
import android.os.Binder;
import android.os.Handler;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.Trace;
import android.os.Trace;
import android.provider.Settings;
import android.util.Log;
import android.util.Log;
import android.view.Display;
import android.view.Display;
import android.view.Gravity;
import android.view.Gravity;
@@ -55,6 +58,8 @@ import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.statusbar.policy.KeyguardStateController;


import lineageos.providers.LineageSettings;

import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.lang.ref.Reference;
import java.lang.ref.Reference;
@@ -85,12 +90,13 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
    private final IActivityManager mActivityManager;
    private final IActivityManager mActivityManager;
    private final DozeParameters mDozeParameters;
    private final DozeParameters mDozeParameters;
    private final LayoutParams mLpChanged;
    private final LayoutParams mLpChanged;
    private final boolean mKeyguardScreenRotation;
    private boolean mKeyguardScreenRotation;
    private final long mLockScreenDisplayTimeout;
    private final long mLockScreenDisplayTimeout;
    private final float mKeyguardPreferredRefreshRate; // takes precedence over max
    private final float mKeyguardPreferredRefreshRate; // takes precedence over max
    private final float mKeyguardMaxRefreshRate;
    private final float mKeyguardMaxRefreshRate;
    private final KeyguardViewMediator mKeyguardViewMediator;
    private final KeyguardViewMediator mKeyguardViewMediator;
    private final KeyguardBypassController mKeyguardBypassController;
    private final KeyguardBypassController mKeyguardBypassController;
    private final KeyguardStateController mKeyguardStateController;
    private final AuthController mAuthController;
    private final AuthController mAuthController;
    private ViewGroup mNotificationShadeView;
    private ViewGroup mNotificationShadeView;
    private LayoutParams mLp;
    private LayoutParams mLp;
@@ -123,7 +129,8 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
        mContext = context;
        mContext = context;
        mWindowManager = windowManager;
        mWindowManager = windowManager;
        mActivityManager = activityManager;
        mActivityManager = activityManager;
        mKeyguardScreenRotation = keyguardStateController.isKeyguardScreenRotationAllowed();
        mKeyguardStateController = keyguardStateController;
        mKeyguardScreenRotation = shouldEnableKeyguardScreenRotation();
        mDozeParameters = dozeParameters;
        mDozeParameters = dozeParameters;
        mScreenBrightnessDoze = mDozeParameters.getScreenBrightnessDoze();
        mScreenBrightnessDoze = mDozeParameters.getScreenBrightnessDoze();
        mLpChanged = new LayoutParams();
        mLpChanged = new LayoutParams();
@@ -197,6 +204,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.
     * Adds the notification shade view to the window manager.
     */
     */
@@ -231,6 +249,8 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW


        mWindowManager.addView(mNotificationShadeView, mLp);
        mWindowManager.addView(mNotificationShadeView, mLp);
        mLpChanged.copyFrom(mLp);
        mLpChanged.copyFrom(mLp);
        SettingsObserver observer = new SettingsObserver(new Handler());
        observer.observe(mContext);
        onThemeChanged();
        onThemeChanged();


        // Make the state consistent with KeyguardViewMediator#setupLocked during initialization.
        // Make the state consistent with KeyguardViewMediator#setupLocked during initialization.
@@ -844,4 +864,30 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
            setDozing(isDozing);
            setDozing(isDozing);
        }
        }
    };
    };

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