Delay license state evaluation for offline licenses am: 8543b4c903 am: 9f2363e076
Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/12646162 Change-Id: I0158e6b1dc2560ff28ff9379533a428f2970efeb
This commit is contained in:
@@ -593,7 +593,8 @@ CdmResponseType CdmSession::AddKeyInternal(const CdmKeyResponse& key_response) {
|
||||
if (sts != NO_ERROR) return sts;
|
||||
}
|
||||
}
|
||||
sts = license_parser_->HandleKeyResponse(key_response);
|
||||
sts = license_parser_->HandleKeyResponse(/* is restore */ false,
|
||||
key_response);
|
||||
|
||||
// Update the license sdk and service versions.
|
||||
const VersionInfo& version_info = license_parser_->GetServiceVersion();
|
||||
@@ -790,8 +791,9 @@ CdmResponseType CdmSession::RenewKey(const CdmKeyResponse& key_response) {
|
||||
LOGE("CDM session not initialized");
|
||||
return NOT_INITIALIZED_ERROR;
|
||||
}
|
||||
CdmResponseType sts =
|
||||
license_parser_->HandleKeyUpdateResponse(true, key_response);
|
||||
CdmResponseType sts = license_parser_->HandleKeyUpdateResponse(
|
||||
/* is renewal */ true,
|
||||
/* is restore */ false, key_response);
|
||||
|
||||
// Record the timing on success.
|
||||
UpdateRequestLatencyTiming(sts);
|
||||
@@ -855,8 +857,9 @@ CdmResponseType CdmSession::ReleaseKey(const CdmKeyResponse& key_response) {
|
||||
LOGE("CDM session not initialized");
|
||||
return NOT_INITIALIZED_ERROR;
|
||||
}
|
||||
CdmResponseType sts =
|
||||
license_parser_->HandleKeyUpdateResponse(false, key_response);
|
||||
CdmResponseType sts = license_parser_->HandleKeyUpdateResponse(
|
||||
/* is renewal */ false,
|
||||
/* is restore */ false, key_response);
|
||||
// Record the timing on success.
|
||||
UpdateRequestLatencyTiming(sts);
|
||||
|
||||
|
||||
@@ -530,7 +530,7 @@ CdmResponseType CdmLicense::PrepareKeyUpdateRequest(
|
||||
}
|
||||
|
||||
CdmResponseType CdmLicense::HandleKeyResponse(
|
||||
const CdmKeyResponse& license_response) {
|
||||
bool is_restore, const CdmKeyResponse& license_response) {
|
||||
if (!initialized_) {
|
||||
LOGE("CdmLicense not initialized");
|
||||
return LICENSE_PARSER_NOT_INITIALIZED_2;
|
||||
@@ -683,18 +683,19 @@ CdmResponseType CdmLicense::HandleKeyResponse(
|
||||
|
||||
CdmResponseType resp = NO_CONTENT_KEY;
|
||||
if (kLicenseKeyTypeEntitlement == key_type) {
|
||||
resp =
|
||||
HandleEntitlementKeyResponse(signed_message, core_message, signature,
|
||||
mac_key_iv, mac_keys, key_array, license);
|
||||
resp = HandleEntitlementKeyResponse(is_restore, signed_message,
|
||||
core_message, signature, mac_key_iv,
|
||||
mac_keys, key_array, license);
|
||||
} else if (kLicenseKeyTypeContent == key_type) {
|
||||
resp = HandleContentKeyResponse(signed_message, core_message, signature,
|
||||
mac_key_iv, mac_keys, key_array, license);
|
||||
resp = HandleContentKeyResponse(is_restore, signed_message, core_message,
|
||||
signature, mac_key_iv, mac_keys, key_array,
|
||||
license);
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
|
||||
CdmResponseType CdmLicense::HandleKeyUpdateResponse(
|
||||
bool is_renewal, const CdmKeyResponse& license_response) {
|
||||
bool is_renewal, bool is_restore, const CdmKeyResponse& license_response) {
|
||||
if (!initialized_) {
|
||||
LOGE("CdmLicense not initialized");
|
||||
return LICENSE_PARSER_NOT_INITIALIZED_3;
|
||||
@@ -781,7 +782,7 @@ CdmResponseType CdmLicense::HandleKeyUpdateResponse(
|
||||
}
|
||||
|
||||
if (status == KEY_ADDED) {
|
||||
policy_engine_->UpdateLicense(license);
|
||||
policy_engine_->UpdateLicense(license, is_restore);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -836,14 +837,14 @@ CdmResponseType CdmLicense::RestoreOfflineLicense(
|
||||
license_nonce_ = original_license_request.key_control_nonce();
|
||||
}
|
||||
|
||||
CdmResponseType sts = HandleKeyResponse(license_response);
|
||||
CdmResponseType sts = HandleKeyResponse(true, license_response);
|
||||
|
||||
if (sts != KEY_ADDED) return sts;
|
||||
|
||||
if (!license_renewal_response.empty()) {
|
||||
sts = PrepareKeyUpdateReload(cdm_session);
|
||||
if (sts != KEY_MESSAGE) return sts;
|
||||
sts = HandleKeyUpdateResponse(true, license_renewal_response);
|
||||
if (sts != KEY_MESSAGE && sts != NO_ERROR) return sts;
|
||||
sts = HandleKeyUpdateResponse(true, true, license_renewal_response);
|
||||
if (sts != KEY_ADDED) return sts;
|
||||
}
|
||||
|
||||
@@ -968,7 +969,7 @@ CdmResponseType CdmLicense::RestoreLicenseForRelease(
|
||||
}
|
||||
|
||||
if (!license.id().has_provider_session_token()) {
|
||||
CdmResponseType result = HandleKeyResponse(license_response);
|
||||
CdmResponseType result = HandleKeyResponse(false, license_response);
|
||||
return result == KEY_ADDED ? NO_ERROR : result;
|
||||
}
|
||||
|
||||
@@ -1116,7 +1117,7 @@ CdmResponseType CdmLicense::PrepareContentId(
|
||||
}
|
||||
|
||||
CdmResponseType CdmLicense::HandleContentKeyResponse(
|
||||
const std::string& msg, const std::string& core_message,
|
||||
bool is_restore, const std::string& msg, const std::string& core_message,
|
||||
const std::string& signature, const std::string& mac_key_iv,
|
||||
const std::string& mac_key, const std::vector<CryptoKey>& key_array,
|
||||
const video_widevine::License& license) {
|
||||
@@ -1140,13 +1141,13 @@ CdmResponseType CdmLicense::HandleContentKeyResponse(
|
||||
it != key_array.end(); ++it) {
|
||||
loaded_keys_.insert(it->key_id());
|
||||
}
|
||||
policy_engine_->SetLicense(license, supports_core_messages());
|
||||
policy_engine_->SetLicense(license, supports_core_messages(), is_restore);
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
|
||||
CdmResponseType CdmLicense::HandleEntitlementKeyResponse(
|
||||
const std::string& msg, const std::string& core_message,
|
||||
bool is_restore, const std::string& msg, const std::string& core_message,
|
||||
const std::string& signature, const std::string& mac_key_iv,
|
||||
const std::string& mac_key, const std::vector<CryptoKey>& key_array,
|
||||
const video_widevine::License& license) {
|
||||
@@ -1170,7 +1171,7 @@ CdmResponseType CdmLicense::HandleEntitlementKeyResponse(
|
||||
|
||||
// Save the entitlement keys for future use to handle key changes.
|
||||
entitlement_keys_.CopyFrom(license.key());
|
||||
policy_engine_->SetLicense(license, supports_core_messages());
|
||||
policy_engine_->SetLicense(license, supports_core_messages(), is_restore);
|
||||
|
||||
return HandleNewEntitledKeys(wrapped_keys_);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ using video_widevine::License;
|
||||
namespace {
|
||||
|
||||
const int kCdmPolicyTimerDurationSeconds = 1;
|
||||
const int kClockSkewDelta = 5; // seconds
|
||||
const int kClockSkewDelta = 5; // seconds
|
||||
const int64_t kLicenseStateUpdateDelay = 20; // seconds
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -30,6 +31,7 @@ PolicyEngine::PolicyEngine(CdmSessionId session_id,
|
||||
WvCdmEventListener* event_listener,
|
||||
CryptoSession* crypto_session)
|
||||
: license_state_(kLicenseStateInitial),
|
||||
license_state_update_deadline_(0),
|
||||
last_recorded_current_time_(0),
|
||||
session_id_(session_id),
|
||||
event_listener_(event_listener),
|
||||
@@ -90,6 +92,17 @@ void PolicyEngine::OnTimerEvent() {
|
||||
last_recorded_current_time_ += kCdmPolicyTimerDurationSeconds;
|
||||
const int64_t current_time = GetCurrentTime();
|
||||
|
||||
// This conditional should not succeed but being cautious in case license
|
||||
// state was not updated after the license was processed. Licenses and
|
||||
// renewals from the license service should update state on
|
||||
// |Set/UpdateLicense|. Offline licenses, when restored, should update license
|
||||
// state when |RestorePlaybackTimes| is called.
|
||||
if (license_state_update_deadline_ != 0 &&
|
||||
license_state_update_deadline_ < current_time) {
|
||||
LOGW("License state was not updated after a license was loaded/renewed");
|
||||
UpdateLicenseState(current_time);
|
||||
}
|
||||
|
||||
// If we have passed the grace period, the expiration will update.
|
||||
if (policy_timers_->HasPassedGracePeriod(current_time)) {
|
||||
NotifyExpirationUpdate(current_time);
|
||||
@@ -159,12 +172,13 @@ void PolicyEngine::OnTimerEvent() {
|
||||
}
|
||||
|
||||
void PolicyEngine::SetLicense(const License& license,
|
||||
bool supports_core_messages) {
|
||||
bool supports_core_messages,
|
||||
bool defer_license_state_update) {
|
||||
if (supports_core_messages) policy_timers_.reset(new PolicyTimersV16());
|
||||
license_id_.CopyFrom(license.id());
|
||||
license_keys_->SetFromLicense(license);
|
||||
policy_timers_->SetLicense(license);
|
||||
UpdateLicense(license);
|
||||
UpdateLicense(license, defer_license_state_update);
|
||||
}
|
||||
|
||||
void PolicyEngine::SetEntitledLicenseKeys(
|
||||
@@ -180,10 +194,11 @@ void PolicyEngine::SetLicenseForRelease(const License& license,
|
||||
// Expire any old keys.
|
||||
NotifyKeysChange(kKeyStatusExpired);
|
||||
policy_timers_->SetLicense(license);
|
||||
UpdateLicense(license);
|
||||
UpdateLicense(license, false);
|
||||
}
|
||||
|
||||
void PolicyEngine::UpdateLicense(const License& license) {
|
||||
void PolicyEngine::UpdateLicense(const License& license,
|
||||
bool defer_license_state_update) {
|
||||
if (!license.has_policy()) return;
|
||||
|
||||
if (kLicenseStateExpired == license_state_) {
|
||||
@@ -204,8 +219,15 @@ void PolicyEngine::UpdateLicense(const License& license) {
|
||||
|
||||
const int64_t current_time = GetCurrentTime();
|
||||
policy_timers_->UpdateLicense(current_time, license);
|
||||
if (defer_license_state_update)
|
||||
license_state_update_deadline_ = current_time + kLicenseStateUpdateDelay;
|
||||
else
|
||||
UpdateLicenseState(current_time);
|
||||
}
|
||||
|
||||
void PolicyEngine::UpdateLicenseState(int64_t current_time) {
|
||||
// Update time information
|
||||
license_state_update_deadline_ = 0;
|
||||
if (!policy_timers_->get_policy().can_play() ||
|
||||
policy_timers_->HasLicenseOrRentalOrPlaybackDurationExpired(
|
||||
current_time)) {
|
||||
@@ -349,7 +371,7 @@ void PolicyEngine::RestorePlaybackTimes(int64_t playback_start_time,
|
||||
last_playback_time,
|
||||
grace_period_end_time);
|
||||
|
||||
NotifyExpirationUpdate(current_time);
|
||||
UpdateLicenseState(current_time);
|
||||
}
|
||||
|
||||
void PolicyEngine::UpdateRenewalRequest(int64_t current_time) {
|
||||
|
||||
Reference in New Issue
Block a user