diff options
author | Joseph Wen <josephwen@google.com> | 2015-06-09 14:30:13 -0400 |
---|---|---|
committer | Joseph Wen <josephwen@google.com> | 2015-06-09 16:47:50 -0400 |
commit | 871fe6ed66e9de1369fbc7e4a145f98272b88c0b (patch) | |
tree | 65947b4dc2c02434c60d245dde40b2cd21103a1b /packages/StatementService | |
parent | 62974816a325fa6ea49d6f9800b962af85a9856a (diff) | |
download | frameworks_base-871fe6ed66e9de1369fbc7e4a145f98272b88c0b.zip frameworks_base-871fe6ed66e9de1369fbc7e4a145f98272b88c0b.tar.gz frameworks_base-871fe6ed66e9de1369fbc7e4a145f98272b88c0b.tar.bz2 |
Update Statement Service
* Change the well known file location to assetlinks.json.
* Cleanup http connection after verification.
BUG=21487368
BUG=21163039
Change-Id: I0d317ac32c44933af7ed9a98ff1b0efa13eb44b1
Diffstat (limited to 'packages/StatementService')
4 files changed, 26 insertions, 23 deletions
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. * * <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 @@ 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: * * <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 @@ 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(); + } } } |