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" |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 20 | #include "update_engine/update_status_utils.h" |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 21 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 22 | namespace chromeos_update_engine { |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 23 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 24 | using brillo::ErrorPtr; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 25 | using chromeos_update_engine::UpdateEngineService; |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 26 | using std::string; |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 27 | |
| 28 | DBusUpdateEngineService::DBusUpdateEngineService(SystemState* system_state) |
| 29 | : common_(new UpdateEngineService{system_state}) { |
| 30 | } |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 31 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 32 | // org::chromium::UpdateEngineInterfaceInterface methods implementation. |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 33 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 34 | bool DBusUpdateEngineService::AttemptUpdate(ErrorPtr* error, |
| 35 | const string& in_app_version, |
| 36 | const string& in_omaha_url) { |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 37 | return AttemptUpdateWithFlags( |
| 38 | error, in_app_version, in_omaha_url, 0 /* no flags */); |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 39 | } |
| 40 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 41 | bool 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 Srinivasan | e73acab | 2012-07-10 14:34:03 -0700 | [diff] [blame] | 50 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 51 | return common_->AttemptUpdate( |
| 52 | error, in_app_version, in_omaha_url, |
| 53 | interactive ? 0 : UpdateEngineService::kAttemptUpdateFlagNonInteractive); |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 56 | bool DBusUpdateEngineService::AttemptRollback(ErrorPtr* error, |
| 57 | bool in_powerwash) { |
| 58 | return common_->AttemptRollback(error, in_powerwash); |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 61 | bool DBusUpdateEngineService::CanRollback(ErrorPtr* error, |
| 62 | bool* out_can_rollback) { |
| 63 | return common_->CanRollback(error, out_can_rollback); |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 66 | bool DBusUpdateEngineService::ResetStatus(ErrorPtr* error) { |
| 67 | return common_->ResetStatus(error); |
Don Garrett | bb26fc8 | 2013-11-15 10:40:17 -0800 | [diff] [blame] | 68 | } |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 69 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 70 | bool 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 Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 84 | bool DBusUpdateEngineService::RebootIfNeeded(ErrorPtr* error) { |
| 85 | return common_->RebootIfNeeded(error); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 88 | bool 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 Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 94 | bool 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 Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 100 | bool DBusUpdateEngineService::SetP2PUpdatePermission(ErrorPtr* error, |
| 101 | bool in_enabled) { |
| 102 | return common_->SetP2PUpdatePermission(error, in_enabled); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 105 | bool DBusUpdateEngineService::GetP2PUpdatePermission(ErrorPtr* error, |
| 106 | bool* out_enabled) { |
| 107 | return common_->GetP2PUpdatePermission(error, out_enabled); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 110 | bool DBusUpdateEngineService::SetUpdateOverCellularPermission(ErrorPtr* error, |
| 111 | bool in_allowed) { |
| 112 | return common_->SetUpdateOverCellularPermission(error, in_allowed); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 115 | bool DBusUpdateEngineService::GetUpdateOverCellularPermission( |
| 116 | ErrorPtr* error, bool* out_allowed) { |
| 117 | return common_->GetUpdateOverCellularPermission(error, out_allowed); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 120 | bool DBusUpdateEngineService::GetDurationSinceUpdate( |
| 121 | ErrorPtr* error, int64_t* out_usec_wallclock) { |
| 122 | return common_->GetDurationSinceUpdate(error, out_usec_wallclock); |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 125 | bool DBusUpdateEngineService::GetPrevVersion(ErrorPtr* error, |
| 126 | string* out_prev_version) { |
| 127 | return common_->GetPrevVersion(error, out_prev_version); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 128 | } |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 129 | |
Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 130 | bool DBusUpdateEngineService::GetRollbackPartition( |
| 131 | ErrorPtr* error, string* out_rollback_partition_name) { |
| 132 | return common_->GetRollbackPartition(error, out_rollback_partition_name); |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Shuqian Zhao | 2997173 | 2016-02-05 11:29:32 -0800 | [diff] [blame] | 135 | bool DBusUpdateEngineService::GetLastAttemptError( |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame^] | 136 | ErrorPtr* error, int32_t* out_last_attempt_error) { |
| 137 | return common_->GetLastAttemptError(error, out_last_attempt_error); |
| 138 | } |
| 139 | |
| 140 | bool DBusUpdateEngineService::GetEolStatus(ErrorPtr* error, |
| 141 | int32_t* out_eol_status) { |
| 142 | return common_->GetEolStatus(error, out_eol_status); |
Shuqian Zhao | 2997173 | 2016-02-05 11:29:32 -0800 | [diff] [blame] | 143 | } |
| 144 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 145 | UpdateEngineAdaptor::UpdateEngineAdaptor(SystemState* system_state, |
| 146 | const scoped_refptr<dbus::Bus>& bus) |
| 147 | : org::chromium::UpdateEngineInterfaceAdaptor(&dbus_service_), |
| 148 | bus_(bus), |
| 149 | dbus_service_(system_state), |
Alex Deymo | d6deb1d | 2015-08-28 15:54:37 -0700 | [diff] [blame] | 150 | dbus_object_(nullptr, |
| 151 | bus, |
| 152 | dbus::ObjectPath(update_engine::kUpdateEngineServicePath)) {} |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 153 | |
| 154 | void UpdateEngineAdaptor::RegisterAsync( |
| 155 | const base::Callback<void(bool)>& completion_callback) { |
| 156 | RegisterWithDBusObject(&dbus_object_); |
| 157 | dbus_object_.RegisterAsync(completion_callback); |
| 158 | } |
| 159 | |
| 160 | bool UpdateEngineAdaptor::RequestOwnership() { |
Alex Deymo | d6deb1d | 2015-08-28 15:54:37 -0700 | [diff] [blame] | 161 | return bus_->RequestOwnershipAndBlock(update_engine::kUpdateEngineServiceName, |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 162 | dbus::Bus::REQUIRE_PRIMARY); |
| 163 | } |
| 164 | |
Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 165 | void UpdateEngineAdaptor::SendStatusUpdate(int64_t last_checked_time, |
| 166 | double progress, |
| 167 | update_engine::UpdateStatus status, |
| 168 | const string& new_version, |
| 169 | int64_t new_size) { |
| 170 | const string str_status = UpdateStatusToString(status); |
| 171 | SendStatusUpdateSignal( |
| 172 | last_checked_time, progress, str_status, new_version, new_size); |
| 173 | } |
| 174 | |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 175 | } // namespace chromeos_update_engine |