Files
ce_cdm/core/include/policy_timers_v16.h
2020-04-10 16:13:07 -07:00

112 lines
4.3 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_V16_H_
#define WVCDM_CORE_POLICY_TIMERS_V16_H_
#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 PolicyTimersV16 : public PolicyTimers {
public:
PolicyTimersV16() {}
virtual ~PolicyTimersV16() {}
// 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.
// |renewal_start_time_| is set 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;
// This is a legacy field for offline licenses. Since no grace period is
// supported return a default value.
int64_t GetGracePeriodEndTime() override { return 0; }
// 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 {
return playback_start_time_ != 0;
}
// For licenses that support core messages, evaluation of only rental and
// playback durations are needed.
bool HasLicenseOrRentalOrPlaybackDurationExpired(
int64_t current_time) override {
return HasRentalOrPlaybackDurationExpired(current_time);
}
bool HasPassedGracePeriod(int64_t /* current_time */) override {
return true;
}
// This returns
// * before playback begins: the time remaining on |rental_duration_seconds|
// * after playback begins:
// - |soft_enforce_playback_duration| is true: the time remaining on
// |playback_duration_seconds|
// - |soft_enforce_playback_duration| is false: the minimum
// of the time remaining on |rental_duration_seconds| or
// |playback_duration_seconds|
//
// |license_duration_seconds| is ignored with the introduction of core
// messages
int64_t GetLicenseOrRentalOrPlaybackDurationRemaining(
int64_t current_time) override;
// This is only used in Query. This should return the time remaining on
// |rental_duration_seconds|.
int64_t GetLicenseOrRentalDurationRemaining(int64_t current_time) override {
return GetRentalDurationRemaining(current_time);
};
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 renewal_start_time_; }
private:
// Gets the clock time that the rental duration or playback will expire.
int64_t GetRentalExpiryTime(int64_t current_time);
int64_t GetPlaybackExpiryTime(int64_t current_time,
bool ignore_soft_enforce_playback_duration);
bool HasRentalOrPlaybackDurationExpired(int64_t current_time);
int64_t GetRentalDurationRemaining(int64_t current_time);
int64_t renewal_start_time_ = 0;
CORE_DISALLOW_COPY_AND_ASSIGN(PolicyTimersV16);
};
} // namespace wvcdm
#endif // WVCDM_CORE_POLICY_TIMERS_V16_H_