From 8b12e5acc964154cdf15b97ee25bf58bbd78e7ae Mon Sep 17 00:00:00 2001 From: Alex Dale Date: Fri, 15 Oct 2021 19:54:02 -0700 Subject: [PATCH] Added debugOtaKeyboxFallbackDuration property. [ Cherry-pick of http://ag/16064434 ] [ Merge of http://go/wvgerrit/136330 ] This changes adds a custom debug property for changing the fallback policy used for the system. Depending on the value set, the device will either use a "fast" fallback (30 seconds) or "default" fallback (~1 day with exponential backoff). Setting this property to either "fast" or "default" will end the current fallback if it has been triggered. Bug: 187646550 Test: Android unit tests Change-Id: I5271f96139c1e468242f7fa742668cc791ffcf91 --- libwvdrmengine/cdm/core/include/cdm_engine.h | 10 ++++++++ libwvdrmengine/cdm/core/src/cdm_engine.cpp | 23 +++++++++++++++++++ .../include/wv_content_decryption_module.h | 3 +++ .../cdm/src/wv_content_decryption_module.cpp | 15 ++++++++++++ libwvdrmengine/mediadrm/src/WVDrmPlugin.cpp | 13 +++++++++++ .../mediadrm/src_hidl/WVDrmPlugin.cpp | 13 +++++++++++ 6 files changed, 77 insertions(+) diff --git a/libwvdrmengine/cdm/core/include/cdm_engine.h b/libwvdrmengine/cdm/core/include/cdm_engine.h index afa73db2..883370a6 100644 --- a/libwvdrmengine/cdm/core/include/cdm_engine.h +++ b/libwvdrmengine/cdm/core/include/cdm_engine.h @@ -360,6 +360,16 @@ class CdmEngine { virtual void SetUserId(uint32_t user_id) { user_id_ = user_id; } virtual uint32_t GetUserId() const { return user_id_; } + // Changes the rules used for calculating the fallback duration + // when OTA keybox provisioning fails. + // Default rules use fallback duration measured in days, with exponential + // backoff. + // Fast rules use fallback durations of a few seconds, without exponential + // backoff. + // This method has no effect if OTA keybox is not required. + virtual void SetDefaultOtaKeyboxFallbackDurationRules(); + virtual void SetFastOtaKeyboxFallbackDurationRules(); + protected: friend class CdmEngineFactory; diff --git a/libwvdrmengine/cdm/core/src/cdm_engine.cpp b/libwvdrmengine/cdm/core/src/cdm_engine.cpp index dee205f4..fd5234f3 100644 --- a/libwvdrmengine/cdm/core/src/cdm_engine.cpp +++ b/libwvdrmengine/cdm/core/src/cdm_engine.cpp @@ -21,6 +21,7 @@ #include "device_files.h" #include "file_store.h" #include "log.h" +#include "okp_fallback_policy.h" #include "ota_keybox_provisioner.h" #include "properties.h" #include "string_conversions.h" @@ -2154,4 +2155,26 @@ void CdmEngine::OkpCleanUp() { } okp_provisioner_.reset(); } + +void CdmEngine::SetDefaultOtaKeyboxFallbackDurationRules() { + OkpCheck(); + std::unique_lock lock(okp_mutex_); + auto* system_fallback_policy = CryptoSession::GetOkpFallbackPolicy(); + if (!system_fallback_policy) { + LOGW("No system fallback policy available"); + return; + } + system_fallback_policy->SetDefaultBackoffDurationRules(); +} + +void CdmEngine::SetFastOtaKeyboxFallbackDurationRules() { + OkpCheck(); + std::unique_lock lock(okp_mutex_); + auto* system_fallback_policy = CryptoSession::GetOkpFallbackPolicy(); + if (!system_fallback_policy) { + LOGW("No system fallback policy available"); + return; + } + system_fallback_policy->SetFastBackoffDurationRules(); +} } // namespace wvcdm diff --git a/libwvdrmengine/cdm/include/wv_content_decryption_module.h b/libwvdrmengine/cdm/include/wv_content_decryption_module.h index 06a75613..1630ae93 100644 --- a/libwvdrmengine/cdm/include/wv_content_decryption_module.h +++ b/libwvdrmengine/cdm/include/wv_content_decryption_module.h @@ -188,6 +188,9 @@ class WvContentDecryptionModule : public android::RefBase, public TimerHandler { virtual CdmResponseType GetSessionUserId(const CdmSessionId& session_id, uint32_t* user_id); + virtual bool SetDefaultOtaKeyboxFallbackDurationRules(); + virtual bool SetFastOtaKeyboxFallbackDurationRules(); + private: struct CdmInfo { CdmInfo(); diff --git a/libwvdrmengine/cdm/src/wv_content_decryption_module.cpp b/libwvdrmengine/cdm/src/wv_content_decryption_module.cpp index ded47c25..3256d102 100644 --- a/libwvdrmengine/cdm/src/wv_content_decryption_module.cpp +++ b/libwvdrmengine/cdm/src/wv_content_decryption_module.cpp @@ -645,4 +645,19 @@ CdmResponseType WvContentDecryptionModule::GetSessionUserId( *user_id = cdm_engine->GetUserId(); return NO_ERROR; } + +bool WvContentDecryptionModule::SetDefaultOtaKeyboxFallbackDurationRules() { + CdmEngine* cdm_engine = EnsureCdmForIdentifier(kDefaultCdmIdentifier); + if (!cdm_engine) return false; + cdm_engine->SetDefaultOtaKeyboxFallbackDurationRules(); + return true; +} + +bool WvContentDecryptionModule::SetFastOtaKeyboxFallbackDurationRules() { + CdmEngine* cdm_engine = EnsureCdmForIdentifier(kDefaultCdmIdentifier); + if (!cdm_engine) return false; + cdm_engine->SetFastOtaKeyboxFallbackDurationRules(); + return true; +} + } // namespace wvcdm diff --git a/libwvdrmengine/mediadrm/src/WVDrmPlugin.cpp b/libwvdrmengine/mediadrm/src/WVDrmPlugin.cpp index b7e67d53..76f09a49 100644 --- a/libwvdrmengine/mediadrm/src/WVDrmPlugin.cpp +++ b/libwvdrmengine/mediadrm/src/WVDrmPlugin.cpp @@ -689,6 +689,19 @@ status_t WVDrmPlugin::setPropertyString(const String8& name, return mapCdmResponseType(res); } else if (name == "decryptHashSessionId") { mDecryptHashSessionId = value.string(); + } else if (name == "debugOtaKeyboxFallbackDuration") { + bool success = false; + if (value == "default") { + success = mCDM->SetDefaultOtaKeyboxFallbackDurationRules(); + } else if (value == "fast") { + success = mCDM->SetFastOtaKeyboxFallbackDurationRules(); + } else { + ALOGE("Unknown OTA fallback duration value %s", value.string()); + return android::BAD_VALUE; + } + if (!success) { + return android::UNKNOWN_ERROR; + } } else if (name == "atscMode") { if (value == kEnable) { mPropertySet.set_use_atsc_mode(true); diff --git a/libwvdrmengine/mediadrm/src_hidl/WVDrmPlugin.cpp b/libwvdrmengine/mediadrm/src_hidl/WVDrmPlugin.cpp index cb3709f9..aa1efe37 100644 --- a/libwvdrmengine/mediadrm/src_hidl/WVDrmPlugin.cpp +++ b/libwvdrmengine/mediadrm/src_hidl/WVDrmPlugin.cpp @@ -1470,6 +1470,19 @@ Return WVDrmPlugin::setPropertyString(const hidl_string& propertyName, ALOGE("App requested unknown ATSC mode %s", _value.c_str()); return Status::BAD_VALUE; } + } else if (name == "debugOtaKeyboxFallbackDuration") { + bool success = false; + if (value == "default") { + success = mCDM->SetDefaultOtaKeyboxFallbackDurationRules(); + } else if (value == "fast") { + success = mCDM->SetFastOtaKeyboxFallbackDurationRules(); + } else { + ALOGE("Unknown OTA fallback duration value %s", _value.c_str()); + return Status::BAD_VALUE; + } + if (!success) { + return Status::ERROR_DRM_UNKNOWN; + } } else { ALOGE("App set unknown string property %s", name.c_str()); return Status::ERROR_DRM_CANNOT_HANDLE;