[ Merge of http://go/wvgerrit/93743 ] Reworks policy engine in preparation for changes to support timer and clock value handling by OEMCrypto core messages in OEMCrypto v16. No major functional changes have yet been introduced. Time and duration evaluation has been devolved to a new policy timer class. Policy specific to licenses that do not support OEMCrypto core messages is handled by a Policy Timer V15 class. This ensures backward compatibility. Backward compatibility may be needed if * OEMCrypto has not been upgraded to v16 * Licenses were persisted before the device was upgraded to v16 * License service does not yet support core messages Some minor changes to when the current time was retrieved required minor modification to test expectations. Bug: 139372190 Test: Android unit/integration tests Change-Id: I420fb181f656ed9a6bfe54f09e8b398c130d23da
113 lines
4.2 KiB
C++
113 lines
4.2 KiB
C++
// 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.
|
|
|
|
#ifndef WVCDM_CORE_POLICY_TIMERS_H_
|
|
#define WVCDM_CORE_POLICY_TIMERS_H_
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "disallow_copy_and_assign.h"
|
|
#include "license_protocol.pb.h"
|
|
#include "wv_cdm_types.h"
|
|
|
|
namespace wvcdm {
|
|
|
|
// This is driven by the Policy Engine and maintains timer related
|
|
// information from the policy such as duration windows and renewals.
|
|
// Timer expiration behavior has changed with the introduction of core
|
|
// messages in OEMCrypto v16. Handling of behavior that differs between
|
|
// a OEMCrypto v16 license with core messages and one without is left to
|
|
// a class that derives from this interface.
|
|
|
|
class PolicyTimers {
|
|
public:
|
|
virtual ~PolicyTimers() {}
|
|
|
|
// SetLicense is used in handling the initial license response.
|
|
virtual void SetLicense(const video_widevine::License& license);
|
|
|
|
// UpdateLicense is used in handling a license response for a renewal request.
|
|
// The response may only contain policy fields that have changed. In this
|
|
// case an exact copy is not what we want to happen.
|
|
virtual bool UpdateLicense(int64_t current_time,
|
|
const video_widevine::License& license) = 0;
|
|
|
|
// Call this on first decrypt to set the start of playback.
|
|
virtual void BeginDecryption(int64_t current_time) = 0;
|
|
// Call this periodically to update the most recent playback time.
|
|
virtual void DecryptionEvent(int64_t current_time);
|
|
|
|
// 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;
|
|
virtual void RestorePlaybackTimes(int64_t current_time,
|
|
int64_t playback_start_time,
|
|
int64_t last_playback_time,
|
|
int64_t grace_period_end_time) = 0;
|
|
|
|
virtual bool HasPlaybackStarted(int64_t current_time) = 0;
|
|
virtual bool HasLicenseOrPlaybackDurationExpired(int64_t current_time) = 0;
|
|
virtual bool HasPassedGracePeriod(int64_t current_time) = 0;
|
|
|
|
virtual int64_t GetLicenseOrPlaybackDurationRemaining(
|
|
int64_t current_time) = 0;
|
|
virtual int64_t GetLicenseOrRentalDurationRemaining(int64_t current_time) = 0;
|
|
virtual int64_t GetPlaybackDurationRemaining(int64_t current_time) = 0;
|
|
|
|
virtual bool GetSecondsSinceStarted(int64_t current_time,
|
|
int64_t* seconds_since_started);
|
|
virtual bool GetSecondsSinceLastPlayed(int64_t current_time,
|
|
int64_t* seconds_since_started);
|
|
|
|
virtual bool IsLicenseForFuture(int64_t current_time);
|
|
|
|
virtual bool UpdateExpirationTime(int64_t current_time, int64_t* expiry_time);
|
|
|
|
// Renewal related methods
|
|
virtual bool HasRenewalDelayExpired(int64_t current_time);
|
|
virtual bool HasRenewalRetryIntervalExpired(int64_t current_time);
|
|
virtual void UpdateRenewalRequest(int64_t current_time);
|
|
virtual bool HasRenewalRecoveryDurationExpired(int64_t current_time);
|
|
|
|
const video_widevine::License::Policy& get_policy() { return policy_; }
|
|
|
|
protected:
|
|
PolicyTimers()
|
|
: license_start_time_(0),
|
|
playback_start_time_(0),
|
|
last_playback_time_(0),
|
|
last_expiry_time_(0),
|
|
last_expiry_time_set_(false),
|
|
next_renewal_time_(0),
|
|
was_expired_on_load_(false) {}
|
|
|
|
// Gets the clock time that the license expires based on whether we have
|
|
// started playing.
|
|
virtual int64_t GetExpiryTime(int64_t current_time,
|
|
bool ignore_soft_enforce_playback_duration) = 0;
|
|
|
|
// This is the current policy information for this license. This gets updated
|
|
// as license renewals occur.
|
|
video_widevine::License::Policy policy_;
|
|
|
|
int64_t license_start_time_;
|
|
int64_t playback_start_time_;
|
|
int64_t last_playback_time_;
|
|
int64_t last_expiry_time_;
|
|
int64_t last_expiry_time_set_;
|
|
int64_t next_renewal_time_;
|
|
|
|
// Indicates whether a persistent license was expired when loaded
|
|
bool was_expired_on_load_;
|
|
|
|
private:
|
|
CORE_DISALLOW_COPY_AND_ASSIGN(PolicyTimers);
|
|
};
|
|
|
|
} // namespace wvcdm
|
|
|
|
#endif // WVCDM_CORE_POLICY_TIMERS_H_
|