blob: 3a35c71eaef7341cf051dec8925a168b97dac8e4 [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);
50 bool interactive = !(flags &
51 update_engine::kAttemptUpdateFlagNonInteractive);
Jay Srinivasane73acab2012-07-10 14:34:03 -070052
Casey Dahlina93cd532016-01-14 16:55:11 -080053 return common_->AttemptUpdate(
54 error, in_app_version, in_omaha_url,
55 interactive ? 0 : UpdateEngineService::kAttemptUpdateFlagNonInteractive);
Darin Petkov296889c2010-07-23 16:20:54 -070056}
57
Casey Dahlina93cd532016-01-14 16:55:11 -080058bool DBusUpdateEngineService::AttemptRollback(ErrorPtr* error,
59 bool in_powerwash) {
60 return common_->AttemptRollback(error, in_powerwash);
Chris Sosad317e402013-06-12 13:47:09 -070061}
62
Casey Dahlina93cd532016-01-14 16:55:11 -080063bool DBusUpdateEngineService::CanRollback(ErrorPtr* error,
64 bool* out_can_rollback) {
65 return common_->CanRollback(error, out_can_rollback);
Alex Vakulenko2bddadd2014-03-27 13:23:46 -070066}
67
Casey Dahlina93cd532016-01-14 16:55:11 -080068bool DBusUpdateEngineService::ResetStatus(ErrorPtr* error) {
69 return common_->ResetStatus(error);
Don Garrettbb26fc82013-11-15 10:40:17 -080070}
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -070071
Casey Dahlina93cd532016-01-14 16:55:11 -080072bool DBusUpdateEngineService::GetStatus(ErrorPtr* error,
73 int64_t* out_last_checked_time,
74 double* out_progress,
75 string* out_current_operation,
76 string* out_new_version,
77 int64_t* out_new_size) {
78 return common_->GetStatus(error,
79 out_last_checked_time,
80 out_progress,
81 out_current_operation,
82 out_new_version,
83 out_new_size);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070084}
85
Casey Dahlina93cd532016-01-14 16:55:11 -080086bool DBusUpdateEngineService::RebootIfNeeded(ErrorPtr* error) {
87 return common_->RebootIfNeeded(error);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070088}
89
Casey Dahlina93cd532016-01-14 16:55:11 -080090bool DBusUpdateEngineService::SetChannel(ErrorPtr* error,
91 const string& in_target_channel,
92 bool in_is_powerwash_allowed) {
93 return common_->SetChannel(error, in_target_channel, in_is_powerwash_allowed);
Jay Srinivasanae4697c2013-03-18 17:08:08 -070094}
95
Casey Dahlina93cd532016-01-14 16:55:11 -080096bool DBusUpdateEngineService::GetChannel(ErrorPtr* error,
97 bool in_get_current_channel,
98 string* out_channel) {
99 return common_->GetChannel(error, in_get_current_channel, out_channel);
Darin Petkov8daa3242010-10-25 13:28:47 -0700100}
101
Alex Deymo5b5fa8b2016-10-06 15:40:49 -0700102bool DBusUpdateEngineService::GetCohortHint(ErrorPtr* error,
103 string* out_cohort_hint) {
104 return common_->GetCohortHint(error, out_cohort_hint);
105}
106
107bool DBusUpdateEngineService::SetCohortHint(ErrorPtr* error,
108 const string& in_cohort_hint) {
109 return common_->SetCohortHint(error, in_cohort_hint);
110}
111
Casey Dahlina93cd532016-01-14 16:55:11 -0800112bool DBusUpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error,
113 bool in_enabled) {
114 return common_->SetP2PUpdatePermission(error, in_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700115}
116
Casey Dahlina93cd532016-01-14 16:55:11 -0800117bool DBusUpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error,
118 bool* out_enabled) {
119 return common_->GetP2PUpdatePermission(error, out_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700120}
121
Casey Dahlina93cd532016-01-14 16:55:11 -0800122bool DBusUpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error,
123 bool in_allowed) {
124 return common_->SetUpdateOverCellularPermission(error, in_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700125}
126
Casey Dahlina93cd532016-01-14 16:55:11 -0800127bool DBusUpdateEngineService::GetUpdateOverCellularPermission(
128 ErrorPtr* error, bool* out_allowed) {
129 return common_->GetUpdateOverCellularPermission(error, out_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700130}
131
Casey Dahlina93cd532016-01-14 16:55:11 -0800132bool DBusUpdateEngineService::GetDurationSinceUpdate(
133 ErrorPtr* error, int64_t* out_usec_wallclock) {
134 return common_->GetDurationSinceUpdate(error, out_usec_wallclock);
David Zeuthen3c55abd2013-10-14 12:48:03 -0700135}
136
Casey Dahlina93cd532016-01-14 16:55:11 -0800137bool DBusUpdateEngineService::GetPrevVersion(ErrorPtr* error,
138 string* out_prev_version) {
139 return common_->GetPrevVersion(error, out_prev_version);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700140}
Alex Vakulenkodea2eac2014-03-14 15:56:59 -0700141
Casey Dahlina93cd532016-01-14 16:55:11 -0800142bool DBusUpdateEngineService::GetRollbackPartition(
143 ErrorPtr* error, string* out_rollback_partition_name) {
144 return common_->GetRollbackPartition(error, out_rollback_partition_name);
Alex Deymob7ca0962014-10-01 17:58:07 -0700145}
146
Shuqian Zhao29971732016-02-05 11:29:32 -0800147bool DBusUpdateEngineService::GetLastAttemptError(
Alex Deymob3fa53b2016-04-18 19:57:58 -0700148 ErrorPtr* error, int32_t* out_last_attempt_error) {
149 return common_->GetLastAttemptError(error, out_last_attempt_error);
150}
151
152bool DBusUpdateEngineService::GetEolStatus(ErrorPtr* error,
153 int32_t* out_eol_status) {
154 return common_->GetEolStatus(error, out_eol_status);
Shuqian Zhao29971732016-02-05 11:29:32 -0800155}
156
Sen Jiang299128e2016-06-03 17:48:18 -0700157UpdateEngineAdaptor::UpdateEngineAdaptor(SystemState* system_state)
Alex Deymob7ca0962014-10-01 17:58:07 -0700158 : org::chromium::UpdateEngineInterfaceAdaptor(&dbus_service_),
Sen Jiang299128e2016-06-03 17:48:18 -0700159 bus_(DBusConnection::Get()->GetDBus()),
160 dbus_service_(system_state),
161 dbus_object_(nullptr,
162 bus_,
163 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)) {}
Alex Deymob7ca0962014-10-01 17:58:07 -0700164
165void UpdateEngineAdaptor::RegisterAsync(
166 const base::Callback<void(bool)>& completion_callback) {
167 RegisterWithDBusObject(&dbus_object_);
168 dbus_object_.RegisterAsync(completion_callback);
169}
170
171bool UpdateEngineAdaptor::RequestOwnership() {
Alex Deymod6deb1d2015-08-28 15:54:37 -0700172 return bus_->RequestOwnershipAndBlock(update_engine::kUpdateEngineServiceName,
Alex Deymob7ca0962014-10-01 17:58:07 -0700173 dbus::Bus::REQUIRE_PRIMARY);
174}
175
Aaron Wood7f92e2b2017-08-28 14:51:21 -0700176void UpdateEngineAdaptor::SendStatusUpdate(
177 const UpdateEngineStatus& update_engine_status) {
178 SendStatusUpdateSignal(update_engine_status.last_checked_time,
179 update_engine_status.progress,
180 UpdateStatusToString(update_engine_status.status),
181 update_engine_status.new_version,
182 update_engine_status.new_size);
Alex Deymofa78f142016-01-26 21:36:16 -0800183}
184
Alex Deymob7ca0962014-10-01 17:58:07 -0700185} // namespace chromeos_update_engine