Merge "Fix StringIndexOutOfBoundsException in MediaDrmAPITest" into nyc-dev
This commit is contained in:
@@ -9,6 +9,8 @@ LOCAL_PACKAGE_NAME := MediaDrmAPITest
|
|||||||
|
|
||||||
LOCAL_JAVA_LIBRARIES := org.apache.http.legacy
|
LOCAL_JAVA_LIBRARIES := org.apache.http.legacy
|
||||||
|
|
||||||
|
LOCAL_DEX_PREOPT := false
|
||||||
|
|
||||||
# TODO: This test app depends on framework implementation details.
|
# TODO: This test app depends on framework implementation details.
|
||||||
# LOCAL_SDK_VERSION := current
|
# LOCAL_SDK_VERSION := current
|
||||||
|
|
||||||
|
|||||||
@@ -142,7 +142,6 @@ public class MediaDrmAPITest extends Activity {
|
|||||||
|
|
||||||
testClearContentNoKeys();
|
testClearContentNoKeys();
|
||||||
testEncryptedContent();
|
testEncryptedContent();
|
||||||
testEncryptedAESSampleContent();
|
|
||||||
testEncryptedContentSharingKeys();
|
testEncryptedContentSharingKeys();
|
||||||
testEncryptedContentNoKeys();
|
testEncryptedContentNoKeys();
|
||||||
|
|
||||||
@@ -334,17 +333,6 @@ public class MediaDrmAPITest extends Activity {
|
|||||||
stopDrm(drm);
|
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() {
|
private void testEncryptedContentSharingKeys() {
|
||||||
MediaDrm drm = startDrm();
|
MediaDrm drm = startDrm();
|
||||||
drm.setPropertyString("sessionSharing", "enable");
|
drm.setPropertyString("sessionSharing", "enable");
|
||||||
@@ -653,6 +641,7 @@ public class MediaDrmAPITest extends Activity {
|
|||||||
|
|
||||||
final int kMaxSubsamplesPerSample = 10;
|
final int kMaxSubsamplesPerSample = 10;
|
||||||
final int kMaxSampleSize = 128 * 1024;
|
final int kMaxSampleSize = 128 * 1024;
|
||||||
|
final int kErrorTestMode = -2500;
|
||||||
|
|
||||||
int clearSizes[] = new int[kMaxSubsamplesPerSample];
|
int clearSizes[] = new int[kMaxSubsamplesPerSample];
|
||||||
int encryptedSizes[] = new int[kMaxSubsamplesPerSample];
|
int encryptedSizes[] = new int[kMaxSubsamplesPerSample];
|
||||||
@@ -689,6 +678,8 @@ public class MediaDrmAPITest extends Activity {
|
|||||||
if (expectNoKey) {
|
if (expectNoKey) {
|
||||||
Log.e(TAG, "MediaCrypto failed to throw ERROR_NO_KEY!");
|
Log.e(TAG, "MediaCrypto failed to throw ERROR_NO_KEY!");
|
||||||
mTestFailed = true;
|
mTestFailed = true;
|
||||||
|
codec.stop();
|
||||||
|
codec.release();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -706,33 +697,44 @@ public class MediaDrmAPITest extends Activity {
|
|||||||
Log.e(TAG, "MediaCrypto reports no key loaded!");
|
Log.e(TAG, "MediaCrypto reports no key loaded!");
|
||||||
mTestFailed = true;
|
mTestFailed = true;
|
||||||
}
|
}
|
||||||
|
codec.stop();
|
||||||
|
codec.release();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// in test mode, the WV CryptoPlugin throws a CryptoException where the
|
// in test mode, the WV CryptoPlugin throws a CryptoException where the
|
||||||
// message string contains a SHA256 hash of the decrypted data, for verification
|
// message string contains a SHA256 hash of the decrypted data, for verification
|
||||||
// purposes.
|
// purposes.
|
||||||
if (!e.getMessage().equals("secure")) {
|
if (e.getErrorCode() == kErrorTestMode) {
|
||||||
Log.i(TAG, "e.getMessage()='" + e.getMessage() + "'");
|
if (!e.getMessage().equals("secure")) {
|
||||||
MessageDigest digest = null;
|
Log.i(TAG, "e.getMessage()='" + e.getMessage() + "'");
|
||||||
try {
|
MessageDigest digest = null;
|
||||||
digest = MessageDigest.getInstance("SHA-256");
|
try {
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
digest = MessageDigest.getInstance("SHA-256");
|
||||||
ex.printStackTrace();
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
finish();
|
ex.printStackTrace();
|
||||||
}
|
finish();
|
||||||
byte buf[] = Arrays.copyOf(refBuffer.array(), sampleSize);
|
}
|
||||||
byte[] sha256 = digest.digest(buf);
|
byte buf[] = Arrays.copyOf(refBuffer.array(), sampleSize);
|
||||||
if (Arrays.equals(sha256, hex2ba(e.getMessage()))) {
|
byte[] sha256 = digest.digest(buf);
|
||||||
Log.i(TAG, "sha256: " + e.getMessage() + " matches OK");
|
if (Arrays.equals(sha256, hex2ba(e.getMessage()))) {
|
||||||
} else {
|
Log.i(TAG, "sha256: " + e.getMessage() + " matches OK");
|
||||||
Log.i(TAG, "MediaCrypto sha256: " + e.getMessage() +
|
} else {
|
||||||
" does not match test vector sha256: ");
|
Log.i(TAG, "MediaCrypto sha256: " + e.getMessage() +
|
||||||
for (int i = 0; i < sha256.length; i++) {
|
" does not match test vector sha256: ");
|
||||||
System.out.printf("%02x", sha256[i]);
|
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