The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 17 | package com.android.keyguard; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 18 | |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 20 | import android.app.ActivityManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 21 | import android.content.Context; |
Jason Chang | 1e4a4bd | 2018-05-22 17:30:19 +0800 | [diff] [blame] | 22 | import android.content.res.ColorStateList; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 23 | import android.content.res.Resources; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 24 | import android.graphics.Canvas; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 25 | import android.media.AudioManager; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 26 | import android.os.SystemClock; |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 27 | import android.service.trust.TrustAgentService; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 28 | import android.telephony.TelephonyManager; |
Karl Rosaen | ad29734 | 2009-03-24 18:55:19 -0700 | [diff] [blame] | 29 | import android.util.AttributeSet; |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 30 | import android.util.Log; |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 31 | import android.view.KeyEvent; |
| 32 | import android.widget.FrameLayout; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 33 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 34 | import com.android.internal.widget.LockPatternUtils; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 35 | import com.android.keyguard.KeyguardSecurityContainer.SecurityCallback; |
| 36 | import com.android.keyguard.KeyguardSecurityModel.SecurityMode; |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 37 | import com.android.settingslib.Utils; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 38 | import com.android.systemui.plugins.ActivityStarter.OnDismissAction; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 39 | |
| 40 | import java.io.File; |
| 41 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 42 | /** |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 43 | * Base class for keyguard view. {@link #reset} is where you should |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 44 | * reset the state of your view. Use the {@link KeyguardViewCallback} via |
| 45 | * {@link #getCallback()} to send information back (such as poking the wake lock, |
| 46 | * or finishing the keyguard). |
| 47 | * |
| 48 | * Handles intercepting of media keys that still work when the keyguard is |
| 49 | * showing. |
| 50 | */ |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 51 | public class KeyguardHostView extends FrameLayout implements SecurityCallback { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 52 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 53 | private AudioManager mAudioManager; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 54 | private TelephonyManager mTelephonyManager = null; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 55 | protected ViewMediatorCallback mViewMediatorCallback; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 56 | protected LockPatternUtils mLockPatternUtils; |
| 57 | private OnDismissAction mDismissAction; |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 58 | private Runnable mCancelAction; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 59 | |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 60 | private final KeyguardUpdateMonitorCallback mUpdateCallback = |
| 61 | new KeyguardUpdateMonitorCallback() { |
| 62 | |
| 63 | @Override |
| 64 | public void onUserSwitchComplete(int userId) { |
| 65 | getSecurityContainer().showPrimarySecurityScreen(false /* turning off */); |
| 66 | } |
| 67 | |
| 68 | @Override |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 69 | public void onTrustGrantedWithFlags(int flags, int userId) { |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 70 | if (userId != KeyguardUpdateMonitor.getCurrentUser()) return; |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 71 | if (!isAttachedToWindow()) return; |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 72 | boolean bouncerVisible = isVisibleToUser(); |
| 73 | boolean initiatedByUser = |
| 74 | (flags & TrustAgentService.FLAG_GRANT_TRUST_INITIATED_BY_USER) != 0; |
| 75 | boolean dismissKeyguard = |
| 76 | (flags & TrustAgentService.FLAG_GRANT_TRUST_DISMISS_KEYGUARD) != 0; |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 77 | |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 78 | if (initiatedByUser || dismissKeyguard) { |
| 79 | if (mViewMediatorCallback.isScreenOn() && (bouncerVisible || dismissKeyguard)) { |
| 80 | if (!bouncerVisible) { |
| 81 | // The trust agent dismissed the keyguard without the user proving |
| 82 | // that they are present (by swiping up to show the bouncer). That's fine if |
| 83 | // the user proved presence via some other way to the trust agent. |
| 84 | Log.i(TAG, "TrustAgent dismissed Keyguard."); |
| 85 | } |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 86 | dismiss(false /* authenticated */, userId); |
Adrian Roos | 94e15a5 | 2015-04-16 12:23:18 -0700 | [diff] [blame] | 87 | } else { |
| 88 | mViewMediatorCallback.playTrustedSound(); |
| 89 | } |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | }; |
| 93 | |
Amith Yamasani | 2ef6f1b | 2011-12-01 14:01:30 -0800 | [diff] [blame] | 94 | // Whether the volume keys should be handled by keyguard. If true, then |
| 95 | // they will be handled here for specific media types such as music, otherwise |
| 96 | // the audio service will bring up the volume dialog. |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 97 | private static final boolean KEYGUARD_MANAGES_VOLUME = false; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 98 | public static final boolean DEBUG = KeyguardConstants.DEBUG; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 99 | private static final String TAG = "KeyguardViewBase"; |
| 100 | |
| 101 | private KeyguardSecurityContainer mSecurityContainer; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 102 | |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 103 | public KeyguardHostView(Context context) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 104 | this(context, null); |
| 105 | } |
| 106 | |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 107 | public KeyguardHostView(Context context, AttributeSet attrs) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 108 | super(context, attrs); |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 109 | KeyguardUpdateMonitor.getInstance(context).registerCallback(mUpdateCallback); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 112 | @Override |
| 113 | protected void dispatchDraw(Canvas canvas) { |
| 114 | super.dispatchDraw(canvas); |
| 115 | if (mViewMediatorCallback != null) { |
| 116 | mViewMediatorCallback.keyguardDoneDrawing(); |
| 117 | } |
| 118 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 119 | |
| 120 | /** |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 121 | * Sets an action to run when keyguard finishes. |
| 122 | * |
| 123 | * @param action |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 124 | */ |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 125 | public void setOnDismissAction(OnDismissAction action, Runnable cancelAction) { |
| 126 | if (mCancelAction != null) { |
| 127 | mCancelAction.run(); |
| 128 | mCancelAction = null; |
| 129 | } |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 130 | mDismissAction = action; |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 131 | mCancelAction = cancelAction; |
| 132 | } |
| 133 | |
Lucas Dupin | 6f0d71f | 2018-03-23 17:26:06 -0700 | [diff] [blame] | 134 | public boolean hasDismissActions() { |
| 135 | return mDismissAction != null || mCancelAction != null; |
| 136 | } |
| 137 | |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 138 | public void cancelDismissAction() { |
| 139 | setOnDismissAction(null, null); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | @Override |
| 143 | protected void onFinishInflate() { |
| 144 | mSecurityContainer = |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 145 | findViewById(R.id.keyguard_security_container); |
Jim Miller | 5e612cf | 2014-02-03 17:57:23 -0800 | [diff] [blame] | 146 | mLockPatternUtils = new LockPatternUtils(mContext); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 147 | mSecurityContainer.setLockPatternUtils(mLockPatternUtils); |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 148 | mSecurityContainer.setSecurityCallback(this); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 149 | mSecurityContainer.showPrimarySecurityScreen(false); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 150 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 151 | |
| 152 | /** |
Brian Colonna | 4284e9d | 2011-09-28 12:08:58 -0400 | [diff] [blame] | 153 | * Called when the view needs to be shown. |
| 154 | */ |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 155 | public void showPrimarySecurityScreen() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 156 | if (DEBUG) Log.d(TAG, "show()"); |
| 157 | mSecurityContainer.showPrimarySecurityScreen(false); |
| 158 | } |
| 159 | |
Lucas Dupin | 27321c4 | 2019-03-20 16:22:24 -0700 | [diff] [blame] | 160 | public KeyguardSecurityView getCurrentSecurityView() { |
| 161 | return mSecurityContainer != null ? mSecurityContainer.getCurrentSecurityView() : null; |
| 162 | } |
| 163 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 164 | /** |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 165 | * Show a string explaining why the security view needs to be solved. |
| 166 | * |
| 167 | * @param reason a flag indicating which string should be shown, see |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 168 | * {@link KeyguardSecurityView#PROMPT_REASON_NONE}, |
| 169 | * {@link KeyguardSecurityView#PROMPT_REASON_RESTART} and |
| 170 | * {@link KeyguardSecurityView#PROMPT_REASON_TIMEOUT}. |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 171 | */ |
| 172 | public void showPromptReason(int reason) { |
| 173 | mSecurityContainer.showPromptReason(reason); |
| 174 | } |
| 175 | |
Jason Chang | 1e4a4bd | 2018-05-22 17:30:19 +0800 | [diff] [blame] | 176 | public void showMessage(CharSequence message, ColorStateList colorState) { |
| 177 | mSecurityContainer.showMessage(message, colorState); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 180 | public void showErrorMessage(CharSequence message) { |
Jason Chang | 1e4a4bd | 2018-05-22 17:30:19 +0800 | [diff] [blame] | 181 | showMessage(message, Utils.getColorError(mContext)); |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 184 | /** |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 185 | * Dismisses the keyguard by going to the next screen or making it gone. |
| 186 | * @param targetUserId a user that needs to be the foreground user at the dismissal completion. |
| 187 | * @return True if the keyguard is done. |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 188 | */ |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 189 | public boolean dismiss(int targetUserId) { |
| 190 | return dismiss(false, targetUserId); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 193 | public boolean handleBackKey() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 194 | if (mSecurityContainer.getCurrentSecuritySelection() != SecurityMode.None) { |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 195 | mSecurityContainer.dismiss(false, KeyguardUpdateMonitor.getCurrentUser()); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 196 | return true; |
| 197 | } |
| 198 | return false; |
| 199 | } |
| 200 | |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 201 | protected KeyguardSecurityContainer getSecurityContainer() { |
| 202 | return mSecurityContainer; |
| 203 | } |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 204 | |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 205 | @Override |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 206 | public boolean dismiss(boolean authenticated, int targetUserId) { |
| 207 | return mSecurityContainer.showNextSecurityScreenOrFinish(authenticated, targetUserId); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Authentication has happened and it's time to dismiss keyguard. This function |
| 212 | * should clean up and inform KeyguardViewMediator. |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 213 | * |
| 214 | * @param strongAuth whether the user has authenticated with strong authentication like |
| 215 | * pattern, password or PIN but not by trust agents or fingerprint |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 216 | * @param targetUserId a user that needs to be the foreground user at the dismissal completion. |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 217 | */ |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 218 | @Override |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 219 | public void finish(boolean strongAuth, int targetUserId) { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 220 | // If there's a pending runnable because the user interacted with a widget |
| 221 | // and we're leaving keyguard, then run it. |
| 222 | boolean deferKeyguardDone = false; |
| 223 | if (mDismissAction != null) { |
| 224 | deferKeyguardDone = mDismissAction.onDismiss(); |
| 225 | mDismissAction = null; |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 226 | mCancelAction = null; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 227 | } |
| 228 | if (mViewMediatorCallback != null) { |
| 229 | if (deferKeyguardDone) { |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 230 | mViewMediatorCallback.keyguardDonePending(strongAuth, targetUserId); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 231 | } else { |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 232 | mViewMediatorCallback.keyguardDone(strongAuth, targetUserId); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 237 | @Override |
Andrew Lee | 72b46d4 | 2015-01-30 13:23:21 -0800 | [diff] [blame] | 238 | public void reset() { |
| 239 | mViewMediatorCallback.resetKeyguard(); |
| 240 | } |
| 241 | |
Aarthi Balachander | 0a427ef | 2018-07-13 15:00:58 -0700 | [diff] [blame] | 242 | @Override |
| 243 | public void onCancelClicked() { |
| 244 | mViewMediatorCallback.onCancelClicked(); |
| 245 | } |
| 246 | |
Lucas Dupin | 8018049 | 2018-05-08 17:06:06 -0700 | [diff] [blame] | 247 | public void resetSecurityContainer() { |
| 248 | mSecurityContainer.reset(); |
| 249 | } |
| 250 | |
Andrew Lee | 72b46d4 | 2015-01-30 13:23:21 -0800 | [diff] [blame] | 251 | @Override |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 252 | public void onSecurityModeChanged(SecurityMode securityMode, boolean needsInput) { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 253 | if (mViewMediatorCallback != null) { |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 254 | mViewMediatorCallback.setNeedsInput(needsInput); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
Phil Weaver | 7d847b0 | 2018-02-13 16:02:35 -0800 | [diff] [blame] | 258 | public CharSequence getAccessibilityTitleForCurrentMode() { |
| 259 | return mSecurityContainer.getTitle(); |
| 260 | } |
| 261 | |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 262 | public void userActivity() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 263 | if (mViewMediatorCallback != null) { |
| 264 | mViewMediatorCallback.userActivity(); |
| 265 | } |
| 266 | } |
| 267 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 268 | /** |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 269 | * Called when the Keyguard is not actively shown anymore on the screen. |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 270 | */ |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 271 | public void onPause() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 272 | if (DEBUG) Log.d(TAG, String.format("screen off, instance %s at %s", |
| 273 | Integer.toHexString(hashCode()), SystemClock.uptimeMillis())); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 274 | mSecurityContainer.showPrimarySecurityScreen(true); |
| 275 | mSecurityContainer.onPause(); |
| 276 | clearFocus(); |
| 277 | } |
| 278 | |
| 279 | /** |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 280 | * Called when the Keyguard is actively shown on the screen. |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 281 | */ |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 282 | public void onResume() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 283 | if (DEBUG) Log.d(TAG, "screen on, instance " + Integer.toHexString(hashCode())); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 284 | mSecurityContainer.onResume(KeyguardSecurityView.SCREEN_ON); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 285 | requestFocus(); |
| 286 | } |
Brian Colonna | 4284e9d | 2011-09-28 12:08:58 -0400 | [diff] [blame] | 287 | |
| 288 | /** |
Jorim Jaggi | c14f829 | 2014-05-27 02:25:45 +0200 | [diff] [blame] | 289 | * Starts the animation when the Keyguard gets shown. |
| 290 | */ |
| 291 | public void startAppearAnimation() { |
| 292 | mSecurityContainer.startAppearAnimation(); |
| 293 | } |
| 294 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 295 | public void startDisappearAnimation(Runnable finishRunnable) { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 296 | if (!mSecurityContainer.startDisappearAnimation(finishRunnable) && finishRunnable != null) { |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 297 | finishRunnable.run(); |
| 298 | } |
| 299 | } |
| 300 | |
Jorim Jaggi | c14f829 | 2014-05-27 02:25:45 +0200 | [diff] [blame] | 301 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 302 | * Called before this view is being removed. |
| 303 | */ |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 304 | public void cleanUp() { |
| 305 | getSecurityContainer().onPause(); |
| 306 | } |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 307 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 308 | @Override |
| 309 | public boolean dispatchKeyEvent(KeyEvent event) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 310 | if (interceptMediaKey(event)) { |
| 311 | return true; |
| 312 | } |
| 313 | return super.dispatchKeyEvent(event); |
| 314 | } |
| 315 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 316 | /** |
Marco Nelissen | 24d1056 | 2009-05-12 14:15:17 -0700 | [diff] [blame] | 317 | * Allows the media keys to work when the keyguard is showing. |
| 318 | * The media keys should be of no interest to the actual keyguard view(s), |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 319 | * so intercepting them here should not be of any harm. |
| 320 | * @param event The key event |
| 321 | * @return whether the event was consumed as a media key. |
| 322 | */ |
Jorim Jaggi | df99351 | 2014-05-13 23:06:35 +0200 | [diff] [blame] | 323 | public boolean interceptMediaKey(KeyEvent event) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 324 | final int keyCode = event.getKeyCode(); |
| 325 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 326 | switch (keyCode) { |
Marco Nelissen | a6face4 | 2010-10-25 10:21:59 -0700 | [diff] [blame] | 327 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 328 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
Andy Stadler | 8b89d69 | 2009-04-10 16:24:49 -0700 | [diff] [blame] | 329 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 330 | /* Suppress PLAY/PAUSE toggle when phone is ringing or |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 331 | * in-call to avoid music playback */ |
| 332 | if (mTelephonyManager == null) { |
| 333 | mTelephonyManager = (TelephonyManager) getContext().getSystemService( |
| 334 | Context.TELEPHONY_SERVICE); |
| 335 | } |
| 336 | if (mTelephonyManager != null && |
| 337 | mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE) { |
| 338 | return true; // suppress key event |
| 339 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 340 | case KeyEvent.KEYCODE_MUTE: |
| 341 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 342 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 343 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 344 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 345 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 346 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 347 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 348 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 349 | handleMediaKeyEvent(event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 350 | return true; |
| 351 | } |
| 352 | |
| 353 | case KeyEvent.KEYCODE_VOLUME_UP: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 354 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 355 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Amith Yamasani | 2ef6f1b | 2011-12-01 14:01:30 -0800 | [diff] [blame] | 356 | if (KEYGUARD_MANAGES_VOLUME) { |
| 357 | synchronized (this) { |
| 358 | if (mAudioManager == null) { |
| 359 | mAudioManager = (AudioManager) getContext().getSystemService( |
| 360 | Context.AUDIO_SERVICE); |
| 361 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 362 | } |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 363 | // Volume buttons should only function for music (local or remote). |
| 364 | // TODO: Actually handle MUTE. |
RoboErik | d3c8642 | 2014-06-16 14:00:48 -0700 | [diff] [blame] | 365 | mAudioManager.adjustSuggestedStreamVolume( |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 366 | keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 367 | ? AudioManager.ADJUST_RAISE |
RoboErik | d3c8642 | 2014-06-16 14:00:48 -0700 | [diff] [blame] | 368 | : AudioManager.ADJUST_LOWER /* direction */, |
| 369 | AudioManager.STREAM_MUSIC /* stream */, 0 /* flags */); |
Amith Yamasani | 2ef6f1b | 2011-12-01 14:01:30 -0800 | [diff] [blame] | 370 | // Don't execute default volume behavior |
| 371 | return true; |
| 372 | } else { |
| 373 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 374 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 378 | switch (keyCode) { |
| 379 | case KeyEvent.KEYCODE_MUTE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 380 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 381 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 382 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 383 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 384 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 385 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 386 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 387 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 388 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 389 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 390 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 391 | handleMediaKeyEvent(event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 392 | return true; |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | return false; |
| 397 | } |
| 398 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 399 | private void handleMediaKeyEvent(KeyEvent keyEvent) { |
RoboErik | d3c8642 | 2014-06-16 14:00:48 -0700 | [diff] [blame] | 400 | synchronized (this) { |
| 401 | if (mAudioManager == null) { |
| 402 | mAudioManager = (AudioManager) getContext().getSystemService( |
| 403 | Context.AUDIO_SERVICE); |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 404 | } |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 405 | } |
RoboErik | d3c8642 | 2014-06-16 14:00:48 -0700 | [diff] [blame] | 406 | mAudioManager.dispatchMediaKeyEvent(keyEvent); |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Joe Onorato | 4671ce5 | 2011-01-27 21:15:42 -0800 | [diff] [blame] | 409 | @Override |
| 410 | public void dispatchSystemUiVisibilityChanged(int visibility) { |
| 411 | super.dispatchSystemUiVisibilityChanged(visibility); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 412 | |
| 413 | if (!(mContext instanceof Activity)) { |
| 414 | setSystemUiVisibility(STATUS_BAR_DISABLE_BACK); |
| 415 | } |
Joe Onorato | 4671ce5 | 2011-01-27 21:15:42 -0800 | [diff] [blame] | 416 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 417 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 418 | /** |
| 419 | * In general, we enable unlocking the insecure keyguard with the menu key. However, there are |
| 420 | * some cases where we wish to disable it, notably when the menu button placement or technology |
| 421 | * is prone to false positives. |
| 422 | * |
| 423 | * @return true if the menu key should be enabled |
| 424 | */ |
| 425 | private static final String ENABLE_MENU_KEY_FILE = "/data/local/enable_menu_key"; |
Selim Cinek | 2854019 | 2016-02-19 17:25:08 -0800 | [diff] [blame] | 426 | public boolean shouldEnableMenuKey() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 427 | final Resources res = getResources(); |
| 428 | final boolean configDisabled = res.getBoolean(R.bool.config_disableMenuKeyInLockScreen); |
| 429 | final boolean isTestHarness = ActivityManager.isRunningInTestHarness(); |
| 430 | final boolean fileOverride = (new File(ENABLE_MENU_KEY_FILE)).exists(); |
| 431 | return !configDisabled || isTestHarness || fileOverride; |
| 432 | } |
| 433 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 434 | public void setViewMediatorCallback(ViewMediatorCallback viewMediatorCallback) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 435 | mViewMediatorCallback = viewMediatorCallback; |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 436 | // Update ViewMediator with the current input method requirements |
| 437 | mViewMediatorCallback.setNeedsInput(mSecurityContainer.needsInput()); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 438 | } |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 439 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 440 | public void setLockPatternUtils(LockPatternUtils utils) { |
Jim Miller | 5e612cf | 2014-02-03 17:57:23 -0800 | [diff] [blame] | 441 | mLockPatternUtils = utils; |
| 442 | mSecurityContainer.setLockPatternUtils(utils); |
| 443 | } |
| 444 | |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 445 | public SecurityMode getSecurityMode() { |
| 446 | return mSecurityContainer.getSecurityMode(); |
| 447 | } |
| 448 | |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 449 | public SecurityMode getCurrentSecurityMode() { |
| 450 | return mSecurityContainer.getCurrentSecurityMode(); |
| 451 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 452 | } |