From ea737a8e1eb043af80e77f0851d4ba245fe4b0c7 Mon Sep 17 00:00:00 2001 From: Brad Ebinger Date: Mon, 9 Oct 2017 11:23:21 -0700 Subject: Require DownloadRequest#Builder to have mandatory Source URI This change modifies the API to require that the DownloadRequest#Builder includes the Source URI as a mandatory, non-null parameter. Test: Manual, Telephony Test MBMS app Change-Id: I7d44e977314a57fdf063aa233bfb978b48ebf1db --- api/current.txt | 3 +-- api/system-current.txt | 3 +-- api/test-current.txt | 3 +-- .../android/telephony/mbms/DownloadRequest.java | 30 +++++++++++++--------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/api/current.txt b/api/current.txt index 63c65f7afdf3..14d2cf5fadf2 100644 --- a/api/current.txt +++ b/api/current.txt @@ -40438,11 +40438,10 @@ package android.telephony.mbms { } public static class DownloadRequest.Builder { - ctor public DownloadRequest.Builder(); + ctor public DownloadRequest.Builder(android.net.Uri); method public android.telephony.mbms.DownloadRequest build(); method public android.telephony.mbms.DownloadRequest.Builder setAppIntent(android.content.Intent); method public android.telephony.mbms.DownloadRequest.Builder setServiceInfo(android.telephony.mbms.FileServiceInfo); - method public android.telephony.mbms.DownloadRequest.Builder setSource(android.net.Uri); method public android.telephony.mbms.DownloadRequest.Builder setSubscriptionId(int); } diff --git a/api/system-current.txt b/api/system-current.txt index 955fd6472ef8..7c09d57fe306 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -43953,13 +43953,12 @@ package android.telephony.mbms { } public static class DownloadRequest.Builder { - ctor public DownloadRequest.Builder(); + ctor public DownloadRequest.Builder(android.net.Uri); method public android.telephony.mbms.DownloadRequest build(); method public android.telephony.mbms.DownloadRequest.Builder setAppIntent(android.content.Intent); method public android.telephony.mbms.DownloadRequest.Builder setOpaqueData(byte[]); method public android.telephony.mbms.DownloadRequest.Builder setServiceId(java.lang.String); method public android.telephony.mbms.DownloadRequest.Builder setServiceInfo(android.telephony.mbms.FileServiceInfo); - method public android.telephony.mbms.DownloadRequest.Builder setSource(android.net.Uri); method public android.telephony.mbms.DownloadRequest.Builder setSubscriptionId(int); } diff --git a/api/test-current.txt b/api/test-current.txt index 03c9bdb6b2ee..78eca187a541 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -40660,11 +40660,10 @@ package android.telephony.mbms { } public static class DownloadRequest.Builder { - ctor public DownloadRequest.Builder(); + ctor public DownloadRequest.Builder(android.net.Uri); method public android.telephony.mbms.DownloadRequest build(); method public android.telephony.mbms.DownloadRequest.Builder setAppIntent(android.content.Intent); method public android.telephony.mbms.DownloadRequest.Builder setServiceInfo(android.telephony.mbms.FileServiceInfo); - method public android.telephony.mbms.DownloadRequest.Builder setSource(android.net.Uri); method public android.telephony.mbms.DownloadRequest.Builder setSubscriptionId(int); } diff --git a/telephony/java/android/telephony/mbms/DownloadRequest.java b/telephony/java/android/telephony/mbms/DownloadRequest.java index 5a57f3221d3a..f0d60b68eb94 100644 --- a/telephony/java/android/telephony/mbms/DownloadRequest.java +++ b/telephony/java/android/telephony/mbms/DownloadRequest.java @@ -16,6 +16,7 @@ package android.telephony.mbms; +import android.annotation.NonNull; import android.annotation.SystemApi; import android.content.Intent; import android.net.Uri; @@ -26,7 +27,6 @@ import android.util.Log; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -71,6 +71,19 @@ public final class DownloadRequest implements Parcelable { private String appIntent; private int version = CURRENT_VERSION; + + /** + * Builds a new DownloadRequest. + * @param sourceUri the source URI for the DownloadRequest to be built. This URI should + * never be null. + */ + public Builder(@NonNull Uri sourceUri) { + if (sourceUri == null) { + throw new IllegalArgumentException("Source URI must be non-null."); + } + source = sourceUri; + } + /** * Sets the service from which the download request to be built will download from. * @param serviceInfo @@ -91,15 +104,6 @@ public final class DownloadRequest implements Parcelable { return this; } - /** - * Sets the source URI for the download request to be built. - * @param source - */ - public Builder setSource(Uri source) { - this.source = source; - return this; - } - /** * Set the subscription ID on which the file(s) should be downloaded. * @param subscriptionId @@ -316,9 +320,11 @@ public final class DownloadRequest implements Parcelable { throw new RuntimeException("Could not get sha256 hash object"); } if (version >= 1) { - // Hash the source URI, destination URI, and the app intent + // Hash the source URI and the app intent digest.update(sourceUri.toString().getBytes(StandardCharsets.UTF_8)); - digest.update(serializedResultIntentForApp.getBytes(StandardCharsets.UTF_8)); + if (serializedResultIntentForApp != null) { + digest.update(serializedResultIntentForApp.getBytes(StandardCharsets.UTF_8)); + } } // Add updates for future versions here return Base64.encodeToString(digest.digest(), Base64.URL_SAFE | Base64.NO_WRAP); -- cgit v1.2.3-59-g8ed1b