blob: 7b8002584e592b2aa0a3cf84e4fac62be66090cb [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 Dahlinef361132015-12-17 13:02:37 -080069bool UpdateEngineClientImpl::SetUpdateOverCellularPermission(bool allowed) {
70 return proxy_->SetUpdateOverCellularPermission(allowed, nullptr);
71}
72
73bool UpdateEngineClientImpl::GetUpdateOverCellularPermission(bool *allowed) {
74 return proxy_->GetUpdateOverCellularPermission(allowed, nullptr);
75}
76
77bool UpdateEngineClientImpl::SetP2PUpdatePermission(bool enabled) {
78 return proxy_->SetP2PUpdatePermission(enabled, nullptr);
79}
80
81bool UpdateEngineClientImpl::GetP2PUpdatePermission(bool* enabled) {
82 return proxy_->GetP2PUpdatePermission(enabled, nullptr);
83}
84
85bool UpdateEngineClientImpl::Rollback(bool powerwash) {
86 return proxy_->AttemptRollback(powerwash, nullptr);
87}
88
89bool UpdateEngineClientImpl::GetRollbackPartition(string* rollback_partition) {
90 return proxy_->GetRollbackPartition(rollback_partition, nullptr);
91}
92
93bool UpdateEngineClientImpl::GetPrevVersion(string* prev_version) {
94 return proxy_->GetPrevVersion(prev_version, nullptr);
95}
96
97void 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 Dahline844c1a2015-12-16 14:30:58 -0800107bool UpdateEngineClientImpl::ResetStatus() {
108 return proxy_->ResetStatus(nullptr);
109}
110
Casey Dahlin87ab88e2015-12-16 17:58:05 -0800111bool UpdateEngineClientImpl::SetTargetChannel(const string& in_target_channel,
112 bool allow_powerwash) {
Christopher Wiley16daa082015-10-01 17:18:40 -0700113 return proxy_->SetChannel(
114 in_target_channel,
Casey Dahlin87ab88e2015-12-16 17:58:05 -0800115 allow_powerwash,
Christopher Wiley16daa082015-10-01 17:18:40 -0700116 nullptr);
117}
118
119bool UpdateEngineClientImpl::GetTargetChannel(string* out_channel) {
120 return proxy_->GetChannel(
121 false, // Get the target channel.
122 out_channel,
123 nullptr);
124}
125
126bool 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