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