• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMMON_SYSTEM_STATE_H_
18 #define UPDATE_ENGINE_COMMON_SYSTEM_STATE_H_
19 
20 #include <memory>
21 
22 #include <base/logging.h>
23 
24 #include "update_engine/common/clock_interface.h"
25 #include "update_engine/common/prefs_interface.h"
26 
27 namespace chromeos_update_manager {
28 
29 class UpdateManager;
30 
31 }  // namespace chromeos_update_manager
32 
33 namespace policy {
34 
35 class DevicePolicy;
36 
37 }  // namespace policy
38 
39 namespace chromeos_update_engine {
40 
41 // SystemState is the root class within the update engine. So we should avoid
42 // any circular references in header file inclusion. Hence forward-declaring
43 // the required classes.
44 class BootControlInterface;
45 class ConnectionManagerInterface;
46 class DlcServiceInterface;
47 class HardwareInterface;
48 class MetricsReporterInterface;
49 class OmahaRequestParams;
50 class P2PManager;
51 class PayloadStateInterface;
52 class PowerManagerInterface;
53 class UpdateAttempter;
54 
55 // An interface to global system context, including platform resources,
56 // the current state of the system, high-level objects whose lifetime is same
57 // as main, system interfaces, etc.
58 // Carved out separately so it can be mocked for unit tests.
59 class SystemState {
60  public:
61   virtual ~SystemState() = default;
62 
Get()63   static SystemState* Get() {
64     CHECK(g_pointer_ != nullptr);
65     return g_pointer_;
66   }
67 
68   // Sets or gets the latest device policy.
69   virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0;
70   virtual const policy::DevicePolicy* device_policy() = 0;
71 
72   // Gets the interface object for the bootloader control interface.
73   virtual BootControlInterface* boot_control() = 0;
74 
75   // Gets the interface object for the clock.
76   virtual ClockInterface* clock() = 0;
77 
78   // Gets the connection manager object.
79   virtual ConnectionManagerInterface* connection_manager() = 0;
80 
81   // Gets the hardware interface object.
82   virtual HardwareInterface* hardware() = 0;
83 
84   // Gets the Metrics Library interface for reporting UMA stats.
85   virtual MetricsReporterInterface* metrics_reporter() = 0;
86 
87   // Gets the interface object for persisted store.
88   virtual PrefsInterface* prefs() = 0;
89 
90   // 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 
96   // Gets the interface for the payload state object.
97   virtual PayloadStateInterface* payload_state() = 0;
98 
99   // Returns a pointer to the update attempter object.
100   virtual UpdateAttempter* update_attempter() = 0;
101 
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;
105 
106   // Returns a pointer to the P2PManager singleton.
107   virtual P2PManager* p2p_manager() = 0;
108 
109   // Returns a pointer to the UpdateManager singleton.
110   virtual chromeos_update_manager::UpdateManager* update_manager() = 0;
111 
112   // Gets the power manager object. Mocked during test.
113   virtual PowerManagerInterface* power_manager() = 0;
114 
115   // 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;
119 
120   // Returns a pointer to the DlcServiceInterface singleton.
121   virtual DlcServiceInterface* dlcservice() = 0;
122 
123  protected:
124   static SystemState* g_pointer_;
125 };
126 
127 }  // namespace chromeos_update_engine
128 
129 #endif  // UPDATE_ENGINE_COMMON_SYSTEM_STATE_H_
130