am f29a315e: am 5e686160: Merge "Update the Statement Service. DO NOT MERGE" into mnc-dev

* commit 'f29a315e8cf4987809982bcd6dac8f8b24b4f45e':
  Update the Statement Service. DO NOT MERGE
This commit is contained in:
Joseph Wen
2015-05-20 21:48:51 +00:00
committed by Android Git Automerger
6 changed files with 39 additions and 5 deletions

View File

@@ -63,4 +63,10 @@ public abstract class AbstractAsset {
throws AssociationServiceException { throws AssociationServiceException {
return AssetFactory.create(assetJson); return AssetFactory.create(assetJson);
} }
/**
* If this is the source asset of a statement file, should the retriever follow
* any insecure (non-HTTPS) include statements made by the asset.
*/
public abstract boolean followInsecureInclude();
} }

View File

@@ -99,6 +99,12 @@ import java.util.Locale;
return getPackageName().hashCode(); return getPackageName().hashCode();
} }
@Override
public boolean followInsecureInclude() {
// Non-HTTPS includes are not allowed in Android App assets.
return false;
}
/** /**
* Checks that the input is a valid Android app asset. * Checks that the input is a valid Android app asset.
* *

View File

@@ -136,7 +136,8 @@ import java.util.List;
} }
} }
private Result retrieveStatementFromUrl(String url, int maxIncludeLevel, AbstractAsset source) private Result retrieveStatementFromUrl(String urlString, int maxIncludeLevel,
AbstractAsset source)
throws AssociationServiceException { throws AssociationServiceException {
List<Statement> statements = new ArrayList<Statement>(); List<Statement> statements = new ArrayList<Statement>();
if (maxIncludeLevel < 0) { if (maxIncludeLevel < 0) {
@@ -145,7 +146,12 @@ import java.util.List;
WebContent webContent; WebContent webContent;
try { try {
webContent = mUrlFetcher.getWebContentFromUrl(new URL(url), URL url = new URL(urlString);
if (!source.followInsecureInclude()
&& !url.getProtocol().toLowerCase().equals("https")) {
return Result.create(statements, DO_NOT_CACHE_RESULT);
}
webContent = mUrlFetcher.getWebContentFromUrl(url,
HTTP_CONTENT_SIZE_LIMIT_IN_BYTES, HTTP_CONNECTION_TIMEOUT_MILLIS); HTTP_CONTENT_SIZE_LIMIT_IN_BYTES, HTTP_CONNECTION_TIMEOUT_MILLIS);
} catch (IOException e) { } catch (IOException e) {
return Result.create(statements, DO_NOT_CACHE_RESULT); return Result.create(statements, DO_NOT_CACHE_RESULT);

View File

@@ -16,6 +16,8 @@
package com.android.statementservice.retriever; package com.android.statementservice.retriever;
import android.util.Log;
import com.android.volley.Cache; import com.android.volley.Cache;
import com.android.volley.NetworkResponse; import com.android.volley.NetworkResponse;
import com.android.volley.toolbox.HttpHeaderParser; import com.android.volley.toolbox.HttpHeaderParser;
@@ -39,6 +41,7 @@ import java.util.Map;
* @hide * @hide
*/ */
public class URLFetcher { public class URLFetcher {
private static final String TAG = URLFetcher.class.getSimpleName();
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;
@@ -63,11 +66,17 @@ public class URLFetcher {
connection.setConnectTimeout(connectionTimeoutMillis); connection.setConnectTimeout(connectionTimeoutMillis);
connection.setReadTimeout(connectionTimeoutMillis); connection.setReadTimeout(connectionTimeoutMillis);
connection.setUseCaches(true); connection.setUseCaches(true);
connection.setInstanceFollowRedirects(false);
connection.addRequestProperty("Cache-Control", "max-stale=60"); 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) { if (connection.getContentLength() > fileSizeLimit) {
throw new AssociationServiceException("The content size of the url is larger than " Log.e(TAG, "The content size of the url is larger than " + fileSizeLimit);
+ fileSizeLimit); return new WebContent("", DO_NOT_CACHE_RESULT);
} }
Long expireTimeMillis = getExpirationTimeMillisFromHTTPHeader(connection.getHeaderFields()); Long expireTimeMillis = getExpirationTimeMillisFromHTTPHeader(connection.getHeaderFields());

View File

@@ -61,7 +61,7 @@ public final class Utils {
*/ */
public static final String ASSET_DESCRIPTOR_FIELD_RELATION = "relation"; public static final String ASSET_DESCRIPTOR_FIELD_RELATION = "relation";
public static final String ASSET_DESCRIPTOR_FIELD_TARGET = "target"; public static final String ASSET_DESCRIPTOR_FIELD_TARGET = "target";
public static final String DELEGATE_FIELD_DELEGATE = "delegate"; public static final String DELEGATE_FIELD_DELEGATE = "include";
private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F' }; 'A', 'B', 'C', 'D', 'E', 'F' };

View File

@@ -39,6 +39,7 @@ import java.util.Locale;
/* package private */ final class WebAsset extends AbstractAsset { /* package private */ final class WebAsset extends AbstractAsset {
private static final String MISSING_FIELD_FORMAT_STRING = "Expected %s to be set."; private static final String MISSING_FIELD_FORMAT_STRING = "Expected %s to be set.";
private static final String SCHEME_HTTP = "http";
private final URL mUrl; private final URL mUrl;
@@ -105,6 +106,12 @@ import java.util.Locale;
return toJson().hashCode(); return toJson().hashCode();
} }
@Override
public boolean followInsecureInclude() {
// Only allow insecure include file if the asset scheme is http.
return SCHEME_HTTP.equals(getScheme());
}
/** /**
* Checks that the input is a valid web asset. * Checks that the input is a valid web asset.
* *