Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Jorim Jaggi | 786afcb | 2014-09-25 02:41:29 +0200 | [diff] [blame] | 19 | import android.content.ComponentCallbacks2; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.os.Bundle; |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 22 | import android.os.SystemClock; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 23 | import android.os.Trace; |
Jorim Jaggi | df99351 | 2014-05-13 23:06:35 +0200 | [diff] [blame] | 24 | import android.view.KeyEvent; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 25 | import android.view.View; |
| 26 | import android.view.ViewGroup; |
Jorim Jaggi | 786afcb | 2014-09-25 02:41:29 +0200 | [diff] [blame] | 27 | import android.view.WindowManagerGlobal; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 28 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 29 | import com.android.internal.widget.LockPatternUtils; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 30 | import com.android.keyguard.KeyguardUpdateMonitor; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 31 | import com.android.keyguard.ViewMediatorCallback; |
Jim Miller | 25d7e51 | 2015-03-03 17:12:09 -0800 | [diff] [blame] | 32 | import com.android.systemui.statusbar.CommandQueue; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 33 | |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 34 | import static com.android.keyguard.KeyguardHostView.OnDismissAction; |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 35 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 36 | /** |
| 37 | * Manages creating, showing, hiding and resetting the keyguard within the status bar. Calls back |
| 38 | * via {@link ViewMediatorCallback} to poke the wake lock and report that the keyguard is done, |
| 39 | * which is in turn, reported to this class by the current |
| 40 | * {@link com.android.keyguard.KeyguardViewBase}. |
| 41 | */ |
| 42 | public class StatusBarKeyguardViewManager { |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 43 | |
| 44 | // When hiding the Keyguard with timing supplied from WindowManager, better be early than late. |
| 45 | private static final long HIDE_TIMING_CORRECTION_MS = -3 * 16; |
| 46 | |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 47 | // Delay for showing the navigation bar when the bouncer appears. This should be kept in sync |
| 48 | // with the appear animations of the PIN/pattern/password views. |
| 49 | private static final long NAV_BAR_SHOW_DELAY_BOUNCER = 320; |
| 50 | |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame^] | 51 | private static final long WAKE_AND_UNLOCK_SCRIM_FADEOUT_DURATION_MS = 200; |
| 52 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 53 | private static String TAG = "StatusBarKeyguardViewManager"; |
| 54 | |
| 55 | private final Context mContext; |
| 56 | |
| 57 | private LockPatternUtils mLockPatternUtils; |
| 58 | private ViewMediatorCallback mViewMediatorCallback; |
| 59 | private PhoneStatusBar mPhoneStatusBar; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 60 | private ScrimController mScrimController; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 61 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 62 | private ViewGroup mContainer; |
| 63 | private StatusBarWindowManager mStatusBarWindowManager; |
| 64 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 65 | private boolean mDeviceInteractive = false; |
| 66 | private boolean mScreenTurnedOn; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 67 | private KeyguardBouncer mBouncer; |
| 68 | private boolean mShowing; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 69 | private boolean mOccluded; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 70 | |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 71 | private boolean mFirstUpdate = true; |
| 72 | private boolean mLastShowing; |
| 73 | private boolean mLastOccluded; |
| 74 | private boolean mLastBouncerShowing; |
| 75 | private boolean mLastBouncerDismissible; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 76 | private boolean mLastDeferScrimFadeOut; |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 77 | private OnDismissAction mAfterKeyguardGoneAction; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 78 | private boolean mDeviceWillWakeUp; |
| 79 | private boolean mWakeAndUnlocking; |
| 80 | private boolean mDeferScrimFadeOut; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 81 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 82 | public StatusBarKeyguardViewManager(Context context, ViewMediatorCallback callback, |
| 83 | LockPatternUtils lockPatternUtils) { |
| 84 | mContext = context; |
| 85 | mViewMediatorCallback = callback; |
| 86 | mLockPatternUtils = lockPatternUtils; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | public void registerStatusBar(PhoneStatusBar phoneStatusBar, |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 90 | ViewGroup container, StatusBarWindowManager statusBarWindowManager, |
| 91 | ScrimController scrimController) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 92 | mPhoneStatusBar = phoneStatusBar; |
| 93 | mContainer = container; |
| 94 | mStatusBarWindowManager = statusBarWindowManager; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 95 | mScrimController = scrimController; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 96 | mBouncer = new KeyguardBouncer(mContext, mViewMediatorCallback, mLockPatternUtils, |
| 97 | mStatusBarWindowManager, container); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Show the keyguard. Will handle creating and attaching to the view manager |
| 102 | * lazily. |
| 103 | */ |
| 104 | public void show(Bundle options) { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 105 | mShowing = true; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 106 | mStatusBarWindowManager.setKeyguardShowing(true); |
Selim Cinek | edd32b8 | 2015-06-23 22:05:58 -0400 | [diff] [blame] | 107 | mScrimController.abortKeyguardFadingOut(); |
Jorim Jaggi | 43bdbbd | 2014-05-09 16:05:53 +0200 | [diff] [blame] | 108 | reset(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 109 | } |
| 110 | |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 111 | /** |
| 112 | * Shows the notification keyguard or the bouncer depending on |
| 113 | * {@link KeyguardBouncer#needsFullscreenBouncer()}. |
| 114 | */ |
| 115 | private void showBouncerOrKeyguard() { |
| 116 | if (mBouncer.needsFullscreenBouncer()) { |
| 117 | |
| 118 | // The keyguard might be showing (already). So we need to hide it. |
| 119 | mPhoneStatusBar.hideKeyguard(); |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 120 | mBouncer.show(true /* resetSecuritySelection */); |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 121 | } else { |
| 122 | mPhoneStatusBar.showKeyguard(); |
Jorim Jaggi | a0be6d5 | 2014-05-26 03:01:13 +0200 | [diff] [blame] | 123 | mBouncer.hide(false /* destroyView */); |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 124 | mBouncer.prepare(); |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 128 | private void showBouncer() { |
Adrian Roos | 0002a45 | 2014-07-03 13:46:07 +0200 | [diff] [blame] | 129 | if (mShowing) { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 130 | mBouncer.show(false /* resetSecuritySelection */); |
Dan Sandler | 3806c77 | 2014-05-08 14:52:10 -0400 | [diff] [blame] | 131 | } |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 132 | updateStates(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 135 | public void dismissWithAction(OnDismissAction r, Runnable cancelAction, |
| 136 | boolean afterKeyguardGone) { |
Adrian Roos | 0002a45 | 2014-07-03 13:46:07 +0200 | [diff] [blame] | 137 | if (mShowing) { |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 138 | if (!afterKeyguardGone) { |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 139 | mBouncer.showWithDismissAction(r, cancelAction); |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 140 | } else { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 141 | mBouncer.show(false /* resetSecuritySelection */); |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 142 | mAfterKeyguardGoneAction = r; |
| 143 | } |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 144 | } |
| 145 | updateStates(); |
| 146 | } |
| 147 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 148 | /** |
| 149 | * Reset the state of the view. |
| 150 | */ |
| 151 | public void reset() { |
Jorim Jaggi | 43bdbbd | 2014-05-09 16:05:53 +0200 | [diff] [blame] | 152 | if (mShowing) { |
| 153 | if (mOccluded) { |
| 154 | mPhoneStatusBar.hideKeyguard(); |
Adrian Roos | d322f1a | 2015-04-23 15:19:45 -0700 | [diff] [blame] | 155 | mPhoneStatusBar.stopWaitingForKeyguardExit(); |
Jorim Jaggi | a0be6d5 | 2014-05-26 03:01:13 +0200 | [diff] [blame] | 156 | mBouncer.hide(false /* destroyView */); |
Jorim Jaggi | 43bdbbd | 2014-05-09 16:05:53 +0200 | [diff] [blame] | 157 | } else { |
| 158 | showBouncerOrKeyguard(); |
| 159 | } |
Selim Cinek | 1fcafc4 | 2015-07-20 14:39:25 -0700 | [diff] [blame] | 160 | KeyguardUpdateMonitor.getInstance(mContext).sendKeyguardReset(); |
Jorim Jaggi | 43bdbbd | 2014-05-09 16:05:53 +0200 | [diff] [blame] | 161 | updateStates(); |
Dan Sandler | 3806c77 | 2014-05-08 14:52:10 -0400 | [diff] [blame] | 162 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 165 | public void onFinishedGoingToSleep() { |
| 166 | mDeviceInteractive = false; |
Jorim Jaggi | 50ff3af | 2015-08-12 18:35:42 -0700 | [diff] [blame] | 167 | mPhoneStatusBar.onFinishedGoingToSleep(); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 168 | mBouncer.onScreenTurnedOff(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 169 | } |
| 170 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 171 | public void onStartedWakingUp() { |
| 172 | mDeviceInteractive = true; |
| 173 | mDeviceWillWakeUp = false; |
Jorim Jaggi | 50ff3af | 2015-08-12 18:35:42 -0700 | [diff] [blame] | 174 | mPhoneStatusBar.onStartedWakingUp(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 175 | } |
| 176 | |
Jorim Jaggi | 9373911 | 2015-08-13 15:53:14 -0700 | [diff] [blame] | 177 | public void onScreenTurningOn() { |
| 178 | mPhoneStatusBar.onScreenTurningOn(); |
| 179 | } |
| 180 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 181 | public void onScreenTurnedOn() { |
| 182 | mScreenTurnedOn = true; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 183 | if (mDeferScrimFadeOut) { |
| 184 | mDeferScrimFadeOut = false; |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame^] | 185 | animateScrimControllerKeyguardFadingOut(0, WAKE_AND_UNLOCK_SCRIM_FADEOUT_DURATION_MS); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 186 | updateStates(); |
| 187 | } |
Jorim Jaggi | 50ff3af | 2015-08-12 18:35:42 -0700 | [diff] [blame] | 188 | mPhoneStatusBar.onScreenTurnedOn(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | public void onScreenTurnedOff() { |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame^] | 192 | mWakeAndUnlocking = false; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 193 | mScreenTurnedOn = false; |
| 194 | } |
| 195 | |
| 196 | public void notifyDeviceWakeUpRequested() { |
| 197 | mDeviceWillWakeUp = !mDeviceInteractive; |
Selim Cinek | f8fbc2a7 | 2015-06-22 16:42:07 -0400 | [diff] [blame] | 198 | } |
| 199 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 200 | public void verifyUnlock() { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 201 | dismiss(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | public void setNeedsInput(boolean needsInput) { |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 205 | mStatusBarWindowManager.setKeyguardNeedsInput(needsInput); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 206 | } |
| 207 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 208 | public void setOccluded(boolean occluded) { |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 209 | if (occluded && !mOccluded && mShowing) { |
| 210 | if (mPhoneStatusBar.isInLaunchTransition()) { |
| 211 | mOccluded = true; |
| 212 | mPhoneStatusBar.fadeKeyguardAfterLaunchTransition(null /* beforeFading */, |
| 213 | new Runnable() { |
| 214 | @Override |
| 215 | public void run() { |
Jorim Jaggi | 826730a | 2014-12-08 21:05:13 +0100 | [diff] [blame] | 216 | mStatusBarWindowManager.setKeyguardOccluded(mOccluded); |
Jorim Jaggi | fbc88e1 | 2014-08-14 23:38:15 +0200 | [diff] [blame] | 217 | reset(); |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 218 | } |
| 219 | }); |
| 220 | return; |
| 221 | } |
| 222 | } |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 223 | mOccluded = occluded; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 224 | mStatusBarWindowManager.setKeyguardOccluded(occluded); |
Dan Sandler | 3806c77 | 2014-05-08 14:52:10 -0400 | [diff] [blame] | 225 | reset(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 226 | } |
| 227 | |
Dan Sandler | 4b22bdf | 2014-06-05 00:58:02 -0400 | [diff] [blame] | 228 | public boolean isOccluded() { |
| 229 | return mOccluded; |
| 230 | } |
| 231 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 232 | /** |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 233 | * Starts the animation before we dismiss Keyguard, i.e. an disappearing animation on the |
| 234 | * security view of the bouncer. |
| 235 | * |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 236 | * @param finishRunnable the runnable to be run after the animation finished, or {@code null} if |
| 237 | * no action should be run |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 238 | */ |
| 239 | public void startPreHideAnimation(Runnable finishRunnable) { |
| 240 | if (mBouncer.isShowing()) { |
| 241 | mBouncer.startPreHideAnimation(finishRunnable); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 242 | } else if (finishRunnable != null) { |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 243 | finishRunnable.run(); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /** |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 248 | * Hides the keyguard view |
| 249 | */ |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 250 | public void hide(long startTime, final long fadeoutDuration) { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 251 | mShowing = false; |
Jorim Jaggi | 44cf919 | 2014-06-17 19:16:00 -0700 | [diff] [blame] | 252 | |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 253 | long uptimeMillis = SystemClock.uptimeMillis(); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 254 | long delay = Math.max(0, startTime + HIDE_TIMING_CORRECTION_MS - uptimeMillis); |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 255 | |
| 256 | if (mPhoneStatusBar.isInLaunchTransition() ) { |
| 257 | mPhoneStatusBar.fadeKeyguardAfterLaunchTransition(new Runnable() { |
| 258 | @Override |
| 259 | public void run() { |
| 260 | mStatusBarWindowManager.setKeyguardShowing(false); |
| 261 | mStatusBarWindowManager.setKeyguardFadingAway(true); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 262 | mBouncer.hide(true /* destroyView */); |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 263 | updateStates(); |
| 264 | mScrimController.animateKeyguardFadingOut( |
| 265 | PhoneStatusBar.FADE_KEYGUARD_START_DELAY, |
| 266 | PhoneStatusBar.FADE_KEYGUARD_DURATION, null); |
| 267 | } |
| 268 | }, new Runnable() { |
| 269 | @Override |
| 270 | public void run() { |
| 271 | mPhoneStatusBar.hideKeyguard(); |
| 272 | mStatusBarWindowManager.setKeyguardFadingAway(false); |
| 273 | mViewMediatorCallback.keyguardGone(); |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 274 | executeAfterKeyguardGoneAction(); |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 275 | } |
| 276 | }); |
| 277 | } else { |
Jorim Jaggi | 33ae80e | 2015-02-04 16:37:11 +0100 | [diff] [blame] | 278 | mPhoneStatusBar.setKeyguardFadingAway(startTime, delay, fadeoutDuration); |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 279 | boolean staying = mPhoneStatusBar.hideKeyguard(); |
| 280 | if (!staying) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 281 | mStatusBarWindowManager.setKeyguardFadingAway(true); |
| 282 | if (mWakeAndUnlocking && !mScreenTurnedOn) { |
| 283 | mDeferScrimFadeOut = true; |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame^] | 284 | } else if (mWakeAndUnlocking){ |
| 285 | |
| 286 | // Screen is already on, don't defer with fading out. |
| 287 | animateScrimControllerKeyguardFadingOut(0, |
| 288 | WAKE_AND_UNLOCK_SCRIM_FADEOUT_DURATION_MS); |
| 289 | } else { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 290 | animateScrimControllerKeyguardFadingOut(delay, fadeoutDuration); |
Jorim Jaggi | 740452e | 2015-07-09 12:13:59 -0700 | [diff] [blame] | 291 | } |
Jorim Jaggi | dbc3dce | 2014-08-01 01:16:36 +0200 | [diff] [blame] | 292 | } else { |
| 293 | mScrimController.animateGoingToFullShade(delay, fadeoutDuration); |
| 294 | mPhoneStatusBar.finishKeyguardFadingAway(); |
| 295 | } |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 296 | mStatusBarWindowManager.setKeyguardShowing(false); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 297 | mBouncer.hide(true /* destroyView */); |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 298 | mViewMediatorCallback.keyguardGone(); |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 299 | executeAfterKeyguardGoneAction(); |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 300 | updateStates(); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 301 | } |
Jorim Jaggi | 007f0e8 | 2015-08-14 13:56:01 -0700 | [diff] [blame^] | 302 | mWakeAndUnlocking = false; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 303 | } |
| 304 | |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 305 | private void animateScrimControllerKeyguardFadingOut(long delay, long duration) { |
| 306 | Trace.asyncTraceBegin(Trace.TRACE_TAG_VIEW, "Fading out", 0); |
| 307 | mScrimController.animateKeyguardFadingOut(delay, duration, new Runnable() { |
| 308 | @Override |
| 309 | public void run() { |
| 310 | mStatusBarWindowManager.setKeyguardFadingAway(false); |
| 311 | mPhoneStatusBar.finishKeyguardFadingAway(); |
| 312 | if (mPhoneStatusBar.getNavigationBarView() != null) { |
| 313 | mPhoneStatusBar.getNavigationBarView().setWakeAndUnlocking(false); |
| 314 | } |
| 315 | WindowManagerGlobal.getInstance().trimMemory( |
| 316 | ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN); |
| 317 | Trace.asyncTraceEnd(Trace.TRACE_TAG_VIEW, "Fading out", 0); |
| 318 | } |
| 319 | }); |
| 320 | } |
| 321 | |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 322 | private void executeAfterKeyguardGoneAction() { |
| 323 | if (mAfterKeyguardGoneAction != null) { |
| 324 | mAfterKeyguardGoneAction.onDismiss(); |
| 325 | mAfterKeyguardGoneAction = null; |
| 326 | } |
| 327 | } |
| 328 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 329 | /** |
| 330 | * Dismisses the keyguard by going to the next screen or making it gone. |
| 331 | */ |
| 332 | public void dismiss() { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 333 | if (mDeviceInteractive || mDeviceWillWakeUp) { |
Jorim Jaggi | 0bed7f2 | 2014-04-03 16:12:54 +0200 | [diff] [blame] | 334 | showBouncer(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
Christoph Studer | 2231c6e | 2014-12-19 12:40:13 +0100 | [diff] [blame] | 338 | /** |
| 339 | * WARNING: This method might cause Binder calls. |
| 340 | */ |
Jorim Jaggi | 1568250 | 2014-04-23 12:01:36 +0200 | [diff] [blame] | 341 | public boolean isSecure() { |
| 342 | return mBouncer.isSecure(); |
| 343 | } |
| 344 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 345 | /** |
| 346 | * @return Whether the keyguard is showing |
| 347 | */ |
| 348 | public boolean isShowing() { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 349 | return mShowing; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 350 | } |
Jorim Jaggi | e5c7a89 | 2014-04-10 20:37:32 +0200 | [diff] [blame] | 351 | |
| 352 | /** |
| 353 | * Notifies this manager that the back button has been pressed. |
| 354 | * |
| 355 | * @return whether the back press has been handled |
| 356 | */ |
| 357 | public boolean onBackPressed() { |
| 358 | if (mBouncer.isShowing()) { |
Jorim Jaggi | 6bad244 | 2014-08-26 15:16:57 +0200 | [diff] [blame] | 359 | reset(); |
Jorim Jaggi | e5c7a89 | 2014-04-10 20:37:32 +0200 | [diff] [blame] | 360 | return true; |
| 361 | } |
| 362 | return false; |
| 363 | } |
| 364 | |
Jim Miller | f41fc96 | 2014-06-18 16:33:51 -0700 | [diff] [blame] | 365 | public boolean isBouncerShowing() { |
| 366 | return mBouncer.isShowing(); |
| 367 | } |
| 368 | |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 369 | private long getNavBarShowDelay() { |
| 370 | if (mPhoneStatusBar.isKeyguardFadingAway()) { |
| 371 | return mPhoneStatusBar.getKeyguardFadingAwayDelay(); |
| 372 | } else { |
| 373 | |
| 374 | // Keyguard is not going away, thus we are showing the navigation bar because the |
| 375 | // bouncer is appearing. |
| 376 | return NAV_BAR_SHOW_DELAY_BOUNCER; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | private Runnable mMakeNavigationBarVisibleRunnable = new Runnable() { |
| 381 | @Override |
| 382 | public void run() { |
| 383 | mPhoneStatusBar.getNavigationBarView().setVisibility(View.VISIBLE); |
| 384 | } |
| 385 | }; |
| 386 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 387 | private void updateStates() { |
Jorim Jaggi | e5c7a89 | 2014-04-10 20:37:32 +0200 | [diff] [blame] | 388 | int vis = mContainer.getSystemUiVisibility(); |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 389 | boolean showing = mShowing; |
| 390 | boolean occluded = mOccluded; |
| 391 | boolean bouncerShowing = mBouncer.isShowing(); |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 392 | boolean bouncerDismissible = !mBouncer.isFullscreenBouncer(); |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 393 | boolean deferScrimFadeOut = mDeferScrimFadeOut; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 394 | |
| 395 | if ((bouncerDismissible || !showing) != (mLastBouncerDismissible || !mLastShowing) |
| 396 | || mFirstUpdate) { |
| 397 | if (bouncerDismissible || !showing) { |
| 398 | mContainer.setSystemUiVisibility(vis & ~View.STATUS_BAR_DISABLE_BACK); |
Jason Monk | 1e68fb3 | 2014-05-02 16:06:20 -0400 | [diff] [blame] | 399 | } else { |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 400 | mContainer.setSystemUiVisibility(vis | View.STATUS_BAR_DISABLE_BACK); |
Jason Monk | 1e68fb3 | 2014-05-02 16:06:20 -0400 | [diff] [blame] | 401 | } |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 402 | } |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 403 | |
| 404 | // Hide navigation bar on Keyguard but not on bouncer and also if we are deferring a scrim |
| 405 | // fade out, i.e. we are waiting for the screen to have turned on. |
| 406 | boolean navBarVisible = !deferScrimFadeOut && (!(showing && !occluded) || bouncerShowing); |
| 407 | boolean lastNavBarVisible = !mLastDeferScrimFadeOut && (!(mLastShowing && !mLastOccluded) |
| 408 | || mLastBouncerShowing); |
| 409 | if (navBarVisible != lastNavBarVisible || mFirstUpdate) { |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 410 | if (mPhoneStatusBar.getNavigationBarView() != null) { |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 411 | if (navBarVisible) { |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 412 | mContainer.postOnAnimationDelayed(mMakeNavigationBarVisibleRunnable, |
| 413 | getNavBarShowDelay()); |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 414 | } else { |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 415 | mContainer.removeCallbacks(mMakeNavigationBarVisibleRunnable); |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 416 | mPhoneStatusBar.getNavigationBarView().setVisibility(View.GONE); |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | if (bouncerShowing != mLastBouncerShowing || mFirstUpdate) { |
| 422 | mStatusBarWindowManager.setBouncerShowing(bouncerShowing); |
| 423 | mPhoneStatusBar.setBouncerShowing(bouncerShowing); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 424 | mScrimController.setBouncerShowing(bouncerShowing); |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
| 428 | if ((showing && !occluded) != (mLastShowing && !mLastOccluded) || mFirstUpdate) { |
| 429 | updateMonitor.sendKeyguardVisibilityChanged(showing && !occluded); |
| 430 | } |
| 431 | if (bouncerShowing != mLastBouncerShowing || mFirstUpdate) { |
| 432 | updateMonitor.sendKeyguardBouncerChanged(bouncerShowing); |
| 433 | } |
| 434 | |
| 435 | mFirstUpdate = false; |
| 436 | mLastShowing = showing; |
| 437 | mLastOccluded = occluded; |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 438 | mLastDeferScrimFadeOut = deferScrimFadeOut; |
Adrian Roos | b601162 | 2014-05-14 15:52:53 +0200 | [diff] [blame] | 439 | mLastBouncerShowing = bouncerShowing; |
| 440 | mLastBouncerDismissible = bouncerDismissible; |
Christoph Studer | 2231c6e | 2014-12-19 12:40:13 +0100 | [diff] [blame] | 441 | |
| 442 | mPhoneStatusBar.onKeyguardViewManagerStatesUpdated(); |
Jorim Jaggi | e5c7a89 | 2014-04-10 20:37:32 +0200 | [diff] [blame] | 443 | } |
Jorim Jaggi | 8c8bcc1 | 2014-04-16 21:36:51 +0200 | [diff] [blame] | 444 | |
| 445 | public boolean onMenuPressed() { |
| 446 | return mBouncer.onMenuPressed(); |
| 447 | } |
Jorim Jaggi | df99351 | 2014-05-13 23:06:35 +0200 | [diff] [blame] | 448 | |
| 449 | public boolean interceptMediaKey(KeyEvent event) { |
| 450 | return mBouncer.interceptMediaKey(event); |
| 451 | } |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 452 | |
| 453 | public void onActivityDrawn() { |
| 454 | if (mPhoneStatusBar.isCollapsing()) { |
| 455 | mPhoneStatusBar.addPostCollapseAction(new Runnable() { |
| 456 | @Override |
| 457 | public void run() { |
| 458 | mViewMediatorCallback.readyForKeyguardDone(); |
| 459 | } |
| 460 | }); |
| 461 | } else { |
| 462 | mViewMediatorCallback.readyForKeyguardDone(); |
| 463 | } |
| 464 | } |
Jorim Jaggi | 84a3e7a | 2014-08-13 17:58:58 +0200 | [diff] [blame] | 465 | |
| 466 | public boolean shouldDisableWindowAnimationsForUnlock() { |
| 467 | return mPhoneStatusBar.isInLaunchTransition(); |
| 468 | } |
| 469 | |
| 470 | public boolean isGoingToNotificationShade() { |
| 471 | return mPhoneStatusBar.isGoingToNotificationShade(); |
| 472 | } |
Adrian Roos | 31b844b | 2014-11-21 13:55:09 +0100 | [diff] [blame] | 473 | |
| 474 | public boolean isSecure(int userId) { |
| 475 | return mBouncer.isSecure() || mLockPatternUtils.isSecure(userId); |
| 476 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 477 | |
| 478 | public boolean isInputRestricted() { |
| 479 | return mViewMediatorCallback.isInputRestricted(); |
| 480 | } |
Jorim Jaggi | 33ae80e | 2015-02-04 16:37:11 +0100 | [diff] [blame] | 481 | |
| 482 | public void keyguardGoingAway() { |
| 483 | mPhoneStatusBar.keyguardGoingAway(); |
| 484 | } |
Jim Miller | 25d7e51 | 2015-03-03 17:12:09 -0800 | [diff] [blame] | 485 | |
Jorim Jaggi | f3b3bee | 2015-04-16 14:57:34 -0700 | [diff] [blame] | 486 | public void animateCollapsePanels(float speedUpFactor) { |
| 487 | mPhoneStatusBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE, true /* force */, |
| 488 | false /* delayed */, speedUpFactor); |
Jim Miller | 25d7e51 | 2015-03-03 17:12:09 -0800 | [diff] [blame] | 489 | } |
Jorim Jaggi | 5cc8659 | 2015-06-08 14:48:28 -0700 | [diff] [blame] | 490 | |
| 491 | /** |
| 492 | * Notifies that the user has authenticated by other means than using the bouncer, for example, |
| 493 | * fingerprint. |
| 494 | */ |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 495 | public void notifyKeyguardAuthenticated(boolean strongAuth) { |
| 496 | mBouncer.notifyKeyguardAuthenticated(strongAuth); |
Jorim Jaggi | 5cc8659 | 2015-06-08 14:48:28 -0700 | [diff] [blame] | 497 | } |
Jorim Jaggi | 0d210f6 | 2015-07-10 14:24:44 -0700 | [diff] [blame] | 498 | |
| 499 | public void setWakeAndUnlocking() { |
| 500 | mWakeAndUnlocking = true; |
| 501 | mScrimController.setWakeAndUnlocking(); |
| 502 | if (mPhoneStatusBar.getNavigationBarView() != null) { |
| 503 | mPhoneStatusBar.getNavigationBarView().setWakeAndUnlocking(true); |
| 504 | } |
| 505 | } |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 506 | |
| 507 | public void showBouncerMessage(String message, int color) { |
| 508 | mBouncer.showMessage(message, color); |
| 509 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 510 | } |