Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 871fe6ed authored by Joseph Wen's avatar Joseph Wen
Browse files

Update Statement Service

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

BUG=21487368
BUG=21163039

Change-Id: I0d317ac32c44933af7ed9a98ff1b0efa13eb44b1
parent 62974816
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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.
     *
+1 −1
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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>
 * {
+23 −20
Original line number Diff line number Diff line
@@ -60,7 +60,8 @@ public class URLFetcher {
            throw new IllegalArgumentException("The url protocol should be on http or https.");
        }

        HttpURLConnection connection;
        HttpURLConnection connection = null;
        try {
            connection = (HttpURLConnection) url.openConnection();
            connection.setInstanceFollowRedirects(true);
            connection.setConnectTimeout(connectionTimeoutMillis);
@@ -79,16 +80,18 @@ public class URLFetcher {
                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 {
            if (connection != null) {
                connection.disconnect();
            }
        }
    }

    /**
     * Visible for testing.