Fix StringIndexOutOfBoundsException in MediaDrmAPITest
The AES test was useful to verify the framework API changes, but the decrypt test was not correct. Removing it for now. Merge of go/wvgerrit/17472 bug: 27973491 Change-Id: I942fda22072636ea7ce56b992e7d3a60077c0d27
This commit is contained in:
@@ -9,6 +9,8 @@ LOCAL_PACKAGE_NAME := MediaDrmAPITest
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := org.apache.http.legacy
|
||||
|
||||
LOCAL_DEX_PREOPT := false
|
||||
|
||||
# TODO: This test app depends on framework implementation details.
|
||||
# LOCAL_SDK_VERSION := current
|
||||
|
||||
|
||||
@@ -142,7 +142,6 @@ public class MediaDrmAPITest extends Activity {
|
||||
|
||||
testClearContentNoKeys();
|
||||
testEncryptedContent();
|
||||
testEncryptedAESSampleContent();
|
||||
testEncryptedContentSharingKeys();
|
||||
testEncryptedContentNoKeys();
|
||||
|
||||
@@ -334,17 +333,6 @@ public class MediaDrmAPITest extends Activity {
|
||||
stopDrm(drm);
|
||||
}
|
||||
|
||||
private void testEncryptedAESSampleContent() {
|
||||
Log.d(TAG, "testEncryptedAESSampleContent");
|
||||
MediaDrm drm = startDrm();
|
||||
byte[] sessionId = openSession(drm);
|
||||
if (getKeys(drm, sessionId)) {
|
||||
testAESSampleDecrypt(sessionId, kRequireKey);
|
||||
}
|
||||
drm.closeSession(sessionId);
|
||||
stopDrm(drm);
|
||||
}
|
||||
|
||||
private void testEncryptedContentSharingKeys() {
|
||||
MediaDrm drm = startDrm();
|
||||
drm.setPropertyString("sessionSharing", "enable");
|
||||
@@ -653,6 +641,7 @@ public class MediaDrmAPITest extends Activity {
|
||||
|
||||
final int kMaxSubsamplesPerSample = 10;
|
||||
final int kMaxSampleSize = 128 * 1024;
|
||||
final int kErrorTestMode = -2500;
|
||||
|
||||
int clearSizes[] = new int[kMaxSubsamplesPerSample];
|
||||
int encryptedSizes[] = new int[kMaxSubsamplesPerSample];
|
||||
@@ -689,6 +678,8 @@ public class MediaDrmAPITest extends Activity {
|
||||
if (expectNoKey) {
|
||||
Log.e(TAG, "MediaCrypto failed to throw ERROR_NO_KEY!");
|
||||
mTestFailed = true;
|
||||
codec.stop();
|
||||
codec.release();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -706,33 +697,44 @@ public class MediaDrmAPITest extends Activity {
|
||||
Log.e(TAG, "MediaCrypto reports no key loaded!");
|
||||
mTestFailed = true;
|
||||
}
|
||||
codec.stop();
|
||||
codec.release();
|
||||
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.
|
||||
if (!e.getMessage().equals("secure")) {
|
||||
Log.i(TAG, "e.getMessage()='" + e.getMessage() + "'");
|
||||
MessageDigest digest = null;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("SHA-256");
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
ex.printStackTrace();
|
||||
finish();
|
||||
}
|
||||
byte buf[] = Arrays.copyOf(refBuffer.array(), sampleSize);
|
||||
byte[] sha256 = digest.digest(buf);
|
||||
if (Arrays.equals(sha256, hex2ba(e.getMessage()))) {
|
||||
Log.i(TAG, "sha256: " + e.getMessage() + " matches OK");
|
||||
} else {
|
||||
Log.i(TAG, "MediaCrypto sha256: " + e.getMessage() +
|
||||
" does not match test vector sha256: ");
|
||||
for (int i = 0; i < sha256.length; i++) {
|
||||
System.out.printf("%02x", sha256[i]);
|
||||
if (e.getErrorCode() == kErrorTestMode) {
|
||||
if (!e.getMessage().equals("secure")) {
|
||||
Log.i(TAG, "e.getMessage()='" + e.getMessage() + "'");
|
||||
MessageDigest digest = null;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("SHA-256");
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
ex.printStackTrace();
|
||||
finish();
|
||||
}
|
||||
byte buf[] = Arrays.copyOf(refBuffer.array(), sampleSize);
|
||||
byte[] sha256 = digest.digest(buf);
|
||||
if (Arrays.equals(sha256, hex2ba(e.getMessage()))) {
|
||||
Log.i(TAG, "sha256: " + e.getMessage() + " matches OK");
|
||||
} else {
|
||||
Log.i(TAG, "MediaCrypto sha256: " + e.getMessage() +
|
||||
" does not match test vector sha256: ");
|
||||
for (int i = 0; i < sha256.length; i++) {
|
||||
System.out.printf("%02x", sha256[i]);
|
||||
}
|
||||
mTestFailed = true;
|
||||
}
|
||||
mTestFailed = true;
|
||||
}
|
||||
} else {
|
||||
// An unexpected exception occurred
|
||||
e.printStackTrace();
|
||||
mTestFailed = true;
|
||||
codec.stop();
|
||||
codec.release();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user