From 871fe6ed66e9de1369fbc7e4a145f98272b88c0b Mon Sep 17 00:00:00 2001 From: Joseph Wen Date: Tue, 9 Jun 2015 14:30:13 -0400 Subject: Update Statement Service * Change the well known file location to assetlinks.json. * Cleanup http connection after verification. BUG=21487368 BUG=21163039 Change-Id: I0d317ac32c44933af7ed9a98ff1b0efa13eb44b1 --- .../retriever/AbstractStatementRetriever.java | 2 +- .../retriever/DirectStatementRetriever.java | 2 +- .../statementservice/retriever/Statement.java | 2 +- .../statementservice/retriever/URLFetcher.java | 43 ++++++++++++---------- 4 files changed, 26 insertions(+), 23 deletions(-) (limited to 'packages/StatementService') diff --git a/packages/StatementService/src/com/android/statementservice/retriever/AbstractStatementRetriever.java b/packages/StatementService/src/com/android/statementservice/retriever/AbstractStatementRetriever.java index 3b59fd6..fe9b99a 100644 --- a/packages/StatementService/src/com/android/statementservice/retriever/AbstractStatementRetriever.java +++ b/packages/StatementService/src/com/android/statementservice/retriever/AbstractStatementRetriever.java @@ -90,7 +90,7 @@ public abstract class AbstractStatementRetriever { * Creates a new StatementRetriever that directly retrieves statements from the asset. * *

For web assets, {@link AbstractStatementRetriever} will try to retrieve the statement - * file from URL: {@code [webAsset.site]/.well-known/statements.json"} where {@code + * file from URL: {@code [webAsset.site]/.well-known/assetlinks.json"} where {@code * [webAsset.site]} is in the form {@code http{s}://[hostname]:[optional_port]}. The file * should contain one JSON array of statements. * diff --git a/packages/StatementService/src/com/android/statementservice/retriever/DirectStatementRetriever.java b/packages/StatementService/src/com/android/statementservice/retriever/DirectStatementRetriever.java index 2ca85e9..e4feb90 100644 --- a/packages/StatementService/src/com/android/statementservice/retriever/DirectStatementRetriever.java +++ b/packages/StatementService/src/com/android/statementservice/retriever/DirectStatementRetriever.java @@ -38,7 +38,7 @@ import java.util.List; private static final int HTTP_CONNECTION_TIMEOUT_MILLIS = 5000; private static final long HTTP_CONTENT_SIZE_LIMIT_IN_BYTES = 1024 * 1024; private static final int MAX_INCLUDE_LEVEL = 1; - private static final String WELL_KNOWN_STATEMENT_PATH = "/.well-known/statements.json"; + private static final String WELL_KNOWN_STATEMENT_PATH = "/.well-known/assetlinks.json"; private final URLFetcher mUrlFetcher; private final AndroidPackageInfoFetcher mAndroidFetcher; diff --git a/packages/StatementService/src/com/android/statementservice/retriever/Statement.java b/packages/StatementService/src/com/android/statementservice/retriever/Statement.java index da3c355..0f40a62 100644 --- a/packages/StatementService/src/com/android/statementservice/retriever/Statement.java +++ b/packages/StatementService/src/com/android/statementservice/retriever/Statement.java @@ -21,7 +21,7 @@ import android.annotation.NonNull; /** * An immutable value type representing a statement, consisting of a source, target, and relation. * This reflects an assertion that the relation holds for the source, target pair. For example, if a - * web site has the following in its statements.json file: + * web site has the following in its assetlinks.json file: * *

  * {
diff --git a/packages/StatementService/src/com/android/statementservice/retriever/URLFetcher.java b/packages/StatementService/src/com/android/statementservice/retriever/URLFetcher.java
index 969aa88..225e26c 100644
--- a/packages/StatementService/src/com/android/statementservice/retriever/URLFetcher.java
+++ b/packages/StatementService/src/com/android/statementservice/retriever/URLFetcher.java
@@ -60,33 +60,36 @@ public class URLFetcher {
             throw new IllegalArgumentException("The url protocol should be on http or https.");
         }
 
-        HttpURLConnection connection;
-        connection = (HttpURLConnection) url.openConnection();
-        connection.setInstanceFollowRedirects(true);
-        connection.setConnectTimeout(connectionTimeoutMillis);
-        connection.setReadTimeout(connectionTimeoutMillis);
-        connection.setUseCaches(true);
-        connection.setInstanceFollowRedirects(false);
-        connection.addRequestProperty("Cache-Control", "max-stale=60");
-
-        if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
-            Log.e(TAG, "The responses code is not 200 but "  + connection.getResponseCode());
-            return new WebContent("", DO_NOT_CACHE_RESULT);
-        }
+        HttpURLConnection connection = null;
+        try {
+            connection = (HttpURLConnection) url.openConnection();
+            connection.setInstanceFollowRedirects(true);
+            connection.setConnectTimeout(connectionTimeoutMillis);
+            connection.setReadTimeout(connectionTimeoutMillis);
+            connection.setUseCaches(true);
+            connection.setInstanceFollowRedirects(false);
+            connection.addRequestProperty("Cache-Control", "max-stale=60");
+
+            if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
+                Log.e(TAG, "The responses code is not 200 but "  + connection.getResponseCode());
+                return new WebContent("", DO_NOT_CACHE_RESULT);
+            }
 
-        if (connection.getContentLength() > fileSizeLimit) {
-            Log.e(TAG, "The content size of the url is larger than "  + fileSizeLimit);
-            return new WebContent("", DO_NOT_CACHE_RESULT);
-        }
+            if (connection.getContentLength() > fileSizeLimit) {
+                Log.e(TAG, "The content size of the url is larger than "  + fileSizeLimit);
+                return new WebContent("", DO_NOT_CACHE_RESULT);
+            }
 
-        Long expireTimeMillis = getExpirationTimeMillisFromHTTPHeader(connection.getHeaderFields());
+            Long expireTimeMillis = getExpirationTimeMillisFromHTTPHeader(
+                    connection.getHeaderFields());
 
-        try {
             return new WebContent(inputStreamToString(
                     connection.getInputStream(), connection.getContentLength(), fileSizeLimit),
                 expireTimeMillis);
         } finally {
-            connection.disconnect();
+            if (connection != null) {
+                connection.disconnect();
+            }
         }
     }
 
-- 
cgit v1.1