Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 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 | // |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 16 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_COMMON_HARDWARE_INTERFACE_H_ |
| 18 | #define UPDATE_ENGINE_COMMON_HARDWARE_INTERFACE_H_ |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 19 | |
Sen Jiang | 5011df6 | 2017-06-28 17:13:19 -0700 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 22 | #include <string> |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 23 | #include <vector> |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 24 | |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 25 | #include <base/files/file_path.h> |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 26 | #include <base/time/time.h> |
| 27 | |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 28 | #include "update_engine/common/error_code.h" |
| 29 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 30 | namespace chromeos_update_engine { |
| 31 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 32 | // The hardware interface allows access to the crossystem exposed properties, |
| 33 | // such as the firmware version, hwid, verified boot mode. |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 34 | // These stateless functions are tied together in this interface to facilitate |
| 35 | // unit testing. |
| 36 | class HardwareInterface { |
| 37 | public: |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 38 | virtual ~HardwareInterface() {} |
| 39 | |
Alex Deymo | 1c4e84a | 2015-09-22 16:58:10 -0700 | [diff] [blame] | 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. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 43 | virtual bool IsOfficialBuild() const = 0; |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 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 |
Alex Deymo | 1c4e84a | 2015-09-22 16:58:10 -0700 | [diff] [blame] | 47 | // developer. A dev-mode boot will allow the user to access developer-only |
| 48 | // features. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 49 | virtual bool IsNormalBootMode() const = 0; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 50 | |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 51 | // Returns whether the developer features are enabled. |
| 52 | virtual bool AreDevFeaturesEnabled() const = 0; |
| 53 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 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 | |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 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 | |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 64 | // Returns the HWID or an empty string on error. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 65 | virtual std::string GetHardwareClass() const = 0; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 66 | |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 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 | |
Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 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 | |
Marton Hunyady | 99ced78 | 2018-05-08 12:59:50 +0200 | [diff] [blame] | 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 | |
Zentaro Kavanagh | 8f6f243 | 2018-05-16 13:48:12 -0700 | [diff] [blame] | 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 | |
Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 92 | // Sets the maximum kernel key version that verified boot should roll |
Zentaro Kavanagh | 5d95615 | 2018-05-15 09:40:33 -0700 | [diff] [blame] | 93 | // forward to. This is the value of crossystem kernel_max_rollforward. |
Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 94 | // Returns false if the value cannot be set, or if not running on Chrome OS. |
Zentaro Kavanagh | 5d95615 | 2018-05-15 09:40:33 -0700 | [diff] [blame] | 95 | virtual bool SetMaxKernelKeyRollforward(int kernel_max_rollforward) = 0; |
Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 96 | |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 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; |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 101 | |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 102 | // Signals that a powerwash (stateful partition wipe) should be performed |
Zentaro Kavanagh | 28def4f | 2019-01-15 17:15:01 -0800 | [diff] [blame] | 103 | // after reboot. If |save_rollback_data| is true additional state is |
| 104 | // preserved during shutdown that can be restored after the powerwash. |
| 105 | virtual bool SchedulePowerwash(bool save_rollback_data) = 0; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 106 | |
| 107 | // Cancel the powerwash operation scheduled to be performed on next boot. |
| 108 | virtual bool CancelPowerwash() = 0; |
| 109 | |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 110 | // Store in |path| the path to a non-volatile directory (persisted across |
| 111 | // reboots) available for this daemon. In case of an error, such as no |
| 112 | // directory available, returns false. |
| 113 | virtual bool GetNonVolatileDirectory(base::FilePath* path) const = 0; |
| 114 | |
| 115 | // Store in |path| the path to a non-volatile directory persisted across |
| 116 | // powerwash cycles. In case of an error, such as no directory available, |
| 117 | // returns false. |
| 118 | virtual bool GetPowerwashSafeDirectory(base::FilePath* path) const = 0; |
Sen Jiang | 5011df6 | 2017-06-28 17:13:19 -0700 | [diff] [blame] | 119 | |
| 120 | // Returns the timestamp of the current OS build. |
| 121 | virtual int64_t GetBuildTimestamp() const = 0; |
Sen Jiang | 4490696 | 2018-01-08 17:39:04 -0800 | [diff] [blame] | 122 | |
Tianjie Xu | 4ad3af6 | 2019-10-30 11:59:45 -0700 | [diff] [blame] | 123 | // Returns true if the current OS build allows installing the payload with an |
| 124 | // older timestamp. |
| 125 | virtual bool AllowDowngrade() const = 0; |
| 126 | |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 127 | // Returns whether the first active ping was sent to Omaha at some point, and |
| 128 | // that the value is persisted across recovery (and powerwash) once set with |
| 129 | // |SetFirstActiveOmahaPingSent()|. |
| 130 | virtual bool GetFirstActiveOmahaPingSent() const = 0; |
| 131 | |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 132 | // Persist the fact that first active ping was sent to omaha and returns false |
| 133 | // if failed to persist it. |
| 134 | virtual bool SetFirstActiveOmahaPingSent() = 0; |
Tianjie Xu | d6aa91f | 2019-11-14 11:55:10 -0800 | [diff] [blame] | 135 | |
| 136 | // If |warm_reset| is true, sets the warm reset to indicate a warm reset is |
| 137 | // needed on the next reboot. Otherwise, clears the flag. |
| 138 | virtual void SetWarmReset(bool warm_reset) = 0; |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 139 | |
Tianjie | 838793d | 2021-01-14 22:05:13 -0800 | [diff] [blame] | 140 | // If not reset, sets the vbmeta digest of the inactive slot as a sysprop. |
| 141 | // Otherwise, clears the sysprop. |
| 142 | virtual void SetVbmetaDigestForInactiveSlot(bool reset) = 0; |
| 143 | |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 144 | // Return the version/timestamp for partition `partition_name`. |
| 145 | // Don't make any assumption about the formatting of returned string. |
| 146 | // Only used for logging/debugging purposes. |
| 147 | virtual std::string GetVersionForLogging( |
| 148 | const std::string& partition_name) const = 0; |
| 149 | |
| 150 | // Return true if and only if `new_version` is "newer" than the |
| 151 | // version number of partition `partition_name`. The notion of |
| 152 | // "newer" is defined by this function. Caller should not make |
| 153 | // any assumption about the underlying logic. |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 154 | // Return: |
| 155 | // - kSuccess if update is valid. |
| 156 | // - kPayloadTimestampError if downgrade is detected |
| 157 | // - kDownloadManifestParseError if |new_version| has an incorrect format |
| 158 | // - Other error values if the source of error is known, or kError for |
| 159 | // a generic error on the device. |
| 160 | virtual ErrorCode IsPartitionUpdateValid( |
| 161 | const std::string& partition_name, |
| 162 | const std::string& new_version) const = 0; |
Alex Light | 7361d27 | 2021-03-12 09:05:55 -0800 | [diff] [blame] | 163 | |
| 164 | virtual const char* GetPartitionMountOptions( |
| 165 | const std::string& partition_name) const = 0; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | } // namespace chromeos_update_engine |
| 169 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 170 | #endif // UPDATE_ENGINE_COMMON_HARDWARE_INTERFACE_H_ |