aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinghao Li <minghaoli@google.com>2024-03-07 19:33:59 +0800
committerMinghao Li <minghaoli@google.com>2024-03-07 19:33:59 +0800
commit1e1220606e7602082f9f25512b07ac30db29d90f (patch)
tree603a77bf989237fd9dd1176e652354670443fc88
parentecea668846f7306ed27003856a28856c69f5bbb6 (diff)
downloadmobly-snippet-lib-1e1220606e7602082f9f25512b07ac30db29d90f.tar.gz
Support using array types in snippet method arguments.
-rw-r--r--third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java14
1 files changed, 13 insertions, 1 deletions
diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java
index 1186399..6b66e2b 100644
--- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java
+++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java
@@ -35,6 +35,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.stream.IntStream;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -141,6 +142,9 @@ public final class MethodDescriptor {
for (int i = 0; i < list.length(); i++) {
result[i] = list.getInt(i);
}
+ if (type == int[].class) {
+ return Arrays.stream(result).mapToInt(Integer::intValue).toArray();
+ }
return result;
} else if (type == Long[].class || type == long[].class) {
JSONArray list = parameters.getJSONArray(index);
@@ -148,13 +152,21 @@ public final class MethodDescriptor {
for (int i = 0; i < list.length(); i++) {
result[i] = list.getLong(i);
}
+ if (type == long[].class) {
+ return Arrays.stream(result).mapToLong(Long::longValue).toArray();
+ }
return result;
- } else if (type == Byte.class || type == byte[].class) {
+ } else if (type == Byte[].class || type == byte[].class) {
JSONArray list = parameters.getJSONArray(index);
byte[] result = new byte[list.length()];
for (int i = 0; i < list.length(); i++) {
result[i] = (byte) list.getInt(i);
}
+ if (type == Byte[].class) {
+ return IntStream.range(0, result.length)
+ .mapToObj(i -> result[i])
+ .toArray(Byte[]::new);
+ }
return result;
} else if (type == String[].class) {
JSONArray list = parameters.getJSONArray(index);