diff options
8 files changed, 43 insertions, 103 deletions
@@ -38,22 +38,6 @@ Note: this is not an official Google product. self.ad.api.wifiEnable() ``` -## Develop - -If you want to contribute, use the usual github method of forking and sending -a pull request. - -Before sending a pull request, run the `presubmit` target to format and run -lint over the code. Fix any issues it indicates. When complete, send the pull -request. - -```shell -./gradlew presubmit -``` - -This target will reformat the code with -[googleJavaFormat](https://github.com/sherter/google-java-format-gradle-plugin) -and run lint. The lint report should open in your default browser. ## Other resources diff --git a/build.gradle b/build.gradle index 114e5ba..5283f0e 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' - classpath 'me.tatarka:gradle-retrolambda:3.7.0' + classpath 'me.tatarka:gradle-retrolambda:3.5.0' // NOTE: Do not place your application dependencies here. } @@ -31,7 +31,7 @@ allprojects { android { compileSdkVersion 24 - buildToolsVersion '25.0.3' + buildToolsVersion '25.0.0' defaultConfig { applicationId "com.google.android.mobly.snippet.bundled" @@ -50,7 +50,6 @@ android { abortOnError true checkAllWarnings true warningsAsErrors true - disable 'HardwareIds','MissingApplicationIcon','GoogleAppIndexingWarning','InvalidPackage','OldTargetApi' } } @@ -73,36 +72,13 @@ artifacts { dependencies { compile 'com.android.support.test:runner:0.5' compile 'com.google.android.mobly:mobly-snippet-lib:1.2.0' - compile 'com.google.code.gson:gson:2.8.2' - compile 'com.google.guava:guava:22.0-android' + compile 'com.google.code.gson:gson:2.6.2' + compile 'com.google.guava:guava:20.0' - testCompile 'com.google.truth:truth:0.36' + testCompile 'com.google.truth:truth:0.32' testCompile 'junit:junit:4.12' } googleJavaFormat { options style: 'AOSP' } - -// 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("darwin")) { - 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/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 0a0dad3..dc5d0af 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -3,8 +3,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.android.mobly.snippet.bundled"> - <uses-feature android:name="android.hardware.telephony" android:required="false" /> - <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> @@ -27,7 +25,7 @@ <uses-permission android:name="android.permission.WRITE_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" /> <uses-permission android:name="android.permission.SEND_SMS" /> - <application android:allowBackup="false"> + <application> <meta-data android:name="mobly-snippets" android:value="com.google.android.mobly.snippet.bundled.AccountSnippet, diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/AccountSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/AccountSnippet.java index f8499b4..627d1b4 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/AccountSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/AccountSnippet.java @@ -34,7 +34,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -113,7 +112,6 @@ public class AccountSnippet implements Snippet { if (result.containsKey(AccountManager.KEY_ERROR_CODE)) { throw new AccountSnippetException( String.format( - Locale.US, "Failed to add account due to code %d: %s", result.getInt(AccountManager.KEY_ERROR_CODE), result.getString(AccountManager.KEY_ERROR_MESSAGE))); diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/FileSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/FileSnippet.java index f6b6918..571d57f 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/FileSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/FileSnippet.java @@ -16,6 +16,10 @@ package com.google.android.mobly.snippet.bundled; +import java.io.IOException; +import java.security.MessageDigest; +import java.security.DigestInputStream; +import java.security.NoSuchAlgorithmException; import android.content.Context; import android.net.Uri; import android.os.ParcelFileDescriptor; @@ -23,10 +27,6 @@ import android.support.test.InstrumentationRegistry; import com.google.android.mobly.snippet.Snippet; import com.google.android.mobly.snippet.bundled.utils.Utils; import com.google.android.mobly.snippet.rpc.Rpc; -import java.io.IOException; -import java.security.DigestInputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; /** Snippet class for File and abstract storage URI operation RPCs. */ public class FileSnippet implements Snippet { @@ -47,14 +47,13 @@ public class FileSnippet implements Snippet { } @Rpc(description = "Compute MD5 hash on a content URI. Return the MD5 has has a hex string.") - public String fileMd5Hash(String uri) throws IOException, NoSuchAlgorithmException { + public String fileMd5Hash(String uri) throws IOException, NoSuchAlgorithmException { Uri uri_ = Uri.parse(uri); ParcelFileDescriptor pfd = mContext.getContentResolver().openFileDescriptor(uri_, "r"); MessageDigest md = MessageDigest.getInstance("MD5"); int length = (int) pfd.getStatSize(); byte[] buf = new byte[length]; - ParcelFileDescriptor.AutoCloseInputStream stream = - new ParcelFileDescriptor.AutoCloseInputStream(pfd); + ParcelFileDescriptor.AutoCloseInputStream stream = new ParcelFileDescriptor.AutoCloseInputStream(pfd); DigestInputStream dis = new DigestInputStream(stream, md); try { dis.read(buf, 0, length); diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/NetworkingSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/NetworkingSnippet.java index e89fc12..f175fdd 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/NetworkingSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/NetworkingSnippet.java @@ -16,24 +16,24 @@ package com.google.android.mobly.snippet.bundled; -import android.app.DownloadManager; -import android.content.BroadcastReceiver; -import android.content.Context; +import java.util.List; +import java.net.InetAddress; +import java.net.Socket; +import java.io.IOException; +import java.net.UnknownHostException; import android.content.Intent; +import android.content.Context; import android.content.IntentFilter; +import android.content.BroadcastReceiver; import android.net.Uri; import android.os.Environment; +import android.os.ParcelFileDescriptor; +import android.app.DownloadManager; import android.support.test.InstrumentationRegistry; import com.google.android.mobly.snippet.Snippet; import com.google.android.mobly.snippet.bundled.utils.Utils; import com.google.android.mobly.snippet.rpc.Rpc; import com.google.android.mobly.snippet.util.Log; -import java.io.IOException; -import java.net.InetAddress; -import java.net.Socket; -import java.net.UnknownHostException; -import java.util.List; -import java.util.Locale; /** Snippet class for networking RPCs. */ public class NetworkingSnippet implements Snippet { @@ -77,23 +77,18 @@ public class NetworkingSnippet implements Snippet { return true; } - @Rpc( - description = - "Download a file using HTTP. Return content Uri (file remains on device). " - + "The Uri should be treated as an opaque handle for further operations." - ) - public String networkHttpDownload(String url) - throws IllegalArgumentException, NetworkingSnippetException { + @Rpc(description = "Download a file using HTTP. Return content Uri (file remains on device). " + + "The Uri should be treated as an opaque handle for further operations.") + public String networkHttpDownload(String url) throws IllegalArgumentException, NetworkingSnippetException { Uri uri = Uri.parse(url); List<String> pathsegments = uri.getPathSegments(); if (pathsegments.size() < 1) { - throw new IllegalArgumentException( - String.format(Locale.US, "The Uri %s does not have a path.", uri.toString())); + throw new IllegalArgumentException(String.format("The Uri %s does not have a path.", uri.toString())); } DownloadManager.Request request = new DownloadManager.Request(uri); - request.setDestinationInExternalPublicDir( - Environment.DIRECTORY_DOWNLOADS, pathsegments.get(pathsegments.size() - 1)); + request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, + pathsegments.get(pathsegments.size() - 1)); mIsDownloadComplete = false; mReqid = 0; IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE); @@ -101,16 +96,9 @@ public class NetworkingSnippet implements Snippet { mContext.registerReceiver(receiver, filter); try { mReqid = mDownloadManager.enqueue(request); - Log.d( - String.format( - Locale.US, - "networkHttpDownload download of %s with id %d", - url, - mReqid)); + Log.d(String.format("networkHttpDownload download of %s with id %d", url, mReqid)); if (!Utils.waitUntil(() -> mIsDownloadComplete, 30)) { - Log.d( - String.format( - Locale.US, "networkHttpDownload timed out waiting for completion")); + Log.d(String.format("networkHttpDownload timed out waiting for completion")); throw new NetworkingSnippetException("networkHttpDownload timed out."); } } finally { @@ -118,15 +106,11 @@ public class NetworkingSnippet implements Snippet { } Uri resp = mDownloadManager.getUriForDownloadedFile(mReqid); if (resp != null) { - Log.d(String.format(Locale.US, "networkHttpDownload completed to %s", resp.toString())); + Log.d(String.format("networkHttpDownload completed to %s", resp.toString())); mReqid = 0; return resp.toString(); } else { - Log.d( - String.format( - Locale.US, - "networkHttpDownload Failed to download %s", - uri.toString())); + Log.d(String.format("networkHttpDownload Failed to download %s", uri.toString())); throw new NetworkingSnippetException("networkHttpDownload didn't get downloaded file."); } } @@ -137,7 +121,8 @@ public class NetworkingSnippet implements Snippet { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); long gotid = (long) intent.getExtras().get("extra_download_id"); - if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action) && gotid == mReqid) { + if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action) + && gotid == mReqid) { mIsDownloadComplete = true; } } diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java b/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java index 83a42f6..6614904 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/WifiManagerSnippet.java @@ -57,9 +57,7 @@ public class WifiManagerSnippet implements Snippet { public WifiManagerSnippet() { mContext = InstrumentationRegistry.getContext(); - mWifiManager = - (WifiManager) - mContext.getApplicationContext().getSystemService(Context.WIFI_SERVICE); + mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); } @Rpc( @@ -198,8 +196,8 @@ public class WifiManagerSnippet implements Snippet { String SSID = wifiConfig.SSID; // Return directly if network is already connected. WifiInfo connectionInfo = mWifiManager.getConnectionInfo(); - if (connectionInfo.getNetworkId() != -1 - && connectionInfo.getSSID().equals(wifiConfig.SSID)) { + if (connectionInfo.getNetworkId() != -1 && connectionInfo.getSSID().equals(wifiConfig.SSID)) + { Log.d("Network " + connectionInfo.getSSID() + " is already connected."); return; } diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/utils/Utils.java b/src/main/java/com/google/android/mobly/snippet/bundled/utils/Utils.java index 376bcb5..e4c0dbd 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/utils/Utils.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/utils/Utils.java @@ -30,7 +30,7 @@ import java.util.concurrent.TimeoutException; public final class Utils { - private static final char[] hexArray = "0123456789abcdef".toCharArray(); + private final static char[] hexArray = "0123456789abcdef".toCharArray(); private Utils() {} @@ -194,20 +194,22 @@ public final class Utils { } /** - * Convert a byte array (binary data) to a hexadecimal string (ASCII) representation. - * - * <p>[\x01\x02] -> "0102" + * Convert a byte array (binary data) to a hexadecimal string (ASCII) + * representation. + + * [\x01\x02] -> "0102" * * @param bytes The array of byte to convert. * @return a String with the ASCII hex representation. */ public static String bytesToHexString(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; - for (int j = 0; j < bytes.length; j++) { + for ( int j = 0; j < bytes.length; j++ ) { int v = bytes[j] & 0xFF; hexChars[j * 2] = hexArray[v >>> 4]; hexChars[j * 2 + 1] = hexArray[v & 0x0F]; } return new String(hexChars); } + } |