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_FAKE_HARDWARE_H_ |
| 18 | #define UPDATE_ENGINE_COMMON_FAKE_HARDWARE_H_ |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 19 | |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 20 | #include <map> |
Alex Deymo | df632d1 | 2014-04-29 20:04:36 -0700 | [diff] [blame] | 21 | #include <string> |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 22 | |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 23 | #include <base/time/time.h> |
| 24 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 25 | #include "update_engine/common/hardware_interface.h" |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 26 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 27 | namespace chromeos_update_engine { |
| 28 | |
| 29 | // Implements a fake hardware interface used for testing. |
| 30 | class FakeHardware : public HardwareInterface { |
| 31 | public: |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 32 | // Value used to signal that the powerwash_count file is not present. When |
| 33 | // this value is used in SetPowerwashCount(), GetPowerwashCount() will return |
| 34 | // false. |
| 35 | static const int kPowerwashCountNotSet = -1; |
| 36 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 37 | FakeHardware() = default; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 38 | |
| 39 | // HardwareInterface methods. |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 40 | bool IsOfficialBuild() const override { return is_official_build_; } |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 41 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 42 | bool IsNormalBootMode() const override { return is_normal_boot_mode_; } |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 43 | |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 44 | bool AreDevFeaturesEnabled() const override { |
| 45 | return are_dev_features_enabled_; |
| 46 | } |
| 47 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 48 | bool IsOOBEEnabled() const override { return is_oobe_enabled_; } |
| 49 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 50 | bool IsOOBEComplete(base::Time* out_time_of_oobe) const override { |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 51 | if (out_time_of_oobe != nullptr) |
| 52 | *out_time_of_oobe = oobe_timestamp_; |
| 53 | return is_oobe_complete_; |
| 54 | } |
| 55 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 56 | std::string GetHardwareClass() const override { return hardware_class_; } |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 57 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 58 | std::string GetFirmwareVersion() const override { return firmware_version_; } |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 59 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 60 | std::string GetECVersion() const override { return ec_version_; } |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 61 | |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 62 | int GetPowerwashCount() const override { return powerwash_count_; } |
| 63 | |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 64 | bool SchedulePowerwash() override { |
| 65 | powerwash_scheduled_ = true; |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | bool CancelPowerwash() override { |
| 70 | powerwash_scheduled_ = false; |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | bool IsPowerwashScheduled() { return powerwash_scheduled_; } |
| 75 | |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 76 | bool GetNonVolatileDirectory(base::FilePath* path) const override { |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | bool GetPowerwashSafeDirectory(base::FilePath* path) const override { |
| 81 | return false; |
| 82 | } |
| 83 | |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame^] | 84 | bool GetFirstActiveOmahaPingSent() const override { |
| 85 | return first_active_omaha_ping_sent_; |
| 86 | } |
| 87 | |
| 88 | void SetFirstActiveOmahaPingSent() override { |
| 89 | first_active_omaha_ping_sent_ = true; |
| 90 | } |
| 91 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 92 | // Setters |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 93 | void SetIsOfficialBuild(bool is_official_build) { |
| 94 | is_official_build_ = is_official_build; |
| 95 | } |
| 96 | |
| 97 | void SetIsNormalBootMode(bool is_normal_boot_mode) { |
| 98 | is_normal_boot_mode_ = is_normal_boot_mode; |
| 99 | } |
| 100 | |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 101 | void SetAreDevFeaturesEnabled(bool are_dev_features_enabled) { |
| 102 | are_dev_features_enabled_ = are_dev_features_enabled; |
| 103 | } |
| 104 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 105 | // Sets the SetIsOOBEEnabled to |is_oobe_enabled|. |
| 106 | void SetIsOOBEEnabled(bool is_oobe_enabled) { |
| 107 | is_oobe_enabled_ = is_oobe_enabled; |
| 108 | } |
| 109 | |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 110 | // Sets the IsOOBEComplete to True with the given timestamp. |
| 111 | void SetIsOOBEComplete(base::Time oobe_timestamp) { |
| 112 | is_oobe_complete_ = true; |
| 113 | oobe_timestamp_ = oobe_timestamp; |
| 114 | } |
| 115 | |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 116 | void UnsetIsOOBEComplete() { |
| 117 | is_oobe_complete_ = false; |
| 118 | } |
| 119 | |
Chih-Hung Hsieh | 5c6bb1d | 2016-07-27 13:33:15 -0700 | [diff] [blame] | 120 | void SetHardwareClass(const std::string& hardware_class) { |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 121 | hardware_class_ = hardware_class; |
| 122 | } |
| 123 | |
Chih-Hung Hsieh | 5c6bb1d | 2016-07-27 13:33:15 -0700 | [diff] [blame] | 124 | void SetFirmwareVersion(const std::string& firmware_version) { |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 125 | firmware_version_ = firmware_version; |
| 126 | } |
| 127 | |
Chih-Hung Hsieh | 5c6bb1d | 2016-07-27 13:33:15 -0700 | [diff] [blame] | 128 | void SetECVersion(const std::string& ec_version) { |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 129 | ec_version_ = ec_version; |
| 130 | } |
| 131 | |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 132 | void SetPowerwashCount(int powerwash_count) { |
| 133 | powerwash_count_ = powerwash_count; |
| 134 | } |
| 135 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 136 | private: |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 137 | bool is_official_build_{true}; |
| 138 | bool is_normal_boot_mode_{true}; |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 139 | bool are_dev_features_enabled_{false}; |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 140 | bool is_oobe_enabled_{true}; |
| 141 | bool is_oobe_complete_{true}; |
| 142 | base::Time oobe_timestamp_{base::Time::FromTimeT(1169280000)}; // Jan 20, 2007 |
| 143 | std::string hardware_class_{"Fake HWID BLAH-1234"}; |
| 144 | std::string firmware_version_{"Fake Firmware v1.0.1"}; |
| 145 | std::string ec_version_{"Fake EC v1.0a"}; |
| 146 | int powerwash_count_{kPowerwashCountNotSet}; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 147 | bool powerwash_scheduled_{false}; |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame^] | 148 | bool first_active_omaha_ping_sent_{false}; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 149 | |
| 150 | DISALLOW_COPY_AND_ASSIGN(FakeHardware); |
| 151 | }; |
| 152 | |
| 153 | } // namespace chromeos_update_engine |
| 154 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 155 | #endif // UPDATE_ENGINE_COMMON_FAKE_HARDWARE_H_ |