Persist usage entry number

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

Usage entries and usage entry numbers need to be stored with license
and usage information, to facilitate loading usage entries when offline
licenses/usage information are restored or prepared for release.

b/34327459

Test: Validated by running unit/integration tests on angler.

Change-Id: I0949fc4cec8a50be0a7700b659dc12bb82ac6f73
This commit is contained in:
Rahul Frias
2017-02-06 23:45:06 -08:00
parent e85e27d596
commit b384408dd2
6 changed files with 104 additions and 48 deletions

View File

@@ -1055,8 +1055,10 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
CdmKeyMessage license_request;
CdmKeyResponse license_response;
std::string usage_entry;
uint32_t usage_entry_number = 0;
if (!handle.RetrieveUsageInfo(app_id, ssid, &license_request,
&license_response, &usage_entry)) {
&license_response, &usage_entry,
&usage_entry_number)) {
usage_property_set_->set_security_level(kLevel3);
usage_property_set_->set_app_id(app_id);
usage_session_.reset(new CdmSession(file_system_));
@@ -1070,7 +1072,8 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id,
return GET_USAGE_INFO_ERROR_2;
}
if (!handle.RetrieveUsageInfo(app_id, ssid, &license_request,
&license_response, &usage_entry)) {
&license_response, &usage_entry,
&usage_entry_number)) {
// No entry found for that ssid.
return USAGE_INFO_NOT_FOUND;
}
@@ -1283,11 +1286,15 @@ 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;
if (!handle.RetrieveUsageInfoByKeySetId(app_id, key_set_id, &key_message,
&key_response, &usage_entry)) {
uint32_t usage_entry_number = 0;
if (!handle.RetrieveUsageInfoByKeySetId(app_id, key_set_id,
&provider_session_token, &key_message,
&key_response, &usage_entry,
&usage_entry_number)) {
LOGE("CdmEngine::LoadUsageSession: unable to find usage information");
return LOAD_USAGE_INFO_MISSING;
}

View File

@@ -179,13 +179,14 @@ CdmResponseType CdmSession::RestoreOfflineSession(
int64_t last_playback_time;
int64_t grace_period_end_time;
std::string usage_entry;
uint32_t usage_entry_number = 0;
if (!file_handle_->RetrieveLicense(
key_set_id, &license_state, &offline_init_data_, &key_request_,
&key_response_, &offline_key_renewal_request_,
&offline_key_renewal_response_, &offline_release_server_url_,
&playback_start_time, &last_playback_time, &grace_period_end_time,
&app_parameters_, &usage_entry)) {
&app_parameters_, &usage_entry, &usage_entry_number)) {
LOGE("CdmSession::Init failed to retrieve license. key set id = %s",
key_set_id.c_str());
return GET_LICENSE_ERROR;
@@ -624,9 +625,10 @@ CdmResponseType CdmSession::StoreLicense() {
std::string app_id;
GetApplicationId(&app_id);
std::string usage_entry;
uint32_t usage_entry_number = 0;
if (!file_handle_->StoreUsageInfo(provider_session_token, key_request_,
key_response_, app_id, key_set_id_,
usage_entry)) {
usage_entry, usage_entry_number)) {
LOGE("CdmSession::StoreLicense: Unable to store usage info");
return STORE_USAGE_INFO_ERROR;
}
@@ -635,12 +637,14 @@ CdmResponseType CdmSession::StoreLicense() {
bool CdmSession::StoreLicense(DeviceFiles::LicenseState state) {
std::string usage_entry;
uint32_t usage_entry_number = 0;
return file_handle_->StoreLicense(
key_set_id_, state, offline_init_data_, key_request_, key_response_,
offline_key_renewal_request_, offline_key_renewal_response_,
offline_release_server_url_, policy_engine_->GetPlaybackStartTime(),
policy_engine_->GetLastPlaybackTime(),
policy_engine_->GetGracePeriodEndTime(), app_parameters_, usage_entry);
policy_engine_->GetGracePeriodEndTime(), app_parameters_, usage_entry,
usage_entry_number);
}
CdmResponseType CdmSession::ReleaseCrypto() {

View File

@@ -177,7 +177,8 @@ bool DeviceFiles::StoreLicense(
const std::string& release_server_url, int64_t playback_start_time,
int64_t last_playback_time, int64_t grace_period_end_time,
const CdmAppParameterMap& app_parameters,
const CdmUsageEntry& usage_entry) {
const CdmUsageEntry& usage_entry,
const uint32_t usage_entry_number) {
if (!initialized_) {
LOGW("DeviceFiles::StoreLicense: not initialized");
return false;
@@ -219,6 +220,7 @@ bool DeviceFiles::StoreLicense(
app_params->set_value(iter->second);
}
license->set_usage_entry(usage_entry);
license->set_usage_entry_number(usage_entry_number);
std::string serialized_file;
file.SerializeToString(&serialized_file);
@@ -233,7 +235,8 @@ bool DeviceFiles::RetrieveLicense(
CdmKeyMessage* license_renewal_request, CdmKeyResponse* license_renewal,
std::string* release_server_url, int64_t* playback_start_time,
int64_t* last_playback_time, int64_t* grace_period_end_time,
CdmAppParameterMap* app_parameters, CdmUsageEntry* usage_entry) {
CdmAppParameterMap* app_parameters, CdmUsageEntry* usage_entry,
uint32_t* usage_entry_number) {
if (!initialized_) {
LOGW("DeviceFiles::RetrieveLicense: not initialized");
return false;
@@ -288,6 +291,7 @@ bool DeviceFiles::RetrieveLicense(
license.app_parameters(i).value();
}
*usage_entry = license.usage_entry();
*usage_entry_number = license.usage_entry_number();
return true;
}
@@ -384,7 +388,8 @@ bool DeviceFiles::StoreUsageInfo(const std::string& provider_session_token,
const CdmKeyResponse& key_response,
const std::string& app_id,
const std::string& key_set_id,
const CdmUsageEntry& usage_entry) {
const std::string& usage_entry,
uint32_t usage_entry_number) {
if (!initialized_) {
LOGW("DeviceFiles::StoreUsageInfo: not initialized");
return false;
@@ -411,6 +416,7 @@ bool DeviceFiles::StoreUsageInfo(const std::string& provider_session_token,
provider_session->set_license(key_response.data(), key_response.size());
provider_session->set_key_set_id(key_set_id.data(), key_set_id.size());
provider_session->set_usage_entry(usage_entry);
provider_session->set_usage_entry_number(usage_entry_number);
std::string serialized_file;
file.SerializeToString(&serialized_file);
@@ -525,7 +531,8 @@ bool DeviceFiles::RetrieveUsageInfo(const std::string& app_id,
const std::string& provider_session_token,
CdmKeyMessage* license_request,
CdmKeyResponse* license_response,
CdmUsageEntry* usage_entry) {
std::string* usage_entry,
uint32_t* usage_entry_number) {
if (!initialized_) {
LOGW("DeviceFiles::RetrieveUsageInfo: not initialized");
return false;
@@ -543,6 +550,8 @@ bool DeviceFiles::RetrieveUsageInfo(const std::string& app_id,
*license_request = file.usage_info().sessions(index).license_request();
*license_response = file.usage_info().sessions(index).license();
*usage_entry = file.usage_info().sessions(index).usage_entry();
*usage_entry_number =
file.usage_info().sessions(index).usage_entry_number();
return true;
}
}
@@ -553,9 +562,11 @@ bool DeviceFiles::RetrieveUsageInfo(const std::string& app_id,
bool DeviceFiles::RetrieveUsageInfoByKeySetId(
const std::string& app_id,
const std::string& key_set_id,
std::string* provider_session_token,
CdmKeyMessage* license_request,
CdmKeyResponse* license_response,
CdmUsageEntry* usage_entry) {
std::string* usage_entry,
uint32_t* usage_entry_number) {
if (!initialized_) {
LOGW("DeviceFiles::RetrieveUsageInfoByKeySetId: not initialized");
return false;
@@ -570,9 +581,12 @@ bool DeviceFiles::RetrieveUsageInfoByKeySetId(
int index = 0;
for (; index < file.usage_info().sessions_size(); ++index) {
if (file.usage_info().sessions(index).key_set_id() == key_set_id) {
*provider_session_token = file.usage_info().sessions(index).token();
*license_request = file.usage_info().sessions(index).license_request();
*license_response = file.usage_info().sessions(index).license();
*usage_entry = file.usage_info().sessions(index).usage_entry();
*usage_entry_number =
file.usage_info().sessions(index).usage_entry_number();
return true;
}
}

View File

@@ -44,6 +44,7 @@ message License {
// ignored if there is no grace period.
optional int64 grace_period_end_time = 11 [default = 0];
optional bytes usage_entry = 12;
optional int64 usage_entry_number = 13;
}
message UsageInfo {
@@ -53,6 +54,7 @@ message UsageInfo {
optional bytes license = 3;
optional bytes key_set_id = 4;
optional bytes usage_entry = 5;
optional int64 usage_entry_number = 6;
}
repeated ProviderSession sessions = 1;