Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2015 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 | // |
| 16 | |
| 17 | #include "update_engine/client_library/client_impl.h" |
| 18 | |
| 19 | #include <dbus/bus.h> |
| 20 | #include <update_engine/dbus-constants.h> |
| 21 | |
| 22 | #include "update_engine/update_status_utils.h" |
| 23 | |
| 24 | using chromeos_update_engine::StringToUpdateStatus; |
| 25 | using dbus::Bus; |
| 26 | using org::chromium::UpdateEngineInterfaceProxy; |
| 27 | using std::string; |
| 28 | |
| 29 | namespace update_engine { |
| 30 | namespace internal { |
| 31 | |
| 32 | UpdateEngineClientImpl::UpdateEngineClientImpl() { |
| 33 | Bus::Options options; |
| 34 | options.bus_type = Bus::SYSTEM; |
| 35 | scoped_refptr<Bus> bus{new Bus{options}}; |
| 36 | proxy_.reset(new UpdateEngineInterfaceProxy{bus}); |
| 37 | } |
| 38 | |
| 39 | bool UpdateEngineClientImpl::AttemptUpdate(const string& in_app_version, |
| 40 | const string& in_omaha_url, |
| 41 | bool at_user_request) { |
| 42 | return proxy_->AttemptUpdateWithFlags( |
| 43 | in_app_version, |
| 44 | in_omaha_url, |
| 45 | (at_user_request) ? 0 : kAttemptUpdateFlagNonInteractive, |
| 46 | nullptr); |
| 47 | } |
| 48 | |
| 49 | bool UpdateEngineClientImpl::GetStatus(int64_t* out_last_checked_time, |
| 50 | double* out_progress, |
| 51 | UpdateStatus* out_update_status, |
| 52 | string* out_new_version, |
| 53 | int64_t* out_new_size) { |
| 54 | string status_as_string; |
| 55 | const bool success = proxy_->GetStatus( |
| 56 | out_last_checked_time, |
| 57 | out_progress, |
| 58 | &status_as_string, |
| 59 | out_new_version, |
| 60 | out_new_size, |
| 61 | nullptr); |
| 62 | if (!success) { |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | return StringToUpdateStatus(status_as_string, out_update_status); |
| 67 | } |
| 68 | |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame^] | 69 | bool UpdateEngineClientImpl::SetUpdateOverCellularPermission(bool allowed) { |
| 70 | return proxy_->SetUpdateOverCellularPermission(allowed, nullptr); |
| 71 | } |
| 72 | |
| 73 | bool UpdateEngineClientImpl::GetUpdateOverCellularPermission(bool *allowed) { |
| 74 | return proxy_->GetUpdateOverCellularPermission(allowed, nullptr); |
| 75 | } |
| 76 | |
| 77 | bool UpdateEngineClientImpl::SetP2PUpdatePermission(bool enabled) { |
| 78 | return proxy_->SetP2PUpdatePermission(enabled, nullptr); |
| 79 | } |
| 80 | |
| 81 | bool UpdateEngineClientImpl::GetP2PUpdatePermission(bool* enabled) { |
| 82 | return proxy_->GetP2PUpdatePermission(enabled, nullptr); |
| 83 | } |
| 84 | |
| 85 | bool UpdateEngineClientImpl::Rollback(bool powerwash) { |
| 86 | return proxy_->AttemptRollback(powerwash, nullptr); |
| 87 | } |
| 88 | |
| 89 | bool UpdateEngineClientImpl::GetRollbackPartition(string* rollback_partition) { |
| 90 | return proxy_->GetRollbackPartition(rollback_partition, nullptr); |
| 91 | } |
| 92 | |
| 93 | bool UpdateEngineClientImpl::GetPrevVersion(string* prev_version) { |
| 94 | return proxy_->GetPrevVersion(prev_version, nullptr); |
| 95 | } |
| 96 | |
| 97 | void UpdateEngineClientImpl::RebootIfNeeded() { |
| 98 | bool ret = proxy_->RebootIfNeeded(nullptr); |
| 99 | if (!ret) { |
| 100 | // Reboot error code doesn't necessarily mean that a reboot |
| 101 | // failed. For example, D-Bus may be shutdown before we receive the |
| 102 | // result. |
| 103 | LOG(INFO) << "RebootIfNeeded() failure ignored."; |
| 104 | } |
| 105 | } |
| 106 | |
Casey Dahlin | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame] | 107 | bool UpdateEngineClientImpl::ResetStatus() { |
| 108 | return proxy_->ResetStatus(nullptr); |
| 109 | } |
| 110 | |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 111 | bool UpdateEngineClientImpl::SetTargetChannel(const string& in_target_channel, |
| 112 | bool allow_powerwash) { |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 113 | return proxy_->SetChannel( |
| 114 | in_target_channel, |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 115 | allow_powerwash, |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 116 | nullptr); |
| 117 | } |
| 118 | |
| 119 | bool UpdateEngineClientImpl::GetTargetChannel(string* out_channel) { |
| 120 | return proxy_->GetChannel( |
| 121 | false, // Get the target channel. |
| 122 | out_channel, |
| 123 | nullptr); |
| 124 | } |
| 125 | |
| 126 | bool UpdateEngineClientImpl::GetChannel(string* out_channel) { |
| 127 | return proxy_->GetChannel( |
| 128 | true, // Get the current channel. |
| 129 | out_channel, |
| 130 | nullptr); |
| 131 | } |
| 132 | |
| 133 | } // namespace internal |
| 134 | } // namespace update_engine |