blob: 480b4b769b9ad594a5dded77216fe12c42920b83 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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//
Jay Srinivasan55f50c22013-01-10 19:24:35 -080016
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_REAL_SYSTEM_STATE_H_
18#define UPDATE_ENGINE_REAL_SYSTEM_STATE_H_
Jay Srinivasan55f50c22013-01-10 19:24:35 -080019
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080020#include "update_engine/system_state.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080021
Ben Chan02f7c1d2014-10-18 15:18:02 -070022#include <memory>
Alex Deymo578b7872016-07-20 16:08:23 -070023#include <set>
Ben Chan02f7c1d2014-10-18 15:18:02 -070024
Alex Deymod6deb1d2015-08-28 15:54:37 -070025#include <debugd/dbus-proxies.h>
Alex Deymoc83baf62014-04-02 17:43:35 -070026#include <metrics/metrics_library.h>
Alex Deymo63784a52014-05-28 10:46:14 -070027#include <policy/device_policy.h>
Alex Deymod6deb1d2015-08-28 15:54:37 -070028#include <power_manager/dbus-proxies.h>
29#include <session_manager/dbus-proxies.h>
Gilad Arnold1f847232014-04-07 12:07:49 -070030
Alex Deymo8b01f442016-07-20 16:45:45 -070031#include "update_engine/certificate_checker.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080032#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"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080036#include "update_engine/connection_manager.h"
Alex Deymofa78f142016-01-26 21:36:16 -080037#include "update_engine/daemon_state_interface.h"
Alex Deymo94c06162014-03-21 20:34:46 -070038#include "update_engine/p2p_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080039#include "update_engine/payload_state.h"
Alex Deymo30534502015-07-20 15:06:33 -070040#include "update_engine/shill_proxy.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080041#include "update_engine/update_attempter.h"
Alex Deymo63784a52014-05-28 10:46:14 -070042#include "update_engine/update_manager/update_manager.h"
Alex Deymof7ead812015-10-23 17:37:27 -070043#include "update_engine/weave_service_interface.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080044
45namespace chromeos_update_engine {
46
47// A real implementation of the SystemStateInterface which is
48// used by the actual product code.
Alex Deymofa78f142016-01-26 21:36:16 -080049class RealSystemState : public SystemState, public DaemonStateInterface {
Alex Deymo94c06162014-03-21 20:34:46 -070050 public:
Gilad Arnold1f847232014-04-07 12:07:49 -070051 // Constructs all system objects that do not require separate initialization;
52 // see Initialize() below for the remaining ones.
Alex Deymo30534502015-07-20 15:06:33 -070053 explicit RealSystemState(const scoped_refptr<dbus::Bus>& bus);
Alex Deymo8c21b352016-01-20 16:38:33 -080054 ~RealSystemState() override;
Gilad Arnold1f847232014-04-07 12:07:49 -070055
56 // Initializes and sets systems objects that require an initialization
57 // separately from construction. Returns |true| on success.
Nam T. Nguyen7d623eb2014-05-13 16:06:28 -070058 bool Initialize();
Jay Srinivasan55f50c22013-01-10 19:24:35 -080059
Alex Deymofa78f142016-01-26 21:36:16 -080060 // DaemonStateInterface overrides.
Alex Deymoe97b39c2016-01-20 13:22:17 -080061 // Start the periodic update attempts. Must be called at the beginning of the
62 // program to start the periodic update check process.
Alex Deymofa78f142016-01-26 21:36:16 -080063 bool StartUpdater() override;
Alex Deymoe97b39c2016-01-20 13:22:17 -080064
Alex Deymofa78f142016-01-26 21:36:16 -080065 void AddObserver(ServiceObserverInterface* observer) override;
66 void RemoveObserver(ServiceObserverInterface* observer) override;
Alex Deymo578b7872016-07-20 16:08:23 -070067 const std::set<ServiceObserverInterface*>& service_observers() override {
68 CHECK(update_attempter_.get());
69 return update_attempter_->service_observers();
70 }
Alex Deymofa78f142016-01-26 21:36:16 -080071
72 // SystemState overrides.
Alex Vakulenko157fe302014-08-11 15:59:58 -070073 inline void set_device_policy(
Gilad Arnold1f847232014-04-07 12:07:49 -070074 const policy::DevicePolicy* device_policy) override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080075 device_policy_ = device_policy;
76 }
77
Alex Vakulenko157fe302014-08-11 15:59:58 -070078 inline const policy::DevicePolicy* device_policy() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080079 return device_policy_;
80 }
81
Alex Deymo763e7db2015-08-27 21:08:08 -070082 inline BootControlInterface* boot_control() override {
83 return boot_control_.get();
84 }
85
Alex Vakulenko157fe302014-08-11 15:59:58 -070086 inline ClockInterface* clock() override { return &clock_; }
David Zeuthenf413fe52013-04-22 14:04:39 -070087
Alex Deymof6ee0162015-07-31 12:35:22 -070088 inline ConnectionManagerInterface* connection_manager() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080089 return &connection_manager_;
90 }
91
Alex Deymo40d86b22015-09-03 22:27:10 -070092 inline HardwareInterface* hardware() override { return hardware_.get(); }
Alex Deymo42432912013-07-12 20:21:15 -070093
Alex Vakulenko157fe302014-08-11 15:59:58 -070094 inline MetricsLibraryInterface* metrics_lib() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080095 return &metrics_lib_;
96 }
97
Alex Deymodd132f32015-09-14 19:12:07 -070098 inline PrefsInterface* prefs() override { return prefs_.get(); }
Jay Srinivasan55f50c22013-01-10 19:24:35 -080099
Alex Vakulenko157fe302014-08-11 15:59:58 -0700100 inline PrefsInterface* powerwash_safe_prefs() override {
Alex Deymodd132f32015-09-14 19:12:07 -0700101 return powerwash_safe_prefs_.get();
102 }
Chris Sosaaa18e162013-06-20 13:20:30 -0700103
Alex Vakulenko157fe302014-08-11 15:59:58 -0700104 inline PayloadStateInterface* payload_state() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800105 return &payload_state_;
106 }
107
Alex Vakulenko157fe302014-08-11 15:59:58 -0700108 inline UpdateAttempter* update_attempter() override {
Alex Deymo33e91e72015-12-01 18:26:08 -0300109 return update_attempter_.get();
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800110 }
111
Alex Deymof7ead812015-10-23 17:37:27 -0700112 inline WeaveServiceInterface* weave_service() override {
113 return weave_service_.get();
114 }
115
Alex Vakulenko157fe302014-08-11 15:59:58 -0700116 inline OmahaRequestParams* request_params() override {
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700117 return &request_params_;
118 }
119
Alex Vakulenko157fe302014-08-11 15:59:58 -0700120 inline P2PManager* p2p_manager() override { return p2p_manager_.get(); }
David Zeuthen526cb582013-08-06 12:26:18 -0700121
Alex Vakulenko157fe302014-08-11 15:59:58 -0700122 inline chromeos_update_manager::UpdateManager* update_manager() override {
Alex Deymo63784a52014-05-28 10:46:14 -0700123 return update_manager_.get();
Alex Deymo94c06162014-03-21 20:34:46 -0700124 }
125
Alex Deymo30534502015-07-20 15:06:33 -0700126 inline org::chromium::PowerManagerProxyInterface* power_manager_proxy()
127 override {
128 return &power_manager_proxy_;
129 }
130
Alex Vakulenko157fe302014-08-11 15:59:58 -0700131 inline bool system_rebooted() override { return system_rebooted_; }
Chris Sosabe45bef2013-04-09 18:25:12 -0700132
Alex Deymo94c06162014-03-21 20:34:46 -0700133 private:
Alex Deymo30534502015-07-20 15:06:33 -0700134 // 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
David Zeuthenf413fe52013-04-22 14:04:39 -0700141 // Interface for the clock.
Alex Deymo763e7db2015-08-27 21:08:08 -0700142 std::unique_ptr<BootControlInterface> boot_control_;
143
144 // Interface for the clock.
David Zeuthenf413fe52013-04-22 14:04:39 -0700145 Clock clock_;
146
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800147 // The latest device policy object from the policy provider.
Alex Deymo30534502015-07-20 15:06:33 -0700148 const policy::DevicePolicy* device_policy_{nullptr};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800149
Alex Deymo30534502015-07-20 15:06:33 -0700150 // The connection manager object that makes download decisions depending on
151 // the current type of connection.
152 ConnectionManager connection_manager_{&shill_proxy_, this};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800153
Alex Deymo42432912013-07-12 20:21:15 -0700154 // Interface for the hardware functions.
Alex Deymo40d86b22015-09-03 22:27:10 -0700155 std::unique_ptr<HardwareInterface> hardware_;
Alex Deymo42432912013-07-12 20:21:15 -0700156
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800157 // The Metrics Library interface for reporting UMA stats.
158 MetricsLibrary metrics_lib_;
159
160 // Interface for persisted store.
Alex Deymodd132f32015-09-14 19:12:07 -0700161 std::unique_ptr<PrefsInterface> prefs_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800162
Chris Sosaaa18e162013-06-20 13:20:30 -0700163 // Interface for persisted store that persists across powerwashes.
Alex Deymodd132f32015-09-14 19:12:07 -0700164 std::unique_ptr<PrefsInterface> powerwash_safe_prefs_;
Chris Sosaaa18e162013-06-20 13:20:30 -0700165
Alex Deymo30534502015-07-20 15:06:33 -0700166 // All state pertaining to payload state such as response, URL, backoff
167 // states.
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800168 PayloadState payload_state_;
169
Alex Deymo33e91e72015-12-01 18:26:08 -0300170 // OpenSSLWrapper and CertificateChecker used for checking SSL certificates.
171 OpenSSLWrapper openssl_wrapper_;
172 std::unique_ptr<CertificateChecker> certificate_checker_;
173
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800174 // Pointer to the update attempter object.
Alex Deymo33e91e72015-12-01 18:26:08 -0300175 std::unique_ptr<UpdateAttempter> update_attempter_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700176
177 // Common parameters for all Omaha requests.
Alex Deymo30534502015-07-20 15:06:33 -0700178 OmahaRequestParams request_params_{this};
Chris Sosabe45bef2013-04-09 18:25:12 -0700179
Ben Chan02f7c1d2014-10-18 15:18:02 -0700180 std::unique_ptr<P2PManager> p2p_manager_;
David Zeuthen526cb582013-08-06 12:26:18 -0700181
Alex Deymof7ead812015-10-23 17:37:27 -0700182 std::unique_ptr<WeaveServiceInterface> weave_service_;
183
Ben Chan02f7c1d2014-10-18 15:18:02 -0700184 std::unique_ptr<chromeos_update_manager::UpdateManager> update_manager_;
Alex Deymo94c06162014-03-21 20:34:46 -0700185
Alex Deymoc83baf62014-04-02 17:43:35 -0700186 policy::PolicyProvider policy_provider_;
187
Chris Sosabe45bef2013-04-09 18:25:12 -0700188 // 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.
Alex Deymo30534502015-07-20 15:06:33 -0700191 bool system_rebooted_{false};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800192};
193
194} // namespace chromeos_update_engine
195
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700196#endif // UPDATE_ENGINE_REAL_SYSTEM_STATE_H_