blob: bb4ff3329af0e70b0a71d764808b1ab585e1cdc4 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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//
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070016
17#include "update_engine/dbus_service.h"
Alex Deymofa78f142016-01-26 21:36:16 -080018
Casey Dahlina93cd532016-01-14 16:55:11 -080019#include "update_engine/dbus-constants.h"
Sen Jiang299128e2016-06-03 17:48:18 -070020#include "update_engine/dbus_connection.h"
Alex Deymofa78f142016-01-26 21:36:16 -080021#include "update_engine/update_status_utils.h"
Don Garrettbb26fc82013-11-15 10:40:17 -080022
Alex Deymob7ca0962014-10-01 17:58:07 -070023namespace chromeos_update_engine {
Don Garrettbb26fc82013-11-15 10:40:17 -080024
Casey Dahlina93cd532016-01-14 16:55:11 -080025using brillo::ErrorPtr;
Casey Dahlina93cd532016-01-14 16:55:11 -080026using chromeos_update_engine::UpdateEngineService;
Alex Deymofa78f142016-01-26 21:36:16 -080027using std::string;
Aaron Wood7f92e2b2017-08-28 14:51:21 -070028using update_engine::UpdateEngineStatus;
Casey Dahlina93cd532016-01-14 16:55:11 -080029
30DBusUpdateEngineService::DBusUpdateEngineService(SystemState* system_state)
31 : common_(new UpdateEngineService{system_state}) {
32}
Don Garrettbb26fc82013-11-15 10:40:17 -080033
Alex Deymob7ca0962014-10-01 17:58:07 -070034// org::chromium::UpdateEngineInterfaceInterface methods implementation.
Don Garrettbb26fc82013-11-15 10:40:17 -080035
Casey Dahlina93cd532016-01-14 16:55:11 -080036bool DBusUpdateEngineService::AttemptUpdate(ErrorPtr* error,
37 const string& in_app_version,
38 const string& in_omaha_url) {
Alex Deymob7ca0962014-10-01 17:58:07 -070039 return AttemptUpdateWithFlags(
40 error, in_app_version, in_omaha_url, 0 /* no flags */);
Don Garrettbb26fc82013-11-15 10:40:17 -080041}
42
Casey Dahlina93cd532016-01-14 16:55:11 -080043bool DBusUpdateEngineService::AttemptUpdateWithFlags(
44 ErrorPtr* error,
45 const string& in_app_version,
46 const string& in_omaha_url,
47 int32_t in_flags_as_int) {
48 update_engine::AttemptUpdateFlags flags =
49 static_cast<update_engine::AttemptUpdateFlags>(in_flags_as_int);
Amin Hassani6bb001f2018-02-26 14:33:02 -080050 bool interactive = !(flags & update_engine::kAttemptUpdateFlagNonInteractive);
51 bool result;
Casey Dahlina93cd532016-01-14 16:55:11 -080052 return common_->AttemptUpdate(
Amin Hassani6bb001f2018-02-26 14:33:02 -080053 error,
54 in_app_version,
55 in_omaha_url,
56 interactive
57 ? 0
58 : update_engine::UpdateAttemptFlags::kFlagNonInteractive,
59 &result) &&
60 result;
Darin Petkov296889c2010-07-23 16:20:54 -070061}
62
Casey Dahlina93cd532016-01-14 16:55:11 -080063bool DBusUpdateEngineService::AttemptRollback(ErrorPtr* error,
64 bool in_powerwash) {
65 return common_->AttemptRollback(error, in_powerwash);
Chris Sosad317e402013-06-12 13:47:09 -070066}
67
Casey Dahlina93cd532016-01-14 16:55:11 -080068bool DBusUpdateEngineService::CanRollback(ErrorPtr* error,
69 bool* out_can_rollback) {
70 return common_->CanRollback(error, out_can_rollback);
Alex Vakulenko2bddadd2014-03-27 13:23:46 -070071}
72
Casey Dahlina93cd532016-01-14 16:55:11 -080073bool DBusUpdateEngineService::ResetStatus(ErrorPtr* error) {
74 return common_->ResetStatus(error);
Don Garrettbb26fc82013-11-15 10:40:17 -080075}
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -070076
Casey Dahlina93cd532016-01-14 16:55:11 -080077bool DBusUpdateEngineService::GetStatus(ErrorPtr* error,
78 int64_t* out_last_checked_time,
79 double* out_progress,
80 string* out_current_operation,
81 string* out_new_version,
82 int64_t* out_new_size) {
Amin Hassani6bb001f2018-02-26 14:33:02 -080083 UpdateEngineStatus status;
84 if (!common_->GetStatus(error, &status)) {
85 return false;
86 }
87 *out_last_checked_time = status.last_checked_time;
88 *out_progress = status.progress;
89 *out_current_operation = UpdateStatusToString(status.status);
90 *out_new_version = status.new_version;
91 *out_new_size = status.new_size_bytes;
92 return true;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070093}
94
Casey Dahlina93cd532016-01-14 16:55:11 -080095bool DBusUpdateEngineService::RebootIfNeeded(ErrorPtr* error) {
96 return common_->RebootIfNeeded(error);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070097}
98
Casey Dahlina93cd532016-01-14 16:55:11 -080099bool DBusUpdateEngineService::SetChannel(ErrorPtr* error,
100 const string& in_target_channel,
101 bool in_is_powerwash_allowed) {
102 return common_->SetChannel(error, in_target_channel, in_is_powerwash_allowed);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700103}
104
Casey Dahlina93cd532016-01-14 16:55:11 -0800105bool DBusUpdateEngineService::GetChannel(ErrorPtr* error,
106 bool in_get_current_channel,
107 string* out_channel) {
108 return common_->GetChannel(error, in_get_current_channel, out_channel);
Darin Petkov8daa3242010-10-25 13:28:47 -0700109}
110
Alex Deymo5b5fa8b2016-10-06 15:40:49 -0700111bool DBusUpdateEngineService::GetCohortHint(ErrorPtr* error,
112 string* out_cohort_hint) {
113 return common_->GetCohortHint(error, out_cohort_hint);
114}
115
116bool DBusUpdateEngineService::SetCohortHint(ErrorPtr* error,
117 const string& in_cohort_hint) {
118 return common_->SetCohortHint(error, in_cohort_hint);
119}
120
Casey Dahlina93cd532016-01-14 16:55:11 -0800121bool DBusUpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error,
122 bool in_enabled) {
123 return common_->SetP2PUpdatePermission(error, in_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700124}
125
Casey Dahlina93cd532016-01-14 16:55:11 -0800126bool DBusUpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error,
127 bool* out_enabled) {
128 return common_->GetP2PUpdatePermission(error, out_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700129}
130
Casey Dahlina93cd532016-01-14 16:55:11 -0800131bool DBusUpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error,
132 bool in_allowed) {
133 return common_->SetUpdateOverCellularPermission(error, in_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700134}
135
Weidong Guo421ff332017-04-17 10:08:38 -0700136bool DBusUpdateEngineService::SetUpdateOverCellularTarget(
137 brillo::ErrorPtr* error,
138 const std::string& target_version,
139 int64_t target_size) {
140 return common_->SetUpdateOverCellularTarget(
141 error, target_version, target_size);
142}
143
Casey Dahlina93cd532016-01-14 16:55:11 -0800144bool DBusUpdateEngineService::GetUpdateOverCellularPermission(
145 ErrorPtr* error, bool* out_allowed) {
146 return common_->GetUpdateOverCellularPermission(error, out_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700147}
148
Casey Dahlina93cd532016-01-14 16:55:11 -0800149bool DBusUpdateEngineService::GetDurationSinceUpdate(
150 ErrorPtr* error, int64_t* out_usec_wallclock) {
151 return common_->GetDurationSinceUpdate(error, out_usec_wallclock);
David Zeuthen3c55abd2013-10-14 12:48:03 -0700152}
153
Casey Dahlina93cd532016-01-14 16:55:11 -0800154bool DBusUpdateEngineService::GetPrevVersion(ErrorPtr* error,
155 string* out_prev_version) {
156 return common_->GetPrevVersion(error, out_prev_version);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700157}
Alex Vakulenkodea2eac2014-03-14 15:56:59 -0700158
Casey Dahlina93cd532016-01-14 16:55:11 -0800159bool DBusUpdateEngineService::GetRollbackPartition(
160 ErrorPtr* error, string* out_rollback_partition_name) {
161 return common_->GetRollbackPartition(error, out_rollback_partition_name);
Alex Deymob7ca0962014-10-01 17:58:07 -0700162}
163
Shuqian Zhao29971732016-02-05 11:29:32 -0800164bool DBusUpdateEngineService::GetLastAttemptError(
Alex Deymob3fa53b2016-04-18 19:57:58 -0700165 ErrorPtr* error, int32_t* out_last_attempt_error) {
166 return common_->GetLastAttemptError(error, out_last_attempt_error);
167}
168
169bool DBusUpdateEngineService::GetEolStatus(ErrorPtr* error,
170 int32_t* out_eol_status) {
171 return common_->GetEolStatus(error, out_eol_status);
Shuqian Zhao29971732016-02-05 11:29:32 -0800172}
173
Sen Jiang299128e2016-06-03 17:48:18 -0700174UpdateEngineAdaptor::UpdateEngineAdaptor(SystemState* system_state)
Alex Deymob7ca0962014-10-01 17:58:07 -0700175 : org::chromium::UpdateEngineInterfaceAdaptor(&dbus_service_),
Sen Jiang299128e2016-06-03 17:48:18 -0700176 bus_(DBusConnection::Get()->GetDBus()),
177 dbus_service_(system_state),
178 dbus_object_(nullptr,
179 bus_,
180 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)) {}
Alex Deymob7ca0962014-10-01 17:58:07 -0700181
182void UpdateEngineAdaptor::RegisterAsync(
183 const base::Callback<void(bool)>& completion_callback) {
184 RegisterWithDBusObject(&dbus_object_);
185 dbus_object_.RegisterAsync(completion_callback);
186}
187
188bool UpdateEngineAdaptor::RequestOwnership() {
Alex Deymod6deb1d2015-08-28 15:54:37 -0700189 return bus_->RequestOwnershipAndBlock(update_engine::kUpdateEngineServiceName,
Alex Deymob7ca0962014-10-01 17:58:07 -0700190 dbus::Bus::REQUIRE_PRIMARY);
191}
192
Aaron Wood7f92e2b2017-08-28 14:51:21 -0700193void UpdateEngineAdaptor::SendStatusUpdate(
194 const UpdateEngineStatus& update_engine_status) {
195 SendStatusUpdateSignal(update_engine_status.last_checked_time,
196 update_engine_status.progress,
197 UpdateStatusToString(update_engine_status.status),
198 update_engine_status.new_version,
Amin Hassani6bb001f2018-02-26 14:33:02 -0800199 update_engine_status.new_size_bytes);
Alex Deymofa78f142016-01-26 21:36:16 -0800200}
201
Alex Deymob7ca0962014-10-01 17:58:07 -0700202} // namespace chromeos_update_engine