-
Notifications
You must be signed in to change notification settings - Fork 0
/
binder_service_brillo.cc
247 lines (200 loc) · 7.77 KB
/
binder_service_brillo.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
//
// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "update_engine/binder_service_brillo.h"
#include <base/bind.h>
#include <binderwrapper/binder_wrapper.h>
#include <utils/String16.h>
#include <utils/StrongPointer.h>
#include "update_engine/update_status_utils.h"
using android::sp;
using android::String16;
using android::String8;
using android::binder::Status;
using android::brillo::IUpdateEngineStatusCallback;
using android::brillo::ParcelableUpdateEngineStatus;
using brillo::ErrorPtr;
using std::string;
using update_engine::UpdateEngineStatus;
namespace chromeos_update_engine {
namespace {
string NormalString(const String16& in) {
return string{String8{in}.string()};
}
Status ToStatus(ErrorPtr* error) {
return Status::fromServiceSpecificError(
1, String8{error->get()->GetMessage().c_str()});
}
} // namespace
template <typename... Parameters, typename... Arguments>
Status BinderUpdateEngineBrilloService::CallCommonHandler(
bool (UpdateEngineService::*Handler)(ErrorPtr*, Parameters...),
Arguments... arguments) {
ErrorPtr error;
if (((common_.get())->*Handler)(&error, arguments...))
return Status::ok();
return ToStatus(&error);
}
Status BinderUpdateEngineBrilloService::SetUpdateAttemptFlags(int flags) {
return CallCommonHandler(&UpdateEngineService::SetUpdateAttemptFlags, flags);
}
Status BinderUpdateEngineBrilloService::AttemptUpdate(
const String16& app_version,
const String16& omaha_url,
int flags,
bool* out_result) {
return CallCommonHandler(&UpdateEngineService::AttemptUpdate,
NormalString(app_version),
NormalString(omaha_url),
flags,
out_result);
}
Status BinderUpdateEngineBrilloService::AttemptRollback(bool powerwash) {
return CallCommonHandler(&UpdateEngineService::AttemptRollback, powerwash);
}
Status BinderUpdateEngineBrilloService::CanRollback(bool* out_can_rollback) {
return CallCommonHandler(&UpdateEngineService::CanRollback, out_can_rollback);
}
Status BinderUpdateEngineBrilloService::ResetStatus() {
return CallCommonHandler(&UpdateEngineService::ResetStatus);
}
Status BinderUpdateEngineBrilloService::GetStatus(
ParcelableUpdateEngineStatus* status) {
UpdateEngineStatus update_engine_status;
auto ret =
CallCommonHandler(&UpdateEngineService::GetStatus, &update_engine_status);
if (ret.isOk()) {
*status = ParcelableUpdateEngineStatus(update_engine_status);
}
return ret;
}
Status BinderUpdateEngineBrilloService::RebootIfNeeded() {
return CallCommonHandler(&UpdateEngineService::RebootIfNeeded);
}
Status BinderUpdateEngineBrilloService::SetChannel(
const String16& target_channel, bool powerwash) {
return CallCommonHandler(&UpdateEngineService::SetChannel,
NormalString(target_channel),
powerwash);
}
Status BinderUpdateEngineBrilloService::GetChannel(bool get_current_channel,
String16* out_channel) {
string channel_string;
auto ret = CallCommonHandler(
&UpdateEngineService::GetChannel, get_current_channel, &channel_string);
*out_channel = String16(channel_string.c_str());
return ret;
}
Status BinderUpdateEngineBrilloService::SetCohortHint(
const String16& in_cohort_hint) {
return CallCommonHandler(&UpdateEngineService::SetCohortHint,
NormalString(in_cohort_hint));
}
Status BinderUpdateEngineBrilloService::GetCohortHint(
String16* out_cohort_hint) {
string cohort_hint;
auto ret =
CallCommonHandler(&UpdateEngineService::GetCohortHint, &cohort_hint);
*out_cohort_hint = String16(cohort_hint.c_str());
return ret;
}
Status BinderUpdateEngineBrilloService::SetP2PUpdatePermission(bool enabled) {
return CallCommonHandler(&UpdateEngineService::SetP2PUpdatePermission,
enabled);
}
Status BinderUpdateEngineBrilloService::GetP2PUpdatePermission(
bool* out_p2p_permission) {
return CallCommonHandler(&UpdateEngineService::GetP2PUpdatePermission,
out_p2p_permission);
}
Status BinderUpdateEngineBrilloService::SetUpdateOverCellularPermission(
bool enabled) {
return CallCommonHandler(
&UpdateEngineService::SetUpdateOverCellularPermission, enabled);
}
Status BinderUpdateEngineBrilloService::SetUpdateOverCellularTarget(
const String16& target_version, int64_t target_size) {
return CallCommonHandler(&UpdateEngineService::SetUpdateOverCellularTarget,
NormalString(target_version),
target_size);
}
Status BinderUpdateEngineBrilloService::GetUpdateOverCellularPermission(
bool* out_cellular_permission) {
return CallCommonHandler(
&UpdateEngineService::GetUpdateOverCellularPermission,
out_cellular_permission);
}
Status BinderUpdateEngineBrilloService::GetDurationSinceUpdate(
int64_t* out_duration) {
return CallCommonHandler(&UpdateEngineService::GetDurationSinceUpdate,
out_duration);
}
Status BinderUpdateEngineBrilloService::GetPrevVersion(
String16* out_prev_version) {
string version_string;
auto ret =
CallCommonHandler(&UpdateEngineService::GetPrevVersion, &version_string);
*out_prev_version = String16(version_string.c_str());
return ret;
}
Status BinderUpdateEngineBrilloService::GetRollbackPartition(
String16* out_rollback_partition) {
string partition_string;
auto ret = CallCommonHandler(&UpdateEngineService::GetRollbackPartition,
&partition_string);
if (ret.isOk()) {
*out_rollback_partition = String16(partition_string.c_str());
}
return ret;
}
Status BinderUpdateEngineBrilloService::RegisterStatusCallback(
const sp<IUpdateEngineStatusCallback>& callback) {
callbacks_.emplace_back(callback);
auto binder_wrapper = android::BinderWrapper::Get();
binder_wrapper->RegisterForDeathNotifications(
IUpdateEngineStatusCallback::asBinder(callback),
base::Bind(&BinderUpdateEngineBrilloService::UnregisterStatusCallback,
base::Unretained(this),
base::Unretained(callback.get())));
return Status::ok();
}
Status BinderUpdateEngineBrilloService::GetLastAttemptError(
int* out_last_attempt_error) {
return CallCommonHandler(&UpdateEngineService::GetLastAttemptError,
out_last_attempt_error);
}
Status BinderUpdateEngineBrilloService::GetEolStatus(int* out_eol_status) {
return CallCommonHandler(&UpdateEngineService::GetEolStatus, out_eol_status);
}
void BinderUpdateEngineBrilloService::UnregisterStatusCallback(
IUpdateEngineStatusCallback* callback) {
auto it = callbacks_.begin();
while (it != callbacks_.end() && it->get() != callback)
it++;
if (it == callbacks_.end()) {
LOG(ERROR) << "Got death notification for unknown callback.";
return;
}
LOG(INFO) << "Erasing orphan callback";
callbacks_.erase(it);
}
void BinderUpdateEngineBrilloService::SendStatusUpdate(
const UpdateEngineStatus& update_engine_status) {
ParcelableUpdateEngineStatus parcelable_status(update_engine_status);
for (auto& callback : callbacks_) {
callback->HandleStatusUpdate(parcelable_status);
}
}
} // namespace chromeos_update_engine