Revert "Take the input device into account for meta state"
This reverts commit 8a1597b39632956cdbcb6b76874ccca786047d4c. That
commit broke some of the handling of meta state, which in turn caused
CTS test failures, notably bug 10210151 (CTS:
android.text.method.cts.BaseKeyListenerTest#testBackspace_withSendKeys
is failing on KLP).
So this revert fixes those test failures, but leaves bug 8303489
(Pressing shift on the hardware keyboard messes with unrelated
keypresses, including virtual ones) still present. We'll plan to
address that in a future release.
Change-Id: Iea42c643b6d08f33cbd2ed1747e8de3b5f8116a6
diff --git a/api/current.txt b/api/current.txt
index 4624c60..0d65629 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -24925,9 +24925,7 @@
method public static void clearMetaKeyState(android.text.Editable, int);
method public long clearMetaKeyState(long, int);
method public static final int getMetaState(java.lang.CharSequence);
- method public static final int getMetaState(java.lang.CharSequence, android.view.KeyEvent);
method public static final int getMetaState(java.lang.CharSequence, int);
- method public static final int getMetaState(java.lang.CharSequence, int, android.view.KeyEvent);
method public static final int getMetaState(long);
method public static final int getMetaState(long, int);
method public static long handleKeyDown(long, int, android.view.KeyEvent);
diff --git a/core/java/android/text/method/ArrowKeyMovementMethod.java b/core/java/android/text/method/ArrowKeyMovementMethod.java
index ba6f1d4..30bb447 100644
--- a/core/java/android/text/method/ArrowKeyMovementMethod.java
+++ b/core/java/android/text/method/ArrowKeyMovementMethod.java
@@ -56,7 +56,7 @@
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.getRepeatCount() == 0
&& MetaKeyKeyListener.getMetaState(buffer,
- MetaKeyKeyListener.META_SELECTING, event) != 0) {
+ MetaKeyKeyListener.META_SELECTING) != 0) {
return widget.showContextMenu();
}
}
diff --git a/core/java/android/text/method/BaseKeyListener.java b/core/java/android/text/method/BaseKeyListener.java
index 63607fa..4fede32 100644
--- a/core/java/android/text/method/BaseKeyListener.java
+++ b/core/java/android/text/method/BaseKeyListener.java
@@ -75,7 +75,7 @@
}
// Alt+Backspace or Alt+ForwardDelete deletes the current line, if possible.
- if (getMetaState(content, META_ALT_ON, event) == 1) {
+ if (event.isAltPressed() || getMetaState(content, META_ALT_ON) == 1) {
if (deleteLine(view, content)) {
return true;
}
diff --git a/core/java/android/text/method/BaseMovementMethod.java b/core/java/android/text/method/BaseMovementMethod.java
index 155a2c4..113a4be 100644
--- a/core/java/android/text/method/BaseMovementMethod.java
+++ b/core/java/android/text/method/BaseMovementMethod.java
@@ -135,7 +135,7 @@
*/
protected int getMovementMetaState(Spannable buffer, KeyEvent event) {
// We ignore locked modifiers and SHIFT.
- int metaState = MetaKeyKeyListener.getMetaState(buffer, event)
+ int metaState = (event.getMetaState() | MetaKeyKeyListener.getMetaState(buffer))
& ~(MetaKeyKeyListener.META_ALT_LOCKED | MetaKeyKeyListener.META_SYM_LOCKED);
return KeyEvent.normalizeMetaState(metaState) & ~KeyEvent.META_SHIFT_MASK;
}
diff --git a/core/java/android/text/method/DialerKeyListener.java b/core/java/android/text/method/DialerKeyListener.java
index bb8b0de..ce51fae 100644
--- a/core/java/android/text/method/DialerKeyListener.java
+++ b/core/java/android/text/method/DialerKeyListener.java
@@ -53,7 +53,7 @@
* from the KeyEvent.
*/
protected int lookup(KeyEvent event, Spannable content) {
- int meta = getMetaState(content, event);
+ int meta = event.getMetaState() | getMetaState(content);
int number = event.getNumber();
/*
diff --git a/core/java/android/text/method/MetaKeyKeyListener.java b/core/java/android/text/method/MetaKeyKeyListener.java
index e9db5fd..5ebb957 100644
--- a/core/java/android/text/method/MetaKeyKeyListener.java
+++ b/core/java/android/text/method/MetaKeyKeyListener.java
@@ -163,29 +163,6 @@
getActive(text, SELECTING, META_SELECTING, META_SELECTING);
}
- /**
- * Gets the state of the meta keys for a specific key event.
- *
- * For input devices that use toggled key modifiers, the `toggled' state
- * is stored into the text buffer. This method retrieves the meta state
- * for this event, accounting for the stored state. If the event has been
- * created by a device that does not support toggled key modifiers, like
- * a virtual device for example, the stored state is ignored.
- *
- * @param text the buffer in which the meta key would have been pressed.
- * @param event the event for which to evaluate the meta state.
- * @return an integer in which each bit set to one represents a pressed
- * or locked meta key.
- */
- public static final int getMetaState(final CharSequence text, final KeyEvent event) {
- int metaState = event.getMetaState();
- if (event.getKeyCharacterMap().getModifierBehavior()
- == KeyCharacterMap.MODIFIER_BEHAVIOR_CHORDED_OR_TOGGLED) {
- metaState |= getMetaState(text);
- }
- return metaState;
- }
-
// As META_SELECTING is @hide we should not mention it in public comments, hence the
// omission in @param meta
/**
@@ -215,37 +192,6 @@
}
}
- /**
- * Gets the state of a particular meta key to use with a particular key event.
- *
- * If the key event has been created by a device that does not support toggled
- * key modifiers, like a virtual keyboard for example, only the meta state in
- * the key event is considered.
- *
- * @param meta META_SHIFT_ON, META_ALT_ON, META_SYM_ON
- * @param text the buffer in which the meta key would have been pressed.
- * @param event the event for which to evaluate the meta state.
- * @return 0 if inactive, 1 if active, 2 if locked.
- */
- public static final int getMetaState(final CharSequence text, final int meta,
- final KeyEvent event) {
- int metaState = event.getMetaState();
- if (event.getKeyCharacterMap().getModifierBehavior()
- == KeyCharacterMap.MODIFIER_BEHAVIOR_CHORDED_OR_TOGGLED) {
- metaState |= getMetaState(text);
- }
- if (META_SELECTING == meta) {
- // #getMetaState(long, int) does not support META_SELECTING, but we want the same
- // behavior as #getMetaState(CharSequence, int) so we need to do it here
- if ((metaState & META_SELECTING) != 0) {
- // META_SELECTING is only ever set to PRESSED and can't be LOCKED, so return 1
- return 1;
- }
- return 0;
- }
- return getMetaState(metaState, meta);
- }
-
private static int getActive(CharSequence text, Object meta,
int on, int lock) {
if (!(text instanceof Spanned)) {
diff --git a/core/java/android/text/method/NumberKeyListener.java b/core/java/android/text/method/NumberKeyListener.java
index 988d566..5d4c732 100644
--- a/core/java/android/text/method/NumberKeyListener.java
+++ b/core/java/android/text/method/NumberKeyListener.java
@@ -41,7 +41,7 @@
protected abstract char[] getAcceptedChars();
protected int lookup(KeyEvent event, Spannable content) {
- return event.getMatch(getAcceptedChars(), getMetaState(content, event));
+ return event.getMatch(getAcceptedChars(), event.getMetaState() | getMetaState(content));
}
public CharSequence filter(CharSequence source, int start, int end,
diff --git a/core/java/android/text/method/QwertyKeyListener.java b/core/java/android/text/method/QwertyKeyListener.java
index 0bd46bc..98316ae 100644
--- a/core/java/android/text/method/QwertyKeyListener.java
+++ b/core/java/android/text/method/QwertyKeyListener.java
@@ -108,7 +108,7 @@
// QWERTY keyboard normal case
- int i = event.getUnicodeChar(getMetaState(content, event));
+ int i = event.getUnicodeChar(event.getMetaState() | getMetaState(content));
if (!mFullKeyboard) {
int count = event.getRepeatCount();