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 | |
| 19 | import android.content.Context; |
| 20 | import android.os.Bundle; |
| 21 | import android.os.IBinder; |
| 22 | import android.os.RemoteException; |
| 23 | import android.util.Log; |
| 24 | import android.util.Slog; |
| 25 | import android.view.LayoutInflater; |
| 26 | import android.view.View; |
| 27 | import android.view.ViewGroup; |
| 28 | import android.view.ViewTreeObserver; |
| 29 | |
| 30 | import com.android.internal.policy.IKeyguardShowCallback; |
| 31 | import com.android.internal.widget.LockPatternUtils; |
Jorim Jaggi | 13b67a9 | 2014-03-28 23:23:44 +0100 | [diff] [blame] | 32 | import com.android.keyguard.KeyguardHostView; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 33 | import com.android.keyguard.KeyguardSimpleHostView; |
| 34 | import com.android.keyguard.R; |
| 35 | import com.android.keyguard.ViewMediatorCallback; |
| 36 | import com.android.systemui.keyguard.KeyguardViewMediator; |
| 37 | |
| 38 | /** |
| 39 | * Manages creating, showing, hiding and resetting the keyguard within the status bar. Calls back |
| 40 | * via {@link ViewMediatorCallback} to poke the wake lock and report that the keyguard is done, |
| 41 | * which is in turn, reported to this class by the current |
| 42 | * {@link com.android.keyguard.KeyguardViewBase}. |
| 43 | */ |
| 44 | public class StatusBarKeyguardViewManager { |
| 45 | private static String TAG = "StatusBarKeyguardViewManager"; |
| 46 | |
| 47 | private final Context mContext; |
| 48 | |
| 49 | private LockPatternUtils mLockPatternUtils; |
| 50 | private ViewMediatorCallback mViewMediatorCallback; |
| 51 | private PhoneStatusBar mPhoneStatusBar; |
| 52 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 53 | private ViewGroup mContainer; |
| 54 | private StatusBarWindowManager mStatusBarWindowManager; |
| 55 | |
| 56 | private boolean mScreenOn = false; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 57 | private KeyguardBouncer mBouncer; |
| 58 | private boolean mShowing; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 59 | private boolean mOccluded; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 60 | |
| 61 | public StatusBarKeyguardViewManager(Context context, ViewMediatorCallback callback, |
| 62 | LockPatternUtils lockPatternUtils) { |
| 63 | mContext = context; |
| 64 | mViewMediatorCallback = callback; |
| 65 | mLockPatternUtils = lockPatternUtils; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | public void registerStatusBar(PhoneStatusBar phoneStatusBar, |
| 69 | ViewGroup container, StatusBarWindowManager statusBarWindowManager) { |
| 70 | mPhoneStatusBar = phoneStatusBar; |
| 71 | mContainer = container; |
| 72 | mStatusBarWindowManager = statusBarWindowManager; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 73 | mBouncer = new KeyguardBouncer(mContext, mViewMediatorCallback, mLockPatternUtils, |
| 74 | mStatusBarWindowManager, container); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Show the keyguard. Will handle creating and attaching to the view manager |
| 79 | * lazily. |
| 80 | */ |
| 81 | public void show(Bundle options) { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 82 | mShowing = true; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 83 | mStatusBarWindowManager.setKeyguardShowing(true); |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 84 | showBouncerOrKeyguard(); |
Jorim Jaggi | e5c7a89 | 2014-04-10 20:37:32 +0200 | [diff] [blame] | 85 | updateBackButtonState(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 88 | /** |
| 89 | * Shows the notification keyguard or the bouncer depending on |
| 90 | * {@link KeyguardBouncer#needsFullscreenBouncer()}. |
| 91 | */ |
| 92 | private void showBouncerOrKeyguard() { |
| 93 | if (mBouncer.needsFullscreenBouncer()) { |
| 94 | |
| 95 | // The keyguard might be showing (already). So we need to hide it. |
| 96 | mPhoneStatusBar.hideKeyguard(); |
| 97 | mBouncer.show(); |
| 98 | } else { |
| 99 | mPhoneStatusBar.showKeyguard(); |
| 100 | mBouncer.hide(); |
| 101 | mBouncer.prepare(); |
| 102 | } |
| 103 | } |
| 104 | |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 105 | public void showBouncer() { |
John Spurlock | 2e50f28 | 2014-04-17 23:45:50 +0000 | [diff] [blame] | 106 | mBouncer.show(); |
| 107 | updateBackButtonState(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Reset the state of the view. |
| 112 | */ |
| 113 | public void reset() { |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 114 | showBouncerOrKeyguard(); |
Jorim Jaggi | e5c7a89 | 2014-04-10 20:37:32 +0200 | [diff] [blame] | 115 | updateBackButtonState(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | public void onScreenTurnedOff() { |
| 119 | mScreenOn = false; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 120 | mBouncer.onScreenTurnedOff(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | public void onScreenTurnedOn(final IKeyguardShowCallback callback) { |
| 124 | mScreenOn = true; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 125 | if (callback != null) { |
| 126 | callbackAfterDraw(callback); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | private void callbackAfterDraw(final IKeyguardShowCallback callback) { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 131 | mContainer.post(new Runnable() { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 132 | @Override |
| 133 | public void run() { |
| 134 | try { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 135 | callback.onShown(mContainer.getWindowToken()); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 136 | } catch (RemoteException e) { |
| 137 | Slog.w(TAG, "Exception calling onShown():", e); |
| 138 | } |
| 139 | } |
| 140 | }); |
| 141 | } |
| 142 | |
| 143 | public void verifyUnlock() { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 144 | dismiss(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | public void setNeedsInput(boolean needsInput) { |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 148 | mStatusBarWindowManager.setKeyguardNeedsInput(needsInput); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | public void updateUserActivityTimeout() { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 152 | mStatusBarWindowManager.setKeyguardUserActivityTimeout(mBouncer.getUserActivityTimeout()); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | public void setOccluded(boolean occluded) { |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 156 | mOccluded = occluded; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 157 | mStatusBarWindowManager.setKeyguardOccluded(occluded); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 158 | updateBackButtonState(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Hides the keyguard view |
| 163 | */ |
| 164 | public void hide() { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 165 | mShowing = false; |
| 166 | mPhoneStatusBar.hideKeyguard(); |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 167 | mStatusBarWindowManager.setKeyguardShowing(false); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 168 | mBouncer.hide(); |
| 169 | mViewMediatorCallback.keyguardGone(); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 170 | updateBackButtonState(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Dismisses the keyguard by going to the next screen or making it gone. |
| 175 | */ |
| 176 | public void dismiss() { |
| 177 | if (mScreenOn) { |
Jorim Jaggi | 0bed7f2 | 2014-04-03 16:12:54 +0200 | [diff] [blame] | 178 | showBouncer(); |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
Jorim Jaggi | 1568250 | 2014-04-23 12:01:36 +0200 | [diff] [blame] | 182 | public boolean isSecure() { |
| 183 | return mBouncer.isSecure(); |
| 184 | } |
| 185 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 186 | /** |
| 187 | * @return Whether the keyguard is showing |
| 188 | */ |
| 189 | public boolean isShowing() { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 190 | return mShowing; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 191 | } |
Jorim Jaggi | e5c7a89 | 2014-04-10 20:37:32 +0200 | [diff] [blame] | 192 | |
| 193 | /** |
| 194 | * Notifies this manager that the back button has been pressed. |
| 195 | * |
| 196 | * @return whether the back press has been handled |
| 197 | */ |
| 198 | public boolean onBackPressed() { |
| 199 | if (mBouncer.isShowing()) { |
| 200 | mBouncer.hide(); |
| 201 | mPhoneStatusBar.showKeyguard(); |
| 202 | updateBackButtonState(); |
| 203 | return true; |
| 204 | } |
| 205 | return false; |
| 206 | } |
| 207 | |
| 208 | private void updateBackButtonState() { |
| 209 | int vis = mContainer.getSystemUiVisibility(); |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 210 | boolean bouncerDismissable = mBouncer.isShowing() && !mBouncer.needsFullscreenBouncer(); |
| 211 | if (bouncerDismissable || !mShowing) { |
Jorim Jaggi | e5c7a89 | 2014-04-10 20:37:32 +0200 | [diff] [blame] | 212 | mContainer.setSystemUiVisibility(vis & ~View.STATUS_BAR_DISABLE_BACK); |
| 213 | } else { |
| 214 | mContainer.setSystemUiVisibility(vis | View.STATUS_BAR_DISABLE_BACK); |
| 215 | } |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 216 | if (!(mShowing && !mOccluded) || mBouncer.isShowing()) { |
| 217 | mPhoneStatusBar.getNavigationBarView().setVisibility(View.VISIBLE); |
| 218 | } else { |
| 219 | mPhoneStatusBar.getNavigationBarView().setVisibility(View.GONE); |
| 220 | } |
Jorim Jaggi | e5c7a89 | 2014-04-10 20:37:32 +0200 | [diff] [blame] | 221 | } |
Jorim Jaggi | 8c8bcc1 | 2014-04-16 21:36:51 +0200 | [diff] [blame] | 222 | |
| 223 | public boolean onMenuPressed() { |
| 224 | return mBouncer.onMenuPressed(); |
| 225 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 226 | } |