-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflex_hwis_check.h
79 lines (62 loc) · 2.58 KB
/
flex_hwis_check.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2023 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLEX_HWIS_FLEX_HWIS_CHECK_H_
#define FLEX_HWIS_FLEX_HWIS_CHECK_H_
#include <optional>
#include <string>
#include <base/files/file_path.h>
#include <policy/device_policy.h>
#include <policy/libpolicy.h>
namespace flex_hwis {
class PermissionInfo {
public:
// If the device is managed, the value of this field is true.
bool managed = false;
// If the device policy is successfully loaded to this device,
// the value of this field is true.
bool loaded = false;
// The value of this field is true if all required device management
// policies are enabled in managed devices, or consent has been granted
// through OOBE in unmanaged devices.
bool permission = false;
};
// This class is for processing management checking items utilized in HWIS.
class FlexHwisCheck {
public:
explicit FlexHwisCheck(const base::FilePath& base_path,
policy::PolicyProvider& provider);
// Verify if the device is authorized to send hardware data to the server.
// In the managed case, management policies should be checked. In the
// current version, there is no fine-grained control. If one of the policies
// is disabled, hardware data will not be uploaded. In the unmanaged case,
// hardware_data_usage_enabled should be checked.
PermissionInfo CheckPermission();
// Check if the HWIS has run in the last 24 hours.
bool HasRunRecently();
// If the hardware data is successfully sent to the server, the new
// timestamp will be stored.
void RecordSendTime();
// Retrieve a device name.
std::optional<std::string> GetDeviceName() const;
// Delete the file that stores the device name.
void DeleteDeviceName();
// Write a device name to the client side.
void SetDeviceName(const std::string_view name);
private:
// Extracts the HWIS info from the file at the file_path.
std::optional<std::string> ReadHwisFile(
const base::FilePath& file_path) const;
// Writes the HWIS information, such as device name or timestamp, to file_path
// and adds a newline.
bool WriteHwisFile(const base::FilePath& file_path,
const std::string_view content);
// Returns the file path that records the device name created by the
// HWIS server.
base::FilePath DeviceNamePath() const;
base::FilePath base_path_;
// The device policy provider, used to get device policy data.
policy::PolicyProvider& policy_provider_;
};
} // namespace flex_hwis
#endif // FLEX_HWIS_FLEX_HWIS_CHECK_H_