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