mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Fix Widevine L3 provisioning in V2
1. HttpMediaDrmCallback.executeProvisionRequest needs to specify an empty byte[], else we do a GET instead of a POST. 2. Content-Type should not be set when making the provision request, since there's no body. 3. DataSource implementations must correctly handle a non-null body with zero length. CronetDataSource was not handling this case. DefaultHttpDataSource was, but made a code modification to make it a little clearer. OkHttpDataSource seems to handle the case correctly, and it doens't look like the code can be made clearer. Issue #1925 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=136042641
This commit is contained in:
parent
a22390c29b
commit
6acf59c4fc
@ -416,8 +416,10 @@ public class CronetDataSource extends UrlRequest.Callback implements HttpDataSou
|
|||||||
executor, cronetEngine);
|
executor, cronetEngine);
|
||||||
// Set the headers.
|
// Set the headers.
|
||||||
synchronized (requestProperties) {
|
synchronized (requestProperties) {
|
||||||
if (dataSpec.postBody != null && !requestProperties.containsKey(CONTENT_TYPE)) {
|
if (dataSpec.postBody != null && dataSpec.postBody.length != 0
|
||||||
throw new OpenException("POST request must set Content-Type", dataSpec, Status.IDLE);
|
&& !requestProperties.containsKey(CONTENT_TYPE)) {
|
||||||
|
throw new OpenException("POST request with non-empty body must set Content-Type", dataSpec,
|
||||||
|
Status.IDLE);
|
||||||
}
|
}
|
||||||
for (Entry<String, String> headerEntry : requestProperties.entrySet()) {
|
for (Entry<String, String> headerEntry : requestProperties.entrySet()) {
|
||||||
requestBuilder.addHeader(headerEntry.getKey(), headerEntry.getValue());
|
requestBuilder.addHeader(headerEntry.getKey(), headerEntry.getValue());
|
||||||
@ -434,11 +436,14 @@ public class CronetDataSource extends UrlRequest.Callback implements HttpDataSou
|
|||||||
}
|
}
|
||||||
requestBuilder.addHeader("Range", rangeValue.toString());
|
requestBuilder.addHeader("Range", rangeValue.toString());
|
||||||
}
|
}
|
||||||
// Set the body.
|
// Set the method and (if non-empty) the body.
|
||||||
if (dataSpec.postBody != null) {
|
if (dataSpec.postBody != null) {
|
||||||
|
requestBuilder.setHttpMethod("POST");
|
||||||
|
if (dataSpec.postBody.length != 0) {
|
||||||
requestBuilder.setUploadDataProvider(new ByteArrayUploadDataProvider(dataSpec.postBody),
|
requestBuilder.setUploadDataProvider(new ByteArrayUploadDataProvider(dataSpec.postBody),
|
||||||
executor);
|
executor);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return requestBuilder.build();
|
return requestBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public final class HttpMediaDrmCallback implements MediaDrmCallback {
|
|||||||
@Override
|
@Override
|
||||||
public byte[] executeProvisionRequest(UUID uuid, ProvisionRequest request) throws IOException {
|
public byte[] executeProvisionRequest(UUID uuid, ProvisionRequest request) throws IOException {
|
||||||
String url = request.getDefaultUrl() + "&signedRequest=" + new String(request.getData());
|
String url = request.getDefaultUrl() + "&signedRequest=" + new String(request.getData());
|
||||||
return executePost(url, null, null);
|
return executePost(url, new byte[0], null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -81,6 +81,7 @@ public final class HttpMediaDrmCallback implements MediaDrmCallback {
|
|||||||
url = defaultUrl;
|
url = defaultUrl;
|
||||||
}
|
}
|
||||||
Map<String, String> requestProperties = new HashMap<>();
|
Map<String, String> requestProperties = new HashMap<>();
|
||||||
|
requestProperties.put("Content-Type", "application/octet-stream");
|
||||||
if (C.PLAYREADY_UUID.equals(uuid)) {
|
if (C.PLAYREADY_UUID.equals(uuid)) {
|
||||||
requestProperties.putAll(PLAYREADY_KEY_REQUEST_PROPERTIES);
|
requestProperties.putAll(PLAYREADY_KEY_REQUEST_PROPERTIES);
|
||||||
}
|
}
|
||||||
@ -93,8 +94,6 @@ public final class HttpMediaDrmCallback implements MediaDrmCallback {
|
|||||||
private byte[] executePost(String url, byte[] data, Map<String, String> requestProperties)
|
private byte[] executePost(String url, byte[] data, Map<String, String> requestProperties)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
HttpDataSource dataSource = dataSourceFactory.createDataSource();
|
HttpDataSource dataSource = dataSourceFactory.createDataSource();
|
||||||
// Note: This will be overridden by a Content-Type in requestProperties, if one is set.
|
|
||||||
dataSource.setRequestProperty("Content-Type", "application/octet-stream");
|
|
||||||
if (requestProperties != null) {
|
if (requestProperties != null) {
|
||||||
for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
|
for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
|
||||||
dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
|
dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
|
||||||
|
@ -413,11 +413,16 @@ public class DefaultHttpDataSource implements HttpDataSource {
|
|||||||
connection.setInstanceFollowRedirects(followRedirects);
|
connection.setInstanceFollowRedirects(followRedirects);
|
||||||
connection.setDoOutput(postBody != null);
|
connection.setDoOutput(postBody != null);
|
||||||
if (postBody != null) {
|
if (postBody != null) {
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
if (postBody.length == 0) {
|
||||||
|
connection.connect();
|
||||||
|
} else {
|
||||||
connection.setFixedLengthStreamingMode(postBody.length);
|
connection.setFixedLengthStreamingMode(postBody.length);
|
||||||
connection.connect();
|
connection.connect();
|
||||||
OutputStream os = connection.getOutputStream();
|
OutputStream os = connection.getOutputStream();
|
||||||
os.write(postBody);
|
os.write(postBody);
|
||||||
os.close();
|
os.close();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
connection.connect();
|
connection.connect();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user