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; |
| 21 | import android.app.ActivityOptions; |
| 22 | import android.app.SearchManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 23 | import android.content.Context; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 24 | import android.content.Intent; |
| 25 | import android.content.res.Resources; |
| 26 | import android.graphics.Canvas; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 27 | import android.media.AudioManager; |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 28 | import android.media.IAudioService; |
Jim Miller | 5e612cf | 2014-02-03 17:57:23 -0800 | [diff] [blame] | 29 | import android.os.Bundle; |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 30 | import android.os.RemoteException; |
| 31 | import android.os.ServiceManager; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 32 | import android.os.SystemClock; |
| 33 | import android.os.UserHandle; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 34 | import android.telephony.TelephonyManager; |
Karl Rosaen | ad29734 | 2009-03-24 18:55:19 -0700 | [diff] [blame] | 35 | import android.util.AttributeSet; |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 36 | import android.util.Log; |
| 37 | import android.util.Slog; |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 38 | import android.view.KeyEvent; |
Jim Miller | 5e612cf | 2014-02-03 17:57:23 -0800 | [diff] [blame] | 39 | import android.view.MotionEvent; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 40 | import android.view.View; |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 41 | import android.widget.FrameLayout; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 42 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 43 | import com.android.internal.widget.LockPatternUtils; |
| 44 | import com.android.keyguard.KeyguardHostView.OnDismissAction; |
| 45 | import com.android.keyguard.KeyguardSecurityContainer.SecurityCallback; |
| 46 | import com.android.keyguard.KeyguardSecurityModel.SecurityMode; |
| 47 | |
| 48 | import java.io.File; |
| 49 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 50 | /** |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 51 | * 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] | 52 | * reset the state of your view. Use the {@link KeyguardViewCallback} via |
| 53 | * {@link #getCallback()} to send information back (such as poking the wake lock, |
| 54 | * or finishing the keyguard). |
| 55 | * |
| 56 | * Handles intercepting of media keys that still work when the keyguard is |
| 57 | * showing. |
| 58 | */ |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 59 | public abstract class KeyguardViewBase extends FrameLayout implements SecurityCallback { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 60 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 61 | private AudioManager mAudioManager; |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 62 | private TelephonyManager mTelephonyManager = null; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 63 | protected ViewMediatorCallback mViewMediatorCallback; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 64 | protected LockPatternUtils mLockPatternUtils; |
| 65 | private OnDismissAction mDismissAction; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 66 | |
Amith Yamasani | 2ef6f1b | 2011-12-01 14:01:30 -0800 | [diff] [blame] | 67 | // Whether the volume keys should be handled by keyguard. If true, then |
| 68 | // they will be handled here for specific media types such as music, otherwise |
| 69 | // the audio service will bring up the volume dialog. |
Amith Yamasani | 6243edd | 2011-12-05 19:58:48 -0800 | [diff] [blame] | 70 | private static final boolean KEYGUARD_MANAGES_VOLUME = true; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 71 | public static final boolean DEBUG = KeyguardConstants.DEBUG; |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 72 | private static final String TAG = "KeyguardViewBase"; |
| 73 | |
| 74 | private KeyguardSecurityContainer mSecurityContainer; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 75 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 76 | public KeyguardViewBase(Context context) { |
| 77 | this(context, null); |
| 78 | } |
| 79 | |
| 80 | public KeyguardViewBase(Context context, AttributeSet attrs) { |
| 81 | super(context, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 82 | } |
| 83 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 84 | @Override |
| 85 | protected void dispatchDraw(Canvas canvas) { |
| 86 | super.dispatchDraw(canvas); |
| 87 | if (mViewMediatorCallback != null) { |
| 88 | mViewMediatorCallback.keyguardDoneDrawing(); |
| 89 | } |
| 90 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 91 | |
| 92 | /** |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 93 | * Sets an action to run when keyguard finishes. |
| 94 | * |
| 95 | * @param action |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 96 | */ |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 97 | public void setOnDismissAction(OnDismissAction action) { |
| 98 | mDismissAction = action; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | protected void onFinishInflate() { |
| 103 | mSecurityContainer = |
| 104 | (KeyguardSecurityContainer) findViewById(R.id.keyguard_security_container); |
Jim Miller | 5e612cf | 2014-02-03 17:57:23 -0800 | [diff] [blame] | 105 | mLockPatternUtils = new LockPatternUtils(mContext); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 106 | mSecurityContainer.setLockPatternUtils(mLockPatternUtils); |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 107 | mSecurityContainer.setSecurityCallback(this); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 108 | mSecurityContainer.showPrimarySecurityScreen(false); |
| 109 | // mSecurityContainer.updateSecurityViews(false /* not bouncing */); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 110 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 111 | |
| 112 | /** |
Brian Colonna | 4284e9d | 2011-09-28 12:08:58 -0400 | [diff] [blame] | 113 | * Called when the view needs to be shown. |
| 114 | */ |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 115 | public void show() { |
| 116 | if (DEBUG) Log.d(TAG, "show()"); |
| 117 | mSecurityContainer.showPrimarySecurityScreen(false); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * 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] | 122 | * |
| 123 | * @return True if the keyguard is done. |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 124 | */ |
Jorim Jaggi | 0bed7f2 | 2014-04-03 16:12:54 +0200 | [diff] [blame] | 125 | public boolean dismiss() { |
| 126 | return dismiss(false); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 127 | } |
| 128 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 129 | protected void showBouncer(boolean show) { |
| 130 | CharSequence what = getContext().getResources().getText( |
| 131 | show ? R.string.keyguard_accessibility_show_bouncer |
| 132 | : R.string.keyguard_accessibility_hide_bouncer); |
| 133 | announceForAccessibility(what); |
| 134 | announceCurrentSecurityMethod(); |
| 135 | } |
| 136 | |
| 137 | public boolean handleBackKey() { |
| 138 | if (mSecurityContainer.getCurrentSecuritySelection() == SecurityMode.Account) { |
Jorim Jaggi | e5c7a89 | 2014-04-10 20:37:32 +0200 | [diff] [blame] | 139 | // go back to primary screen |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 140 | mSecurityContainer.showPrimarySecurityScreen(false /*turningOff*/); |
| 141 | return true; |
| 142 | } |
| 143 | if (mSecurityContainer.getCurrentSecuritySelection() != SecurityMode.None) { |
| 144 | mSecurityContainer.dismiss(false); |
| 145 | return true; |
| 146 | } |
| 147 | return false; |
| 148 | } |
| 149 | |
| 150 | protected void announceCurrentSecurityMethod() { |
| 151 | mSecurityContainer.announceCurrentSecurityMethod(); |
| 152 | } |
| 153 | |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 154 | protected KeyguardSecurityContainer getSecurityContainer() { |
| 155 | return mSecurityContainer; |
| 156 | } |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 157 | |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 158 | /** |
| 159 | * Extend display timeout |
| 160 | * @param timeout duration to delay timeout, in ms. |
| 161 | */ |
| 162 | @Override |
| 163 | public void userActivity(long timeout) { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 164 | if (mViewMediatorCallback != null) { |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 165 | mViewMediatorCallback.userActivity(timeout); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 169 | @Override |
| 170 | public boolean dismiss(boolean authenticated) { |
| 171 | return mSecurityContainer.showNextSecurityScreenOrFinish(authenticated); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Authentication has happened and it's time to dismiss keyguard. This function |
| 176 | * should clean up and inform KeyguardViewMediator. |
| 177 | */ |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 178 | @Override |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 179 | public void finish() { |
| 180 | // If the alternate unlock was suppressed, it can now be safely |
| 181 | // enabled because the user has left keyguard. |
| 182 | KeyguardUpdateMonitor.getInstance(mContext).setAlternateUnlockEnabled(true); |
| 183 | |
| 184 | // If there's a pending runnable because the user interacted with a widget |
| 185 | // and we're leaving keyguard, then run it. |
| 186 | boolean deferKeyguardDone = false; |
| 187 | if (mDismissAction != null) { |
| 188 | deferKeyguardDone = mDismissAction.onDismiss(); |
| 189 | mDismissAction = null; |
| 190 | } |
| 191 | if (mViewMediatorCallback != null) { |
| 192 | if (deferKeyguardDone) { |
| 193 | mViewMediatorCallback.keyguardDonePending(); |
| 194 | } else { |
| 195 | mViewMediatorCallback.keyguardDone(true); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 200 | @Override |
| 201 | public void onSecurityModeChanged(SecurityMode securityMode, boolean needsInput) { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 202 | if (mViewMediatorCallback != null) { |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 203 | mViewMediatorCallback.setNeedsInput(needsInput); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 207 | public void userActivity() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 208 | if (mViewMediatorCallback != null) { |
| 209 | mViewMediatorCallback.userActivity(); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | protected void onUserActivityTimeoutChanged() { |
| 214 | if (mViewMediatorCallback != null) { |
| 215 | mViewMediatorCallback.onUserActivityTimeoutChanged(); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | /** |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 220 | * Called when the Keyguard is not actively shown anymore on the screen. |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 221 | */ |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 222 | public void onPause() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 223 | if (DEBUG) Log.d(TAG, String.format("screen off, instance %s at %s", |
| 224 | Integer.toHexString(hashCode()), SystemClock.uptimeMillis())); |
| 225 | // Once the screen turns off, we no longer consider this to be first boot and we want the |
| 226 | // biometric unlock to start next time keyguard is shown. |
| 227 | KeyguardUpdateMonitor.getInstance(mContext).setAlternateUnlockEnabled(true); |
| 228 | mSecurityContainer.showPrimarySecurityScreen(true); |
| 229 | mSecurityContainer.onPause(); |
| 230 | clearFocus(); |
| 231 | } |
| 232 | |
| 233 | /** |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 234 | * Called when the Keyguard is actively shown on the screen. |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 235 | */ |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 236 | public void onResume() { |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 237 | if (DEBUG) Log.d(TAG, "screen on, instance " + Integer.toHexString(hashCode())); |
| 238 | mSecurityContainer.showPrimarySecurityScreen(false); |
| 239 | mSecurityContainer.onResume(KeyguardSecurityView.SCREEN_ON); |
| 240 | |
| 241 | // This is a an attempt to fix bug 7137389 where the device comes back on but the entire |
| 242 | // layout is blank but forcing a layout causes it to reappear (e.g. with with |
| 243 | // hierarchyviewer). |
| 244 | requestLayout(); |
| 245 | requestFocus(); |
| 246 | } |
Brian Colonna | 4284e9d | 2011-09-28 12:08:58 -0400 | [diff] [blame] | 247 | |
| 248 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 249 | * Verify that the user can get past the keyguard securely. This is called, |
| 250 | * for example, when the phone disables the keyguard but then wants to launch |
| 251 | * something else that requires secure access. |
| 252 | * |
| 253 | * The result will be propogated back via {@link KeyguardViewCallback#keyguardDone(boolean)} |
| 254 | */ |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 255 | public void verifyUnlock() { |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 256 | SecurityMode securityMode = mSecurityContainer.getSecurityMode(); |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 257 | if (securityMode == KeyguardSecurityModel.SecurityMode.None) { |
| 258 | if (mViewMediatorCallback != null) { |
| 259 | mViewMediatorCallback.keyguardDone(true); |
| 260 | } |
| 261 | } else if (securityMode != KeyguardSecurityModel.SecurityMode.Pattern |
| 262 | && securityMode != KeyguardSecurityModel.SecurityMode.PIN |
| 263 | && securityMode != KeyguardSecurityModel.SecurityMode.Password) { |
| 264 | // can only verify unlock when in pattern/password mode |
| 265 | if (mViewMediatorCallback != null) { |
| 266 | mViewMediatorCallback.keyguardDone(false); |
| 267 | } |
| 268 | } else { |
| 269 | // otherwise, go to the unlock screen, see if they can verify it |
| 270 | mSecurityContainer.verifyUnlock(); |
| 271 | } |
| 272 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 273 | |
| 274 | /** |
| 275 | * Called before this view is being removed. |
| 276 | */ |
| 277 | abstract public void cleanUp(); |
| 278 | |
Jeff Brown | c7505bc | 2012-10-05 21:58:15 -0700 | [diff] [blame] | 279 | /** |
| 280 | * Gets the desired user activity timeout in milliseconds, or -1 if the |
| 281 | * default should be used. |
| 282 | */ |
| 283 | abstract public long getUserActivityTimeout(); |
| 284 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 285 | @Override |
| 286 | public boolean dispatchKeyEvent(KeyEvent event) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 287 | if (interceptMediaKey(event)) { |
| 288 | return true; |
| 289 | } |
| 290 | return super.dispatchKeyEvent(event); |
| 291 | } |
| 292 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 293 | /** |
Marco Nelissen | 24d1056 | 2009-05-12 14:15:17 -0700 | [diff] [blame] | 294 | * Allows the media keys to work when the keyguard is showing. |
| 295 | * 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] | 296 | * so intercepting them here should not be of any harm. |
| 297 | * @param event The key event |
| 298 | * @return whether the event was consumed as a media key. |
| 299 | */ |
| 300 | private boolean interceptMediaKey(KeyEvent event) { |
| 301 | final int keyCode = event.getKeyCode(); |
| 302 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 303 | switch (keyCode) { |
Marco Nelissen | a6face4 | 2010-10-25 10:21:59 -0700 | [diff] [blame] | 304 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 305 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
Andy Stadler | 8b89d69 | 2009-04-10 16:24:49 -0700 | [diff] [blame] | 306 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 307 | /* Suppress PLAY/PAUSE toggle when phone is ringing or |
The Android Open Source Project | bc8d29f | 2009-03-05 20:00:44 -0800 | [diff] [blame] | 308 | * in-call to avoid music playback */ |
| 309 | if (mTelephonyManager == null) { |
| 310 | mTelephonyManager = (TelephonyManager) getContext().getSystemService( |
| 311 | Context.TELEPHONY_SERVICE); |
| 312 | } |
| 313 | if (mTelephonyManager != null && |
| 314 | mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE) { |
| 315 | return true; // suppress key event |
| 316 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 317 | case KeyEvent.KEYCODE_MUTE: |
| 318 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 319 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 320 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 321 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 322 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 323 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 324 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 325 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 326 | handleMediaKeyEvent(event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 327 | return true; |
| 328 | } |
| 329 | |
| 330 | case KeyEvent.KEYCODE_VOLUME_UP: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 331 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 332 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Amith Yamasani | 2ef6f1b | 2011-12-01 14:01:30 -0800 | [diff] [blame] | 333 | if (KEYGUARD_MANAGES_VOLUME) { |
| 334 | synchronized (this) { |
| 335 | if (mAudioManager == null) { |
| 336 | mAudioManager = (AudioManager) getContext().getSystemService( |
| 337 | Context.AUDIO_SERVICE); |
| 338 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 339 | } |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 340 | // Volume buttons should only function for music (local or remote). |
| 341 | // TODO: Actually handle MUTE. |
| 342 | mAudioManager.adjustLocalOrRemoteStreamVolume( |
| 343 | AudioManager.STREAM_MUSIC, |
| 344 | keyCode == KeyEvent.KEYCODE_VOLUME_UP |
| 345 | ? AudioManager.ADJUST_RAISE |
| 346 | : AudioManager.ADJUST_LOWER); |
Amith Yamasani | 2ef6f1b | 2011-12-01 14:01:30 -0800 | [diff] [blame] | 347 | // Don't execute default volume behavior |
| 348 | return true; |
| 349 | } else { |
| 350 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 351 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 355 | switch (keyCode) { |
| 356 | case KeyEvent.KEYCODE_MUTE: |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 357 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 358 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 359 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 360 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 361 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 362 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 363 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 364 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 365 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 366 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 367 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 368 | handleMediaKeyEvent(event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 369 | return true; |
| 370 | } |
| 371 | } |
| 372 | } |
| 373 | return false; |
| 374 | } |
| 375 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 376 | private void handleMediaKeyEvent(KeyEvent keyEvent) { |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 377 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 378 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 379 | if (audioService != null) { |
| 380 | try { |
| 381 | audioService.dispatchMediaKeyEvent(keyEvent); |
| 382 | } catch (RemoteException e) { |
| 383 | Log.e("KeyguardViewBase", "dispatchMediaKeyEvent threw exception " + e); |
| 384 | } |
| 385 | } else { |
| 386 | Slog.w("KeyguardViewBase", "Unable to find IAudioService for media key event"); |
| 387 | } |
| 388 | } |
| 389 | |
Joe Onorato | 4671ce5 | 2011-01-27 21:15:42 -0800 | [diff] [blame] | 390 | @Override |
| 391 | public void dispatchSystemUiVisibilityChanged(int visibility) { |
| 392 | super.dispatchSystemUiVisibilityChanged(visibility); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 393 | |
| 394 | if (!(mContext instanceof Activity)) { |
| 395 | setSystemUiVisibility(STATUS_BAR_DISABLE_BACK); |
| 396 | } |
Joe Onorato | 4671ce5 | 2011-01-27 21:15:42 -0800 | [diff] [blame] | 397 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 398 | |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 399 | /** |
| 400 | * In general, we enable unlocking the insecure keyguard with the menu key. However, there are |
| 401 | * some cases where we wish to disable it, notably when the menu button placement or technology |
| 402 | * is prone to false positives. |
| 403 | * |
| 404 | * @return true if the menu key should be enabled |
| 405 | */ |
| 406 | private static final String ENABLE_MENU_KEY_FILE = "/data/local/enable_menu_key"; |
| 407 | private boolean shouldEnableMenuKey() { |
| 408 | final Resources res = getResources(); |
| 409 | final boolean configDisabled = res.getBoolean(R.bool.config_disableMenuKeyInLockScreen); |
| 410 | final boolean isTestHarness = ActivityManager.isRunningInTestHarness(); |
| 411 | final boolean fileOverride = (new File(ENABLE_MENU_KEY_FILE)).exists(); |
| 412 | return !configDisabled || isTestHarness || fileOverride; |
| 413 | } |
| 414 | |
| 415 | public boolean handleMenuKey() { |
| 416 | // The following enables the MENU key to work for testing automation |
| 417 | if (shouldEnableMenuKey()) { |
| 418 | dismiss(); |
| 419 | return true; |
| 420 | } |
| 421 | return false; |
| 422 | } |
| 423 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 424 | public void setViewMediatorCallback(ViewMediatorCallback viewMediatorCallback) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 425 | mViewMediatorCallback = viewMediatorCallback; |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 426 | // Update ViewMediator with the current input method requirements |
| 427 | mViewMediatorCallback.setNeedsInput(mSecurityContainer.needsInput()); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 428 | } |
Jim Miller | 3eb4971 | 2014-01-28 18:22:42 -0800 | [diff] [blame] | 429 | |
| 430 | protected KeyguardActivityLauncher getActivityLauncher() { |
| 431 | return mActivityLauncher; |
| 432 | } |
| 433 | |
| 434 | private final KeyguardActivityLauncher mActivityLauncher = new KeyguardActivityLauncher() { |
| 435 | @Override |
| 436 | Context getContext() { |
| 437 | return mContext; |
| 438 | } |
| 439 | |
| 440 | @Override |
| 441 | void setOnDismissAction(OnDismissAction action) { |
| 442 | KeyguardViewBase.this.setOnDismissAction(action); |
| 443 | } |
| 444 | |
| 445 | @Override |
| 446 | LockPatternUtils getLockPatternUtils() { |
| 447 | return mLockPatternUtils; |
| 448 | } |
| 449 | |
| 450 | @Override |
| 451 | void requestDismissKeyguard() { |
| 452 | KeyguardViewBase.this.dismiss(false); |
| 453 | } |
| 454 | }; |
| 455 | |
| 456 | public void showAssistant() { |
| 457 | final Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
| 458 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
| 459 | |
| 460 | if (intent == null) return; |
| 461 | |
| 462 | final ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext, |
| 463 | R.anim.keyguard_action_assist_enter, R.anim.keyguard_action_assist_exit, |
| 464 | getHandler(), null); |
| 465 | |
| 466 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 467 | mActivityLauncher.launchActivityWithAnimation(intent, false, opts.toBundle(), null, null); |
| 468 | } |
| 469 | |
| 470 | public void launchCamera() { |
| 471 | mActivityLauncher.launchCamera(getHandler(), null); |
| 472 | } |
| 473 | |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 474 | public void setLockPatternUtils(LockPatternUtils utils) { |
Jim Miller | 5e612cf | 2014-02-03 17:57:23 -0800 | [diff] [blame] | 475 | mLockPatternUtils = utils; |
| 476 | mSecurityContainer.setLockPatternUtils(utils); |
| 477 | } |
| 478 | |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 479 | public SecurityMode getSecurityMode() { |
| 480 | return mSecurityContainer.getSecurityMode(); |
| 481 | } |
| 482 | |
Jim Miller | 5e612cf | 2014-02-03 17:57:23 -0800 | [diff] [blame] | 483 | protected abstract void onUserSwitching(boolean switching); |
| 484 | |
| 485 | protected abstract void onCreateOptions(Bundle options); |
| 486 | |
| 487 | protected abstract void onExternalMotionEvent(MotionEvent event); |
| 488 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 489 | } |