blob: b3bd3e771a357cdbe07cf3773a7c8091c49897fb [file] [log] [blame]
Casey Dahlina93cd532016-01-14 16:55:11 -08001//
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_binder.h"
18
19#include <binder/IServiceManager.h>
20
21#include <base/message_loop/message_loop.h>
22#include <utils/String16.h>
23#include <utils/String8.h>
24
25#include "update_engine/parcelable_update_engine_status.h"
26#include "update_engine/update_status_utils.h"
27
28using android::OK;
29using android::String16;
30using android::String8;
31using android::brillo::ParcelableUpdateEngineStatus;
32using android::getService;
33using chromeos_update_engine::StringToUpdateStatus;
34using std::string;
35
36namespace update_engine {
37namespace internal {
38
39bool BinderUpdateEngineClient::Init() {
40 return getService(String16{"android.brillo.UpdateEngineService"},
41 &service_) == OK;
42}
43
44bool BinderUpdateEngineClient::AttemptUpdate(const string& in_app_version,
45 const string& in_omaha_url,
46 bool at_user_request) {
47 return service_->AttemptUpdate(String16{in_app_version.c_str()},
48 String16{in_omaha_url.c_str()},
49 at_user_request ? 1 : 0).isOk();
50}
51
52bool BinderUpdateEngineClient::GetStatus(int64_t* out_last_checked_time,
53 double* out_progress,
54 UpdateStatus* out_update_status,
55 string* out_new_version,
56 int64_t* out_new_size) const {
57 ParcelableUpdateEngineStatus status;
58
59 if (!service_->GetStatus(&status).isOk())
60 return false;
61
62 *out_last_checked_time = status.last_checked_time_;
63 *out_progress = status.progress_;
64 StringToUpdateStatus(String8{status.current_operation_}.string(),
65 out_update_status);
66 *out_new_version = String8{status.new_version_}.string();
67 *out_new_size = status.new_size_;
68 return true;
69}
70
71bool BinderUpdateEngineClient::SetUpdateOverCellularPermission(bool allowed) {
72 return service_->SetUpdateOverCellularPermission(allowed).isOk();
73}
74
75bool BinderUpdateEngineClient::GetUpdateOverCellularPermission(
76 bool* allowed) const {
77 return service_->GetUpdateOverCellularPermission(allowed).isOk();
78}
79
80bool BinderUpdateEngineClient::SetP2PUpdatePermission(bool enabled) {
81 return service_->SetP2PUpdatePermission(enabled).isOk();
82}
83
84bool BinderUpdateEngineClient::GetP2PUpdatePermission(bool* enabled) const {
85 return service_->GetP2PUpdatePermission(enabled).isOk();
86}
87
88bool BinderUpdateEngineClient::Rollback(bool powerwash) {
89 return service_->AttemptRollback(powerwash).isOk();
90}
91
92bool BinderUpdateEngineClient::GetRollbackPartition(
93 string* rollback_partition) const {
94 String16 out_as_string16;
95
96 if (!service_->GetRollbackPartition(&out_as_string16).isOk())
97 return false;
98
99 *rollback_partition = String8{out_as_string16}.string();
100 return true;
101}
102
103bool BinderUpdateEngineClient::GetPrevVersion(string* prev_version) const {
104 String16 out_as_string16;
105
106 if (!service_->GetPrevVersion(&out_as_string16).isOk())
107 return false;
108
109 *prev_version = String8{out_as_string16}.string();
110 return true;
111}
112
113void BinderUpdateEngineClient::RebootIfNeeded() {
114 if (!service_->RebootIfNeeded().isOk()) {
115 // Reboot error code doesn't necessarily mean that a reboot
116 // failed. For example, D-Bus may be shutdown before we receive the
117 // result.
118 LOG(INFO) << "RebootIfNeeded() failure ignored.";
119 }
120}
121
122bool BinderUpdateEngineClient::ResetStatus() {
123 return service_->ResetStatus().isOk();
124}
125
126void BinderUpdateEngineClient::RegisterStatusUpdateHandler(
127 StatusUpdateHandler* handler) {
128}
129
130bool BinderUpdateEngineClient::SetTargetChannel(const string& in_target_channel,
131 bool allow_powerwash) {
132 return service_->SetChannel(String16{in_target_channel.c_str()},
133 allow_powerwash).isOk();
134}
135
136bool BinderUpdateEngineClient::GetTargetChannel(string* out_channel) const {
137 String16 out_as_string16;
138
139 if (!service_->GetChannel(false, &out_as_string16).isOk())
140 return false;
141
142 *out_channel = String8{out_as_string16}.string();
143 return true;
144}
145
146bool BinderUpdateEngineClient::GetChannel(string* out_channel) const {
147 String16 out_as_string16;
148
149 if (!service_->GetChannel(true, &out_as_string16).isOk())
150 return false;
151
152 *out_channel = String8{out_as_string16}.string();
153 return true;
154}
155
156} // namespace internal
157} // namespace update_engine