Merge "Add tests for key sharing mode and decrypting without keys" into klp-dev

This commit is contained in:
Jeff Tinker
2013-12-19 21:51:55 +00:00
committed by Android (Google) Code Review

View File

@@ -121,6 +121,9 @@ public class MediaDrmAPITest extends Activity {
testWidevineSchemeSupported();
testProperties();
displayText("Running test...screen will blank briefly");
testQueryKeyStatus();
testGenericEncryptAndDecrypt();
@@ -136,6 +139,8 @@ public class MediaDrmAPITest extends Activity {
testClearContentNoKeys();
testEncryptedContent();
testEncryptedContentSharingKeys();
testEncryptedContentNoKeys();
runOnUiThread(new Runnable() {
public void run() {
@@ -305,16 +310,39 @@ public class MediaDrmAPITest extends Activity {
return result;
}
private final boolean kExpectNoKeyError = true;
private final boolean kRequireKey = false;
private void testEncryptedContent() {
MediaDrm drm = startDrm();
byte[] sessionId = openSession(drm);
if (getKeys(drm, sessionId)) {
testDecrypt(sessionId);
testDecrypt(sessionId, kRequireKey);
}
drm.closeSession(sessionId);
stopDrm(drm);
}
private void testEncryptedContentSharingKeys() {
MediaDrm drm = startDrm();
drm.setPropertyString("sessionSharing", "enable");
byte[] sessionId = openSession(drm);
if (getKeys(drm, sessionId)) {
byte[] sessionId2 = openSession(drm);
testDecrypt(sessionId2, kRequireKey);
}
drm.closeSession(sessionId);
stopDrm(drm);
}
private void testEncryptedContentNoKeys() {
MediaDrm drm = startDrm();
byte[] sessionId = openSession(drm);
testDecrypt(sessionId, kExpectNoKeyError);
drm.closeSession(sessionId);
stopDrm(drm);
}
private void testGenericEncryptAndDecrypt() {
final byte[] kOperatorSessionAESPssh = hex2ba("080112103be2b25db355fc64a0e69a50f4dbb298");
@@ -547,7 +575,7 @@ public class MediaDrmAPITest extends Activity {
// do minimal codec setup to pass an encrypted buffer down the stack to see if it gets
// decrypted correctly.
public void testDecrypt(byte[] sessionId) {
public void testDecrypt(byte[] sessionId, boolean expectNoKey) {
Log.i(TAG, "testDecrypt");
MediaCrypto crypto = null;
@@ -618,9 +646,22 @@ public class MediaDrmAPITest extends Activity {
// Log.i(TAG,"Sending " + sampleSize + " bytes, numSubSamples=" + numSubSamples);
codec.queueSecureInputBuffer(index, 0 /* offset */, info,
0 /* sampleTime */, 0 /* flags */);
if (expectNoKey) {
Log.e(TAG, "MediaCrypto failed to throw ERROR_NO_KEY!");
mTestFailed = true;
return;
}
} catch (CryptoException e) {
// Log.i(TAG,"Checking " + sampleSize + " bytes");
if (e.getErrorCode() == CryptoException.ERROR_NO_KEY) {
if (!expectNoKey) {
Log.e(TAG, "MediaCrypto reports no key loaded!");
mTestFailed = true;
}
return;
}
// in test mode, the WV CryptoPlugin throws a CryptoException where the
// message string contains a SHA256 hash of the decrypted data, for verification
// purposes.