blob: 46ac1d1aa163083873abd9fcbbdf1baa828fa1c6 [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>
Xiaochu Liu88d90382018-08-29 16:09:11 -070023
Sen Jiang299128e2016-06-03 17:48:18 -070024#include "update_engine/dbus_connection.h"
Amin Hassanieb463ee2019-06-20 19:23:03 -070025#include "update_engine/proto_bindings/update_engine.pb.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;
Amin Hassania4417432019-07-08 12:52:40 -070034using update_engine::Operation;
Amin Hassanieb463ee2019-06-20 19:23:03 -070035using update_engine::StatusResult;
Aaron Wood7f92e2b2017-08-28 14:51:21 -070036using update_engine::UpdateEngineStatus;
Casey Dahlina93cd532016-01-14 16:55:11 -080037
Amin Hassanieb463ee2019-06-20 19:23:03 -070038namespace {
39// Converts the internal |UpdateEngineStatus| to the protobuf |StatusResult|.
40void ConvertToStatusResult(const UpdateEngineStatus& ue_status,
41 StatusResult* out_status) {
42 out_status->set_last_checked_time(ue_status.last_checked_time);
43 out_status->set_progress(ue_status.progress);
Amin Hassania4417432019-07-08 12:52:40 -070044 out_status->set_current_operation(static_cast<Operation>(ue_status.status));
Amin Hassanieb463ee2019-06-20 19:23:03 -070045 out_status->set_new_version(ue_status.new_version);
46 out_status->set_new_size(ue_status.new_size_bytes);
Amin Hassani9be122e2019-08-29 09:20:12 -070047 out_status->set_is_enterprise_rollback(ue_status.is_enterprise_rollback);
Jae Hoon Kim2f78c1c2019-07-25 13:20:43 -070048 out_status->set_is_install(ue_status.is_install);
Jae Hoon Kim051627a2019-09-03 12:56:32 -070049 out_status->set_eol_date(ue_status.eol_date);
Amin Hassanieb463ee2019-06-20 19:23:03 -070050}
51} // namespace
52
Casey Dahlina93cd532016-01-14 16:55:11 -080053DBusUpdateEngineService::DBusUpdateEngineService(SystemState* system_state)
Amin Hassani7cc8bb02019-01-14 16:29:47 -080054 : common_(new UpdateEngineService{system_state}) {}
Don Garrettbb26fc82013-11-15 10:40:17 -080055
Alex Deymob7ca0962014-10-01 17:58:07 -070056// org::chromium::UpdateEngineInterfaceInterface methods implementation.
Don Garrettbb26fc82013-11-15 10:40:17 -080057
Casey Dahlina93cd532016-01-14 16:55:11 -080058bool DBusUpdateEngineService::AttemptUpdate(ErrorPtr* error,
59 const string& in_app_version,
60 const string& in_omaha_url) {
Alex Deymob7ca0962014-10-01 17:58:07 -070061 return AttemptUpdateWithFlags(
62 error, in_app_version, in_omaha_url, 0 /* no flags */);
Don Garrettbb26fc82013-11-15 10:40:17 -080063}
64
Casey Dahlina93cd532016-01-14 16:55:11 -080065bool DBusUpdateEngineService::AttemptUpdateWithFlags(
66 ErrorPtr* error,
67 const string& in_app_version,
68 const string& in_omaha_url,
69 int32_t in_flags_as_int) {
70 update_engine::AttemptUpdateFlags flags =
71 static_cast<update_engine::AttemptUpdateFlags>(in_flags_as_int);
Amin Hassani6bb001f2018-02-26 14:33:02 -080072 bool interactive = !(flags & update_engine::kAttemptUpdateFlagNonInteractive);
73 bool result;
Casey Dahlina93cd532016-01-14 16:55:11 -080074 return common_->AttemptUpdate(
Amin Hassani0eae4272018-06-01 11:31:34 -070075 error,
76 in_app_version,
77 in_omaha_url,
78 interactive ? 0 : update_engine::UpdateAttemptFlags::kFlagNonInteractive,
79 &result);
Darin Petkov296889c2010-07-23 16:20:54 -070080}
81
Xiaochu Liu88d90382018-08-29 16:09:11 -070082bool DBusUpdateEngineService::AttemptInstall(ErrorPtr* error,
Amin Hassanifab175a2020-04-17 11:20:50 -070083 const string& in_omaha_url,
84 const vector<string>& dlc_ids) {
85 return common_->AttemptInstall(error, in_omaha_url, dlc_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
Andrewa8d7df32020-03-15 20:10:01 -0700102bool DBusUpdateEngineService::SetDlcActiveValue(brillo::ErrorPtr* error,
103 bool is_active,
104 const string& dlc_id) {
105 return common_->SetDlcActiveValue(error, is_active, dlc_id);
106}
107
Amin Hassanieb463ee2019-06-20 19:23:03 -0700108bool DBusUpdateEngineService::GetStatusAdvanced(ErrorPtr* error,
109 StatusResult* out_status) {
110 UpdateEngineStatus status;
111 if (!common_->GetStatus(error, &status)) {
112 return false;
113 }
114
115 ConvertToStatusResult(status, out_status);
116 return true;
117}
118
Casey Dahlina93cd532016-01-14 16:55:11 -0800119bool DBusUpdateEngineService::RebootIfNeeded(ErrorPtr* error) {
120 return common_->RebootIfNeeded(error);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700121}
122
Casey Dahlina93cd532016-01-14 16:55:11 -0800123bool DBusUpdateEngineService::SetChannel(ErrorPtr* error,
124 const string& in_target_channel,
125 bool in_is_powerwash_allowed) {
126 return common_->SetChannel(error, in_target_channel, in_is_powerwash_allowed);
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700127}
128
Casey Dahlina93cd532016-01-14 16:55:11 -0800129bool DBusUpdateEngineService::GetChannel(ErrorPtr* error,
130 bool in_get_current_channel,
131 string* out_channel) {
132 return common_->GetChannel(error, in_get_current_channel, out_channel);
Darin Petkov8daa3242010-10-25 13:28:47 -0700133}
134
Alex Deymo5b5fa8b2016-10-06 15:40:49 -0700135bool DBusUpdateEngineService::GetCohortHint(ErrorPtr* error,
136 string* out_cohort_hint) {
137 return common_->GetCohortHint(error, out_cohort_hint);
138}
139
140bool DBusUpdateEngineService::SetCohortHint(ErrorPtr* error,
141 const string& in_cohort_hint) {
142 return common_->SetCohortHint(error, in_cohort_hint);
143}
144
Casey Dahlina93cd532016-01-14 16:55:11 -0800145bool DBusUpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error,
146 bool in_enabled) {
147 return common_->SetP2PUpdatePermission(error, in_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700148}
149
Casey Dahlina93cd532016-01-14 16:55:11 -0800150bool DBusUpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error,
151 bool* out_enabled) {
152 return common_->GetP2PUpdatePermission(error, out_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700153}
154
Casey Dahlina93cd532016-01-14 16:55:11 -0800155bool DBusUpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error,
156 bool in_allowed) {
157 return common_->SetUpdateOverCellularPermission(error, in_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700158}
159
Weidong Guo421ff332017-04-17 10:08:38 -0700160bool DBusUpdateEngineService::SetUpdateOverCellularTarget(
161 brillo::ErrorPtr* error,
162 const std::string& target_version,
163 int64_t target_size) {
164 return common_->SetUpdateOverCellularTarget(
165 error, target_version, target_size);
166}
167
Casey Dahlina93cd532016-01-14 16:55:11 -0800168bool DBusUpdateEngineService::GetUpdateOverCellularPermission(
169 ErrorPtr* error, bool* out_allowed) {
170 return common_->GetUpdateOverCellularPermission(error, out_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700171}
172
Casey Dahlina93cd532016-01-14 16:55:11 -0800173bool DBusUpdateEngineService::GetDurationSinceUpdate(
174 ErrorPtr* error, int64_t* out_usec_wallclock) {
175 return common_->GetDurationSinceUpdate(error, out_usec_wallclock);
David Zeuthen3c55abd2013-10-14 12:48:03 -0700176}
177
Casey Dahlina93cd532016-01-14 16:55:11 -0800178bool DBusUpdateEngineService::GetPrevVersion(ErrorPtr* error,
179 string* out_prev_version) {
180 return common_->GetPrevVersion(error, out_prev_version);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700181}
Alex Vakulenkodea2eac2014-03-14 15:56:59 -0700182
Casey Dahlina93cd532016-01-14 16:55:11 -0800183bool DBusUpdateEngineService::GetRollbackPartition(
184 ErrorPtr* error, string* out_rollback_partition_name) {
185 return common_->GetRollbackPartition(error, out_rollback_partition_name);
Alex Deymob7ca0962014-10-01 17:58:07 -0700186}
187
Shuqian Zhao29971732016-02-05 11:29:32 -0800188bool DBusUpdateEngineService::GetLastAttemptError(
Alex Deymob3fa53b2016-04-18 19:57:58 -0700189 ErrorPtr* error, int32_t* out_last_attempt_error) {
190 return common_->GetLastAttemptError(error, out_last_attempt_error);
191}
192
Sen Jiang299128e2016-06-03 17:48:18 -0700193UpdateEngineAdaptor::UpdateEngineAdaptor(SystemState* system_state)
Alex Deymob7ca0962014-10-01 17:58:07 -0700194 : org::chromium::UpdateEngineInterfaceAdaptor(&dbus_service_),
Sen Jiang299128e2016-06-03 17:48:18 -0700195 bus_(DBusConnection::Get()->GetDBus()),
196 dbus_service_(system_state),
197 dbus_object_(nullptr,
198 bus_,
199 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)) {}
Alex Deymob7ca0962014-10-01 17:58:07 -0700200
201void UpdateEngineAdaptor::RegisterAsync(
202 const base::Callback<void(bool)>& completion_callback) {
203 RegisterWithDBusObject(&dbus_object_);
204 dbus_object_.RegisterAsync(completion_callback);
205}
206
207bool UpdateEngineAdaptor::RequestOwnership() {
Alex Deymod6deb1d2015-08-28 15:54:37 -0700208 return bus_->RequestOwnershipAndBlock(update_engine::kUpdateEngineServiceName,
Alex Deymob7ca0962014-10-01 17:58:07 -0700209 dbus::Bus::REQUIRE_PRIMARY);
210}
211
Aaron Wood7f92e2b2017-08-28 14:51:21 -0700212void UpdateEngineAdaptor::SendStatusUpdate(
213 const UpdateEngineStatus& update_engine_status) {
Amin Hassanieb463ee2019-06-20 19:23:03 -0700214 StatusResult status;
215 ConvertToStatusResult(update_engine_status, &status);
216
Amin Hassanieb463ee2019-06-20 19:23:03 -0700217 // Send |StatusUpdateAdvanced| signal.
218 SendStatusUpdateAdvancedSignal(status);
Alex Deymofa78f142016-01-26 21:36:16 -0800219}
220
Alex Deymob7ca0962014-10-01 17:58:07 -0700221} // namespace chromeos_update_engine