Policy Engine refactoring
[ Merge of http://go/wvgerrit/93743 ] Reworks policy engine in preparation for changes to support timer and clock value handling by OEMCrypto core messages in OEMCrypto v16. No major functional changes have yet been introduced. Time and duration evaluation has been devolved to a new policy timer class. Policy specific to licenses that do not support OEMCrypto core messages is handled by a Policy Timer V15 class. This ensures backward compatibility. Backward compatibility may be needed if * OEMCrypto has not been upgraded to v16 * Licenses were persisted before the device was upgraded to v16 * License service does not yet support core messages Some minor changes to when the current time was retrieved required minor modification to test expectations. Bug: 139372190 Test: Android unit/integration tests Change-Id: I420fb181f656ed9a6bfe54f09e8b398c130d23da
This commit is contained in:
97
libwvdrmengine/cdm/core/src/policy_timers.cpp
Normal file
97
libwvdrmengine/cdm/core/src/policy_timers.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
// Copyright 2020 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
|
||||
#include "policy_timers.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
using video_widevine::License;
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
void PolicyTimers::SetLicense(const video_widevine::License& license) {
|
||||
policy_.Clear();
|
||||
license_start_time_ = license.license_start_time();
|
||||
}
|
||||
|
||||
void PolicyTimers::DecryptionEvent(int64_t current_time) {
|
||||
last_playback_time_ = current_time;
|
||||
}
|
||||
|
||||
bool PolicyTimers::GetSecondsSinceStarted(int64_t current_time,
|
||||
int64_t* seconds_since_started) {
|
||||
if (seconds_since_started == nullptr) {
|
||||
LOGE("|seconds_since_started| not provided");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (playback_start_time_ == 0) return false;
|
||||
|
||||
*seconds_since_started = current_time - playback_start_time_;
|
||||
return (*seconds_since_started >= 0) ? true : false;
|
||||
}
|
||||
|
||||
bool PolicyTimers::GetSecondsSinceLastPlayed(
|
||||
int64_t current_time, int64_t* seconds_since_last_played) {
|
||||
if (seconds_since_last_played == nullptr) {
|
||||
LOGE("|seconds_since_last_played| not provided");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (last_playback_time_ == 0) return false;
|
||||
|
||||
*seconds_since_last_played = current_time - last_playback_time_;
|
||||
return (*seconds_since_last_played >= 0) ? true : false;
|
||||
}
|
||||
|
||||
bool PolicyTimers::IsLicenseForFuture(int64_t current_time) {
|
||||
return current_time < license_start_time_;
|
||||
}
|
||||
|
||||
bool PolicyTimers::UpdateExpirationTime(int64_t current_time,
|
||||
int64_t* expiry_time) {
|
||||
if (expiry_time == nullptr) {
|
||||
LOGE("|expiry_time| mot provided");
|
||||
return false;
|
||||
}
|
||||
|
||||
*expiry_time =
|
||||
GetExpiryTime(current_time,
|
||||
/* ignore_soft_enforce_playback_duration */ false);
|
||||
const bool has_expiry_time_been_updated =
|
||||
!last_expiry_time_set_ || *expiry_time != last_expiry_time_;
|
||||
|
||||
if (has_expiry_time_been_updated) last_expiry_time_ = *expiry_time;
|
||||
|
||||
last_expiry_time_set_ = true;
|
||||
return has_expiry_time_been_updated;
|
||||
}
|
||||
|
||||
bool PolicyTimers::HasRenewalDelayExpired(int64_t current_time) {
|
||||
return policy_.can_renew() && (policy_.renewal_delay_seconds() > 0) &&
|
||||
(license_start_time_ + policy_.renewal_delay_seconds() <=
|
||||
current_time);
|
||||
}
|
||||
|
||||
bool PolicyTimers::HasRenewalRetryIntervalExpired(int64_t current_time) {
|
||||
return policy_.can_renew() &&
|
||||
(policy_.renewal_retry_interval_seconds() > 0) &&
|
||||
(next_renewal_time_ <= current_time);
|
||||
}
|
||||
|
||||
void PolicyTimers::UpdateRenewalRequest(int64_t current_time) {
|
||||
next_renewal_time_ = current_time + policy_.renewal_retry_interval_seconds();
|
||||
}
|
||||
|
||||
bool PolicyTimers::HasRenewalRecoveryDurationExpired(int64_t current_time) {
|
||||
return (policy_.renewal_recovery_duration_seconds() > 0) &&
|
||||
(license_start_time_ + policy_.renewal_recovery_duration_seconds() <=
|
||||
current_time);
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
Reference in New Issue
Block a user