Add License::Policy::soft_enforce_playback_duration

[ Merge of http://go/wvgerrit/22564 ]

b/34211676

Test: All unittests other than some oemcrypto, request_license_test
passed. Those tests failed with or without this CL.

Change-Id: I20474339aa1777da2db3677c10f186726505ecc8
This commit is contained in:
Rahul Frias
2017-01-13 19:20:30 -08:00
parent b413037733
commit 4ba59828eb
4 changed files with 110 additions and 6 deletions

View File

@@ -32,6 +32,7 @@ PolicyEngine::PolicyEngine(CdmSessionId session_id,
last_playback_time_(0),
last_expiry_time_(0),
last_expiry_time_set_(false),
was_expired_on_load_(false),
next_renewal_time_(0),
session_id_(session_id),
event_listener_(event_listener),
@@ -290,7 +291,8 @@ bool PolicyEngine::GetSecondsSinceLastPlayed(
int64_t PolicyEngine::GetLicenseOrPlaybackDurationRemaining() {
int64_t current_time = clock_->GetCurrentTime();
const int64_t expiry_time = GetExpiryTime();
const int64_t expiry_time =
GetExpiryTime(/* 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;
@@ -300,6 +302,13 @@ void PolicyEngine::RestorePlaybackTimes(int64_t playback_start_time,
int64_t last_playback_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 current_time = clock_->GetCurrentTime();
const int64_t expiry_time =
GetExpiryTime(/* ignore_soft_enforce_playback_duration */ true);
was_expired_on_load_ =
expiry_time != NEVER_EXPIRES && expiry_time < current_time;
NotifyExpirationUpdate();
}
@@ -309,8 +318,9 @@ void PolicyEngine::UpdateRenewalRequest(int64_t current_time) {
}
bool PolicyEngine::HasLicenseOrPlaybackDurationExpired(int64_t current_time) {
const int64_t expiry_time = GetExpiryTime();
return (expiry_time == NEVER_EXPIRES) ? false : (expiry_time <= current_time);
const int64_t expiry_time =
GetExpiryTime(/* ignore_soft_enforce_playback_duration */ false);
return (expiry_time != NEVER_EXPIRES) && expiry_time <= current_time;
}
// For the policy time fields checked in the following methods, a value of 0
@@ -332,12 +342,17 @@ int64_t PolicyEngine::GetRentalExpiryTime() {
return std::min(hard_limit, expiry_time);
}
int64_t PolicyEngine::GetExpiryTime() {
int64_t PolicyEngine::GetExpiryTime(
bool ignore_soft_enforce_playback_duration) {
if (!HasPlaybackStarted())
return GetRentalExpiryTime();
const int64_t hard_limit = GetHardLicenseExpiryTime();
if (policy_.playback_duration_seconds() == 0) return hard_limit;
if (!ignore_soft_enforce_playback_duration && !was_expired_on_load_ &&
policy_.soft_enforce_playback_duration()) {
return hard_limit;
}
const int64_t expiry_time =
playback_start_time_ + policy_.playback_duration_seconds();
@@ -404,7 +419,8 @@ void PolicyEngine::NotifyKeysChange(CdmKeyStatus new_status) {
}
void PolicyEngine::NotifyExpirationUpdate() {
const int64_t expiry_time = GetExpiryTime();
const int64_t expiry_time =
GetExpiryTime(/* ignore_soft_enforce_playback_duration */ false);
if (!last_expiry_time_set_ || expiry_time != last_expiry_time_) {
last_expiry_time_ = expiry_time;
if (event_listener_)