Update Statement Service

* Change the well known file location to assetlinks.json.
* Cleanup http connection after verification.

BUG=21487368
BUG=21163039

Change-Id: I0d317ac32c44933af7ed9a98ff1b0efa13eb44b1
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 @@
      * Creates a new StatementRetriever that directly retrieves statements from the asset.
      *
      * <p> 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 @@
     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 @@
 /**
  * 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:
  *
  * <pre>
  * {
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 @@
             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);
-        }
-
-        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());
-
+        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);
+            }
+
+            Long expireTimeMillis = getExpirationTimeMillisFromHTTPHeader(
+                    connection.getHeaderFields());
+
             return new WebContent(inputStreamToString(
                     connection.getInputStream(), connection.getContentLength(), fileSizeLimit),
                 expireTimeMillis);
         } finally {
-            connection.disconnect();
+            if (connection != null) {
+                connection.disconnect();
+            }
         }
     }