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

Commit 142394d1 authored by BootsSiR's avatar BootsSiR Committed by Steve Kondik
Browse files

Delay showing screen lock based on user-defined settings

Change-Id: I01ff46cb2f4030caed8176be6e0560b11bb02eda
parent 98dba2ab
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -1738,6 +1738,22 @@ public final class Settings {
         */
        public static final String POWER_DIALOG_PROMPT = "power_dialog_prompt";

        /**
         * How many ms to delay before enabling the screen lock when the screen
         * goes off due to timeout
         *
         * @hide
         */
        public static final String SCREEN_LOCK_TIMEOUT_DELAY = "screen_lock_timeout_delay";

        /**
         * How many ms to delay before enabling the screen lock when the screen
         * is turned off by the user
         *
         * @hide
         */
        public static final String SCREEN_LOCK_SCREENOFF_DELAY = "screen_lock_screenoff_delay";

        /**
         * Whether the audible DTMF tones are played by the dialer when dialing. The value is
         * boolean (1 or 0).
+44 −14
Original line number Diff line number Diff line
@@ -321,20 +321,30 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
            } else if (mShowing) {
                notifyScreenOffLocked();
                resetStateLocked();
            } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT) {
                // if the screen turned off because of timeout, set an alarm
                // to enable it a little bit later (i.e, give the user a chance
                // to turn the screen back on within a certain window without
                // having to unlock the screen)
                long when = SystemClock.elapsedRealtime() + KEYGUARD_DELAY_MS;
                Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
                intent.putExtra("seq", mDelayedShowingSequence);
                PendingIntent sender = PendingIntent.getBroadcast(mContext,
                        0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
                mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, when,
                        sender);
                if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
                                 + mDelayedShowingSequence);
            } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT
                    || why == WindowManagerPolicy.OFF_BECAUSE_OF_USER) {
                final ContentResolver cr = mContext.getContentResolver();

                // retrieve the correct timeout setting depending on why
                // the screen went off
                int timeoutDelay = (why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT ? Settings.System
                        .getInt(cr, Settings.System.SCREEN_LOCK_TIMEOUT_DELAY, KEYGUARD_DELAY_MS)
                        : Settings.System
                                .getInt(cr, Settings.System.SCREEN_LOCK_SCREENOFF_DELAY, 0));

                if (DEBUG)
                    Log.d(TAG, "Lock screen timeout delay is " + String.valueOf(timeoutDelay)
                            + "ms");

                // if there is a delay, turn on the screen lock after the delay
                // expires
                // otherwise turn it on now
                if (timeoutDelay > 0) {
                    delayedScreenLockOn(timeoutDelay);
                } else {
                    doKeyguard();
                }

            } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_PROX_SENSOR) {
                // Do not enable the keyguard if the prox sensor forced the screen off.
            } else {
@@ -343,6 +353,26 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
        }
    }

    /**
     * Handles setting an alarm to enable the screen lock after a delay
     */
    private void delayedScreenLockOn(int delay) {
        final ContentResolver cr = mContext.getContentResolver();

        mShowLockIcon = (Settings.System.getInt(cr, "show_status_bar_lock", 0) == 1);
        // set an alarm to enable the screen lock a little bit later
        // (i.e, give the user a chance to turn the screen back on
        // within a certain window without having to unlock the screen)
        long when = SystemClock.elapsedRealtime() + delay;
        Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
        intent.putExtra("seq", mDelayedShowingSequence);
        PendingIntent sender = PendingIntent.getBroadcast(mContext, 0, intent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
        if (DEBUG)
            Log.d(TAG, "setting alarm to turn off keyguard, seq = " + mDelayedShowingSequence);
    }

    /**
     * Let's us know the screen was turned on.
     */