Merge changes I5271f961,I8a75d2e1 into sc-widevine-release

* changes:
  Added debugOtaKeyboxFallbackDuration property.
  Update fallback policy for fast fallback.
This commit is contained in:
TreeHugger Robot
2021-10-22 04:00:00 +00:00
committed by Android (Google) Code Review
10 changed files with 230 additions and 11 deletions

View File

@@ -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<std::mutex> 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<std::mutex> 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

View File

@@ -16,11 +16,6 @@ namespace okp {
using UniqueLock = std::unique_lock<std::mutex>;
namespace {
constexpr int64_t kErrorTime = -1;
int64_t GenerateInitialBackoffDuration() {
return static_cast<int64_t>(CdmRandom::RandomInRange(
kMinInitialBackoffDuration, kMaxInitialBackoffDuration));
}
} // namespace
// static
@@ -131,11 +126,11 @@ void SystemFallbackPolicy::TriggerFallback() {
info_.SetFirstCheckedTime(current_time);
}
info_.SetBackoffStartTime(GetCurrentTime());
if (info_.HasBackoffDuration()) {
// Doubling backoff duration for exponential backoff.
if (!fast_fallback_ && info_.HasBackoffDuration()) {
// Doubling backoff duration for exponential backoff. Except when
// performing fast fallback off.
info_.DoubleBackoffDuration();
} else {
// Use a random backoff period to avoid server spam across all devices.
info_.SetBackoffDuration(GenerateInitialBackoffDuration());
}
StoreInfo();
@@ -185,6 +180,37 @@ bool SystemFallbackPolicy::IsInFallbackMode() {
return false; // Only stored if previously in fallback and has ended.
}
void SystemFallbackPolicy::SetDefaultBackoffDurationRules() {
UniqueLock lock(mutex_);
fast_fallback_ = false;
if (state() == SystemState::kFallbackMode) {
LOGI("Ending fallback");
EndBackoffPeriod();
}
info_.ClearBackoffDuration();
StoreInfo();
}
void SystemFallbackPolicy::SetFastBackoffDurationRules() {
UniqueLock lock(mutex_);
fast_fallback_ = true;
if (state() == SystemState::kFallbackMode) {
LOGI("Ending fallback");
EndBackoffPeriod();
}
info_.ClearBackoffDuration();
StoreInfo();
}
int64_t SystemFallbackPolicy::GenerateInitialBackoffDuration() {
if (fast_fallback_) {
return kFastBackoffDuration;
}
// Use a random backoff period to avoid server spam across all devices.
return static_cast<int64_t>(CdmRandom::RandomInRange(
kMinInitialBackoffDuration, kMaxInitialBackoffDuration));
}
int64_t SystemFallbackPolicy::GetSecondsSinceBackoffStart() const {
if (!info_.HasBackoffStartTime()) return 0;
const int64_t backoff_start_time = info_.backoff_start_time();