Index: media/base/android/java/src/org/chromium/media/MediaDrmBridge.java |
diff --git a/media/base/android/java/src/org/chromium/media/MediaDrmBridge.java b/media/base/android/java/src/org/chromium/media/MediaDrmBridge.java |
index 95f67803d65f6567c55056fae001e6588ba21c66..c63bf439ef7f0516932f9c1c0a36fa5a98786362 100644 |
--- a/media/base/android/java/src/org/chromium/media/MediaDrmBridge.java |
+++ b/media/base/android/java/src/org/chromium/media/MediaDrmBridge.java |
@@ -7,19 +7,12 @@ package org.chromium.media; |
import android.annotation.TargetApi; |
import android.media.MediaCrypto; |
import android.media.MediaDrm; |
-import android.os.AsyncTask; |
import android.os.Build; |
import org.chromium.base.Log; |
import org.chromium.base.annotations.CalledByNative; |
import org.chromium.base.annotations.JNINamespace; |
-import java.io.BufferedInputStream; |
-import java.io.ByteArrayOutputStream; |
-import java.io.IOException; |
-import java.net.HttpURLConnection; |
-import java.net.MalformedURLException; |
-import java.net.URL; |
import java.nio.ByteBuffer; |
import java.util.ArrayDeque; |
import java.util.ArrayList; |
@@ -414,8 +407,11 @@ public class MediaDrmBridge { |
private void resetDeviceCredentials() { |
mResetDeviceCredentialsPending = true; |
MediaDrm.ProvisionRequest request = mMediaDrm.getProvisionRequest(); |
- PostRequestTask postTask = new PostRequestTask(request.getData()); |
- postTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, request.getDefaultUrl()); |
+ |
+ if (isNativeMediaDrmBridgeValid()) { |
+ nativeOnStartProvisioning( |
+ mNativeMediaDrmBridge, request.getDefaultUrl(), request.getData()); |
+ } |
} |
/** |
@@ -745,8 +741,11 @@ public class MediaDrmBridge { |
assert !mProvisioningPending; |
mProvisioningPending = true; |
MediaDrm.ProvisionRequest request = mMediaDrm.getProvisionRequest(); |
- PostRequestTask postTask = new PostRequestTask(request.getData()); |
- postTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, request.getDefaultUrl()); |
+ |
+ if (isNativeMediaDrmBridgeValid()) { |
+ nativeOnStartProvisioning( |
+ mNativeMediaDrmBridge, request.getDefaultUrl(), request.getData()); |
+ } |
xhwang
2015/11/11 09:53:21
+qinmin
In theory, it's possible that resetDevice
Tima Vaisburd
2015/11/11 23:26:35
Now I call startProvisioning() from resetDeviceCre
|
} |
/** |
@@ -754,7 +753,8 @@ public class MediaDrmBridge { |
* |
* @param response Response data from the provision server. |
*/ |
- private void onProvisionResponse(byte[] response) { |
+ @CalledByNative |
+ private void processProvisionResponse(byte[] response) { |
Log.d(TAG, "onProvisionResponse()"); |
assert mProvisioningPending; |
xhwang
2015/11/11 09:53:21
Wondering how this didn't fire when resetting devi
Tima Vaisburd
2015/11/11 23:26:35
Thank you for spotting this. Now I call startProvi
|
mProvisioningPending = false; |
@@ -769,6 +769,7 @@ public class MediaDrmBridge { |
if (mResetDeviceCredentialsPending) { |
onResetDeviceCredentialsCompleted(success); |
mResetDeviceCredentialsPending = false; |
+ return; |
xhwang
2015/11/11 09:53:21
Why making this change? Is that because currently
Tima Vaisburd
2015/11/11 23:26:35
Removed.
|
} |
if (success) { |
@@ -777,7 +778,7 @@ public class MediaDrmBridge { |
} |
/** |
- * Provide the provisioning response to MediaDrm. |
+ * Provides the provision response to MediaDrm. |
* |
* @returns false if the response is invalid or on error, true otherwise. |
*/ |
@@ -966,81 +967,13 @@ public class MediaDrmBridge { |
} |
} |
- private class PostRequestTask extends AsyncTask<String, Void, Void> { |
- private static final String TAG = "PostRequestTask"; |
- |
- private byte[] mDrmRequest; |
- private byte[] mResponseBody; |
- |
- public PostRequestTask(byte[] drmRequest) { |
- mDrmRequest = drmRequest; |
- } |
- |
- @Override |
- protected Void doInBackground(String... urls) { |
- mResponseBody = postRequest(urls[0], mDrmRequest); |
- if (mResponseBody != null) { |
- Log.d(TAG, "response length=%d", mResponseBody.length); |
- } |
- return null; |
- } |
- |
- private byte[] postRequest(String url, byte[] drmRequest) { |
- HttpURLConnection urlConnection = null; |
- try { |
- URL request = new URL(url + "&signedRequest=" + new String(drmRequest)); |
- urlConnection = (HttpURLConnection) request.openConnection(); |
- urlConnection.setDoOutput(true); |
- urlConnection.setDoInput(true); |
- urlConnection.setUseCaches(false); |
- urlConnection.setRequestMethod("POST"); |
- urlConnection.setRequestProperty("User-Agent", "Widevine CDM v1.0"); |
- urlConnection.setRequestProperty("Content-Type", "application/json"); |
- |
- int responseCode = urlConnection.getResponseCode(); |
- if (responseCode == 200) { |
- BufferedInputStream bis = |
- new BufferedInputStream(urlConnection.getInputStream()); |
- ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
- int read = 0; |
- int bufferSize = 512; |
- byte[] buffer = new byte[bufferSize]; |
- try { |
- while (true) { |
- read = bis.read(buffer); |
- if (read == -1) break; |
- bos.write(buffer, 0, read); |
- } |
- } finally { |
- bis.close(); |
- } |
- return bos.toByteArray(); |
- } else { |
- Log.d(TAG, "Server returned HTTP error code %d", responseCode); |
- return null; |
- } |
- } catch (MalformedURLException e) { |
- e.printStackTrace(); |
- } catch (IOException e) { |
- e.printStackTrace(); |
- } catch (IllegalStateException e) { |
- e.printStackTrace(); |
- } finally { |
- if (urlConnection != null) urlConnection.disconnect(); |
- } |
- return null; |
- } |
- |
- @Override |
- protected void onPostExecute(Void v) { |
- onProvisionResponse(mResponseBody); |
- } |
- } |
- |
// Native functions. At the native side, must post the task immediately to |
// avoid reentrancy issues. |
private native void nativeOnMediaCryptoReady(long nativeMediaDrmBridge); |
+ private native void nativeOnStartProvisioning( |
+ long nativeMediaDrmBridge, String defaultUrl, byte[] requestData); |
+ |
private native void nativeOnPromiseResolved(long nativeMediaDrmBridge, long promiseId); |
private native void nativeOnPromiseResolvedWithSession( |
long nativeMediaDrmBridge, long promiseId, byte[] sessionId); |