Enable usage header table and entries

[ Merge of http://go/wvgerrit/24022 ]

b/34327459

Test: Verified by unit, integration tests on angler

Change-Id: Idb17dc472dddbdad217c35bdaa3fb20ae8152371
This commit is contained in:
Rahul Frias
2017-02-14 10:45:44 -08:00
parent 826e390ad6
commit db5c3dfb6d
7 changed files with 334 additions and 78 deletions

View File

@@ -1043,7 +1043,7 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
usage_session_.reset(new CdmSession(file_system_));
CdmResponseType status = usage_session_->Init(usage_property_set_.get());
if (NO_ERROR != status) {
LOGE("CdmEngine::GetUsageInfo: session init error");
LOGE("CdmEngine::GetUsageInfo: session init error: %d", status);
return status;
}
DeviceFiles handle(file_system_);
@@ -1055,11 +1055,9 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
CdmKeyMessage license_request;
CdmKeyResponse license_response;
std::string usage_entry;
uint32_t usage_entry_number = 0;
DeviceFiles::CdmUsageData usage_data;
if (!handle.RetrieveUsageInfo(DeviceFiles::GetUsageInfoFileName(app_id),
ssid, &license_request,
&license_response, &usage_entry,
&usage_entry_number)) {
ssid, &usage_data)) {
usage_property_set_->set_security_level(kLevel3);
usage_property_set_->set_app_id(app_id);
usage_session_.reset(new CdmSession(file_system_));
@@ -1073,16 +1071,14 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
return GET_USAGE_INFO_ERROR_2;
}
if (!handle.RetrieveUsageInfo(DeviceFiles::GetUsageInfoFileName(app_id),
ssid, &license_request,
&license_response, &usage_entry,
&usage_entry_number)) {
ssid, &usage_data)) {
// No entry found for that ssid.
return USAGE_INFO_NOT_FOUND;
}
}
status =
usage_session_->RestoreUsageSession(license_request,license_response);
usage_session_->RestoreUsageSession(usage_data);
if (KEY_ADDED != status) {
LOGE("CdmEngine::GetUsageInfo: restore usage session error %d", status);
@@ -1152,9 +1148,9 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
return GET_USAGE_INFO_ERROR_3;
}
std::vector<std::pair<CdmKeyMessage, CdmKeyResponse> > license_info;
std::vector<DeviceFiles::CdmUsageData> usage_data;
if (!handle.RetrieveUsageInfo(DeviceFiles::GetUsageInfoFileName(app_id),
&license_info)) {
&usage_data)) {
LOGE("CdmEngine::GetUsageInfo: unable to read usage information");
return GET_USAGE_INFO_ERROR_4;
}
@@ -1163,16 +1159,15 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
LOGE("CdmEngine::GetUsageInfo: no usage info destination");
return INVALID_PARAMETERS_ENG_10;
}
if (0 == license_info.size()) {
if (0 == usage_data.size()) {
usage_info->resize(0);
return NO_ERROR;
}
usage_info->resize(kUsageReportsPerRequest);
uint32_t index = rand() % license_info.size();
status = usage_session_->RestoreUsageSession(license_info[index].first,
license_info[index].second);
uint32_t index = rand() % usage_data.size();
status = usage_session_->RestoreUsageSession(usage_data[index]);
if (KEY_ADDED != status) {
LOGE("CdmEngine::GetUsageInfo: restore usage session (%d) error %ld", index,
status);
@@ -1212,25 +1207,49 @@ CdmResponseType CdmEngine::ReleaseAllUsageInfo(const std::string& app_id) {
for (int j = kSecurityLevelL1; j < kSecurityLevelUnknown; ++j) {
DeviceFiles handle(file_system_);
if (handle.Init(static_cast<CdmSecurityLevel>(j))) {
std::vector<std::string> provider_session_tokens;
if (!handle.DeleteAllUsageInfoForApp(
DeviceFiles::GetUsageInfoFileName(app_id),
&provider_session_tokens)) {
LOGE("CdmEngine::ReleaseAllUsageInfo: failed to delete L%d secure"
"stops", j);
status = RELEASE_ALL_USAGE_INFO_ERROR_1;
} else {
SecurityLevel security_level =
static_cast<CdmSecurityLevel>(j) == kSecurityLevelL3
? kLevel3
: kLevelDefault;
usage_property_set_->set_security_level(security_level);
usage_session_.reset(new CdmSession(file_system_));
usage_session_->Init(usage_property_set_.get());
CdmResponseType status2 = usage_session_->
DeleteMultipleUsageInformation(provider_session_tokens);
if (status2 != NO_ERROR) {
status = status2;
SecurityLevel security_level =
static_cast<CdmSecurityLevel>(j) == kSecurityLevelL3
? kLevel3
: kLevelDefault;
usage_property_set_->set_security_level(security_level);
usage_session_.reset(new CdmSession(file_system_));
usage_session_->Init(usage_property_set_.get());
if (usage_session_->get_usage_support_type() == kUsageEntrySupport) {
std::vector<DeviceFiles::CdmUsageData> usage_data;
if (!handle.RetrieveUsageInfo(
DeviceFiles::GetUsageInfoFileName(app_id),
&usage_data)) {
status = RELEASE_ALL_USAGE_INFO_ERROR_4;
} else {
for (size_t k = 0; k < usage_data.size(); ++k) {
CdmResponseType status2 =
usage_session_->DeleteUsageEntry(usage_data[k]);
if (status == NO_ERROR && status2 != NO_ERROR)
status = status2;
}
}
std::vector<std::string> provider_session_tokens;
if (!handle.DeleteAllUsageInfoForApp(
DeviceFiles::GetUsageInfoFileName(app_id),
&provider_session_tokens)) {
status = RELEASE_ALL_USAGE_INFO_ERROR_5;
}
} else if (usage_session_->get_usage_support_type()
== kUsageTableSupport) {
std::vector<std::string> provider_session_tokens;
if (!handle.DeleteAllUsageInfoForApp(
DeviceFiles::GetUsageInfoFileName(app_id),
&provider_session_tokens)) {
LOGE("CdmEngine::ReleaseAllUsageInfo: failed to delete L%d secure"
"stops", j);
status = RELEASE_ALL_USAGE_INFO_ERROR_1;
} else {
CdmResponseType status2 = usage_session_->
DeleteMultipleUsageInformation(provider_session_tokens);
if (status2 != NO_ERROR) {
status = status2;
}
}
}
} else {
@@ -1291,24 +1310,20 @@ CdmResponseType CdmEngine::LoadUsageSession(const CdmKeySetId& key_set_id,
std::string app_id;
iter->second->GetApplicationId(&app_id);
std::string provider_session_token;
CdmKeyMessage key_message;
CdmKeyResponse key_response;
std::string usage_entry;
uint32_t usage_entry_number = 0;
DeviceFiles::CdmUsageData usage_data;
if (!handle.RetrieveUsageInfoByKeySetId(
DeviceFiles::GetUsageInfoFileName(app_id), key_set_id,
&provider_session_token, &key_message, &key_response,
&usage_entry, &usage_entry_number)) {
&(usage_data.provider_session_token),
&(usage_data.license_request),
&(usage_data.license), &(usage_data.usage_entry),
&(usage_data.usage_entry_number))) {
LOGE("CdmEngine::LoadUsageSession: unable to find usage information");
return LOAD_USAGE_INFO_MISSING;
}
CdmResponseType status;
M_TIME(
status = iter->second->RestoreUsageSession(
key_message,
key_response),
status = iter->second->RestoreUsageSession(usage_data),
iter->second->GetMetrics(),
cdm_session_restore_usage_session_,
status);
@@ -1605,19 +1620,24 @@ void CdmEngine::OnTimerEvent() {
for (CdmSessionMap::iterator iter = sessions_.begin();
iter != sessions_.end(); ++iter) {
iter->second->reset_usage_flags();
if (iter->second->get_usage_support_type() == kUsageEntrySupport)
iter->second->UpdateUsageEntryInformation();
if (!has_usage_been_updated) {
// usage is updated for all sessions so this needs to be
// called only once per update usage information period
CdmResponseType status;
M_TIME(
status = iter->second->UpdateUsageInformation(),
iter->second->GetMetrics(),
cdm_session_update_usage_information_,
status);
if (NO_ERROR != status) {
LOGW("Update usage information failed: %d", status);
} else {
has_usage_been_updated = true;
if (iter->second->get_usage_support_type() == kUsageTableSupport) {
CdmResponseType status;
M_TIME(
status = iter->second->UpdateUsageTableInformation(),
iter->second->GetMetrics(),
cdm_session_update_usage_information_,
status);
if (NO_ERROR != status) {
LOGW("Update usage information failed: %d", status);
} else {
has_usage_been_updated = true;
}
}
}
}