Loading packages/StatementService/src/com/android/statementservice/retriever/DirectStatementRetriever.java +6 −3 Original line number Original line Diff line number Diff line Loading @@ -36,6 +36,8 @@ import java.util.List; private static final long DO_NOT_CACHE_RESULT = 0L; private static final long DO_NOT_CACHE_RESULT = 0L; private static final int HTTP_CONNECTION_TIMEOUT_MILLIS = 5000; private static final int HTTP_CONNECTION_TIMEOUT_MILLIS = 5000; private static final int HTTP_CONNECTION_BACKOFF_MILLIS = 3000; private static final int HTTP_CONNECTION_RETRY = 3; private static final long HTTP_CONTENT_SIZE_LIMIT_IN_BYTES = 1024 * 1024; private static final long HTTP_CONTENT_SIZE_LIMIT_IN_BYTES = 1024 * 1024; private static final int MAX_INCLUDE_LEVEL = 1; private static final int MAX_INCLUDE_LEVEL = 1; private static final String WELL_KNOWN_STATEMENT_PATH = "/.well-known/assetlinks.json"; private static final String WELL_KNOWN_STATEMENT_PATH = "/.well-known/assetlinks.json"; Loading Loading @@ -151,9 +153,10 @@ import java.util.List; && !url.getProtocol().toLowerCase().equals("https")) { && !url.getProtocol().toLowerCase().equals("https")) { return Result.create(statements, DO_NOT_CACHE_RESULT); return Result.create(statements, DO_NOT_CACHE_RESULT); } } webContent = mUrlFetcher.getWebContentFromUrl(url, webContent = mUrlFetcher.getWebContentFromUrlWithRetry(url, HTTP_CONTENT_SIZE_LIMIT_IN_BYTES, HTTP_CONNECTION_TIMEOUT_MILLIS); HTTP_CONTENT_SIZE_LIMIT_IN_BYTES, HTTP_CONNECTION_TIMEOUT_MILLIS, } catch (IOException e) { HTTP_CONNECTION_BACKOFF_MILLIS, HTTP_CONNECTION_RETRY); } catch (IOException | InterruptedException e) { return Result.create(statements, DO_NOT_CACHE_RESULT); return Result.create(statements, DO_NOT_CACHE_RESULT); } } Loading packages/StatementService/src/com/android/statementservice/retriever/URLFetcher.java +34 −0 Original line number Original line Diff line number Diff line Loading @@ -46,6 +46,40 @@ public class URLFetcher { private static final long DO_NOT_CACHE_RESULT = 0L; private static final long DO_NOT_CACHE_RESULT = 0L; private static final int INPUT_BUFFER_SIZE_IN_BYTES = 1024; private static final int INPUT_BUFFER_SIZE_IN_BYTES = 1024; /** * Fetches the specified url and returns the content and ttl. * * <p> * Retry {@code retry} times if the connection failed or timed out for any reason. * HTTP error code (e.g. 404/500) won't be retried. * * @throws IOException if it can't retrieve the content due to a network problem. * @throws AssociationServiceException if the URL scheme is not http or https or the content * length exceeds {code fileSizeLimit}. */ public WebContent getWebContentFromUrlWithRetry(URL url, long fileSizeLimit, int connectionTimeoutMillis, int backoffMillis, int retry) throws AssociationServiceException, IOException, InterruptedException { if (retry <= 0) { throw new IllegalArgumentException("retry should be a postive inetger."); } while (retry > 0) { try { return getWebContentFromUrl(url, fileSizeLimit, connectionTimeoutMillis); } catch (IOException e) { retry--; if (retry == 0) { throw e; } } Thread.sleep(backoffMillis); } // Should never reach here. return null; } /** /** * Fetches the specified url and returns the content and ttl. * Fetches the specified url and returns the content and ttl. * * Loading Loading
packages/StatementService/src/com/android/statementservice/retriever/DirectStatementRetriever.java +6 −3 Original line number Original line Diff line number Diff line Loading @@ -36,6 +36,8 @@ import java.util.List; private static final long DO_NOT_CACHE_RESULT = 0L; private static final long DO_NOT_CACHE_RESULT = 0L; private static final int HTTP_CONNECTION_TIMEOUT_MILLIS = 5000; private static final int HTTP_CONNECTION_TIMEOUT_MILLIS = 5000; private static final int HTTP_CONNECTION_BACKOFF_MILLIS = 3000; private static final int HTTP_CONNECTION_RETRY = 3; private static final long HTTP_CONTENT_SIZE_LIMIT_IN_BYTES = 1024 * 1024; private static final long HTTP_CONTENT_SIZE_LIMIT_IN_BYTES = 1024 * 1024; private static final int MAX_INCLUDE_LEVEL = 1; private static final int MAX_INCLUDE_LEVEL = 1; private static final String WELL_KNOWN_STATEMENT_PATH = "/.well-known/assetlinks.json"; private static final String WELL_KNOWN_STATEMENT_PATH = "/.well-known/assetlinks.json"; Loading Loading @@ -151,9 +153,10 @@ import java.util.List; && !url.getProtocol().toLowerCase().equals("https")) { && !url.getProtocol().toLowerCase().equals("https")) { return Result.create(statements, DO_NOT_CACHE_RESULT); return Result.create(statements, DO_NOT_CACHE_RESULT); } } webContent = mUrlFetcher.getWebContentFromUrl(url, webContent = mUrlFetcher.getWebContentFromUrlWithRetry(url, HTTP_CONTENT_SIZE_LIMIT_IN_BYTES, HTTP_CONNECTION_TIMEOUT_MILLIS); HTTP_CONTENT_SIZE_LIMIT_IN_BYTES, HTTP_CONNECTION_TIMEOUT_MILLIS, } catch (IOException e) { HTTP_CONNECTION_BACKOFF_MILLIS, HTTP_CONNECTION_RETRY); } catch (IOException | InterruptedException e) { return Result.create(statements, DO_NOT_CACHE_RESULT); return Result.create(statements, DO_NOT_CACHE_RESULT); } } Loading
packages/StatementService/src/com/android/statementservice/retriever/URLFetcher.java +34 −0 Original line number Original line Diff line number Diff line Loading @@ -46,6 +46,40 @@ public class URLFetcher { private static final long DO_NOT_CACHE_RESULT = 0L; private static final long DO_NOT_CACHE_RESULT = 0L; private static final int INPUT_BUFFER_SIZE_IN_BYTES = 1024; private static final int INPUT_BUFFER_SIZE_IN_BYTES = 1024; /** * Fetches the specified url and returns the content and ttl. * * <p> * Retry {@code retry} times if the connection failed or timed out for any reason. * HTTP error code (e.g. 404/500) won't be retried. * * @throws IOException if it can't retrieve the content due to a network problem. * @throws AssociationServiceException if the URL scheme is not http or https or the content * length exceeds {code fileSizeLimit}. */ public WebContent getWebContentFromUrlWithRetry(URL url, long fileSizeLimit, int connectionTimeoutMillis, int backoffMillis, int retry) throws AssociationServiceException, IOException, InterruptedException { if (retry <= 0) { throw new IllegalArgumentException("retry should be a postive inetger."); } while (retry > 0) { try { return getWebContentFromUrl(url, fileSizeLimit, connectionTimeoutMillis); } catch (IOException e) { retry--; if (retry == 0) { throw e; } } Thread.sleep(backoffMillis); } // Should never reach here. return null; } /** /** * Fetches the specified url and returns the content and ttl. * Fetches the specified url and returns the content and ttl. * * Loading