blob: 9eaa6cb9c9659bc93a95f45971da00a81d337c08 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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//
Jay Srinivasan55f50c22013-01-10 19:24:35 -080016
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_REAL_SYSTEM_STATE_H_
18#define UPDATE_ENGINE_REAL_SYSTEM_STATE_H_
Jay Srinivasan55f50c22013-01-10 19:24:35 -080019
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080020#include "update_engine/system_state.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080021
Ben Chan02f7c1d2014-10-18 15:18:02 -070022#include <memory>
23
Alex Deymoc83baf62014-04-02 17:43:35 -070024#include <metrics/metrics_library.h>
Alex Deymo63784a52014-05-28 10:46:14 -070025#include <policy/device_policy.h>
Gilad Arnold1f847232014-04-07 12:07:49 -070026
Alex Deymob8803bb2015-08-19 23:14:49 -070027#include "debugd/dbus-proxies.h"
28#include "login_manager/dbus-proxies.h"
29#include "power_manager/dbus-proxies.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080030#include "update_engine/clock.h"
31#include "update_engine/connection_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080032#include "update_engine/hardware.h"
Alex Deymo94c06162014-03-21 20:34:46 -070033#include "update_engine/p2p_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080034#include "update_engine/payload_state.h"
35#include "update_engine/prefs.h"
Alex Deymo30534502015-07-20 15:06:33 -070036#include "update_engine/shill_proxy.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080037#include "update_engine/update_attempter.h"
Alex Deymo63784a52014-05-28 10:46:14 -070038#include "update_engine/update_manager/update_manager.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080039
40namespace chromeos_update_engine {
41
42// A real implementation of the SystemStateInterface which is
43// used by the actual product code.
44class RealSystemState : public SystemState {
Alex Deymo94c06162014-03-21 20:34:46 -070045 public:
Gilad Arnold1f847232014-04-07 12:07:49 -070046 // Constructs all system objects that do not require separate initialization;
47 // see Initialize() below for the remaining ones.
Alex Deymo30534502015-07-20 15:06:33 -070048 explicit RealSystemState(const scoped_refptr<dbus::Bus>& bus);
Gilad Arnold1f847232014-04-07 12:07:49 -070049
50 // Initializes and sets systems objects that require an initialization
51 // separately from construction. Returns |true| on success.
Nam T. Nguyen7d623eb2014-05-13 16:06:28 -070052 bool Initialize();
Jay Srinivasan55f50c22013-01-10 19:24:35 -080053
Alex Vakulenko157fe302014-08-11 15:59:58 -070054 inline void set_device_policy(
Gilad Arnold1f847232014-04-07 12:07:49 -070055 const policy::DevicePolicy* device_policy) override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080056 device_policy_ = device_policy;
57 }
58
Alex Vakulenko157fe302014-08-11 15:59:58 -070059 inline const policy::DevicePolicy* device_policy() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080060 return device_policy_;
61 }
62
Alex Vakulenko157fe302014-08-11 15:59:58 -070063 inline ClockInterface* clock() override { return &clock_; }
David Zeuthenf413fe52013-04-22 14:04:39 -070064
Alex Deymof6ee0162015-07-31 12:35:22 -070065 inline ConnectionManagerInterface* connection_manager() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080066 return &connection_manager_;
67 }
68
Alex Vakulenko157fe302014-08-11 15:59:58 -070069 inline HardwareInterface* hardware() override { return &hardware_; }
Alex Deymo42432912013-07-12 20:21:15 -070070
Alex Vakulenko157fe302014-08-11 15:59:58 -070071 inline MetricsLibraryInterface* metrics_lib() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080072 return &metrics_lib_;
73 }
74
Alex Vakulenko157fe302014-08-11 15:59:58 -070075 inline PrefsInterface* prefs() override { return &prefs_; }
Jay Srinivasan55f50c22013-01-10 19:24:35 -080076
Alex Vakulenko157fe302014-08-11 15:59:58 -070077 inline PrefsInterface* powerwash_safe_prefs() override {
Chris Sosaaa18e162013-06-20 13:20:30 -070078 return &powerwash_safe_prefs_;
79 }
80
Alex Vakulenko157fe302014-08-11 15:59:58 -070081 inline PayloadStateInterface* payload_state() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080082 return &payload_state_;
83 }
84
Alex Vakulenko157fe302014-08-11 15:59:58 -070085 inline UpdateAttempter* update_attempter() override {
Gilad Arnold1f847232014-04-07 12:07:49 -070086 return &update_attempter_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080087 }
88
Alex Vakulenko157fe302014-08-11 15:59:58 -070089 inline OmahaRequestParams* request_params() override {
Jay Srinivasanae4697c2013-03-18 17:08:08 -070090 return &request_params_;
91 }
92
Alex Vakulenko157fe302014-08-11 15:59:58 -070093 inline P2PManager* p2p_manager() override { return p2p_manager_.get(); }
David Zeuthen526cb582013-08-06 12:26:18 -070094
Alex Vakulenko157fe302014-08-11 15:59:58 -070095 inline chromeos_update_manager::UpdateManager* update_manager() override {
Alex Deymo63784a52014-05-28 10:46:14 -070096 return update_manager_.get();
Alex Deymo94c06162014-03-21 20:34:46 -070097 }
98
Alex Deymo30534502015-07-20 15:06:33 -070099 inline org::chromium::PowerManagerProxyInterface* power_manager_proxy()
100 override {
101 return &power_manager_proxy_;
102 }
103
Alex Vakulenko157fe302014-08-11 15:59:58 -0700104 inline bool system_rebooted() override { return system_rebooted_; }
Chris Sosabe45bef2013-04-09 18:25:12 -0700105
Alex Deymo94c06162014-03-21 20:34:46 -0700106 private:
Alex Deymo30534502015-07-20 15:06:33 -0700107 // Real DBus proxies using the DBus connection.
108 org::chromium::debugdProxy debugd_proxy_;
109 org::chromium::PowerManagerProxy power_manager_proxy_;
110 org::chromium::SessionManagerInterfaceProxy session_manager_proxy_;
111 ShillProxy shill_proxy_;
112 LibCrosProxy libcros_proxy_;
113
David Zeuthenf413fe52013-04-22 14:04:39 -0700114 // Interface for the clock.
115 Clock clock_;
116
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800117 // The latest device policy object from the policy provider.
Alex Deymo30534502015-07-20 15:06:33 -0700118 const policy::DevicePolicy* device_policy_{nullptr};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800119
Alex Deymo30534502015-07-20 15:06:33 -0700120 // The connection manager object that makes download decisions depending on
121 // the current type of connection.
122 ConnectionManager connection_manager_{&shill_proxy_, this};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800123
Alex Deymo42432912013-07-12 20:21:15 -0700124 // Interface for the hardware functions.
125 Hardware hardware_;
126
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800127 // The Metrics Library interface for reporting UMA stats.
128 MetricsLibrary metrics_lib_;
129
130 // Interface for persisted store.
131 Prefs prefs_;
132
Chris Sosaaa18e162013-06-20 13:20:30 -0700133 // Interface for persisted store that persists across powerwashes.
134 Prefs powerwash_safe_prefs_;
135
Alex Deymo30534502015-07-20 15:06:33 -0700136 // All state pertaining to payload state such as response, URL, backoff
137 // states.
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800138 PayloadState payload_state_;
139
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800140 // Pointer to the update attempter object.
Alex Deymo30534502015-07-20 15:06:33 -0700141 UpdateAttempter update_attempter_{this, &libcros_proxy_, &debugd_proxy_};
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700142
143 // Common parameters for all Omaha requests.
Alex Deymo30534502015-07-20 15:06:33 -0700144 OmahaRequestParams request_params_{this};
Chris Sosabe45bef2013-04-09 18:25:12 -0700145
Ben Chan02f7c1d2014-10-18 15:18:02 -0700146 std::unique_ptr<P2PManager> p2p_manager_;
David Zeuthen526cb582013-08-06 12:26:18 -0700147
Ben Chan02f7c1d2014-10-18 15:18:02 -0700148 std::unique_ptr<chromeos_update_manager::UpdateManager> update_manager_;
Alex Deymo94c06162014-03-21 20:34:46 -0700149
Alex Deymoc83baf62014-04-02 17:43:35 -0700150 policy::PolicyProvider policy_provider_;
151
Chris Sosabe45bef2013-04-09 18:25:12 -0700152 // If true, this is the first instance of the update engine since the system
153 // rebooted. Important for tracking whether you are running instance of the
154 // update engine on first boot or due to a crash/restart.
Alex Deymo30534502015-07-20 15:06:33 -0700155 bool system_rebooted_{false};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800156};
157
158} // namespace chromeos_update_engine
159
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700160#endif // UPDATE_ENGINE_REAL_SYSTEM_STATE_H_