Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 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 Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 16 | |
| 17 | #include "update_engine/dbus_service.h" |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 18 | |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 19 | #include <string> |
| 20 | #include <vector> |
| 21 | |
Amin Hassani | 9b66aa6 | 2019-03-14 14:13:30 -0700 | [diff] [blame] | 22 | #include <dlcservice/proto_bindings/dlcservice.pb.h> |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 23 | #include <update_engine/dbus-constants.h> |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 24 | |
Sen Jiang | 299128e | 2016-06-03 17:48:18 -0700 | [diff] [blame] | 25 | #include "update_engine/dbus_connection.h" |
Amin Hassani | eb463ee | 2019-06-20 19:23:03 -0700 | [diff] [blame] | 26 | #include "update_engine/proto_bindings/update_engine.pb.h" |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 27 | #include "update_engine/update_status_utils.h" |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 28 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 29 | namespace chromeos_update_engine { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 30 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 31 | using brillo::ErrorPtr; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 32 | using chromeos_update_engine::UpdateEngineService; |
Amin Hassani | 3bab177 | 2019-06-21 14:58:25 -0700 | [diff] [blame] | 33 | using dlcservice::DlcModuleList; |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 34 | using std::string; |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 35 | using std::vector; |
Amin Hassani | a441743 | 2019-07-08 12:52:40 -0700 | [diff] [blame] | 36 | using update_engine::Operation; |
Amin Hassani | eb463ee | 2019-06-20 19:23:03 -0700 | [diff] [blame] | 37 | using update_engine::StatusResult; |
Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 38 | using update_engine::UpdateEngineStatus; |
Amin Hassani | a441743 | 2019-07-08 12:52:40 -0700 | [diff] [blame] | 39 | using update_engine::UpdateStatus; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 40 | |
Amin Hassani | eb463ee | 2019-06-20 19:23:03 -0700 | [diff] [blame] | 41 | namespace { |
| 42 | // Converts the internal |UpdateEngineStatus| to the protobuf |StatusResult|. |
| 43 | void ConvertToStatusResult(const UpdateEngineStatus& ue_status, |
| 44 | StatusResult* out_status) { |
| 45 | out_status->set_last_checked_time(ue_status.last_checked_time); |
| 46 | out_status->set_progress(ue_status.progress); |
Amin Hassani | a441743 | 2019-07-08 12:52:40 -0700 | [diff] [blame] | 47 | out_status->set_current_operation(static_cast<Operation>(ue_status.status)); |
Amin Hassani | eb463ee | 2019-06-20 19:23:03 -0700 | [diff] [blame] | 48 | out_status->set_new_version(ue_status.new_version); |
| 49 | out_status->set_new_size(ue_status.new_size_bytes); |
Jae Hoon Kim | 2f78c1c | 2019-07-25 13:20:43 -0700 | [diff] [blame^] | 50 | out_status->set_is_install(ue_status.is_install); |
Amin Hassani | eb463ee | 2019-06-20 19:23:03 -0700 | [diff] [blame] | 51 | } |
| 52 | } // namespace |
| 53 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 54 | DBusUpdateEngineService::DBusUpdateEngineService(SystemState* system_state) |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 55 | : common_(new UpdateEngineService{system_state}) {} |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 56 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 57 | // org::chromium::UpdateEngineInterfaceInterface methods implementation. |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 58 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 59 | bool DBusUpdateEngineService::AttemptUpdate(ErrorPtr* error, |
| 60 | const string& in_app_version, |
| 61 | const string& in_omaha_url) { |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 62 | return AttemptUpdateWithFlags( |
| 63 | error, in_app_version, in_omaha_url, 0 /* no flags */); |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 66 | bool DBusUpdateEngineService::AttemptUpdateWithFlags( |
| 67 | ErrorPtr* error, |
| 68 | const string& in_app_version, |
| 69 | const string& in_omaha_url, |
| 70 | int32_t in_flags_as_int) { |
| 71 | update_engine::AttemptUpdateFlags flags = |
| 72 | static_cast<update_engine::AttemptUpdateFlags>(in_flags_as_int); |
Amin Hassani | 6bb001f | 2018-02-26 14:33:02 -0800 | [diff] [blame] | 73 | bool interactive = !(flags & update_engine::kAttemptUpdateFlagNonInteractive); |
| 74 | bool result; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 75 | return common_->AttemptUpdate( |
Amin Hassani | 0eae427 | 2018-06-01 11:31:34 -0700 | [diff] [blame] | 76 | error, |
| 77 | in_app_version, |
| 78 | in_omaha_url, |
| 79 | interactive ? 0 : update_engine::UpdateAttemptFlags::kFlagNonInteractive, |
| 80 | &result); |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 83 | bool DBusUpdateEngineService::AttemptInstall(ErrorPtr* error, |
Amin Hassani | 3bab177 | 2019-06-21 14:58:25 -0700 | [diff] [blame] | 84 | const DlcModuleList& request) { |
Amin Hassani | 9b66aa6 | 2019-03-14 14:13:30 -0700 | [diff] [blame] | 85 | vector<string> dlc_ids; |
Amin Hassani | 3bab177 | 2019-06-21 14:58:25 -0700 | [diff] [blame] | 86 | for (const auto& dlc_module_info : request.dlc_module_infos()) { |
Amin Hassani | 9b66aa6 | 2019-03-14 14:13:30 -0700 | [diff] [blame] | 87 | if (dlc_module_info.dlc_id().empty()) { |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 88 | *error = brillo::Error::Create( |
Amin Hassani | 3bab177 | 2019-06-21 14:58:25 -0700 | [diff] [blame] | 89 | FROM_HERE, "update_engine", "INTERNAL", "Empty DLC ID passed."); |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 90 | return false; |
| 91 | } |
Amin Hassani | 9b66aa6 | 2019-03-14 14:13:30 -0700 | [diff] [blame] | 92 | dlc_ids.push_back(dlc_module_info.dlc_id()); |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 93 | } |
Amin Hassani | 3bab177 | 2019-06-21 14:58:25 -0700 | [diff] [blame] | 94 | return common_->AttemptInstall(error, request.omaha_url(), dlc_ids); |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 97 | bool DBusUpdateEngineService::AttemptRollback(ErrorPtr* error, |
| 98 | bool in_powerwash) { |
| 99 | return common_->AttemptRollback(error, in_powerwash); |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 102 | bool DBusUpdateEngineService::CanRollback(ErrorPtr* error, |
| 103 | bool* out_can_rollback) { |
| 104 | return common_->CanRollback(error, out_can_rollback); |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 107 | bool DBusUpdateEngineService::ResetStatus(ErrorPtr* error) { |
| 108 | return common_->ResetStatus(error); |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 109 | } |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 110 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 111 | bool DBusUpdateEngineService::GetStatus(ErrorPtr* error, |
| 112 | int64_t* out_last_checked_time, |
| 113 | double* out_progress, |
| 114 | string* out_current_operation, |
| 115 | string* out_new_version, |
| 116 | int64_t* out_new_size) { |
Amin Hassani | 6bb001f | 2018-02-26 14:33:02 -0800 | [diff] [blame] | 117 | UpdateEngineStatus status; |
| 118 | if (!common_->GetStatus(error, &status)) { |
| 119 | return false; |
| 120 | } |
| 121 | *out_last_checked_time = status.last_checked_time; |
| 122 | *out_progress = status.progress; |
| 123 | *out_current_operation = UpdateStatusToString(status.status); |
| 124 | *out_new_version = status.new_version; |
| 125 | *out_new_size = status.new_size_bytes; |
| 126 | return true; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Amin Hassani | eb463ee | 2019-06-20 19:23:03 -0700 | [diff] [blame] | 129 | bool DBusUpdateEngineService::GetStatusAdvanced(ErrorPtr* error, |
| 130 | StatusResult* out_status) { |
| 131 | UpdateEngineStatus status; |
| 132 | if (!common_->GetStatus(error, &status)) { |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | ConvertToStatusResult(status, out_status); |
| 137 | return true; |
| 138 | } |
| 139 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 140 | bool DBusUpdateEngineService::RebootIfNeeded(ErrorPtr* error) { |
| 141 | return common_->RebootIfNeeded(error); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 144 | bool DBusUpdateEngineService::SetChannel(ErrorPtr* error, |
| 145 | const string& in_target_channel, |
| 146 | bool in_is_powerwash_allowed) { |
| 147 | return common_->SetChannel(error, in_target_channel, in_is_powerwash_allowed); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 150 | bool DBusUpdateEngineService::GetChannel(ErrorPtr* error, |
| 151 | bool in_get_current_channel, |
| 152 | string* out_channel) { |
| 153 | return common_->GetChannel(error, in_get_current_channel, out_channel); |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Alex Deymo | 5b5fa8b | 2016-10-06 15:40:49 -0700 | [diff] [blame] | 156 | bool DBusUpdateEngineService::GetCohortHint(ErrorPtr* error, |
| 157 | string* out_cohort_hint) { |
| 158 | return common_->GetCohortHint(error, out_cohort_hint); |
| 159 | } |
| 160 | |
| 161 | bool DBusUpdateEngineService::SetCohortHint(ErrorPtr* error, |
| 162 | const string& in_cohort_hint) { |
| 163 | return common_->SetCohortHint(error, in_cohort_hint); |
| 164 | } |
| 165 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 166 | bool DBusUpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error, |
| 167 | bool in_enabled) { |
| 168 | return common_->SetP2PUpdatePermission(error, in_enabled); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 171 | bool DBusUpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error, |
| 172 | bool* out_enabled) { |
| 173 | return common_->GetP2PUpdatePermission(error, out_enabled); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 176 | bool DBusUpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error, |
| 177 | bool in_allowed) { |
| 178 | return common_->SetUpdateOverCellularPermission(error, in_allowed); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 181 | bool DBusUpdateEngineService::SetUpdateOverCellularTarget( |
| 182 | brillo::ErrorPtr* error, |
| 183 | const std::string& target_version, |
| 184 | int64_t target_size) { |
| 185 | return common_->SetUpdateOverCellularTarget( |
| 186 | error, target_version, target_size); |
| 187 | } |
| 188 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 189 | bool DBusUpdateEngineService::GetUpdateOverCellularPermission( |
| 190 | ErrorPtr* error, bool* out_allowed) { |
| 191 | return common_->GetUpdateOverCellularPermission(error, out_allowed); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 194 | bool DBusUpdateEngineService::GetDurationSinceUpdate( |
| 195 | ErrorPtr* error, int64_t* out_usec_wallclock) { |
| 196 | return common_->GetDurationSinceUpdate(error, out_usec_wallclock); |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 199 | bool DBusUpdateEngineService::GetPrevVersion(ErrorPtr* error, |
| 200 | string* out_prev_version) { |
| 201 | return common_->GetPrevVersion(error, out_prev_version); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 202 | } |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 203 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 204 | bool DBusUpdateEngineService::GetRollbackPartition( |
| 205 | ErrorPtr* error, string* out_rollback_partition_name) { |
| 206 | return common_->GetRollbackPartition(error, out_rollback_partition_name); |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Shuqian Zhao | 2997173 | 2016-02-05 11:29:32 -0800 | [diff] [blame] | 209 | bool DBusUpdateEngineService::GetLastAttemptError( |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 210 | ErrorPtr* error, int32_t* out_last_attempt_error) { |
| 211 | return common_->GetLastAttemptError(error, out_last_attempt_error); |
| 212 | } |
| 213 | |
| 214 | bool DBusUpdateEngineService::GetEolStatus(ErrorPtr* error, |
| 215 | int32_t* out_eol_status) { |
| 216 | return common_->GetEolStatus(error, out_eol_status); |
Shuqian Zhao | 2997173 | 2016-02-05 11:29:32 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Sen Jiang | 299128e | 2016-06-03 17:48:18 -0700 | [diff] [blame] | 219 | UpdateEngineAdaptor::UpdateEngineAdaptor(SystemState* system_state) |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 220 | : org::chromium::UpdateEngineInterfaceAdaptor(&dbus_service_), |
Sen Jiang | 299128e | 2016-06-03 17:48:18 -0700 | [diff] [blame] | 221 | bus_(DBusConnection::Get()->GetDBus()), |
| 222 | dbus_service_(system_state), |
| 223 | dbus_object_(nullptr, |
| 224 | bus_, |
| 225 | dbus::ObjectPath(update_engine::kUpdateEngineServicePath)) {} |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 226 | |
| 227 | void UpdateEngineAdaptor::RegisterAsync( |
| 228 | const base::Callback<void(bool)>& completion_callback) { |
| 229 | RegisterWithDBusObject(&dbus_object_); |
| 230 | dbus_object_.RegisterAsync(completion_callback); |
| 231 | } |
| 232 | |
| 233 | bool UpdateEngineAdaptor::RequestOwnership() { |
Alex Deymo | d6deb1d | 2015-08-28 15:54:37 -0700 | [diff] [blame] | 234 | return bus_->RequestOwnershipAndBlock(update_engine::kUpdateEngineServiceName, |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 235 | dbus::Bus::REQUIRE_PRIMARY); |
| 236 | } |
| 237 | |
Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 238 | void UpdateEngineAdaptor::SendStatusUpdate( |
| 239 | const UpdateEngineStatus& update_engine_status) { |
Amin Hassani | eb463ee | 2019-06-20 19:23:03 -0700 | [diff] [blame] | 240 | StatusResult status; |
| 241 | ConvertToStatusResult(update_engine_status, &status); |
| 242 | |
| 243 | // TODO(crbug.com/977320): Deprecate |StatusUpdate| signal. |
| 244 | SendStatusUpdateSignal(status.last_checked_time(), |
| 245 | status.progress(), |
Amin Hassani | a441743 | 2019-07-08 12:52:40 -0700 | [diff] [blame] | 246 | UpdateStatusToString(static_cast<UpdateStatus>( |
| 247 | status.current_operation())), |
Amin Hassani | eb463ee | 2019-06-20 19:23:03 -0700 | [diff] [blame] | 248 | status.new_version(), |
| 249 | status.new_size()); |
| 250 | |
| 251 | // Send |StatusUpdateAdvanced| signal. |
| 252 | SendStatusUpdateAdvancedSignal(status); |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 255 | } // namespace chromeos_update_engine |