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 namespace chromeos_update_manager { 21 22 class UpdateManager; 23 24 } // namespace chromeos_update_manager 25 26 namespace policy { 27 28 class DevicePolicy; 29 30 } // namespace policy 31 32 namespace chromeos_update_engine { 33 34 // SystemState is the root class within the update engine. So we should avoid 35 // any circular references in header file inclusion. Hence forward-declaring 36 // the required classes. 37 class BootControlInterface; 38 class ClockInterface; 39 class ConnectionManagerInterface; 40 class DlcServiceInterface; 41 class HardwareInterface; 42 class MetricsReporterInterface; 43 class OmahaRequestParams; 44 class P2PManager; 45 class PayloadStateInterface; 46 class PowerManagerInterface; 47 class PrefsInterface; 48 class UpdateAttempter; 49 50 // An interface to global system context, including platform resources, 51 // the current state of the system, high-level objects whose lifetime is same 52 // as main, system interfaces, etc. 53 // Carved out separately so it can be mocked for unit tests. 54 // Currently it has only one method, but we should start migrating other 55 // methods to use this as and when needed to unit test them. 56 // TODO(jaysri): Consider renaming this to something like GlobalContext. 57 class SystemState { 58 public: 59 // Destructs this object. ~SystemState()60 virtual ~SystemState() {} 61 62 // Sets or gets the latest device policy. 63 virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0; 64 virtual const policy::DevicePolicy* device_policy() = 0; 65 66 // Gets the interface object for the bootloader control interface. 67 virtual BootControlInterface* boot_control() = 0; 68 69 // Gets the interface object for the clock. 70 virtual ClockInterface* clock() = 0; 71 72 // Gets the connection manager object. 73 virtual ConnectionManagerInterface* connection_manager() = 0; 74 75 // Gets the hardware interface object. 76 virtual HardwareInterface* hardware() = 0; 77 78 // Gets the Metrics Library interface for reporting UMA stats. 79 virtual MetricsReporterInterface* metrics_reporter() = 0; 80 81 // Gets the interface object for persisted store. 82 virtual PrefsInterface* prefs() = 0; 83 84 // Gets the interface object for the persisted store that persists across 85 // powerwashes. Please note that this should be used very seldomly and must 86 // be forwards and backwards compatible as powerwash is used to go back and 87 // forth in system versions. 88 virtual PrefsInterface* powerwash_safe_prefs() = 0; 89 90 // Gets the interface for the payload state object. 91 virtual PayloadStateInterface* payload_state() = 0; 92 93 // Returns a pointer to the update attempter object. 94 virtual UpdateAttempter* update_attempter() = 0; 95 96 // Returns a pointer to the object that stores the parameters that are 97 // common to all Omaha requests. 98 virtual OmahaRequestParams* request_params() = 0; 99 100 // Returns a pointer to the P2PManager singleton. 101 virtual P2PManager* p2p_manager() = 0; 102 103 // Returns a pointer to the UpdateManager singleton. 104 virtual chromeos_update_manager::UpdateManager* update_manager() = 0; 105 106 // Gets the power manager object. Mocked during test. 107 virtual PowerManagerInterface* power_manager() = 0; 108 109 // If true, this is the first instance of the update engine since the system 110 // restarted. Important for tracking whether you are running instance of the 111 // update engine on first boot or due to a crash/restart. 112 virtual bool system_rebooted() = 0; 113 114 // Returns a pointer to the DlcServiceInterface singleton. 115 virtual DlcServiceInterface* dlcservice() = 0; 116 }; 117 118 } // namespace chromeos_update_engine 119 120 #endif // UPDATE_ENGINE_SYSTEM_STATE_H_ 121