File: statistics_provider.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (225 lines) | stat: -rw-r--r-- 8,823 bytes parent folder | download | duplicates (5)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_SYSTEM_STATISTICS_PROVIDER_H_
#define CHROMEOS_ASH_COMPONENTS_SYSTEM_STATISTICS_PROVIDER_H_

#include <optional>
#include <string_view>

#include "base/component_export.h"
#include "base/functional/callback.h"

namespace ash::system {

// Activation date key.
inline constexpr char kActivateDateKey[] = "ActivateDate";

// The key that will be present in VPD if the device was enrolled in a domain
// that blocks dev mode.
inline constexpr char kBlockDevModeKey[] = "block_devmode";
// The key that will be present in VPD if the device ever was enrolled.
inline constexpr char kCheckEnrollmentKey[] = "check_enrollment";

// The key and values present in VPD to indicate if RLZ ping should be sent.
inline constexpr char kShouldSendRlzPingKey[] = "should_send_rlz_ping";
inline constexpr char kShouldSendRlzPingValueFalse[] = "0";
inline constexpr char kShouldSendRlzPingValueTrue[] = "1";

// The key present in VPD that indicates the date after which the RLZ ping is
// allowed to be sent. It is in the format of "yyyy-mm-dd".
inline constexpr char kRlzEmbargoEndDateKey[] = "rlz_embargo_end_date";

// Customization ID key.
inline constexpr char kCustomizationIdKey[] = "customization_id";

// Developer switch value.
inline constexpr char kDevSwitchBootKey[] = "devsw_boot";
inline constexpr char kDevSwitchBootValueDev[] = "1";
inline constexpr char kDevSwitchBootValueVerified[] = "0";

// Dock MAC address key.
inline constexpr char kDockMacAddressKey[] = "dock_mac";

// Ethernet MAC address key.
inline constexpr char kEthernetMacAddressKey[] = "ethernet_mac0";

// Firmware write protect switch value.
inline constexpr char kFirmwareWriteProtectCurrentKey[] = "wpsw_cur";
inline constexpr char kFirmwareWriteProtectCurrentValueOn[] = "1";
inline constexpr char kFirmwareWriteProtectCurrentValueOff[] = "0";

// Firmware type and associated values. The values are from crossystem output
// for the mainfw_type key. Normal and developer correspond to Chrome OS
// firmware with MP and developer keys respectively, nonchrome indicates the
// machine doesn't run on Chrome OS firmware. See crossystem source for more
// details.
inline constexpr char kFirmwareTypeKey[] = "mainfw_type";
inline constexpr char kFirmwareTypeValueDeveloper[] = "developer";
inline constexpr char kFirmwareTypeValueNonchrome[] = "nonchrome";
inline constexpr char kFirmwareTypeValueNormal[] = "normal";

// HWID key.
inline constexpr char kHardwareClassKey[] = "hardware_class";

// Key/values reporting if Chrome OS is running in a VM or not. These values are
// read from crossystem output. See crossystem source for VM detection logic.
inline constexpr char kIsVmKey[] = "is_vm";
inline constexpr char kIsVmValueFalse[] = "0";
inline constexpr char kIsVmValueTrue[] = "1";

// Key/values reporting if ChromeOS is running in debug mode or not. These
// values are read from crossystem output. See crossystem source for cros_debug
// detection logic.
inline constexpr char kIsCrosDebugKey[] = "is_cros_debug";
inline constexpr char kIsCrosDebugValueFalse[] = "0";
inline constexpr char kIsCrosDebugValueTrue[] = "1";

// Manufacture date key.
inline constexpr char kManufactureDateKey[] = "mfg_date";

// OEM customization flag that permits exiting enterprise enrollment flow in
// OOBE when 'oem_enterprise_managed' flag is set.
inline constexpr char kOemCanExitEnterpriseEnrollmentKey[] =
    "oem_can_exit_enrollment";

// OEM customization directive that specified intended device purpose.
inline constexpr char kOemDeviceRequisitionKey[] = "oem_device_requisition";

// OEM customization flag that enforces enterprise enrollment flow in OOBE.
inline constexpr char kOemIsEnterpriseManagedKey[] = "oem_enterprise_managed";

// OEM customization flag that specifies if OOBE flow should be enhanced for
// keyboard driven control.
inline constexpr char kOemKeyboardDrivenOobeKey[] = "oem_keyboard_driven_oobe";

// Offer coupon code key.
inline constexpr char kOffersCouponCodeKey[] = "ubind_attribute";

// Offer group key.
inline constexpr char kOffersGroupCodeKey[] = "gbind_attribute";

// Release Brand Code key.
inline constexpr char kRlzBrandCodeKey[] = "rlz_brand_code";

// Regional data
inline constexpr char kRegionKey[] = "region";
inline constexpr char kInitialLocaleKey[] = "initial_locale";
inline constexpr char kInitialTimezoneKey[] = "initial_timezone";
inline constexpr char kKeyboardLayoutKey[] = "keyboard_layout";
inline constexpr char kKeyboardMechanicalLayoutKey[] =
    "keyboard_mechanical_layout";

// The key that will be present in RO VPD to indicate what identifier is used
// for attestation-based registration of a device.
inline constexpr char kAttestedDeviceIdKey[] = "attested_device_id";

// Serial number key (legacy VPD devices). In most cases,
// GetEnterpriseMachineID() is the appropriate way to obtain the serial number.
inline constexpr char kLegacySerialNumberKey[] = "Product_S/N";

// Serial number key (VPD v2+ devices, Samsung: caroline and later). In most
// cases, GetEnterpriseMachineID() is the appropriate way to obtain the serial
// number.
inline constexpr char kSerialNumberKey[] = "serial_number";

// Serial number key for Flex devices. In most cases, GetEnterpriseMachineID()
// is the appropriate way to obtain the serial number.
inline constexpr char kFlexIdKey[] = "flex_id";

// Display Profiles key.
inline constexpr char kDisplayProfilesKey[] = "display_profiles";

// Machine model and oem names.
inline constexpr char kMachineModelName[] = "model_name";
inline constexpr char kMachineOemName[] = "oem_name";

// This interface provides access to Chrome OS statistics.
class COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_SYSTEM) StatisticsProvider {
 public:
  // Represents the status of the VPD statistics source.
  enum class VpdStatus {
    kUnknown = 0,
    kValid = 1,
    kRoInvalid = 2,
    kRwInvalid = 3,
    kInvalid = 4
  };

