blob: be71b034f3f9f876c3bc48ff2af7db081f8561c2 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
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 Miller5ecd8112013-01-09 18:50:26 -080017package com.android.keyguard;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Jim Millerd6523da2012-10-21 16:47:02 -070019import android.app.Activity;
Jim Miller3eb49712014-01-28 18:22:42 -080020import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080021import android.content.Context;
Jim Miller3eb49712014-01-28 18:22:42 -080022import android.content.res.Resources;
23import android.graphics.Canvas;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080024import android.media.AudioManager;
Jim Miller3eb49712014-01-28 18:22:42 -080025import android.os.SystemClock;
Adrian Roos94e15a52015-04-16 12:23:18 -070026import android.service.trust.TrustAgentService;
The Android Open Source Projectbc8d29f2009-03-05 20:00:44 -080027import android.telephony.TelephonyManager;
Karl Rosaenad297342009-03-24 18:55:19 -070028import android.util.AttributeSet;
Jean-Michel Trivic6802222012-04-30 11:15:03 -070029import android.util.Log;
Jim Miller838906b2012-10-19 18:41:25 -070030import android.view.KeyEvent;
Jorim Jaggi10c85c72015-02-02 20:45:32 +010031import android.view.accessibility.AccessibilityEvent;
Jim Miller838906b2012-10-19 18:41:25 -070032import android.widget.FrameLayout;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080033
Jim Miller3eb49712014-01-28 18:22:42 -080034import com.android.internal.widget.LockPatternUtils;
Jim Miller3eb49712014-01-28 18:22:42 -080035import com.android.keyguard.KeyguardSecurityContainer.SecurityCallback;
36import com.android.keyguard.KeyguardSecurityModel.SecurityMode;
37
38import java.io.File;
39
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080040/**
Jim Millerdcb3d842012-08-23 19:18:12 -070041 * Base class for keyguard view. {@link #reset} is where you should
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080042 * 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 Jaggi6b88cdf2014-12-22 20:56:50 +010049public class KeyguardHostView extends FrameLayout implements SecurityCallback {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080050
Jorim Jaggi5c60b642014-12-19 18:13:28 +010051 public interface OnDismissAction {
52 /**
53 * @return true if the dismiss should be deferred
54 */
55 boolean onDismiss();
56 }
57
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080058 private AudioManager mAudioManager;
The Android Open Source Projectbc8d29f2009-03-05 20:00:44 -080059 private TelephonyManager mTelephonyManager = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010060 protected ViewMediatorCallback mViewMediatorCallback;
Jim Miller3eb49712014-01-28 18:22:42 -080061 protected LockPatternUtils mLockPatternUtils;
62 private OnDismissAction mDismissAction;
Jim Millerdcb3d842012-08-23 19:18:12 -070063
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010064 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 Roos94e15a52015-04-16 12:23:18 -070073 public void onTrustGrantedWithFlags(int flags, int userId) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010074 if (userId != mLockPatternUtils.getCurrentUser()) return;
75 if (!isAttachedToWindow()) return;
Adrian Roos94e15a52015-04-16 12:23:18 -070076 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 Jaggi6b88cdf2014-12-22 20:56:50 +010081
Adrian Roos94e15a52015-04-16 12:23:18 -070082 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 Jaggi6b88cdf2014-12-22 20:56:50 +010094 }
95 }
96 };
97
Amith Yamasani2ef6f1b2011-12-01 14:01:30 -080098 // 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 Spurlockae641c92014-06-30 18:11:40 -0400101 private static final boolean KEYGUARD_MANAGES_VOLUME = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100102 public static final boolean DEBUG = KeyguardConstants.DEBUG;
Jim Miller3eb49712014-01-28 18:22:42 -0800103 private static final String TAG = "KeyguardViewBase";
104
105 private KeyguardSecurityContainer mSecurityContainer;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800106
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100107 public KeyguardHostView(Context context) {
Jim Millerdcb3d842012-08-23 19:18:12 -0700108 this(context, null);
109 }
110
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100111 public KeyguardHostView(Context context, AttributeSet attrs) {
Jim Millerdcb3d842012-08-23 19:18:12 -0700112 super(context, attrs);
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100113 KeyguardUpdateMonitor.getInstance(context).registerCallback(mUpdateCallback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800114 }
115
Jim Miller3eb49712014-01-28 18:22:42 -0800116 @Override
117 protected void dispatchDraw(Canvas canvas) {
118 super.dispatchDraw(canvas);
119 if (mViewMediatorCallback != null) {
120 mViewMediatorCallback.keyguardDoneDrawing();
121 }
122 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800123
124 /**
Jim Miller3eb49712014-01-28 18:22:42 -0800125 * Sets an action to run when keyguard finishes.
126 *
127 * @param action
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800128 */
Jim Miller3eb49712014-01-28 18:22:42 -0800129 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 Miller5e612cf2014-02-03 17:57:23 -0800137 mLockPatternUtils = new LockPatternUtils(mContext);
Jim Miller3eb49712014-01-28 18:22:42 -0800138 mSecurityContainer.setLockPatternUtils(mLockPatternUtils);
Jim Millerba7d94b2014-02-05 17:30:50 -0800139 mSecurityContainer.setSecurityCallback(this);
Jim Miller3eb49712014-01-28 18:22:42 -0800140 mSecurityContainer.showPrimarySecurityScreen(false);
141 // mSecurityContainer.updateSecurityViews(false /* not bouncing */);
Jim Miller3eb49712014-01-28 18:22:42 -0800142 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800143
144 /**
Brian Colonna4284e9d2011-09-28 12:08:58 -0400145 * Called when the view needs to be shown.
146 */
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100147 public void showPrimarySecurityScreen() {
Jim Miller3eb49712014-01-28 18:22:42 -0800148 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 Jaggi0bed7f22014-04-03 16:12:54 +0200154 *
155 * @return True if the keyguard is done.
Jim Miller3eb49712014-01-28 18:22:42 -0800156 */
Jorim Jaggi0bed7f22014-04-03 16:12:54 +0200157 public boolean dismiss() {
158 return dismiss(false);
Jim Miller3eb49712014-01-28 18:22:42 -0800159 }
160
Jim Miller3eb49712014-01-28 18:22:42 -0800161 public boolean handleBackKey() {
Jim Miller3eb49712014-01-28 18:22:42 -0800162 if (mSecurityContainer.getCurrentSecuritySelection() != SecurityMode.None) {
163 mSecurityContainer.dismiss(false);
164 return true;
165 }
166 return false;
167 }
168
Jorim Jaggi10c85c72015-02-02 20:45:32 +0100169 @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 Miller9ccf1232013-10-10 22:23:07 -0700174 } else {
Jorim Jaggi10c85c72015-02-02 20:45:32 +0100175 return super.dispatchPopulateAccessibilityEvent(event);
Jim Miller9ccf1232013-10-10 22:23:07 -0700176 }
Jim Millere46efc02012-09-07 16:43:51 -0700177 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700178
Jim Millerba7d94b2014-02-05 17:30:50 -0800179 protected KeyguardSecurityContainer getSecurityContainer() {
180 return mSecurityContainer;
181 }
Jim Miller3eb49712014-01-28 18:22:42 -0800182
Jim Millerba7d94b2014-02-05 17:30:50 -0800183 @Override
184 public boolean dismiss(boolean authenticated) {
185 return mSecurityContainer.showNextSecurityScreenOrFinish(authenticated);
Jim Miller3eb49712014-01-28 18:22:42 -0800186 }
187
188 /**
189 * Authentication has happened and it's time to dismiss keyguard. This function
190 * should clean up and inform KeyguardViewMediator.
191 */
Jim Millerba7d94b2014-02-05 17:30:50 -0800192 @Override
Jim Miller3eb49712014-01-28 18:22:42 -0800193 public void finish() {
Jim Miller3eb49712014-01-28 18:22:42 -0800194 // 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 Millerba7d94b2014-02-05 17:30:50 -0800210 @Override
Andrew Lee72b46d42015-01-30 13:23:21 -0800211 public void reset() {
212 mViewMediatorCallback.resetKeyguard();
213 }
214
215 @Override
Jim Millerba7d94b2014-02-05 17:30:50 -0800216 public void onSecurityModeChanged(SecurityMode securityMode, boolean needsInput) {
Jim Miller3eb49712014-01-28 18:22:42 -0800217 if (mViewMediatorCallback != null) {
Jim Millerba7d94b2014-02-05 17:30:50 -0800218 mViewMediatorCallback.setNeedsInput(needsInput);
Jim Miller3eb49712014-01-28 18:22:42 -0800219 }
220 }
221
Jim Millerba7d94b2014-02-05 17:30:50 -0800222 public void userActivity() {
Jim Miller3eb49712014-01-28 18:22:42 -0800223 if (mViewMediatorCallback != null) {
224 mViewMediatorCallback.userActivity();
225 }
226 }
227
Jim Miller3eb49712014-01-28 18:22:42 -0800228 /**
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200229 * Called when the Keyguard is not actively shown anymore on the screen.
Jim Miller3eb49712014-01-28 18:22:42 -0800230 */
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200231 public void onPause() {
Jim Miller3eb49712014-01-28 18:22:42 -0800232 if (DEBUG) Log.d(TAG, String.format("screen off, instance %s at %s",
233 Integer.toHexString(hashCode()), SystemClock.uptimeMillis()));
Jim Miller3eb49712014-01-28 18:22:42 -0800234 mSecurityContainer.showPrimarySecurityScreen(true);
235 mSecurityContainer.onPause();
236 clearFocus();
237 }
238
239 /**
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200240 * Called when the Keyguard is actively shown on the screen.
Jim Miller3eb49712014-01-28 18:22:42 -0800241 */
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200242 public void onResume() {
Jim Miller3eb49712014-01-28 18:22:42 -0800243 if (DEBUG) Log.d(TAG, "screen on, instance " + Integer.toHexString(hashCode()));
Jim Miller3eb49712014-01-28 18:22:42 -0800244 mSecurityContainer.onResume(KeyguardSecurityView.SCREEN_ON);
Jim Miller3eb49712014-01-28 18:22:42 -0800245 requestFocus();
246 }
Brian Colonna4284e9d2011-09-28 12:08:58 -0400247
248 /**
Jorim Jaggic14f8292014-05-27 02:25:45 +0200249 * Starts the animation when the Keyguard gets shown.
250 */
251 public void startAppearAnimation() {
252 mSecurityContainer.startAppearAnimation();
253 }
254
Jorim Jaggi76a16232014-08-08 17:00:47 +0200255 public void startDisappearAnimation(Runnable finishRunnable) {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200256 if (!mSecurityContainer.startDisappearAnimation(finishRunnable) && finishRunnable != null) {
Jorim Jaggi76a16232014-08-08 17:00:47 +0200257 finishRunnable.run();
258 }
259 }
260
Jorim Jaggic14f8292014-05-27 02:25:45 +0200261 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800262 * 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 Miller3eb49712014-01-28 18:22:42 -0800268 public void verifyUnlock() {
Jim Millerba7d94b2014-02-05 17:30:50 -0800269 SecurityMode securityMode = mSecurityContainer.getSecurityMode();
Jim Miller3eb49712014-01-28 18:22:42 -0800270 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 Project1f838aa2009-03-03 19:32:13 -0800286
287 /**
288 * Called before this view is being removed.
289 */
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100290 public void cleanUp() {
291 getSecurityContainer().onPause();
292 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700293
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800294 @Override
295 public boolean dispatchKeyEvent(KeyEvent event) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800296 if (interceptMediaKey(event)) {
297 return true;
298 }
299 return super.dispatchKeyEvent(event);
300 }
301
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800302 /**
Marco Nelissen24d10562009-05-12 14:15:17 -0700303 * 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 Project1f838aa2009-03-03 19:32:13 -0800305 * 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 Jaggidf993512014-05-13 23:06:35 +0200309 public boolean interceptMediaKey(KeyEvent event) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800310 final int keyCode = event.getKeyCode();
311 if (event.getAction() == KeyEvent.ACTION_DOWN) {
312 switch (keyCode) {
Marco Nelissena6face42010-10-25 10:21:59 -0700313 case KeyEvent.KEYCODE_MEDIA_PLAY:
314 case KeyEvent.KEYCODE_MEDIA_PAUSE:
Andy Stadler8b89d692009-04-10 16:24:49 -0700315 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -0700316 /* Suppress PLAY/PAUSE toggle when phone is ringing or
The Android Open Source Projectbc8d29f2009-03-05 20:00:44 -0800317 * 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 Brown4d396052010-10-29 21:50:21 -0700326 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 Seokbfdad8e2013-07-08 13:53:21 +0900333 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
334 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jean-Michel Trivic6802222012-04-30 11:15:03 -0700335 handleMediaKeyEvent(event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800336 return true;
337 }
338
339 case KeyEvent.KEYCODE_VOLUME_UP:
Jeff Brownb0418da2010-11-01 15:24:01 -0700340 case KeyEvent.KEYCODE_VOLUME_DOWN:
341 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Amith Yamasani2ef6f1b2011-12-01 14:01:30 -0800342 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 Project1f838aa2009-03-03 19:32:13 -0800348 }
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700349 // Volume buttons should only function for music (local or remote).
350 // TODO: Actually handle MUTE.
RoboErikd3c86422014-06-16 14:00:48 -0700351 mAudioManager.adjustSuggestedStreamVolume(
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700352 keyCode == KeyEvent.KEYCODE_VOLUME_UP
353 ? AudioManager.ADJUST_RAISE
RoboErikd3c86422014-06-16 14:00:48 -0700354 : AudioManager.ADJUST_LOWER /* direction */,
355 AudioManager.STREAM_MUSIC /* stream */, 0 /* flags */);
Amith Yamasani2ef6f1b2011-12-01 14:01:30 -0800356 // Don't execute default volume behavior
357 return true;
358 } else {
359 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800360 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800361 }
362 }
363 } else if (event.getAction() == KeyEvent.ACTION_UP) {
364 switch (keyCode) {
365 case KeyEvent.KEYCODE_MUTE:
Jeff Brown4d396052010-10-29 21:50:21 -0700366 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 Seokbfdad8e2013-07-08 13:53:21 +0900375 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
376 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jean-Michel Trivic6802222012-04-30 11:15:03 -0700377 handleMediaKeyEvent(event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800378 return true;
379 }
380 }
381 }
382 return false;
383 }
384
Jim Miller3eb49712014-01-28 18:22:42 -0800385 private void handleMediaKeyEvent(KeyEvent keyEvent) {
RoboErikd3c86422014-06-16 14:00:48 -0700386 synchronized (this) {
387 if (mAudioManager == null) {
388 mAudioManager = (AudioManager) getContext().getSystemService(
389 Context.AUDIO_SERVICE);
Jean-Michel Trivic6802222012-04-30 11:15:03 -0700390 }
Jean-Michel Trivic6802222012-04-30 11:15:03 -0700391 }
RoboErikd3c86422014-06-16 14:00:48 -0700392 mAudioManager.dispatchMediaKeyEvent(keyEvent);
Jean-Michel Trivic6802222012-04-30 11:15:03 -0700393 }
394
Joe Onorato4671ce52011-01-27 21:15:42 -0800395 @Override
396 public void dispatchSystemUiVisibilityChanged(int visibility) {
397 super.dispatchSystemUiVisibilityChanged(visibility);
Jim Millerd6523da2012-10-21 16:47:02 -0700398
399 if (!(mContext instanceof Activity)) {
400 setSystemUiVisibility(STATUS_BAR_DISABLE_BACK);
401 }
Joe Onorato4671ce52011-01-27 21:15:42 -0800402 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700403
Jim Miller3eb49712014-01-28 18:22:42 -0800404 /**
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 Jaggi5cf17872014-03-26 18:31:48 +0100429 public void setViewMediatorCallback(ViewMediatorCallback viewMediatorCallback) {
Jim Millerdcb3d842012-08-23 19:18:12 -0700430 mViewMediatorCallback = viewMediatorCallback;
Jim Millerba7d94b2014-02-05 17:30:50 -0800431 // Update ViewMediator with the current input method requirements
432 mViewMediatorCallback.setNeedsInput(mSecurityContainer.needsInput());
Jim Millerdcb3d842012-08-23 19:18:12 -0700433 }
Jim Miller3eb49712014-01-28 18:22:42 -0800434
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100435 public void setLockPatternUtils(LockPatternUtils utils) {
Jim Miller5e612cf2014-02-03 17:57:23 -0800436 mLockPatternUtils = utils;
437 mSecurityContainer.setLockPatternUtils(utils);
438 }
439
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200440 public SecurityMode getSecurityMode() {
441 return mSecurityContainer.getSecurityMode();
442 }
443
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100444 public SecurityMode getCurrentSecurityMode() {
445 return mSecurityContainer.getCurrentSecurityMode();
446 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800447}