98 lines
3.8 KiB
C++
98 lines
3.8 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_V15_H_
|
|
#define WVCDM_CORE_POLICY_TIMERS_V15_H_
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "disallow_copy_and_assign.h"
|
|
#include "license_protocol.pb.h"
|
|
#include "policy_timers.h"
|
|
#include "wv_cdm_types.h"
|
|
|
|
namespace wvcdm {
|
|
|
|
// OEMCrypto v16 and core messages introduced changes to how duration values
|
|
// and clocks should be evaluated. This class provides backward compatibility
|
|
// for licenses that do not include a core message. Durations are handled
|
|
// in the same way as in earlier releases.
|
|
//
|
|
// 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
|
|
|
|
class PolicyTimersV15 : public PolicyTimers {
|
|
public:
|
|
PolicyTimersV15() : grace_period_end_time_(0) {}
|
|
|
|
virtual ~PolicyTimersV15() {}
|
|
|
|
// UpdateLicense is used in handling a license response, a renewal response,
|
|
// or when restoring or releasing a persistent license.
|
|
// In a renewal the response may only contain policy fields that have
|
|
// changed. In this case an exact copy is not what we want to happen.
|
|
// |license_start_time_| is updated to the time mentioned in the renewal
|
|
// response.
|
|
// UpdateLicense will return false if |license_start_time| is not
|
|
// present or playback is not allowed due to policy or timer duration
|
|
// expiration.
|
|
bool UpdateLicense(int64_t current_time,
|
|
const video_widevine::License& license) override;
|
|
|
|
// Call this on first decrypt to set the start of playback.
|
|
void BeginDecryption(int64_t current_time) override;
|
|
|
|
// for offline save and restore
|
|
int64_t GetGracePeriodEndTime() override { return grace_period_end_time_; }
|
|
|
|
// for offline save and restore
|
|
void RestorePlaybackTimes(int64_t current_time, int64_t playback_start_time,
|
|
int64_t last_playback_time,
|
|
int64_t grace_period_end_time) override;
|
|
|
|
bool HasPlaybackStarted(int64_t current_time) override;
|
|
bool HasLicenseOrRentalOrPlaybackDurationExpired(
|
|
int64_t current_time) override;
|
|
bool HasPassedGracePeriod(int64_t current_time) override;
|
|
|
|
// This returns
|
|
// * for streaming licenses: the time remaining on |license_duration_seconds|
|
|
// * for persistent licenses: the time remaining on |rental_duration_seconds|
|
|
// before playback begins or the time remaining on
|
|
// |playback_duration_seconds| after.
|
|
int64_t GetLicenseOrRentalOrPlaybackDurationRemaining(
|
|
int64_t current_time) override;
|
|
// This is only used in Query. This should return the time remaining on
|
|
// |license_duration_seconds| for streaming licenses and
|
|
// |rental_duration_seconds| for persistent licenses.
|
|
int64_t GetLicenseOrRentalDurationRemaining(int64_t current_time) override;
|
|
|
|
protected:
|
|
// Gets the clock time that the license expires based on whether we have
|
|
// started playing. This takes into account GetHardLicenseExpiryTime.
|
|
int64_t GetExpiryTime(int64_t current_time,
|
|
bool ignore_soft_enforce_playback_duration) override;
|
|
|
|
int64_t GetRenewalStartTime() override { return license_start_time_; }
|
|
|
|
private:
|
|
// Gets the clock time that the license expires. This is the hard limit that
|
|
// all license types must obey at all times.
|
|
int64_t GetHardLicenseExpiryTime();
|
|
// Gets the clock time that the rental duration will expire, using the license
|
|
// duration if one is not present.
|
|
int64_t GetRentalExpiryTime();
|
|
|
|
int64_t grace_period_end_time_;
|
|
|
|
CORE_DISALLOW_COPY_AND_ASSIGN(PolicyTimersV15);
|
|
};
|
|
|
|
} // namespace wvcdm
|
|
|
|
#endif // WVCDM_CORE_POLICY_TIMERS_V15_H_
|