Support GetPropertyByteArray for getting metrics.

Adds support for GetPropertyByteArray to return a serialized set of metrics
to the caller. This should be the last part of the widevine plugin
changes that fix the referenced bug.  More changes are coming on the
MediaDrm side.

This is a merge of wvgerrit/28422

I intend to submit 2048751, 2048750, and 2048509 together.

Bug: 36217927
Test: Added additional unit tests for affected code.
Change-Id: I2618c2be48d7d780127e35f237e2276efd080879
This commit is contained in:
Adam Stone
2017-03-30 11:31:51 -07:00
parent b851dd8cfd
commit a0da1f067b
9 changed files with 85 additions and 32 deletions

View File

@@ -114,7 +114,17 @@ const std::string kAppId("com.unittest.mock.app.id");
const uint8_t* const kUnprovisionResponse =
reinterpret_cast<const uint8_t*>("unprovision");
const size_t kUnprovisionResponseSize = 11;
}
const std::string kDeviceId = "0123456789ABCDEF";
// 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 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};
} // anonymous namespace
class MockCDM : public WvContentDecryptionModule {
public:
@@ -177,6 +187,8 @@ class MockCDM : public WvContentDecryptionModule {
CdmResponseType(const CdmUsageInfoReleaseMessage&));
MOCK_METHOD1(IsValidServiceCertificate, bool(const std::string&));
MOCK_METHOD1(GetSerializedMetrics, void(std::string*));
};
class MockCrypto : public WVGenericCryptoInterface {
@@ -1040,6 +1052,8 @@ TEST_F(WVDrmPluginTest, ReturnsExpectedPropertyValues) {
static const std::string openSessions = "42";
static const std::string maxSessions = "54";
static const std::string oemCryptoApiVersion = "13";
std::string serializedMetrics(
kSerializedMetrics, kSerializedMetrics + sizeof(kSerializedMetrics));
EXPECT_CALL(*cdm, QueryStatus(_, QUERY_KEY_SECURITY_LEVEL, _))
.WillOnce(DoAll(SetArgPointee<2>(QUERY_VALUE_SECURITY_LEVEL_L1),
@@ -1071,6 +1085,9 @@ TEST_F(WVDrmPluginTest, ReturnsExpectedPropertyValues) {
.WillOnce(DoAll(SetArgPointee<2>(oemCryptoApiVersion),
testing::Return(wvcdm::NO_ERROR)));
EXPECT_CALL(*cdm, GetSerializedMetrics(_))
.WillOnce(SetArgPointee<0>(serializedMetrics));
WVDrmPlugin plugin(cdm.get(), appPackageName, &crypto, false);
std::string stringResult;
std::vector<uint8_t> vectorResult;
@@ -1157,6 +1174,15 @@ TEST_F(WVDrmPluginTest, ReturnsExpectedPropertyValues) {
ASSERT_EQ(Status::OK, status);
EXPECT_EQ(oemCryptoApiVersion, stringResult.c_str());
});
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(serializedMetrics.data(),
serializedMetrics.size()));
});
}
TEST_F(WVDrmPluginTest, DoesNotGetUnknownProperties) {

View File

@@ -32,7 +32,16 @@ const String8 kAppId("com.unittest.mock.app.id");
const uint8_t* const kUnprovisionResponse =
reinterpret_cast<const uint8_t*>("unprovision");
const size_t kUnprovisionResponseSize = 11;
}
// 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 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};
} // anonymous namespace
class MockCDM : public WvContentDecryptionModule {
public:
@@ -95,6 +104,8 @@ class MockCDM : public WvContentDecryptionModule {
CdmResponseType(const CdmUsageInfoReleaseMessage&));
MOCK_METHOD1(IsValidServiceCertificate, bool(const std::string&));
MOCK_METHOD1(GetSerializedMetrics, void(std::string*));
};
class MockCrypto : public WVGenericCryptoInterface {
@@ -833,6 +844,8 @@ TEST_F(WVDrmPluginTest, ReturnsExpectedPropertyValues) {
static const string openSessions = "15";
static const string maxSessions = "18";
static const string oemCryptoApiVersion = "10";
string serializedMetrics(kSerializedMetrics,
kSerializedMetrics + sizeof(kSerializedMetrics));
EXPECT_CALL(*cdm, QueryStatus(_, QUERY_KEY_SECURITY_LEVEL, _))
.WillOnce(DoAll(SetArgPointee<2>(QUERY_VALUE_SECURITY_LEVEL_L1),
@@ -864,6 +877,9 @@ TEST_F(WVDrmPluginTest, ReturnsExpectedPropertyValues) {
.WillOnce(DoAll(SetArgPointee<2>(oemCryptoApiVersion),
Return(wvcdm::NO_ERROR)));
EXPECT_CALL(*cdm, GetSerializedMetrics(_))
.WillOnce(SetArgPointee<0>(serializedMetrics));
String8 stringResult;
Vector<uint8_t> vectorResult;
@@ -915,6 +931,12 @@ TEST_F(WVDrmPluginTest, ReturnsExpectedPropertyValues) {
res = plugin.getPropertyString(String8("oemCryptoApiVersion"), stringResult);
ASSERT_EQ(OK, res);
EXPECT_EQ(oemCryptoApiVersion, stringResult.string());
vectorResult.clear();
res = plugin.getPropertyByteArray(String8("metrics"), vectorResult);
ASSERT_EQ(OK, res);
EXPECT_THAT(vectorResult, ElementsAreArray(serializedMetrics.data(),
serializedMetrics.size()));
}
TEST_F(WVDrmPluginTest, DoesNotGetUnknownProperties) {