Add a field indicating online vs offline licenses.

Import of http://go/wvgerrit/68188

This adds an attribute to metrics indicating if the license was online
or offline.

Also, added a unit test for CdmEngineMetricsImpl.

Test: Unit tests. GPlay manual. GTS tests.
Bug: 115523917

Change-Id: Id315c643048914a2c51904451f9665987bc87eb7
This commit is contained in:
Adam Stone
2018-12-11 10:40:32 -08:00
parent 4c5c4caf66
commit 0a64d25067
11 changed files with 88 additions and 11 deletions

View File

@@ -97,6 +97,9 @@ class CdmEngine {
// process the response. Should be empty if a release response.
// |key_data| is the license, renewal, release response or service
// certificate response.
// |license_type| must not be null. If the result is KEY_ADDED, this out
// parameter indicates the type of license containd in
// key_data. For any other return code, no value is provided.
// |key_set_id| should be non-null and specified if license release.
// If offline license or streaming license associated with
// a secure stop, |key_set_id| should be non-null and will
@@ -107,6 +110,7 @@ class CdmEngine {
// (not associated with a secure stop).
virtual CdmResponseType AddKey(const CdmSessionId& session_id,
const CdmKeyResponse& key_data,
CdmLicenseType* license_type,
CdmKeySetId* key_set_id);
virtual CdmResponseType RestoreKey(const CdmSessionId& session_id,

View File

@@ -5,6 +5,7 @@
#ifndef WVCDM_CORE_WV_CDM_TYPES_H_
#define WVCDM_CORE_WV_CDM_TYPES_H_
#include <array>
#include <stdint.h>
#include <map>
#include <string>

View File

@@ -311,8 +311,13 @@ CdmResponseType CdmEngine::GenerateKeyRequest(
CdmResponseType CdmEngine::AddKey(const CdmSessionId& session_id,
const CdmKeyResponse& key_data,
CdmLicenseType* license_type,
CdmKeySetId* key_set_id) {
LOGI("CdmEngine::AddKey");
if (license_type == nullptr) {
LOGE("CdmEngine::AddKey: license_type cannot be null.");
return PARAMETER_NULL;
}
CdmSessionId id = session_id;
bool license_type_release = session_id.empty();
@@ -349,7 +354,21 @@ CdmResponseType CdmEngine::AddKey(const CdmSessionId& session_id,
return EMPTY_KEY_DATA_1;
}
CdmResponseType sts = session->AddKey(key_data);
CdmResponseType sts = (session->AddKey(key_data));
if (sts == KEY_ADDED) {
if (session->is_release()) {
*license_type = kLicenseTypeRelease;
} else if (session->is_temporary()) {
*license_type = kLicenseTypeTemporary;
} else if (session->is_offline()) {
*license_type = kLicenseTypeOffline;
} else {
*license_type = kLicenseTypeStreaming;
}
}
if (key_set_id) {
if ((session->is_offline() ||
session->has_provider_session_token()) && !license_type_release) {

View File

@@ -159,6 +159,12 @@ class WvCdmEngineTest : public WvCdmEnginePreProvTest {
protected:
void GenerateKeyRequest(const std::string& key_id,
const std::string& init_data_type_string) {
GenerateKeyRequest(key_id, init_data_type_string, kLicenseTypeStreaming);
}
void GenerateKeyRequest(const std::string& key_id,
const std::string& init_data_type_string,
CdmLicenseType license_type) {
CdmAppParameterMap app_parameters;
CdmKeySetId key_set_id;
@@ -167,7 +173,7 @@ class WvCdmEngineTest : public WvCdmEnginePreProvTest {
CdmKeyRequest key_request;
CdmResponseType result = cdm_engine_.GenerateKeyRequest(
session_id_, key_set_id, init_data, kLicenseTypeStreaming,
session_id_, key_set_id, init_data, license_type,
app_parameters, &key_request);
EXPECT_EQ(KEY_MESSAGE, result);
@@ -234,9 +240,19 @@ class WvCdmEngineTest : public WvCdmEnginePreProvTest {
void VerifyNewKeyResponse(const std::string& server_url,
const std::string& client_auth) {
VerifyNewKeyResponse(server_url, client_auth, kLicenseTypeStreaming);
}
void VerifyNewKeyResponse(const std::string& server_url,
const std::string& client_auth,
CdmLicenseType expected_license_type) {
std::string resp = GetKeyRequestResponse(server_url, client_auth);
CdmKeySetId key_set_id;
EXPECT_EQ(KEY_ADDED, cdm_engine_.AddKey(session_id_, resp, &key_set_id));
CdmLicenseType license_type;
CdmResponseType status =
cdm_engine_.AddKey(session_id_, resp, &license_type, &key_set_id);
EXPECT_EQ(KEY_ADDED, status);
EXPECT_EQ(expected_license_type, license_type);
VerifyLicenseRequestLatency(kKeyRequestTypeInitial,
*cdm_engine_.GetMetrics());
}
@@ -335,6 +351,13 @@ TEST_F(WvCdmEngineTest, NormalDecryptionIsoBmff) {
VerifyNewKeyResponse(config_.license_server(), config_.client_auth());
}
// TODO(blueeyes): Add tests for different license types.
TEST_F(WvCdmEngineTest, ReturnsLicenseTypeDetailStreaming) {
GenerateKeyRequest(binary_key_id(), kCencMimeType, kLicenseTypeStreaming);
VerifyNewKeyResponse(config_.license_server(), config_.client_auth(),
kLicenseTypeStreaming);
}
// TODO(juce): Set up with correct test data.
TEST_F(WvCdmEngineTest, DISABLED_NormalDecryptionWebm) {
// Extract the key ID from the PSSH box.

View File

@@ -610,8 +610,10 @@ void TestLicenseHolder::SignAndLoadLicense() {
signed_response.SerializeToString(&response_data);
CdmKeySetId key_set_id;
CdmLicenseType license_type; // Required for AddKey. Result value ignored.
EXPECT_EQ(KEY_ADDED,
cdm_engine_->AddKey(session_id_, response_data, &key_set_id));
cdm_engine_->AddKey(session_id_, response_data,
&license_type, &key_set_id));
}
void TestLicenseHolder::DeriveKeysFromSessionKey() {