From 8d5a6e7ce3c74fb4cebc0ac388e5fcf92e04cecf Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Wed, 2 Nov 2016 21:57:33 -0700 Subject: [PATCH 1/2] UI Keyguard fixes - Streamline the various keyguardDone paths. The keyguard will be dismissed if and only if both the hide animation has run and the Keyguard is ready for dismissal. This fixes a bug in which the hide animation was not run. - When we get an external dismiss call, make sure to collapse the panel as well. - When we execute an action and Keyguard is occluded, we execute if after the Keyguard is gone so there are no weird transition because Keyguard might get unoccluded. Test: Manual for the above flows. Bug: 30961403 Bug: 27422134 Change-Id: I43decfeec270c4ed628bd9479109150c57201dae --- .../keyguard/KeyguardViewMediator.java | 43 ++++++++++++------- .../statusbar/phone/PhoneStatusBar.java | 18 +++++--- .../phone/StatusBarKeyguardViewManager.java | 12 +++--- 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index 9ae341a90cb1f..f8c50f6291b8d 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -285,6 +285,7 @@ public class KeyguardViewMediator extends SystemUI { private LockPatternUtils mLockPatternUtils; private boolean mKeyguardDonePending = false; private boolean mHideAnimationRun = false; + private boolean mHideAnimationRunning = false; private SoundPool mLockSounds; private int mLockSoundId; @@ -515,9 +516,7 @@ public class KeyguardViewMediator extends SystemUI { return; } - if (!mKeyguardDonePending) { - KeyguardViewMediator.this.handleKeyguardDone(true /* authenticated */); - } + tryKeyguardDone(true); if (strongAuth) { mUpdateMonitor.reportSuccessfulStrongAuthUnlockAttempt(); } @@ -545,7 +544,8 @@ public class KeyguardViewMediator extends SystemUI { mKeyguardDonePending = true; mHideAnimationRun = true; - mStatusBarKeyguardViewManager.startPreHideAnimation(null /* finishRunnable */); + mHideAnimationRunning = true; + mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable); mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT, KEYGUARD_DONE_PENDING_TIMEOUT_MS); if (strongAuth) { @@ -565,9 +565,11 @@ public class KeyguardViewMediator extends SystemUI { public void readyForKeyguardDone() { Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#readyForKeyguardDone"); if (mKeyguardDonePending) { + mKeyguardDonePending = false; + // Somebody has called keyguardDonePending before, which means that we are // authenticated - KeyguardViewMediator.this.handleKeyguardDone(true /* authenticated */); + tryKeyguardDone(true); } Trace.endSection(); } @@ -1257,7 +1259,7 @@ public class KeyguardViewMediator extends SystemUI { */ public void handleDismiss(boolean allowWhileOccluded) { if (mShowing && (allowWhileOccluded || !mOccluded)) { - mStatusBarKeyguardViewManager.dismiss(); + mStatusBarKeyguardViewManager.dismissAndCollapse(); } } @@ -1493,6 +1495,16 @@ public class KeyguardViewMediator extends SystemUI { } }; + private void tryKeyguardDone(boolean authenticated) { + if (!mKeyguardDonePending && mHideAnimationRun && !mHideAnimationRunning) { + handleKeyguardDone(authenticated); + } else if (!mHideAnimationRun) { + mHideAnimationRun = true; + mHideAnimationRunning = true; + mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable); + } + } + /** * @see #keyguardDone * @see #KEYGUARD_DONE @@ -1679,6 +1691,11 @@ public class KeyguardViewMediator extends SystemUI { } }; + private final Runnable mHideAnimationFinishedRunnable = () -> { + mHideAnimationRunning = false; + tryKeyguardDone(true); + }; + /** * Handle message sent by {@link #hideLocked()} * @see #HIDE @@ -1697,16 +1714,10 @@ public class KeyguardViewMediator extends SystemUI { return; } mHiding = true; - if (mShowing && !mOccluded) { - if (!mHideAnimationRun) { - mStatusBarKeyguardViewManager.startPreHideAnimation(mKeyguardGoingAwayRunnable); - } else { - mKeyguardGoingAwayRunnable.run(); - } - } else { - // Don't try to rely on WindowManager - if Keyguard wasn't showing, window - // manager won't start the exit animation. + if (mShowing && !mOccluded) { + mKeyguardGoingAwayRunnable.run(); + } else { handleStartKeyguardExitAnimation( SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(), mHideAnimation.getDuration()); @@ -1806,7 +1817,7 @@ public class KeyguardViewMediator extends SystemUI { synchronized (KeyguardViewMediator.this) { if (DEBUG) Log.d(TAG, "handleVerifyUnlock"); setShowingLocked(true); - mStatusBarKeyguardViewManager.verifyUnlock(); + mStatusBarKeyguardViewManager.dismissAndCollapse(); } Trace.endSection(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 669a5125c66e4..a121245b99fc1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -3552,8 +3552,14 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, AsyncTask.execute(runnable); } if (dismissShade) { - animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, true /* force */, - true /* delayed*/); + if (mExpandedVisible) { + animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, true /* force */, + true /* delayed*/); + } else { + + // Do it after DismissAction has been processed to conserve the needed ordering. + mHandler.post(this::runPostCollapseRunnables); + } } return deferred; }, cancelAction, afterKeyguardGone); @@ -3631,12 +3637,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, dismissKeyguardThenExecute(action, null /* cancelRunnable */, afterKeyguardGone); } - public void dismissKeyguard() { - mStatusBarKeyguardViewManager.dismiss(); - } - private void dismissKeyguardThenExecute(OnDismissAction action, Runnable cancelAction, boolean afterKeyguardGone) { + afterKeyguardGone |= mStatusBarKeyguardViewManager.isShowing() + && mStatusBarKeyguardViewManager.isOccluded(); if (mStatusBarKeyguardViewManager.isShowing()) { mStatusBarKeyguardViewManager.dismissWithAction(action, cancelAction, afterKeyguardGone); @@ -4249,7 +4253,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, } }, delay + StackStateAnimator.ANIMATION_DURATION_GO_TO_FULL_SHADE); } - } else { + } else if (!mNotificationPanel.isCollapsing()) { instantCollapseNotificationPanel(); } updateKeyguardState(staying, false /* fromShadeLocked */); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java index f5c5e56359a7d..69decd72c03aa 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java @@ -155,8 +155,8 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb if (!afterKeyguardGone) { mBouncer.showWithDismissAction(r, cancelAction); } else { - mBouncer.show(false /* resetSecuritySelection */); mAfterKeyguardGoneAction = r; + mBouncer.show(false /* resetSecuritySelection */); } } updateStates(); @@ -235,10 +235,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb mDeviceWillWakeUp = !mDeviceInteractive; } - public void verifyUnlock() { - dismiss(); - } - public void setNeedsInput(boolean needsInput) { mStatusBarWindowManager.setKeyguardNeedsInput(needsInput); } @@ -333,6 +329,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb } }); } else { + executeAfterKeyguardGoneAction(); if (mFingerprintUnlockController.getMode() == MODE_WAKE_AND_UNLOCK_PULSING) { mFingerprintUnlockController.startKeyguardFadingAway(); mPhoneStatusBar.setKeyguardFadingAway(startTime, 0, 240); @@ -372,7 +369,6 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb mStatusBarWindowManager.setKeyguardShowing(false); mBouncer.hide(true /* destroyView */); mViewMediatorCallback.keyguardGone(); - executeAfterKeyguardGoneAction(); updateStates(); } } @@ -423,6 +419,10 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb /** * Dismisses the keyguard by going to the next screen or making it gone. */ + public void dismissAndCollapse() { + mPhoneStatusBar.executeRunnableDismissingKeyguard(null, null, true, false, true); + } + public void dismiss() { showBouncer(); } From e8f321e7495e2c9e61e7dea61c0ccc543768c80f Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Mon, 7 Nov 2016 16:48:31 -0800 Subject: [PATCH 2/2] Update callbacks when initializing to initial state This fixes a bug where activity manager was not informed about the lockscreen state if Keyguard was disabled and SystemUI crashed, so we just displayed a black screen. Test: - Set no lockscreen - Crash SystemUI Change-Id: I93b8ed74dd12af6903ffdb05b59c78f2f12febb4 --- .../systemui/keyguard/KeyguardViewMediator.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index f8c50f6291b8d..8f1a943d98ff0 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -645,9 +645,7 @@ public class KeyguardViewMediator extends SystemUI { // Assume keyguard is showing (unless it's disabled) until we know for sure... setShowingLocked(!shouldWaitForProvisioning() && !mLockPatternUtils.isLockScreenDisabled( - KeyguardUpdateMonitor.getCurrentUser())); - updateInputRestrictedLocked(); - mTrustManager.reportKeyguardShowingChanged(); + KeyguardUpdateMonitor.getCurrentUser()), true /* forceCallbacks */); mStatusBarKeyguardViewManager = SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext, @@ -1980,7 +1978,11 @@ public class KeyguardViewMediator extends SystemUI { } private void setShowingLocked(boolean showing) { - if (showing != mShowing) { + setShowingLocked(showing, false /* forceCallbacks */); + } + + private void setShowingLocked(boolean showing, boolean forceCallbacks) { + if (showing != mShowing || forceCallbacks) { mShowing = showing; int size = mKeyguardStateCallbacks.size(); for (int i = size - 1; i >= 0; i--) {