blob: 19acf6e14cf0bbb9bc21d26329bdf7a57cfccf18 [file] [log] [blame]
Christopher Wiley9e1eda92015-11-16 15:23:37 -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/binder_service.h"
18
Casey Dahlina93cd532016-01-14 16:55:11 -080019#include <utils/String16.h>
20#include <utils/StrongPointer.h>
21
Christopher Wiley9e1eda92015-11-16 15:23:37 -080022using android::String16;
Casey Dahlina93cd532016-01-14 16:55:11 -080023using android::String8;
Christopher Wiley09af8812015-11-19 08:12:33 -080024using android::binder::Status;
Casey Dahlina93cd532016-01-14 16:55:11 -080025using android::brillo::IUpdateEngineStatusCallback;
26using android::brillo::ParcelableUpdateEngineStatus;
27using android::sp;
28using brillo::ErrorPtr;
29using std::string;
Christopher Wiley9e1eda92015-11-16 15:23:37 -080030
31namespace chromeos_update_engine {
32
Casey Dahlina93cd532016-01-14 16:55:11 -080033namespace {
34string NormalString(const String16& in) {
35 return string{String8{in}.string()};
Tao Baoe78e3fb2016-01-04 17:57:53 -080036}
37
Casey Dahlina93cd532016-01-14 16:55:11 -080038Status ToStatus(ErrorPtr* error) {
39 return Status::fromServiceSpecificError(
40 1, String8{error->get()->GetMessage().c_str()});
41}
42} // namespace
43
44template<typename... Parameters, typename... Arguments>
45Status BinderUpdateEngineService::CallCommonHandler(
46 bool (UpdateEngineService::*Handler)(ErrorPtr*, Parameters...),
47 Arguments... arguments) {
48 ErrorPtr error;
49 if (((common_.get())->*Handler)(&error, arguments...)) return Status::ok();
50 return ToStatus(&error);
Christopher Wiley9e1eda92015-11-16 15:23:37 -080051}
52
Casey Dahlina93cd532016-01-14 16:55:11 -080053Status BinderUpdateEngineService::AttemptUpdate(const String16& app_version,
54 const String16& omaha_url,
55 int flags) {
56 return CallCommonHandler(
57 &UpdateEngineService::AttemptUpdate, NormalString(app_version),
58 NormalString(omaha_url), flags);
Christopher Wiley9e1eda92015-11-16 15:23:37 -080059}
60
Casey Dahlina93cd532016-01-14 16:55:11 -080061Status BinderUpdateEngineService::AttemptRollback(bool powerwash) {
62 return CallCommonHandler(&UpdateEngineService::AttemptRollback, powerwash);
Christopher Wiley9e1eda92015-11-16 15:23:37 -080063}
64
Casey Dahlina93cd532016-01-14 16:55:11 -080065Status BinderUpdateEngineService::CanRollback(bool* out_can_rollback) {
66 return CallCommonHandler(&UpdateEngineService::CanRollback,
67 out_can_rollback);
68}
69
70Status BinderUpdateEngineService::ResetStatus() {
71 return CallCommonHandler(&UpdateEngineService::ResetStatus);
72}
73
74Status BinderUpdateEngineService::GetStatus(
75 ParcelableUpdateEngineStatus* status) {
76 string current_op;
77 string new_version;
78
79 auto ret = CallCommonHandler(&UpdateEngineService::GetStatus,
80 &status->last_checked_time_,
81 &status->progress_,
82 &current_op,
83 &new_version,
84 &status->new_size_);
85
86 if (ret.isOk()) {
87 status->current_operation_ = String16{current_op.c_str()};
88 status->new_version_ = String16{new_version.c_str()};
89 }
90
91 return ret;
92}
93
94Status BinderUpdateEngineService::RebootIfNeeded() {
95 return CallCommonHandler(&UpdateEngineService::RebootIfNeeded);
96}
97
98Status BinderUpdateEngineService::SetChannel(const String16& target_channel,
99 bool powerwash) {
100 return CallCommonHandler(&UpdateEngineService::SetChannel,
101 NormalString(target_channel), powerwash);
102}
103
104Status BinderUpdateEngineService::GetChannel(bool get_current_channel,
105 String16* out_channel) {
106 string channel_string;
107 auto ret = CallCommonHandler(&UpdateEngineService::GetChannel,
108 get_current_channel,
109 &channel_string);
110
111 *out_channel = String16(channel_string.c_str());
112 return ret;
113}
114
115Status BinderUpdateEngineService::SetP2PUpdatePermission(bool enabled) {
116 return CallCommonHandler(&UpdateEngineService::SetP2PUpdatePermission,
117 enabled);
118}
119
120Status BinderUpdateEngineService::GetP2PUpdatePermission(
121 bool* out_p2p_permission) {
122 return CallCommonHandler(&UpdateEngineService::GetP2PUpdatePermission,
123 out_p2p_permission);
124}
125
126Status BinderUpdateEngineService::SetUpdateOverCellularPermission(
127 bool enabled) {
128 return CallCommonHandler(
129 &UpdateEngineService::SetUpdateOverCellularPermission, enabled);
130}
131
132Status BinderUpdateEngineService::GetUpdateOverCellularPermission(
133 bool* out_cellular_permission) {
134 return CallCommonHandler(
135 &UpdateEngineService::GetUpdateOverCellularPermission,
136 out_cellular_permission);
137}
138
139Status BinderUpdateEngineService::GetDurationSinceUpdate(
140 int64_t* out_duration) {
141 return CallCommonHandler(&UpdateEngineService::GetDurationSinceUpdate,
142 out_duration);
143}
144
145Status BinderUpdateEngineService::GetPrevVersion(String16* out_prev_version) {
146 string version_string;
147 auto ret = CallCommonHandler(&UpdateEngineService::GetPrevVersion,
148 &version_string);
149
150 *out_prev_version = String16(version_string.c_str());
151 return ret;
152}
153
154Status BinderUpdateEngineService::GetRollbackPartition(
155 String16* out_rollback_partition) {
156 string partition_string;
157 auto ret = CallCommonHandler(&UpdateEngineService::GetRollbackPartition,
158 &partition_string);
159
160 if (ret.isOk()) {
161 *out_rollback_partition = String16(partition_string.c_str());
162 }
163
164 return ret;
165}
166
167Status BinderUpdateEngineService::RegisterStatusCallback(
168 const sp<IUpdateEngineStatusCallback>& callback) {
Christopher Wiley09af8812015-11-19 08:12:33 -0800169 return Status::ok();
Christopher Wiley9e1eda92015-11-16 15:23:37 -0800170}
171
172} // namespace chromeos_update_engine