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