diff options
author | Kolin Lu <kolinlu@google.com> | 2023-05-15 18:20:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-15 18:20:51 -0700 |
commit | d1e43897a7b08549a2b1804623f3e680e87c5b45 (patch) | |
tree | a3f0123a586531bf637e68b34a7610161762b031 | |
parent | c38e059a7750ee7af53f37e495d96889a9b4718f (diff) | |
parent | 22ce03c84d3dc5b5697302a2ef4a2ea9f96c6eeb (diff) | |
download | mobly-snippet-lib-d1e43897a7b08549a2b1804623f3e680e87c5b45.tar.gz |
Merge pull request #126 from ko1in1u/master
Deprecate non-primitive array types and enable checked warnings in Js…
3 files changed, 7 insertions, 52 deletions
diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/JsonBuilder.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/JsonBuilder.java index 42629d8..f543b62 100644 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/JsonBuilder.java +++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/JsonBuilder.java @@ -21,9 +21,6 @@ import android.content.Intent; import android.os.Bundle; import android.os.ParcelUuid; import com.google.android.mobly.snippet.manager.SnippetObjectConverterManager; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -34,11 +31,11 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +/** Builds the result for JSON RPC. */ public class JsonBuilder { private JsonBuilder() {} - @SuppressWarnings("unchecked") public static Object build(Object data) throws JSONException { if (data == null) { return JSONObject.NULL; @@ -89,21 +86,11 @@ public class JsonBuilder { } if (data instanceof Map<?, ?>) { // TODO(damonkohler): I would like to make this a checked cast if possible. - return buildJsonMap((Map<String, ?>) data); + return buildJsonMap((Map<?, ?>) data); } if (data instanceof ParcelUuid) { return data.toString(); } - // TODO(xpconanfan): Deprecate the following default non-primitive type builders. - if (data instanceof InetSocketAddress) { - return buildInetSocketAddress((InetSocketAddress) data); - } - if (data instanceof InetAddress) { - return buildInetAddress((InetAddress) data); - } - if (data instanceof URL) { - return buildURL((URL) data); - } if (data.getClass().isArray()) { return buildJSONArray(data); } @@ -115,20 +102,6 @@ public class JsonBuilder { return data.toString(); } - private static Object buildInetAddress(InetAddress data) { - JSONArray address = new JSONArray(); - address.put(data.getHostName()); - address.put(data.getHostAddress()); - return address; - } - - private static Object buildInetSocketAddress(InetSocketAddress data) { - JSONArray address = new JSONArray(); - address.put(data.getHostName()); - address.put(data.getPort()); - return address; - } - private static JSONArray buildJSONArray(Object data) throws JSONException { JSONArray result = new JSONArray(); if (data instanceof int[]) { @@ -204,25 +177,13 @@ public class JsonBuilder { return result; } - private static JSONObject buildJsonMap(Map<String, ?> map) throws JSONException { + private static JSONObject buildJsonMap(Map<?, ?> map) throws JSONException { JSONObject result = new JSONObject(); - for (Entry<String, ?> entry : map.entrySet()) { - String key = entry.getKey(); - if (key == null) { - key = ""; - } - result.put(key, build(entry.getValue())); + for (Entry<?, ?> entry : map.entrySet()) { + Object key = entry.getKey(); + String keyStr = key == null ? "" : key.toString(); + result.put(keyStr, build(entry.getValue())); } return result; } - - private static Object buildURL(URL data) throws JSONException { - JSONObject url = new JSONObject(); - url.put("Authority", data.getAuthority()); - url.put("Host", data.getHost()); - url.put("Path", data.getPath()); - url.put("Port", data.getPort()); - url.put("Protocol", data.getProtocol()); - return url; - } } 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 467053d..214ffe7 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 @@ -102,10 +102,6 @@ public final class MethodDescriptor { } /** Converts a parameter from JSON into a Java Object. */ - // TODO(damonkohler): This signature is a bit weird (auto-refactored). The obvious alternative - // would be to work on one supplied parameter and return the converted parameter. However, - // that's problematic because you lose the ability to call the getXXX methods on the JSON array. - // @VisibleForTesting private static Object convertParameter(final JSONArray parameters, int index, Type type) throws JSONException, RpcError { try { diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/AndroidUtil.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/AndroidUtil.java index 46c4940..69d5cf6 100644 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/AndroidUtil.java +++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/AndroidUtil.java @@ -25,8 +25,6 @@ import org.json.JSONObject; public final class AndroidUtil { private AndroidUtil() {} - // TODO(damonkohler): Pull this out into proper argument deserialization and support - // complex/nested types being passed in. public static void putExtrasFromJsonObject(JSONObject extras, Intent intent) throws JSONException { JSONArray names = extras.names(); |