blob: 8e1f6d384d1d99d7990221f0791495d4f465a564 [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;
Jason Chang1e4a4bd2018-05-22 17:30:19 +080022import android.content.res.ColorStateList;
Gus Prevasab336792018-11-14 13:52:20 -050023import android.content.res.Resources;
Jim Miller3eb49712014-01-28 18:22:42 -080024import android.graphics.Canvas;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080025import android.media.AudioManager;
Jim Miller3eb49712014-01-28 18:22:42 -080026import android.os.SystemClock;
Adrian Roos94e15a52015-04-16 12:23:18 -070027import android.service.trust.TrustAgentService;
The Android Open Source Projectbc8d29f2009-03-05 20:00:44 -080028import android.telephony.TelephonyManager;
Karl Rosaenad297342009-03-24 18:55:19 -070029import android.util.AttributeSet;
Jean-Michel Trivic6802222012-04-30 11:15:03 -070030import android.util.Log;
Jim Miller838906b2012-10-19 18:41:25 -070031import android.view.KeyEvent;
32import 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;
Lucas Dupinc80c67e2017-12-04 14:29:10 -080037import com.android.settingslib.Utils;
Sunny Goyal87fccf02019-08-13 17:39:10 -070038import com.android.systemui.R;
Jason Monk297c04e2018-08-23 17:16:59 -040039import com.android.systemui.plugins.ActivityStarter.OnDismissAction;
Jim Miller3eb49712014-01-28 18:22:42 -080040
41import java.io.File;
42
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043/**
Jim Millerdcb3d842012-08-23 19:18:12 -070044 * Base class for keyguard view. {@link #reset} is where you should
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080045 * 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 Jaggi6b88cdf2014-12-22 20:56:50 +010052public class KeyguardHostView extends FrameLayout implements SecurityCallback {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080053
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080054 private AudioManager mAudioManager;
The Android Open Source Projectbc8d29f2009-03-05 20:00:44 -080055 private TelephonyManager mTelephonyManager = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010056 protected ViewMediatorCallback mViewMediatorCallback;
Jim Miller3eb49712014-01-28 18:22:42 -080057 protected LockPatternUtils mLockPatternUtils;
58 private OnDismissAction mDismissAction;
Jorim Jaggid9449862015-05-29 14:49:08 -070059 private Runnable mCancelAction;
Jim Millerdcb3d842012-08-23 19:18:12 -070060
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010061 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 Roos94e15a52015-04-16 12:23:18 -070070 public void onTrustGrantedWithFlags(int flags, int userId) {
Adrian Roosd6aa6cb2015-04-16 19:31:29 -070071 if (userId != KeyguardUpdateMonitor.getCurrentUser()) return;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010072 if (!isAttachedToWindow()) return;
Adrian Roos94e15a52015-04-16 12:23:18 -070073 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 Jaggi6b88cdf2014-12-22 20:56:50 +010078
Adrian Roos94e15a52015-04-16 12:23:18 -070079 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 Tryshev8702ca72016-04-22 08:14:12 -070087 dismiss(false /* authenticated */, userId);
Adrian Roos94e15a52015-04-16 12:23:18 -070088 } else {
89 mViewMediatorCallback.playTrustedSound();
90 }
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010091 }
92 }
93 };
94
Amith Yamasani2ef6f1b2011-12-01 14:01:30 -080095 // 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 Spurlockae641c92014-06-30 18:11:40 -040098 private static final boolean KEYGUARD_MANAGES_VOLUME = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010099 public static final boolean DEBUG = KeyguardConstants.DEBUG;
Jim Miller3eb49712014-01-28 18:22:42 -0800100 private static final String TAG = "KeyguardViewBase";
101
102 private KeyguardSecurityContainer mSecurityContainer;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800103
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100104 public KeyguardHostView(Context context) {
Jim Millerdcb3d842012-08-23 19:18:12 -0700105 this(context, null);
106 }
107
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100108 public KeyguardHostView(Context context, AttributeSet attrs) {
Jim Millerdcb3d842012-08-23 19:18:12 -0700109 super(context, attrs);
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100110 KeyguardUpdateMonitor.getInstance(context).registerCallback(mUpdateCallback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800111 }
112
Jim Miller3eb49712014-01-28 18:22:42 -0800113 @Override
114 protected void dispatchDraw(Canvas canvas) {
115 super.dispatchDraw(canvas);
116 if (mViewMediatorCallback != null) {
117 mViewMediatorCallback.keyguardDoneDrawing();
118 }
119 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800120
121 /**
Jim Miller3eb49712014-01-28 18:22:42 -0800122 * Sets an action to run when keyguard finishes.
123 *
124 * @param action
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800125 */
Jorim Jaggid9449862015-05-29 14:49:08 -0700126 public void setOnDismissAction(OnDismissAction action, Runnable cancelAction) {
127 if (mCancelAction != null) {
128 mCancelAction.run();
129 mCancelAction = null;
130 }
Jim Miller3eb49712014-01-28 18:22:42 -0800131 mDismissAction = action;
Jorim Jaggid9449862015-05-29 14:49:08 -0700132 mCancelAction = cancelAction;
133 }
134
Lucas Dupin6f0d71f2018-03-23 17:26:06 -0700135 public boolean hasDismissActions() {
136 return mDismissAction != null || mCancelAction != null;
137 }
138
Jorim Jaggid9449862015-05-29 14:49:08 -0700139 public void cancelDismissAction() {
140 setOnDismissAction(null, null);
Jim Miller3eb49712014-01-28 18:22:42 -0800141 }
142
143 @Override
144 protected void onFinishInflate() {
145 mSecurityContainer =
Alan Viverette51efddb2017-04-05 10:00:01 -0400146 findViewById(R.id.keyguard_security_container);
Jim Miller5e612cf2014-02-03 17:57:23 -0800147 mLockPatternUtils = new LockPatternUtils(mContext);
Jim Miller3eb49712014-01-28 18:22:42 -0800148 mSecurityContainer.setLockPatternUtils(mLockPatternUtils);
Jim Millerba7d94b2014-02-05 17:30:50 -0800149 mSecurityContainer.setSecurityCallback(this);
Jim Miller3eb49712014-01-28 18:22:42 -0800150 mSecurityContainer.showPrimarySecurityScreen(false);
Jim Miller3eb49712014-01-28 18:22:42 -0800151 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800152
153 /**
Brian Colonna4284e9d2011-09-28 12:08:58 -0400154 * Called when the view needs to be shown.
155 */
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100156 public void showPrimarySecurityScreen() {
Jim Miller3eb49712014-01-28 18:22:42 -0800157 if (DEBUG) Log.d(TAG, "show()");
158 mSecurityContainer.showPrimarySecurityScreen(false);
159 }
160
Lucas Dupin27321c42019-03-20 16:22:24 -0700161 public KeyguardSecurityView getCurrentSecurityView() {
162 return mSecurityContainer != null ? mSecurityContainer.getCurrentSecurityView() : null;
163 }
164
Jim Miller3eb49712014-01-28 18:22:42 -0800165 /**
Selim Cinek3122fa82015-06-18 01:38:59 -0700166 * 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 Jaggi25b4d4b2015-08-11 15:54:06 -0700169 * {@link KeyguardSecurityView#PROMPT_REASON_NONE},
170 * {@link KeyguardSecurityView#PROMPT_REASON_RESTART} and
171 * {@link KeyguardSecurityView#PROMPT_REASON_TIMEOUT}.
Selim Cinek3122fa82015-06-18 01:38:59 -0700172 */
173 public void showPromptReason(int reason) {
174 mSecurityContainer.showPromptReason(reason);
175 }
176
Jason Chang1e4a4bd2018-05-22 17:30:19 +0800177 public void showMessage(CharSequence message, ColorStateList colorState) {
178 mSecurityContainer.showMessage(message, colorState);
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700179 }
180
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800181 public void showErrorMessage(CharSequence message) {
Jason Chang1e4a4bd2018-05-22 17:30:19 +0800182 showMessage(message, Utils.getColorError(mContext));
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800183 }
184
Selim Cinek3122fa82015-06-18 01:38:59 -0700185 /**
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700186 * 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 Miller3eb49712014-01-28 18:22:42 -0800189 */
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700190 public boolean dismiss(int targetUserId) {
191 return dismiss(false, targetUserId);
Jim Miller3eb49712014-01-28 18:22:42 -0800192 }
193
Jim Miller3eb49712014-01-28 18:22:42 -0800194 public boolean handleBackKey() {
Jim Miller3eb49712014-01-28 18:22:42 -0800195 if (mSecurityContainer.getCurrentSecuritySelection() != SecurityMode.None) {
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700196 mSecurityContainer.dismiss(false, KeyguardUpdateMonitor.getCurrentUser());
Jim Miller3eb49712014-01-28 18:22:42 -0800197 return true;
198 }
199 return false;
200 }
201
Jim Millerba7d94b2014-02-05 17:30:50 -0800202 protected KeyguardSecurityContainer getSecurityContainer() {
203 return mSecurityContainer;
204 }
Jim Miller3eb49712014-01-28 18:22:42 -0800205
Jim Millerba7d94b2014-02-05 17:30:50 -0800206 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700207 public boolean dismiss(boolean authenticated, int targetUserId) {
208 return mSecurityContainer.showNextSecurityScreenOrFinish(authenticated, targetUserId);
Jim Miller3eb49712014-01-28 18:22:42 -0800209 }
210
211 /**
212 * Authentication has happened and it's time to dismiss keyguard. This function
213 * should clean up and inform KeyguardViewMediator.
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700214 *
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 Tryshev8702ca72016-04-22 08:14:12 -0700217 * @param targetUserId a user that needs to be the foreground user at the dismissal completion.
Jim Miller3eb49712014-01-28 18:22:42 -0800218 */
Jim Millerba7d94b2014-02-05 17:30:50 -0800219 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700220 public void finish(boolean strongAuth, int targetUserId) {
Jim Miller3eb49712014-01-28 18:22:42 -0800221 // 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 Jaggid9449862015-05-29 14:49:08 -0700227 mCancelAction = null;
Jim Miller3eb49712014-01-28 18:22:42 -0800228 }
229 if (mViewMediatorCallback != null) {
230 if (deferKeyguardDone) {
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700231 mViewMediatorCallback.keyguardDonePending(strongAuth, targetUserId);
Jim Miller3eb49712014-01-28 18:22:42 -0800232 } else {
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700233 mViewMediatorCallback.keyguardDone(strongAuth, targetUserId);
Jim Miller3eb49712014-01-28 18:22:42 -0800234 }
235 }
236 }
237
Jim Millerba7d94b2014-02-05 17:30:50 -0800238 @Override
Andrew Lee72b46d42015-01-30 13:23:21 -0800239 public void reset() {
240 mViewMediatorCallback.resetKeyguard();
241 }
242
Aarthi Balachander0a427ef2018-07-13 15:00:58 -0700243 @Override
244 public void onCancelClicked() {
245 mViewMediatorCallback.onCancelClicked();
246 }
247
Lucas Dupin80180492018-05-08 17:06:06 -0700248 public void resetSecurityContainer() {
249 mSecurityContainer.reset();
250 }
251
Andrew Lee72b46d42015-01-30 13:23:21 -0800252 @Override
Jim Millerba7d94b2014-02-05 17:30:50 -0800253 public void onSecurityModeChanged(SecurityMode securityMode, boolean needsInput) {
Jim Miller3eb49712014-01-28 18:22:42 -0800254 if (mViewMediatorCallback != null) {
Jim Millerba7d94b2014-02-05 17:30:50 -0800255 mViewMediatorCallback.setNeedsInput(needsInput);
Jim Miller3eb49712014-01-28 18:22:42 -0800256 }
257 }
258
Phil Weaver7d847b02018-02-13 16:02:35 -0800259 public CharSequence getAccessibilityTitleForCurrentMode() {
260 return mSecurityContainer.getTitle();
261 }
262
Jim Millerba7d94b2014-02-05 17:30:50 -0800263 public void userActivity() {
Jim Miller3eb49712014-01-28 18:22:42 -0800264 if (mViewMediatorCallback != null) {
265 mViewMediatorCallback.userActivity();
266 }
267 }
268
Jim Miller3eb49712014-01-28 18:22:42 -0800269 /**
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200270 * Called when the Keyguard is not actively shown anymore on the screen.
Jim Miller3eb49712014-01-28 18:22:42 -0800271 */
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200272 public void onPause() {
Jim Miller3eb49712014-01-28 18:22:42 -0800273 if (DEBUG) Log.d(TAG, String.format("screen off, instance %s at %s",
274 Integer.toHexString(hashCode()), SystemClock.uptimeMillis()));
Jim Miller3eb49712014-01-28 18:22:42 -0800275 mSecurityContainer.showPrimarySecurityScreen(true);
276 mSecurityContainer.onPause();
277 clearFocus();
278 }
279
280 /**
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200281 * Called when the Keyguard is actively shown on the screen.
Jim Miller3eb49712014-01-28 18:22:42 -0800282 */
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200283 public void onResume() {
Jim Miller3eb49712014-01-28 18:22:42 -0800284 if (DEBUG) Log.d(TAG, "screen on, instance " + Integer.toHexString(hashCode()));
Jim Miller3eb49712014-01-28 18:22:42 -0800285 mSecurityContainer.onResume(KeyguardSecurityView.SCREEN_ON);
Jim Miller3eb49712014-01-28 18:22:42 -0800286 requestFocus();
287 }
Brian Colonna4284e9d2011-09-28 12:08:58 -0400288
289 /**
Jorim Jaggic14f8292014-05-27 02:25:45 +0200290 * Starts the animation when the Keyguard gets shown.
291 */
292 public void startAppearAnimation() {
293 mSecurityContainer.startAppearAnimation();
294 }
295
Jorim Jaggi76a16232014-08-08 17:00:47 +0200296 public void startDisappearAnimation(Runnable finishRunnable) {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200297 if (!mSecurityContainer.startDisappearAnimation(finishRunnable) && finishRunnable != null) {
Jorim Jaggi76a16232014-08-08 17:00:47 +0200298 finishRunnable.run();
299 }
300 }
301
Jorim Jaggic14f8292014-05-27 02:25:45 +0200302 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800303 * Called before this view is being removed.
304 */
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100305 public void cleanUp() {
306 getSecurityContainer().onPause();
307 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700308
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800309 @Override
310 public boolean dispatchKeyEvent(KeyEvent event) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800311 if (interceptMediaKey(event)) {
312 return true;
313 }
314 return super.dispatchKeyEvent(event);
315 }
316
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800317 /**
Marco Nelissen24d10562009-05-12 14:15:17 -0700318 * 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 Project1f838aa2009-03-03 19:32:13 -0800320 * 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 Jaggidf993512014-05-13 23:06:35 +0200324 public boolean interceptMediaKey(KeyEvent event) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800325 final int keyCode = event.getKeyCode();
326 if (event.getAction() == KeyEvent.ACTION_DOWN) {
327 switch (keyCode) {
Marco Nelissena6face42010-10-25 10:21:59 -0700328 case KeyEvent.KEYCODE_MEDIA_PLAY:
329 case KeyEvent.KEYCODE_MEDIA_PAUSE:
Andy Stadler8b89d692009-04-10 16:24:49 -0700330 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -0700331 /* Suppress PLAY/PAUSE toggle when phone is ringing or
The Android Open Source Projectbc8d29f2009-03-05 20:00:44 -0800332 * 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 Brown4d396052010-10-29 21:50:21 -0700341 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 Seokbfdad8e2013-07-08 13:53:21 +0900348 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
349 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jean-Michel Trivic6802222012-04-30 11:15:03 -0700350 handleMediaKeyEvent(event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800351 return true;
352 }
353
354 case KeyEvent.KEYCODE_VOLUME_UP:
Jeff Brownb0418da2010-11-01 15:24:01 -0700355 case KeyEvent.KEYCODE_VOLUME_DOWN:
356 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Amith Yamasani2ef6f1b2011-12-01 14:01:30 -0800357 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 Project1f838aa2009-03-03 19:32:13 -0800363 }
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700364 // Volume buttons should only function for music (local or remote).
365 // TODO: Actually handle MUTE.
RoboErikd3c86422014-06-16 14:00:48 -0700366 mAudioManager.adjustSuggestedStreamVolume(
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700367 keyCode == KeyEvent.KEYCODE_VOLUME_UP
368 ? AudioManager.ADJUST_RAISE
RoboErikd3c86422014-06-16 14:00:48 -0700369 : AudioManager.ADJUST_LOWER /* direction */,
370 AudioManager.STREAM_MUSIC /* stream */, 0 /* flags */);
Amith Yamasani2ef6f1b2011-12-01 14:01:30 -0800371 // Don't execute default volume behavior
372 return true;
373 } else {
374 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800375 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800376 }
377 }
378 } else if (event.getAction() == KeyEvent.ACTION_UP) {
379 switch (keyCode) {
380 case KeyEvent.KEYCODE_MUTE:
Jeff Brown4d396052010-10-29 21:50:21 -0700381 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 Seokbfdad8e2013-07-08 13:53:21 +0900390 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
391 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jean-Michel Trivic6802222012-04-30 11:15:03 -0700392 handleMediaKeyEvent(event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800393 return true;
394 }
395 }
396 }
397 return false;
398 }
399
Jim Miller3eb49712014-01-28 18:22:42 -0800400 private void handleMediaKeyEvent(KeyEvent keyEvent) {
RoboErikd3c86422014-06-16 14:00:48 -0700401 synchronized (this) {
402 if (mAudioManager == null) {
403 mAudioManager = (AudioManager) getContext().getSystemService(
404 Context.AUDIO_SERVICE);
Jean-Michel Trivic6802222012-04-30 11:15:03 -0700405 }
Jean-Michel Trivic6802222012-04-30 11:15:03 -0700406 }
RoboErikd3c86422014-06-16 14:00:48 -0700407 mAudioManager.dispatchMediaKeyEvent(keyEvent);
Jean-Michel Trivic6802222012-04-30 11:15:03 -0700408 }
409
Joe Onorato4671ce52011-01-27 21:15:42 -0800410 @Override
411 public void dispatchSystemUiVisibilityChanged(int visibility) {
412 super.dispatchSystemUiVisibilityChanged(visibility);
Jim Millerd6523da2012-10-21 16:47:02 -0700413
414 if (!(mContext instanceof Activity)) {
415 setSystemUiVisibility(STATUS_BAR_DISABLE_BACK);
416 }
Joe Onorato4671ce52011-01-27 21:15:42 -0800417 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700418
Jim Miller3eb49712014-01-28 18:22:42 -0800419 /**
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 Cinek28540192016-02-19 17:25:08 -0800427 public boolean shouldEnableMenuKey() {
Jim Miller3eb49712014-01-28 18:22:42 -0800428 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 Jaggi5cf17872014-03-26 18:31:48 +0100435 public void setViewMediatorCallback(ViewMediatorCallback viewMediatorCallback) {
Jim Millerdcb3d842012-08-23 19:18:12 -0700436 mViewMediatorCallback = viewMediatorCallback;
Jim Millerba7d94b2014-02-05 17:30:50 -0800437 // Update ViewMediator with the current input method requirements
438 mViewMediatorCallback.setNeedsInput(mSecurityContainer.needsInput());
Jim Millerdcb3d842012-08-23 19:18:12 -0700439 }
Jim Miller3eb49712014-01-28 18:22:42 -0800440
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100441 public void setLockPatternUtils(LockPatternUtils utils) {
Jim Miller5e612cf2014-02-03 17:57:23 -0800442 mLockPatternUtils = utils;
443 mSecurityContainer.setLockPatternUtils(utils);
444 }
445
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200446 public SecurityMode getSecurityMode() {
447 return mSecurityContainer.getSecurityMode();
448 }
449
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100450 public SecurityMode getCurrentSecurityMode() {
451 return mSecurityContainer.getCurrentSecurityMode();
452 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800453}