xref: /aosp_15_r20/system/update_engine/common/hardware_interface.h (revision 5a9231315b4521097b8dc3750bc806fcafe0c72f)
1 //
2 // Copyright (C) 2013 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef UPDATE_ENGINE_COMMON_HARDWARE_INTERFACE_H_
18 #define UPDATE_ENGINE_COMMON_HARDWARE_INTERFACE_H_
19 
20 #include <stdint.h>
21 
22 #include <string>
23 #include <vector>
24 
25 #include <base/files/file_path.h>
26 #include <base/time/time.h>
27 
28 #include "update_engine/common/error_code.h"
29 
30 namespace chromeos_update_engine {
31 
32 // The hardware interface allows access to the crossystem exposed properties,
33 // such as the firmware version, hwid, verified boot mode.
34 // These stateless functions are tied together in this interface to facilitate
35 // unit testing.
36 class HardwareInterface {
37  public:
~HardwareInterface()38   virtual ~HardwareInterface() {}
39 
40   // Returns whether this is an official build. Official build means that the
41   // server maintains and updates the build, so update_engine should run and
42   // periodically check for updates.
43   virtual bool IsOfficialBuild() const = 0;
44 
45   // Returns true if the boot mode is normal or if it's unable to
46   // determine the boot mode. Returns false if the boot mode is
47   // developer. A dev-mode boot will allow the user to access developer-only
48   // features.
49   virtual bool IsNormalBootMode() const = 0;
50 
51   // Returns whether the developer features are enabled.
52   virtual bool AreDevFeaturesEnabled() const = 0;
53 
54   // Returns whether the device has an OOBE flow that the user must go through
55   // before getting non-critical updates. Use IsOOBEComplete() to determine if
56   // that flow is complete.
57   virtual bool IsOOBEEnabled() const = 0;
58 
59   // Returns true if the OOBE process has been completed and EULA accepted,
60   // False otherwise. If True is returned, and |out_time_of_oobe| isn't null,
61   // the time-stamp of when OOBE happened is stored at |out_time_of_oobe|.
62   virtual bool IsOOBEComplete(base::Time* out_time_of_oobe) const = 0;
63 
64   // Returns the HWID or an empty string on error.
65   virtual std::string GetHardwareClass() const = 0;
66 
67   // Returns the OEM device requisition or an empty string if the system does
68   // not have a requisition, or if not running Chrome OS.
69   virtual std::string GetDeviceRequisition() const = 0;
70 
71   // Returns the minimum kernel key version that verified boot on Chrome OS
72   // will allow to boot. This is the value of crossystem tpm_kernver. Returns
73   // -1 on error, or if not running on Chrome OS.
74   virtual int GetMinKernelKeyVersion() const = 0;
75 
76   // Returns the minimum firmware key version that verified boot on Chrome OS
77   // will allow to boot. This is the value of crossystem tpm_fwver. Returns
78   // -1 on error, or if not running on Chrome OS.
79   virtual int GetMinFirmwareKeyVersion() const = 0;
80 
81   // Returns the maximum firmware key version that verified boot should roll
82   // forward to. This is the value of crossystem firmware_max_rollforward.
83   // Returns -1 on error, if this board does not yet support this value, or
84   // if not running on Chrome OS.
85   virtual int GetMaxFirmwareKeyRollforward() const = 0;
86 
87   // Sets the maximum firmware key version that verified boot should roll
88   // forward to. This is the value of crossystem firmware_max_rollforward.
89   // This value is not available on all Chrome OS devices.
90   virtual bool SetMaxFirmwareKeyRollforward(int firmware_max_rollforward) = 0;
91 
92   // Sets the maximum kernel key version that verified boot should roll
93   // forward to. This is the value of crossystem kernel_max_rollforward.
94   // Returns false if the value cannot be set, or if not running on Chrome OS.
95   virtual bool SetMaxKernelKeyRollforward(int kernel_max_rollforward) = 0;
96 
97   // Returns the powerwash_count from the stateful. If the file is not found
98   // or is invalid, returns -1. Brand new machines out of the factory or after
99   // recovery don't have this value set.
100   virtual int GetPowerwashCount() const = 0;
101 
102   // Signals that a powerwash (stateful partition wipe) should be performed
103   // after reboot.
104   virtual bool SchedulePowerwash() = 0;
105 
106   // Cancel the powerwash operation scheduled to be performed on next boot.
107   virtual bool CancelPowerwash() = 0;
108 
109   // Store in |path| the path to a non-volatile directory (persisted across
110   // reboots) available for this daemon. In case of an error, such as no
111   // directory available, returns false.
112   virtual bool GetNonVolatileDirectory(base::FilePath* path) const = 0;
113 
114   // Store in |path| the path to a non-volatile directory persisted across
115   // powerwash cycles. In case of an error, such as no directory available,
116   // returns false.
117   virtual bool GetPowerwashSafeDirectory(base::FilePath* path) const = 0;
118 
119   // Returns the timestamp of the current OS build.
120   virtual int64_t GetBuildTimestamp() const = 0;
121 
122   // Returns true if the current OS build allows installing the payload with an
123   // older timestamp.
124   virtual bool AllowDowngrade() const = 0;
125 
126   // Returns whether the first active ping was sent to Omaha at some point, and
127   // that the value is persisted across recovery (and powerwash) once set with
128   // |SetFirstActiveOmahaPingSent()|.
129   virtual bool GetFirstActiveOmahaPingSent() const = 0;
130 
131   // Persist the fact that first active ping was sent to omaha and returns false
132   // if failed to persist it.
133   virtual bool SetFirstActiveOmahaPingSent() = 0;
134 
135   // If |warm_reset| is true, sets the warm reset to indicate a warm reset is
136   // needed on the next reboot. Otherwise, clears the flag.
137   virtual void SetWarmReset(bool warm_reset) = 0;
138 
139   // If not reset, sets the vbmeta digest of the inactive slot as a sysprop.
140   // Otherwise, clears the sysprop.
141   virtual void SetVbmetaDigestForInactiveSlot(bool reset) = 0;
142 
143   // Return the version/timestamp for partition `partition_name`.
144   // Don't make any assumption about the formatting of returned string.
145   // Only used for logging/debugging purposes.
146   virtual std::string GetVersionForLogging(
147       const std::string& partition_name) const = 0;
148 
149   // Return true if and only if `new_version` is "newer" than the
150   // version number of partition `partition_name`. The notion of
151   // "newer" is defined by this function. Caller should not make
152   // any assumption about the underlying logic.
153   // Return:
154   // - kSuccess if update is valid.
155   // - kPayloadTimestampError if downgrade is detected
156   // - kDownloadManifestParseError if |new_version| has an incorrect format
157   // - Other error values if the source of error is known, or kError for
158   //   a generic error on the device.
159   virtual ErrorCode IsPartitionUpdateValid(
160       const std::string& partition_name,
161       const std::string& new_version) const = 0;
162 
163   virtual const char* GetPartitionMountOptions(
164       const std::string& partition_name) const = 0;
165 };
166 
167 }  // namespace chromeos_update_engine
168 
169 #endif  // UPDATE_ENGINE_COMMON_HARDWARE_INTERFACE_H_
170