|
16 | 16 |
|
17 | 17 | package com.android.internal.policy.impl.keyguard; |
18 | 18 |
|
| 19 | +import android.app.ActivityManager; |
19 | 20 | import android.app.ActivityOptions; |
20 | 21 | import android.appwidget.AppWidgetHost; |
21 | 22 | import android.appwidget.AppWidgetHostView; |
|
25 | 26 | import android.content.Intent; |
26 | 27 | import android.content.IntentSender; |
27 | 28 | import android.content.SharedPreferences; |
28 | | -import android.content.SharedPreferences.Editor; |
29 | | -import android.content.res.Configuration; |
| 29 | +import android.content.res.Resources; |
30 | 30 | import android.graphics.Canvas; |
31 | 31 | import android.telephony.TelephonyManager; |
32 | 32 | import android.util.AttributeSet; |
|
43 | 43 | import com.android.internal.widget.LockPatternUtils; |
44 | 44 | import com.android.internal.R; |
45 | 45 |
|
| 46 | +import java.io.File; |
46 | 47 | import java.util.ArrayList; |
47 | 48 |
|
48 | 49 | public class KeyguardHostView extends KeyguardViewBase { |
@@ -72,7 +73,7 @@ public class KeyguardHostView extends KeyguardViewBase { |
72 | 73 | private ViewGroup mAppWidgetContainer; |
73 | 74 | private ViewFlipper mViewFlipper; |
74 | 75 | private Button mEmergencyDialerButton; |
75 | | - |
| 76 | + private boolean mEnableMenuKey; |
76 | 77 | private boolean mScreenOn; |
77 | 78 | private boolean mIsVerifyUnlockOnly; |
78 | 79 | private int mCurrentSecurityId = SECURITY_SELECTOR_ID; |
@@ -105,6 +106,11 @@ public KeyguardHostView(Context context, AttributeSet attrs) { |
105 | 106 | super(context, attrs); |
106 | 107 | mAppWidgetHost = new AppWidgetHost(mContext, APPWIDGET_HOST_ID, mOnClickHandler); |
107 | 108 | mSecurityModel = new KeyguardSecurityModel(mContext); |
| 109 | + |
| 110 | + // The following enables the MENU key to work for testing automation |
| 111 | + mEnableMenuKey = shouldEnableMenuKey(); |
| 112 | + setFocusable(true); |
| 113 | + setFocusableInTouchMode(true); |
108 | 114 | } |
109 | 115 |
|
110 | 116 | @Override |
@@ -298,7 +304,7 @@ public void run() { |
298 | 304 |
|
299 | 305 | @Override |
300 | 306 | public void reset() { |
301 | | - |
| 307 | + requestFocus(); |
302 | 308 | } |
303 | 309 |
|
304 | 310 | private KeyguardSecurityView getSecurityView(int securitySelectorId) { |
@@ -440,4 +446,30 @@ public void cleanUp() { |
440 | 446 |
|
441 | 447 | } |
442 | 448 |
|
| 449 | + /** |
| 450 | + * In general, we enable unlocking the insecure keyguard with the menu key. However, there are |
| 451 | + * some cases where we wish to disable it, notably when the menu button placement or technology |
| 452 | + * is prone to false positives. |
| 453 | + * |
| 454 | + * @return true if the menu key should be enabled |
| 455 | + */ |
| 456 | + private static final String ENABLE_MENU_KEY_FILE = "/data/local/enable_menu_key"; |
| 457 | + private boolean shouldEnableMenuKey() { |
| 458 | + final Resources res = getResources(); |
| 459 | + final boolean configDisabled = res.getBoolean(R.bool.config_disableMenuKeyInLockScreen); |
| 460 | + final boolean isTestHarness = ActivityManager.isRunningInTestHarness(); |
| 461 | + final boolean fileOverride = (new File(ENABLE_MENU_KEY_FILE)).exists(); |
| 462 | + return !configDisabled || isTestHarness || fileOverride; |
| 463 | + } |
| 464 | + |
| 465 | + @Override |
| 466 | + public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 467 | + if (keyCode == KeyEvent.KEYCODE_MENU && mEnableMenuKey) { |
| 468 | + showNextSecurityScreenOrFinish(false); |
| 469 | + return true; |
| 470 | + } else { |
| 471 | + return super.onKeyDown(keyCode, event); |
| 472 | + } |
| 473 | + } |
| 474 | + |
443 | 475 | } |
0 commit comments