blob: 4d040ec06ce93a40bd8059299953f254bff8d6db [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
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_SYSTEM_STATE_H_
18#define UPDATE_ENGINE_SYSTEM_STATE_H_
Jay Srinivasan43488792012-06-19 00:25:31 -070019
Gilad Arnold1f847232014-04-07 12:07:49 -070020class MetricsLibraryInterface;
Gilad Arnoldf3815bb2013-01-14 11:58:24 -080021
Alex Deymo63784a52014-05-28 10:46:14 -070022namespace chromeos_update_manager {
Alex Deymo94c06162014-03-21 20:34:46 -070023
Alex Deymo63784a52014-05-28 10:46:14 -070024class UpdateManager;
Alex Deymo94c06162014-03-21 20:34:46 -070025
Alex Deymo63784a52014-05-28 10:46:14 -070026} // namespace chromeos_update_manager
Alex Deymo94c06162014-03-21 20:34:46 -070027
Gilad Arnold1f847232014-04-07 12:07:49 -070028namespace policy {
29
30class DevicePolicy;
31
32} // namespace policy
33
Jay Srinivasan43488792012-06-19 00:25:31 -070034namespace chromeos_update_engine {
35
Jay Srinivasan55f50c22013-01-10 19:24:35 -080036// SystemState is the root class within the update engine. So we should avoid
37// any circular references in header file inclusion. Hence forward-declaring
38// the required classes.
Alex Deymo763e7db2015-08-27 21:08:08 -070039class BootControlInterface;
David Zeuthenf413fe52013-04-22 14:04:39 -070040class ClockInterface;
Alex Deymof6ee0162015-07-31 12:35:22 -070041class ConnectionManagerInterface;
Alex Deymo94c06162014-03-21 20:34:46 -070042class HardwareInterface;
Gilad Arnold1f847232014-04-07 12:07:49 -070043class OmahaRequestParams;
David Zeuthen526cb582013-08-06 12:26:18 -070044class P2PManager;
Alex Deymo94c06162014-03-21 20:34:46 -070045class PayloadStateInterface;
Sen Jiangb8c6a8f2016-06-07 17:33:17 -070046class PowerManagerInterface;
Alex Deymo94c06162014-03-21 20:34:46 -070047class PrefsInterface;
48class UpdateAttempter;
Alex Deymof7ead812015-10-23 17:37:27 -070049class WeaveServiceInterface;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080050
Jay Srinivasan43488792012-06-19 00:25:31 -070051// An interface to global system context, including platform resources,
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080052// the current state of the system, high-level objects whose lifetime is same
53// as main, system interfaces, etc.
Jay Srinivasan43488792012-06-19 00:25:31 -070054// Carved out separately so it can be mocked for unit tests.
55// Currently it has only one method, but we should start migrating other
56// methods to use this as and when needed to unit test them.
Alex Deymo94c06162014-03-21 20:34:46 -070057// TODO(jaysri): Consider renaming this to something like GlobalContext.
Jay Srinivasan43488792012-06-19 00:25:31 -070058class SystemState {
59 public:
60 // Destructs this object.
61 virtual ~SystemState() {}
62
Jay Srinivasan43488792012-06-19 00:25:31 -070063 // Sets or gets the latest device policy.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080064 virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0;
Gilad Arnold1f847232014-04-07 12:07:49 -070065 virtual const policy::DevicePolicy* device_policy() = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070066
Alex Deymo763e7db2015-08-27 21:08:08 -070067 // Gets the interface object for the bootloader control interface.
68 virtual BootControlInterface* boot_control() = 0;
69
David Zeuthenf413fe52013-04-22 14:04:39 -070070 // Gets the interface object for the clock.
71 virtual ClockInterface* clock() = 0;
72
Jay Srinivasan43488792012-06-19 00:25:31 -070073 // Gets the connection manager object.
Alex Deymof6ee0162015-07-31 12:35:22 -070074 virtual ConnectionManagerInterface* connection_manager() = 0;
Jay Srinivasanf0572052012-10-23 18:12:56 -070075
Alex Deymo42432912013-07-12 20:21:15 -070076 // Gets the hardware interface object.
77 virtual HardwareInterface* hardware() = 0;
78
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080079 // Gets the Metrics Library interface for reporting UMA stats.
Jay Srinivasanf0572052012-10-23 18:12:56 -070080 virtual MetricsLibraryInterface* metrics_lib() = 0;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080081
82 // Gets the interface object for persisted store.
83 virtual PrefsInterface* prefs() = 0;
84
Chris Sosaaa18e162013-06-20 13:20:30 -070085 // Gets the interface object for the persisted store that persists across
86 // powerwashes. Please note that this should be used very seldomly and must
87 // be forwards and backwards compatible as powerwash is used to go back and
88 // forth in system versions.
89 virtual PrefsInterface* powerwash_safe_prefs() = 0;
90
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080091 // Gets the interface for the payload state object.
92 virtual PayloadStateInterface* payload_state() = 0;
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080093
Jay Srinivasan55f50c22013-01-10 19:24:35 -080094 // Returns a pointer to the update attempter object.
Gilad Arnold1f847232014-04-07 12:07:49 -070095 virtual UpdateAttempter* update_attempter() = 0;
Jay Srinivasanae4697c2013-03-18 17:08:08 -070096
Alex Deymof7ead812015-10-23 17:37:27 -070097 // Returns a pointer to the WeaveServiceInterface class or nullptr if none.
98 virtual WeaveServiceInterface* weave_service() = 0;
99
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700100 // Returns a pointer to the object that stores the parameters that are
101 // common to all Omaha requests.
102 virtual OmahaRequestParams* request_params() = 0;
Chris Sosabe45bef2013-04-09 18:25:12 -0700103
David Zeuthen526cb582013-08-06 12:26:18 -0700104 // Returns a pointer to the P2PManager singleton.
105 virtual P2PManager* p2p_manager() = 0;
106
Alex Deymo63784a52014-05-28 10:46:14 -0700107 // Returns a pointer to the UpdateManager singleton.
108 virtual chromeos_update_manager::UpdateManager* update_manager() = 0;
Alex Deymo94c06162014-03-21 20:34:46 -0700109
Sen Jiangb8c6a8f2016-06-07 17:33:17 -0700110 // Gets the power manager object. Mocked during test.
111 virtual PowerManagerInterface* power_manager() = 0;
Alex Deymo30534502015-07-20 15:06:33 -0700112
Chris Sosabe45bef2013-04-09 18:25:12 -0700113 // If true, this is the first instance of the update engine since the system
114 // restarted. Important for tracking whether you are running instance of the
115 // update engine on first boot or due to a crash/restart.
116 virtual bool system_rebooted() = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -0700117};
118
119} // namespace chromeos_update_engine
120
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700121#endif // UPDATE_ENGINE_SYSTEM_STATE_H_