blob: fd2a684a1d4d99a57966a9627300ab6d3789d675 [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 Deymod6deb1d2015-08-28 15:54:37 -070024#include <debugd/dbus-proxies.h>
Alex Deymoc83baf62014-04-02 17:43:35 -070025#include <metrics/metrics_library.h>
Alex Deymo63784a52014-05-28 10:46:14 -070026#include <policy/device_policy.h>
Alex Deymod6deb1d2015-08-28 15:54:37 -070027#include <power_manager/dbus-proxies.h>
28#include <session_manager/dbus-proxies.h>
Gilad Arnold1f847232014-04-07 12:07:49 -070029
Alex Deymo763e7db2015-08-27 21:08:08 -070030#include "update_engine/boot_control_interface.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080031#include "update_engine/clock.h"
32#include "update_engine/connection_manager.h"
Alex Deymo40d86b22015-09-03 22:27:10 -070033#include "update_engine/hardware_interface.h"
Alex Deymo94c06162014-03-21 20:34:46 -070034#include "update_engine/p2p_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080035#include "update_engine/payload_state.h"
36#include "update_engine/prefs.h"
Alex Deymo30534502015-07-20 15:06:33 -070037#include "update_engine/shill_proxy.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080038#include "update_engine/update_attempter.h"
Alex Deymo63784a52014-05-28 10:46:14 -070039#include "update_engine/update_manager/update_manager.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080040
41namespace chromeos_update_engine {
42
43// A real implementation of the SystemStateInterface which is
44// used by the actual product code.
45class RealSystemState : public SystemState {
Alex Deymo94c06162014-03-21 20:34:46 -070046 public:
Gilad Arnold1f847232014-04-07 12:07:49 -070047 // Constructs all system objects that do not require separate initialization;
48 // see Initialize() below for the remaining ones.
Alex Deymo30534502015-07-20 15:06:33 -070049 explicit RealSystemState(const scoped_refptr<dbus::Bus>& bus);
Gilad Arnold1f847232014-04-07 12:07:49 -070050
51 // Initializes and sets systems objects that require an initialization
52 // separately from construction. Returns |true| on success.
Nam T. Nguyen7d623eb2014-05-13 16:06:28 -070053 bool Initialize();
Jay Srinivasan55f50c22013-01-10 19:24:35 -080054
Alex Vakulenko157fe302014-08-11 15:59:58 -070055 inline void set_device_policy(
Gilad Arnold1f847232014-04-07 12:07:49 -070056 const policy::DevicePolicy* device_policy) override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080057 device_policy_ = device_policy;
58 }
59
Alex Vakulenko157fe302014-08-11 15:59:58 -070060 inline const policy::DevicePolicy* device_policy() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080061 return device_policy_;
62 }
63
Alex Deymo763e7db2015-08-27 21:08:08 -070064 inline BootControlInterface* boot_control() override {
65 return boot_control_.get();
66 }
67
Alex Vakulenko157fe302014-08-11 15:59:58 -070068 inline ClockInterface* clock() override { return &clock_; }
David Zeuthenf413fe52013-04-22 14:04:39 -070069
Alex Deymof6ee0162015-07-31 12:35:22 -070070 inline ConnectionManagerInterface* connection_manager() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080071 return &connection_manager_;
72 }
73
Alex Deymo40d86b22015-09-03 22:27:10 -070074 inline HardwareInterface* hardware() override { return hardware_.get(); }
Alex Deymo42432912013-07-12 20:21:15 -070075
Alex Vakulenko157fe302014-08-11 15:59:58 -070076 inline MetricsLibraryInterface* metrics_lib() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080077 return &metrics_lib_;
78 }
79
Alex Deymodd132f32015-09-14 19:12:07 -070080 inline PrefsInterface* prefs() override { return prefs_.get(); }
Jay Srinivasan55f50c22013-01-10 19:24:35 -080081
Alex Vakulenko157fe302014-08-11 15:59:58 -070082 inline PrefsInterface* powerwash_safe_prefs() override {
Alex Deymodd132f32015-09-14 19:12:07 -070083 return powerwash_safe_prefs_.get();
84 }
Chris Sosaaa18e162013-06-20 13:20:30 -070085
Alex Vakulenko157fe302014-08-11 15:59:58 -070086 inline PayloadStateInterface* payload_state() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080087 return &payload_state_;
88 }
89
Alex Vakulenko157fe302014-08-11 15:59:58 -070090 inline UpdateAttempter* update_attempter() override {
Gilad Arnold1f847232014-04-07 12:07:49 -070091 return &update_attempter_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080092 }
93
Alex Vakulenko157fe302014-08-11 15:59:58 -070094 inline OmahaRequestParams* request_params() override {
Jay Srinivasanae4697c2013-03-18 17:08:08 -070095 return &request_params_;
96 }
97
Alex Vakulenko157fe302014-08-11 15:59:58 -070098 inline P2PManager* p2p_manager() override { return p2p_manager_.get(); }
David Zeuthen526cb582013-08-06 12:26:18 -070099
Alex Vakulenko157fe302014-08-11 15:59:58 -0700100 inline chromeos_update_manager::UpdateManager* update_manager() override {
Alex Deymo63784a52014-05-28 10:46:14 -0700101 return update_manager_.get();
Alex Deymo94c06162014-03-21 20:34:46 -0700102 }
103
Alex Deymo30534502015-07-20 15:06:33 -0700104 inline org::chromium::PowerManagerProxyInterface* power_manager_proxy()
105 override {
106 return &power_manager_proxy_;
107 }
108
Alex Vakulenko157fe302014-08-11 15:59:58 -0700109 inline bool system_rebooted() override { return system_rebooted_; }
Chris Sosabe45bef2013-04-09 18:25:12 -0700110
Alex Deymo94c06162014-03-21 20:34:46 -0700111 private:
Alex Deymo30534502015-07-20 15:06:33 -0700112 // Real DBus proxies using the DBus connection.
113 org::chromium::debugdProxy debugd_proxy_;
114 org::chromium::PowerManagerProxy power_manager_proxy_;
115 org::chromium::SessionManagerInterfaceProxy session_manager_proxy_;
116 ShillProxy shill_proxy_;
117 LibCrosProxy libcros_proxy_;
118
David Zeuthenf413fe52013-04-22 14:04:39 -0700119 // Interface for the clock.
Alex Deymo763e7db2015-08-27 21:08:08 -0700120 std::unique_ptr<BootControlInterface> boot_control_;
121
122 // Interface for the clock.
David Zeuthenf413fe52013-04-22 14:04:39 -0700123 Clock clock_;
124
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800125 // The latest device policy object from the policy provider.
Alex Deymo30534502015-07-20 15:06:33 -0700126 const policy::DevicePolicy* device_policy_{nullptr};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800127
Alex Deymo30534502015-07-20 15:06:33 -0700128 // The connection manager object that makes download decisions depending on
129 // the current type of connection.
130 ConnectionManager connection_manager_{&shill_proxy_, this};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800131
Alex Deymo42432912013-07-12 20:21:15 -0700132 // Interface for the hardware functions.
Alex Deymo40d86b22015-09-03 22:27:10 -0700133 std::unique_ptr<HardwareInterface> hardware_;
Alex Deymo42432912013-07-12 20:21:15 -0700134
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800135 // The Metrics Library interface for reporting UMA stats.
136 MetricsLibrary metrics_lib_;
137
138 // Interface for persisted store.
Alex Deymodd132f32015-09-14 19:12:07 -0700139 std::unique_ptr<PrefsInterface> prefs_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800140
Chris Sosaaa18e162013-06-20 13:20:30 -0700141 // Interface for persisted store that persists across powerwashes.
Alex Deymodd132f32015-09-14 19:12:07 -0700142 std::unique_ptr<PrefsInterface> powerwash_safe_prefs_;
Chris Sosaaa18e162013-06-20 13:20:30 -0700143
Alex Deymo30534502015-07-20 15:06:33 -0700144 // All state pertaining to payload state such as response, URL, backoff
145 // states.
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800146 PayloadState payload_state_;
147
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800148 // Pointer to the update attempter object.
Alex Deymo30534502015-07-20 15:06:33 -0700149 UpdateAttempter update_attempter_{this, &libcros_proxy_, &debugd_proxy_};
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700150
151 // Common parameters for all Omaha requests.
Alex Deymo30534502015-07-20 15:06:33 -0700152 OmahaRequestParams request_params_{this};
Chris Sosabe45bef2013-04-09 18:25:12 -0700153
Ben Chan02f7c1d2014-10-18 15:18:02 -0700154 std::unique_ptr<P2PManager> p2p_manager_;
David Zeuthen526cb582013-08-06 12:26:18 -0700155
Ben Chan02f7c1d2014-10-18 15:18:02 -0700156 std::unique_ptr<chromeos_update_manager::UpdateManager> update_manager_;
Alex Deymo94c06162014-03-21 20:34:46 -0700157
Alex Deymoc83baf62014-04-02 17:43:35 -0700158 policy::PolicyProvider policy_provider_;
159
Chris Sosabe45bef2013-04-09 18:25:12 -0700160 // If true, this is the first instance of the update engine since the system
161 // rebooted. Important for tracking whether you are running instance of the
162 // update engine on first boot or due to a crash/restart.
Alex Deymo30534502015-07-20 15:06:33 -0700163 bool system_rebooted_{false};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800164};
165
166} // namespace chromeos_update_engine
167
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700168#endif // UPDATE_ENGINE_REAL_SYSTEM_STATE_H_