• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <metrics/metrics_library.h>
26 #include <policy/device_policy.h>
27 
28 #if USE_LIBCROS
29 #include <libcros/dbus-proxies.h>
30 #include <network_proxy/dbus-proxies.h>
31 #endif  // USE_LIBCROS
32 
33 #include "update_engine/certificate_checker.h"
34 #include "update_engine/common/boot_control_interface.h"
35 #include "update_engine/common/clock.h"
36 #include "update_engine/common/hardware_interface.h"
37 #include "update_engine/common/prefs.h"
38 #include "update_engine/connection_manager_interface.h"
39 #include "update_engine/daemon_state_interface.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;
service_observers()68   const std::set<ServiceObserverInterface*>& service_observers() override {
69     CHECK(update_attempter_.get());
70     return update_attempter_->service_observers();
71   }
72 
73   // SystemState overrides.
set_device_policy(const policy::DevicePolicy * device_policy)74   inline void set_device_policy(
75       const policy::DevicePolicy* device_policy) override {
76     device_policy_ = device_policy;
77   }
78 
device_policy()79   inline const policy::DevicePolicy* device_policy() override {
80     return device_policy_;
81   }
82 
boot_control()83   inline BootControlInterface* boot_control() override {
84     return boot_control_.get();
85   }
86 
clock()87   inline ClockInterface* clock() override { return &clock_; }
88 
connection_manager()89   inline ConnectionManagerInterface* connection_manager() override {
90     return connection_manager_.get();
91   }
92 
hardware()93   inline HardwareInterface* hardware() override { return hardware_.get(); }
94 
metrics_lib()95   inline MetricsLibraryInterface* metrics_lib() override {
96     return &metrics_lib_;
97   }
98 
prefs()99   inline PrefsInterface* prefs() override { return prefs_.get(); }
100 
powerwash_safe_prefs()101   inline PrefsInterface* powerwash_safe_prefs() override {
102     return powerwash_safe_prefs_.get();
103   }
104 
payload_state()105   inline PayloadStateInterface* payload_state() override {
106     return &payload_state_;
107   }
108 
update_attempter()109   inline UpdateAttempter* update_attempter() override {
110     return update_attempter_.get();
111   }
112 
request_params()113   inline OmahaRequestParams* request_params() override {
114     return &request_params_;
115   }
116 
p2p_manager()117   inline P2PManager* p2p_manager() override { return p2p_manager_.get(); }
118 
update_manager()119   inline chromeos_update_manager::UpdateManager* update_manager() override {
120     return update_manager_.get();
121   }
122 
power_manager()123   inline PowerManagerInterface* power_manager() override {
124     return power_manager_.get();
125   }
126 
system_rebooted()127   inline bool system_rebooted() override { return system_rebooted_; }
128 
129  private:
130 #if USE_LIBCROS
131   // Real DBus proxies using the DBus connection.
132   std::unique_ptr<org::chromium::LibCrosServiceInterfaceProxy> libcros_proxy_;
133   std::unique_ptr<org::chromium::NetworkProxyServiceInterfaceProxy>
134       network_proxy_service_proxy_;
135 #endif  // USE_LIBCROS
136 
137   // Interface for the power manager.
138   std::unique_ptr<PowerManagerInterface> power_manager_;
139 
140   // Interface for the clock.
141   std::unique_ptr<BootControlInterface> boot_control_;
142 
143   // Interface for the clock.
144   Clock clock_;
145 
146   // The latest device policy object from the policy provider.
147   const policy::DevicePolicy* device_policy_{nullptr};
148 
149   // The connection manager object that makes download decisions depending on
150   // the current type of connection.
151   std::unique_ptr<ConnectionManagerInterface> connection_manager_;
152 
153   // Interface for the hardware functions.
154   std::unique_ptr<HardwareInterface> hardware_;
155 
156   // The Metrics Library interface for reporting UMA stats.
157   MetricsLibrary metrics_lib_;
158 
159   // Interface for persisted store.
160   std::unique_ptr<PrefsInterface> prefs_;
161 
162   // Interface for persisted store that persists across powerwashes.
163   std::unique_ptr<PrefsInterface> powerwash_safe_prefs_;
164 
165   // All state pertaining to payload state such as response, URL, backoff
166   // states.
167   PayloadState payload_state_;
168 
169   // OpenSSLWrapper and CertificateChecker used for checking SSL certificates.
170   OpenSSLWrapper openssl_wrapper_;
171   std::unique_ptr<CertificateChecker> certificate_checker_;
172 
173   // Pointer to the update attempter object.
174   std::unique_ptr<UpdateAttempter> update_attempter_;
175 
176   // Common parameters for all Omaha requests.
177   OmahaRequestParams request_params_{this};
178 
179   std::unique_ptr<P2PManager> p2p_manager_;
180 
181   std::unique_ptr<chromeos_update_manager::UpdateManager> update_manager_;
182 
183   policy::PolicyProvider policy_provider_;
184 
185   // If true, this is the first instance of the update engine since the system
186   // rebooted. Important for tracking whether you are running instance of the
187   // update engine on first boot or due to a crash/restart.
188   bool system_rebooted_{false};
189 };
190 
191 }  // namespace chromeos_update_engine
192 
193 #endif  // UPDATE_ENGINE_REAL_SYSTEM_STATE_H_
194