blob: 81a5e0e3af6469a638d534e05487bbf7c6c57e4a [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
Amin Hassaniec7bc112020-10-29 16:47:58 -070017#ifndef UPDATE_ENGINE_CROS_REAL_SYSTEM_STATE_H_
18#define UPDATE_ENGINE_CROS_REAL_SYSTEM_STATE_H_
Jay Srinivasan55f50c22013-01-10 19:24:35 -080019
Amin Hassaniec7bc112020-10-29 16:47:58 -070020#include "update_engine/common/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>
Daniel Erat04df23a2018-03-29 17:55:35 -070026#include <kiosk-app/dbus-proxies.h>
Daniel Erate5f6f252017-04-20 12:09:58 -060027
Alex Deymo14c0da82016-07-20 16:45:45 -070028#include "update_engine/certificate_checker.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080029#include "update_engine/common/boot_control_interface.h"
30#include "update_engine/common/clock.h"
Amin Hassaniec7bc112020-10-29 16:47:58 -070031#include "update_engine/common/daemon_state_interface.h"
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080032#include "update_engine/common/dlcservice_interface.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080033#include "update_engine/common/hardware_interface.h"
Amin Hassaniec7bc112020-10-29 16:47:58 -070034#include "update_engine/common/metrics_reporter_interface.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080035#include "update_engine/common/prefs.h"
Amin Hassaniec7bc112020-10-29 16:47:58 -070036#include "update_engine/cros/connection_manager_interface.h"
37#include "update_engine/cros/metrics_reporter_omaha.h"
38#include "update_engine/cros/p2p_manager.h"
39#include "update_engine/cros/payload_state.h"
40#include "update_engine/cros/power_manager_interface.h"
41#include "update_engine/cros/update_attempter.h"
Alex Deymo63784a52014-05-28 10:46:14 -070042#include "update_engine/update_manager/update_manager.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080043
44namespace chromeos_update_engine {
45
46// A real implementation of the SystemStateInterface which is
47// used by the actual product code.
Amin Hassanic288bf62020-11-04 19:33:43 -080048class RealSystemState : public SystemState {
Alex Deymo94c06162014-03-21 20:34:46 -070049 public:
Amin Hassaniddd68222020-11-30 16:45:59 -080050 // Constructs all system objects that do not require separate initialization;
51 // see Initialize() below for the remaining ones.
52 RealSystemState() = default;
Amin Hassanic288bf62020-11-04 19:33:43 -080053 ~RealSystemState() = default;
Gilad Arnold1f847232014-04-07 12:07:49 -070054
Amin Hassaniddd68222020-11-30 16:45:59 -080055 static void SetInstance(RealSystemState* system_state) {
56 CHECK(g_pointer_ == nullptr) << "SystemState has been previously set.";
57 g_pointer_ = system_state;
58 LOG_IF(FATAL, !system_state->Initialize())
59 << "Failed to initialize system state.";
Amin Hassani538bd592020-11-04 20:46:08 -080060 }
Jay Srinivasan55f50c22013-01-10 19:24:35 -080061
Alex Deymofa78f142016-01-26 21:36:16 -080062 // SystemState overrides.
Amin Hassani956a89c2020-11-04 19:59:16 -080063 void set_device_policy(const policy::DevicePolicy* device_policy) override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080064 device_policy_ = device_policy;
65 }
66
Amin Hassani956a89c2020-11-04 19:59:16 -080067 const policy::DevicePolicy* device_policy() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080068 return device_policy_;
69 }
70
Amin Hassani956a89c2020-11-04 19:59:16 -080071 BootControlInterface* boot_control() override { return boot_control_.get(); }
Alex Deymo763e7db2015-08-27 21:08:08 -070072
Amin Hassani956a89c2020-11-04 19:59:16 -080073 ClockInterface* clock() override { return &clock_; }
David Zeuthenf413fe52013-04-22 14:04:39 -070074
Amin Hassani956a89c2020-11-04 19:59:16 -080075 ConnectionManagerInterface* connection_manager() override {
Sen Jiangf5bebae2016-06-03 15:36:54 -070076 return connection_manager_.get();
Jay Srinivasan55f50c22013-01-10 19:24:35 -080077 }
78
Amin Hassani956a89c2020-11-04 19:59:16 -080079 HardwareInterface* hardware() override { return hardware_.get(); }
Alex Deymo42432912013-07-12 20:21:15 -070080
Amin Hassani956a89c2020-11-04 19:59:16 -080081 MetricsReporterInterface* metrics_reporter() override {
Tianjie Xu282aa1f2017-09-05 13:42:45 -070082 return &metrics_reporter_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080083 }
84
Amin Hassani956a89c2020-11-04 19:59:16 -080085 PrefsInterface* prefs() override { return prefs_.get(); }
Jay Srinivasan55f50c22013-01-10 19:24:35 -080086
Amin Hassani956a89c2020-11-04 19:59:16 -080087 PrefsInterface* powerwash_safe_prefs() override {
Alex Deymodd132f32015-09-14 19:12:07 -070088 return powerwash_safe_prefs_.get();
89 }
Chris Sosaaa18e162013-06-20 13:20:30 -070090
Amin Hassani956a89c2020-11-04 19:59:16 -080091 PayloadStateInterface* payload_state() override { return &payload_state_; }
Jay Srinivasan55f50c22013-01-10 19:24:35 -080092
Amin Hassani956a89c2020-11-04 19:59:16 -080093 UpdateAttempter* update_attempter() override {
Alex Deymo33e91e72015-12-01 18:26:08 -030094 return update_attempter_.get();
Jay Srinivasan55f50c22013-01-10 19:24:35 -080095 }
96
Amin Hassani956a89c2020-11-04 19:59:16 -080097 OmahaRequestParams* request_params() override { return &request_params_; }
Jay Srinivasanae4697c2013-03-18 17:08:08 -070098
Amin Hassani956a89c2020-11-04 19:59:16 -080099 P2PManager* p2p_manager() override { return p2p_manager_.get(); }
David Zeuthen526cb582013-08-06 12:26:18 -0700100
Amin Hassani956a89c2020-11-04 19:59:16 -0800101 chromeos_update_manager::UpdateManager* update_manager() override {
Alex Deymo63784a52014-05-28 10:46:14 -0700102 return update_manager_.get();
Alex Deymo94c06162014-03-21 20:34:46 -0700103 }
104
Amin Hassani956a89c2020-11-04 19:59:16 -0800105 PowerManagerInterface* power_manager() override {
Sen Jiangb8c6a8f2016-06-07 17:33:17 -0700106 return power_manager_.get();
Alex Deymo30534502015-07-20 15:06:33 -0700107 }
108
Amin Hassani956a89c2020-11-04 19:59:16 -0800109 bool system_rebooted() override { return system_rebooted_; }
Chris Sosabe45bef2013-04-09 18:25:12 -0700110
Amin Hassani956a89c2020-11-04 19:59:16 -0800111 DlcServiceInterface* dlcservice() override { return dlcservice_.get(); }
Xiaochu Liu8ba486f2018-11-06 11:14:10 -0800112
Alex Deymo94c06162014-03-21 20:34:46 -0700113 private:
Amin Hassani538bd592020-11-04 20:46:08 -0800114 // Initializes and sets systems objects that require an initialization
115 // separately from construction. Returns |true| on success.
116 bool Initialize();
117
Daniel Erate5f6f252017-04-20 12:09:58 -0600118 // Real DBus proxies using the DBus connection.
Daniel Erat04df23a2018-03-29 17:55:35 -0700119 std::unique_ptr<org::chromium::KioskAppServiceInterfaceProxy>
120 kiosk_app_proxy_;
Alex Deymo30534502015-07-20 15:06:33 -0700121
Sen Jiangb8c6a8f2016-06-07 17:33:17 -0700122 // Interface for the power manager.
123 std::unique_ptr<PowerManagerInterface> power_manager_;
124
Xiaochu Liu8ba486f2018-11-06 11:14:10 -0800125 // Interface for dlcservice.
126 std::unique_ptr<DlcServiceInterface> dlcservice_;
127
Andrewd9b511d2020-04-14 15:26:32 -0700128 // Interface for the bootloader control.
Alex Deymo763e7db2015-08-27 21:08:08 -0700129 std::unique_ptr<BootControlInterface> boot_control_;
130
131 // Interface for the clock.
David Zeuthenf413fe52013-04-22 14:04:39 -0700132 Clock clock_;
133
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800134 // The latest device policy object from the policy provider.
Alex Deymo30534502015-07-20 15:06:33 -0700135 const policy::DevicePolicy* device_policy_{nullptr};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800136
Alex Deymo30534502015-07-20 15:06:33 -0700137 // The connection manager object that makes download decisions depending on
138 // the current type of connection.
Sen Jiangf5bebae2016-06-03 15:36:54 -0700139 std::unique_ptr<ConnectionManagerInterface> connection_manager_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800140
Alex Deymo42432912013-07-12 20:21:15 -0700141 // Interface for the hardware functions.
Alex Deymo40d86b22015-09-03 22:27:10 -0700142 std::unique_ptr<HardwareInterface> hardware_;
Alex Deymo42432912013-07-12 20:21:15 -0700143
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700144 // The Metrics reporter for reporting UMA stats.
145 MetricsReporterOmaha metrics_reporter_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800146
147 // Interface for persisted store.
Alex Deymodd132f32015-09-14 19:12:07 -0700148 std::unique_ptr<PrefsInterface> prefs_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800149
Chris Sosaaa18e162013-06-20 13:20:30 -0700150 // Interface for persisted store that persists across powerwashes.
Alex Deymodd132f32015-09-14 19:12:07 -0700151 std::unique_ptr<PrefsInterface> powerwash_safe_prefs_;
Chris Sosaaa18e162013-06-20 13:20:30 -0700152
Alex Deymo30534502015-07-20 15:06:33 -0700153 // All state pertaining to payload state such as response, URL, backoff
154 // states.
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800155 PayloadState payload_state_;
156
Alex Deymo33e91e72015-12-01 18:26:08 -0300157 // OpenSSLWrapper and CertificateChecker used for checking SSL certificates.
158 OpenSSLWrapper openssl_wrapper_;
159 std::unique_ptr<CertificateChecker> certificate_checker_;
160
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800161 // Pointer to the update attempter object.
Alex Deymo33e91e72015-12-01 18:26:08 -0300162 std::unique_ptr<UpdateAttempter> update_attempter_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700163
164 // Common parameters for all Omaha requests.
Amin Hassani538bd592020-11-04 20:46:08 -0800165 OmahaRequestParams request_params_;
Chris Sosabe45bef2013-04-09 18:25:12 -0700166
Ben Chan02f7c1d2014-10-18 15:18:02 -0700167 std::unique_ptr<P2PManager> p2p_manager_;
David Zeuthen526cb582013-08-06 12:26:18 -0700168
Ben Chan02f7c1d2014-10-18 15:18:02 -0700169 std::unique_ptr<chromeos_update_manager::UpdateManager> update_manager_;
Alex Deymo94c06162014-03-21 20:34:46 -0700170
Alex Deymoc83baf62014-04-02 17:43:35 -0700171 policy::PolicyProvider policy_provider_;
172
Chris Sosabe45bef2013-04-09 18:25:12 -0700173 // If true, this is the first instance of the update engine since the system
174 // rebooted. Important for tracking whether you are running instance of the
175 // update engine on first boot or due to a crash/restart.
Alex Deymo30534502015-07-20 15:06:33 -0700176 bool system_rebooted_{false};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800177};
178
179} // namespace chromeos_update_engine
180
Amin Hassaniec7bc112020-10-29 16:47:58 -0700181#endif // UPDATE_ENGINE_CROS_REAL_SYSTEM_STATE_H_