Revert "Create unique cdm engines per WVDrmPlugin instance"

This change introduced b/77618383, need to revert.

This reverts commit 58234a69f2.

Change-Id: Ie7d515bcd94f2dcee6fa9b885cd0441845c82c22

Bug: 77618383
(cherry picked from commit 90441e24df)

Change-Id: I114cb3cf5b69e2698d407ba4cf15cefcad2aaf3d
This commit is contained in:
Jeff Tinker
2018-04-05 17:56:43 +00:00
committed by android-build-team Robot
parent 94157fbfeb
commit 629e179f7c
11 changed files with 198 additions and 338 deletions

View File

@@ -20,7 +20,6 @@
#include "gtest/gtest.h"
#include "media/stagefright/foundation/ABase.h"
#include "media/stagefright/MediaErrors.h"
#include "string_conversions.h"
#include "wv_cdm_constants.h"
#include "wv_cdm_types.h"
#include "wv_content_decryption_module.h"
@@ -121,17 +120,15 @@ const uint8_t* const kUnprovisionResponse =
const size_t kUnprovisionResponseSize = 11;
const std::string kDeviceId("0123456789\0ABCDEF", 17);
// This is a serialized WvCdmMetrics message containing a small amount of
// This is a serialized MetricsGroup message containing a small amount of
// sample data. This ensures we're able to extract it via a property.
const char kSerializedMetricsHex[] =
"0a580a001a0210072202100d2a02100832182216636f6d2e676f6f676c652e616e64726f69"
"642e676d734208220631342e302e304a06080112020800520610d5f3fad5056a0b1d00fd4c"
"47280132020804a2010608011202080012cb010a0622047369643412b5010a021001520919"
"1d5a643bdfff50405a0b1d00d01945280132021001620d1d00f8e84528013204080020006a"
"0310b739820102100d8a01060801120248009a010310ff01da0106080112024800e2010e1d"
"005243472801320528800248009a020d1d00b016452801320428404800a202060801120248"
"19aa0206080212024800b2020b1d8098f047280132024800ba02021001ca020b1d00101945"
"280132024800e202021004fa02021002a203021000b2030210021a09196891ed7c3f355040";
const char kSerializedMetrics[] = {
0x0a, 0x0a, 0x0a, 0x04, 0x74, 0x65, 0x73, 0x74, 0x12, 0x02, 0x08, 0x00,
0x0a, 0x12, 0x0a, 0x05, 0x74, 0x65, 0x73, 0x74, 0x32, 0x12, 0x09, 0x11,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x15, 0x0a, 0x05,
0x74, 0x65, 0x73, 0x74, 0x33, 0x12, 0x0c, 0x1a, 0x0a, 0x74, 0x65, 0x73,
0x74, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65
};
#define N_ELEM(a) (sizeof(a)/sizeof(a[0]))
} // anonymous namespace
@@ -201,8 +198,7 @@ class MockCDM : public WvContentDecryptionModule {
MOCK_METHOD1(IsValidServiceCertificate, bool(const std::string&));
MOCK_METHOD2(GetMetrics, CdmResponseType(const CdmIdentifier&,
drm_metrics::WvCdmMetrics*));
MOCK_METHOD1(GetSerializedMetrics, void(std::string*));
};
class MockCrypto : public WVGenericCryptoInterface {
@@ -1130,9 +1126,8 @@ TEST_F(WVDrmPluginTest, ReturnsExpectedPropertyValues) {
static const std::string oemCryptoApiVersion = "13";
static const std::string currentSRMVersion = "1";
static const std::string cdmVersion = "Infinity Minus 1";
drm_metrics::WvCdmMetrics expected_metrics;
std::string serialized_metrics = wvcdm::a2bs_hex(kSerializedMetricsHex);
ASSERT_TRUE(expected_metrics.ParseFromString(serialized_metrics));
std::string serializedMetrics(
kSerializedMetrics, kSerializedMetrics + sizeof(kSerializedMetrics));
EXPECT_CALL(*cdm, QueryStatus(_, QUERY_KEY_SECURITY_LEVEL, _))
.WillOnce(DoAll(SetArgPointee<2>(QUERY_VALUE_SECURITY_LEVEL_L1),
@@ -1176,9 +1171,8 @@ TEST_F(WVDrmPluginTest, ReturnsExpectedPropertyValues) {
.WillOnce(DoAll(SetArgPointee<2>(cdmVersion),
testing::Return(wvcdm::NO_ERROR)));
EXPECT_CALL(*cdm, GetMetrics(_, _))
.WillOnce(DoAll(SetArgPointee<1>(expected_metrics),
testing::Return(wvcdm::NO_ERROR)));
EXPECT_CALL(*cdm, GetSerializedMetrics(_))
.WillOnce(SetArgPointee<0>(serializedMetrics));
WVDrmPlugin plugin(cdm.get(), appPackageName, &crypto, false);
std::string stringResult;
@@ -1281,51 +1275,14 @@ TEST_F(WVDrmPluginTest, ReturnsExpectedPropertyValues) {
EXPECT_STREQ(currentSRMVersion.c_str(), stringResult.c_str());
});
// This call occurs before any open session or other call. This means
// that the cdm identifer is not yet sealed, and metrics return empty
// metrics data.
plugin.getPropertyByteArray(
hidl_string("metrics"),
[&](Status status, hidl_vec<uint8_t> vectorResult) {
ASSERT_EQ(Status::OK, status);
std::vector<uint8_t> id(vectorResult);
const char empty[] = {};
EXPECT_THAT(id, ElementsAreArray(empty, sizeof(empty)));
EXPECT_THAT(id, ElementsAreArray(serializedMetrics.data(),
serializedMetrics.size()));
});
// Set expectations for the OpenSession call and a CloseSession call.
EXPECT_CALL(*cdm,
OpenSession(StrEq("com.widevine"), _, HasOrigin(EMPTY_ORIGIN), _, _))
.WillOnce(DoAll(SetArgPointee<4>(cdmSessionId),
testing::Return(wvcdm::NO_ERROR)));
// Provide expected behavior when plugin requests session control info
EXPECT_CALL(*cdm, QueryOemCryptoSessionId(cdmSessionId, _))
.Times(AtLeast(1))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
EXPECT_CALL(*cdm, CloseSession(_))
.Times(AtLeast(0));
// This call causes the cdm identifier to become sealed.
std::vector<uint8_t> sessionId;
plugin.openSession([&](Status status, hidl_vec<uint8_t> hSessionId) {
ASSERT_EQ(Status::OK, status);
sessionId.clear();
sessionId.assign(hSessionId.data(),
hSessionId.data() + hSessionId.size());
});
// This call occurs after open session. The CDM identifer should be sealed.
// And the call should populate the mock metrics data.
plugin.getPropertyByteArray(
hidl_string("metrics"),
[&](Status status, hidl_vec<uint8_t> vectorResult) {
ASSERT_EQ(Status::OK, status);
std::vector<uint8_t> id(vectorResult);
EXPECT_THAT(id, ElementsAreArray(serialized_metrics.data(),
serialized_metrics.size()));
});
ASSERT_EQ(Status::OK, plugin.closeSession(toHidlVec(sessionId)));
}
TEST_F(WVDrmPluginTest, DoesNotGetUnknownProperties) {