blob: 729605324be4fc59117284c6fdc7387d78341bef [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)
Amin Hassani7cc8bb02019-01-14 16:29:47 -080037 : common_(new UpdateEngineService{system_state}) {}
Don Garrettbb26fc82013-11-15 10:40:17 -080038
Alex Deymob7ca0962014-10-01 17:58:07 -070039// org::chromium::UpdateEngineInterfaceInterface methods implementation.
Don Garrettbb26fc82013-11-15 10:40:17 -080040
Casey Dahlina93cd532016-01-14 16:55:11 -080041bool DBusUpdateEngineService::AttemptUpdate(ErrorPtr* error,
42 const string& in_app_version,
43 const string& in_omaha_url) {
Alex Deymob7ca0962014-10-01 17:58:07 -070044 return AttemptUpdateWithFlags(
45 error, in_app_version, in_omaha_url, 0 /* no flags */);
Don Garrettbb26fc82013-11-15 10:40:17 -080046}
47
Casey Dahlina93cd532016-01-14 16:55:11 -080048bool DBusUpdateEngineService::AttemptUpdateWithFlags(
49 ErrorPtr* error,
50 const string& in_app_version,
51 const string& in_omaha_url,
52 int32_t in_flags_as_int) {
53 update_engine::AttemptUpdateFlags flags =
54 static_cast<update_engine::AttemptUpdateFlags>(in_flags_as_int);
Amin Hassani6bb001f2018-02-26 14:33:02 -080055 bool interactive = !(flags & update_engine::kAttemptUpdateFlagNonInteractive);
56 bool result;
Casey Dahlina93cd532016-01-14 16:55:11 -080057 return common_->AttemptUpdate(
Amin Hassani0eae4272018-06-01 11:31:34 -070058 error,
59 in_app_version,
60 in_omaha_url,
61 interactive ? 0 : update_engine::UpdateAttemptFlags::kFlagNonInteractive,
62 &result);
Darin Petkov296889c2010-07-23 16:20:54 -070063}
64
Xiaochu Liu88d90382018-08-29 16:09:11 -070065bool DBusUpdateEngineService::AttemptInstall(ErrorPtr* error,
66 const string& dlc_request) {
67 // Parse the raw parameters into protobuf.
68 DlcParameters dlc_parameters;
69 if (!dlc_parameters.ParseFromString(dlc_request)) {
70 *error = brillo::Error::Create(
71 FROM_HERE, "update_engine", "INTERNAL", "parameters are invalid.");
72 return false;
73 }
74 // Extract fields from the protobuf.
Xiaochu Liuf53a5d32018-11-26 13:48:59 -080075 vector<string> dlc_module_ids;
Xiaochu Liu88d90382018-08-29 16:09:11 -070076 for (const auto& dlc_info : dlc_parameters.dlc_infos()) {
77 if (dlc_info.dlc_id().empty()) {
78 *error = brillo::Error::Create(
79 FROM_HERE, "update_engine", "INTERNAL", "parameters are invalid.");
80 return false;
81 }
Xiaochu Liuf53a5d32018-11-26 13:48:59 -080082 dlc_module_ids.push_back(dlc_info.dlc_id());
Xiaochu Liu88d90382018-08-29 16:09:11 -070083 }
Xiaochu Liuf53a5d32018-11-26 13:48:59 -080084 return common_->AttemptInstall(
85 error, dlc_parameters.omaha_url(), dlc_module_ids);
Xiaochu Liu88d90382018-08-29 16:09:11 -070086}
87
Casey Dahlina93cd532016-01-14 16:55:11 -080088bool DBusUpdateEngineService::AttemptRollback(ErrorPtr* error,
89 bool in_powerwash) {
90 return common_->AttemptRollback(error, in_powerwash);
Chris Sosad317e402013-06-12 13:47:09 -070091}
92
Casey Dahlina93cd532016-01-14 16:55:11 -080093bool DBusUpdateEngineService::CanRollback(ErrorPtr* error,
94 bool* out_can_rollback) {
95 return common_->CanRollback(error, out_can_rollback);
Alex Vakulenko2bddadd2014-03-27 13:23:46 -070096}
97
Casey Dahlina93cd532016-01-14 16:55:11 -080098bool DBusUpdateEngineService::ResetStatus(ErrorPtr* error) {
99 return common_->ResetStatus(error);
Don Garrettbb26fc82013-11-15 10:40:17 -0800100}
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -0700101
Casey Dahlina93cd532016-01-14 16:55:11 -0800102bool DBusUpdateEngineService::GetStatus(ErrorPtr* error,
103 int64_t* out_last_checked_time,
104 double* out_progress,
105 string* out_current_operation,
106 string* out_new_version,
107 int64_t* out_new_size) {
Amin Hassani6bb001f2018-02-26 14:33:02 -0800108 UpdateEngineStatus status;
109 if (!common_->GetStatus(error, &status)) {
110 return false;
111 }
112 *out_last_checked_time = status.last_checked_time;
113 *out_progress = status.progress;
114 *out_current_operation = UpdateStatusToString(status.status);
115 *out_new_version = status.new_version;
116 *out_new_size = status.new_size_bytes;
117 return true;
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -0700118}
119
Casey Dahlina93cd532016-01-14 16:55:11 -0800120bool DBusUpdateEngineService::RebootIfNeeded(ErrorPtr* error) {
121 return common_->RebootIfNeeded(error);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700122}
123
Casey Dahlina93cd532016-01-14 16:55:11 -0800124bool DBusUpdateEngineService::SetChannel(ErrorPtr* error,
125 const string& in_target_channel,
126 bool in_is_powerwash_allowed) {
127 return common_->SetChannel(error, in_target_channel, in_is_powerwash_allowed);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700128}
129
Casey Dahlina93cd532016-01-14 16:55:11 -0800130bool DBusUpdateEngineService::GetChannel(ErrorPtr* error,
131 bool in_get_current_channel,
132 string* out_channel) {
133 return common_->GetChannel(error, in_get_current_channel, out_channel);
Darin Petkov8daa3242010-10-25 13:28:47 -0700134}
135
Alex Deymo5b5fa8b2016-10-06 15:40:49 -0700136bool DBusUpdateEngineService::GetCohortHint(ErrorPtr* error,
137 string* out_cohort_hint) {
138 return common_->GetCohortHint(error, out_cohort_hint);
139}
140
141bool DBusUpdateEngineService::SetCohortHint(ErrorPtr* error,
142 const string& in_cohort_hint) {
143 return common_->SetCohortHint(error, in_cohort_hint);
144}
145
Casey Dahlina93cd532016-01-14 16:55:11 -0800146bool DBusUpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error,
147 bool in_enabled) {
148 return common_->SetP2PUpdatePermission(error, in_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700149}
150
Casey Dahlina93cd532016-01-14 16:55:11 -0800151bool DBusUpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error,
152 bool* out_enabled) {
153 return common_->GetP2PUpdatePermission(error, out_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700154}
155
Casey Dahlina93cd532016-01-14 16:55:11 -0800156bool DBusUpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error,
157 bool in_allowed) {
158 return common_->SetUpdateOverCellularPermission(error, in_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700159}
160
Weidong Guo421ff332017-04-17 10:08:38 -0700161bool DBusUpdateEngineService::SetUpdateOverCellularTarget(
162 brillo::ErrorPtr* error,
163 const std::string& target_version,
164 int64_t target_size) {
165 return common_->SetUpdateOverCellularTarget(
166 error, target_version, target_size);
167}
168
Casey Dahlina93cd532016-01-14 16:55:11 -0800169bool DBusUpdateEngineService::GetUpdateOverCellularPermission(
170 ErrorPtr* error, bool* out_allowed) {
171 return common_->GetUpdateOverCellularPermission(error, out_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700172}
173
Casey Dahlina93cd532016-01-14 16:55:11 -0800174bool DBusUpdateEngineService::GetDurationSinceUpdate(
175 ErrorPtr* error, int64_t* out_usec_wallclock) {
176 return common_->GetDurationSinceUpdate(error, out_usec_wallclock);
David Zeuthen3c55abd2013-10-14 12:48:03 -0700177}
178
Casey Dahlina93cd532016-01-14 16:55:11 -0800179bool DBusUpdateEngineService::GetPrevVersion(ErrorPtr* error,
180 string* out_prev_version) {
181 return common_->GetPrevVersion(error, out_prev_version);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700182}
Alex Vakulenkodea2eac2014-03-14 15:56:59 -0700183
Casey Dahlina93cd532016-01-14 16:55:11 -0800184bool DBusUpdateEngineService::GetRollbackPartition(
185 ErrorPtr* error, string* out_rollback_partition_name) {
186 return common_->GetRollbackPartition(error, out_rollback_partition_name);
Alex Deymob7ca0962014-10-01 17:58:07 -0700187}
188
Shuqian Zhao29971732016-02-05 11:29:32 -0800189bool DBusUpdateEngineService::GetLastAttemptError(
Alex Deymob3fa53b2016-04-18 19:57:58 -0700190 ErrorPtr* error, int32_t* out_last_attempt_error) {
191 return common_->GetLastAttemptError(error, out_last_attempt_error);
192}
193
194bool DBusUpdateEngineService::GetEolStatus(ErrorPtr* error,
195 int32_t* out_eol_status) {
196 return common_->GetEolStatus(error, out_eol_status);
Shuqian Zhao29971732016-02-05 11:29:32 -0800197}
198
Sen Jiang299128e2016-06-03 17:48:18 -0700199UpdateEngineAdaptor::UpdateEngineAdaptor(SystemState* system_state)
Alex Deymob7ca0962014-10-01 17:58:07 -0700200 : org::chromium::UpdateEngineInterfaceAdaptor(&dbus_service_),
Sen Jiang299128e2016-06-03 17:48:18 -0700201 bus_(DBusConnection::Get()->GetDBus()),
202 dbus_service_(system_state),
203 dbus_object_(nullptr,
204 bus_,
205 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)) {}
Alex Deymob7ca0962014-10-01 17:58:07 -0700206
207void UpdateEngineAdaptor::RegisterAsync(
208 const base::Callback<void(bool)>& completion_callback) {
209 RegisterWithDBusObject(&dbus_object_);
210 dbus_object_.RegisterAsync(completion_callback);
211}
212
213bool UpdateEngineAdaptor::RequestOwnership() {
Alex Deymod6deb1d2015-08-28 15:54:37 -0700214 return bus_->RequestOwnershipAndBlock(update_engine::kUpdateEngineServiceName,
Alex Deymob7ca0962014-10-01 17:58:07 -0700215 dbus::Bus::REQUIRE_PRIMARY);
216}
217
Aaron Wood7f92e2b2017-08-28 14:51:21 -0700218void UpdateEngineAdaptor::SendStatusUpdate(
219 const UpdateEngineStatus& update_engine_status) {
220 SendStatusUpdateSignal(update_engine_status.last_checked_time,
221 update_engine_status.progress,
222 UpdateStatusToString(update_engine_status.status),
223 update_engine_status.new_version,
Amin Hassani6bb001f2018-02-26 14:33:02 -0800224 update_engine_status.new_size_bytes);
Alex Deymofa78f142016-01-26 21:36:16 -0800225}
226
Alex Deymob7ca0962014-10-01 17:58:07 -0700227} // namespace chromeos_update_engine