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 //
16 
17 #ifndef UPDATE_ENGINE_SYSTEM_STATE_H_
18 #define UPDATE_ENGINE_SYSTEM_STATE_H_
19 
20 class MetricsLibraryInterface;
21 
22 namespace chromeos_update_manager {
23 
24 class UpdateManager;
25 
26 }  // namespace chromeos_update_manager
27 
28 namespace policy {
29 
30 class DevicePolicy;
31 
32 }  // namespace policy
33 
34 namespace chromeos_update_engine {
35 
36 // 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.
39 class BootControlInterface;
40 class ClockInterface;
41 class ConnectionManagerInterface;
42 class HardwareInterface;
43 class OmahaRequestParams;
44 class P2PManager;
45 class PayloadStateInterface;
46 class PowerManagerInterface;
47 class PrefsInterface;
48 class UpdateAttempter;
49 class WeaveServiceInterface;
50 
51 // An interface to global system context, including platform resources,
52 // the current state of the system, high-level objects whose lifetime is same
53 // as main, system interfaces, etc.
54 // 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.
57 // TODO(jaysri): Consider renaming this to something like GlobalContext.
58 class SystemState {
59  public:
60   // Destructs this object.
~SystemState()61   virtual ~SystemState() {}
62 
63   // Sets or gets the latest device policy.
64   virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0;
65   virtual const policy::DevicePolicy* device_policy() = 0;
66 
67   // Gets the interface object for the bootloader control interface.
68   virtual BootControlInterface* boot_control() = 0;
69 
70   // Gets the interface object for the clock.
71   virtual ClockInterface* clock() = 0;
72 
73   // Gets the connection manager object.
74   virtual ConnectionManagerInterface* connection_manager() = 0;
75 
76   // Gets the hardware interface object.
77   virtual HardwareInterface* hardware() = 0;
78 
79   // Gets the Metrics Library interface for reporting UMA stats.
80   virtual MetricsLibraryInterface* metrics_lib() = 0;
81 
82   // Gets the interface object for persisted store.
83   virtual PrefsInterface* prefs() = 0;
84 
85   // 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 
91   // Gets the interface for the payload state object.
92   virtual PayloadStateInterface* payload_state() = 0;
93 
94   // Returns a pointer to the update attempter object.
95   virtual UpdateAttempter* update_attempter() = 0;
96 
97   // Returns a pointer to the WeaveServiceInterface class or nullptr if none.
98   virtual WeaveServiceInterface* weave_service() = 0;
99 
100   // Returns a pointer to the object that stores the parameters that are
101   // common to all Omaha requests.
102   virtual OmahaRequestParams* request_params() = 0;
103 
104   // Returns a pointer to the P2PManager singleton.
105   virtual P2PManager* p2p_manager() = 0;
106 
107   // Returns a pointer to the UpdateManager singleton.
108   virtual chromeos_update_manager::UpdateManager* update_manager() = 0;
109 
110   // Gets the power manager object. Mocked during test.
111   virtual PowerManagerInterface* power_manager() = 0;
112 
113   // 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;
117 };
118 
119 }  // namespace chromeos_update_engine
120 
121 #endif  // UPDATE_ENGINE_SYSTEM_STATE_H_
122