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_CROS_HARDWARE_CHROMEOS_H_
18 #define UPDATE_ENGINE_CROS_HARDWARE_CHROMEOS_H_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include <base/macros.h>
25 #include <base/time/time.h>
26 #include <debugd/dbus-proxies.h>
27 
28 #include "update_engine/common/error_code.h"
29 #include "update_engine/common/hardware_interface.h"
30 
31 namespace chromeos_update_engine {
32 
33 // Implements the real interface with Chrome OS verified boot and recovery
34 // process.
35 class HardwareChromeOS final : public HardwareInterface {
36  public:
37   HardwareChromeOS() = default;
38   ~HardwareChromeOS() override = default;
39 
40   void Init();
41 
42   // HardwareInterface methods.
43   bool IsOfficialBuild() const override;
44   bool IsNormalBootMode() const override;
45   bool AreDevFeaturesEnabled() const override;
46   bool IsOOBEEnabled() const override;
47   bool IsOOBEComplete(base::Time* out_time_of_oobe) const override;
48   std::string GetHardwareClass() const override;
49   std::string GetDeviceRequisition() const override;
50   int GetMinKernelKeyVersion() const override;
51   int GetMinFirmwareKeyVersion() const override;
52   int GetMaxFirmwareKeyRollforward() const override;
53   bool SetMaxFirmwareKeyRollforward(int firmware_max_rollforward) override;
54   bool SetMaxKernelKeyRollforward(int kernel_max_rollforward) override;
55   int GetPowerwashCount() const override;
56   bool SchedulePowerwash(bool save_rollback_data) override;
57   bool CancelPowerwash() override;
58   bool GetNonVolatileDirectory(base::FilePath* path) const override;
59   bool GetPowerwashSafeDirectory(base::FilePath* path) const override;
60   int64_t GetBuildTimestamp() const override;
AllowDowngrade()61   bool AllowDowngrade() const override { return false; }
62   bool GetFirstActiveOmahaPingSent() const override;
63   bool SetFirstActiveOmahaPingSent() override;
64   void SetWarmReset(bool warm_reset) override;
65   void SetVbmetaDigestForInactiveSlot(bool reset) override;
66   std::string GetVersionForLogging(
67       const std::string& partition_name) const override;
68   ErrorCode IsPartitionUpdateValid(
69       const std::string& partition_name,
70       const std::string& new_version) const override;
71   const char* GetPartitionMountOptions(
72       const std::string& partition_name) const override;
73 
74  private:
75   friend class HardwareChromeOSTest;
76 
77   // Load the update manager config flags (is_oobe_enabled flag) from the
78   // appropriate location based on whether we are in a normal mode boot (as
79   // passed in |normal_mode|) prefixing the paths with |root_prefix|.
80   void LoadConfig(const std::string& root_prefix, bool normal_mode);
81 
82   bool is_oobe_enabled_;
83 
84   std::unique_ptr<org::chromium::debugdProxyInterface> debugd_proxy_;
85 
86   DISALLOW_COPY_AND_ASSIGN(HardwareChromeOS);
87 };
88 
89 }  // namespace chromeos_update_engine
90 
91 #endif  // UPDATE_ENGINE_CROS_HARDWARE_CHROMEOS_H_
92