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