Update fallback policy for fast fallback. am: 28b45c4f1b am: 596363ef9e

Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/16096533

Change-Id: Ifd8e70f097345d9d17f2c96e7bdd0415fea62ca5
This commit is contained in:
Alex Dale
2021-10-28 17:18:20 +00:00
committed by Automerger Merge Worker
4 changed files with 153 additions and 11 deletions

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();