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