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