Home | History | Annotate | Download | only in common
      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 //
     16 
     17 #ifndef UPDATE_ENGINE_COMMON_FAKE_HARDWARE_H_
     18 #define UPDATE_ENGINE_COMMON_FAKE_HARDWARE_H_
     19 
     20 #include <map>
     21 #include <string>
     22 
     23 #include <base/time/time.h>
     24 
     25 #include "update_engine/common/hardware_interface.h"
     26 
     27 namespace chromeos_update_engine {
     28 
     29 // Implements a fake hardware interface used for testing.
     30 class FakeHardware : public HardwareInterface {
     31  public:
     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 
     37   FakeHardware()
     38       : is_official_build_(true),
     39         is_normal_boot_mode_(true),
     40         is_oobe_complete_(false),
     41         hardware_class_("Fake HWID BLAH-1234"),
     42         firmware_version_("Fake Firmware v1.0.1"),
     43         ec_version_("Fake EC v1.0a"),
     44         powerwash_count_(kPowerwashCountNotSet) {}
     45 
     46   // HardwareInterface methods.
     47   bool IsOfficialBuild() const override { return is_official_build_; }
     48 
     49   bool IsNormalBootMode() const override { return is_normal_boot_mode_; }
     50 
     51   bool IsOOBEComplete(base::Time* out_time_of_oobe) const override {
     52     if (out_time_of_oobe != nullptr)
     53       *out_time_of_oobe = oobe_timestamp_;
     54     return is_oobe_complete_;
     55   }
     56 
     57   std::string GetHardwareClass() const override { return hardware_class_; }
     58 
     59   std::string GetFirmwareVersion() const override { return firmware_version_; }
     60 
     61   std::string GetECVersion() const override { return ec_version_; }
     62 
     63   int GetPowerwashCount() const override { return powerwash_count_; }
     64 
     65   bool SchedulePowerwash() override {
     66     powerwash_scheduled_ = true;
     67     return true;
     68   }
     69 
     70   bool CancelPowerwash() override {
     71     powerwash_scheduled_ = false;
     72     return true;
     73   }
     74 
     75   bool IsPowerwashScheduled() { return powerwash_scheduled_; }
     76 
     77   bool GetNonVolatileDirectory(base::FilePath* path) const override {
     78     return false;
     79   }
     80 
     81   bool GetPowerwashSafeDirectory(base::FilePath* path) const override {
     82     return false;
     83   }
     84 
     85   // Setters
     86   void SetIsOfficialBuild(bool is_official_build) {
     87     is_official_build_ = is_official_build;
     88   }
     89 
     90   void SetIsNormalBootMode(bool is_normal_boot_mode) {
     91     is_normal_boot_mode_ = is_normal_boot_mode;
     92   }
     93 
     94   // Sets the IsOOBEComplete to True with the given timestamp.
     95   void SetIsOOBEComplete(base::Time oobe_timestamp) {
     96     is_oobe_complete_ = true;
     97     oobe_timestamp_ = oobe_timestamp;
     98   }
     99 
    100   // Sets the IsOOBEComplete to False.
    101   void UnsetIsOOBEComplete() {
    102     is_oobe_complete_ = false;
    103   }
    104 
    105   void SetHardwareClass(std::string hardware_class) {
    106     hardware_class_ = hardware_class;
    107   }
    108 
    109   void SetFirmwareVersion(std::string firmware_version) {
    110     firmware_version_ = firmware_version;
    111   }
    112 
    113   void SetECVersion(std::string ec_version) {
    114     ec_version_ = ec_version;
    115   }
    116 
    117   void SetPowerwashCount(int powerwash_count) {
    118     powerwash_count_ = powerwash_count;
    119   }
    120 
    121  private:
    122   bool is_official_build_;
    123   bool is_normal_boot_mode_;
    124   bool is_oobe_complete_;
    125   base::Time oobe_timestamp_;
    126   std::string hardware_class_;
    127   std::string firmware_version_;
    128   std::string ec_version_;
    129   int powerwash_count_;
    130   bool powerwash_scheduled_{false};
    131 
    132   DISALLOW_COPY_AND_ASSIGN(FakeHardware);
    133 };
    134 
    135 }  // namespace chromeos_update_engine
    136 
    137 #endif  // UPDATE_ENGINE_COMMON_FAKE_HARDWARE_H_
    138