Uinput command: allow duplicate configuration entries for a type

Make the uinput command more robust by allowing multiple configuration
entries for the same "type" by concatenating the "data".

With this change, the following configuration:

  "configuration": [
    {"type": 100, "data": [1, 3]}  // UI_SET_EVBIT : EV_KEY, EV_ABS
  ]

can also be written as:

  "configuration": [
    {"type": 100, "data": [1]},  // UI_SET_EVBIT : EV_KEY
    {"type": 100, "data": [3]}   // UI_SET_EVBIT : EV_ABS
  ]

Bug: 240493155
Test: atest TouchScreenTest
Change-Id: Id18d42ceba28ac68b02ef12525cd2384c948f9a8
diff --git a/cmds/uinput/src/com/android/commands/uinput/Event.java b/cmds/uinput/src/com/android/commands/uinput/Event.java
index 9add310e..4b090f5 100644
--- a/cmds/uinput/src/com/android/commands/uinput/Event.java
+++ b/cmds/uinput/src/com/android/commands/uinput/Event.java
@@ -25,6 +25,7 @@
 import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.stream.IntStream;
 
 import src.com.android.commands.uinput.InputAbsInfo;
 
@@ -338,7 +339,7 @@
                 mReader.beginArray();
                 while (mReader.hasNext()) {
                     int type = 0;
-                    int[] data = null;
+                    IntStream data = null;
                     mReader.beginObject();
                     while (mReader.hasNext()) {
                         String name = mReader.nextName();
@@ -347,8 +348,7 @@
                                 type = readInt();
                                 break;
                             case "data":
-                                data = readIntList().stream()
-                                            .mapToInt(Integer::intValue).toArray();
+                                data = readIntList().stream().mapToInt(Integer::intValue);
                                 break;
                             default:
                                 consumeRemainingElements();
@@ -359,7 +359,9 @@
                     }
                     mReader.endObject();
                     if (data != null) {
-                        configuration.put(type, data);
+                        final int[] existing = configuration.get(type);
+                        configuration.put(type, existing == null ? data.toArray()
+                                : IntStream.concat(IntStream.of(existing), data).toArray());
                     }
                 }
                 mReader.endArray();