blob: 03425b6dd6c17736c3e8fe437b4324a63e608c33 [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
Xiaochu Liu88d90382018-08-29 16:09:11 -070019#include <string>
20#include <vector>
21
22#include <update_engine/dbus-constants.h>
23#include <update_engine/proto_bindings/update_engine.pb.h>
24
Sen Jiang299128e2016-06-03 17:48:18 -070025#include "update_engine/dbus_connection.h"
Alex Deymofa78f142016-01-26 21:36:16 -080026#include "update_engine/update_status_utils.h"
Don Garrettbb26fc82013-11-15 10:40:17 -080027
Alex Deymob7ca0962014-10-01 17:58:07 -070028namespace chromeos_update_engine {
Don Garrettbb26fc82013-11-15 10:40:17 -080029
Casey Dahlina93cd532016-01-14 16:55:11 -080030using brillo::ErrorPtr;
Casey Dahlina93cd532016-01-14 16:55:11 -080031using chromeos_update_engine::UpdateEngineService;
Alex Deymofa78f142016-01-26 21:36:16 -080032using std::string;
Xiaochu Liu88d90382018-08-29 16:09:11 -070033using std::vector;
Aaron Wood7f92e2b2017-08-28 14:51:21 -070034using update_engine::UpdateEngineStatus;
Casey Dahlina93cd532016-01-14 16:55:11 -080035
36DBusUpdateEngineService::DBusUpdateEngineService(SystemState* system_state)
37 : common_(new UpdateEngineService{system_state}) {
38}
Don Garrettbb26fc82013-11-15 10:40:17 -080039
Alex Deymob7ca0962014-10-01 17:58:07 -070040// org::chromium::UpdateEngineInterfaceInterface methods implementation.
Don Garrettbb26fc82013-11-15 10:40:17 -080041
Casey Dahlina93cd532016-01-14 16:55:11 -080042bool DBusUpdateEngineService::AttemptUpdate(ErrorPtr* error,
43 const string& in_app_version,
44 const string& in_omaha_url) {
Alex Deymob7ca0962014-10-01 17:58:07 -070045 return AttemptUpdateWithFlags(
46 error, in_app_version, in_omaha_url, 0 /* no flags */);
Don Garrettbb26fc82013-11-15 10:40:17 -080047}
48
Casey Dahlina93cd532016-01-14 16:55:11 -080049bool DBusUpdateEngineService::AttemptUpdateWithFlags(
50 ErrorPtr* error,
51 const string& in_app_version,
52 const string& in_omaha_url,
53 int32_t in_flags_as_int) {
54 update_engine::AttemptUpdateFlags flags =
55 static_cast<update_engine::AttemptUpdateFlags>(in_flags_as_int);
Amin Hassani6bb001f2018-02-26 14:33:02 -080056 bool interactive = !(flags & update_engine::kAttemptUpdateFlagNonInteractive);
57 bool result;
Casey Dahlina93cd532016-01-14 16:55:11 -080058 return common_->AttemptUpdate(
Amin Hassani0eae4272018-06-01 11:31:34 -070059 error,
60 in_app_version,
61 in_omaha_url,
62 interactive ? 0 : update_engine::UpdateAttemptFlags::kFlagNonInteractive,
63 &result);
Darin Petkov296889c2010-07-23 16:20:54 -070064}
65
Xiaochu Liu88d90382018-08-29 16:09:11 -070066bool DBusUpdateEngineService::AttemptInstall(ErrorPtr* error,
67 const string& dlc_request) {
68 // Parse the raw parameters into protobuf.
69 DlcParameters dlc_parameters;
70 if (!dlc_parameters.ParseFromString(dlc_request)) {
71 *error = brillo::Error::Create(
72 FROM_HERE, "update_engine", "INTERNAL", "parameters are invalid.");
73 return false;
74 }
75 // Extract fields from the protobuf.
Xiaochu Liuf53a5d32018-11-26 13:48:59 -080076 vector<string> dlc_module_ids;
Xiaochu Liu88d90382018-08-29 16:09:11 -070077 for (const auto& dlc_info : dlc_parameters.dlc_infos()) {
78 if (dlc_info.dlc_id().empty()) {
79 *error = brillo::Error::Create(
80 FROM_HERE, "update_engine", "INTERNAL", "parameters are invalid.");
81 return false;
82 }
Xiaochu Liuf53a5d32018-11-26 13:48:59 -080083 dlc_module_ids.push_back(dlc_info.dlc_id());
Xiaochu Liu88d90382018-08-29 16:09:11 -070084 }
Xiaochu Liuf53a5d32018-11-26 13:48:59 -080085 return common_->AttemptInstall(
86 error, dlc_parameters.omaha_url(), dlc_module_ids);
Xiaochu Liu88d90382018-08-29 16:09:11 -070087}
88
Casey Dahlina93cd532016-01-14 16:55:11 -080089bool DBusUpdateEngineService::AttemptRollback(ErrorPtr* error,
90 bool in_powerwash) {
91 return common_->AttemptRollback(error, in_powerwash);
Chris Sosad317e402013-06-12 13:47:09 -070092}
93
Casey Dahlina93cd532016-01-14 16:55:11 -080094bool DBusUpdateEngineService::CanRollback(ErrorPtr* error,
95 bool* out_can_rollback) {
96 return common_->CanRollback(error, out_can_rollback);
Alex Vakulenko2bddadd2014-03-27 13:23:46 -070097}
98
Casey Dahlina93cd532016-01-14 16:55:11 -080099bool DBusUpdateEngineService::ResetStatus(ErrorPtr* error) {
100 return common_->ResetStatus(error);
Don Garrettbb26fc82013-11-15 10:40:17 -0800101}
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700102
Casey Dahlina93cd532016-01-14 16:55:11 -0800103bool DBusUpdateEngineService::GetStatus(ErrorPtr* error,
104 int64_t* out_last_checked_time,
105 double* out_progress,
106 string* out_current_operation,
107 string* out_new_version,
108 int64_t* out_new_size) {
Amin Hassani6bb001f2018-02-26 14:33:02 -0800109 UpdateEngineStatus status;
110 if (!common_->GetStatus(error, &status)) {
111 return false;
112 }
113 *out_last_checked_time = status.last_checked_time;
114 *out_progress = status.progress;
115 *out_current_operation = UpdateStatusToString(status.status);
116 *out_new_version = status.new_version;
117 *out_new_size = status.new_size_bytes;
118 return true;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700119}
120
Casey Dahlina93cd532016-01-14 16:55:11 -0800121bool DBusUpdateEngineService::RebootIfNeeded(ErrorPtr* error) {
122 return common_->RebootIfNeeded(error);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700123}
124
Casey Dahlina93cd532016-01-14 16:55:11 -0800125bool DBusUpdateEngineService::SetChannel(ErrorPtr* error,
126 const string& in_target_channel,
127 bool in_is_powerwash_allowed) {
128 return common_->SetChannel(error, in_target_channel, in_is_powerwash_allowed);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700129}
130
Casey Dahlina93cd532016-01-14 16:55:11 -0800131bool DBusUpdateEngineService::GetChannel(ErrorPtr* error,
132 bool in_get_current_channel,
133 string* out_channel) {
134 return common_->GetChannel(error, in_get_current_channel, out_channel);
Darin Petkov8daa3242010-10-25 13:28:47 -0700135}
136
Alex Deymo5b5fa8b2016-10-06 15:40:49 -0700137bool DBusUpdateEngineService::GetCohortHint(ErrorPtr* error,
138 string* out_cohort_hint) {
139 return common_->GetCohortHint(error, out_cohort_hint);
140}
141
142bool DBusUpdateEngineService::SetCohortHint(ErrorPtr* error,
143 const string& in_cohort_hint) {
144 return common_->SetCohortHint(error, in_cohort_hint);
145}
146
Casey Dahlina93cd532016-01-14 16:55:11 -0800147bool DBusUpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error,
148 bool in_enabled) {
149 return common_->SetP2PUpdatePermission(error, in_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700150}
151
Casey Dahlina93cd532016-01-14 16:55:11 -0800152bool DBusUpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error,
153 bool* out_enabled) {
154 return common_->GetP2PUpdatePermission(error, out_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700155}
156
Casey Dahlina93cd532016-01-14 16:55:11 -0800157bool DBusUpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error,
158 bool in_allowed) {
159 return common_->SetUpdateOverCellularPermission(error, in_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700160}
161
Weidong Guo421ff332017-04-17 10:08:38 -0700162bool DBusUpdateEngineService::SetUpdateOverCellularTarget(
163 brillo::ErrorPtr* error,
164 const std::string& target_version,
165 int64_t target_size) {
166 return common_->SetUpdateOverCellularTarget(
167 error, target_version, target_size);
168}
169
Casey Dahlina93cd532016-01-14 16:55:11 -0800170bool DBusUpdateEngineService::GetUpdateOverCellularPermission(
171 ErrorPtr* error, bool* out_allowed) {
172 return common_->GetUpdateOverCellularPermission(error, out_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700173}
174
Casey Dahlina93cd532016-01-14 16:55:11 -0800175bool DBusUpdateEngineService::GetDurationSinceUpdate(
176 ErrorPtr* error, int64_t* out_usec_wallclock) {
177 return common_->GetDurationSinceUpdate(error, out_usec_wallclock);
David Zeuthen3c55abd2013-10-14 12:48:03 -0700178}
179
Casey Dahlina93cd532016-01-14 16:55:11 -0800180bool DBusUpdateEngineService::GetPrevVersion(ErrorPtr* error,
181 string* out_prev_version) {
182 return common_->GetPrevVersion(error, out_prev_version);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700183}
Alex Vakulenkodea2eac2014-03-14 15:56:59 -0700184
Casey Dahlina93cd532016-01-14 16:55:11 -0800185bool DBusUpdateEngineService::GetRollbackPartition(
186 ErrorPtr* error, string* out_rollback_partition_name) {
187 return common_->GetRollbackPartition(error, out_rollback_partition_name);
Alex Deymob7ca0962014-10-01 17:58:07 -0700188}
189
Shuqian Zhao29971732016-02-05 11:29:32 -0800190bool DBusUpdateEngineService::GetLastAttemptError(
Alex Deymob3fa53b2016-04-18 19:57:58 -0700191 ErrorPtr* error, int32_t* out_last_attempt_error) {
192 return common_->GetLastAttemptError(error, out_last_attempt_error);
193}
194
195bool DBusUpdateEngineService::GetEolStatus(ErrorPtr* error,
196 int32_t* out_eol_status) {
197 return common_->GetEolStatus(error, out_eol_status);
Shuqian Zhao29971732016-02-05 11:29:32 -0800198}
199
Sen Jiang299128e2016-06-03 17:48:18 -0700200UpdateEngineAdaptor::UpdateEngineAdaptor(SystemState* system_state)
Alex Deymob7ca0962014-10-01 17:58:07 -0700201 : org::chromium::UpdateEngineInterfaceAdaptor(&dbus_service_),
Sen Jiang299128e2016-06-03 17:48:18 -0700202 bus_(DBusConnection::Get()->GetDBus()),
203 dbus_service_(system_state),
204 dbus_object_(nullptr,
205 bus_,
206 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)) {}
Alex Deymob7ca0962014-10-01 17:58:07 -0700207
208void UpdateEngineAdaptor::RegisterAsync(
209 const base::Callback<void(bool)>& completion_callback) {
210 RegisterWithDBusObject(&dbus_object_);
211 dbus_object_.RegisterAsync(completion_callback);
212}
213
214bool UpdateEngineAdaptor::RequestOwnership() {
Alex Deymod6deb1d2015-08-28 15:54:37 -0700215 return bus_->RequestOwnershipAndBlock(update_engine::kUpdateEngineServiceName,
Alex Deymob7ca0962014-10-01 17:58:07 -0700216 dbus::Bus::REQUIRE_PRIMARY);
217}
218
Aaron Wood7f92e2b2017-08-28 14:51:21 -0700219void UpdateEngineAdaptor::SendStatusUpdate(
220 const UpdateEngineStatus& update_engine_status) {
221 SendStatusUpdateSignal(update_engine_status.last_checked_time,
222 update_engine_status.progress,
223 UpdateStatusToString(update_engine_status.status),
224 update_engine_status.new_version,
Amin Hassani6bb001f2018-02-26 14:33:02 -0800225 update_engine_status.new_size_bytes);
Alex Deymofa78f142016-01-26 21:36:16 -0800226}
227
Alex Deymob7ca0962014-10-01 17:58:07 -0700228} // namespace chromeos_update_engine