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 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_HARDWARE_INTERFACE_H_ |
| 18 | #define UPDATE_ENGINE_HARDWARE_INTERFACE_H_ |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 19 | |
| 20 | #include <string> |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 21 | #include <vector> |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 22 | |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 23 | #include <base/time/time.h> |
| 24 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 25 | namespace chromeos_update_engine { |
| 26 | |
| 27 | // The hardware interface allows access to the following parts of the system, |
| 28 | // closely related to the hardware: |
| 29 | // * crossystem exposed properties: firmware, hwid, etc. |
| 30 | // * Physical disk: partition booted from and partition name conversions. |
| 31 | // These stateless functions are tied together in this interface to facilitate |
| 32 | // unit testing. |
| 33 | class HardwareInterface { |
| 34 | public: |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 35 | virtual ~HardwareInterface() {} |
| 36 | |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 37 | // Returns the currently booted kernel partition. "/dev/sda2", for example. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 38 | virtual std::string BootKernelDevice() const = 0; |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 39 | |
| 40 | // Returns the currently booted rootfs partition. "/dev/sda3", for example. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 41 | virtual std::string BootDevice() const = 0; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 42 | |
Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 43 | // Return whether the BootDevice() is a removable device. |
| 44 | virtual bool IsBootDeviceRemovable() const = 0; |
| 45 | |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 46 | // Returns a list of all kernel partitions available (whether bootable or not) |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 47 | virtual std::vector<std::string> GetKernelDevices() const = 0; |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 48 | |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 49 | // Is the specified kernel partition currently bootable, based on GPT flags? |
| 50 | // Returns success. |
| 51 | virtual bool IsKernelBootable(const std::string& kernel_device, |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 52 | bool* bootable) const = 0; |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 53 | |
| 54 | // Mark the specified kernel partition unbootable in GPT flags. We mark |
| 55 | // the other kernel as bootable inside postinst, not inside the UE. |
| 56 | // Returns success. |
| 57 | virtual bool MarkKernelUnbootable(const std::string& kernel_device) = 0; |
| 58 | |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 59 | // Returns true if this is an official Chrome OS build, false otherwise. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 60 | virtual bool IsOfficialBuild() const = 0; |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 61 | |
| 62 | // Returns true if the boot mode is normal or if it's unable to |
| 63 | // determine the boot mode. Returns false if the boot mode is |
| 64 | // developer. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 65 | virtual bool IsNormalBootMode() const = 0; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 66 | |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 67 | // Returns true if the OOBE process has been completed and EULA accepted, |
| 68 | // False otherwise. If True is returned, and |out_time_of_oobe| isn't null, |
| 69 | // the time-stamp of when OOBE happened is stored at |out_time_of_oobe|. |
| 70 | virtual bool IsOOBEComplete(base::Time* out_time_of_oobe) const = 0; |
| 71 | |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 72 | // Returns the HWID or an empty string on error. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 73 | virtual std::string GetHardwareClass() const = 0; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 74 | |
| 75 | // Returns the firmware version or an empty string if the system is |
| 76 | // not running chrome os firmware. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 77 | virtual std::string GetFirmwareVersion() const = 0; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 78 | |
| 79 | // Returns the ec version or an empty string if the system is not |
| 80 | // running a custom chrome os ec. |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 81 | virtual std::string GetECVersion() const = 0; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 82 | |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 83 | // Returns the powerwash_count from the stateful. If the file is not found |
| 84 | // or is invalid, returns -1. Brand new machines out of the factory or after |
| 85 | // recovery don't have this value set. |
| 86 | virtual int GetPowerwashCount() const = 0; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | } // namespace chromeos_update_engine |
| 90 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 91 | #endif // UPDATE_ENGINE_HARDWARE_INTERFACE_H_ |