  enum class FlagValue {
    kUnset,
    kTrue,
    kFalse,
  };

  enum class LoadingState {
    kNotStarted,
    kStarted,
    kFinished,
  };

  // Converts `value` to bool. Returns corresponding true or false, or
  // `default_value` if unset.
  static bool FlagValueToBool(FlagValue value, bool default_value);

  // Starts loading the machine statistics.
  virtual void StartLoadingMachineStatistics(bool load_oem_manifest) = 0;

  // Schedules `callback` on the current sequence when machine statistics are
  // loaded. That can be immediately if machine statistics are already loaded.
  virtual void ScheduleOnMachineStatisticsLoaded(
      base::OnceClosure callback) = 0;

  // `GetMachineStatistic`, `GetMachineFlag` and `GetMachineID` will block if
  // called before statistics have been loaded. To avoid this, call from a
  // callback passed to ScheduleOnMachineStatisticsLoaded(). These methods are
  // safe to call on any sequence. `StartLoadingMachineStatistics` must be
  // called before these methods.

  // Returns statistic value if the named machine statistic (e.g.
  // "hardware_class") is found. Returns nullopt otherwise.
  // Once statistics are loaded, returned std::string_view will never become
  // dangling as statistics are loaded only once and `StatisticsProvider` is
  // a singleton.
  virtual std::optional<std::string_view> GetMachineStatistic(
      std::string_view name) = 0;

  // Similar to `GetMachineStatistic` for boolean flags. As optional and bool do
  // not work safely together, returns custom tribool value.
  virtual FlagValue GetMachineFlag(std::string_view name) = 0;

  // Returns the machine serial number after examining a set of well-known
  // keys. In case no serial is found nullopt is returned.
  // Caveat: On older Samsung devices, the last letter is omitted from the
  // serial number for historical reasons. This is fine.
  std::optional<std::string_view> GetMachineID();

  // Cancels any pending file operations.
  virtual void Shutdown() = 0;

  // Returns true if the machine is a VM.
  virtual bool IsRunningOnVm() = 0;

  // Returns true if the ChromeOS machine is in debug mode.
  virtual bool IsCrosDebugMode() = 0;

  // Returns the status of RO_VPD and RW_VPD partitions.
  virtual VpdStatus GetVpdStatus() const = 0;

  // Get the current state of loading VPD data.
  virtual LoadingState GetLoadingState() const = 0;

  // Get the Singleton instance.
  static StatisticsProvider* GetInstance();

  // Set the instance returned by GetInstance() for testing.
  static void SetTestProvider(StatisticsProvider* test_provider);

 protected:
  virtual ~StatisticsProvider() = default;
};

}  // namespace ash::system

#endif  // CHROMEOS_ASH_COMPONENTS_SYSTEM_STATISTICS_PROVIDER_H_