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