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_REAL_SYSTEM_STATE_H_ 18 #define UPDATE_ENGINE_REAL_SYSTEM_STATE_H_ 19 20 #include "update_engine/system_state.h" 21 22 #include <memory> 23 24 #include <debugd/dbus-proxies.h> 25 #include <metrics/metrics_library.h> 26 #include <policy/device_policy.h> 27 #include <power_manager/dbus-proxies.h> 28 #include <session_manager/dbus-proxies.h> 29 30 #include "update_engine/common/boot_control_interface.h" 31 #include "update_engine/common/certificate_checker.h" 32 #include "update_engine/common/clock.h" 33 #include "update_engine/common/hardware_interface.h" 34 #include "update_engine/common/prefs.h" 35 #include "update_engine/connection_manager.h" 36 #include "update_engine/daemon_state_interface.h" 37 #include "update_engine/p2p_manager.h" 38 #include "update_engine/payload_state.h" 39 #include "update_engine/shill_proxy.h" 40 #include "update_engine/update_attempter.h" 41 #include "update_engine/update_manager/update_manager.h" 42 #include "update_engine/weave_service_interface.h" 43 44 namespace chromeos_update_engine { 45 46 // A real implementation of the SystemStateInterface which is 47 // used by the actual product code. 48 class RealSystemState : public SystemState, public DaemonStateInterface { 49 public: 50 // Constructs all system objects that do not require separate initialization; 51 // see Initialize() below for the remaining ones. 52 explicit RealSystemState(const scoped_refptr<dbus::Bus>& bus); 53 ~RealSystemState() override; 54 55 // Initializes and sets systems objects that require an initialization 56 // separately from construction. Returns |true| on success. 57 bool Initialize(); 58 59 // DaemonStateInterface overrides. 60 // Start the periodic update attempts. Must be called at the beginning of the 61 // program to start the periodic update check process. 62 bool StartUpdater() override; 63 64 void AddObserver(ServiceObserverInterface* observer) override; 65 void RemoveObserver(ServiceObserverInterface* observer) override; 66 67 // SystemState overrides. 68 inline void set_device_policy( 69 const policy::DevicePolicy* device_policy) override { 70 device_policy_ = device_policy; 71 } 72 73 inline const policy::DevicePolicy* device_policy() override { 74 return device_policy_; 75 } 76 77 inline BootControlInterface* boot_control() override { 78 return boot_control_.get(); 79 } 80 81 inline ClockInterface* clock() override { return &clock_; } 82 83 inline ConnectionManagerInterface* connection_manager() override { 84 return &connection_manager_; 85 } 86 87 inline HardwareInterface* hardware() override { return hardware_.get(); } 88 89 inline MetricsLibraryInterface* metrics_lib() override { 90 return &metrics_lib_; 91 } 92 93 inline PrefsInterface* prefs() override { return prefs_.get(); } 94 95 inline PrefsInterface* powerwash_safe_prefs() override { 96 return powerwash_safe_prefs_.get(); 97 } 98 99 inline PayloadStateInterface* payload_state() override { 100 return &payload_state_; 101 } 102 103 inline UpdateAttempter* update_attempter() override { 104 return update_attempter_.get(); 105 } 106 107 inline WeaveServiceInterface* weave_service() override { 108 return weave_service_.get(); 109 } 110 111 inline OmahaRequestParams* request_params() override { 112 return &request_params_; 113 } 114 115 inline P2PManager* p2p_manager() override { return p2p_manager_.get(); } 116 117 inline chromeos_update_manager::UpdateManager* update_manager() override { 118 return update_manager_.get(); 119 } 120 121 inline org::chromium::PowerManagerProxyInterface* power_manager_proxy() 122 override { 123 return &power_manager_proxy_; 124 } 125 126 inline bool system_rebooted() override { return system_rebooted_; } 127 128 private: 129 // Real DBus proxies using the DBus connection. 130 org::chromium::debugdProxy debugd_proxy_; 131 org::chromium::PowerManagerProxy power_manager_proxy_; 132 org::chromium::SessionManagerInterfaceProxy session_manager_proxy_; 133 ShillProxy shill_proxy_; 134 LibCrosProxy libcros_proxy_; 135 136 // Interface for the clock. 137 std::unique_ptr<BootControlInterface> boot_control_; 138 139 // Interface for the clock. 140 Clock clock_; 141 142 // The latest device policy object from the policy provider. 143 const policy::DevicePolicy* device_policy_{nullptr}; 144 145 // The connection manager object that makes download decisions depending on 146 // the current type of connection. 147 ConnectionManager connection_manager_{&shill_proxy_, this}; 148 149 // Interface for the hardware functions. 150 std::unique_ptr<HardwareInterface> hardware_; 151 152 // The Metrics Library interface for reporting UMA stats. 153 MetricsLibrary metrics_lib_; 154 155 // Interface for persisted store. 156 std::unique_ptr<PrefsInterface> prefs_; 157 158 // Interface for persisted store that persists across powerwashes. 159 std::unique_ptr<PrefsInterface> powerwash_safe_prefs_; 160 161 // All state pertaining to payload state such as response, URL, backoff 162 // states. 163 PayloadState payload_state_; 164 165 // OpenSSLWrapper and CertificateChecker used for checking SSL certificates. 166 OpenSSLWrapper openssl_wrapper_; 167 std::unique_ptr<CertificateChecker> certificate_checker_; 168 169 // Pointer to the update attempter object. 170 std::unique_ptr<UpdateAttempter> update_attempter_; 171 172 // Common parameters for all Omaha requests. 173 OmahaRequestParams request_params_{this}; 174 175 std::unique_ptr<P2PManager> p2p_manager_; 176 177 std::unique_ptr<WeaveServiceInterface> weave_service_; 178 179 std::unique_ptr<chromeos_update_manager::UpdateManager> update_manager_; 180 181 policy::PolicyProvider policy_provider_; 182 183 // If true, this is the first instance of the update engine since the system 184 // rebooted. Important for tracking whether you are running instance of the 185 // update engine on first boot or due to a crash/restart. 186 bool system_rebooted_{false}; 187 }; 188 189 } // namespace chromeos_update_engine 190 191 #endif // UPDATE_ENGINE_REAL_SYSTEM_STATE_H_ 192