Merge "Fix UNKNOWN keycode parsing in monkey."
This commit is contained in:
@@ -247,13 +247,17 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
|
||||
// Ok, it wasn't a number, see if we have a
|
||||
// keycode name for it
|
||||
keyCode = MonkeySourceRandom.getKeyCode(keyName);
|
||||
if (keyCode == -1) {
|
||||
if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
|
||||
// OK, one last ditch effort to find a match.
|
||||
// Build the KEYCODE_STRING from the string
|
||||
// we've been given and see if that key
|
||||
// exists. This would allow you to do "key
|
||||
// down menu", for example.
|
||||
keyCode = MonkeySourceRandom.getKeyCode("KEYCODE_" + keyName.toUpperCase());
|
||||
if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
|
||||
// Still unknown
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return keyCode;
|
||||
|
||||
@@ -102,7 +102,7 @@ public class MonkeySourceRandom implements MonkeyEventSource {
|
||||
* be an expensive operation.
|
||||
*
|
||||
* @param keyName the name of the KEYCODE_VALUE to lookup.
|
||||
* @returns the intenger keyCode value, or -1 if not found
|
||||
* @returns the intenger keyCode value, or KeyEvent.KEYCODE_UNKNOWN if not found
|
||||
*/
|
||||
public static int getKeyCode(String keyName) {
|
||||
return KeyEvent.keyCodeFromString(keyName);
|
||||
|
||||
@@ -547,6 +547,9 @@ public class MonkeySourceScript implements MonkeyEventSource {
|
||||
if (s.indexOf(EVENT_KEYWORD_KEYPRESS) >= 0 && args.length == 1) {
|
||||
String key_name = args[0];
|
||||
int keyCode = MonkeySourceRandom.getKeyCode(key_name);
|
||||
if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
|
||||
return;
|
||||
}
|
||||
MonkeyKeyEvent e = new MonkeyKeyEvent(KeyEvent.ACTION_DOWN, keyCode);
|
||||
mQ.addLast(e);
|
||||
e = new MonkeyKeyEvent(KeyEvent.ACTION_UP, keyCode);
|
||||
@@ -772,7 +775,7 @@ public class MonkeySourceScript implements MonkeyEventSource {
|
||||
|
||||
if (e.getEventTime() < 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
updatedDownTime = SystemClock.uptimeMillis();
|
||||
e.setDownTime(updatedDownTime);
|
||||
e.setEventTime(updatedDownTime);
|
||||
|
||||
Reference in New Issue
Block a user