blob: 29b897b06d40fb46b364a03ddac5fc0fd19cb8fb [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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 Srinivasan43488792012-06-19 00:25:31 -070016
Amin Hassaniec7bc112020-10-29 16:47:58 -070017#ifndef UPDATE_ENGINE_COMMON_SYSTEM_STATE_H_
18#define UPDATE_ENGINE_COMMON_SYSTEM_STATE_H_
Jay Srinivasan43488792012-06-19 00:25:31 -070019
Amin Hassani538bd592020-11-04 20:46:08 -080020#include <memory>
21
22#include <base/logging.h>
23
Amin Hassani0468a762020-11-17 23:53:48 -080024#include "update_engine/common/clock_interface.h"
25
Alex Deymo63784a52014-05-28 10:46:14 -070026namespace chromeos_update_manager {
Alex Deymo94c06162014-03-21 20:34:46 -070027
Alex Deymo63784a52014-05-28 10:46:14 -070028class UpdateManager;
Alex Deymo94c06162014-03-21 20:34:46 -070029
Alex Deymo63784a52014-05-28 10:46:14 -070030} // namespace chromeos_update_manager
Alex Deymo94c06162014-03-21 20:34:46 -070031
Gilad Arnold1f847232014-04-07 12:07:49 -070032namespace policy {
33
34class DevicePolicy;
35
36} // namespace policy
37
Jay Srinivasan43488792012-06-19 00:25:31 -070038namespace chromeos_update_engine {
39
Jay Srinivasan55f50c22013-01-10 19:24:35 -080040// SystemState is the root class within the update engine. So we should avoid
41// any circular references in header file inclusion. Hence forward-declaring
42// the required classes.
Alex Deymo763e7db2015-08-27 21:08:08 -070043class BootControlInterface;
Alex Deymof6ee0162015-07-31 12:35:22 -070044class ConnectionManagerInterface;
Xiaochu Liu8ba486f2018-11-06 11:14:10 -080045class DlcServiceInterface;
Alex Deymo94c06162014-03-21 20:34:46 -070046class HardwareInterface;
Tianjie Xu282aa1f2017-09-05 13:42:45 -070047class MetricsReporterInterface;
Gilad Arnold1f847232014-04-07 12:07:49 -070048class OmahaRequestParams;
David Zeuthen526cb582013-08-06 12:26:18 -070049class P2PManager;
Alex Deymo94c06162014-03-21 20:34:46 -070050class PayloadStateInterface;
Sen Jiangb8c6a8f2016-06-07 17:33:17 -070051class PowerManagerInterface;
Alex Deymo94c06162014-03-21 20:34:46 -070052class PrefsInterface;
53class UpdateAttempter;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080054
Jay Srinivasan43488792012-06-19 00:25:31 -070055// An interface to global system context, including platform resources,
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080056// the current state of the system, high-level objects whose lifetime is same
57// as main, system interfaces, etc.
Jay Srinivasan43488792012-06-19 00:25:31 -070058// Carved out separately so it can be mocked for unit tests.
Jay Srinivasan43488792012-06-19 00:25:31 -070059class SystemState {
60 public:
Amin Hassani538bd592020-11-04 20:46:08 -080061 virtual ~SystemState() = default;
62
63 static SystemState* Get() {
64 CHECK(g_instance_);
65 return g_instance_.get();
66 }
Jay Srinivasan43488792012-06-19 00:25:31 -070067
Jay Srinivasan43488792012-06-19 00:25:31 -070068 // Sets or gets the latest device policy.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080069 virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0;
Gilad Arnold1f847232014-04-07 12:07:49 -070070 virtual const policy::DevicePolicy* device_policy() = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070071
Alex Deymo763e7db2015-08-27 21:08:08 -070072 // Gets the interface object for the bootloader control interface.
73 virtual BootControlInterface* boot_control() = 0;
74
David Zeuthenf413fe52013-04-22 14:04:39 -070075 // Gets the interface object for the clock.
76 virtual ClockInterface* clock() = 0;
77
Jay Srinivasan43488792012-06-19 00:25:31 -070078 // Gets the connection manager object.
Alex Deymof6ee0162015-07-31 12:35:22 -070079 virtual ConnectionManagerInterface* connection_manager() = 0;
Jay Srinivasanf0572052012-10-23 18:12:56 -070080
Alex Deymo42432912013-07-12 20:21:15 -070081 // Gets the hardware interface object.
82 virtual HardwareInterface* hardware() = 0;
83
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080084 // Gets the Metrics Library interface for reporting UMA stats.
Tianjie Xu282aa1f2017-09-05 13:42:45 -070085 virtual MetricsReporterInterface* metrics_reporter() = 0;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080086
87 // Gets the interface object for persisted store.
88 virtual PrefsInterface* prefs() = 0;
89
Chris Sosaaa18e162013-06-20 13:20:30 -070090 // Gets the interface object for the persisted store that persists across
91 // powerwashes. Please note that this should be used very seldomly and must
92 // be forwards and backwards compatible as powerwash is used to go back and
93 // forth in system versions.
94 virtual PrefsInterface* powerwash_safe_prefs() = 0;
95
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080096 // Gets the interface for the payload state object.
97 virtual PayloadStateInterface* payload_state() = 0;
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080098
Jay Srinivasan55f50c22013-01-10 19:24:35 -080099 // Returns a pointer to the update attempter object.
Gilad Arnold1f847232014-04-07 12:07:49 -0700100 virtual UpdateAttempter* update_attempter() = 0;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700101
102 // Returns a pointer to the object that stores the parameters that are
103 // common to all Omaha requests.
104 virtual OmahaRequestParams* request_params() = 0;
Chris Sosabe45bef2013-04-09 18:25:12 -0700105
David Zeuthen526cb582013-08-06 12:26:18 -0700106 // Returns a pointer to the P2PManager singleton.
107 virtual P2PManager* p2p_manager() = 0;
108
Alex Deymo63784a52014-05-28 10:46:14 -0700109 // Returns a pointer to the UpdateManager singleton.
110 virtual chromeos_update_manager::UpdateManager* update_manager() = 0;
Alex Deymo94c06162014-03-21 20:34:46 -0700111
Sen Jiangb8c6a8f2016-06-07 17:33:17 -0700112 // Gets the power manager object. Mocked during test.
113 virtual PowerManagerInterface* power_manager() = 0;
Alex Deymo30534502015-07-20 15:06:33 -0700114
Chris Sosabe45bef2013-04-09 18:25:12 -0700115 // If true, this is the first instance of the update engine since the system
116 // restarted. Important for tracking whether you are running instance of the
117 // update engine on first boot or due to a crash/restart.
118 virtual bool system_rebooted() = 0;
Xiaochu Liu8ba486f2018-11-06 11:14:10 -0800119
120 // Returns a pointer to the DlcServiceInterface singleton.
121 virtual DlcServiceInterface* dlcservice() = 0;
Amin Hassani538bd592020-11-04 20:46:08 -0800122
123 protected:
124 static std::unique_ptr<SystemState> g_instance_;
Jay Srinivasan43488792012-06-19 00:25:31 -0700125};
126
127} // namespace chromeos_update_engine
128
Amin Hassaniec7bc112020-10-29 16:47:58 -0700129#endif // UPDATE_ENGINE_COMMON_SYSTEM_STATE_H_