[ Merge of http://go/wvgerrit/93838 ] Some more rework of policy engine/policy timers code to support timer and clock value handling introduced by OEMCrypto v16. Changes are * renamed methods to include rental duration since policies for v16 use rental and playback duration for all licenses. Previously rental and playback durations enforced timing for persistent licenses and license duration was used for streaming licenses. * Moved some common code to the base PolicyTimer class from PolicyTimerV15. * Corrected data member naming (policy_timers -> policy_timers_) * Updated comments Bug: 139372190 Test: Android WV unit/integration tests Change-Id: Id925ddcc14608a8500f30c2c68486d91608a9abe
111 lines
3.5 KiB
C++
111 lines
3.5 KiB
C++
// 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();
|
|
if (license.has_license_start_time())
|
|
license_start_time_ = license.license_start_time();
|
|
}
|
|
|
|
void PolicyTimers::DecryptionEvent(int64_t current_time) {
|
|
last_playback_time_ = current_time;
|
|
}
|
|
|
|
int64_t PolicyTimers::GetPlaybackDurationRemaining(int64_t current_time) {
|
|
const int64_t playback_duration = policy_.playback_duration_seconds();
|
|
if (playback_duration == 0) return LLONG_MAX;
|
|
if (playback_start_time_ == 0) return playback_duration;
|
|
|
|
const int64_t playback_expiry_time = playback_duration + playback_start_time_;
|
|
if (playback_expiry_time < current_time) return 0;
|
|
const int64_t policy_playback_duration = policy_.playback_duration_seconds();
|
|
return std::min(playback_expiry_time - current_time,
|
|
policy_playback_duration);
|
|
}
|
|
|
|
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
|