fake_hardware.h revision dd132f39cced9028c01e98895a4f6c5fb9553de1
1a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville//
2a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// Copyright (C) 2013 The Android Open Source Project
3a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville//
4a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// Licensed under the Apache License, Version 2.0 (the "License");
5a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// you may not use this file except in compliance with the License.
6a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// You may obtain a copy of the License at
7a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville//
8a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville//      http://www.apache.org/licenses/LICENSE-2.0
9a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville//
10a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// Unless required by applicable law or agreed to in writing, software
11a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// distributed under the License is distributed on an "AS IS" BASIS,
12a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// See the License for the specific language governing permissions and
14a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// limitations under the License.
15a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville//
16a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
17a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville#ifndef UPDATE_ENGINE_FAKE_HARDWARE_H_
18a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville#define UPDATE_ENGINE_FAKE_HARDWARE_H_
19a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
20d7f4ed8ac190763dce7e57b737caa44654b4592aTyler Gunn#include <map>
21a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville#include <string>
22a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
23a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville#include <base/time/time.h>
24a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
25a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville#include "update_engine/hardware_interface.h"
26a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
27a8467dd0c524787104b1ccdddc5e8af10ba729edWink Savillenamespace chromeos_update_engine {
28a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
29a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// Implements a fake hardware interface used for testing.
30a8467dd0c524787104b1ccdddc5e8af10ba729edWink Savilleclass FakeHardware : public HardwareInterface {
31a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville public:
322999afbcfeab69bf7473e1b9bcabb1c9c6935b19Tyler Gunn  // Value used to signal that the powerwash_count file is not present. When
337fa8ac39602ee9841dfcb0fb5c5f4d401925f8b5Tyler Gunn  // this value is used in SetPowerwashCount(), GetPowerwashCount() will return
34a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  // false.
35a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  static const int kPowerwashCountNotSet = -1;
36a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
37a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  FakeHardware()
38a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville      : is_official_build_(true),
39a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        is_normal_boot_mode_(true),
40a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        is_oobe_complete_(false),
41a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        hardware_class_("Fake HWID BLAH-1234"),
42a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        firmware_version_("Fake Firmware v1.0.1"),
43a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        ec_version_("Fake EC v1.0a"),
44a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville        powerwash_count_(kPowerwashCountNotSet) {}
45a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
46a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  // HardwareInterface methods.
47a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  bool IsOfficialBuild() const override { return is_official_build_; }
48a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
49a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  bool IsNormalBootMode() const override { return is_normal_boot_mode_; }
50a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
51a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  bool IsOOBEComplete(base::Time* out_time_of_oobe) const override {
52a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    if (out_time_of_oobe != nullptr)
53a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville      *out_time_of_oobe = oobe_timestamp_;
54a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    return is_oobe_complete_;
55a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  }
56a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
57a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  std::string GetHardwareClass() const override { return hardware_class_; }
58a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
59a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  std::string GetFirmwareVersion() const override { return firmware_version_; }
60a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
61a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  std::string GetECVersion() const override { return ec_version_; }
62a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
63a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  int GetPowerwashCount() const override { return powerwash_count_; }
64a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
65a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  bool GetNonVolatileDirectory(base::FilePath* path) const override {
66a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    return false;
67a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  }
68a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
69a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  bool GetPowerwashSafeDirectory(base::FilePath* path) const override {
70a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    return false;
71a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  }
72a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
73a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  // Setters
74a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  void SetIsOfficialBuild(bool is_official_build) {
75a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    is_official_build_ = is_official_build;
76a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  }
77a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
78a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  void SetIsNormalBootMode(bool is_normal_boot_mode) {
79a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    is_normal_boot_mode_ = is_normal_boot_mode;
80a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  }
81a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
82a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  // Sets the IsOOBEComplete to True with the given timestamp.
83a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  void SetIsOOBEComplete(base::Time oobe_timestamp) {
84a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    is_oobe_complete_ = true;
85a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    oobe_timestamp_ = oobe_timestamp;
86a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  }
87a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
88a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  // Sets the IsOOBEComplete to False.
89a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  void UnsetIsOOBEComplete() {
90a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    is_oobe_complete_ = false;
91a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  }
92a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
93a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  void SetHardwareClass(std::string hardware_class) {
94a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    hardware_class_ = hardware_class;
95a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  }
96a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
97a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  void SetFirmwareVersion(std::string firmware_version) {
98a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    firmware_version_ = firmware_version;
99a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  }
100a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
101a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  void SetECVersion(std::string ec_version) {
102a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    ec_version_ = ec_version;
103a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  }
104a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
105a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  void SetPowerwashCount(int powerwash_count) {
106a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville    powerwash_count_ = powerwash_count;
107a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  }
108a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
109a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville private:
110a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  bool is_official_build_;
111a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  bool is_normal_boot_mode_;
112a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  bool is_oobe_complete_;
113a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  base::Time oobe_timestamp_;
114a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  std::string hardware_class_;
115a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  std::string firmware_version_;
116a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  std::string ec_version_;
117a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  int powerwash_count_;
118a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
119a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville  DISALLOW_COPY_AND_ASSIGN(FakeHardware);
120a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville};
121a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
122a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville}  // namespace chromeos_update_engine
123a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville
124a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville#endif  // UPDATE_ENGINE_FAKE_HARDWARE_H_
125a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville