blob: 5d3da1ad15cd7d2da5e9c71ad13e5576b07ef569 [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
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_FAKE_HARDWARE_H_
18#define UPDATE_ENGINE_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>
22#include <vector>
Don Garrett83692e42013-11-08 10:11:30 -080023
Alex Deymobccbc382014-04-03 13:38:55 -070024#include <base/time/time.h>
25
Alex Deymo42432912013-07-12 20:21:15 -070026#include "update_engine/hardware_interface.h"
27
Alex Deymo42432912013-07-12 20:21:15 -070028namespace chromeos_update_engine {
29
30// Implements a fake hardware interface used for testing.
31class FakeHardware : public HardwareInterface {
32 public:
Alex Deymoebbe7ef2014-10-30 13:02:49 -070033 // Value used to signal that the powerwash_count file is not present. When
34 // this value is used in SetPowerwashCount(), GetPowerwashCount() will return
35 // false.
36 static const int kPowerwashCountNotSet = -1;
37
J. Richard Barnette4da2cc12013-10-28 16:11:10 -070038 FakeHardware()
Alex Deymo763e7db2015-08-27 21:08:08 -070039 : is_official_build_(true),
40 is_normal_boot_mode_(true),
41 is_oobe_complete_(false),
42 hardware_class_("Fake HWID BLAH-1234"),
43 firmware_version_("Fake Firmware v1.0.1"),
44 ec_version_("Fake EC v1.0a"),
45 powerwash_count_(kPowerwashCountNotSet) {}
Alex Deymo42432912013-07-12 20:21:15 -070046
47 // HardwareInterface methods.
Alex Vakulenko157fe302014-08-11 15:59:58 -070048 bool IsOfficialBuild() const override { return is_official_build_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080049
Alex Vakulenko157fe302014-08-11 15:59:58 -070050 bool IsNormalBootMode() const override { return is_normal_boot_mode_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080051
Alex Vakulenko157fe302014-08-11 15:59:58 -070052 bool IsOOBEComplete(base::Time* out_time_of_oobe) const override {
Alex Deymobccbc382014-04-03 13:38:55 -070053 if (out_time_of_oobe != nullptr)
54 *out_time_of_oobe = oobe_timestamp_;
55 return is_oobe_complete_;
56 }
57
Alex Vakulenko157fe302014-08-11 15:59:58 -070058 std::string GetHardwareClass() const override { return hardware_class_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080059
Alex Vakulenko157fe302014-08-11 15:59:58 -070060 std::string GetFirmwareVersion() const override { return firmware_version_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080061
Alex Vakulenko157fe302014-08-11 15:59:58 -070062 std::string GetECVersion() const override { return ec_version_; }
Alex Deymo42432912013-07-12 20:21:15 -070063
Alex Deymoebbe7ef2014-10-30 13:02:49 -070064 int GetPowerwashCount() const override { return powerwash_count_; }
65
Alex Deymo42432912013-07-12 20:21:15 -070066 // Setters
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070067 void SetIsOfficialBuild(bool is_official_build) {
68 is_official_build_ = is_official_build;
69 }
70
71 void SetIsNormalBootMode(bool is_normal_boot_mode) {
72 is_normal_boot_mode_ = is_normal_boot_mode;
73 }
74
Alex Deymobccbc382014-04-03 13:38:55 -070075 // Sets the IsOOBEComplete to True with the given timestamp.
76 void SetIsOOBEComplete(base::Time oobe_timestamp) {
77 is_oobe_complete_ = true;
78 oobe_timestamp_ = oobe_timestamp;
79 }
80
81 // Sets the IsOOBEComplete to False.
82 void UnsetIsOOBEComplete() {
83 is_oobe_complete_ = false;
84 }
85
J. Richard Barnette522d36f2013-10-28 17:22:12 -070086 void SetHardwareClass(std::string hardware_class) {
87 hardware_class_ = hardware_class;
88 }
89
90 void SetFirmwareVersion(std::string firmware_version) {
91 firmware_version_ = firmware_version;
92 }
93
94 void SetECVersion(std::string ec_version) {
95 ec_version_ = ec_version;
96 }
97
Alex Deymoebbe7ef2014-10-30 13:02:49 -070098 void SetPowerwashCount(int powerwash_count) {
99 powerwash_count_ = powerwash_count;
100 }
101
Alex Deymo42432912013-07-12 20:21:15 -0700102 private:
J. Richard Barnette056b0ab2013-10-29 15:24:56 -0700103 bool is_official_build_;
104 bool is_normal_boot_mode_;
Alex Deymobccbc382014-04-03 13:38:55 -0700105 bool is_oobe_complete_;
106 base::Time oobe_timestamp_;
J. Richard Barnette522d36f2013-10-28 17:22:12 -0700107 std::string hardware_class_;
108 std::string firmware_version_;
109 std::string ec_version_;
Alex Deymoebbe7ef2014-10-30 13:02:49 -0700110 int powerwash_count_;
Alex Deymo42432912013-07-12 20:21:15 -0700111
112 DISALLOW_COPY_AND_ASSIGN(FakeHardware);
113};
114
115} // namespace chromeos_update_engine
116
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700117#endif // UPDATE_ENGINE_FAKE_HARDWARE_H_