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

Commit bfd4e325 authored by Jeff Brown's avatar Jeff Brown Committed by The Android Automerger
Browse files

Lock the screen while dreaming after the appropriate timeout.

Bug: 7267187
Change-Id: I26ce3970a2d7cf446efe3e8c810fbbf3ddfcc47b
parent 7af8d1bd
Loading
Loading
Loading
Loading
+21 −0
Original line number Original line Diff line number Diff line
@@ -933,6 +933,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    Intent.EXTRA_DOCK_STATE_UNDOCKED);
                    Intent.EXTRA_DOCK_STATE_UNDOCKED);
        }
        }


        // register for dream-related broadcasts
        filter = new IntentFilter();
        filter.addAction(Intent.ACTION_DREAMING_STARTED);
        filter.addAction(Intent.ACTION_DREAMING_STOPPED);
        context.registerReceiver(mDreamReceiver, filter);

        // register for multiuser-relevant broadcasts
        // register for multiuser-relevant broadcasts
        filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
        filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
        context.registerReceiver(mMultiuserReceiver, filter);
        context.registerReceiver(mMultiuserReceiver, filter);
@@ -3567,6 +3573,21 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
        }
    };
    };


    BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
                if (mKeyguardMediator != null) {
                    mKeyguardMediator.onDreamingStarted();
                }
            } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
                if (mKeyguardMediator != null) {
                    mKeyguardMediator.onDreamingStopped();
                }
            }
        }
    };

    BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
    BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
+76 −45
Original line number Original line Diff line number Diff line
@@ -535,6 +535,16 @@ public class KeyguardViewMediator {
                resetStateLocked(null);
                resetStateLocked(null);
            } 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)) {
                doKeyguardLaterLocked();
            } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_PROX_SENSOR) {
                // Do not enable the keyguard if the prox sensor forced the screen off.
            } else {
                doKeyguardLocked();
            }
        }
    }

    private void doKeyguardLaterLocked() {
        // 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 bit later (i.e, give the user a chance
        // to enable it a little bit later (i.e, give the user a chance
@@ -579,12 +589,10 @@ public class KeyguardViewMediator {
            if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
            if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
                             + mDelayedShowingSequence);
                             + mDelayedShowingSequence);
        }
        }
            } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_PROX_SENSOR) {
                // Do not enable the keyguard if the prox sensor forced the screen off.
            } else {
                doKeyguardLocked();
            }
    }
    }

    private void cancelDoKeyguardLaterLocked() {
        mDelayedShowingSequence++;
    }
    }


    /**
    /**
@@ -593,7 +601,7 @@ public class KeyguardViewMediator {
    public void onScreenTurnedOn(KeyguardViewManager.ShowListener showListener) {
    public void onScreenTurnedOn(KeyguardViewManager.ShowListener showListener) {
        synchronized (this) {
        synchronized (this) {
            mScreenOn = true;
            mScreenOn = true;
            mDelayedShowingSequence++;
            cancelDoKeyguardLaterLocked();
            if (DEBUG) Log.d(TAG, "onScreenTurnedOn, seq = " + mDelayedShowingSequence);
            if (DEBUG) Log.d(TAG, "onScreenTurnedOn, seq = " + mDelayedShowingSequence);
            if (showListener != null) {
            if (showListener != null) {
                notifyScreenOnLocked(showListener);
                notifyScreenOnLocked(showListener);
@@ -612,6 +620,29 @@ public class KeyguardViewMediator {
        }
        }
    }
    }


    /**
     * A dream started.  We should lock after the usual screen-off lock timeout but only
     * if there is a secure lock pattern.
     */
    public void onDreamingStarted() {
        synchronized (this) {
            if (mScreenOn && mLockPatternUtils.isSecure()) {
                doKeyguardLaterLocked();
            }
        }
    }

    /**
     * A dream stopped.
     */
    public void onDreamingStopped() {
        synchronized (this) {
            if (mScreenOn) {
                cancelDoKeyguardLaterLocked();
            }
        }
    }

    /**
    /**
     * Same semantics as {@link WindowManagerPolicy#enableKeyguard}; provide
     * Same semantics as {@link WindowManagerPolicy#enableKeyguard}; provide
     * a way for external stuff to override normal keyguard behavior.  For instance
     * a way for external stuff to override normal keyguard behavior.  For instance