Merge "Add License::Policy::soft_enforce_playback_duration"

This commit is contained in:
Rahul Frias
2017-01-20 09:16:52 +00:00
committed by Android (Google) Code Review
4 changed files with 110 additions and 6 deletions

View File

@@ -82,6 +82,10 @@ message License {
// Indicates to client that license renewal and release requests ought to
// include ClientIdentification (client_id).
optional bool renew_with_client_id = 12 [default = false];
// Enables "soft enforcement" of playback_duration_seconds, letting the user
// finish playback even if short window expires. Optional.
optional bool soft_enforce_playback_duration = 14 [default = false];
}
message KeyContainer {

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_)