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 namespace chromeos_update_engine { 29 30 // The hardware interface allows access to the crossystem exposed properties, 31 // such as the firmware version, hwid, verified boot mode. 32 // These stateless functions are tied together in this interface to facilitate 33 // unit testing. 34 class HardwareInterface { 35 public: ~HardwareInterface()36 virtual ~HardwareInterface() {} 37 38 // Returns whether this is an official build. Official build means that the 39 // server maintains and updates the build, so update_engine should run and 40 // periodically check for updates. 41 virtual bool IsOfficialBuild() const = 0; 42 43 // Returns true if the boot mode is normal or if it's unable to 44 // determine the boot mode. Returns false if the boot mode is 45 // developer. A dev-mode boot will allow the user to access developer-only 46 // features. 47 virtual bool IsNormalBootMode() const = 0; 48 49 // Returns whether the developer features are enabled. 50 virtual bool AreDevFeaturesEnabled() const = 0; 51 52 // Returns whether the device has an OOBE flow that the user must go through 53 // before getting non-critical updates. Use IsOOBEComplete() to determine if 54 // that flow is complete. 55 virtual bool IsOOBEEnabled() const = 0; 56 57 // Returns true if the OOBE process has been completed and EULA accepted, 58 // False otherwise. If True is returned, and |out_time_of_oobe| isn't null, 59 // the time-stamp of when OOBE happened is stored at |out_time_of_oobe|. 60 virtual bool IsOOBEComplete(base::Time* out_time_of_oobe) const = 0; 61 62 // Returns the HWID or an empty string on error. 63 virtual std::string GetHardwareClass() const = 0; 64 65 // Returns the firmware version or an empty string if the system is 66 // not running chrome os firmware. 67 virtual std::string GetFirmwareVersion() const = 0; 68 69 // Returns the ec version or an empty string if the system is not 70 // running a custom chrome os ec. 71 virtual std::string GetECVersion() const = 0; 72 73 // Returns the minimum kernel key version that verified boot on Chrome OS 74 // will allow to boot. This is the value of crossystem tpm_kernver. Returns 75 // -1 on error, or if not running on Chrome OS. 76 virtual int GetMinKernelKeyVersion() const = 0; 77 78 // Returns the minimum firmware key version that verified boot on Chrome OS 79 // will allow to boot. This is the value of crossystem tpm_fwver. Returns 80 // -1 on error, or if not running on Chrome OS. 81 virtual int GetMinFirmwareKeyVersion() const = 0; 82 83 // Returns the maximum firmware key version that verified boot should roll 84 // forward to. This is the value of crossystem firmware_max_rollforward. 85 // Returns -1 on error, if this board does not yet support this value, or 86 // if not running on Chrome OS. 87 virtual int GetMaxFirmwareKeyRollforward() const = 0; 88 89 // Sets the maximum firmware key version that verified boot should roll 90 // forward to. This is the value of crossystem firmware_max_rollforward. 91 // This value is not available on all Chrome OS devices. 92 virtual bool SetMaxFirmwareKeyRollforward(int firmware_max_rollforward) = 0; 93 94 // Sets the maximum kernel key version that verified boot should roll 95 // forward to. This is the value of crossystem kernel_max_rollforward. 96 // Returns false if the value cannot be set, or if not running on Chrome OS. 97 virtual bool SetMaxKernelKeyRollforward(int kernel_max_rollforward) = 0; 98 99 // Returns the powerwash_count from the stateful. If the file is not found 100 // or is invalid, returns -1. Brand new machines out of the factory or after 101 // recovery don't have this value set. 102 virtual int GetPowerwashCount() const = 0; 103 104 // Signals that a powerwash (stateful partition wipe) should be performed 105 // after reboot. If |is_rollback| is true additional state is preserved 106 // during shutdown that can be restored after the powerwash. 107 virtual bool SchedulePowerwash(bool is_rollback) = 0; 108 109 // Cancel the powerwash operation scheduled to be performed on next boot. 110 virtual bool CancelPowerwash() = 0; 111 112 // Store in |path| the path to a non-volatile directory (persisted across 113 // reboots) available for this daemon. In case of an error, such as no 114 // directory available, returns false. 115 virtual bool GetNonVolatileDirectory(base::FilePath* path) const = 0; 116 117 // Store in |path| the path to a non-volatile directory persisted across 118 // powerwash cycles. In case of an error, such as no directory available, 119 // returns false. 120 virtual bool GetPowerwashSafeDirectory(base::FilePath* path) const = 0; 121 122 // Returns the timestamp of the current OS build. 123 virtual int64_t GetBuildTimestamp() const = 0; 124 125 // Returns whether the first active ping was sent to Omaha at some point, and 126 // that the value is persisted across recovery (and powerwash) once set with 127 // |SetFirstActiveOmahaPingSent()|. 128 virtual bool GetFirstActiveOmahaPingSent() const = 0; 129 130 // Persist the fact that first active ping was sent to omaha and returns false 131 // if failed to persist it. 132 virtual bool SetFirstActiveOmahaPingSent() = 0; 133 }; 134 135 } // namespace chromeos_update_engine 136 137 #endif // UPDATE_ENGINE_COMMON_HARDWARE_INTERFACE_H_ 138