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 <policy/device_policy.h> 26 27 #if USE_CHROME_KIOSK_APP 28 #include <libcros/dbus-proxies.h> 29 #endif // USE_CHROME_KIOSK_APP 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_interface.h" 37 #include "update_engine/daemon_state_interface.h" 38 #include "update_engine/metrics_reporter_interface.h" 39 #include "update_engine/metrics_reporter_omaha.h" 40 #include "update_engine/p2p_manager.h" 41 #include "update_engine/payload_state.h" 42 #include "update_engine/power_manager_interface.h" 43 #include "update_engine/update_attempter.h" 44 #include "update_engine/update_manager/update_manager.h" 45 46 namespace chromeos_update_engine { 47 48 // A real implementation of the SystemStateInterface which is 49 // used by the actual product code. 50 class RealSystemState : public SystemState, public DaemonStateInterface { 51 public: 52 // Constructs all system objects that do not require separate initialization; 53 // see Initialize() below for the remaining ones. 54 RealSystemState() = default; 55 ~RealSystemState() override; 56 57 // Initializes and sets systems objects that require an initialization 58 // separately from construction. Returns |true| on success. 59 bool Initialize(); 60 61 // DaemonStateInterface overrides. 62 // Start the periodic update attempts. Must be called at the beginning of the 63 // program to start the periodic update check process. 64 bool StartUpdater() override; 65 66 void AddObserver(ServiceObserverInterface* observer) override; 67 void RemoveObserver(ServiceObserverInterface* observer) override; 68 const std::set<ServiceObserverInterface*>& service_observers() override { 69 CHECK(update_attempter_.get()); 70 return update_attempter_->service_observers(); 71 } 72 73 // SystemState overrides. 74 inline void set_device_policy( 75 const policy::DevicePolicy* device_policy) override { 76 device_policy_ = device_policy; 77 } 78 79 inline const policy::DevicePolicy* device_policy() override { 80 return device_policy_; 81 } 82 83 inline BootControlInterface* boot_control() override { 84 return boot_control_.get(); 85 } 86 87 inline ClockInterface* clock() override { return &clock_; } 88 89 inline ConnectionManagerInterface* connection_manager() override { 90 return connection_manager_.get(); 91 } 92 93 inline HardwareInterface* hardware() override { return hardware_.get(); } 94 95 inline MetricsReporterInterface* metrics_reporter() override { 96 return &metrics_reporter_; 97 } 98 99 inline PrefsInterface* prefs() override { return prefs_.get(); } 100 101 inline PrefsInterface* powerwash_safe_prefs() override { 102 return powerwash_safe_prefs_.get(); 103 } 104 105 inline PayloadStateInterface* payload_state() override { 106 return &payload_state_; 107 } 108 109 inline UpdateAttempter* update_attempter() override { 110 return update_attempter_.get(); 111 } 112 113 inline OmahaRequestParams* request_params() override { 114 return &request_params_; 115 } 116 117 inline P2PManager* p2p_manager() override { return p2p_manager_.get(); } 118 119 inline chromeos_update_manager::UpdateManager* update_manager() override { 120 return update_manager_.get(); 121 } 122 123 inline PowerManagerInterface* power_manager() override { 124 return power_manager_.get(); 125 } 126 127 inline bool system_rebooted() override { return system_rebooted_; } 128 129 private: 130 // Real DBus proxies using the DBus connection. 131 #if USE_CHROME_KIOSK_APP 132 std::unique_ptr<org::chromium::LibCrosServiceInterfaceProxy> libcros_proxy_; 133 #endif // USE_CHROME_KIOSK_APP 134 135 // Interface for the power manager. 136 std::unique_ptr<PowerManagerInterface> power_manager_; 137 138 // Interface for the clock. 139 std::unique_ptr<BootControlInterface> boot_control_; 140 141 // Interface for the clock. 142 Clock clock_; 143 144 // The latest device policy object from the policy provider. 145 const policy::DevicePolicy* device_policy_{nullptr}; 146 147 // The connection manager object that makes download decisions depending on 148 // the current type of connection. 149 std::unique_ptr<ConnectionManagerInterface> connection_manager_; 150 151 // Interface for the hardware functions. 152 std::unique_ptr<HardwareInterface> hardware_; 153 154 // The Metrics reporter for reporting UMA stats. 155 MetricsReporterOmaha metrics_reporter_; 156 157 // Interface for persisted store. 158 std::unique_ptr<PrefsInterface> prefs_; 159 160 // Interface for persisted store that persists across powerwashes. 161 std::unique_ptr<PrefsInterface> powerwash_safe_prefs_; 162 163 // All state pertaining to payload state such as response, URL, backoff 164 // states. 165 PayloadState payload_state_; 166 167 // OpenSSLWrapper and CertificateChecker used for checking SSL certificates. 168 OpenSSLWrapper openssl_wrapper_; 169 std::unique_ptr<CertificateChecker> certificate_checker_; 170 171 // Pointer to the update attempter object. 172 std::unique_ptr<UpdateAttempter> update_attempter_; 173 174 // Common parameters for all Omaha requests. 175 OmahaRequestParams request_params_{this}; 176 177 std::unique_ptr<P2PManager> p2p_manager_; 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