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