Merge "Simplify AOA key actions"
diff --git a/libraries/aoa-helper/src/com/android/helper/aoa/AoaDevice.java b/libraries/aoa-helper/src/com/android/helper/aoa/AoaDevice.java
index 7aa19e8..b43690f 100644
--- a/libraries/aoa-helper/src/com/android/helper/aoa/AoaDevice.java
+++ b/libraries/aoa-helper/src/com/android/helper/aoa/AoaDevice.java
@@ -22,11 +22,12 @@
 import com.google.common.primitives.Bytes;
 import com.google.common.util.concurrent.Uninterruptibles;
 
-import java.awt.*;
+import java.awt.Point;
 import java.time.Duration;
 import java.time.Instant;
 import java.util.Arrays;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.TimeUnit;
 
@@ -243,38 +244,23 @@
     }
 
     /**
-     * Write a string by pressing keys. Only alphanumeric characters and whitespace is supported.
+     * Press a combination of keys.
      *
-     * @param value string to write
+     * @param keys key HID usages, see <a
+     *     https://source.android.com/devices/input/keyboard-devices">Keyboard devices</a>
      */
-    public void write(@Nonnull String value) {
-        // map characters to HID usages
-        Integer[] keyCodes =
-                value.codePoints()
-                        .mapToObj(
-                                c -> {
-                                    if (Character.isSpaceChar(c)) {
-                                        return 0x2C;
-                                    } else if (Character.isAlphabetic(c)) {
-                                        return Character.toLowerCase(c) - 'a' + 0x04;
-                                    } else if (Character.isDigit(c)) {
-                                        return c == '0' ? 0x27 : c - '1' + 0x1E;
-                                    }
-                                    return null;
-                                })
-                        .toArray(Integer[]::new);
-        // press the keys
-        key(keyCodes);
+    public void pressKeys(Integer... keys) {
+        pressKeys(Arrays.asList(keys));
     }
 
     /**
-     * Press a key.
+     * Press a combination of keys.
      *
-     * @param keyCodes key HID usages, see <a
+     * @param keys list of key HID usages, see <a
      *     https://source.android.com/devices/input/keyboard-devices">Keyboard devices</a>
      */
-    public void key(Integer... keyCodes) {
-        Iterator<Integer> it = Arrays.stream(keyCodes).filter(Objects::nonNull).iterator();
+    public void pressKeys(@Nonnull List<Integer> keys) {
+        Iterator<Integer> it = keys.stream().filter(Objects::nonNull).iterator();
         while (it.hasNext()) {
             Integer keyCode = it.next();
             send(HID.KEYBOARD, new byte[] {keyCode.byteValue()}, STEP_DELAY);
diff --git a/libraries/aoa-helper/tests/src/com/android/helper/aoa/AoaDeviceTest.java b/libraries/aoa-helper/tests/src/com/android/helper/aoa/AoaDeviceTest.java
index 2945a74..f40c153 100644
--- a/libraries/aoa-helper/tests/src/com/android/helper/aoa/AoaDeviceTest.java
+++ b/libraries/aoa-helper/tests/src/com/android/helper/aoa/AoaDeviceTest.java
@@ -245,17 +245,9 @@
     }
 
     @Test
-    public void testWrite() {
-        mDevice = spy(createDevice());
-        mDevice.write("Test #0123!");
-
-        verify(mDevice).key(0x17, 0x08, 0x16, 0x17, 0x2C, null, 0x27, 0x1E, 0x1F, 0x20, null);
-    }
-
-    @Test
-    public void testKey() {
+    public void testPressKeys() {
         mDevice = createDevice();
-        mDevice.key(1, null, 2);
+        mDevice.pressKeys(1, null, 2);
 
         InOrder order = inOrder(mDelegate);
         // press and release 1