Skip to content

Commit 5a05f2b

Browse files
Jim MillerAndroid (Google) Code Review
authored andcommitted
Merge "Fix MENU key in keyguard." into jb-mr1-dev
2 parents 9e3045c + 95b005c commit 5a05f2b

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.android.internal.policy.impl.keyguard;
1818

19+
import android.app.ActivityManager;
1920
import android.app.ActivityOptions;
2021
import android.appwidget.AppWidgetHost;
2122
import android.appwidget.AppWidgetHostView;
@@ -25,8 +26,7 @@
2526
import android.content.Intent;
2627
import android.content.IntentSender;
2728
import android.content.SharedPreferences;
28-
import android.content.SharedPreferences.Editor;
29-
import android.content.res.Configuration;
29+
import android.content.res.Resources;
3030
import android.graphics.Canvas;
3131
import android.telephony.TelephonyManager;
3232
import android.util.AttributeSet;
@@ -43,6 +43,7 @@
4343
import com.android.internal.widget.LockPatternUtils;
4444
import com.android.internal.R;
4545

46+
import java.io.File;
4647
import java.util.ArrayList;
4748

4849
public class KeyguardHostView extends KeyguardViewBase {
@@ -72,7 +73,7 @@ public class KeyguardHostView extends KeyguardViewBase {
7273
private ViewGroup mAppWidgetContainer;
7374
private ViewFlipper mViewFlipper;
7475
private Button mEmergencyDialerButton;
75-
76+
private boolean mEnableMenuKey;
7677
private boolean mScreenOn;
7778
private boolean mIsVerifyUnlockOnly;
7879
private int mCurrentSecurityId = SECURITY_SELECTOR_ID;
@@ -105,6 +106,11 @@ public KeyguardHostView(Context context, AttributeSet attrs) {
105106
super(context, attrs);
106107
mAppWidgetHost = new AppWidgetHost(mContext, APPWIDGET_HOST_ID, mOnClickHandler);
107108
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);
108114
}
109115

110116
@Override
@@ -298,7 +304,7 @@ public void run() {
298304

299305
@Override
300306
public void reset() {
301-
307+
requestFocus();
302308
}
303309

304310
private KeyguardSecurityView getSecurityView(int securitySelectorId) {
@@ -440,4 +446,30 @@ public void cleanUp() {
440446

441447
}
442448

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+
443475
}

0 commit comments

Comments
 (0)