blob: 0ab0ac05eb2a4e0779f98d4c3fcc8d5c7e69e626 [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"
Alex Deymofa78f142016-01-26 21:36:16 -080020#include "update_engine/update_status_utils.h"
Don Garrettbb26fc82013-11-15 10:40:17 -080021
Alex Deymob7ca0962014-10-01 17:58:07 -070022namespace chromeos_update_engine {
Don Garrettbb26fc82013-11-15 10:40:17 -080023
Casey Dahlina93cd532016-01-14 16:55:11 -080024using brillo::ErrorPtr;
Casey Dahlina93cd532016-01-14 16:55:11 -080025using chromeos_update_engine::UpdateEngineService;
Alex Deymofa78f142016-01-26 21:36:16 -080026using std::string;
Casey Dahlina93cd532016-01-14 16:55:11 -080027
28DBusUpdateEngineService::DBusUpdateEngineService(SystemState* system_state)
29 : common_(new UpdateEngineService{system_state}) {
30}
Don Garrettbb26fc82013-11-15 10:40:17 -080031
Alex Deymob7ca0962014-10-01 17:58:07 -070032// org::chromium::UpdateEngineInterfaceInterface methods implementation.
Don Garrettbb26fc82013-11-15 10:40:17 -080033
Casey Dahlina93cd532016-01-14 16:55:11 -080034bool DBusUpdateEngineService::AttemptUpdate(ErrorPtr* error,
35 const string& in_app_version,
36 const string& in_omaha_url) {
Alex Deymob7ca0962014-10-01 17:58:07 -070037 return AttemptUpdateWithFlags(
38 error, in_app_version, in_omaha_url, 0 /* no flags */);
Don Garrettbb26fc82013-11-15 10:40:17 -080039}
40
Casey Dahlina93cd532016-01-14 16:55:11 -080041bool DBusUpdateEngineService::AttemptUpdateWithFlags(
42 ErrorPtr* error,
43 const string& in_app_version,
44 const string& in_omaha_url,
45 int32_t in_flags_as_int) {
46 update_engine::AttemptUpdateFlags flags =
47 static_cast<update_engine::AttemptUpdateFlags>(in_flags_as_int);
48 bool interactive = !(flags &
49 update_engine::kAttemptUpdateFlagNonInteractive);
Jay Srinivasane73acab2012-07-10 14:34:03 -070050
Casey Dahlina93cd532016-01-14 16:55:11 -080051 return common_->AttemptUpdate(
52 error, in_app_version, in_omaha_url,
53 interactive ? 0 : UpdateEngineService::kAttemptUpdateFlagNonInteractive);
Darin Petkov296889c2010-07-23 16:20:54 -070054}
55
Casey Dahlina93cd532016-01-14 16:55:11 -080056bool DBusUpdateEngineService::AttemptRollback(ErrorPtr* error,
57 bool in_powerwash) {
58 return common_->AttemptRollback(error, in_powerwash);
Chris Sosad317e402013-06-12 13:47:09 -070059}
60
Casey Dahlina93cd532016-01-14 16:55:11 -080061bool DBusUpdateEngineService::CanRollback(ErrorPtr* error,
62 bool* out_can_rollback) {
63 return common_->CanRollback(error, out_can_rollback);
Alex Vakulenko2bddadd2014-03-27 13:23:46 -070064}
65
Casey Dahlina93cd532016-01-14 16:55:11 -080066bool DBusUpdateEngineService::ResetStatus(ErrorPtr* error) {
67 return common_->ResetStatus(error);
Don Garrettbb26fc82013-11-15 10:40:17 -080068}
Jay Srinivasanc1ba09a2012-08-14 14:15:57 -070069
Casey Dahlina93cd532016-01-14 16:55:11 -080070bool DBusUpdateEngineService::GetStatus(ErrorPtr* error,
71 int64_t* out_last_checked_time,
72 double* out_progress,
73 string* out_current_operation,
74 string* out_new_version,
75 int64_t* out_new_size) {
76 return common_->GetStatus(error,
77 out_last_checked_time,
78 out_progress,
79 out_current_operation,
80 out_new_version,
81 out_new_size);
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070082}
83
Casey Dahlina93cd532016-01-14 16:55:11 -080084bool DBusUpdateEngineService::RebootIfNeeded(ErrorPtr* error) {
85 return common_->RebootIfNeeded(error);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070086}
87
Casey Dahlina93cd532016-01-14 16:55:11 -080088bool DBusUpdateEngineService::SetChannel(ErrorPtr* error,
89 const string& in_target_channel,
90 bool in_is_powerwash_allowed) {
91 return common_->SetChannel(error, in_target_channel, in_is_powerwash_allowed);
Jay Srinivasanae4697c2013-03-18 17:08:08 -070092}
93
Casey Dahlina93cd532016-01-14 16:55:11 -080094bool DBusUpdateEngineService::GetChannel(ErrorPtr* error,
95 bool in_get_current_channel,
96 string* out_channel) {
97 return common_->GetChannel(error, in_get_current_channel, out_channel);
Darin Petkov8daa3242010-10-25 13:28:47 -070098}
99
Casey Dahlina93cd532016-01-14 16:55:11 -0800100bool DBusUpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error,
101 bool in_enabled) {
102 return common_->SetP2PUpdatePermission(error, in_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700103}
104
Casey Dahlina93cd532016-01-14 16:55:11 -0800105bool DBusUpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error,
106 bool* out_enabled) {
107 return common_->GetP2PUpdatePermission(error, out_enabled);
Alex Deymo5fdf7762013-07-17 20:01:40 -0700108}
109
Casey Dahlina93cd532016-01-14 16:55:11 -0800110bool DBusUpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error,
111 bool in_allowed) {
112 return common_->SetUpdateOverCellularPermission(error, in_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700113}
114
Casey Dahlina93cd532016-01-14 16:55:11 -0800115bool DBusUpdateEngineService::GetUpdateOverCellularPermission(
116 ErrorPtr* error, bool* out_allowed) {
117 return common_->GetUpdateOverCellularPermission(error, out_allowed);
Alex Deymof4867c42013-06-28 14:41:39 -0700118}
119
Casey Dahlina93cd532016-01-14 16:55:11 -0800120bool DBusUpdateEngineService::GetDurationSinceUpdate(
121 ErrorPtr* error, int64_t* out_usec_wallclock) {
122 return common_->GetDurationSinceUpdate(error, out_usec_wallclock);
David Zeuthen3c55abd2013-10-14 12:48:03 -0700123}
124
Casey Dahlina93cd532016-01-14 16:55:11 -0800125bool DBusUpdateEngineService::GetPrevVersion(ErrorPtr* error,
126 string* out_prev_version) {
127 return common_->GetPrevVersion(error, out_prev_version);
Andrew de los Reyes63b96d72010-05-10 13:08:54 -0700128}
Alex Vakulenkodea2eac2014-03-14 15:56:59 -0700129
Casey Dahlina93cd532016-01-14 16:55:11 -0800130bool DBusUpdateEngineService::GetRollbackPartition(
131 ErrorPtr* error, string* out_rollback_partition_name) {
132 return common_->GetRollbackPartition(error, out_rollback_partition_name);
Alex Deymob7ca0962014-10-01 17:58:07 -0700133}
134
Alex Deymob7ca0962014-10-01 17:58:07 -0700135UpdateEngineAdaptor::UpdateEngineAdaptor(SystemState* system_state,
136 const scoped_refptr<dbus::Bus>& bus)
137 : org::chromium::UpdateEngineInterfaceAdaptor(&dbus_service_),
138 bus_(bus),
139 dbus_service_(system_state),
Alex Deymod6deb1d2015-08-28 15:54:37 -0700140 dbus_object_(nullptr,
141 bus,
142 dbus::ObjectPath(update_engine::kUpdateEngineServicePath)) {}
Alex Deymob7ca0962014-10-01 17:58:07 -0700143
144void UpdateEngineAdaptor::RegisterAsync(
145 const base::Callback<void(bool)>& completion_callback) {
146 RegisterWithDBusObject(&dbus_object_);
147 dbus_object_.RegisterAsync(completion_callback);
148}
149
150bool UpdateEngineAdaptor::RequestOwnership() {
Alex Deymod6deb1d2015-08-28 15:54:37 -0700151 return bus_->RequestOwnershipAndBlock(update_engine::kUpdateEngineServiceName,
Alex Deymob7ca0962014-10-01 17:58:07 -0700152 dbus::Bus::REQUIRE_PRIMARY);
153}
154
Alex Deymofa78f142016-01-26 21:36:16 -0800155void UpdateEngineAdaptor::SendStatusUpdate(int64_t last_checked_time,
156 double progress,
157 update_engine::UpdateStatus status,
158 const string& new_version,
159 int64_t new_size) {
160 const string str_status = UpdateStatusToString(status);
161 SendStatusUpdateSignal(
162 last_checked_time, progress, str_status, new_version, new_size);
163}
164
Alex Deymob7ca0962014-10-01 17:58:07 -0700165} // namespace chromeos_update_engine