blob: 533fa108099125a28854b42bc5acdfc0557ec485 [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
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080027#include "update_engine/clock.h"
28#include "update_engine/connection_manager.h"
Alex Deymo30534502015-07-20 15:06:33 -070029#include "update_engine/dbus_proxies.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080030#include "update_engine/hardware.h"
Alex Deymo94c06162014-03-21 20:34:46 -070031#include "update_engine/p2p_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080032#include "update_engine/payload_state.h"
33#include "update_engine/prefs.h"
Alex Deymo30534502015-07-20 15:06:33 -070034#include "update_engine/shill_proxy.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080035#include "update_engine/update_attempter.h"
Alex Deymo63784a52014-05-28 10:46:14 -070036#include "update_engine/update_manager/update_manager.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080037
38namespace chromeos_update_engine {
39
40// A real implementation of the SystemStateInterface which is
41// used by the actual product code.
42class RealSystemState : public SystemState {
Alex Deymo94c06162014-03-21 20:34:46 -070043 public:
Gilad Arnold1f847232014-04-07 12:07:49 -070044 // Constructs all system objects that do not require separate initialization;
45 // see Initialize() below for the remaining ones.
Alex Deymo30534502015-07-20 15:06:33 -070046 explicit RealSystemState(const scoped_refptr<dbus::Bus>& bus);
Gilad Arnold1f847232014-04-07 12:07:49 -070047
48 // Initializes and sets systems objects that require an initialization
49 // separately from construction. Returns |true| on success.
Nam T. Nguyen7d623eb2014-05-13 16:06:28 -070050 bool Initialize();
Jay Srinivasan55f50c22013-01-10 19:24:35 -080051
Alex Vakulenko157fe302014-08-11 15:59:58 -070052 inline void set_device_policy(
Gilad Arnold1f847232014-04-07 12:07:49 -070053 const policy::DevicePolicy* device_policy) override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080054 device_policy_ = device_policy;
55 }
56
Alex Vakulenko157fe302014-08-11 15:59:58 -070057 inline const policy::DevicePolicy* device_policy() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080058 return device_policy_;
59 }
60
Alex Vakulenko157fe302014-08-11 15:59:58 -070061 inline ClockInterface* clock() override { return &clock_; }
David Zeuthenf413fe52013-04-22 14:04:39 -070062
Alex Deymof6ee0162015-07-31 12:35:22 -070063 inline ConnectionManagerInterface* connection_manager() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080064 return &connection_manager_;
65 }
66
Alex Vakulenko157fe302014-08-11 15:59:58 -070067 inline HardwareInterface* hardware() override { return &hardware_; }
Alex Deymo42432912013-07-12 20:21:15 -070068
Alex Vakulenko157fe302014-08-11 15:59:58 -070069 inline MetricsLibraryInterface* metrics_lib() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080070 return &metrics_lib_;
71 }
72
Alex Vakulenko157fe302014-08-11 15:59:58 -070073 inline PrefsInterface* prefs() override { return &prefs_; }
Jay Srinivasan55f50c22013-01-10 19:24:35 -080074
Alex Vakulenko157fe302014-08-11 15:59:58 -070075 inline PrefsInterface* powerwash_safe_prefs() override {
Chris Sosaaa18e162013-06-20 13:20:30 -070076 return &powerwash_safe_prefs_;
77 }
78
Alex Vakulenko157fe302014-08-11 15:59:58 -070079 inline PayloadStateInterface* payload_state() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080080 return &payload_state_;
81 }
82
Alex Vakulenko157fe302014-08-11 15:59:58 -070083 inline UpdateAttempter* update_attempter() override {
Gilad Arnold1f847232014-04-07 12:07:49 -070084 return &update_attempter_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080085 }
86
Alex Vakulenko157fe302014-08-11 15:59:58 -070087 inline OmahaRequestParams* request_params() override {
Jay Srinivasanae4697c2013-03-18 17:08:08 -070088 return &request_params_;
89 }
90
Alex Vakulenko157fe302014-08-11 15:59:58 -070091 inline P2PManager* p2p_manager() override { return p2p_manager_.get(); }
David Zeuthen526cb582013-08-06 12:26:18 -070092
Alex Vakulenko157fe302014-08-11 15:59:58 -070093 inline chromeos_update_manager::UpdateManager* update_manager() override {
Alex Deymo63784a52014-05-28 10:46:14 -070094 return update_manager_.get();
Alex Deymo94c06162014-03-21 20:34:46 -070095 }
96
Alex Deymo30534502015-07-20 15:06:33 -070097 inline org::chromium::PowerManagerProxyInterface* power_manager_proxy()
98 override {
99 return &power_manager_proxy_;
100 }
101
Alex Vakulenko157fe302014-08-11 15:59:58 -0700102 inline bool system_rebooted() override { return system_rebooted_; }
Chris Sosabe45bef2013-04-09 18:25:12 -0700103
Alex Deymo94c06162014-03-21 20:34:46 -0700104 private:
Alex Deymo30534502015-07-20 15:06:33 -0700105 // Real DBus proxies using the DBus connection.
106 org::chromium::debugdProxy debugd_proxy_;
107 org::chromium::PowerManagerProxy power_manager_proxy_;
108 org::chromium::SessionManagerInterfaceProxy session_manager_proxy_;
109 ShillProxy shill_proxy_;
110 LibCrosProxy libcros_proxy_;
111
David Zeuthenf413fe52013-04-22 14:04:39 -0700112 // Interface for the clock.
113 Clock clock_;
114
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800115 // The latest device policy object from the policy provider.
Alex Deymo30534502015-07-20 15:06:33 -0700116 const policy::DevicePolicy* device_policy_{nullptr};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800117
Alex Deymo30534502015-07-20 15:06:33 -0700118 // The connection manager object that makes download decisions depending on
119 // the current type of connection.
120 ConnectionManager connection_manager_{&shill_proxy_, this};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800121
Alex Deymo42432912013-07-12 20:21:15 -0700122 // Interface for the hardware functions.
123 Hardware hardware_;
124
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800125 // The Metrics Library interface for reporting UMA stats.
126 MetricsLibrary metrics_lib_;
127
128 // Interface for persisted store.
129 Prefs prefs_;
130
Chris Sosaaa18e162013-06-20 13:20:30 -0700131 // Interface for persisted store that persists across powerwashes.
132 Prefs powerwash_safe_prefs_;
133
Alex Deymo30534502015-07-20 15:06:33 -0700134 // All state pertaining to payload state such as response, URL, backoff
135 // states.
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800136 PayloadState payload_state_;
137
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800138 // Pointer to the update attempter object.
Alex Deymo30534502015-07-20 15:06:33 -0700139 UpdateAttempter update_attempter_{this, &libcros_proxy_, &debugd_proxy_};
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700140
141 // Common parameters for all Omaha requests.
Alex Deymo30534502015-07-20 15:06:33 -0700142 OmahaRequestParams request_params_{this};
Chris Sosabe45bef2013-04-09 18:25:12 -0700143
Ben Chan02f7c1d2014-10-18 15:18:02 -0700144 std::unique_ptr<P2PManager> p2p_manager_;
David Zeuthen526cb582013-08-06 12:26:18 -0700145
Ben Chan02f7c1d2014-10-18 15:18:02 -0700146 std::unique_ptr<chromeos_update_manager::UpdateManager> update_manager_;
Alex Deymo94c06162014-03-21 20:34:46 -0700147
Alex Deymoc83baf62014-04-02 17:43:35 -0700148 policy::PolicyProvider policy_provider_;
149
Chris Sosabe45bef2013-04-09 18:25:12 -0700150 // If true, this is the first instance of the update engine since the system
151 // rebooted. Important for tracking whether you are running instance of the
152 // update engine on first boot or due to a crash/restart.
Alex Deymo30534502015-07-20 15:06:33 -0700153 bool system_rebooted_{false};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800154};
155
156} // namespace chromeos_update_engine
157
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700158#endif // UPDATE_ENGINE_REAL_SYSTEM_STATE_H_