blob: d1e6d9ebbf3e6aee7661f64095d4866e6cbe2c35 [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;
Casey Dahlina93cd532016-01-14 16:55:11 -080028
29DBusUpdateEngineService::DBusUpdateEngineService(SystemState* system_state)
30 : common_(new UpdateEngineService{system_state}) {
31}
Don Garrettbb26fc82013-11-15 10:40:17 -080032
Alex Deymob7ca0962014-10-01 17:58:07 -070033// org::chromium::UpdateEngineInterfaceInterface methods implementation.
Don Garrettbb26fc82013-11-15 10:40:17 -080034
Casey Dahlina93cd532016-01-14 16:55:11 -080035bool DBusUpdateEngineService::AttemptUpdate(ErrorPtr* error,
36 const string& in_app_version,
37 const string& in_omaha_url) {
Alex Deymob7ca0962014-10-01 17:58:07 -070038 return AttemptUpdateWithFlags(
39 error, in_app_version, in_omaha_url, 0 /* no flags */);
Don Garrettbb26fc82013-11-15 10:40:17 -080040}
41
Casey Dahlina93cd532016-01-14 16:55:11 -080042bool DBusUpdateEngineService::AttemptUpdateWithFlags(
43 ErrorPtr* error,
44 const string& in_app_version,
45 const string& in_omaha_url,
46 int32_t in_flags_as_int) {
47 update_engine::AttemptUpdateFlags flags =
48 static_cast<update_engine::AttemptUpdateFlags>(in_flags_as_int);
49 bool interactive = !(flags &
50 update_engine::kAttemptUpdateFlagNonInteractive);
Jay Srinivasane73acab2012-07-10 14:34:03 -070051
Casey Dahlina93cd532016-01-14 16:55:11 -080052 return common_->AttemptUpdate(
53 error, in_app_version, in_omaha_url,
54 interactive ? 0 : UpdateEngineService::kAttemptUpdateFlagNonInteractive);
Darin Petkov296889c2010-07-23 16:20:54 -070055}
56
Casey Dahlina93cd532016-01-14 16:55:11 -080057bool DBusUpdateEngineService::AttemptRollback(ErrorPtr* error,
58 bool in_powerwash) {
59 return common_->AttemptRollback(error, in_powerwash);
Chris Sosad317e402013-06-12 13:47:09 -070060}
61
Casey Dahlina93cd532016-01-14 16:55:11 -080062bool DBusUpdateEngineService::CanRollback(ErrorPtr* error,
63 bool* out_can_rollback) {
64 return common_->CanRollback(error, out_can_rollback);
Alex Vakulenko2bddadd2014-03-27 13:23:46 -070065}
66
Casey Dahlina93cd532016-01-14 16:55:11 -080067bool DBusUpdateEngineService::ResetStatus(ErrorPtr* error) {
68 return common_->ResetStatus(error);
Don Garrettbb26fc82013-11-15 10:40:17 -080069}
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -070070
Casey Dahlina93cd532016-01-14 16:55:11 -080071bool DBusUpdateEngineService::GetStatus(ErrorPtr* error,
72 int64_t* out_last_checked_time,
73 double* out_progress,
74 string* out_current_operation,
75 string* out_new_version,
76 int64_t* out_new_size) {
77 return common_->GetStatus(error,
78 out_last_checked_time,
79 out_progress,
80 out_current_operation,
81 out_new_version,
82 out_new_size);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070083}
84
Casey Dahlina93cd532016-01-14 16:55:11 -080085bool DBusUpdateEngineService::RebootIfNeeded(ErrorPtr* error) {
86 return common_->RebootIfNeeded(error);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070087}
88
Casey Dahlina93cd532016-01-14 16:55:11 -080089bool DBusUpdateEngineService::SetChannel(ErrorPtr* error,
90 const string& in_target_channel,
91 bool in_is_powerwash_allowed) {
92 return common_->SetChannel(error, in_target_channel, in_is_powerwash_allowed);
Jay Srinivasanae4697c2013-03-18 17:08:08 -070093}
94
Casey Dahlina93cd532016-01-14 16:55:11 -080095bool DBusUpdateEngineService::GetChannel(ErrorPtr* error,
96 bool in_get_current_channel,
97 string* out_channel) {
98 return common_->GetChannel(error, in_get_current_channel, out_channel);
Darin Petkov8daa3242010-10-25 13:28:47 -070099}
100
Casey Dahlina93cd532016-01-14 16:55:11 -0800101bool DBusUpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error,
102 bool in_enabled) {
103 return common_->SetP2PUpdatePermission(error, in_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700104}
105
Casey Dahlina93cd532016-01-14 16:55:11 -0800106bool DBusUpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error,
107 bool* out_enabled) {
108 return common_->GetP2PUpdatePermission(error, out_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700109}
110
Casey Dahlina93cd532016-01-14 16:55:11 -0800111bool DBusUpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error,
112 bool in_allowed) {
113 return common_->SetUpdateOverCellularPermission(error, in_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700114}
115
Casey Dahlina93cd532016-01-14 16:55:11 -0800116bool DBusUpdateEngineService::GetUpdateOverCellularPermission(
117 ErrorPtr* error, bool* out_allowed) {
118 return common_->GetUpdateOverCellularPermission(error, out_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700119}
120
Casey Dahlina93cd532016-01-14 16:55:11 -0800121bool DBusUpdateEngineService::GetDurationSinceUpdate(
122 ErrorPtr* error, int64_t* out_usec_wallclock) {
123 return common_->GetDurationSinceUpdate(error, out_usec_wallclock);
David Zeuthen3c55abd2013-10-14 12:48:03 -0700124}
125
Casey Dahlina93cd532016-01-14 16:55:11 -0800126bool DBusUpdateEngineService::GetPrevVersion(ErrorPtr* error,
127 string* out_prev_version) {
128 return common_->GetPrevVersion(error, out_prev_version);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700129}
Alex Vakulenkodea2eac2014-03-14 15:56:59 -0700130
Casey Dahlina93cd532016-01-14 16:55:11 -0800131bool DBusUpdateEngineService::GetRollbackPartition(
132 ErrorPtr* error, string* out_rollback_partition_name) {
133 return common_->GetRollbackPartition(error, out_rollback_partition_name);
Alex Deymob7ca0962014-10-01 17:58:07 -0700134}
135
Shuqian Zhao29971732016-02-05 11:29:32 -0800136bool DBusUpdateEngineService::GetLastAttemptError(
Alex Deymob3fa53b2016-04-18 19:57:58 -0700137 ErrorPtr* error, int32_t* out_last_attempt_error) {
138 return common_->GetLastAttemptError(error, out_last_attempt_error);
139}
140
141bool DBusUpdateEngineService::GetEolStatus(ErrorPtr* error,
142 int32_t* out_eol_status) {
143 return common_->GetEolStatus(error, out_eol_status);
Shuqian Zhao29971732016-02-05 11:29:32 -0800144}
145
Sen Jiang299128e2016-06-03 17:48:18 -0700146UpdateEngineAdaptor::UpdateEngineAdaptor(SystemState* system_state)
Alex Deymob7ca0962014-10-01 17:58:07 -0700147 : org::chromium::UpdateEngineInterfaceAdaptor(&dbus_service_),
Sen Jiang299128e2016-06-03 17:48:18 -0700148 bus_(DBusConnection::Get()->GetDBus()),
149 dbus_service_(system_state),
150 dbus_object_(nullptr,
151 bus_,
152 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)) {}
Alex Deymob7ca0962014-10-01 17:58:07 -0700153
154void UpdateEngineAdaptor::RegisterAsync(
155 const base::Callback<void(bool)>& completion_callback) {
156 RegisterWithDBusObject(&dbus_object_);
157 dbus_object_.RegisterAsync(completion_callback);
158}
159
160bool UpdateEngineAdaptor::RequestOwnership() {
Alex Deymod6deb1d2015-08-28 15:54:37 -0700161 return bus_->RequestOwnershipAndBlock(update_engine::kUpdateEngineServiceName,
Alex Deymob7ca0962014-10-01 17:58:07 -0700162 dbus::Bus::REQUIRE_PRIMARY);
163}
164
Alex Deymofa78f142016-01-26 21:36:16 -0800165void UpdateEngineAdaptor::SendStatusUpdate(int64_t last_checked_time,
166 double progress,
167 update_engine::UpdateStatus status,
168 const string& new_version,
169 int64_t new_size) {
170 const string str_status = UpdateStatusToString(status);
171 SendStatusUpdateSignal(
172 last_checked_time, progress, str_status, new_version, new_size);
173}
174
Alex Deymob7ca0962014-10-01 17:58:07 -0700175} // namespace chromeos_update_engine