Revert "Update gradle, dependency versions and fix lint reported issues (#80)" (#82)
This reverts commit aeddc8bcd123ddf6c865622464001fe0f3835b87.
diff --git a/build.gradle b/build.gradle
index 21ab790..4ed31c7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,13 +1,11 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
-// For android studio 2.3 and plugin 2.3.3
buildscript {
repositories {
jcenter()
- google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.0.0'
+ classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@@ -17,7 +15,6 @@
allprojects {
repositories {
jcenter()
- google()
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
@@ -26,3 +23,6 @@
}
}
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
diff --git a/examples/ex1_standalone_app/build.gradle b/examples/ex1_standalone_app/build.gradle
index 1825c7e..29e61b3 100644
--- a/examples/ex1_standalone_app/build.gradle
+++ b/examples/ex1_standalone_app/build.gradle
@@ -1,27 +1,27 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 26
+ compileSdkVersion 24
+ buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.google.android.mobly.snippet.example1"
- minSdkVersion 15
- targetSdkVersion 22
+ minSdkVersion 11
+ targetSdkVersion 24
versionCode 1
versionName "0.0.1"
}
lintOptions {
- abortOnError false
+ abortOnError true
checkAllWarnings true
warningsAsErrors true
- disable 'HardwareIds','MissingApplicationIcon','GoogleAppIndexingWarning','InvalidPackage','OldTargetApi'
}
}
dependencies {
- // The 'implementation project' dep is to compile against the snippet lib source in
+ // The 'compile project' dep is to compile against the snippet lib source in
// this repo. For your own snippets, you'll want to use the regular
- // 'implementation' dep instead:
- //implementation 'com.google.android.mobly:mobly-snippet-lib:1.3.0'
- implementation project(':mobly-snippet-lib')
+ // 'compile' dep instead:
+ //compile 'com.google.android.mobly:mobly-snippet-lib:1.2.0'
+ compile project(':mobly-snippet-lib')
}
diff --git a/examples/ex1_standalone_app/src/main/AndroidManifest.xml b/examples/ex1_standalone_app/src/main/AndroidManifest.xml
index 90ebdea..e1b5cf1 100644
--- a/examples/ex1_standalone_app/src/main/AndroidManifest.xml
+++ b/examples/ex1_standalone_app/src/main/AndroidManifest.xml
@@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.mobly.snippet.example1">
- <application android:allowBackup="false">
+ <application>
<!-- Required: list of all classes with @Rpc methods. -->
<meta-data
android:name="mobly-snippets"
diff --git a/examples/ex2_espresso/build.gradle b/examples/ex2_espresso/build.gradle
index 2757808..a8c0c31 100644
--- a/examples/ex2_espresso/build.gradle
+++ b/examples/ex2_espresso/build.gradle
@@ -1,46 +1,39 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 26
- flavorDimensions "examples"
+ compileSdkVersion 24
+ buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.google.android.mobly.snippet.example2"
- minSdkVersion 15
- targetSdkVersion 22
+ minSdkVersion 11
+ targetSdkVersion 24
versionCode 1
versionName "0.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
productFlavors {
- main {
- dimension "examples"
- }
- snippet {
- dimension "examples"
- }
+ main {}
+ snippet {}
}
-
lintOptions {
abortOnError true
checkAllWarnings true
warningsAsErrors true
- disable 'HardcodedText', 'UnusedIds','MissingApplicationIcon','GoogleAppIndexingWarning','InvalidPackage','OldTargetApi'
}
}
dependencies {
- implementation 'com.android.support:appcompat-v7:26.1.0'
- implementation 'com.android.support.test:runner:1.0.1'
+ compile 'com.android.support:appcompat-v7:24.2.1'
// The androidTest package is not for snippet support; it shows an example
// of an instrumentation test coexisting with a snippet in the same
// codebase.
- androidTestImplementation 'com.android.support:support-annotations:26.1.0'
- androidTestImplementation 'com.android.support.test:runner:1.0.1'
- androidTestImplementation 'com.android.support.test:rules:1.0.1'
- androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
+ androidTestCompile 'com.android.support:support-annotations:24.2.1'
+ androidTestCompile 'com.android.support.test:runner:0.5'
+ androidTestCompile 'com.android.support.test:rules:0.5'
+ androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
@@ -48,8 +41,8 @@
// source in this repo. For your own snippets, you'll want to use the
// regular 'snippetCompile' dep instead:
//snippetCompile 'com.google.android.mobly:mobly-snippet-lib:1.2.0'
- snippetImplementation project(':mobly-snippet-lib')
+ snippetCompile project(':mobly-snippet-lib')
- snippetImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
- snippetImplementation 'com.android.support:support-annotations:26.1.0'
+ snippetCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
+ snippetCompile 'com.android.support:support-annotations:24.2.1'
}
diff --git a/examples/ex2_espresso/src/main/java/com/google/android/mobly/snippet/example2/MainActivity.java b/examples/ex2_espresso/src/main/java/com/google/android/mobly/snippet/example2/MainActivity.java
index 940418a..40311c3 100644
--- a/examples/ex2_espresso/src/main/java/com/google/android/mobly/snippet/example2/MainActivity.java
+++ b/examples/ex2_espresso/src/main/java/com/google/android/mobly/snippet/example2/MainActivity.java
@@ -16,7 +16,6 @@
package com.google.android.mobly.snippet.example2;
-import java.util.Locale;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
@@ -43,7 +42,7 @@
@Override
public void onClick(View v) {
mNumPressed++;
- mTextView.setText(String.format(Locale.ROOT, "Button pressed %d times.", mNumPressed));
+ mTextView.setText("Button pressed " + mNumPressed + " times");
}
});
}
diff --git a/examples/ex2_espresso/src/main/res/layout/activity_main.xml b/examples/ex2_espresso/src/main/res/layout/activity_main.xml
index e190302..013d6a4 100644
--- a/examples/ex2_espresso/src/main/res/layout/activity_main.xml
+++ b/examples/ex2_espresso/src/main/res/layout/activity_main.xml
@@ -8,16 +8,20 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.google.android.mobly.snippet.example2.MainActivity">
-<TextView
- android:id="@+id/main_text_view"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal"
- android:text="Hello World!" />
-
-<Button
- android:id="@+id/main_button"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Push the button!" />
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+ <TextView
+ android:id="@+id/main_text_view"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:text="Hello World!" />
+ <Button
+ android:id="@+id/main_button"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Push the button!" />
+ </LinearLayout>
</RelativeLayout>
diff --git a/examples/ex3_async_event/build.gradle b/examples/ex3_async_event/build.gradle
index 4fb63f9..2fcb8f9 100644
--- a/examples/ex3_async_event/build.gradle
+++ b/examples/ex3_async_event/build.gradle
@@ -1,20 +1,20 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 26
+ compileSdkVersion 24
+ buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.google.android.mobly.snippet.example3"
- minSdkVersion 15
- targetSdkVersion 22
+ minSdkVersion 11
+ targetSdkVersion 24
versionCode 1
versionName "0.0.1"
}
lintOptions {
- abortOnError false
+ abortOnError true
checkAllWarnings true
warningsAsErrors true
- disable 'HardwareIds','MissingApplicationIcon','GoogleAppIndexingWarning','InvalidPackage','OldTargetApi'
}
}
@@ -22,5 +22,5 @@
// The 'compile project' dep is to compile against the snippet lib source in
// this repo. For your own snippets, you'll want to use the regular 'compile' dep instead:
// compile 'com.google.android.mobly:mobly-snippet-lib:1.2.0'
- implementation project(':mobly-snippet-lib')
+ compile project(':mobly-snippet-lib')
}
diff --git a/examples/ex3_async_event/src/main/AndroidManifest.xml b/examples/ex3_async_event/src/main/AndroidManifest.xml
index dcc724b..8e2887c 100644
--- a/examples/ex3_async_event/src/main/AndroidManifest.xml
+++ b/examples/ex3_async_event/src/main/AndroidManifest.xml
@@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.mobly.snippet.example3">
- <application android:allowBackup="false">
+ <application>
<meta-data
android:name="mobly-snippets"
android:value="com.google.android.mobly.snippet.example3.ExampleAsyncSnippet" />
diff --git a/examples/ex4_uiautomator/build.gradle b/examples/ex4_uiautomator/build.gradle
index 1d89fdf..8298d9b 100644
--- a/examples/ex4_uiautomator/build.gradle
+++ b/examples/ex4_uiautomator/build.gradle
@@ -1,20 +1,20 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 26
+ compileSdkVersion 24
+ buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.google.android.mobly.snippet.example4"
minSdkVersion 18
- targetSdkVersion 22
+ targetSdkVersion 24
versionCode 1
- versionName "0.0.2"
+ versionName "0.0.1"
}
lintOptions {
- abortOnError false
+ abortOnError true
checkAllWarnings true
warningsAsErrors true
- disable 'HardwareIds','MissingApplicationIcon','GoogleAppIndexingWarning','InvalidPackage','OldTargetApi'
}
}
@@ -23,9 +23,8 @@
// this repo. For your own snippets, you'll want to use the regular
// 'compile' dep instead:
//compile 'com.google.android.mobly:mobly-snippet-lib:1.2.0'
- implementation project(':mobly-snippet-lib')
- implementation 'junit:junit:4.12'
- implementation 'com.android.support.test:runner:1.0.1'
- implementation 'com.android.support:appcompat-v7:26.1.0'
- implementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
+ compile project(':mobly-snippet-lib')
+
+ compile 'com.android.support:appcompat-v7:24.2.1'
+ compile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
}
diff --git a/examples/ex4_uiautomator/src/main/AndroidManifest.xml b/examples/ex4_uiautomator/src/main/AndroidManifest.xml
index 89d5276..4644ff0 100644
--- a/examples/ex4_uiautomator/src/main/AndroidManifest.xml
+++ b/examples/ex4_uiautomator/src/main/AndroidManifest.xml
@@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.mobly.snippet.example4">
- <application android:allowBackup="false">
+ <application>
<meta-data
android:name="mobly-snippets"
android:value="com.google.android.mobly.snippet.example4.UiAutomatorSnippet" />
diff --git a/examples/ex5_schedule_rpc/build.gradle b/examples/ex5_schedule_rpc/build.gradle
index 53cd5a0..8c25983 100644
--- a/examples/ex5_schedule_rpc/build.gradle
+++ b/examples/ex5_schedule_rpc/build.gradle
@@ -1,20 +1,20 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 26
+ compileSdkVersion 24
+ buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.google.android.mobly.snippet.example5"
- minSdkVersion 15
- targetSdkVersion 22
+ minSdkVersion 11
+ targetSdkVersion 24
versionCode 1
versionName "0.0.1"
}
lintOptions {
- abortOnError false
+ abortOnError true
checkAllWarnings true
warningsAsErrors true
- disable 'HardwareIds','MissingApplicationIcon','GoogleAppIndexingWarning','InvalidPackage','OldTargetApi'
}
}
@@ -22,6 +22,5 @@
// The 'compile project' dep is to compile against the snippet lib source in
// this repo. For your own snippets, you'll want to use the regular 'compile' dep instead:
// compile 'com.google.android.mobly:mobly-snippet-lib:1.1.0'
- implementation project(':mobly-snippet-lib')
- implementation 'com.android.support.test:runner:1.0.1'
+ compile project(':mobly-snippet-lib')
}
diff --git a/examples/ex5_schedule_rpc/src/main/AndroidManifest.xml b/examples/ex5_schedule_rpc/src/main/AndroidManifest.xml
index 9a3271c..cef56e6 100644
--- a/examples/ex5_schedule_rpc/src/main/AndroidManifest.xml
+++ b/examples/ex5_schedule_rpc/src/main/AndroidManifest.xml
@@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.mobly.snippet.example5">
- <application android:allowBackup="false">
+ <application>
<meta-data
android:name="mobly-snippets"
android:value="com.google.android.mobly.snippet.example5.ExampleScheduleRpcSnippet" />
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 06228b6..1652023 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Oct 04 16:01:04 PDT 2017
+#Tue Jun 20 10:15:00 PDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
diff --git a/third_party/sl4a/build.gradle b/third_party/sl4a/build.gradle
index 46c3797..3492848 100644
--- a/third_party/sl4a/build.gradle
+++ b/third_party/sl4a/build.gradle
@@ -1,68 +1,44 @@
buildscript {
repositories {
jcenter()
- google()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
- classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
+ classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
plugins {
id 'com.github.sherter.google-java-format' version '0.6'
- id 'com.github.dcendents.android-maven' version '2.0'
}
-
apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.bintray'
-
+apply plugin: 'com.github.dcendents.android-maven'
android {
- compileSdkVersion 26
+ compileSdkVersion 24
+ buildToolsVersion '25.0.0'
defaultConfig {
- minSdkVersion 15
- targetSdkVersion 22
- // testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+ minSdkVersion 11
+ targetSdkVersion 24
versionCode VERSION_CODE.toInteger()
versionName VERSION_NAME
-
// Need to set up some project properties to publish to bintray.
project.group = GROUP_ID
project.archivesBaseName = ARTIFACT_ID
project.version = VERSION_NAME
}
-
- splits {
- abi {
- enable true
- reset()
- // Specifies a list of ABIs that Gradle should create APKs for.
- include "arm64-v8a", "armeabi-v7a", "armeabi"
- universalApk true
- }
- }
-
lintOptions {
- abortOnError false
+ abortOnError true
checkAllWarnings true
warningsAsErrors true
- disable 'HardwareIds','MissingApplicationIcon','GoogleAppIndexingWarning','InvalidPackage','OldTargetApi'
- }
-
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
- // implementation fileTree(include: ['*.jar'], dir: 'libs')
- // implementation 'com.android.support:appcompat-v7:26.1.0'
- implementation 'junit:junit:4.12'
- implementation 'com.android.support.test:runner:1.0.1'
+ compile 'com.android.support.test:runner:0.5'
}
googleJavaFormat {
@@ -167,26 +143,3 @@
}
}
}
-
-// Open lint's HTML report in your default browser or viewer.
-task openLintReport(type: Exec) {
- def lint_report = "build/reports/lint-results.html"
- def cmd = "cat"
- def platform = System.getProperty('os.name').toLowerCase(Locale.ROOT)
- if (platform.contains("linux")) {
- cmd = "xdg-open"
- } else if (platform.contains("mac os x")) {
- cmd = "open"
- } else if (platform.contains("windows")) {
- cmd = "launch"
- }
- commandLine cmd, lint_report
-}
-
-task presubmit {
- dependsOn { ['googleJavaFormat', 'lint', 'openLintReport'] }
- doLast {
- println "Fix any lint issues you see. When it looks good, submit the pull request."
- }
-}
-
diff --git a/third_party/sl4a/gradle.properties b/third_party/sl4a/gradle.properties
index 1146440..b1c5a0a 100644
--- a/third_party/sl4a/gradle.properties
+++ b/third_party/sl4a/gradle.properties
@@ -1,6 +1,6 @@
# This version code implements the versioning recommendations in:
# https://blog.jayway.com/2015/03/11/automatic-versioncode-generation-in-android-gradle/
-VERSION_CODE=1030000
-VERSION_NAME=1.3
+VERSION_CODE=1020100
+VERSION_NAME=1.2.1-SNAPSHOT
GROUP_ID=com.google.android.mobly
ARTIFACT_ID=mobly-snippet-lib
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 f79a4b4..fbd4a4a 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,7 +28,6 @@
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
@@ -117,7 +116,7 @@
if (actionStr == null) {
throw new IllegalArgumentException("\"--e action <action>\" was not specified");
}
- Action action = Action.valueOf(actionStr.toUpperCase(Locale.ROOT));
+ Action action = Action.valueOf(actionStr.toUpperCase());
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 a3106f5..d150987 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,7 +19,6 @@
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;
@@ -55,7 +54,7 @@
}
public static String getQueueId(String callbackId, String name) {
- return String.format(Locale.US, EVENT_DEQUE_ID_TEMPLATE, callbackId, name);
+ return String.format(EVENT_DEQUE_ID_TEMPLATE, callbackId, name);
}
public LinkedBlockingDeque<SnippetEvent> getEventDeque(String qId) {
@@ -85,13 +84,11 @@
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(Locale.US, "Posted event(%s)", qId));
+ Log.v(String.format("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 3fceb36..66e33b3 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,7 +37,6 @@
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;
@@ -112,11 +111,8 @@
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 185b7be..bc9bd48 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,7 +26,6 @@
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;
@@ -227,7 +226,6 @@
}
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 db7255a..8d86723 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 @@
public abstract class SimpleServer {
private static int threadIndex = 0;
private final ConcurrentHashMap<Integer, ConnectionThread> mConnectionThreads =
- new ConcurrentHashMap<>();
+ new ConcurrentHashMap<Integer, ConnectionThread>();
private final List<SimpleServerObserver> mObservers = new ArrayList<>();
private volatile boolean mStopServer = false;
private ServerSocket mServer;
@@ -134,7 +134,12 @@
}
}
- private InetAddress getPrivateInetAddress() throws UnknownHostException, SocketException {
+ /** Returns the number of active connections to this server. */
+ public int getNumberOfConnections() {
+ return mConnectionThreads.size();
+ }
+
+ public static InetAddress getPrivateInetAddress() throws UnknownHostException, SocketException {
InetAddress candidate = null;
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
@@ -157,6 +162,28 @@
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 64f03e9..81018f7 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 @@
// 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 4601e93..7eba07f 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,7 +22,6 @@
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;
@@ -100,7 +99,7 @@
*/
public JSONObject invokeRpc(String methodName, JSONArray params, int id, Integer UID)
throws JSONException {
- return invokeRpc(methodName, params, id, String.format(Locale.US, "%d-%d", UID, id));
+ return invokeRpc(methodName, params, id, String.format("%d-%d", UID, id));
}
/**