Add policy handling for v16
[ Merge of http://go/wvgerrit/93865 ] This allows for handling of timer and clock values as supported when both the license service and the OEMCrypto on the device support v16. A flag based on a value in the SignedResponse license indicates whether this support should be enabled. A new class PolicyTimerV16 performs the duration value evaluation. Bug: 139372190 Test: Android WV unit/integration tests Change-Id: Iacbbd51ad26c9f29cb5418ff832f8822982644b7
This commit is contained in:
@@ -944,7 +944,7 @@ CdmResponseType CdmLicense::RestoreLicenseForRelease(
|
||||
|
||||
// If the policy engine already has keys, they will now expire.
|
||||
// If the policy engine does not already have keys, this will not add any.
|
||||
policy_engine_->SetLicenseForRelease(license);
|
||||
policy_engine_->SetLicenseForRelease(license, supports_core_messages());
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -1106,7 +1106,7 @@ CdmResponseType CdmLicense::HandleContentKeyResponse(
|
||||
it != key_array.end(); ++it) {
|
||||
loaded_keys_.insert(it->key_id());
|
||||
}
|
||||
policy_engine_->SetLicense(license);
|
||||
policy_engine_->SetLicense(license, supports_core_messages());
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
@@ -1135,7 +1135,7 @@ CdmResponseType CdmLicense::HandleEntitlementKeyResponse(
|
||||
|
||||
// Save the entitlement keys for future use to handle key changes.
|
||||
entitlement_keys_.CopyFrom(license.key());
|
||||
policy_engine_->SetLicense(license);
|
||||
policy_engine_->SetLicense(license, supports_core_messages());
|
||||
|
||||
return HandleNewEntitledKeys(wrapped_keys_);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "clock.h"
|
||||
#include "log.h"
|
||||
#include "policy_timers_v15.h"
|
||||
#include "policy_timers_v16.h"
|
||||
#include "properties.h"
|
||||
#include "string_conversions.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
@@ -157,7 +158,9 @@ void PolicyEngine::OnTimerEvent() {
|
||||
}
|
||||
}
|
||||
|
||||
void PolicyEngine::SetLicense(const License& license) {
|
||||
void PolicyEngine::SetLicense(const License& license,
|
||||
bool supports_core_messages) {
|
||||
if (supports_core_messages) policy_timers_.reset(new PolicyTimersV16());
|
||||
license_id_.CopyFrom(license.id());
|
||||
license_keys_->SetFromLicense(license);
|
||||
policy_timers_->SetLicense(license);
|
||||
@@ -169,7 +172,9 @@ void PolicyEngine::SetEntitledLicenseKeys(
|
||||
license_keys_->SetEntitledKeys(entitled_keys);
|
||||
}
|
||||
|
||||
void PolicyEngine::SetLicenseForRelease(const License& license) {
|
||||
void PolicyEngine::SetLicenseForRelease(const License& license,
|
||||
bool supports_core_messages) {
|
||||
if (supports_core_messages) policy_timers_.reset(new PolicyTimersV16());
|
||||
license_id_.CopyFrom(license.id());
|
||||
|
||||
// Expire any old keys.
|
||||
|
||||
@@ -110,14 +110,15 @@ int64_t PolicyTimersV15::GetLicenseOrRentalDurationRemaining(
|
||||
if (license_expiry_time == NEVER_EXPIRES) return LLONG_MAX;
|
||||
if (license_expiry_time < current_time) return 0;
|
||||
const int64_t policy_license_duration = policy_.license_duration_seconds();
|
||||
if (policy_license_duration == NEVER_EXPIRES)
|
||||
if (policy_license_duration == UNLIMITED_DURATION)
|
||||
return license_expiry_time - current_time;
|
||||
return std::min(license_expiry_time - current_time, policy_license_duration);
|
||||
}
|
||||
|
||||
// For the policy time fields checked in the following methods, a value of 0
|
||||
// indicates that there is no limit to the duration. If the fields are zero
|
||||
// (including the hard limit) then these methods will return NEVER_EXPIRES.
|
||||
// (UNLIMITED_DURATION) indicates that there is no limit to the duration.
|
||||
// If the fields are UNLIMITED_DURATION (including the hard limit) then these
|
||||
// methods will return NEVER_EXPIRES.
|
||||
int64_t PolicyTimersV15::GetHardLicenseExpiryTime() {
|
||||
return policy_.license_duration_seconds() > 0
|
||||
? license_start_time_ + policy_.license_duration_seconds()
|
||||
|
||||
123
libwvdrmengine/cdm/core/src/policy_timers_v16.cpp
Normal file
123
libwvdrmengine/cdm/core/src/policy_timers_v16.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
// 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_v16.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "log.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
|
||||
using video_widevine::License;
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
bool PolicyTimersV16::UpdateLicense(int64_t current_time,
|
||||
const License& license) {
|
||||
if (!license.has_policy()) return false;
|
||||
|
||||
policy_.MergeFrom(license.policy());
|
||||
|
||||
// some basic license validation
|
||||
// license start time needs to be specified in the initial response
|
||||
if (!license.has_license_start_time()) return false;
|
||||
|
||||
// Update time information
|
||||
renewal_start_time_ = license.license_start_time();
|
||||
next_renewal_time_ =
|
||||
license.license_start_time() + policy_.renewal_delay_seconds();
|
||||
|
||||
if (!policy_.can_play() ||
|
||||
HasLicenseOrRentalOrPlaybackDurationExpired(current_time))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PolicyTimersV16::BeginDecryption(int64_t current_time) {
|
||||
if (playback_start_time_ == 0) {
|
||||
playback_start_time_ = current_time;
|
||||
last_playback_time_ = 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;
|
||||
}
|
||||
|
||||
// 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