blob: c95458edd8ceb076af8446d2264daa42e760aaad [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 Deymo03a4de72016-07-20 16:08:23 -070023#include <set>
Ben Chan02f7c1d2014-10-18 15:18:02 -070024
Alex Deymo63784a52014-05-28 10:46:14 -070025#include <policy/device_policy.h>
Gilad Arnold1f847232014-04-07 12:07:49 -070026
Amin Hassanie94ece52017-08-01 15:03:08 -070027#if USE_CHROME_KIOSK_APP
Daniel Erate5f6f252017-04-20 12:09:58 -060028#include <libcros/dbus-proxies.h>
Amin Hassanie94ece52017-08-01 15:03:08 -070029#endif // USE_CHROME_KIOSK_APP
30#if USE_CHROME_NETWORK_PROXY
Daniel Erate5f6f252017-04-20 12:09:58 -060031#include <network_proxy/dbus-proxies.h>
Amin Hassanie94ece52017-08-01 15:03:08 -070032#endif // USE_CHROME_NETWORK_PROXY
Daniel Erate5f6f252017-04-20 12:09:58 -060033
Alex Deymo14c0da82016-07-20 16:45:45 -070034#include "update_engine/certificate_checker.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080035#include "update_engine/common/boot_control_interface.h"
36#include "update_engine/common/clock.h"
37#include "update_engine/common/hardware_interface.h"
38#include "update_engine/common/prefs.h"
Sen Jiangf5bebae2016-06-03 15:36:54 -070039#include "update_engine/connection_manager_interface.h"
Alex Deymofa78f142016-01-26 21:36:16 -080040#include "update_engine/daemon_state_interface.h"
Tianjie Xu282aa1f2017-09-05 13:42:45 -070041#include "update_engine/metrics_reporter_interface.h"
42#include "update_engine/metrics_reporter_omaha.h"
Alex Deymo94c06162014-03-21 20:34:46 -070043#include "update_engine/p2p_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080044#include "update_engine/payload_state.h"
Sen Jiangb8c6a8f2016-06-07 17:33:17 -070045#include "update_engine/power_manager_interface.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080046#include "update_engine/update_attempter.h"
Alex Deymo63784a52014-05-28 10:46:14 -070047#include "update_engine/update_manager/update_manager.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080048
49namespace chromeos_update_engine {
50
51// A real implementation of the SystemStateInterface which is
52// used by the actual product code.
Alex Deymofa78f142016-01-26 21:36:16 -080053class RealSystemState : public SystemState, public DaemonStateInterface {
Alex Deymo94c06162014-03-21 20:34:46 -070054 public:
Gilad Arnold1f847232014-04-07 12:07:49 -070055 // Constructs all system objects that do not require separate initialization;
56 // see Initialize() below for the remaining ones.
Sen Jiangaeeb2e02016-06-09 15:00:16 -070057 RealSystemState() = default;
Alex Deymo8c21b352016-01-20 16:38:33 -080058 ~RealSystemState() override;
Gilad Arnold1f847232014-04-07 12:07:49 -070059
60 // Initializes and sets systems objects that require an initialization
61 // separately from construction. Returns |true| on success.
Nam T. Nguyen7d623eb2014-05-13 16:06:28 -070062 bool Initialize();
Jay Srinivasan55f50c22013-01-10 19:24:35 -080063
Alex Deymofa78f142016-01-26 21:36:16 -080064 // DaemonStateInterface overrides.
Alex Deymoe97b39c2016-01-20 13:22:17 -080065 // Start the periodic update attempts. Must be called at the beginning of the
66 // program to start the periodic update check process.
Alex Deymofa78f142016-01-26 21:36:16 -080067 bool StartUpdater() override;
Alex Deymoe97b39c2016-01-20 13:22:17 -080068
Alex Deymofa78f142016-01-26 21:36:16 -080069 void AddObserver(ServiceObserverInterface* observer) override;
70 void RemoveObserver(ServiceObserverInterface* observer) override;
Alex Deymo03a4de72016-07-20 16:08:23 -070071 const std::set<ServiceObserverInterface*>& service_observers() override {
72 CHECK(update_attempter_.get());
73 return update_attempter_->service_observers();
74 }
Alex Deymofa78f142016-01-26 21:36:16 -080075
76 // SystemState overrides.
Alex Vakulenko157fe302014-08-11 15:59:58 -070077 inline void set_device_policy(
Gilad Arnold1f847232014-04-07 12:07:49 -070078 const policy::DevicePolicy* device_policy) override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080079 device_policy_ = device_policy;
80 }
81
Alex Vakulenko157fe302014-08-11 15:59:58 -070082 inline const policy::DevicePolicy* device_policy() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080083 return device_policy_;
84 }
85
Alex Deymo763e7db2015-08-27 21:08:08 -070086 inline BootControlInterface* boot_control() override {
87 return boot_control_.get();
88 }
89
Alex Vakulenko157fe302014-08-11 15:59:58 -070090 inline ClockInterface* clock() override { return &clock_; }
David Zeuthenf413fe52013-04-22 14:04:39 -070091
Alex Deymof6ee0162015-07-31 12:35:22 -070092 inline ConnectionManagerInterface* connection_manager() override {
Sen Jiangf5bebae2016-06-03 15:36:54 -070093 return connection_manager_.get();
Jay Srinivasan55f50c22013-01-10 19:24:35 -080094 }
95
Alex Deymo40d86b22015-09-03 22:27:10 -070096 inline HardwareInterface* hardware() override { return hardware_.get(); }
Alex Deymo42432912013-07-12 20:21:15 -070097
Tianjie Xu282aa1f2017-09-05 13:42:45 -070098 inline MetricsReporterInterface* metrics_reporter() override {
99 return &metrics_reporter_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800100 }
101
Alex Deymodd132f32015-09-14 19:12:07 -0700102 inline PrefsInterface* prefs() override { return prefs_.get(); }
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800103
Alex Vakulenko157fe302014-08-11 15:59:58 -0700104 inline PrefsInterface* powerwash_safe_prefs() override {
Alex Deymodd132f32015-09-14 19:12:07 -0700105 return powerwash_safe_prefs_.get();
106 }
Chris Sosaaa18e162013-06-20 13:20:30 -0700107
Alex Vakulenko157fe302014-08-11 15:59:58 -0700108 inline PayloadStateInterface* payload_state() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800109 return &payload_state_;
110 }
111
Alex Vakulenko157fe302014-08-11 15:59:58 -0700112 inline UpdateAttempter* update_attempter() override {
Alex Deymo33e91e72015-12-01 18:26:08 -0300113 return update_attempter_.get();
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800114 }
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
Sen Jiangb8c6a8f2016-06-07 17:33:17 -0700126 inline PowerManagerInterface* power_manager() override {
127 return power_manager_.get();
Alex Deymo30534502015-07-20 15:06:33 -0700128 }
129
Alex Vakulenko157fe302014-08-11 15:59:58 -0700130 inline bool system_rebooted() override { return system_rebooted_; }
Chris Sosabe45bef2013-04-09 18:25:12 -0700131
Alex Deymo94c06162014-03-21 20:34:46 -0700132 private:
Daniel Erate5f6f252017-04-20 12:09:58 -0600133 // Real DBus proxies using the DBus connection.
Amin Hassanie94ece52017-08-01 15:03:08 -0700134#if USE_CHROME_KIOSK_APP
Daniel Erate5f6f252017-04-20 12:09:58 -0600135 std::unique_ptr<org::chromium::LibCrosServiceInterfaceProxy> libcros_proxy_;
Amin Hassanie94ece52017-08-01 15:03:08 -0700136#endif // USE_CHROME_KIOSK_APP
137#if USE_CHROME_NETWORK_PROXY
Daniel Erate5f6f252017-04-20 12:09:58 -0600138 std::unique_ptr<org::chromium::NetworkProxyServiceInterfaceProxy>
139 network_proxy_service_proxy_;
Amin Hassanie94ece52017-08-01 15:03:08 -0700140#endif // USE_CHROME_NETWORK_PROXY
Alex Deymo30534502015-07-20 15:06:33 -0700141
Sen Jiangb8c6a8f2016-06-07 17:33:17 -0700142 // Interface for the power manager.
143 std::unique_ptr<PowerManagerInterface> power_manager_;
144
David Zeuthenf413fe52013-04-22 14:04:39 -0700145 // Interface for the clock.
Alex Deymo763e7db2015-08-27 21:08:08 -0700146 std::unique_ptr<BootControlInterface> boot_control_;
147
148 // Interface for the clock.
David Zeuthenf413fe52013-04-22 14:04:39 -0700149 Clock clock_;
150
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800151 // The latest device policy object from the policy provider.
Alex Deymo30534502015-07-20 15:06:33 -0700152 const policy::DevicePolicy* device_policy_{nullptr};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800153
Alex Deymo30534502015-07-20 15:06:33 -0700154 // The connection manager object that makes download decisions depending on
155 // the current type of connection.
Sen Jiangf5bebae2016-06-03 15:36:54 -0700156 std::unique_ptr<ConnectionManagerInterface> connection_manager_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800157
Alex Deymo42432912013-07-12 20:21:15 -0700158 // Interface for the hardware functions.
Alex Deymo40d86b22015-09-03 22:27:10 -0700159 std::unique_ptr<HardwareInterface> hardware_;
Alex Deymo42432912013-07-12 20:21:15 -0700160
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700161 // The Metrics reporter for reporting UMA stats.
162 MetricsReporterOmaha metrics_reporter_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800163
164 // Interface for persisted store.
Alex Deymodd132f32015-09-14 19:12:07 -0700165 std::unique_ptr<PrefsInterface> prefs_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800166
Chris Sosaaa18e162013-06-20 13:20:30 -0700167 // Interface for persisted store that persists across powerwashes.
Alex Deymodd132f32015-09-14 19:12:07 -0700168 std::unique_ptr<PrefsInterface> powerwash_safe_prefs_;
Chris Sosaaa18e162013-06-20 13:20:30 -0700169
Alex Deymo30534502015-07-20 15:06:33 -0700170 // All state pertaining to payload state such as response, URL, backoff
171 // states.
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800172 PayloadState payload_state_;
173
Alex Deymo33e91e72015-12-01 18:26:08 -0300174 // OpenSSLWrapper and CertificateChecker used for checking SSL certificates.
175 OpenSSLWrapper openssl_wrapper_;
176 std::unique_ptr<CertificateChecker> certificate_checker_;
177
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800178 // Pointer to the update attempter object.
Alex Deymo33e91e72015-12-01 18:26:08 -0300179 std::unique_ptr<UpdateAttempter> update_attempter_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700180
181 // Common parameters for all Omaha requests.
Alex Deymo30534502015-07-20 15:06:33 -0700182 OmahaRequestParams request_params_{this};
Chris Sosabe45bef2013-04-09 18:25:12 -0700183
Ben Chan02f7c1d2014-10-18 15:18:02 -0700184 std::unique_ptr<P2PManager> p2p_manager_;
David Zeuthen526cb582013-08-06 12:26:18 -0700185
Ben Chan02f7c1d2014-10-18 15:18:02 -0700186 std::unique_ptr<chromeos_update_manager::UpdateManager> update_manager_;
Alex Deymo94c06162014-03-21 20:34:46 -0700187
Alex Deymoc83baf62014-04-02 17:43:35 -0700188 policy::PolicyProvider policy_provider_;
189
Chris Sosabe45bef2013-04-09 18:25:12 -0700190 // If true, this is the first instance of the update engine since the system
191 // rebooted. Important for tracking whether you are running instance of the
192 // update engine on first boot or due to a crash/restart.
Alex Deymo30534502015-07-20 15:06:33 -0700193 bool system_rebooted_{false};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800194};
195
196} // namespace chromeos_update_engine
197
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700198#endif // UPDATE_ENGINE_REAL_SYSTEM_STATE_H_