blob: af9cb05c5af6f3d1e2c0fcd87a0e9ea482a23846 [file] [log] [blame]
Christopher Wiley16daa082015-10-01 17:18:40 -07001//
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
24using chromeos_update_engine::StringToUpdateStatus;
25using dbus::Bus;
26using org::chromium::UpdateEngineInterfaceProxy;
27using std::string;
28
29namespace update_engine {
30namespace internal {
31
32UpdateEngineClientImpl::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
39bool 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
49bool 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 Dahline844c1a2015-12-16 14:30:58 -080069bool UpdateEngineClientImpl::ResetStatus() {
70 return proxy_->ResetStatus(nullptr);
71}
72
Casey Dahlin87ab88e2015-12-16 17:58:05 -080073bool UpdateEngineClientImpl::SetTargetChannel(const string& in_target_channel,
74 bool allow_powerwash) {
Christopher Wiley16daa082015-10-01 17:18:40 -070075 return proxy_->SetChannel(
76 in_target_channel,
Casey Dahlin87ab88e2015-12-16 17:58:05 -080077 allow_powerwash,
Christopher Wiley16daa082015-10-01 17:18:40 -070078 nullptr);
79}
80
81bool UpdateEngineClientImpl::GetTargetChannel(string* out_channel) {
82 return proxy_->GetChannel(
83 false, // Get the target channel.
84 out_channel,
85 nullptr);
86}
87
88bool UpdateEngineClientImpl::GetChannel(string* out_channel) {
89 return proxy_->GetChannel(
90 true, // Get the current channel.
91 out_channel,
92 nullptr);
93}
94
95} // namespace internal
96} // namespace update_engine