am 6817946f: Merge change 25601 into eclair
Merge commit '6817946fd0a009a554f6c0aae1b6c608ebd531c5' into eclair-plus-aosp
* commit '6817946fd0a009a554f6c0aae1b6c608ebd531c5':
Fix possible race condition when switching keyboards while there are pending messages.
diff --git a/core/java/android/inputmethodservice/KeyboardView.java b/core/java/android/inputmethodservice/KeyboardView.java
index a141a2a..e59a987 100755
--- a/core/java/android/inputmethodservice/KeyboardView.java
+++ b/core/java/android/inputmethodservice/KeyboardView.java
@@ -408,6 +408,8 @@
if (mKeyboard != null) {
showPreview(NOT_A_KEY);
}
+ // Remove any pending messages
+ removeMessages();
mKeyboard = keyboard;
List<Key> keys = mKeyboard.getKeys();
mKeys = keys.toArray(new Key[keys.size()]);
@@ -828,6 +830,7 @@
private void showKey(final int keyIndex) {
final PopupWindow previewPopup = mPreviewPopup;
final Key[] keys = mKeys;
+ if (keyIndex < 0 || keyIndex >= mKeys.length) return;
Key key = keys[keyIndex];
if (key.icon != null) {
mPreviewText.setCompoundDrawables(null, null, null,
@@ -1145,9 +1148,7 @@
break;
case MotionEvent.ACTION_UP:
- mHandler.removeMessages(MSG_SHOW_PREVIEW);
- mHandler.removeMessages(MSG_REPEAT);
- mHandler.removeMessages(MSG_LONGPRESS);
+ removeMessages();
if (keyIndex == mCurrentKey) {
mCurrentKeyTime += eventTime - mLastMoveTime;
} else {
@@ -1203,16 +1204,20 @@
if (mPreviewPopup.isShowing()) {
mPreviewPopup.dismiss();
}
- mHandler.removeMessages(MSG_REPEAT);
- mHandler.removeMessages(MSG_LONGPRESS);
- mHandler.removeMessages(MSG_SHOW_PREVIEW);
+ removeMessages();
dismissPopupKeyboard();
mBuffer = null;
mCanvas = null;
mMiniKeyboardCache.clear();
}
-
+
+ private void removeMessages() {
+ mHandler.removeMessages(MSG_REPEAT);
+ mHandler.removeMessages(MSG_LONGPRESS);
+ mHandler.removeMessages(MSG_SHOW_PREVIEW);
+ }
+
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();