Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2012 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 | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 16 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_COMMON_SYSTEM_STATE_H_ |
| 18 | #define UPDATE_ENGINE_COMMON_SYSTEM_STATE_H_ |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 19 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 20 | #include <memory> |
| 21 | |
| 22 | #include <base/logging.h> |
| 23 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 24 | namespace chromeos_update_manager { |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 25 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 26 | class UpdateManager; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 27 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 28 | } // namespace chromeos_update_manager |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 29 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 30 | namespace policy { |
| 31 | |
| 32 | class DevicePolicy; |
| 33 | |
| 34 | } // namespace policy |
| 35 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 36 | namespace chromeos_update_engine { |
| 37 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 38 | // SystemState is the root class within the update engine. So we should avoid |
| 39 | // any circular references in header file inclusion. Hence forward-declaring |
| 40 | // the required classes. |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 41 | class BootControlInterface; |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 42 | class ClockInterface; |
Alex Deymo | f6ee016 | 2015-07-31 12:35:22 -0700 | [diff] [blame] | 43 | class ConnectionManagerInterface; |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 44 | class DlcServiceInterface; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 45 | class HardwareInterface; |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 46 | class MetricsReporterInterface; |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 47 | class OmahaRequestParams; |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 48 | class P2PManager; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 49 | class PayloadStateInterface; |
Sen Jiang | b8c6a8f | 2016-06-07 17:33:17 -0700 | [diff] [blame] | 50 | class PowerManagerInterface; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 51 | class PrefsInterface; |
| 52 | class UpdateAttempter; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 53 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 54 | // An interface to global system context, including platform resources, |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 55 | // the current state of the system, high-level objects whose lifetime is same |
| 56 | // as main, system interfaces, etc. |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 57 | // Carved out separately so it can be mocked for unit tests. |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 58 | class SystemState { |
| 59 | public: |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 60 | virtual ~SystemState() = default; |
| 61 | |
| 62 | static SystemState* Get() { |
| 63 | CHECK(g_instance_); |
| 64 | return g_instance_.get(); |
| 65 | } |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 66 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 67 | // Sets or gets the latest device policy. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 68 | virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0; |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 69 | virtual const policy::DevicePolicy* device_policy() = 0; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 70 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 71 | // Gets the interface object for the bootloader control interface. |
| 72 | virtual BootControlInterface* boot_control() = 0; |
| 73 | |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 74 | // Gets the interface object for the clock. |
| 75 | virtual ClockInterface* clock() = 0; |
| 76 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 77 | // Gets the connection manager object. |
Alex Deymo | f6ee016 | 2015-07-31 12:35:22 -0700 | [diff] [blame] | 78 | virtual ConnectionManagerInterface* connection_manager() = 0; |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 79 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 80 | // Gets the hardware interface object. |
| 81 | virtual HardwareInterface* hardware() = 0; |
| 82 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 83 | // Gets the Metrics Library interface for reporting UMA stats. |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 84 | virtual MetricsReporterInterface* metrics_reporter() = 0; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 85 | |
| 86 | // Gets the interface object for persisted store. |
| 87 | virtual PrefsInterface* prefs() = 0; |
| 88 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 89 | // Gets the interface object for the persisted store that persists across |
| 90 | // powerwashes. Please note that this should be used very seldomly and must |
| 91 | // be forwards and backwards compatible as powerwash is used to go back and |
| 92 | // forth in system versions. |
| 93 | virtual PrefsInterface* powerwash_safe_prefs() = 0; |
| 94 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 95 | // Gets the interface for the payload state object. |
| 96 | virtual PayloadStateInterface* payload_state() = 0; |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 97 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 98 | // Returns a pointer to the update attempter object. |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 99 | virtual UpdateAttempter* update_attempter() = 0; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 100 | |
| 101 | // Returns a pointer to the object that stores the parameters that are |
| 102 | // common to all Omaha requests. |
| 103 | virtual OmahaRequestParams* request_params() = 0; |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 104 | |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 105 | // Returns a pointer to the P2PManager singleton. |
| 106 | virtual P2PManager* p2p_manager() = 0; |
| 107 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 108 | // Returns a pointer to the UpdateManager singleton. |
| 109 | virtual chromeos_update_manager::UpdateManager* update_manager() = 0; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 110 | |
Sen Jiang | b8c6a8f | 2016-06-07 17:33:17 -0700 | [diff] [blame] | 111 | // Gets the power manager object. Mocked during test. |
| 112 | virtual PowerManagerInterface* power_manager() = 0; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 113 | |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 114 | // If true, this is the first instance of the update engine since the system |
| 115 | // restarted. Important for tracking whether you are running instance of the |
| 116 | // update engine on first boot or due to a crash/restart. |
| 117 | virtual bool system_rebooted() = 0; |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 118 | |
| 119 | // Returns a pointer to the DlcServiceInterface singleton. |
| 120 | virtual DlcServiceInterface* dlcservice() = 0; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 121 | |
| 122 | protected: |
| 123 | static std::unique_ptr<SystemState> g_instance_; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } // namespace chromeos_update_engine |
| 127 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 128 | #endif // UPDATE_ENGINE_COMMON_SYSTEM_STATE_H_ |