Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 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 | // |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 16 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_CROS_REAL_SYSTEM_STATE_H_ |
| 18 | #define UPDATE_ENGINE_CROS_REAL_SYSTEM_STATE_H_ |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 19 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 20 | #include "update_engine/common/system_state.h" |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 21 | |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 22 | #include <memory> |
Alex Deymo | 03a4de7 | 2016-07-20 16:08:23 -0700 | [diff] [blame] | 23 | #include <set> |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 24 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 25 | #include <policy/device_policy.h> |
Daniel Erat | 04df23a | 2018-03-29 17:55:35 -0700 | [diff] [blame] | 26 | #include <kiosk-app/dbus-proxies.h> |
Daniel Erat | e5f6f25 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 27 | |
Alex Deymo | 14c0da8 | 2016-07-20 16:45:45 -0700 | [diff] [blame] | 28 | #include "update_engine/certificate_checker.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 29 | #include "update_engine/common/boot_control_interface.h" |
| 30 | #include "update_engine/common/clock.h" |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 31 | #include "update_engine/common/daemon_state_interface.h" |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 32 | #include "update_engine/common/dlcservice_interface.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 33 | #include "update_engine/common/hardware_interface.h" |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 34 | #include "update_engine/common/metrics_reporter_interface.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 35 | #include "update_engine/common/prefs.h" |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 36 | #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 Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 42 | #include "update_engine/update_manager/update_manager.h" |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 43 | |
| 44 | namespace chromeos_update_engine { |
| 45 | |
| 46 | // A real implementation of the SystemStateInterface which is |
| 47 | // used by the actual product code. |
Amin Hassani | c288bf6 | 2020-11-04 19:33:43 -0800 | [diff] [blame] | 48 | class RealSystemState : public SystemState { |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 49 | public: |
Amin Hassani | ddd6822 | 2020-11-30 16:45:59 -0800 | [diff] [blame] | 50 | // Constructs all system objects that do not require separate initialization; |
| 51 | // see Initialize() below for the remaining ones. |
| 52 | RealSystemState() = default; |
Amin Hassani | c288bf6 | 2020-11-04 19:33:43 -0800 | [diff] [blame] | 53 | ~RealSystemState() = default; |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 54 | |
Amin Hassani | ddd6822 | 2020-11-30 16:45:59 -0800 | [diff] [blame] | 55 | 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 Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 60 | } |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 61 | |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 62 | // SystemState overrides. |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 63 | void set_device_policy(const policy::DevicePolicy* device_policy) override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 64 | device_policy_ = device_policy; |
| 65 | } |
| 66 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 67 | const policy::DevicePolicy* device_policy() override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 68 | return device_policy_; |
| 69 | } |
| 70 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 71 | BootControlInterface* boot_control() override { return boot_control_.get(); } |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 72 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 73 | ClockInterface* clock() override { return &clock_; } |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 74 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 75 | ConnectionManagerInterface* connection_manager() override { |
Sen Jiang | f5bebae | 2016-06-03 15:36:54 -0700 | [diff] [blame] | 76 | return connection_manager_.get(); |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 79 | HardwareInterface* hardware() override { return hardware_.get(); } |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 80 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 81 | MetricsReporterInterface* metrics_reporter() override { |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 82 | return &metrics_reporter_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 85 | PrefsInterface* prefs() override { return prefs_.get(); } |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 86 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 87 | PrefsInterface* powerwash_safe_prefs() override { |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 88 | return powerwash_safe_prefs_.get(); |
| 89 | } |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 90 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 91 | PayloadStateInterface* payload_state() override { return &payload_state_; } |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 92 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 93 | UpdateAttempter* update_attempter() override { |
Alex Deymo | 33e91e7 | 2015-12-01 18:26:08 -0300 | [diff] [blame] | 94 | return update_attempter_.get(); |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 97 | OmahaRequestParams* request_params() override { return &request_params_; } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 98 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 99 | P2PManager* p2p_manager() override { return p2p_manager_.get(); } |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 100 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 101 | chromeos_update_manager::UpdateManager* update_manager() override { |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 102 | return update_manager_.get(); |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 105 | PowerManagerInterface* power_manager() override { |
Sen Jiang | b8c6a8f | 2016-06-07 17:33:17 -0700 | [diff] [blame] | 106 | return power_manager_.get(); |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 109 | bool system_rebooted() override { return system_rebooted_; } |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 110 | |
Amin Hassani | 956a89c | 2020-11-04 19:59:16 -0800 | [diff] [blame] | 111 | DlcServiceInterface* dlcservice() override { return dlcservice_.get(); } |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 112 | |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 113 | private: |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 114 | // Initializes and sets systems objects that require an initialization |
| 115 | // separately from construction. Returns |true| on success. |
| 116 | bool Initialize(); |
| 117 | |
Daniel Erat | e5f6f25 | 2017-04-20 12:09:58 -0600 | [diff] [blame] | 118 | // Real DBus proxies using the DBus connection. |
Daniel Erat | 04df23a | 2018-03-29 17:55:35 -0700 | [diff] [blame] | 119 | std::unique_ptr<org::chromium::KioskAppServiceInterfaceProxy> |
| 120 | kiosk_app_proxy_; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 121 | |
Sen Jiang | b8c6a8f | 2016-06-07 17:33:17 -0700 | [diff] [blame] | 122 | // Interface for the power manager. |
| 123 | std::unique_ptr<PowerManagerInterface> power_manager_; |
| 124 | |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 125 | // Interface for dlcservice. |
| 126 | std::unique_ptr<DlcServiceInterface> dlcservice_; |
| 127 | |
Andrew | d9b511d | 2020-04-14 15:26:32 -0700 | [diff] [blame] | 128 | // Interface for the bootloader control. |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 129 | std::unique_ptr<BootControlInterface> boot_control_; |
| 130 | |
| 131 | // Interface for the clock. |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 132 | Clock clock_; |
| 133 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 134 | // The latest device policy object from the policy provider. |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 135 | const policy::DevicePolicy* device_policy_{nullptr}; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 136 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 137 | // The connection manager object that makes download decisions depending on |
| 138 | // the current type of connection. |
Sen Jiang | f5bebae | 2016-06-03 15:36:54 -0700 | [diff] [blame] | 139 | std::unique_ptr<ConnectionManagerInterface> connection_manager_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 140 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 141 | // Interface for the hardware functions. |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 142 | std::unique_ptr<HardwareInterface> hardware_; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 143 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 144 | // The Metrics reporter for reporting UMA stats. |
| 145 | MetricsReporterOmaha metrics_reporter_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 146 | |
| 147 | // Interface for persisted store. |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 148 | std::unique_ptr<PrefsInterface> prefs_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 149 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 150 | // Interface for persisted store that persists across powerwashes. |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 151 | std::unique_ptr<PrefsInterface> powerwash_safe_prefs_; |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 152 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 153 | // All state pertaining to payload state such as response, URL, backoff |
| 154 | // states. |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 155 | PayloadState payload_state_; |
| 156 | |
Alex Deymo | 33e91e7 | 2015-12-01 18:26:08 -0300 | [diff] [blame] | 157 | // OpenSSLWrapper and CertificateChecker used for checking SSL certificates. |
| 158 | OpenSSLWrapper openssl_wrapper_; |
| 159 | std::unique_ptr<CertificateChecker> certificate_checker_; |
| 160 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 161 | // Pointer to the update attempter object. |
Alex Deymo | 33e91e7 | 2015-12-01 18:26:08 -0300 | [diff] [blame] | 162 | std::unique_ptr<UpdateAttempter> update_attempter_; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 163 | |
| 164 | // Common parameters for all Omaha requests. |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 165 | OmahaRequestParams request_params_; |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 166 | |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 167 | std::unique_ptr<P2PManager> p2p_manager_; |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 168 | |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 169 | std::unique_ptr<chromeos_update_manager::UpdateManager> update_manager_; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 170 | |
Alex Deymo | c83baf6 | 2014-04-02 17:43:35 -0700 | [diff] [blame] | 171 | policy::PolicyProvider policy_provider_; |
| 172 | |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 173 | // 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 Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 176 | bool system_rebooted_{false}; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | } // namespace chromeos_update_engine |
| 180 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 181 | #endif // UPDATE_ENGINE_CROS_REAL_SYSTEM_STATE_H_ |