blob: 81a6efdcc656c691a0ed240b4684577b1daca571 [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"
Casey Dahlina93cd532016-01-14 16:55:11 -080018#include "update_engine/dbus-constants.h"
Don Garrettbb26fc82013-11-15 10:40:17 -080019
Alex Deymob7ca0962014-10-01 17:58:07 -070020namespace chromeos_update_engine {
Don Garrettbb26fc82013-11-15 10:40:17 -080021
Casey Dahlina93cd532016-01-14 16:55:11 -080022using brillo::ErrorPtr;
23using std::string;
24using chromeos_update_engine::UpdateEngineService;
25
26DBusUpdateEngineService::DBusUpdateEngineService(SystemState* system_state)
27 : common_(new UpdateEngineService{system_state}) {
28}
Don Garrettbb26fc82013-11-15 10:40:17 -080029
Alex Deymob7ca0962014-10-01 17:58:07 -070030// org::chromium::UpdateEngineInterfaceInterface methods implementation.
Don Garrettbb26fc82013-11-15 10:40:17 -080031
Casey Dahlina93cd532016-01-14 16:55:11 -080032bool DBusUpdateEngineService::AttemptUpdate(ErrorPtr* error,
33 const string& in_app_version,
34 const string& in_omaha_url) {
Alex Deymob7ca0962014-10-01 17:58:07 -070035 return AttemptUpdateWithFlags(
36 error, in_app_version, in_omaha_url, 0 /* no flags */);
Don Garrettbb26fc82013-11-15 10:40:17 -080037}
38
Casey Dahlina93cd532016-01-14 16:55:11 -080039bool DBusUpdateEngineService::AttemptUpdateWithFlags(
40 ErrorPtr* error,
41 const string& in_app_version,
42 const string& in_omaha_url,
43 int32_t in_flags_as_int) {
44 update_engine::AttemptUpdateFlags flags =
45 static_cast<update_engine::AttemptUpdateFlags>(in_flags_as_int);
46 bool interactive = !(flags &
47 update_engine::kAttemptUpdateFlagNonInteractive);
Jay Srinivasane73acab2012-07-10 14:34:03 -070048
Casey Dahlina93cd532016-01-14 16:55:11 -080049 return common_->AttemptUpdate(
50 error, in_app_version, in_omaha_url,
51 interactive ? 0 : UpdateEngineService::kAttemptUpdateFlagNonInteractive);
Darin Petkov296889c2010-07-23 16:20:54 -070052}
53
Casey Dahlina93cd532016-01-14 16:55:11 -080054bool DBusUpdateEngineService::AttemptRollback(ErrorPtr* error,
55 bool in_powerwash) {
56 return common_->AttemptRollback(error, in_powerwash);
Chris Sosad317e402013-06-12 13:47:09 -070057}
58
Casey Dahlina93cd532016-01-14 16:55:11 -080059bool DBusUpdateEngineService::CanRollback(ErrorPtr* error,
60 bool* out_can_rollback) {
61 return common_->CanRollback(error, out_can_rollback);
Alex Vakulenko2bddadd2014-03-27 13:23:46 -070062}
63
Casey Dahlina93cd532016-01-14 16:55:11 -080064bool DBusUpdateEngineService::ResetStatus(ErrorPtr* error) {
65 return common_->ResetStatus(error);
Don Garrettbb26fc82013-11-15 10:40:17 -080066}
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -070067
Casey Dahlina93cd532016-01-14 16:55:11 -080068bool DBusUpdateEngineService::GetStatus(ErrorPtr* error,
69 int64_t* out_last_checked_time,
70 double* out_progress,
71 string* out_current_operation,
72 string* out_new_version,
73 int64_t* out_new_size) {
74 return common_->GetStatus(error,
75 out_last_checked_time,
76 out_progress,
77 out_current_operation,
78 out_new_version,
79 out_new_size);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070080}
81
Casey Dahlina93cd532016-01-14 16:55:11 -080082bool DBusUpdateEngineService::RebootIfNeeded(ErrorPtr* error) {
83 return common_->RebootIfNeeded(error);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070084}
85
Casey Dahlina93cd532016-01-14 16:55:11 -080086bool DBusUpdateEngineService::SetChannel(ErrorPtr* error,
87 const string& in_target_channel,
88 bool in_is_powerwash_allowed) {
89 return common_->SetChannel(error, in_target_channel, in_is_powerwash_allowed);
Jay Srinivasanae4697c2013-03-18 17:08:08 -070090}
91
Casey Dahlina93cd532016-01-14 16:55:11 -080092bool DBusUpdateEngineService::GetChannel(ErrorPtr* error,
93 bool in_get_current_channel,
94 string* out_channel) {
95 return common_->GetChannel(error, in_get_current_channel, out_channel);
Darin Petkov8daa3242010-10-25 13:28:47 -070096}
97
Casey Dahlina93cd532016-01-14 16:55:11 -080098bool DBusUpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error,
99 bool in_enabled) {
100 return common_->SetP2PUpdatePermission(error, in_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700101}
102
Casey Dahlina93cd532016-01-14 16:55:11 -0800103bool DBusUpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error,
104 bool* out_enabled) {
105 return common_->GetP2PUpdatePermission(error, out_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700106}
107
Casey Dahlina93cd532016-01-14 16:55:11 -0800108bool DBusUpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error,
109 bool in_allowed) {
110 return common_->SetUpdateOverCellularPermission(error, in_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700111}
112
Casey Dahlina93cd532016-01-14 16:55:11 -0800113bool DBusUpdateEngineService::GetUpdateOverCellularPermission(
114 ErrorPtr* error, bool* out_allowed) {
115 return common_->GetUpdateOverCellularPermission(error, out_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700116}
117
Casey Dahlina93cd532016-01-14 16:55:11 -0800118bool DBusUpdateEngineService::GetDurationSinceUpdate(
119 ErrorPtr* error, int64_t* out_usec_wallclock) {
120 return common_->GetDurationSinceUpdate(error, out_usec_wallclock);
David Zeuthen3c55abd2013-10-14 12:48:03 -0700121}
122
Casey Dahlina93cd532016-01-14 16:55:11 -0800123bool DBusUpdateEngineService::GetPrevVersion(ErrorPtr* error,
124 string* out_prev_version) {
125 return common_->GetPrevVersion(error, out_prev_version);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700126}
Alex Vakulenkodea2eac2014-03-14 15:56:59 -0700127
Casey Dahlina93cd532016-01-14 16:55:11 -0800128bool DBusUpdateEngineService::GetRollbackPartition(
129 ErrorPtr* error, string* out_rollback_partition_name) {
130 return common_->GetRollbackPartition(error, out_rollback_partition_name);
Alex Deymob7ca0962014-10-01 17:58:07 -0700131}
132
Alex Deymob7ca0962014-10-01 17:58:07 -0700133UpdateEngineAdaptor::UpdateEngineAdaptor(SystemState* system_state,
134 const scoped_refptr<dbus::Bus>& bus)
135 : org::chromium::UpdateEngineInterfaceAdaptor(&dbus_service_),
136 bus_(bus),
137 dbus_service_(system_state),
Alex Deymod6deb1d2015-08-28 15:54:37 -0700138 dbus_object_(nullptr,
139 bus,
140 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)) {}
Alex Deymob7ca0962014-10-01 17:58:07 -0700141
142void UpdateEngineAdaptor::RegisterAsync(
143 const base::Callback<void(bool)>& completion_callback) {
144 RegisterWithDBusObject(&dbus_object_);
145 dbus_object_.RegisterAsync(completion_callback);
146}
147
148bool UpdateEngineAdaptor::RequestOwnership() {
Alex Deymod6deb1d2015-08-28 15:54:37 -0700149 return bus_->RequestOwnershipAndBlock(update_engine::kUpdateEngineServiceName,
Alex Deymob7ca0962014-10-01 17:58:07 -0700150 dbus::Bus::REQUIRE_PRIMARY);
151}
152
153} // namespace chromeos_update_engine