|
|
|
|
@@ -40,6 +40,8 @@ using video_widevine_client::sdk::
|
|
|
|
|
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_LICENSE;
|
|
|
|
|
using video_widevine_client::sdk::
|
|
|
|
|
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_USAGE_INFO;
|
|
|
|
|
using video_widevine_client::sdk::
|
|
|
|
|
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_UNKNOWN;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
@@ -386,7 +388,7 @@ bool DeviceFiles::UnreserveLicenseId(const std::string& key_set_id) {
|
|
|
|
|
bool DeviceFiles::StoreUsageInfo(const std::string& provider_session_token,
|
|
|
|
|
const CdmKeyMessage& key_request,
|
|
|
|
|
const CdmKeyResponse& key_response,
|
|
|
|
|
const std::string& app_id,
|
|
|
|
|
const std::string& usage_info_file_name,
|
|
|
|
|
const std::string& key_set_id,
|
|
|
|
|
const std::string& usage_entry,
|
|
|
|
|
uint32_t usage_entry_number) {
|
|
|
|
|
@@ -396,12 +398,11 @@ bool DeviceFiles::StoreUsageInfo(const std::string& provider_session_token,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
video_widevine_client::sdk::File file;
|
|
|
|
|
std::string file_name = GetUsageInfoFileName(app_id);
|
|
|
|
|
if (!FileExists(file_name)) {
|
|
|
|
|
if (!FileExists(usage_info_file_name)) {
|
|
|
|
|
file.set_type(video_widevine_client::sdk::File::USAGE_INFO);
|
|
|
|
|
file.set_version(video_widevine_client::sdk::File::VERSION_1);
|
|
|
|
|
} else {
|
|
|
|
|
if (!RetrieveHashedFile(file_name, &file)) {
|
|
|
|
|
if (!RetrieveHashedFile(usage_info_file_name, &file)) {
|
|
|
|
|
LOGW("DeviceFiles::StoreUsageInfo: Unable to parse file");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@@ -420,18 +421,17 @@ bool DeviceFiles::StoreUsageInfo(const std::string& provider_session_token,
|
|
|
|
|
|
|
|
|
|
std::string serialized_file;
|
|
|
|
|
file.SerializeToString(&serialized_file);
|
|
|
|
|
return StoreFileWithHash(file_name, serialized_file);
|
|
|
|
|
return StoreFileWithHash(usage_info_file_name, serialized_file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DeviceFiles::DeleteUsageInfo(const std::string& app_id,
|
|
|
|
|
bool DeviceFiles::DeleteUsageInfo(const std::string& usage_info_file_name,
|
|
|
|
|
const std::string& provider_session_token) {
|
|
|
|
|
if (!initialized_) {
|
|
|
|
|
LOGW("DeviceFiles::DeleteUsageInfo: not initialized");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
video_widevine_client::sdk::File file;
|
|
|
|
|
std::string file_name = GetUsageInfoFileName(app_id);
|
|
|
|
|
if (!RetrieveHashedFile(file_name, &file)) return false;
|
|
|
|
|
if (!RetrieveHashedFile(usage_info_file_name, &file)) return false;
|
|
|
|
|
|
|
|
|
|
UsageInfo* usage_info = file.mutable_usage_info();
|
|
|
|
|
int index = 0;
|
|
|
|
|
@@ -460,11 +460,11 @@ bool DeviceFiles::DeleteUsageInfo(const std::string& app_id,
|
|
|
|
|
|
|
|
|
|
std::string serialized_file;
|
|
|
|
|
file.SerializeToString(&serialized_file);
|
|
|
|
|
return StoreFileWithHash(file_name, serialized_file);
|
|
|
|
|
return StoreFileWithHash(usage_info_file_name, serialized_file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DeviceFiles::DeleteAllUsageInfoForApp(
|
|
|
|
|
const std::string& app_id,
|
|
|
|
|
const std::string& usage_info_file_name,
|
|
|
|
|
std::vector<std::string>* provider_session_tokens) {
|
|
|
|
|
if (!initialized_) {
|
|
|
|
|
LOGW("DeviceFiles::DeleteAllUsageInfoForApp: not initialized");
|
|
|
|
|
@@ -476,22 +476,21 @@ bool DeviceFiles::DeleteAllUsageInfoForApp(
|
|
|
|
|
}
|
|
|
|
|
provider_session_tokens->clear();
|
|
|
|
|
|
|
|
|
|
std::string file_name = GetUsageInfoFileName(app_id);
|
|
|
|
|
if (!FileExists(file_name)) return true;
|
|
|
|
|
if (!FileExists(usage_info_file_name)) return true;
|
|
|
|
|
|
|
|
|
|
video_widevine_client::sdk::File file;
|
|
|
|
|
if (RetrieveHashedFile(file_name, &file)) {
|
|
|
|
|
if (RetrieveHashedFile(usage_info_file_name, &file)) {
|
|
|
|
|
for (int i = 0; i < file.usage_info().sessions_size(); ++i) {
|
|
|
|
|
provider_session_tokens->push_back(file.usage_info().sessions(i).token());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
LOGW("DeviceFiles::DeleteAllUsageInfoForApp: Unable to retrieve file");
|
|
|
|
|
}
|
|
|
|
|
return RemoveFile(file_name);
|
|
|
|
|
return RemoveFile(usage_info_file_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DeviceFiles::RetrieveUsageInfo(
|
|
|
|
|
const std::string& app_id,
|
|
|
|
|
const std::string& usage_info_file_name,
|
|
|
|
|
std::vector<std::pair<CdmKeyMessage, CdmKeyResponse> >* usage_info) {
|
|
|
|
|
if (!initialized_) {
|
|
|
|
|
LOGW("DeviceFiles::RetrieveUsageInfo: not initialized");
|
|
|
|
|
@@ -505,14 +504,14 @@ bool DeviceFiles::RetrieveUsageInfo(
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string file_name = GetUsageInfoFileName(app_id);
|
|
|
|
|
if (!FileExists(file_name) || GetFileSize(file_name) == 0) {
|
|
|
|
|
if (!FileExists(usage_info_file_name) ||
|
|
|
|
|
GetFileSize(usage_info_file_name) == 0) {
|
|
|
|
|
usage_info->resize(0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
video_widevine_client::sdk::File file;
|
|
|
|
|
if (!RetrieveHashedFile(file_name, &file)) {
|
|
|
|
|
if (!RetrieveHashedFile(usage_info_file_name, &file)) {
|
|
|
|
|
LOGW("DeviceFiles::RetrieveUsageInfo: Unable to parse file");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@@ -527,7 +526,7 @@ bool DeviceFiles::RetrieveUsageInfo(
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DeviceFiles::RetrieveUsageInfo(const std::string& app_id,
|
|
|
|
|
bool DeviceFiles::RetrieveUsageInfo(const std::string& usage_info_file_name,
|
|
|
|
|
const std::string& provider_session_token,
|
|
|
|
|
CdmKeyMessage* license_request,
|
|
|
|
|
CdmKeyResponse* license_response,
|
|
|
|
|
@@ -538,9 +537,8 @@ bool DeviceFiles::RetrieveUsageInfo(const std::string& app_id,
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string file_name = GetUsageInfoFileName(app_id);
|
|
|
|
|
video_widevine_client::sdk::File file;
|
|
|
|
|
if (!RetrieveHashedFile(file_name, &file)) {
|
|
|
|
|
if (!RetrieveHashedFile(usage_info_file_name, &file)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -560,7 +558,7 @@ bool DeviceFiles::RetrieveUsageInfo(const std::string& app_id,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DeviceFiles::RetrieveUsageInfoByKeySetId(
|
|
|
|
|
const std::string& app_id,
|
|
|
|
|
const std::string& usage_info_file_name,
|
|
|
|
|
const std::string& key_set_id,
|
|
|
|
|
std::string* provider_session_token,
|
|
|
|
|
CdmKeyMessage* license_request,
|
|
|
|
|
@@ -572,9 +570,8 @@ bool DeviceFiles::RetrieveUsageInfoByKeySetId(
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string file_name = GetUsageInfoFileName(app_id);
|
|
|
|
|
video_widevine_client::sdk::File file;
|
|
|
|
|
if (!RetrieveHashedFile(file_name, &file)) {
|
|
|
|
|
if (!RetrieveHashedFile(usage_info_file_name, &file)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -594,6 +591,97 @@ bool DeviceFiles::RetrieveUsageInfoByKeySetId(
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DeviceFiles::StoreUsageInfo(const std::string& usage_info_file_name,
|
|
|
|
|
const std::vector<CdmUsageData>& usage_data) {
|
|
|
|
|
if (!initialized_) {
|
|
|
|
|
LOGW("DeviceFiles::StoreUsageInfo: not initialized");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
video_widevine_client::sdk::File file;
|
|
|
|
|
file.set_type(video_widevine_client::sdk::File::USAGE_INFO);
|
|
|
|
|
file.set_version(video_widevine_client::sdk::File::VERSION_1);
|
|
|
|
|
|
|
|
|
|
UsageInfo* usage_info = file.mutable_usage_info();
|
|
|
|
|
for (size_t i = 0; i < usage_data.size(); ++i) {
|
|
|
|
|
UsageInfo_ProviderSession* provider_session = usage_info->add_sessions();
|
|
|
|
|
|
|
|
|
|
provider_session->set_token(usage_data[i].provider_session_token.data(),
|
|
|
|
|
usage_data[i].provider_session_token.size());
|
|
|
|
|
provider_session->set_license_request(usage_data[i].license_request.data(),
|
|
|
|
|
usage_data[i].license_request.size());
|
|
|
|
|
provider_session->set_license(usage_data[i].license.data(),
|
|
|
|
|
usage_data[i].license.size());
|
|
|
|
|
provider_session->set_key_set_id(usage_data[i].key_set_id.data(),
|
|
|
|
|
usage_data[i].key_set_id.size());
|
|
|
|
|
provider_session->set_usage_entry(usage_data[i].usage_entry);
|
|
|
|
|
provider_session->set_usage_entry_number(usage_data[i].usage_entry_number);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string serialized_file;
|
|
|
|
|
file.SerializeToString(&serialized_file);
|
|
|
|
|
return StoreFileWithHash(usage_info_file_name, serialized_file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DeviceFiles::RetrieveUsageInfo(const std::string& usage_info_file_name,
|
|
|
|
|
std::vector<CdmUsageData>* usage_data) {
|
|
|
|
|
|
|
|
|
|
if (!initialized_) {
|
|
|
|
|
LOGW("DeviceFiles::RetrieveUsageInfo: not initialized");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
video_widevine_client::sdk::File file;
|
|
|
|
|
if (!RetrieveHashedFile(usage_info_file_name, &file)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usage_data->resize(file.usage_info().sessions_size());
|
|
|
|
|
for (int i = 0; i < file.usage_info().sessions_size(); ++i) {
|
|
|
|
|
(*usage_data)[i].provider_session_token =
|
|
|
|
|
file.usage_info().sessions(i).token();
|
|
|
|
|
(*usage_data)[i].license_request =
|
|
|
|
|
file.usage_info().sessions(i).license_request();
|
|
|
|
|
(*usage_data)[i].license = file.usage_info().sessions(i).license();
|
|
|
|
|
(*usage_data)[i].key_set_id = file.usage_info().sessions(i).key_set_id();
|
|
|
|
|
(*usage_data)[i].usage_entry = file.usage_info().sessions(i).usage_entry();
|
|
|
|
|
(*usage_data)[i].usage_entry_number =
|
|
|
|
|
file.usage_info().sessions(i).usage_entry_number();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DeviceFiles::ListUsageInfoFiles(
|
|
|
|
|
std::vector<std::string>* usage_info_file_names) {
|
|
|
|
|
if (!initialized_) {
|
|
|
|
|
LOGW("DeviceFiles::ListUsageInfoFiles: not initialized");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get list of filenames
|
|
|
|
|
std::vector<std::string> filenames;
|
|
|
|
|
if (!ListFiles(&filenames)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Scan list of all filenames and return only usage info filenames
|
|
|
|
|
usage_info_file_names->clear();
|
|
|
|
|
for (size_t i = 0; i < filenames.size(); i++) {
|
|
|
|
|
std::string* name = &filenames[i];
|
|
|
|
|
std::size_t pos_prefix = name->find(kUsageInfoFileNamePrefix);
|
|
|
|
|
std::size_t pos_suffix = name->find(kUsageInfoFileNameExt);
|
|
|
|
|
if (pos_prefix == std::string::npos ||
|
|
|
|
|
pos_suffix == std::string::npos) {
|
|
|
|
|
// Skip this file - extension does not match
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usage_info_file_names->push_back(*name);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DeviceFiles::StoreHlsAttributes(
|
|
|
|
|
const std::string& key_set_id, const CdmHlsMethod method,
|
|
|
|
|
const std::vector<uint8_t>& media_segment_iv) {
|
|
|
|
|
@@ -693,7 +781,7 @@ bool DeviceFiles::DeleteHlsAttributes(const std::string& key_set_id) {
|
|
|
|
|
|
|
|
|
|
bool DeviceFiles::StoreUsageTableInfo(
|
|
|
|
|
const CdmUsageTableHeader& usage_table_header,
|
|
|
|
|
const std::vector<DeviceFiles::UsageEntryInfo>& usage_entry_info) {
|
|
|
|
|
const std::vector<CdmUsageEntryInfo>& usage_entry_info) {
|
|
|
|
|
if (!initialized_) {
|
|
|
|
|
LOGW("DeviceFiles::StoreUsageTableHeader: not initialized");
|
|
|
|
|
return false;
|
|
|
|
|
@@ -710,23 +798,23 @@ bool DeviceFiles::StoreUsageTableInfo(
|
|
|
|
|
for (size_t i = 0; i < usage_entry_info.size(); ++i) {
|
|
|
|
|
UsageTableInfo_UsageEntryInfo* info =
|
|
|
|
|
usage_table_info->add_usage_entry_info();
|
|
|
|
|
info->set_key_set_id(usage_entry_info[i].key_set_id);
|
|
|
|
|
switch (usage_entry_info[i].storage_type) {
|
|
|
|
|
case kStorageLicense:
|
|
|
|
|
info->set_storage(
|
|
|
|
|
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_LICENSE);
|
|
|
|
|
info->set_key_set_id(usage_entry_info[i].key_set_id);
|
|
|
|
|
break;
|
|
|
|
|
case kStorageUsageInfo:
|
|
|
|
|
info->set_storage(
|
|
|
|
|
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_USAGE_INFO);
|
|
|
|
|
info->set_provider_session_token(
|
|
|
|
|
usage_entry_info[i].provider_session_token);
|
|
|
|
|
info->set_app_id(usage_entry_info[i].app_id);
|
|
|
|
|
info->set_usage_info_file_name(
|
|
|
|
|
usage_entry_info[i].usage_info_file_name);
|
|
|
|
|
break;
|
|
|
|
|
case kStorageUnknown:
|
|
|
|
|
default:
|
|
|
|
|
LOGW("DeviceFiles::StoreUsageTableHeader: unknown storage type: %d",
|
|
|
|
|
usage_entry_info[i].storage_type);
|
|
|
|
|
return false;
|
|
|
|
|
info->set_storage(
|
|
|
|
|
UsageTableInfo_UsageEntryInfo_UsageEntryStorage_UNKNOWN);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -738,7 +826,7 @@ bool DeviceFiles::StoreUsageTableInfo(
|
|
|
|
|
|
|
|
|
|
bool DeviceFiles::RetrieveUsageTableInfo(
|
|
|
|
|
CdmUsageTableHeader* usage_table_header,
|
|
|
|
|
std::vector<DeviceFiles::UsageEntryInfo>* usage_entry_info) {
|
|
|
|
|
std::vector<CdmUsageEntryInfo>* usage_entry_info) {
|
|
|
|
|
if (!initialized_) {
|
|
|
|
|
LOGW("DeviceFiles::RetrieveUsageTableInfo: not initialized");
|
|
|
|
|
return false;
|
|
|
|
|
@@ -782,21 +870,20 @@ bool DeviceFiles::RetrieveUsageTableInfo(
|
|
|
|
|
for (int i = 0; i < usage_table_info.usage_entry_info_size(); ++i) {
|
|
|
|
|
const UsageTableInfo_UsageEntryInfo& info =
|
|
|
|
|
usage_table_info.usage_entry_info(i);
|
|
|
|
|
(*usage_entry_info)[i].key_set_id = info.key_set_id();
|
|
|
|
|
switch (info.storage()) {
|
|
|
|
|
case UsageTableInfo_UsageEntryInfo_UsageEntryStorage_LICENSE:
|
|
|
|
|
(*usage_entry_info)[i].storage_type = kStorageLicense;
|
|
|
|
|
(*usage_entry_info)[i].key_set_id = info.key_set_id();
|
|
|
|
|
break;
|
|
|
|
|
case UsageTableInfo_UsageEntryInfo_UsageEntryStorage_USAGE_INFO:
|
|
|
|
|
(*usage_entry_info)[i].storage_type = kStorageUsageInfo;
|
|
|
|
|
(*usage_entry_info)[i].provider_session_token =
|
|
|
|
|
info.provider_session_token();
|
|
|
|
|
(*usage_entry_info)[i].app_id = info.app_id();
|
|
|
|
|
(*usage_entry_info)[i].usage_info_file_name =
|
|
|
|
|
info.usage_info_file_name();
|
|
|
|
|
break;
|
|
|
|
|
case UsageTableInfo_UsageEntryInfo_UsageEntryStorage_UNKNOWN:
|
|
|
|
|
default:
|
|
|
|
|
LOGW("DeviceFiles::RetrieveUsageTableInfo: Unknown storage type: %d",
|
|
|
|
|
info.storage());
|
|
|
|
|
return false;
|
|
|
|
|
(*usage_entry_info)[i].storage_type = kStorageUnknown;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|