85 lines
2.9 KiB
C++
85 lines
2.9 KiB
C++
// Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine License
|
|
// Agreement.
|
|
#ifndef WVCDM_CORE_OKP_SYSTEM_INFO_H_
|
|
#define WVCDM_CORE_OKP_SYSTEM_INFO_H_
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include "wv_class_utils.h"
|
|
|
|
namespace wvcdm {
|
|
// OTA Keybox Provisioning (OKP)
|
|
namespace okp {
|
|
enum class SystemState {
|
|
kUnknown = 0,
|
|
kNeedsProvisioning = 1,
|
|
kFallbackMode = 2, // Fallback indicates provisioning is needed.
|
|
kProvisioned = 3
|
|
// Note: "Not needed" is represented by an absence of info.
|
|
};
|
|
// Converts a SystemState value to a human readable string. Intended
|
|
// to be used for debug logging.
|
|
const char* SystemStateToString(SystemState state);
|
|
|
|
// Container for all the device information related to OKP.
|
|
class SystemFallbackInfo {
|
|
public:
|
|
constexpr SystemFallbackInfo() = default;
|
|
WVCDM_CONSTEXPR_DEFAULT_COPY_AND_MOVE(SystemFallbackInfo);
|
|
|
|
constexpr SystemState state() const { return state_; }
|
|
constexpr void SetState(SystemState state) { state_ = state; }
|
|
|
|
constexpr bool HasFirstCheckedTime() const {
|
|
return first_checked_time_ != 0;
|
|
}
|
|
constexpr int64_t first_checked_time() const { return first_checked_time_; }
|
|
constexpr void SetFirstCheckedTime(int64_t time) {
|
|
first_checked_time_ = (time > 0 ? time : 0);
|
|
}
|
|
|
|
constexpr bool HasBackoffStartTime() const { return backoff_start_time_ > 0; }
|
|
constexpr int64_t backoff_start_time() const { return backoff_start_time_; }
|
|
constexpr void SetBackoffStartTime(int64_t time) {
|
|
backoff_start_time_ = (time > 0 ? time : 0);
|
|
}
|
|
constexpr void ClearBackoffStartTime() { backoff_start_time_ = 0; }
|
|
|
|
constexpr bool HasBackoffDuration() const { return backoff_duration_ > 0; }
|
|
constexpr int64_t backoff_duration() const { return backoff_duration_; }
|
|
constexpr void SetBackoffDuration(int64_t duration) {
|
|
backoff_duration_ = (duration > 0 ? duration : 0);
|
|
}
|
|
constexpr void DoubleBackoffDuration() { backoff_duration_ *= 2; }
|
|
constexpr void ClearBackoffDuration() { backoff_duration_ = 0; }
|
|
|
|
constexpr bool HasProvisioningTime() const { return provisioning_time_ != 0; }
|
|
constexpr int64_t provisioning_time() const { return provisioning_time_; }
|
|
constexpr void SetProvisioningTime(int64_t time) {
|
|
provisioning_time_ = (time > 0 ? time : 0);
|
|
}
|
|
constexpr void ClearProvisioningTime() { provisioning_time_ = 0; }
|
|
|
|
constexpr void Clear() {
|
|
state_ = SystemState::kUnknown;
|
|
first_checked_time_ = 0;
|
|
backoff_start_time_ = 0;
|
|
backoff_duration_ = 0;
|
|
provisioning_time_ = 0;
|
|
}
|
|
|
|
bool IsEqualTo(const SystemFallbackInfo& other) const;
|
|
WVCDM_DEFINE_EQ_OPERATORS(SystemFallbackInfo);
|
|
|
|
private:
|
|
SystemState state_ = SystemState::kUnknown;
|
|
int64_t first_checked_time_ = 0;
|
|
int64_t backoff_start_time_ = 0;
|
|
int64_t backoff_duration_ = 0;
|
|
int64_t provisioning_time_ = 0;
|
|
}; // class SystemFallbackInfo
|
|
} // namespace okp
|
|
} // namespace wvcdm
|
|
#endif // WVCDM_CORE_OKP_SYSTEM_INFO_H_
|