Skip to content

Commit fe635d7

Browse files
committed
Fix crash when a dead key is pressed in the physical keyboard in Android
The root cause of the crash was unawareness of KeyCharacterMap.COMBINING_ACCENT_MASK flag in Mozc's hardware key event handling. The return value of android.view.KeyEvent#getUnicodeChar() should have been masked with KeyCharacterMap.COMBINING_ACCENT_MASK before it is treated as a Unicode character. Note that even with this CL, Mozc for Android still cannot handle dead keys correctly. It should be addressed by another CL. Closes Issue 248. BUG=Issue mozc:248 TEST=manually done with Nexus 5 / Android 5.0.1 (LRX22C) git-svn-id: https://mozc.googlecode.com/svn/trunk@463 a6090854-d499-a067-5803-1114d4e51264
1 parent e9667ee commit fe635d7

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

src/android/src/com/google/android/inputmethod/japanese/hardwarekeyboard/CompactKeyEvent.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.mozc.android.inputmethod.japanese.hardwarekeyboard.KeyEventMapperFactory.KeyEventMapper;
3333
import com.google.common.base.Preconditions;
3434

35+
import android.view.KeyCharacterMap;
3536
import android.view.KeyEvent;
3637

3738
/**
@@ -42,13 +43,18 @@ class CompactKeyEvent {
4243
private int keyCode;
4344
private int metaState;
4445
private int unicodeCharacter;
46+
private int combiningAccent;
4547
private int scanCode;
4648

4749
public CompactKeyEvent(KeyEvent keyEvent) {
4850
Preconditions.checkNotNull(keyEvent);
4951
keyCode = keyEvent.getKeyCode();
5052
metaState = keyEvent.getMetaState();
51-
unicodeCharacter = keyEvent.getUnicodeChar();
53+
int flagedCodepoint = keyEvent.getUnicodeChar();
54+
// TODO(team): Come up with a better definition of the "character" when
55+
// KeyCharacterMap.COMBINING_ACCENT bit is set.
56+
unicodeCharacter = flagedCodepoint & KeyCharacterMap.COMBINING_ACCENT_MASK;
57+
combiningAccent = flagedCodepoint & KeyCharacterMap.COMBINING_ACCENT_MASK;
5258
scanCode = keyEvent.getScanCode();
5359
}
5460

@@ -76,6 +82,14 @@ void setMetaState(int metaState) {
7682
this.metaState = metaState;
7783
}
7884

85+
public int getCombiningAccent() {
86+
return combiningAccent;
87+
}
88+
89+
public int getDeadChar(int character) {
90+
return KeyCharacterMap.getDeadChar(combiningAccent, character);
91+
}
92+
7993
public int getUnicodeCharacter() {
8094
return unicodeCharacter;
8195
}

src/android/src/com/google/android/inputmethod/japanese/hardwarekeyboard/HardwareKeyboardSpecification.java

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public enum HardwareKeyboardSpecification {
116116
*/
117117
@VisibleForTesting
118118
static boolean isPrintable(int codepoint) {
119+
Preconditions.checkArgument(codepoint >= 0);
119120
if (Character.isISOControl(codepoint)) {
120121
return false;
121122
}

src/android/tests/src/com/google/android/inputmethod/japanese/hardwarekeyboard/HardwareKeyboardSpecificationTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import android.test.MoreAsserts;
4848
import android.test.suitebuilder.annotation.SmallTest;
4949
import android.view.InputDevice;
50+
import android.view.KeyCharacterMap;
5051
import android.view.KeyEvent;
5152

5253
import java.util.Collections;
@@ -101,6 +102,18 @@ public int getUnicodeChar() {
101102
assertEquals(keyEvent, keyEventInterface.getNativeEvent());
102103
}
103104

105+
{
106+
KeyEvent keyEvent = new KeyEventMock(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_GRAVE,
107+
0, '`' | KeyCharacterMap.COMBINING_ACCENT);
108+
keyEvent.setSource(InputDevice.SOURCE_KEYBOARD);
109+
110+
ProtoCommands.KeyEvent mozcKeyEvent = keyboardSpecification.getMozcKeyEvent(keyEvent);
111+
assertEquals('`', mozcKeyEvent.getKeyCode());
112+
113+
KeyEventInterface keyEventInterface = keyboardSpecification.getKeyEventInterface(keyEvent);
114+
assertEquals(keyEvent, keyEventInterface.getNativeEvent().orNull());
115+
}
116+
104117
{
105118
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SPACE);
106119
keyEvent.setSource(InputDevice.SOURCE_KEYBOARD);

src/mozc_version_template.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MAJOR=2
22
MINOR=16
3-
BUILD=2002
3+
BUILD=2003
44
REVISION=102
55
# NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
66
# downloaded by NaCl Mozc.

0 commit comments

Comments
 (0)