xref: /aosp_15_r20/system/update_engine/common/system_state.h (revision 5a9231315b4521097b8dc3750bc806fcafe0c72f)
1*5a923131SAndroid Build Coastguard Worker //
2*5a923131SAndroid Build Coastguard Worker // Copyright (C) 2012 The Android Open Source Project
3*5a923131SAndroid Build Coastguard Worker //
4*5a923131SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
5*5a923131SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
6*5a923131SAndroid Build Coastguard Worker // You may obtain a copy of the License at
7*5a923131SAndroid Build Coastguard Worker //
8*5a923131SAndroid Build Coastguard Worker //      http://www.apache.org/licenses/LICENSE-2.0
9*5a923131SAndroid Build Coastguard Worker //
10*5a923131SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
11*5a923131SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
12*5a923131SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*5a923131SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
14*5a923131SAndroid Build Coastguard Worker // limitations under the License.
15*5a923131SAndroid Build Coastguard Worker //
16*5a923131SAndroid Build Coastguard Worker 
17*5a923131SAndroid Build Coastguard Worker #ifndef UPDATE_ENGINE_COMMON_SYSTEM_STATE_H_
18*5a923131SAndroid Build Coastguard Worker #define UPDATE_ENGINE_COMMON_SYSTEM_STATE_H_
19*5a923131SAndroid Build Coastguard Worker 
20*5a923131SAndroid Build Coastguard Worker #include <memory>
21*5a923131SAndroid Build Coastguard Worker 
22*5a923131SAndroid Build Coastguard Worker #include <base/logging.h>
23*5a923131SAndroid Build Coastguard Worker 
24*5a923131SAndroid Build Coastguard Worker #include "update_engine/common/clock_interface.h"
25*5a923131SAndroid Build Coastguard Worker #include "update_engine/common/prefs_interface.h"
26*5a923131SAndroid Build Coastguard Worker 
27*5a923131SAndroid Build Coastguard Worker namespace chromeos_update_manager {
28*5a923131SAndroid Build Coastguard Worker 
29*5a923131SAndroid Build Coastguard Worker class UpdateManager;
30*5a923131SAndroid Build Coastguard Worker 
31*5a923131SAndroid Build Coastguard Worker }  // namespace chromeos_update_manager
32*5a923131SAndroid Build Coastguard Worker 
33*5a923131SAndroid Build Coastguard Worker namespace policy {
34*5a923131SAndroid Build Coastguard Worker 
35*5a923131SAndroid Build Coastguard Worker class DevicePolicy;
36*5a923131SAndroid Build Coastguard Worker 
37*5a923131SAndroid Build Coastguard Worker }  // namespace policy
38*5a923131SAndroid Build Coastguard Worker 
39*5a923131SAndroid Build Coastguard Worker namespace chromeos_update_engine {
40*5a923131SAndroid Build Coastguard Worker 
41*5a923131SAndroid Build Coastguard Worker // SystemState is the root class within the update engine. So we should avoid
42*5a923131SAndroid Build Coastguard Worker // any circular references in header file inclusion. Hence forward-declaring
43*5a923131SAndroid Build Coastguard Worker // the required classes.
44*5a923131SAndroid Build Coastguard Worker class BootControlInterface;
45*5a923131SAndroid Build Coastguard Worker class ConnectionManagerInterface;
46*5a923131SAndroid Build Coastguard Worker class DlcServiceInterface;
47*5a923131SAndroid Build Coastguard Worker class HardwareInterface;
48*5a923131SAndroid Build Coastguard Worker class MetricsReporterInterface;
49*5a923131SAndroid Build Coastguard Worker class OmahaRequestParams;
50*5a923131SAndroid Build Coastguard Worker class P2PManager;
51*5a923131SAndroid Build Coastguard Worker class PayloadStateInterface;
52*5a923131SAndroid Build Coastguard Worker class PowerManagerInterface;
53*5a923131SAndroid Build Coastguard Worker class UpdateAttempter;
54*5a923131SAndroid Build Coastguard Worker 
55*5a923131SAndroid Build Coastguard Worker // An interface to global system context, including platform resources,
56*5a923131SAndroid Build Coastguard Worker // the current state of the system, high-level objects whose lifetime is same
57*5a923131SAndroid Build Coastguard Worker // as main, system interfaces, etc.
58*5a923131SAndroid Build Coastguard Worker // Carved out separately so it can be mocked for unit tests.
59*5a923131SAndroid Build Coastguard Worker class SystemState {
60*5a923131SAndroid Build Coastguard Worker  public:
61*5a923131SAndroid Build Coastguard Worker   virtual ~SystemState() = default;
62*5a923131SAndroid Build Coastguard Worker 
Get()63*5a923131SAndroid Build Coastguard Worker   static SystemState* Get() {
64*5a923131SAndroid Build Coastguard Worker     CHECK(g_pointer_ != nullptr);
65*5a923131SAndroid Build Coastguard Worker     return g_pointer_;
66*5a923131SAndroid Build Coastguard Worker   }
67*5a923131SAndroid Build Coastguard Worker 
68*5a923131SAndroid Build Coastguard Worker   // Sets or gets the latest device policy.
69*5a923131SAndroid Build Coastguard Worker   virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0;
70*5a923131SAndroid Build Coastguard Worker   virtual const policy::DevicePolicy* device_policy() = 0;
71*5a923131SAndroid Build Coastguard Worker 
72*5a923131SAndroid Build Coastguard Worker   // Gets the interface object for the bootloader control interface.
73*5a923131SAndroid Build Coastguard Worker   virtual BootControlInterface* boot_control() = 0;
74*5a923131SAndroid Build Coastguard Worker 
75*5a923131SAndroid Build Coastguard Worker   // Gets the interface object for the clock.
76*5a923131SAndroid Build Coastguard Worker   virtual ClockInterface* clock() = 0;
77*5a923131SAndroid Build Coastguard Worker 
78*5a923131SAndroid Build Coastguard Worker   // Gets the connection manager object.
79*5a923131SAndroid Build Coastguard Worker   virtual ConnectionManagerInterface* connection_manager() = 0;
80*5a923131SAndroid Build Coastguard Worker 
81*5a923131SAndroid Build Coastguard Worker   // Gets the hardware interface object.
82*5a923131SAndroid Build Coastguard Worker   virtual HardwareInterface* hardware() = 0;
83*5a923131SAndroid Build Coastguard Worker 
84*5a923131SAndroid Build Coastguard Worker   // Gets the Metrics Library interface for reporting UMA stats.
85*5a923131SAndroid Build Coastguard Worker   virtual MetricsReporterInterface* metrics_reporter() = 0;
86*5a923131SAndroid Build Coastguard Worker 
87*5a923131SAndroid Build Coastguard Worker   // Gets the interface object for persisted store.
88*5a923131SAndroid Build Coastguard Worker   virtual PrefsInterface* prefs() = 0;
89*5a923131SAndroid Build Coastguard Worker 
90*5a923131SAndroid Build Coastguard Worker   // Gets the interface object for the persisted store that persists across
91*5a923131SAndroid Build Coastguard Worker   // powerwashes. Please note that this should be used very seldomly and must
92*5a923131SAndroid Build Coastguard Worker   // be forwards and backwards compatible as powerwash is used to go back and
93*5a923131SAndroid Build Coastguard Worker   // forth in system versions.
94*5a923131SAndroid Build Coastguard Worker   virtual PrefsInterface* powerwash_safe_prefs() = 0;
95*5a923131SAndroid Build Coastguard Worker 
96*5a923131SAndroid Build Coastguard Worker   // Gets the interface for the payload state object.
97*5a923131SAndroid Build Coastguard Worker   virtual PayloadStateInterface* payload_state() = 0;
98*5a923131SAndroid Build Coastguard Worker 
99*5a923131SAndroid Build Coastguard Worker   // Returns a pointer to the update attempter object.
100*5a923131SAndroid Build Coastguard Worker   virtual UpdateAttempter* update_attempter() = 0;
101*5a923131SAndroid Build Coastguard Worker 
102*5a923131SAndroid Build Coastguard Worker   // Returns a pointer to the object that stores the parameters that are
103*5a923131SAndroid Build Coastguard Worker   // common to all Omaha requests.
104*5a923131SAndroid Build Coastguard Worker   virtual OmahaRequestParams* request_params() = 0;
105*5a923131SAndroid Build Coastguard Worker 
106*5a923131SAndroid Build Coastguard Worker   // Returns a pointer to the P2PManager singleton.
107*5a923131SAndroid Build Coastguard Worker   virtual P2PManager* p2p_manager() = 0;
108*5a923131SAndroid Build Coastguard Worker 
109*5a923131SAndroid Build Coastguard Worker   // Returns a pointer to the UpdateManager singleton.
110*5a923131SAndroid Build Coastguard Worker   virtual chromeos_update_manager::UpdateManager* update_manager() = 0;
111*5a923131SAndroid Build Coastguard Worker 
112*5a923131SAndroid Build Coastguard Worker   // Gets the power manager object. Mocked during test.
113*5a923131SAndroid Build Coastguard Worker   virtual PowerManagerInterface* power_manager() = 0;
114*5a923131SAndroid Build Coastguard Worker 
115*5a923131SAndroid Build Coastguard Worker   // If true, this is the first instance of the update engine since the system
116*5a923131SAndroid Build Coastguard Worker   // restarted. Important for tracking whether you are running instance of the
117*5a923131SAndroid Build Coastguard Worker   // update engine on first boot or due to a crash/restart.
118*5a923131SAndroid Build Coastguard Worker   virtual bool system_rebooted() = 0;
119*5a923131SAndroid Build Coastguard Worker 
120*5a923131SAndroid Build Coastguard Worker   // Returns a pointer to the DlcServiceInterface singleton.
121*5a923131SAndroid Build Coastguard Worker   virtual DlcServiceInterface* dlcservice() = 0;
122*5a923131SAndroid Build Coastguard Worker 
123*5a923131SAndroid Build Coastguard Worker  protected:
124*5a923131SAndroid Build Coastguard Worker   static SystemState* g_pointer_;
125*5a923131SAndroid Build Coastguard Worker };
126*5a923131SAndroid Build Coastguard Worker 
127*5a923131SAndroid Build Coastguard Worker }  // namespace chromeos_update_engine
128*5a923131SAndroid Build Coastguard Worker 
129*5a923131SAndroid Build Coastguard Worker #endif  // UPDATE_ENGINE_COMMON_SYSTEM_STATE_H_
130