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

Commit 983986d1 authored by Roman Birg's avatar Roman Birg Committed by Adnan Begovic
Browse files

SystemUI: improve lockscreen tile behavior



* Stay disabled when disabled
* No need to use Keyguard locks, use internal update monitor

Change-Id: I9e66458d5789aa45b933ca60643e049d932ce58b
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 4601c9fd
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.SearchManager;
import android.app.StatusBarManager;
import android.app.admin.DevicePolicyManager;
import android.app.trust.TrustManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
@@ -282,6 +283,11 @@ public class KeyguardViewMediator extends SystemUI {
     * */
    private boolean mHiding;

    /**
     * Whether we are disabling the lock screen internally
     */
    private boolean mInternallyDisabled = false;

    /**
     * we send this intent when the keyguard is dismissed.
     */
@@ -869,6 +875,23 @@ public class KeyguardViewMediator extends SystemUI {
        }
    }

    /**
     * Set the internal keyguard enabled state. This allows SystemUI to disable the lockscreen,
     * overriding any apps.
     * @param enabled
     */
    public void setKeyguardEnabledInternal(boolean enabled) {
        mInternallyDisabled = !enabled;
        setKeyguardEnabled(enabled);
        if (mInternallyDisabled) {
            mNeedToReshowWhenReenabled = false;
        }
    }

    public boolean getKeyguardEnabledInternal() {
        return !mInternallyDisabled;
    }

    /**
     * Same semantics as {@link android.view.WindowManagerPolicy#enableKeyguard}; provide
     * a way for external stuff to override normal keyguard behavior.  For instance
@@ -878,6 +901,12 @@ public class KeyguardViewMediator extends SystemUI {
        synchronized (this) {
            if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");

            if (mInternallyDisabled && enabled && !lockscreenEnforcedByDevicePolicy()) {
                // if keyguard is forcefully disabled internally (by lock screen tile), don't allow
                // it to be enabled externally, unless the device policy manager says so.
                return;
            }

            mExternallyEnabled = enabled;

            if (!enabled && mShowing) {
@@ -1132,6 +1161,23 @@ public class KeyguardViewMediator extends SystemUI {
        return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
    }

    public boolean lockscreenEnforcedByDevicePolicy() {
        DevicePolicyManager dpm = (DevicePolicyManager)
                mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
        if (dpm != null) {
            int passwordQuality = dpm.getPasswordQuality(null);
            switch (passwordQuality) {
                case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
                case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
                case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
                case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
                case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
                    return true;
            }
        }
        return false;
    }

    /**
     * Dismiss the keyguard through the security layers.
     */