real_system_state.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // Copyright (C) 2013 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. #ifndef UPDATE_ENGINE_REAL_SYSTEM_STATE_H_
  17. #define UPDATE_ENGINE_REAL_SYSTEM_STATE_H_
  18. #include "update_engine/system_state.h"
  19. #include <memory>
  20. #include <set>
  21. #include <policy/device_policy.h>
  22. #if USE_CHROME_KIOSK_APP
  23. #include <kiosk-app/dbus-proxies.h>
  24. #endif // USE_CHROME_KIOSK_APP
  25. #include "update_engine/certificate_checker.h"
  26. #include "update_engine/common/boot_control_interface.h"
  27. #include "update_engine/common/clock.h"
  28. #include "update_engine/common/dlcservice_interface.h"
  29. #include "update_engine/common/hardware_interface.h"
  30. #include "update_engine/common/prefs.h"
  31. #include "update_engine/connection_manager_interface.h"
  32. #include "update_engine/daemon_state_interface.h"
  33. #include "update_engine/metrics_reporter_interface.h"
  34. #include "update_engine/metrics_reporter_omaha.h"
  35. #include "update_engine/p2p_manager.h"
  36. #include "update_engine/payload_state.h"
  37. #include "update_engine/power_manager_interface.h"
  38. #include "update_engine/update_attempter.h"
  39. #include "update_engine/update_manager/update_manager.h"
  40. namespace chromeos_update_engine {
  41. // A real implementation of the SystemStateInterface which is
  42. // used by the actual product code.
  43. class RealSystemState : public SystemState, public DaemonStateInterface {
  44. public:
  45. // Constructs all system objects that do not require separate initialization;
  46. // see Initialize() below for the remaining ones.
  47. RealSystemState() = default;
  48. ~RealSystemState() override;
  49. // Initializes and sets systems objects that require an initialization
  50. // separately from construction. Returns |true| on success.
  51. bool Initialize();
  52. // DaemonStateInterface overrides.
  53. // Start the periodic update attempts. Must be called at the beginning of the
  54. // program to start the periodic update check process.
  55. bool StartUpdater() override;
  56. void AddObserver(ServiceObserverInterface* observer) override;
  57. void RemoveObserver(ServiceObserverInterface* observer) override;
  58. const std::set<ServiceObserverInterface*>& service_observers() override {
  59. CHECK(update_attempter_.get());
  60. return update_attempter_->service_observers();
  61. }
  62. // SystemState overrides.
  63. inline void set_device_policy(
  64. const policy::DevicePolicy* device_policy) override {
  65. device_policy_ = device_policy;
  66. }
  67. inline const policy::DevicePolicy* device_policy() override {
  68. return device_policy_;
  69. }
  70. inline BootControlInterface* boot_control() override {
  71. return boot_control_.get();
  72. }
  73. inline ClockInterface* clock() override { return &clock_; }
  74. inline ConnectionManagerInterface* connection_manager() override {
  75. return connection_manager_.get();
  76. }
  77. inline HardwareInterface* hardware() override { return hardware_.get(); }
  78. inline MetricsReporterInterface* metrics_reporter() override {
  79. return &metrics_reporter_;
  80. }
  81. inline PrefsInterface* prefs() override { return prefs_.get(); }
  82. inline PrefsInterface* powerwash_safe_prefs() override {
  83. return powerwash_safe_prefs_.get();
  84. }
  85. inline PayloadStateInterface* payload_state() override {
  86. return &payload_state_;
  87. }
  88. inline UpdateAttempter* update_attempter() override {
  89. return update_attempter_.get();
  90. }
  91. inline OmahaRequestParams* request_params() override {
  92. return &request_params_;
  93. }
  94. inline P2PManager* p2p_manager() override { return p2p_manager_.get(); }
  95. inline chromeos_update_manager::UpdateManager* update_manager() override {
  96. return update_manager_.get();
  97. }
  98. inline PowerManagerInterface* power_manager() override {
  99. return power_manager_.get();
  100. }
  101. inline bool system_rebooted() override { return system_rebooted_; }
  102. inline DlcServiceInterface* dlcservice() override {
  103. return dlcservice_.get();
  104. }
  105. private:
  106. // Real DBus proxies using the DBus connection.
  107. #if USE_CHROME_KIOSK_APP
  108. std::unique_ptr<org::chromium::KioskAppServiceInterfaceProxy>
  109. kiosk_app_proxy_;
  110. #endif // USE_CHROME_KIOSK_APP
  111. // Interface for the power manager.
  112. std::unique_ptr<PowerManagerInterface> power_manager_;
  113. // Interface for dlcservice.
  114. std::unique_ptr<DlcServiceInterface> dlcservice_;
  115. // Interface for the clock.
  116. std::unique_ptr<BootControlInterface> boot_control_;
  117. // Interface for the clock.
  118. Clock clock_;
  119. // The latest device policy object from the policy provider.
  120. const policy::DevicePolicy* device_policy_{nullptr};
  121. // The connection manager object that makes download decisions depending on
  122. // the current type of connection.
  123. std::unique_ptr<ConnectionManagerInterface> connection_manager_;
  124. // Interface for the hardware functions.
  125. std::unique_ptr<HardwareInterface> hardware_;
  126. // The Metrics reporter for reporting UMA stats.
  127. MetricsReporterOmaha metrics_reporter_;
  128. // Interface for persisted store.
  129. std::unique_ptr<PrefsInterface> prefs_;
  130. // Interface for persisted store that persists across powerwashes.
  131. std::unique_ptr<PrefsInterface> powerwash_safe_prefs_;
  132. // All state pertaining to payload state such as response, URL, backoff
  133. // states.
  134. PayloadState payload_state_;
  135. // OpenSSLWrapper and CertificateChecker used for checking SSL certificates.
  136. OpenSSLWrapper openssl_wrapper_;
  137. std::unique_ptr<CertificateChecker> certificate_checker_;
  138. // Pointer to the update attempter object.
  139. std::unique_ptr<UpdateAttempter> update_attempter_;
  140. // Common parameters for all Omaha requests.
  141. OmahaRequestParams request_params_{this};
  142. std::unique_ptr<P2PManager> p2p_manager_;
  143. std::unique_ptr<chromeos_update_manager::UpdateManager> update_manager_;
  144. policy::PolicyProvider policy_provider_;
  145. // If true, this is the first instance of the update engine since the system
  146. // rebooted. Important for tracking whether you are running instance of the
  147. // update engine on first boot or due to a crash/restart.
  148. bool system_rebooted_{false};
  149. ActionProcessor processor_;
  150. };
  151. } // namespace chromeos_update_engine
  152. #endif // UPDATE_ENGINE_REAL_SYSTEM_STATE_H_