Move functionality to policy_timer.
[ Merge of http://go/wvgerrit/164277 ] No functional changes are made in this CL. policy_timer_v16 and policy_timer_v15 derive from policy_timer. We have removed support for OEMCrypto v15. policy_timer_v15 has also been removed. This allows us to move functionality from policy_timer_v16 to policy_timer class. This will ease subsequent renew on license load functionality. Bug: 256038127 Test: Luci tests Change-Id: Iebd588237edd02b30a820c4d9d57ce041c26964e
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "disallow_copy_and_assign.h"
|
||||
#include "license_protocol.pb.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
#include "wv_cdm_types.h"
|
||||
|
||||
namespace wvcdm {
|
||||
@@ -43,20 +44,45 @@ class PolicyTimers {
|
||||
// For offline save and restore
|
||||
virtual int64_t GetPlaybackStartTime() { return playback_start_time_; }
|
||||
virtual int64_t GetLastPlaybackTime() { return last_playback_time_; }
|
||||
virtual int64_t GetGracePeriodEndTime() = 0;
|
||||
// This is a legacy field for offline licenses. Since no grace period is
|
||||
// supported return a default value.
|
||||
virtual int64_t GetGracePeriodEndTime() { return 0; }
|
||||
virtual void RestorePlaybackTimes(int64_t current_time,
|
||||
int64_t playback_start_time,
|
||||
int64_t last_playback_time,
|
||||
int64_t grace_period_end_time) = 0;
|
||||
int64_t grace_period_end_time);
|
||||
|
||||
virtual bool HasPlaybackStarted(int64_t current_time) = 0;
|
||||
virtual bool HasPlaybackStarted(int64_t /* current_time */) {
|
||||
return playback_start_time_ != 0;
|
||||
}
|
||||
|
||||
// For licenses that support core messages, evaluation of only rental and
|
||||
// playback durations are needed.
|
||||
virtual bool HasLicenseOrRentalOrPlaybackDurationExpired(
|
||||
int64_t current_time) = 0;
|
||||
virtual bool HasPassedGracePeriod(int64_t current_time) = 0;
|
||||
int64_t current_time) {
|
||||
return HasRentalOrPlaybackDurationExpired(current_time);
|
||||
}
|
||||
virtual bool HasPassedGracePeriod(int64_t /* current_time */) { return true; }
|
||||
|
||||
// This returns
|
||||
// * before playback begins: the time remaining on |rental_duration_seconds|
|
||||
// * after playback begins:
|
||||
// - |soft_enforce_playback_duration| is true: the time remaining on
|
||||
// |playback_duration_seconds|
|
||||
// - |soft_enforce_playback_duration| is false: the minimum
|
||||
// of the time remaining on |rental_duration_seconds| or
|
||||
// |playback_duration_seconds|
|
||||
//
|
||||
// |license_duration_seconds| is ignored with the introduction of core
|
||||
// messages
|
||||
virtual int64_t GetLicenseOrRentalOrPlaybackDurationRemaining(
|
||||
int64_t current_time) = 0;
|
||||
virtual int64_t GetLicenseOrRentalDurationRemaining(int64_t current_time) = 0;
|
||||
int64_t current_time);
|
||||
// This is only used in Query. This should return the time remaining on
|
||||
// |rental_duration_seconds|.
|
||||
virtual int64_t GetLicenseOrRentalDurationRemaining(int64_t current_time) {
|
||||
return GetRentalDurationRemaining(current_time);
|
||||
};
|
||||
|
||||
// This is only used in Query. This should return |playback_duration_seconds|
|
||||
// before playback begins or the time remaining on
|
||||
// |playback_duration_seconds| after playback begins.
|
||||
@@ -72,7 +98,7 @@ class PolicyTimers {
|
||||
virtual bool UpdateExpirationTime(int64_t current_time, int64_t* expiry_time);
|
||||
|
||||
// Renewal related methods
|
||||
virtual bool HasRenewalDelayExpired(int64_t current_time);
|
||||
virtual bool HasRenewalDelayExpired(int64_t current_time) = 0;
|
||||
virtual bool HasRenewalRetryIntervalExpired(int64_t current_time);
|
||||
virtual void UpdateRenewalRequest(int64_t current_time);
|
||||
virtual bool HasRenewalRecoveryDurationExpired(int64_t current_time);
|
||||
@@ -90,11 +116,11 @@ class PolicyTimers {
|
||||
was_expired_on_load_(false) {}
|
||||
|
||||
// Gets the clock time that the license expires based on whether we have
|
||||
// started playing.
|
||||
// started playing. This takes into account GetHardLicenseExpiryTime.
|
||||
virtual int64_t GetExpiryTime(int64_t current_time,
|
||||
bool ignore_soft_enforce_playback_duration) = 0;
|
||||
bool ignore_soft_enforce_playback_duration);
|
||||
|
||||
virtual int64_t GetRenewalStartTime() = 0;
|
||||
virtual int64_t GetRenewalStartTime() { return renewal_start_time_; }
|
||||
|
||||
// This is the current policy information for this license. This gets updated
|
||||
// as license renewals occur.
|
||||
@@ -105,12 +131,20 @@ class PolicyTimers {
|
||||
int64_t last_playback_time_;
|
||||
int64_t last_expiry_time_;
|
||||
int64_t last_expiry_time_set_;
|
||||
int64_t renewal_start_time_ = 0;
|
||||
int64_t next_renewal_time_;
|
||||
|
||||
// Indicates whether a persistent license was expired when loaded
|
||||
bool was_expired_on_load_;
|
||||
|
||||
private:
|
||||
// Gets the clock time that the rental duration or playback will expire.
|
||||
virtual int64_t GetRentalExpiryTime(int64_t current_time);
|
||||
virtual int64_t GetPlaybackExpiryTime(
|
||||
int64_t current_time, bool ignore_soft_enforce_playback_duration);
|
||||
bool HasRentalOrPlaybackDurationExpired(int64_t current_time);
|
||||
virtual int64_t GetRentalDurationRemaining(int64_t current_time);
|
||||
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(PolicyTimers);
|
||||
};
|
||||
|
||||
|
||||
@@ -43,68 +43,10 @@ class PolicyTimersV16 : public PolicyTimers {
|
||||
// Call this on first decrypt to set the start of playback.
|
||||
void BeginDecryption(int64_t current_time) override;
|
||||
|
||||
// This is a legacy field for offline licenses. Since no grace period is
|
||||
// supported return a default value.
|
||||
int64_t GetGracePeriodEndTime() override { return 0; }
|
||||
|
||||
// For offline save and restore.
|
||||
void RestorePlaybackTimes(int64_t current_time, int64_t playback_start_time,
|
||||
int64_t last_playback_time,
|
||||
int64_t grace_period_end_time) override;
|
||||
|
||||
bool HasPlaybackStarted(int64_t /* current_time */) override {
|
||||
return playback_start_time_ != 0;
|
||||
}
|
||||
// For licenses that support core messages, evaluation of only rental and
|
||||
// playback durations are needed.
|
||||
bool HasLicenseOrRentalOrPlaybackDurationExpired(
|
||||
int64_t current_time) override {
|
||||
return HasRentalOrPlaybackDurationExpired(current_time);
|
||||
}
|
||||
bool HasPassedGracePeriod(int64_t /* current_time */) override {
|
||||
return true;
|
||||
}
|
||||
|
||||
// This returns
|
||||
// * before playback begins: the time remaining on |rental_duration_seconds|
|
||||
// * after playback begins:
|
||||
// - |soft_enforce_playback_duration| is true: the time remaining on
|
||||
// |playback_duration_seconds|
|
||||
// - |soft_enforce_playback_duration| is false: the minimum
|
||||
// of the time remaining on |rental_duration_seconds| or
|
||||
// |playback_duration_seconds|
|
||||
//
|
||||
// |license_duration_seconds| is ignored with the introduction of core
|
||||
// messages
|
||||
int64_t GetLicenseOrRentalOrPlaybackDurationRemaining(
|
||||
int64_t current_time) override;
|
||||
// This is only used in Query. This should return the time remaining on
|
||||
// |rental_duration_seconds|.
|
||||
int64_t GetLicenseOrRentalDurationRemaining(int64_t current_time) override {
|
||||
return GetRentalDurationRemaining(current_time);
|
||||
};
|
||||
|
||||
// Renewal related methods
|
||||
bool HasRenewalDelayExpired(int64_t current_time) override;
|
||||
|
||||
protected:
|
||||
// Gets the clock time that the license expires based on whether we have
|
||||
// started playing. This takes into account GetHardLicenseExpiryTime.
|
||||
int64_t GetExpiryTime(int64_t current_time,
|
||||
bool ignore_soft_enforce_playback_duration) override;
|
||||
|
||||
int64_t GetRenewalStartTime() override { return renewal_start_time_; }
|
||||
|
||||
private:
|
||||
// Gets the clock time that the rental duration or playback will expire.
|
||||
int64_t GetRentalExpiryTime(int64_t current_time);
|
||||
int64_t GetPlaybackExpiryTime(int64_t current_time,
|
||||
bool ignore_soft_enforce_playback_duration);
|
||||
|
||||
bool HasRentalOrPlaybackDurationExpired(int64_t current_time);
|
||||
int64_t GetRentalDurationRemaining(int64_t current_time);
|
||||
|
||||
int64_t renewal_start_time_ = 0;
|
||||
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(PolicyTimersV16);
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,28 @@ void PolicyTimers::DecryptionEvent(int64_t current_time) {
|
||||
last_playback_time_ = current_time;
|
||||
}
|
||||
|
||||
void PolicyTimers::RestorePlaybackTimes(int64_t current_time,
|
||||
int64_t playback_start_time,
|
||||
int64_t last_playback_time,
|
||||
int64_t /* grace_period_end_time */) {
|
||||
playback_start_time_ = (playback_start_time > 0) ? playback_start_time : 0;
|
||||
last_playback_time_ = (last_playback_time > 0) ? last_playback_time : 0;
|
||||
|
||||
const int64_t expiry_time = GetExpiryTime(
|
||||
current_time, /* ignore_soft_enforce_playback_duration */ true);
|
||||
was_expired_on_load_ =
|
||||
expiry_time != NEVER_EXPIRES && expiry_time < current_time;
|
||||
}
|
||||
|
||||
int64_t PolicyTimers::GetLicenseOrRentalOrPlaybackDurationRemaining(
|
||||
int64_t current_time) {
|
||||
const int64_t expiry_time = GetExpiryTime(
|
||||
current_time, /* ignore_soft_enforce_playback_duration */ false);
|
||||
if (expiry_time == NEVER_EXPIRES) return LLONG_MAX;
|
||||
if (expiry_time < current_time) return 0;
|
||||
return expiry_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;
|
||||
@@ -85,12 +107,6 @@ bool PolicyTimers::UpdateExpirationTime(int64_t current_time,
|
||||
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) &&
|
||||
@@ -107,4 +123,61 @@ bool PolicyTimers::HasRenewalRecoveryDurationExpired(int64_t current_time) {
|
||||
current_time);
|
||||
}
|
||||
|
||||
int64_t PolicyTimers::GetExpiryTime(
|
||||
int64_t current_time, bool ignore_soft_enforce_playback_duration) {
|
||||
const int64_t rental_expiry_time = GetRentalExpiryTime(current_time);
|
||||
const int64_t playback_expiry_time = GetPlaybackExpiryTime(
|
||||
current_time, ignore_soft_enforce_playback_duration);
|
||||
|
||||
if (rental_expiry_time == NEVER_EXPIRES) return playback_expiry_time;
|
||||
if (playback_expiry_time == NEVER_EXPIRES) return rental_expiry_time;
|
||||
|
||||
return std::min(rental_expiry_time, playback_expiry_time);
|
||||
}
|
||||
|
||||
// For the policy time fields checked in the following methods, a value of 0
|
||||
// (UNLIMITED_DURATION) indicates that there is no limit to the duration.
|
||||
// If the fields are UNLIMITED_DURATION then these methods will return
|
||||
// NEVER_EXPIRES.
|
||||
int64_t PolicyTimers::GetRentalExpiryTime(int64_t current_time) {
|
||||
if (policy_.rental_duration_seconds() == UNLIMITED_DURATION)
|
||||
return NEVER_EXPIRES;
|
||||
|
||||
if (HasPlaybackStarted(current_time) &&
|
||||
policy_.soft_enforce_rental_duration())
|
||||
return NEVER_EXPIRES;
|
||||
|
||||
return license_start_time_ + policy_.rental_duration_seconds();
|
||||
}
|
||||
|
||||
int64_t PolicyTimers::GetPlaybackExpiryTime(
|
||||
int64_t current_time, bool ignore_soft_enforce_playback_duration) {
|
||||
if (policy_.playback_duration_seconds() == UNLIMITED_DURATION)
|
||||
return NEVER_EXPIRES;
|
||||
|
||||
if (!HasPlaybackStarted(current_time)) return NEVER_EXPIRES;
|
||||
|
||||
if (was_expired_on_load_) return current_time;
|
||||
|
||||
if (!ignore_soft_enforce_playback_duration &&
|
||||
policy_.soft_enforce_playback_duration())
|
||||
return NEVER_EXPIRES;
|
||||
|
||||
return playback_start_time_ + policy_.playback_duration_seconds();
|
||||
}
|
||||
|
||||
int64_t PolicyTimers::GetRentalDurationRemaining(int64_t current_time) {
|
||||
if (HasLicenseOrRentalOrPlaybackDurationExpired(current_time)) return 0;
|
||||
const int64_t rental_expiry_time = GetRentalExpiryTime(current_time);
|
||||
if (rental_expiry_time == NEVER_EXPIRES) return LLONG_MAX;
|
||||
if (rental_expiry_time < current_time) return 0;
|
||||
return rental_expiry_time - current_time;
|
||||
}
|
||||
|
||||
bool PolicyTimers::HasRentalOrPlaybackDurationExpired(int64_t current_time) {
|
||||
const int64_t expiry_time = GetExpiryTime(
|
||||
current_time, /* ignore_soft_enforce_playback_duration */ false);
|
||||
return expiry_time != NEVER_EXPIRES && expiry_time <= current_time;
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
@@ -42,88 +42,10 @@ void PolicyTimersV16::BeginDecryption(int64_t current_time) {
|
||||
}
|
||||
}
|
||||
|
||||
void PolicyTimersV16::RestorePlaybackTimes(
|
||||
int64_t current_time, int64_t playback_start_time,
|
||||
int64_t last_playback_time, int64_t /* grace_period_end_time */) {
|
||||
playback_start_time_ = (playback_start_time > 0) ? playback_start_time : 0;
|
||||
last_playback_time_ = (last_playback_time > 0) ? last_playback_time : 0;
|
||||
|
||||
const int64_t expiry_time = GetExpiryTime(
|
||||
current_time, /* ignore_soft_enforce_playback_duration */ true);
|
||||
was_expired_on_load_ =
|
||||
expiry_time != NEVER_EXPIRES && expiry_time < current_time;
|
||||
}
|
||||
|
||||
bool PolicyTimersV16::HasRentalOrPlaybackDurationExpired(int64_t current_time) {
|
||||
const int64_t expiry_time = GetExpiryTime(
|
||||
current_time, /* ignore_soft_enforce_playback_duration */ false);
|
||||
return expiry_time != NEVER_EXPIRES && expiry_time <= current_time;
|
||||
}
|
||||
|
||||
int64_t PolicyTimersV16::GetLicenseOrRentalOrPlaybackDurationRemaining(
|
||||
int64_t current_time) {
|
||||
const int64_t expiry_time = GetExpiryTime(
|
||||
current_time, /* ignore_soft_enforce_playback_duration */ false);
|
||||
if (expiry_time == NEVER_EXPIRES) return LLONG_MAX;
|
||||
if (expiry_time < current_time) return 0;
|
||||
return expiry_time - current_time;
|
||||
}
|
||||
|
||||
int64_t PolicyTimersV16::GetRentalDurationRemaining(int64_t current_time) {
|
||||
if (HasLicenseOrRentalOrPlaybackDurationExpired(current_time)) return 0;
|
||||
const int64_t rental_expiry_time = GetRentalExpiryTime(current_time);
|
||||
if (rental_expiry_time == NEVER_EXPIRES) return LLONG_MAX;
|
||||
if (rental_expiry_time < current_time) return 0;
|
||||
return rental_expiry_time - current_time;
|
||||
}
|
||||
|
||||
bool PolicyTimersV16::HasRenewalDelayExpired(int64_t current_time) {
|
||||
return policy_.can_renew() && (policy_.renewal_delay_seconds() > 0) &&
|
||||
(renewal_start_time_ + policy_.renewal_delay_seconds() <=
|
||||
current_time);
|
||||
}
|
||||
|
||||
// For the policy time fields checked in the following methods, a value of 0
|
||||
// (UNLIMITED_DURATION) indicates that there is no limit to the duration.
|
||||
// If the fields are UNLIMITED_DURATION then these methods will return
|
||||
// NEVER_EXPIRES.
|
||||
int64_t PolicyTimersV16::GetRentalExpiryTime(int64_t current_time) {
|
||||
if (policy_.rental_duration_seconds() == UNLIMITED_DURATION)
|
||||
return NEVER_EXPIRES;
|
||||
|
||||
if (HasPlaybackStarted(current_time) &&
|
||||
policy_.soft_enforce_rental_duration())
|
||||
return NEVER_EXPIRES;
|
||||
|
||||
return license_start_time_ + policy_.rental_duration_seconds();
|
||||
}
|
||||
|
||||
int64_t PolicyTimersV16::GetPlaybackExpiryTime(
|
||||
int64_t current_time, bool ignore_soft_enforce_playback_duration) {
|
||||
if (policy_.playback_duration_seconds() == UNLIMITED_DURATION)
|
||||
return NEVER_EXPIRES;
|
||||
|
||||
if (!HasPlaybackStarted(current_time)) return NEVER_EXPIRES;
|
||||
|
||||
if (was_expired_on_load_) return current_time;
|
||||
|
||||
if (!ignore_soft_enforce_playback_duration &&
|
||||
policy_.soft_enforce_playback_duration())
|
||||
return NEVER_EXPIRES;
|
||||
|
||||
return playback_start_time_ + policy_.playback_duration_seconds();
|
||||
}
|
||||
|
||||
int64_t PolicyTimersV16::GetExpiryTime(
|
||||
int64_t current_time, bool ignore_soft_enforce_playback_duration) {
|
||||
const int64_t rental_expiry_time = GetRentalExpiryTime(current_time);
|
||||
const int64_t playback_expiry_time = GetPlaybackExpiryTime(
|
||||
current_time, ignore_soft_enforce_playback_duration);
|
||||
|
||||
if (rental_expiry_time == NEVER_EXPIRES) return playback_expiry_time;
|
||||
if (playback_expiry_time == NEVER_EXPIRES) return rental_expiry_time;
|
||||
|
||||
return std::min(rental_expiry_time, playback_expiry_time);
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
Reference in New Issue
Block a user