Bug 1320271 - Some tweaks related to MediaDrmBridge. r?jchen
MozReview-Commit-ID: Nt5FEmd1p6
--- a/mobile/android/base/java/org/mozilla/gecko/media/GeckoMediaDrmBridgeV21.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/GeckoMediaDrmBridgeV21.java
@@ -207,21 +207,17 @@ public class GeckoMediaDrmBridgeV21 impl
final byte [] keySetId = mDrm.provideKeyResponse(session.array(), response);
if (DEBUG) {
HashMap<String, String> infoMap = mDrm.queryKeyStatus(session.array());
for (String strKey : infoMap.keySet()) {
String strValue = infoMap.get(strKey);
Log.d(LOGTAG, "InfoMap : key(" + strKey + ")/value(" + strValue + ")");
}
}
- SessionKeyInfo[] keyInfos = new SessionKeyInfo[1];
- keyInfos[0] = new SessionKeyInfo(DUMMY_KEY_ID,
- MediaDrm.KeyStatus.STATUS_USABLE);
- onSessionBatchedKeyChanged(session.array(), keyInfos);
- if (DEBUG) Log.d(LOGTAG, "Key successfully added for session " + sessionId);
+ HandleKeyStatusChangeByDummyKey(sessionId);
onSessionUpdated(promiseId, session.array());
return;
} catch (final NotProvisionedException | DeniedByServerException | IllegalStateException e) {
if (DEBUG) Log.d(LOGTAG, "Failed to provide key response:", e);
onSessionError(session.array(), "Got exception during updateSession.");
onRejectPromise(promiseId, "Got exception during updateSession.");
}
release();
@@ -280,16 +276,25 @@ public class GeckoMediaDrmBridgeV21 impl
}
@Override
public MediaCrypto getMediaCrypto() {
if (DEBUG) Log.d(LOGTAG, "getMediaCrypto()");
return mCrypto;
}
+ protected void HandleKeyStatusChangeByDummyKey(String sessionId)
+ {
+ SessionKeyInfo[] keyInfos = new SessionKeyInfo[1];
+ keyInfos[0] = new SessionKeyInfo(DUMMY_KEY_ID,
+ MediaDrm.KeyStatus.STATUS_USABLE);
+ onSessionBatchedKeyChanged(sessionId.getBytes(), keyInfos);
+ if (DEBUG) Log.d(LOGTAG, "Key successfully added for session " + sessionId);
+ }
+
protected void onSessionCreated(int createSessionToken,
int promiseId,
byte[] sessionId,
byte[] request) {
assertTrue(mCallbacks != null);
mCallbacks.onSessionCreated(createSessionToken, promiseId, sessionId, request);
}
--- a/mobile/android/base/java/org/mozilla/gecko/media/GeckoMediaDrmBridgeV23.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/GeckoMediaDrmBridgeV23.java
@@ -11,26 +11,26 @@ import android.media.NotProvisionedExcep
import static android.os.Build.VERSION_CODES.M;
import android.media.MediaDrm;
import android.util.Log;
import java.lang.IllegalStateException;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.List;
+@TargetApi(M)
public class GeckoMediaDrmBridgeV23 extends GeckoMediaDrmBridgeV21 {
private static final boolean DEBUG = false;
GeckoMediaDrmBridgeV23(String keySystem) throws Exception {
super(keySystem);
if (DEBUG) Log.d(LOGTAG, "GeckoMediaDrmBridgeV23 ctor");
mDrm.setOnKeyStatusChangeListener(new KeyStatusChangeListener(), null);
}
- @TargetApi(M)
private class KeyStatusChangeListener implements MediaDrm.OnKeyStatusChangeListener {
@Override
public void onKeyStatusChange(MediaDrm mediaDrm,
byte[] sessionId,
List<MediaDrm.KeyStatus> keyInformation,
boolean hasNewUsableKey) {
if (DEBUG) Log.d(LOGTAG, "[onKeyStatusChange] hasNewUsableKey = " + hasNewUsableKey);
if (keyInformation.size() == 0) {
@@ -43,43 +43,14 @@ public class GeckoMediaDrmBridgeV23 exte
keyStatus.getStatusCode());
}
onSessionBatchedKeyChanged(sessionId, keyInfos);
if (DEBUG) Log.d(LOGTAG, "Key successfully added for session " + new String(sessionId));
}
}
@Override
- public void updateSession(int promiseId,
- String sessionId,
- byte[] response) {
- if (DEBUG) Log.d(LOGTAG, "updateSession(), sessionId = " + sessionId);
- if (mDrm == null) {
- onRejectPromise(promiseId, "MediaDrm instance doesn't exist !!");
- return;
- }
-
- ByteBuffer session = ByteBuffer.wrap(sessionId.getBytes());
- if (!sessionExists(session)) {
- onRejectPromise(promiseId, "Invalid session during updateSession.");
- return;
- }
-
- try {
- final byte [] keySetId = mDrm.provideKeyResponse(session.array(), response);
- if (DEBUG) {
- HashMap<String, String> infoMap = mDrm.queryKeyStatus(session.array());
- for (String strKey : infoMap.keySet()) {
- String strValue = infoMap.get(strKey);
- Log.d(LOGTAG, "InfoMap : key(" + strKey + ")/value(" + strValue + ")");
- }
- }
- onSessionUpdated(promiseId, session.array());
- return;
- } catch (final NotProvisionedException | DeniedByServerException | IllegalStateException e) {
- if (DEBUG) Log.d(LOGTAG, "Failed to provide key response:", e);
- onSessionError(session.array(), "Got exception during updateSession.");
- onRejectPromise(promiseId, "Got exception during updateSession.");
- }
- release();
- return;
+ protected void HandleKeyStatusChangeByDummyKey(String sessionId)
+ {
+ // MediaDrm.KeyStatus information listener is supported on M+, there is no need to use
+ // dummy key id to report key status anymore.
}
}
--- a/mobile/android/base/java/org/mozilla/gecko/media/LocalMediaDrmBridge.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/LocalMediaDrmBridge.java
@@ -81,19 +81,19 @@ final class LocalMediaDrmBridge implemen
private static void assertTrue(boolean condition) {
if (DEBUG && !condition) {
throw new AssertionError("Expected condition to be true");
}
}
LocalMediaDrmBridge(String keySystem) throws Exception {
if (AppConstants.Versions.preLollipop) {
+ Log.e(LOGTAG, "Pre-Lollipop should never enter here!!");
mBridge = null;
- } else if (AppConstants.Versions.feature21Plus &&
- AppConstants.Versions.preMarshmallow) {
+ } else if (AppConstants.Versions.preMarshmallow) {
mBridge = new GeckoMediaDrmBridgeV21(keySystem);
} else {
mBridge = new GeckoMediaDrmBridgeV23(keySystem);
}
}
@Override
public synchronized void setCallbacks(Callbacks callbacks) {
--- a/mobile/android/base/java/org/mozilla/gecko/media/RemoteMediaDrmBridgeStub.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/RemoteMediaDrmBridgeStub.java
@@ -146,18 +146,17 @@ final class RemoteMediaDrmBridgeStub ext
}
RemoteMediaDrmBridgeStub(String keySystem, String stubId) throws RemoteException {
if (AppConstants.Versions.preLollipop) {
Log.e(LOGTAG, "Pre-Lollipop should never enter here!!");
throw new RemoteException("Error, unsupported version!");
}
try {
- if (AppConstants.Versions.feature21Plus &&
- AppConstants.Versions.preMarshmallow) {
+ if (AppConstants.Versions.preMarshmallow) {
mBridge = new GeckoMediaDrmBridgeV21(keySystem);
} else {
mBridge = new GeckoMediaDrmBridgeV23(keySystem);
}
mStubId = stubId;
mBridgeStubs.add(this);
} catch (Exception e) {
throw new RemoteException("RemoteMediaDrmBridgeStub cannot create bridge implementation.");