blob: a384597564b787eeb551062e325db6d5519d1ce4 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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 Deymo42432912013-07-12 20:21:15 -070016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#ifndef UPDATE_ENGINE_COMMON_FAKE_HARDWARE_H_
18#define UPDATE_ENGINE_COMMON_FAKE_HARDWARE_H_
Alex Deymo42432912013-07-12 20:21:15 -070019
Don Garrett83692e42013-11-08 10:11:30 -080020#include <map>
Alex Deymodf632d12014-04-29 20:04:36 -070021#include <string>
Don Garrett83692e42013-11-08 10:11:30 -080022
Alex Deymobccbc382014-04-03 13:38:55 -070023#include <base/time/time.h>
24
Alex Deymo39910dc2015-11-09 17:04:30 -080025#include "update_engine/common/hardware_interface.h"
Alex Deymo42432912013-07-12 20:21:15 -070026
Alex Deymo42432912013-07-12 20:21:15 -070027namespace chromeos_update_engine {
28
29// Implements a fake hardware interface used for testing.
30class FakeHardware : public HardwareInterface {
31 public:
Alex Deymoebbe7ef2014-10-30 13:02:49 -070032 // 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 Deymo46a9aae2016-05-04 20:20:11 -070037 FakeHardware() = default;
Alex Deymo42432912013-07-12 20:21:15 -070038
39 // HardwareInterface methods.
Alex Vakulenko157fe302014-08-11 15:59:58 -070040 bool IsOfficialBuild() const override { return is_official_build_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080041
Alex Vakulenko157fe302014-08-11 15:59:58 -070042 bool IsNormalBootMode() const override { return is_normal_boot_mode_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080043
Sen Jiange67bb5b2016-06-20 15:53:56 -070044 bool AreDevFeaturesEnabled() const override {
45 return are_dev_features_enabled_;
46 }
47
Alex Deymo46a9aae2016-05-04 20:20:11 -070048 bool IsOOBEEnabled() const override { return is_oobe_enabled_; }
49
Alex Vakulenko157fe302014-08-11 15:59:58 -070050 bool IsOOBEComplete(base::Time* out_time_of_oobe) const override {
Alex Deymobccbc382014-04-03 13:38:55 -070051 if (out_time_of_oobe != nullptr)
52 *out_time_of_oobe = oobe_timestamp_;
53 return is_oobe_complete_;
54 }
55
Alex Vakulenko157fe302014-08-11 15:59:58 -070056 std::string GetHardwareClass() const override { return hardware_class_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080057
Alex Vakulenko157fe302014-08-11 15:59:58 -070058 std::string GetFirmwareVersion() const override { return firmware_version_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080059
Alex Vakulenko157fe302014-08-11 15:59:58 -070060 std::string GetECVersion() const override { return ec_version_; }
Alex Deymo42432912013-07-12 20:21:15 -070061
Alex Deymoebbe7ef2014-10-30 13:02:49 -070062 int GetPowerwashCount() const override { return powerwash_count_; }
63
Alex Deymofb905d92016-06-03 19:26:58 -070064 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 Deymodd132f32015-09-14 19:12:07 -070076 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
Sen Jiang5011df62017-06-28 17:13:19 -070084 int64_t GetBuildTimestamp() const override { return build_timestamp_; }
85
Alex Deymo42432912013-07-12 20:21:15 -070086 // Setters
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070087 void SetIsOfficialBuild(bool is_official_build) {
88 is_official_build_ = is_official_build;
89 }
90
91 void SetIsNormalBootMode(bool is_normal_boot_mode) {
92 is_normal_boot_mode_ = is_normal_boot_mode;
93 }
94
Sen Jiange67bb5b2016-06-20 15:53:56 -070095 void SetAreDevFeaturesEnabled(bool are_dev_features_enabled) {
96 are_dev_features_enabled_ = are_dev_features_enabled;
97 }
98
Alex Deymo46a9aae2016-05-04 20:20:11 -070099 // Sets the SetIsOOBEEnabled to |is_oobe_enabled|.
100 void SetIsOOBEEnabled(bool is_oobe_enabled) {
101 is_oobe_enabled_ = is_oobe_enabled;
102 }
103
Alex Deymobccbc382014-04-03 13:38:55 -0700104 // Sets the IsOOBEComplete to True with the given timestamp.
105 void SetIsOOBEComplete(base::Time oobe_timestamp) {
106 is_oobe_complete_ = true;
107 oobe_timestamp_ = oobe_timestamp;
108 }
109
Alex Deymobccbc382014-04-03 13:38:55 -0700110 void UnsetIsOOBEComplete() {
111 is_oobe_complete_ = false;
112 }
113
Chih-Hung Hsieh5c6bb1d2016-07-27 13:33:15 -0700114 void SetHardwareClass(const std::string& hardware_class) {
J. Richard Barnette522d36f2013-10-28 17:22:12 -0700115 hardware_class_ = hardware_class;
116 }
117
Chih-Hung Hsieh5c6bb1d2016-07-27 13:33:15 -0700118 void SetFirmwareVersion(const std::string& firmware_version) {
J. Richard Barnette522d36f2013-10-28 17:22:12 -0700119 firmware_version_ = firmware_version;
120 }
121
Chih-Hung Hsieh5c6bb1d2016-07-27 13:33:15 -0700122 void SetECVersion(const std::string& ec_version) {
J. Richard Barnette522d36f2013-10-28 17:22:12 -0700123 ec_version_ = ec_version;
124 }
125
Alex Deymoebbe7ef2014-10-30 13:02:49 -0700126 void SetPowerwashCount(int powerwash_count) {
127 powerwash_count_ = powerwash_count;
128 }
129
Sen Jiang5011df62017-06-28 17:13:19 -0700130 void SetBuildTimestamp(int64_t build_timestamp) {
131 build_timestamp_ = build_timestamp;
132 }
133
Alex Deymo42432912013-07-12 20:21:15 -0700134 private:
Alex Deymo46a9aae2016-05-04 20:20:11 -0700135 bool is_official_build_{true};
136 bool is_normal_boot_mode_{true};
Sen Jiange67bb5b2016-06-20 15:53:56 -0700137 bool are_dev_features_enabled_{false};
Alex Deymo46a9aae2016-05-04 20:20:11 -0700138 bool is_oobe_enabled_{true};
139 bool is_oobe_complete_{true};
140 base::Time oobe_timestamp_{base::Time::FromTimeT(1169280000)}; // Jan 20, 2007
141 std::string hardware_class_{"Fake HWID BLAH-1234"};
142 std::string firmware_version_{"Fake Firmware v1.0.1"};
143 std::string ec_version_{"Fake EC v1.0a"};
144 int powerwash_count_{kPowerwashCountNotSet};
Alex Deymofb905d92016-06-03 19:26:58 -0700145 bool powerwash_scheduled_{false};
Sen Jiang5011df62017-06-28 17:13:19 -0700146 int64_t build_timestamp_{0};
Alex Deymo42432912013-07-12 20:21:15 -0700147
148 DISALLOW_COPY_AND_ASSIGN(FakeHardware);
149};
150
151} // namespace chromeos_update_engine
152
Alex Deymo39910dc2015-11-09 17:04:30 -0800153#endif // UPDATE_ENGINE_COMMON_FAKE_HARDWARE_H_