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 | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame^] | 69 | bool UpdateEngineClientImpl::ResetStatus() { |
| 70 | return proxy_->ResetStatus(nullptr); |
| 71 | } |
| 72 | |
Christopher Wiley | 16daa08 | 2015-10-01 17:18:40 -0700 | [diff] [blame] | 73 | bool UpdateEngineClientImpl::SetTargetChannel(const string& in_target_channel) { |
| 74 | return proxy_->SetChannel( |
| 75 | in_target_channel, |
| 76 | true, |
| 77 | nullptr); |
| 78 | } |
| 79 | |
| 80 | bool UpdateEngineClientImpl::GetTargetChannel(string* out_channel) { |
| 81 | return proxy_->GetChannel( |
| 82 | false, // Get the target channel. |
| 83 | out_channel, |
| 84 | nullptr); |
| 85 | } |
| 86 | |
| 87 | bool UpdateEngineClientImpl::GetChannel(string* out_channel) { |
| 88 | return proxy_->GetChannel( |
| 89 | true, // Get the current channel. |
| 90 | out_channel, |
| 91 | nullptr); |
| 92 | } |
| 93 | |
| 94 | } // namespace internal |
| 95 | } // namespace update_engine |