aboutsummaryrefslogtreecommitdiff
path: root/third_party/sl4a/src
diff options
context:
space:
mode:
authorKeith Dart <keith.dart@gmail.com>2017-12-15 19:40:09 -0800
committerAng Li <angli@google.com>2017-12-15 19:40:09 -0800
commitaeddc8bcd123ddf6c865622464001fe0f3835b87 (patch)
tree2497bdc66fbe0df6b5990d0b71479b520eed6620 /third_party/sl4a/src
parentf48f37f7a4de86306cc7193d92b464fab491b67b (diff)
downloadmobly-snippet-lib-aeddc8bcd123ddf6c865622464001fe0f3835b87.tar.gz
Update gradle, dependency versions and fix lint reported issues (#80)
* Update to latest build tools. * Fix lint issues and reformat. * Add presubmit target. * Fix IDE reported issues. * Fix test runner versions in example. * Review feedback changes. * Make getPrivateInetAddress a private method.
Diffstat (limited to 'third_party/sl4a/src')
-rw-r--r--third_party/sl4a/src/main/java/com/google/android/mobly/snippet/SnippetRunner.java3
-rw-r--r--third_party/sl4a/src/main/java/com/google/android/mobly/snippet/event/EventCache.java9
-rw-r--r--third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/SnippetManager.java6
-rw-r--r--third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/MethodDescriptor.java2
-rw-r--r--third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java31
-rw-r--r--third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/Log.java24
-rw-r--r--third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/RpcUtil.java3
7 files changed, 31 insertions, 47 deletions
diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/SnippetRunner.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/SnippetRunner.java
index fbd4a4a..f79a4b4 100644
--- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/SnippetRunner.java
+++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/SnippetRunner.java
@@ -28,6 +28,7 @@ import com.google.android.mobly.snippet.util.Log;
import com.google.android.mobly.snippet.util.NotificationIdFactory;
import java.io.IOException;
import java.net.SocketException;
+import java.util.Locale;
/**
* A launcher that starts the snippet server as an instrumentation so that it has access to the
@@ -116,7 +117,7 @@ public class SnippetRunner extends AndroidJUnitRunner {
if (actionStr == null) {
throw new IllegalArgumentException("\"--e action <action>\" was not specified");
}
- Action action = Action.valueOf(actionStr.toUpperCase());
+ Action action = Action.valueOf(actionStr.toUpperCase(Locale.ROOT));
switch (action) {
case START:
String servicePort = mArguments.getString(ARG_PORT);
diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/event/EventCache.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/event/EventCache.java
index d150987..a3106f5 100644
--- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/event/EventCache.java
+++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/event/EventCache.java
@@ -19,6 +19,7 @@ package com.google.android.mobly.snippet.event;
import com.google.android.mobly.snippet.util.Log;
import java.util.Deque;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
import java.util.concurrent.LinkedBlockingDeque;
@@ -54,7 +55,7 @@ public class EventCache {
}
public static String getQueueId(String callbackId, String name) {
- return String.format(EVENT_DEQUE_ID_TEMPLATE, callbackId, name);
+ return String.format(Locale.US, EVENT_DEQUE_ID_TEMPLATE, callbackId, name);
}
public LinkedBlockingDeque<SnippetEvent> getEventDeque(String qId) {
@@ -84,11 +85,13 @@ public class EventCache {
SnippetEvent retiredEvent = q.removeFirst();
Log.v(
String.format(
+ Locale.US,
"Retired event %s due to deque reaching the size limit (%s).",
- retiredEvent, EVENT_DEQUE_MAX_SIZE));
+ retiredEvent,
+ EVENT_DEQUE_MAX_SIZE));
}
}
- Log.v(String.format("Posted event(%s)", qId));
+ Log.v(String.format(Locale.US, "Posted event(%s)", qId));
}
/** Clears all cached events. */
diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/SnippetManager.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/SnippetManager.java
index 66e33b3..3fceb36 100644
--- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/SnippetManager.java
+++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/manager/SnippetManager.java
@@ -37,6 +37,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@@ -111,8 +112,11 @@ public class SnippetManager {
if (Build.VERSION.SDK_INT < requiredSdkLevel) {
throw new SnippetLibException(
String.format(
+ Locale.US,
"%s requires API level %d, current level is %d",
- method.getName(), requiredSdkLevel, Build.VERSION.SDK_INT));
+ method.getName(),
+ requiredSdkLevel,
+ Build.VERSION.SDK_INT));
}
}
Snippet object;
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 bc9bd48..185b7be 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
@@ -26,6 +26,7 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Locale;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -226,6 +227,7 @@ public final class MethodDescriptor {
}
String help =
String.format(
+ Locale.US,
"%s %s(%s) returns %s // %s",
isAsync() ? "@AsyncRpc" : "@Rpc",
mMethod.getName(),
diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java
index 8d86723..db7255a 100644
--- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java
+++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java
@@ -40,7 +40,7 @@ import org.json.JSONObject;
public abstract class SimpleServer {
private static int threadIndex = 0;
private final ConcurrentHashMap<Integer, ConnectionThread> mConnectionThreads =
- new ConcurrentHashMap<Integer, ConnectionThread>();
+ new ConcurrentHashMap<>();
private final List<SimpleServerObserver> mObservers = new ArrayList<>();
private volatile boolean mStopServer = false;
private ServerSocket mServer;
@@ -134,12 +134,7 @@ public abstract class SimpleServer {
}
}
- /** Returns the number of active connections to this server. */
- public int getNumberOfConnections() {
- return mConnectionThreads.size();
- }
-
- public static InetAddress getPrivateInetAddress() throws UnknownHostException, SocketException {
+ private InetAddress getPrivateInetAddress() throws UnknownHostException, SocketException {
InetAddress candidate = null;
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
@@ -162,28 +157,6 @@ public abstract class SimpleServer {
return InetAddress.getLocalHost(); // No damn matches. Give up, return local host.
}
- public static InetAddress getPublicInetAddress() throws UnknownHostException, SocketException {
-
- InetAddress candidate = null;
- Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
- for (NetworkInterface netint : Collections.list(nets)) {
- if (netint.isLoopback() || !netint.isUp()) { // Ignore if localhost or not active
- continue;
- }
- Enumeration<InetAddress> addresses = netint.getInetAddresses();
- for (InetAddress address : Collections.list(addresses)) {
- if (address instanceof Inet4Address) {
- return address; // Prefer ipv4
- }
- candidate = address; // Probably an ipv6
- }
- }
- if (candidate != null) {
- return candidate; // return ipv6 address if no suitable ipv6
- }
- return InetAddress.getLocalHost(); // No damn matches. Give up, return local host.
- }
-
/**
* Starts the RPC server bound to the localhost address.
*
diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/Log.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/Log.java
index 81018f7..64f03e9 100644
--- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/Log.java
+++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/Log.java
@@ -77,22 +77,22 @@ public final class Log {
// Do not used hard-coded stack depth: that does not work all the time because of proguard
// inline optimization.
for (int i = STACK_TRACE_WALK_START_INDEX; i < stackTraceElements.length; i++) {
- StackTraceElement element = stackTraceElements[i];
- fullClassName = element.getClassName();
- if (!fullClassName.equals(MY_CLASS_NAME) &&
- !fullClassName.equals(ANDROID_LOG_CLASS_NAME)) {
- lineNumber = element.getLineNumber();
- isCallerClassNameFound = true;
- break;
- }
+ StackTraceElement element = stackTraceElements[i];
+ fullClassName = element.getClassName();
+ if (!fullClassName.equals(MY_CLASS_NAME)
+ && !fullClassName.equals(ANDROID_LOG_CLASS_NAME)) {
+ lineNumber = element.getLineNumber();
+ isCallerClassNameFound = true;
+ break;
+ }
}
if (!isCallerClassNameFound) {
- // Failed to determine caller's class name, fall back the the minimal one.
- return logTag;
+ // Failed to determine caller's class name, fall back the the minimal one.
+ return logTag;
} else {
- String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1);
- return logTag + "." + className + ":" + lineNumber;
+ String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1);
+ return logTag + "." + className + ":" + lineNumber;
}
}
diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/RpcUtil.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/RpcUtil.java
index 7eba07f..4601e93 100644
--- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/RpcUtil.java
+++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/util/RpcUtil.java
@@ -22,6 +22,7 @@ import com.google.android.mobly.snippet.manager.SnippetManager;
import com.google.android.mobly.snippet.rpc.JsonRpcResult;
import com.google.android.mobly.snippet.rpc.MethodDescriptor;
import com.google.android.mobly.snippet.rpc.RpcError;
+import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import org.json.JSONArray;
@@ -99,7 +100,7 @@ public class RpcUtil {
*/
public JSONObject invokeRpc(String methodName, JSONArray params, int id, Integer UID)
throws JSONException {
- return invokeRpc(methodName, params, id, String.format("%d-%d", UID, id));
+ return invokeRpc(methodName, params, id, String.format(Locale.US, "%d-%d", UID, id));
}
/**