From e34f83cdcee6906c1a16c6b22673828bd9f5defe Mon Sep 17 00:00:00 2001 From: Rahul Frias Date: Thu, 4 Jan 2018 10:59:05 -0800 Subject: [PATCH] Consolidate update usage table calls [ Merge of http://go/wvgerrit/24147 ] In OEMCrypto version 13, usage information is updated by calls to OEMCrypto_UpdateUsageEntry. In previous versions calls were made to OEMCrypto_UpdateUsageTable instead. Both need to be supported as the OEMCrypto version may vary by device. This consolidates calls to OEMCrypto_UpdateUsageTable so that they can be disabled if OEMCrypto version >= 13. No functional changes other than disabling by OEMCrypto version were introduced in this section. Helper routines have been added to device files as well. Bug: 34327459 Test: WV unit/integration tests Change-Id: I223b0a947c21b8b7ba3c8f345b0206747eb50984 --- .../cdm/core/include/crypto_session.h | 2 +- .../cdm/core/src/crypto_session.cpp | 23 ++++++++++++------- libwvdrmengine/cdm/core/src/device_files.cpp | 10 ++++++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/libwvdrmengine/cdm/core/include/crypto_session.h b/libwvdrmengine/cdm/core/include/crypto_session.h index f0ae42e8..eed80a62 100644 --- a/libwvdrmengine/cdm/core/include/crypto_session.h +++ b/libwvdrmengine/cdm/core/include/crypto_session.h @@ -96,7 +96,7 @@ class CryptoSession { // Usage related methods virtual bool UsageInformationSupport(bool* has_support); - virtual CdmResponseType UpdateUsageInformation(); + virtual CdmResponseType UpdateUsageInformation(); // only for OEMCrypto v9-12 virtual CdmResponseType DeactivateUsageInformation( const std::string& provider_session_token); virtual CdmResponseType GenerateUsageReport( diff --git a/libwvdrmengine/cdm/core/src/crypto_session.cpp b/libwvdrmengine/cdm/core/src/crypto_session.cpp index 4ceaf957..c442d38d 100644 --- a/libwvdrmengine/cdm/core/src/crypto_session.cpp +++ b/libwvdrmengine/cdm/core/src/crypto_session.cpp @@ -633,7 +633,8 @@ void CryptoSession::Close() { open_ = false; update_usage_table = update_usage_table_after_close_session_; } - if (close_sts == OEMCrypto_SUCCESS && update_usage_table) { + if (close_sts == OEMCrypto_SUCCESS && update_usage_table && + usage_support_type_ == kUsageTableSupport) { UpdateUsageInformation(); } } @@ -826,8 +827,10 @@ CdmResponseType CryptoSession::LoadKeys( // Leaving critical section crypto_lock_.Release(); - if (!provider_session_token.empty()) + if (!provider_session_token.empty() && + usage_support_type_ == kUsageTableSupport) { UpdateUsageInformation(); + } return result; } @@ -1240,7 +1243,7 @@ bool CryptoSession::UsageInformationSupport(bool* has_support) { } CdmResponseType CryptoSession::UpdateUsageInformation() { - LOGV("UpdateUsageInformation: id=%ld", (uint32_t)oec_session_id_); + LOGV("CryptoSession::UpdateUsageInformation: id=%ld", (uint32_t)oec_session_id_); AutoLock auto_lock(crypto_lock_); if (!initialized_) return UNKNOWN_ERROR; @@ -1252,7 +1255,7 @@ CdmResponseType CryptoSession::UpdateUsageInformation() { OEMCryptoResult status = OEMCrypto_UpdateUsageTable(); metrics_->oemcrypto_update_usage_table_.Increment(status); if (status != OEMCrypto_SUCCESS) { - LOGE("CryptoSession::UsageUsageInformation: error=%ld", status); + LOGE("CryptoSession::UpdateUsageInformation: error=%ld", status); return UNKNOWN_ERROR; } return NO_ERROR; @@ -1406,7 +1409,8 @@ CdmResponseType CryptoSession::ReleaseUsageInformation( } } - UpdateUsageInformation(); + if (usage_support_type_ == kUsageTableSupport) + UpdateUsageInformation(); return NO_ERROR; } @@ -1427,7 +1431,8 @@ CdmResponseType CryptoSession::DeleteUsageInformation( response = UNKNOWN_ERROR; } } - UpdateUsageInformation(); + if (usage_support_type_ == kUsageTableSupport) + UpdateUsageInformation(); return response; } @@ -1449,7 +1454,8 @@ CdmResponseType CryptoSession::DeleteMultipleUsageInformation( } } } - UpdateUsageInformation(); + if (usage_support_type_ == kUsageTableSupport) + UpdateUsageInformation(); return response; } @@ -1466,7 +1472,8 @@ CdmResponseType CryptoSession::DeleteAllUsageReports() { } } - UpdateUsageInformation(); + if (usage_support_type_ == kUsageTableSupport) + UpdateUsageInformation(); return NO_ERROR; } diff --git a/libwvdrmengine/cdm/core/src/device_files.cpp b/libwvdrmengine/cdm/core/src/device_files.cpp index 860a5c9d..589f8db3 100644 --- a/libwvdrmengine/cdm/core/src/device_files.cpp +++ b/libwvdrmengine/cdm/core/src/device_files.cpp @@ -671,6 +671,11 @@ bool DeviceFiles::RetrieveUsageInfo(const std::string& usage_info_file_name, return false; } + if (usage_data == NULL) { + LOGW("DeviceFiles::RetrieveUsageInfo: usage_data not provided"); + return false; + } + if (!FileExists(usage_info_file_name) || GetFileSize(usage_info_file_name) == 0) { usage_data->resize(0); @@ -706,6 +711,11 @@ bool DeviceFiles::RetrieveUsageInfo(const std::string& usage_info_file_name, return false; } + if (usage_data == NULL) { + LOGW("DeviceFiles::RetrieveUsageInfo: usage_data not provided"); + return false; + } + video_widevine_client::sdk::File file; if (!RetrieveHashedFile(usage_info_file_name, &file)) { return false;