Update Statement Service

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

BUG=21487368
BUG=21163039

Change-Id: I0d317ac32c44933af7ed9a98ff1b0efa13eb44b1
This commit is contained in:
Joseph Wen
2015-06-09 14:30:13 -04:00
parent 62974816a3
commit 871fe6ed66
4 changed files with 28 additions and 25 deletions

View File

@ -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.
*

View File

@ -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;

View File

@ -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>
* {

View File

@ -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);
}
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();
}
}
}