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

Commit a11b2ddc authored by David van Tonder's avatar David van Tonder
Browse files

Framework: Slide lock delay support (Part 1 of 2)

This commit adds the framework support for the Slide lock delay settings while
retaining the security integrity of AOSP.

Change-Id: Ib023025535c022213dc13de82b0ffae9a53d9ef5
parent 690f7075
Loading
Loading
Loading
Loading
+35 −12
Original line number Original line Diff line number Diff line
@@ -122,7 +122,6 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
     */
     */
    protected static final int AWAKE_INTERVAL_DEFAULT_MS = 10000;
    protected static final int AWAKE_INTERVAL_DEFAULT_MS = 10000;



    /**
    /**
     * The default amount of time we stay awake (used for all key input) when
     * The default amount of time we stay awake (used for all key input) when
     * the keyboard is open
     * the keyboard is open
@@ -356,11 +355,21 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
            mScreenOn = false;
            mScreenOn = false;
            if (DEBUG) Log.d(TAG, "onScreenTurnedOff(" + why + ")");
            if (DEBUG) Log.d(TAG, "onScreenTurnedOff(" + why + ")");


            // Lock immediately based on setting if secure (user has a pin/pattern/password).
            // Prepare for handling Lock/Slide lock delay and timeout
            // This also "locks" the device when not secure to provide easy access to the
            boolean lockImmediately = false;
            // camera while preventing unwanted input.
            final ContentResolver cr = mContext.getContentResolver();
            final boolean lockImmediately =
            boolean separateSlideLockTimeoutEnabled = Settings.System.getInt(cr,
                mLockPatternUtils.getPowerButtonInstantlyLocks() || !mLockPatternUtils.isSecure();
                    Settings.System.SCREEN_LOCK_SLIDE_DELAY_TOGGLE, 0) == 1;
            if (mLockPatternUtils.isSecure()) {
                // Lock immediately based on setting if secure (user has a pin/pattern/password)
                // This is retained as-is to ensue AOSP security integrity is maintained
                lockImmediately = true;
            } else {
                // Unless a separate slide lock timeout is enabled, this "locks" the device when
                // not secure to provide easy access to the camera while preventing unwanted input
                lockImmediately = separateSlideLockTimeoutEnabled ? false
                        : mLockPatternUtils.getPowerButtonInstantlyLocks();
            }


            if (mExitSecureCallback != null) {
            if (mExitSecureCallback != null) {
                if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
                if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
@@ -375,11 +384,9 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
            } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT
            } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT
                   || (why == WindowManagerPolicy.OFF_BECAUSE_OF_USER && !lockImmediately)) {
                   || (why == WindowManagerPolicy.OFF_BECAUSE_OF_USER && !lockImmediately)) {
                // if the screen turned off because of timeout or the user hit the power button
                // if the screen turned off because of timeout or the user hit the power button
                // and we don't need to lock immediately, set an alarm
                // and we don't need to lock immediately, set an alarm to enable it a little
                // to enable it a little bit later (i.e, give the user a chance
                // bit later (i.e, give the user a chance to turn the screen back on within
                // to turn the screen back on within a certain window without
                // a certain window without having to unlock the screen)
                // having to unlock the screen)
                final ContentResolver cr = mContext.getContentResolver();


                // From DisplaySettings
                // From DisplaySettings
                long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
                long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
@@ -390,17 +397,33 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
                        Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
                        Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
                        KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
                        KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);


                // From CyanogenMod specific Settings
                int slideLockTimeoutDelay = (why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT ? Settings.System
                        .getInt(cr, Settings.System.SCREEN_LOCK_SLIDE_TIMEOUT_DELAY,
                                KEYGUARD_LOCK_AFTER_DELAY_DEFAULT) : Settings.System.getInt(cr,
                        Settings.System.SCREEN_LOCK_SLIDE_SCREENOFF_DELAY, 0));

                // From DevicePolicyAdmin
                // From DevicePolicyAdmin
                final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
                final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
                        .getMaximumTimeToLock(null);
                        .getMaximumTimeToLock(null);


                if (DEBUG) Log.d(TAG, "Security lock screen timeout delay is " + lockAfterTimeout
                        + " ms; slide lock screen timeout delay is "
                        + slideLockTimeoutDelay
                        + " ms; Separate slide lock delay settings considered: "
                        + separateSlideLockTimeoutEnabled
                        + "; Policy timeout is "
                        + policyTimeout
                        + " ms");

                long timeout;
                long timeout;
                if (policyTimeout > 0) {
                if (policyTimeout > 0) {
                    // policy in effect. Make sure we don't go beyond policy limit.
                    // policy in effect. Make sure we don't go beyond policy limit.
                    displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
                    displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
                    timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
                    timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
                } else {
                } else {
                    timeout = lockAfterTimeout;
                    // Not sure lockAfterTimeout is needed any more but keeping it for AOSP compatibility
                    timeout = separateSlideLockTimeoutEnabled ? slideLockTimeoutDelay : lockAfterTimeout;
                }
                }


                if (timeout <= 0) {
                if (timeout <= 0) {