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

Commit 8dbccff0 authored by Roman Birg's avatar Roman Birg
Browse files

SystemUI: improve lockscreen tile behavior with profiles



Disable (grey out) the lock screen tile when a profile is already
disabling it. Profiles takes precedence over the internal setting.

Also simplify lockscreen disable logic - using a null'd Boolean without
synchonization will lead to things falling out of place.

Ref: CYNGNOS-1930

Change-Id: Ia4cb7926e418a4d72426be65e5bfb11dc44bee5e
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent ae32bafb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@
    <string name="quick_settings_lockscreen_label">Lock screen</string>
    <string name="quick_settings_ambient_display_label">Ambient display</string>
    <string name="quick_settings_lockscreen_label_enforced">Lock screen enforced</string>
    <string name="quick_settings_lockscreen_label_locked_by_profile">Disabled by profile</string>
    <!-- Content description of the screen timeout tile in quick settings (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_quick_settings_screen_timeout">Screen timeout: <xliff:g id="timeout" example="30 seconds">%s</xliff:g>.</string>

+18 −21
Original line number Diff line number Diff line
@@ -203,7 +203,6 @@ public class KeyguardViewMediator extends SystemUI {
    private AudioManager mAudioManager;
    private StatusBarManager mStatusBarManager;
    private boolean mSwitchingUser;
    private ProfileManager mProfileManager;
    private boolean mSystemReady;
    private boolean mBootCompleted;
    private boolean mBootSendUserPresent;
@@ -290,7 +289,7 @@ public class KeyguardViewMediator extends SystemUI {
    /**
     * Whether we are disabling the lock screen internally
     */
    private Boolean mInternallyDisabled = null;
    private boolean mInternallyDisabled = false;

    /**
     * we send this intent when the keyguard is dismissed.
@@ -627,7 +626,6 @@ public class KeyguardViewMediator extends SystemUI {

        mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
        mShowKeyguardWakeLock.setReferenceCounted(false);
        mProfileManager = ProfileManager.getInstance(mContext);
        mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DELAYED_KEYGUARD_ACTION));
        mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DISMISS_KEYGUARD_SECURELY_ACTION),
                android.Manifest.permission.CONTROL_KEYGUARD, null);
@@ -693,21 +691,15 @@ public class KeyguardViewMediator extends SystemUI {
                        getPersistedDefaultOldSetting() ? 1 : 0,
                        UserHandle.USER_CURRENT) == 0;

                synchronized (KeyguardViewMediator.this) {
                    if (mKeyguardBound) {
                    if (mInternallyDisabled == null) {
                        // if it's enabled on boot, don't go through the notions of
                        // setting it enabled, as it might cause a flicker, just set the state
                        if (newDisabledState) {
                            setKeyguardEnabledInternal(false); // will set mInternallyDisabled
                        } else {
                            mInternallyDisabled = false;
                        }
                    } else if (newDisabledState != mInternallyDisabled) {
                        if (newDisabledState != mInternallyDisabled) {
                            // it was updated,
                            setKeyguardEnabledInternal(!newDisabledState);
                        }
                    }
                }
            }
        };
    }

@@ -920,13 +912,10 @@ public class KeyguardViewMediator extends SystemUI {
            if (DEBUG) Log.d(TAG, "isKeyguardDisabled: keyguard is disabled internally");
            return true;
        }
        Profile profile = mProfileManager.getActiveProfile();
        if (profile != null) {
            if (profile.getScreenLockMode().getValue() == Profile.LockMode.DISABLE) {
        if (isProfileDisablingKeyguard()) {
            if (DEBUG) Log.d(TAG, "isKeyguardDisabled: keyguard is disabled by profile");
            return true;
        }
        }
        return false;
    }

@@ -961,6 +950,10 @@ public class KeyguardViewMediator extends SystemUI {
     */
    public void setKeyguardEnabledInternal(boolean enabled) {
        mInternallyDisabled = !enabled;
        if (!mUpdateMonitor.isSimPinSecure()) {
            // disable when sim is ready
            return;
        }
        setKeyguardEnabled(enabled);
        if (mInternallyDisabled) {
            mNeedToReshowWhenReenabled = false;
@@ -971,7 +964,7 @@ public class KeyguardViewMediator extends SystemUI {
        return !mInternallyDisabled;
    }

    private boolean isProfileDisablingKeyguard() {
    public boolean isProfileDisablingKeyguard() {
        final Profile activeProfile = ProfileManager.getInstance(mContext).getActiveProfile();
        return activeProfile != null
                && activeProfile.getScreenLockMode().getValue() == Profile.LockMode.DISABLE;
@@ -1558,6 +1551,10 @@ public class KeyguardViewMediator extends SystemUI {

    private void playSound(int soundId) {
        if (soundId == 0) return;
        if (mInternallyDisabled) {
            Log.d(TAG, "suppressing lock screen sounds because it is disabled");
            return;
        }
        final ContentResolver cr = mContext.getContentResolver();
        if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {

+40 −27
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ import com.android.systemui.SystemUIApplication;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.qs.QSTile;
import com.android.systemui.statusbar.policy.KeyguardMonitor;

import cyanogenmod.app.Profile;
import cyanogenmod.app.ProfileManager;
import cyanogenmod.providers.CMSettings;
import org.cyanogenmod.internal.logging.CMMetricsLogger;

@@ -32,7 +35,6 @@ public class LockscreenToggleTile extends QSTile<QSTile.BooleanState>
    private static final Intent LOCK_SCREEN_SETTINGS =
            new Intent("android.settings.LOCK_SCREEN_SETTINGS");

    private KeyguardViewMediator mKeyguardViewMediator;
    private KeyguardMonitor mKeyguard;
    private boolean mListening;

@@ -42,21 +44,13 @@ public class LockscreenToggleTile extends QSTile<QSTile.BooleanState>
        super(host);

        mKeyguard = host.getKeyguardMonitor();
        mKeyguardViewMediator =
                ((SystemUIApplication)
                        mContext.getApplicationContext()).getComponent(KeyguardViewMediator.class);

        mSettingsObserver = new KeyguardViewMediator.LockscreenEnabledSettingsObserver(mContext,
                mUiHandler) {

            @Override
            public void update() {
                boolean newState = CMSettings.Secure.getIntForUser(
                        mContext.getContentResolver(),
                        CMSettings.Secure.LOCKSCREEN_INTERNALLY_ENABLED,
                        getPersistedDefaultOldSetting() ? 1 : 0,
                        UserHandle.USER_CURRENT) != 0;
                refreshState(newState);
                refreshState();
            }
        };

@@ -97,16 +91,34 @@ public class LockscreenToggleTile extends QSTile<QSTile.BooleanState>

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        final boolean lockscreenEnforced = mKeyguardViewMediator.lockscreenEnforcedByDevicePolicy();
        KeyguardViewMediator mediator = ((SystemUIApplication)
                        mContext.getApplicationContext()).getComponent(KeyguardViewMediator.class);

        if (mediator == null) {
            state.visible = false;
            state.value = false;
            state.enabled = false;
        } else {
            final boolean lockscreenEnforced = mediator.lockscreenEnforcedByDevicePolicy();
            final boolean lockscreenEnabled = lockscreenEnforced ||
                arg != null ? (Boolean) arg : mKeyguardViewMediator.getKeyguardEnabledInternal();
                    arg != null ? (Boolean) arg : mediator.getKeyguardEnabledInternal();

            state.visible = mediator.isKeyguardBound();

            if (mediator.isProfileDisablingKeyguard()) {
                state.label = mContext.getString(
                        R.string.quick_settings_lockscreen_label_locked_by_profile);
                state.value = false;
                state.enabled = false;
            } else {
                state.value = lockscreenEnabled;
        state.visible = mKeyguardViewMediator.isKeyguardBound();
                state.enabled = !mKeyguard.isShowing() || !mKeyguard.isSecure();

                state.label = mContext.getString(lockscreenEnforced
                        ? R.string.quick_settings_lockscreen_label_enforced
                        : R.string.quick_settings_lockscreen_label);
            }
            // update icon
            if (lockscreenEnabled) {
                state.icon = ResourceIcon.get(R.drawable.ic_qs_lock_screen_on);
                state.contentDescription = mContext.getString(
@@ -117,6 +129,7 @@ public class LockscreenToggleTile extends QSTile<QSTile.BooleanState>
                        R.string.accessibility_quick_settings_lock_screen_off);
            }
        }
    }

    @Override
    public int getMetricsCategory() {