1 /*
2 * Copyright (C) 2023 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 #define LOG_TAG "aidl_ndk_service"
17
18 #include <aidl/android/aidl/fixedsizearray/FixedSizeArrayExample.h>
19 #include <aidl/android/aidl/loggable/BnLoggableInterface.h>
20 #include <aidl/android/aidl/loggable/Data.h>
21 #include <aidl/android/aidl/test/trunk/BnTrunkStableTest.h>
22 #include <aidl/android/aidl/test/trunk/ITrunkStableTest.h>
23 #include <aidl/android/aidl/tests/BackendType.h>
24 #include <aidl/android/aidl/tests/BnCircular.h>
25 #include <aidl/android/aidl/tests/BnNamedCallback.h>
26 #include <aidl/android/aidl/tests/BnNewName.h>
27 #include <aidl/android/aidl/tests/BnOldName.h>
28 #include <aidl/android/aidl/tests/BnTestService.h>
29 #include <aidl/android/aidl/tests/ICircular.h>
30 #include <aidl/android/aidl/tests/INamedCallback.h>
31 #include <aidl/android/aidl/tests/ITestService.h>
32 #include <aidl/android/aidl/tests/Union.h>
33 #include <aidl/android/aidl/tests/extension/MyExt.h>
34 #include <aidl/android/aidl/tests/extension/MyExt2.h>
35 #include <aidl/android/aidl/tests/nested/BnNestedService.h>
36 #include <aidl/android/aidl/tests/vintf/VintfExtendableParcelable.h>
37 #include <aidl/android/aidl/versioned/tests/BnFooInterface.h>
38 #include <aidl/android/aidl/versioned/tests/IFooInterface.h>
39 #include <android/binder_manager.h>
40 #include <android/binder_process.h>
41 #include <tests/simple_parcelable_ndk.h>
42
43 #include <map>
44 #include <mutex>
45 #include <optional>
46 #include <sstream>
47 #include <string>
48 #include <vector>
49
50 #include <unistd.h>
51
52 using aidl::android::aidl::tests::BackendType;
53 using aidl::android::aidl::tests::BnCircular;
54 using aidl::android::aidl::tests::BnNamedCallback;
55 using aidl::android::aidl::tests::BnNewName;
56 using aidl::android::aidl::tests::BnOldName;
57 using aidl::android::aidl::tests::BnTestService;
58 using aidl::android::aidl::tests::ByteEnum;
59 using aidl::android::aidl::tests::CircularParcelable;
60 using aidl::android::aidl::tests::ConstantExpressionEnum;
61 using aidl::android::aidl::tests::ICircular;
62 using aidl::android::aidl::tests::INamedCallback;
63 using aidl::android::aidl::tests::INewName;
64 using aidl::android::aidl::tests::IntEnum;
65 using aidl::android::aidl::tests::IOldName;
66 using aidl::android::aidl::tests::ITestService;
67 using aidl::android::aidl::tests::LongEnum;
68 using aidl::android::aidl::tests::RecursiveList;
69 using aidl::android::aidl::tests::SimpleParcelable;
70 using aidl::android::aidl::tests::StructuredParcelable;
71 using aidl::android::aidl::tests::Union;
72 using aidl::android::aidl::tests::extension::ExtendableParcelable;
73
74 using std::optional;
75 using std::string;
76 using std::vector;
77
78 using ndk::ScopedAStatus;
79 using ndk::ScopedFileDescriptor;
80 using ndk::SharedRefBase;
81 using ndk::SpAIBinder;
82
83 namespace {
84
85 class NamedCallback : public BnNamedCallback {
86 public:
NamedCallback(std::string name)87 explicit NamedCallback(std::string name) : name_(name) {}
88
GetName(std::string * ret)89 ScopedAStatus GetName(std::string* ret) override {
90 *ret = name_;
91 return ScopedAStatus::ok();
92 }
93
94 private:
95 std::string name_;
96 };
97
98 class OldName : public BnOldName {
99 public:
100 OldName() = default;
101 ~OldName() = default;
102
RealName(std::string * output)103 ScopedAStatus RealName(std::string* output) override {
104 *output = std::string("OldName");
105 return ScopedAStatus::ok();
106 }
107 };
108
109 class NewName : public BnNewName {
110 public:
111 NewName() = default;
112 ~NewName() = default;
113
RealName(std::string * output)114 ScopedAStatus RealName(std::string* output) override {
115 *output = std::string("NewName");
116 return ScopedAStatus::ok();
117 }
118 };
119
120 class Circular : public BnCircular {
121 public:
Circular(std::shared_ptr<ITestService> srv)122 Circular(std::shared_ptr<ITestService> srv) : mSrv(srv) {}
123 ~Circular() = default;
124
GetTestService(std::shared_ptr<ITestService> * _aidl_return)125 ScopedAStatus GetTestService(std::shared_ptr<ITestService>* _aidl_return) override {
126 *_aidl_return = mSrv;
127 return ScopedAStatus::ok();
128 }
129
130 private:
131 std::shared_ptr<ITestService> mSrv;
132 };
133
134 template <typename T>
ReverseArray(const vector<T> & input,vector<T> * repeated,vector<T> * _aidl_return)135 ScopedAStatus ReverseArray(const vector<T>& input, vector<T>* repeated, vector<T>* _aidl_return) {
136 ALOGI("Reversing array of length %zu", input.size());
137 *repeated = input;
138 *_aidl_return = input;
139 std::reverse(_aidl_return->begin(), _aidl_return->end());
140 return ScopedAStatus::ok();
141 }
142
143 template <typename T>
RepeatNullable(const optional<T> & input,optional<T> * _aidl_return)144 ScopedAStatus RepeatNullable(const optional<T>& input, optional<T>* _aidl_return) {
145 ALOGI("Repeating nullable value");
146 *_aidl_return = input;
147 return ScopedAStatus::ok();
148 }
149
150 class NativeService : public BnTestService {
151 public:
NativeService()152 NativeService() {}
153 virtual ~NativeService() = default;
154
LogRepeatedStringToken(const std::string & token)155 void LogRepeatedStringToken(const std::string& token) {
156 ALOGI("Repeating '%s' of length=%zu", token.c_str(), token.size());
157 }
158
159 template <typename T>
LogRepeatedToken(const T & token)160 void LogRepeatedToken(const T& token) {
161 std::ostringstream token_str;
162 token_str << token;
163 ALOGI("Repeating token %s", token_str.str().c_str());
164 }
165
166 template <>
LogRepeatedToken(const char16_t & token)167 void LogRepeatedToken(const char16_t& token) {
168 ALOGI("Repeating token (char16_t) %d", token);
169 }
170
TestOneway()171 ScopedAStatus TestOneway() override { return ScopedAStatus::fromStatus(android::UNKNOWN_ERROR); }
172
Deprecated()173 ScopedAStatus Deprecated() override { return ScopedAStatus::ok(); }
174
RepeatBoolean(bool token,bool * _aidl_return)175 ScopedAStatus RepeatBoolean(bool token, bool* _aidl_return) override {
176 LogRepeatedToken(token ? 1 : 0);
177 *_aidl_return = token;
178 return ScopedAStatus::ok();
179 }
RepeatByte(int8_t token,int8_t * _aidl_return)180 ScopedAStatus RepeatByte(int8_t token, int8_t* _aidl_return) override {
181 LogRepeatedToken(token);
182 *_aidl_return = token;
183 return ScopedAStatus::ok();
184 }
RepeatChar(char16_t token,char16_t * _aidl_return)185 ScopedAStatus RepeatChar(char16_t token, char16_t* _aidl_return) override {
186 LogRepeatedToken(token);
187 *_aidl_return = token;
188 return ScopedAStatus::ok();
189 }
RepeatInt(int32_t token,int32_t * _aidl_return)190 ScopedAStatus RepeatInt(int32_t token, int32_t* _aidl_return) override {
191 LogRepeatedToken(token);
192 *_aidl_return = token;
193 return ScopedAStatus::ok();
194 }
RepeatLong(int64_t token,int64_t * _aidl_return)195 ScopedAStatus RepeatLong(int64_t token, int64_t* _aidl_return) override {
196 LogRepeatedToken(token);
197 *_aidl_return = token;
198 return ScopedAStatus::ok();
199 }
RepeatFloat(float token,float * _aidl_return)200 ScopedAStatus RepeatFloat(float token, float* _aidl_return) override {
201 LogRepeatedToken(token);
202 *_aidl_return = token;
203 return ScopedAStatus::ok();
204 }
RepeatDouble(double token,double * _aidl_return)205 ScopedAStatus RepeatDouble(double token, double* _aidl_return) override {
206 LogRepeatedToken(token);
207 *_aidl_return = token;
208 return ScopedAStatus::ok();
209 }
RepeatString(const std::string & token,std::string * _aidl_return)210 ScopedAStatus RepeatString(const std::string& token, std::string* _aidl_return) override {
211 LogRepeatedStringToken(token);
212 *_aidl_return = token;
213 return ScopedAStatus::ok();
214 }
RepeatByteEnum(ByteEnum token,ByteEnum * _aidl_return)215 ScopedAStatus RepeatByteEnum(ByteEnum token, ByteEnum* _aidl_return) override {
216 ALOGI("Repeating ByteEnum token %s", toString(token).c_str());
217 *_aidl_return = token;
218 return ScopedAStatus::ok();
219 }
RepeatIntEnum(IntEnum token,IntEnum * _aidl_return)220 ScopedAStatus RepeatIntEnum(IntEnum token, IntEnum* _aidl_return) override {
221 ALOGI("Repeating IntEnum token %s", toString(token).c_str());
222 *_aidl_return = token;
223 return ScopedAStatus::ok();
224 }
RepeatLongEnum(LongEnum token,LongEnum * _aidl_return)225 ScopedAStatus RepeatLongEnum(LongEnum token, LongEnum* _aidl_return) override {
226 ALOGI("Repeating LongEnum token %s", toString(token).c_str());
227 *_aidl_return = token;
228 return ScopedAStatus::ok();
229 }
230
ReverseBoolean(const vector<bool> & input,vector<bool> * repeated,vector<bool> * _aidl_return)231 ScopedAStatus ReverseBoolean(const vector<bool>& input, vector<bool>* repeated,
232 vector<bool>* _aidl_return) override {
233 return ReverseArray(input, repeated, _aidl_return);
234 }
ReverseByte(const vector<uint8_t> & input,vector<uint8_t> * repeated,vector<uint8_t> * _aidl_return)235 ScopedAStatus ReverseByte(const vector<uint8_t>& input, vector<uint8_t>* repeated,
236 vector<uint8_t>* _aidl_return) override {
237 return ReverseArray(input, repeated, _aidl_return);
238 }
ReverseChar(const vector<char16_t> & input,vector<char16_t> * repeated,vector<char16_t> * _aidl_return)239 ScopedAStatus ReverseChar(const vector<char16_t>& input, vector<char16_t>* repeated,
240 vector<char16_t>* _aidl_return) override {
241 return ReverseArray(input, repeated, _aidl_return);
242 }
ReverseInt(const vector<int32_t> & input,vector<int32_t> * repeated,vector<int32_t> * _aidl_return)243 ScopedAStatus ReverseInt(const vector<int32_t>& input, vector<int32_t>* repeated,
244 vector<int32_t>* _aidl_return) override {
245 return ReverseArray(input, repeated, _aidl_return);
246 }
ReverseLong(const vector<int64_t> & input,vector<int64_t> * repeated,vector<int64_t> * _aidl_return)247 ScopedAStatus ReverseLong(const vector<int64_t>& input, vector<int64_t>* repeated,
248 vector<int64_t>* _aidl_return) override {
249 return ReverseArray(input, repeated, _aidl_return);
250 }
ReverseFloat(const vector<float> & input,vector<float> * repeated,vector<float> * _aidl_return)251 ScopedAStatus ReverseFloat(const vector<float>& input, vector<float>* repeated,
252 vector<float>* _aidl_return) override {
253 return ReverseArray(input, repeated, _aidl_return);
254 }
ReverseDouble(const vector<double> & input,vector<double> * repeated,vector<double> * _aidl_return)255 ScopedAStatus ReverseDouble(const vector<double>& input, vector<double>* repeated,
256 vector<double>* _aidl_return) override {
257 return ReverseArray(input, repeated, _aidl_return);
258 }
ReverseString(const vector<std::string> & input,vector<std::string> * repeated,vector<std::string> * _aidl_return)259 ScopedAStatus ReverseString(const vector<std::string>& input, vector<std::string>* repeated,
260 vector<std::string>* _aidl_return) override {
261 return ReverseArray(input, repeated, _aidl_return);
262 }
ReverseByteEnum(const vector<ByteEnum> & input,vector<ByteEnum> * repeated,vector<ByteEnum> * _aidl_return)263 ScopedAStatus ReverseByteEnum(const vector<ByteEnum>& input, vector<ByteEnum>* repeated,
264 vector<ByteEnum>* _aidl_return) override {
265 return ReverseArray(input, repeated, _aidl_return);
266 }
ReverseIntEnum(const vector<IntEnum> & input,vector<IntEnum> * repeated,vector<IntEnum> * _aidl_return)267 ScopedAStatus ReverseIntEnum(const vector<IntEnum>& input, vector<IntEnum>* repeated,
268 vector<IntEnum>* _aidl_return) override {
269 return ReverseArray(input, repeated, _aidl_return);
270 }
ReverseLongEnum(const vector<LongEnum> & input,vector<LongEnum> * repeated,vector<LongEnum> * _aidl_return)271 ScopedAStatus ReverseLongEnum(const vector<LongEnum>& input, vector<LongEnum>* repeated,
272 vector<LongEnum>* _aidl_return) override {
273 return ReverseArray(input, repeated, _aidl_return);
274 }
275
SetOtherTestService(const std::string & name,const std::shared_ptr<INamedCallback> & service,bool * _aidl_return)276 ScopedAStatus SetOtherTestService(const std::string& name,
277 const std::shared_ptr<INamedCallback>& service,
278 bool* _aidl_return) override {
279 std::lock_guard<std::mutex> guard(service_map_mutex_);
280 const auto& existing = service_map_.find(name);
281 if (existing != service_map_.end() && existing->second == service) {
282 *_aidl_return = true;
283
284 return ScopedAStatus::ok();
285 } else {
286 *_aidl_return = false;
287 service_map_[name] = service;
288
289 return ScopedAStatus::ok();
290 }
291 }
292
GetOtherTestService(const std::string & name,std::shared_ptr<INamedCallback> * returned_service)293 ScopedAStatus GetOtherTestService(const std::string& name,
294 std::shared_ptr<INamedCallback>* returned_service) override {
295 std::lock_guard<std::mutex> guard(service_map_mutex_);
296 if (service_map_.find(name) == service_map_.end()) {
297 service_map_[name] = SharedRefBase::make<NamedCallback>(name);
298 }
299
300 *returned_service = service_map_[name];
301 return ScopedAStatus::ok();
302 }
303
VerifyName(const std::shared_ptr<INamedCallback> & service,const std::string & name,bool * returned_value)304 ScopedAStatus VerifyName(const std::shared_ptr<INamedCallback>& service, const std::string& name,
305 bool* returned_value) override {
306 std::string foundName;
307 ScopedAStatus status = service->GetName(&foundName);
308
309 if (status.isOk()) {
310 *returned_value = foundName == name;
311 }
312
313 return status;
314 }
315
GetInterfaceArray(const vector<std::string> & names,vector<std::shared_ptr<INamedCallback>> * _aidl_return)316 ScopedAStatus GetInterfaceArray(const vector<std::string>& names,
317 vector<std::shared_ptr<INamedCallback>>* _aidl_return) override {
318 vector<std::shared_ptr<INamedCallback>> services(names.size());
319 for (size_t i = 0; i < names.size(); i++) {
320 if (auto st = GetOtherTestService(names[i], &services[i]); !st.isOk()) {
321 return st;
322 }
323 }
324 *_aidl_return = std::move(services);
325 return ScopedAStatus::ok();
326 }
327
VerifyNamesWithInterfaceArray(const vector<std::shared_ptr<INamedCallback>> & services,const vector<std::string> & names,bool * _aidl_ret)328 ScopedAStatus VerifyNamesWithInterfaceArray(
329 const vector<std::shared_ptr<INamedCallback>>& services, const vector<std::string>& names,
330 bool* _aidl_ret) override {
331 if (services.size() == names.size()) {
332 for (size_t i = 0; i < services.size(); i++) {
333 if (auto st = VerifyName(services[i], names[i], _aidl_ret); !st.isOk() || !*_aidl_ret) {
334 return st;
335 }
336 }
337 *_aidl_ret = true;
338 } else {
339 *_aidl_ret = false;
340 }
341 return ScopedAStatus::ok();
342 }
343
GetNullableInterfaceArray(const optional<vector<optional<std::string>>> & names,optional<vector<std::shared_ptr<INamedCallback>>> * _aidl_ret)344 ScopedAStatus GetNullableInterfaceArray(
345 const optional<vector<optional<std::string>>>& names,
346 optional<vector<std::shared_ptr<INamedCallback>>>* _aidl_ret) override {
347 vector<std::shared_ptr<INamedCallback>> services;
348 if (names.has_value()) {
349 for (const auto& name : *names) {
350 if (name.has_value()) {
351 std::shared_ptr<INamedCallback> ret;
352 if (auto st = GetOtherTestService(*name, &ret); !st.isOk()) {
353 return st;
354 }
355 services.push_back(std::move(ret));
356 } else {
357 services.emplace_back();
358 }
359 }
360 }
361 *_aidl_ret = std::move(services);
362 return ScopedAStatus::ok();
363 }
364
VerifyNamesWithNullableInterfaceArray(const optional<vector<std::shared_ptr<INamedCallback>>> & services,const optional<vector<optional<std::string>>> & names,bool * _aidl_ret)365 ScopedAStatus VerifyNamesWithNullableInterfaceArray(
366 const optional<vector<std::shared_ptr<INamedCallback>>>& services,
367 const optional<vector<optional<std::string>>>& names, bool* _aidl_ret) override {
368 if (services.has_value() && names.has_value()) {
369 if (services->size() == names->size()) {
370 for (size_t i = 0; i < services->size(); i++) {
371 if (services->at(i).get() && names->at(i).has_value()) {
372 if (auto st = VerifyName(services->at(i), names->at(i).value(), _aidl_ret);
373 !st.isOk() || !*_aidl_ret) {
374 return st;
375 }
376 } else if (services->at(i).get() || names->at(i).has_value()) {
377 *_aidl_ret = false;
378 return ScopedAStatus::ok();
379 } else {
380 // ok if service=null && name=null
381 }
382 }
383 *_aidl_ret = true;
384 } else {
385 *_aidl_ret = false;
386 }
387 } else {
388 *_aidl_ret = services.has_value() == names.has_value();
389 }
390 return ScopedAStatus::ok();
391 }
392
GetInterfaceList(const optional<vector<optional<std::string>>> & names,optional<vector<std::shared_ptr<INamedCallback>>> * _aidl_ret)393 ScopedAStatus GetInterfaceList(
394 const optional<vector<optional<std::string>>>& names,
395 optional<vector<std::shared_ptr<INamedCallback>>>* _aidl_ret) override {
396 return GetNullableInterfaceArray(names, _aidl_ret);
397 }
398
VerifyNamesWithInterfaceList(const optional<vector<std::shared_ptr<INamedCallback>>> & services,const optional<vector<optional<std::string>>> & names,bool * _aidl_ret)399 ScopedAStatus VerifyNamesWithInterfaceList(
400 const optional<vector<std::shared_ptr<INamedCallback>>>& services,
401 const optional<vector<optional<std::string>>>& names, bool* _aidl_ret) override {
402 return VerifyNamesWithNullableInterfaceArray(services, names, _aidl_ret);
403 }
404
ReverseStringList(const vector<std::string> & input,vector<std::string> * repeated,vector<std::string> * _aidl_return)405 ScopedAStatus ReverseStringList(const vector<std::string>& input, vector<std::string>* repeated,
406 vector<std::string>* _aidl_return) override {
407 return ReverseArray(input, repeated, _aidl_return);
408 }
409
RepeatParcelFileDescriptor(const ScopedFileDescriptor & read,ScopedFileDescriptor * _aidl_return)410 ScopedAStatus RepeatParcelFileDescriptor(const ScopedFileDescriptor& read,
411 ScopedFileDescriptor* _aidl_return) override {
412 ALOGE("Repeating parcel file descriptor");
413 *_aidl_return = read.dup();
414 return ScopedAStatus::ok();
415 }
416
ReverseParcelFileDescriptorArray(const vector<ScopedFileDescriptor> & input,vector<ScopedFileDescriptor> * repeated,vector<ScopedFileDescriptor> * _aidl_return)417 ScopedAStatus ReverseParcelFileDescriptorArray(
418 const vector<ScopedFileDescriptor>& input, vector<ScopedFileDescriptor>* repeated,
419 vector<ScopedFileDescriptor>* _aidl_return) override {
420 ALOGI("Reversing parcel descriptor array of length %zu", input.size());
421 for (const auto& item : input) {
422 repeated->push_back(item.dup());
423 }
424
425 for (auto i = input.rbegin(); i != input.rend(); i++) {
426 _aidl_return->push_back(i->dup());
427 }
428 return ScopedAStatus::ok();
429 }
430
ThrowServiceException(int code)431 ScopedAStatus ThrowServiceException(int code) override {
432 return ScopedAStatus::fromServiceSpecificError(code);
433 }
434
RepeatNullableIntArray(const optional<vector<int32_t>> & input,optional<vector<int32_t>> * _aidl_return)435 ScopedAStatus RepeatNullableIntArray(const optional<vector<int32_t>>& input,
436 optional<vector<int32_t>>* _aidl_return) {
437 return RepeatNullable(input, _aidl_return);
438 }
439
RepeatNullableByteEnumArray(const optional<vector<ByteEnum>> & input,optional<vector<ByteEnum>> * _aidl_return)440 ScopedAStatus RepeatNullableByteEnumArray(const optional<vector<ByteEnum>>& input,
441 optional<vector<ByteEnum>>* _aidl_return) {
442 return RepeatNullable(input, _aidl_return);
443 }
444
RepeatNullableIntEnumArray(const optional<vector<IntEnum>> & input,optional<vector<IntEnum>> * _aidl_return)445 ScopedAStatus RepeatNullableIntEnumArray(const optional<vector<IntEnum>>& input,
446 optional<vector<IntEnum>>* _aidl_return) {
447 return RepeatNullable(input, _aidl_return);
448 }
449
RepeatNullableLongEnumArray(const optional<vector<LongEnum>> & input,optional<vector<LongEnum>> * _aidl_return)450 ScopedAStatus RepeatNullableLongEnumArray(const optional<vector<LongEnum>>& input,
451 optional<vector<LongEnum>>* _aidl_return) {
452 return RepeatNullable(input, _aidl_return);
453 }
454
RepeatNullableStringList(const optional<vector<optional<std::string>>> & input,optional<vector<optional<std::string>>> * _aidl_return)455 ScopedAStatus RepeatNullableStringList(const optional<vector<optional<std::string>>>& input,
456 optional<vector<optional<std::string>>>* _aidl_return) {
457 ALOGI("Repeating nullable string list");
458 return RepeatNullable(input, _aidl_return);
459 }
460
RepeatNullableString(const optional<std::string> & input,optional<std::string> * _aidl_return)461 ScopedAStatus RepeatNullableString(const optional<std::string>& input,
462 optional<std::string>* _aidl_return) {
463 return RepeatNullable(input, _aidl_return);
464 }
465
RepeatNullableParcelable(const optional<ITestService::Empty> & input,optional<ITestService::Empty> * _aidl_return)466 ScopedAStatus RepeatNullableParcelable(const optional<ITestService::Empty>& input,
467 optional<ITestService::Empty>* _aidl_return) {
468 return RepeatNullable(input, _aidl_return);
469 }
470
RepeatNullableParcelableList(const optional<vector<optional<ITestService::Empty>>> & input,optional<vector<optional<ITestService::Empty>>> * _aidl_return)471 ScopedAStatus RepeatNullableParcelableList(
472 const optional<vector<optional<ITestService::Empty>>>& input,
473 optional<vector<optional<ITestService::Empty>>>* _aidl_return) {
474 return RepeatNullable(input, _aidl_return);
475 }
476
RepeatNullableParcelableArray(const optional<vector<optional<ITestService::Empty>>> & input,optional<vector<optional<ITestService::Empty>>> * _aidl_return)477 ScopedAStatus RepeatNullableParcelableArray(
478 const optional<vector<optional<ITestService::Empty>>>& input,
479 optional<vector<optional<ITestService::Empty>>>* _aidl_return) {
480 return RepeatNullable(input, _aidl_return);
481 }
482
TakesAnIBinder(const SpAIBinder & input)483 ScopedAStatus TakesAnIBinder(const SpAIBinder& input) override {
484 (void)input;
485 return ScopedAStatus::ok();
486 }
TakesANullableIBinder(const SpAIBinder & input)487 ScopedAStatus TakesANullableIBinder(const SpAIBinder& input) {
488 (void)input;
489 return ScopedAStatus::ok();
490 }
TakesAnIBinderList(const vector<SpAIBinder> & input)491 ScopedAStatus TakesAnIBinderList(const vector<SpAIBinder>& input) override {
492 (void)input;
493 return ScopedAStatus::ok();
494 }
TakesANullableIBinderList(const optional<vector<SpAIBinder>> & input)495 ScopedAStatus TakesANullableIBinderList(const optional<vector<SpAIBinder>>& input) {
496 (void)input;
497 return ScopedAStatus::ok();
498 }
499
RepeatUtf8CppString(const string & token,string * _aidl_return)500 ScopedAStatus RepeatUtf8CppString(const string& token, string* _aidl_return) override {
501 ALOGI("Repeating utf8 string '%s' of length=%zu", token.c_str(), token.size());
502 *_aidl_return = token;
503 return ScopedAStatus::ok();
504 }
505
RepeatNullableUtf8CppString(const optional<string> & token,optional<string> * _aidl_return)506 ScopedAStatus RepeatNullableUtf8CppString(const optional<string>& token,
507 optional<string>* _aidl_return) override {
508 if (!token) {
509 ALOGI("Received null @utf8InCpp string");
510 return ScopedAStatus::ok();
511 }
512 ALOGI("Repeating utf8 string '%s' of length=%zu", token->c_str(), token->size());
513 *_aidl_return = token;
514 return ScopedAStatus::ok();
515 }
516
ReverseUtf8CppString(const vector<string> & input,vector<string> * repeated,vector<string> * _aidl_return)517 ScopedAStatus ReverseUtf8CppString(const vector<string>& input, vector<string>* repeated,
518 vector<string>* _aidl_return) {
519 return ReverseArray(input, repeated, _aidl_return);
520 }
521
ReverseNullableUtf8CppString(const optional<vector<optional<string>>> & input,optional<vector<optional<string>>> * repeated,optional<vector<optional<string>>> * _aidl_return)522 ScopedAStatus ReverseNullableUtf8CppString(const optional<vector<optional<string>>>& input,
523 optional<vector<optional<string>>>* repeated,
524 optional<vector<optional<string>>>* _aidl_return) {
525 return ReverseUtf8CppStringList(input, repeated, _aidl_return);
526 }
527
ReverseUtf8CppStringList(const optional<vector<optional<string>>> & input,optional<vector<optional<string>>> * repeated,optional<vector<optional<string>>> * _aidl_return)528 ScopedAStatus ReverseUtf8CppStringList(const optional<vector<optional<string>>>& input,
529 optional<vector<optional<string>>>* repeated,
530 optional<vector<optional<string>>>* _aidl_return) {
531 if (!input) {
532 ALOGI("Received null list of utf8 strings");
533 return ScopedAStatus::ok();
534 }
535 *_aidl_return = input;
536 *repeated = input;
537 std::reverse((*_aidl_return)->begin(), (*_aidl_return)->end());
538 return ScopedAStatus::ok();
539 }
540
GetCallback(bool return_null,std::shared_ptr<INamedCallback> * ret)541 ScopedAStatus GetCallback(bool return_null, std::shared_ptr<INamedCallback>* ret) {
542 if (!return_null) {
543 return GetOtherTestService(std::string("ABT: always be testing"), ret);
544 }
545 return ScopedAStatus::ok();
546 }
547
FillOutStructuredParcelable(StructuredParcelable * parcelable)548 virtual ScopedAStatus FillOutStructuredParcelable(StructuredParcelable* parcelable) {
549 parcelable->shouldBeJerry = "Jerry";
550 parcelable->shouldContainThreeFs = {parcelable->f, parcelable->f, parcelable->f};
551 parcelable->shouldBeByteBar = ByteEnum::BAR;
552 parcelable->shouldBeIntBar = IntEnum::BAR;
553 parcelable->shouldBeLongBar = LongEnum::BAR;
554 parcelable->shouldContainTwoByteFoos = {ByteEnum::FOO, ByteEnum::FOO};
555 parcelable->shouldContainTwoIntFoos = {IntEnum::FOO, IntEnum::FOO};
556 parcelable->shouldContainTwoLongFoos = {LongEnum::FOO, LongEnum::FOO};
557
558 parcelable->const_exprs_1 = ConstantExpressionEnum::decInt32_1;
559 parcelable->const_exprs_2 = ConstantExpressionEnum::decInt32_2;
560 parcelable->const_exprs_3 = ConstantExpressionEnum::decInt64_1;
561 parcelable->const_exprs_4 = ConstantExpressionEnum::decInt64_2;
562 parcelable->const_exprs_5 = ConstantExpressionEnum::decInt64_3;
563 parcelable->const_exprs_6 = ConstantExpressionEnum::decInt64_4;
564 parcelable->const_exprs_7 = ConstantExpressionEnum::hexInt32_1;
565 parcelable->const_exprs_8 = ConstantExpressionEnum::hexInt32_2;
566 parcelable->const_exprs_9 = ConstantExpressionEnum::hexInt32_3;
567 parcelable->const_exprs_10 = ConstantExpressionEnum::hexInt64_1;
568
569 parcelable->shouldSetBit0AndBit2 = StructuredParcelable::BIT0 | StructuredParcelable::BIT2;
570
571 parcelable->u = Union::make<Union::ns>({1, 2, 3});
572 parcelable->shouldBeConstS1 = Union::S1;
573 return ScopedAStatus::ok();
574 }
575
RepeatExtendableParcelable(const::aidl::android::aidl::tests::extension::ExtendableParcelable & ep,::aidl::android::aidl::tests::extension::ExtendableParcelable * ep2)576 ScopedAStatus RepeatExtendableParcelable(
577 const ::aidl::android::aidl::tests::extension::ExtendableParcelable& ep,
578 ::aidl::android::aidl::tests::extension::ExtendableParcelable* ep2) {
579 ep2->a = ep.a;
580 ep2->b = ep.b;
581 std::optional<aidl::android::aidl::tests::extension::MyExt> myExt;
582 ep.ext.getParcelable(&myExt);
583
584 if (myExt == std::nullopt) {
585 return ScopedAStatus::fromStatus(android::UNKNOWN_ERROR);
586 }
587
588 ep2->ext.setParcelable(*myExt);
589
590 return ScopedAStatus::ok();
591 }
592
RepeatExtendableParcelableVintf(const::aidl::android::aidl::tests::extension::ExtendableParcelable & ep,::aidl::android::aidl::tests::extension::ExtendableParcelable * ep2)593 ScopedAStatus RepeatExtendableParcelableVintf(
594 const ::aidl::android::aidl::tests::extension::ExtendableParcelable& ep,
595 ::aidl::android::aidl::tests::extension::ExtendableParcelable* ep2) {
596 ep2->a = ep.a;
597 ep2->b = ep.b;
598 std::optional<aidl::android::aidl::tests::vintf::VintfExtendableParcelable> myExt;
599 ep.ext.getParcelable(&myExt);
600
601 if (myExt == std::nullopt) {
602 return ScopedAStatus::fromStatus(android::UNKNOWN_ERROR);
603 }
604
605 ep2->ext.setParcelable(*myExt);
606
607 return ScopedAStatus::ok();
608 }
609
ReverseList(const RecursiveList & list,RecursiveList * ret)610 ScopedAStatus ReverseList(const RecursiveList& list, RecursiveList* ret) override {
611 std::unique_ptr<RecursiveList> reversed;
612 const RecursiveList* cur = &list;
613 while (cur) {
614 auto node = std::make_unique<RecursiveList>();
615 node->value = cur->value;
616 node->next = std::move(reversed);
617 reversed = std::move(node);
618 cur = cur->next.get();
619 }
620 *ret = std::move(*reversed);
621 return ScopedAStatus::ok();
622 }
623
ReverseIBinderArray(const vector<SpAIBinder> & input,vector<SpAIBinder> * repeated,vector<SpAIBinder> * _aidl_return)624 ScopedAStatus ReverseIBinderArray(const vector<SpAIBinder>& input, vector<SpAIBinder>* repeated,
625 vector<SpAIBinder>* _aidl_return) override {
626 *repeated = input;
627 *_aidl_return = input;
628 std::reverse(_aidl_return->begin(), _aidl_return->end());
629 return ScopedAStatus::ok();
630 }
631
ReverseNullableIBinderArray(const std::optional<vector<SpAIBinder>> & input,std::optional<vector<SpAIBinder>> * repeated,std::optional<vector<SpAIBinder>> * _aidl_return)632 ScopedAStatus ReverseNullableIBinderArray(
633 const std::optional<vector<SpAIBinder>>& input, std::optional<vector<SpAIBinder>>* repeated,
634 std::optional<vector<SpAIBinder>>* _aidl_return) override {
635 *repeated = input;
636 *_aidl_return = input;
637 if (*_aidl_return) {
638 std::reverse((*_aidl_return)->begin(), (*_aidl_return)->end());
639 }
640 return ScopedAStatus::ok();
641 }
642
RepeatSimpleParcelable(const SimpleParcelable & input,SimpleParcelable * repeat,SimpleParcelable * _aidl_return)643 ScopedAStatus RepeatSimpleParcelable(const SimpleParcelable& input, SimpleParcelable* repeat,
644 SimpleParcelable* _aidl_return) override {
645 ALOGI("Repeated a SimpleParcelable %s", input.toString().c_str());
646 *repeat = input;
647 *_aidl_return = input;
648 return ScopedAStatus::ok();
649 }
650
ReverseSimpleParcelables(const vector<SimpleParcelable> & input,vector<SimpleParcelable> * repeated,vector<SimpleParcelable> * _aidl_return)651 ScopedAStatus ReverseSimpleParcelables(const vector<SimpleParcelable>& input,
652 vector<SimpleParcelable>* repeated,
653 vector<SimpleParcelable>* _aidl_return) override {
654 return ReverseArray(input, repeated, _aidl_return);
655 }
656
UnimplementedMethod(int32_t,int32_t *)657 ScopedAStatus UnimplementedMethod(int32_t /* arg */, int32_t* /* _aidl_return */) override {
658 return ScopedAStatus::fromStatus(STATUS_UNKNOWN_TRANSACTION);
659 }
660
GetOldNameInterface(std::shared_ptr<IOldName> * ret)661 ScopedAStatus GetOldNameInterface(std::shared_ptr<IOldName>* ret) {
662 *ret = SharedRefBase::make<OldName>();
663 return ScopedAStatus::ok();
664 }
665
GetNewNameInterface(std::shared_ptr<INewName> * ret)666 ScopedAStatus GetNewNameInterface(std::shared_ptr<INewName>* ret) {
667 *ret = SharedRefBase::make<NewName>();
668 return ScopedAStatus::ok();
669 }
670
GetUnionTags(const std::vector<Union> & input,std::vector<Union::Tag> * _aidl_return)671 ScopedAStatus GetUnionTags(const std::vector<Union>& input,
672 std::vector<Union::Tag>* _aidl_return) override {
673 std::vector<Union::Tag> tags;
674 std::transform(input.begin(), input.end(), std::back_inserter(tags),
675 std::mem_fn(&Union::getTag));
676 *_aidl_return = std::move(tags);
677 return ScopedAStatus::ok();
678 }
679
GetCppJavaTests(SpAIBinder * ret)680 ScopedAStatus GetCppJavaTests(SpAIBinder* ret) {
681 *ret = nullptr;
682 return ScopedAStatus::ok();
683 }
684
getBackendType(BackendType * _aidl_return)685 ScopedAStatus getBackendType(BackendType* _aidl_return) override {
686 *_aidl_return = BackendType::NDK;
687 return ScopedAStatus::ok();
688 }
689
GetCircular(CircularParcelable * cp,std::shared_ptr<ICircular> * _aidl_return)690 ScopedAStatus GetCircular(CircularParcelable* cp,
691 std::shared_ptr<ICircular>* _aidl_return) override {
692 auto thiz = ref<ITestService>();
693 cp->testService = thiz;
694 *_aidl_return = SharedRefBase::make<Circular>(thiz);
695 return ScopedAStatus::ok();
696 }
697
698 private:
699 std::map<std::string, std::shared_ptr<INamedCallback>> service_map_;
700 std::mutex service_map_mutex_;
701 };
702
703 class VersionedService : public aidl::android::aidl::versioned::tests::BnFooInterface {
704 public:
VersionedService()705 VersionedService() {}
706 virtual ~VersionedService() = default;
707
originalApi()708 ScopedAStatus originalApi() override { return ScopedAStatus::ok(); }
acceptUnionAndReturnString(const::aidl::android::aidl::versioned::tests::BazUnion & u,std::string * _aidl_return)709 ScopedAStatus acceptUnionAndReturnString(
710 const ::aidl::android::aidl::versioned::tests::BazUnion& u,
711 std::string* _aidl_return) override {
712 switch (u.getTag()) {
713 case ::aidl::android::aidl::versioned::tests::BazUnion::intNum:
714 *_aidl_return =
715 std::to_string(u.get<::aidl::android::aidl::versioned::tests::BazUnion::intNum>());
716 break;
717 }
718 return ScopedAStatus::ok();
719 }
returnsLengthOfFooArray(const vector<::aidl::android::aidl::versioned::tests::Foo> & foos,int32_t * ret)720 ScopedAStatus returnsLengthOfFooArray(
721 const vector<::aidl::android::aidl::versioned::tests::Foo>& foos, int32_t* ret) override {
722 *ret = static_cast<int32_t>(foos.size());
723 return ScopedAStatus::ok();
724 }
ignoreParcelablesAndRepeatInt(const::aidl::android::aidl::versioned::tests::Foo & inFoo,::aidl::android::aidl::versioned::tests::Foo * inoutFoo,::aidl::android::aidl::versioned::tests::Foo * outFoo,int32_t value,int32_t * ret)725 ScopedAStatus ignoreParcelablesAndRepeatInt(
726 const ::aidl::android::aidl::versioned::tests::Foo& inFoo,
727 ::aidl::android::aidl::versioned::tests::Foo* inoutFoo,
728 ::aidl::android::aidl::versioned::tests::Foo* outFoo, int32_t value, int32_t* ret) override {
729 (void)inFoo;
730 (void)inoutFoo;
731 (void)outFoo;
732 *ret = value;
733 return ScopedAStatus::ok();
734 }
735 };
736
737 class LoggableInterfaceService : public aidl::android::aidl::loggable::BnLoggableInterface {
738 public:
LoggableInterfaceService()739 LoggableInterfaceService() {}
740 virtual ~LoggableInterfaceService() = default;
741
LogThis(bool,vector<bool> *,int8_t,vector<uint8_t> *,char16_t,vector<char16_t> *,int32_t,vector<int32_t> *,int64_t,vector<int64_t> *,float,vector<float> *,double,vector<double> *,const std::string &,vector<std::string> *,vector<std::string> *,const aidl::android::aidl::loggable::Data &,const SpAIBinder &,ScopedFileDescriptor *,vector<ScopedFileDescriptor> *,vector<std::string> * _aidl_return)742 virtual ScopedAStatus LogThis(bool, vector<bool>*, int8_t, vector<uint8_t>*, char16_t,
743 vector<char16_t>*, int32_t, vector<int32_t>*, int64_t,
744 vector<int64_t>*, float, vector<float>*, double, vector<double>*,
745 const std::string&, vector<std::string>*, vector<std::string>*,
746 const aidl::android::aidl::loggable::Data&, const SpAIBinder&,
747 ScopedFileDescriptor*, vector<ScopedFileDescriptor>*,
748 vector<std::string>* _aidl_return) override {
749 *_aidl_return = vector<std::string>{std::string("loggable")};
750 return ScopedAStatus::ok();
751 }
752 };
753
754 using namespace aidl::android::aidl::tests::nested;
755 class NestedService : public BnNestedService {
756 public:
NestedService()757 NestedService() {}
758 virtual ~NestedService() = default;
759
flipStatus(const ParcelableWithNested & p,INestedService::Result * _aidl_return)760 virtual ScopedAStatus flipStatus(const ParcelableWithNested& p,
761 INestedService::Result* _aidl_return) {
762 if (p.status == ParcelableWithNested::Status::OK) {
763 _aidl_return->status = ParcelableWithNested::Status::NOT_OK;
764 } else {
765 _aidl_return->status = ParcelableWithNested::Status::OK;
766 }
767 return ScopedAStatus::ok();
768 }
flipStatusWithCallback(ParcelableWithNested::Status status,const std::shared_ptr<INestedService::ICallback> & cb)769 virtual ScopedAStatus flipStatusWithCallback(
770 ParcelableWithNested::Status status, const std::shared_ptr<INestedService::ICallback>& cb) {
771 if (status == ParcelableWithNested::Status::OK) {
772 return cb->done(ParcelableWithNested::Status::NOT_OK);
773 } else {
774 return cb->done(ParcelableWithNested::Status::OK);
775 }
776 }
777 };
778
779 using aidl::android::aidl::fixedsizearray::FixedSizeArrayExample;
780 class FixedSizeArrayService : public FixedSizeArrayExample::BnRepeatFixedSizeArray {
781 public:
FixedSizeArrayService()782 FixedSizeArrayService() {}
783 virtual ~FixedSizeArrayService() = default;
784
RepeatBytes(const std::array<uint8_t,3> & in_input,std::array<uint8_t,3> * out_repeated,std::array<uint8_t,3> * _aidl_return)785 ScopedAStatus RepeatBytes(const std::array<uint8_t, 3>& in_input,
786 std::array<uint8_t, 3>* out_repeated,
787 std::array<uint8_t, 3>* _aidl_return) override {
788 *out_repeated = in_input;
789 *_aidl_return = in_input;
790 return ScopedAStatus::ok();
791 }
RepeatInts(const std::array<int32_t,3> & in_input,std::array<int32_t,3> * out_repeated,std::array<int32_t,3> * _aidl_return)792 ScopedAStatus RepeatInts(const std::array<int32_t, 3>& in_input,
793 std::array<int32_t, 3>* out_repeated,
794 std::array<int32_t, 3>* _aidl_return) override {
795 *out_repeated = in_input;
796 *_aidl_return = in_input;
797 return ScopedAStatus::ok();
798 }
RepeatBinders(const std::array<SpAIBinder,3> & in_input,std::array<SpAIBinder,3> * out_repeated,std::array<SpAIBinder,3> * _aidl_return)799 ScopedAStatus RepeatBinders(const std::array<SpAIBinder, 3>& in_input,
800 std::array<SpAIBinder, 3>* out_repeated,
801 std::array<SpAIBinder, 3>* _aidl_return) override {
802 *out_repeated = in_input;
803 *_aidl_return = in_input;
804 return ScopedAStatus::ok();
805 }
RepeatParcelables(const std::array<FixedSizeArrayExample::IntParcelable,3> & in_input,std::array<FixedSizeArrayExample::IntParcelable,3> * out_repeated,std::array<FixedSizeArrayExample::IntParcelable,3> * _aidl_return)806 ScopedAStatus RepeatParcelables(
807 const std::array<FixedSizeArrayExample::IntParcelable, 3>& in_input,
808 std::array<FixedSizeArrayExample::IntParcelable, 3>* out_repeated,
809 std::array<FixedSizeArrayExample::IntParcelable, 3>* _aidl_return) override {
810 *out_repeated = in_input;
811 *_aidl_return = in_input;
812 return ScopedAStatus::ok();
813 }
Repeat2dBytes(const std::array<std::array<uint8_t,3>,2> & in_input,std::array<std::array<uint8_t,3>,2> * out_repeated,std::array<std::array<uint8_t,3>,2> * _aidl_return)814 ScopedAStatus Repeat2dBytes(const std::array<std::array<uint8_t, 3>, 2>& in_input,
815 std::array<std::array<uint8_t, 3>, 2>* out_repeated,
816 std::array<std::array<uint8_t, 3>, 2>* _aidl_return) override {
817 *out_repeated = in_input;
818 *_aidl_return = in_input;
819 return ScopedAStatus::ok();
820 }
Repeat2dInts(const std::array<std::array<int32_t,3>,2> & in_input,std::array<std::array<int32_t,3>,2> * out_repeated,std::array<std::array<int32_t,3>,2> * _aidl_return)821 ScopedAStatus Repeat2dInts(const std::array<std::array<int32_t, 3>, 2>& in_input,
822 std::array<std::array<int32_t, 3>, 2>* out_repeated,
823 std::array<std::array<int32_t, 3>, 2>* _aidl_return) override {
824 *out_repeated = in_input;
825 *_aidl_return = in_input;
826 return ScopedAStatus::ok();
827 }
Repeat2dBinders(const std::array<std::array<SpAIBinder,3>,2> & in_input,std::array<std::array<SpAIBinder,3>,2> * out_repeated,std::array<std::array<SpAIBinder,3>,2> * _aidl_return)828 ScopedAStatus Repeat2dBinders(const std::array<std::array<SpAIBinder, 3>, 2>& in_input,
829 std::array<std::array<SpAIBinder, 3>, 2>* out_repeated,
830 std::array<std::array<SpAIBinder, 3>, 2>* _aidl_return) override {
831 *out_repeated = in_input;
832 *_aidl_return = in_input;
833 return ScopedAStatus::ok();
834 }
Repeat2dParcelables(const std::array<std::array<FixedSizeArrayExample::IntParcelable,3>,2> & in_input,std::array<std::array<FixedSizeArrayExample::IntParcelable,3>,2> * out_repeated,std::array<std::array<FixedSizeArrayExample::IntParcelable,3>,2> * _aidl_return)835 ScopedAStatus Repeat2dParcelables(
836 const std::array<std::array<FixedSizeArrayExample::IntParcelable, 3>, 2>& in_input,
837 std::array<std::array<FixedSizeArrayExample::IntParcelable, 3>, 2>* out_repeated,
838 std::array<std::array<FixedSizeArrayExample::IntParcelable, 3>, 2>* _aidl_return) override {
839 *out_repeated = in_input;
840 *_aidl_return = in_input;
841 return ScopedAStatus::ok();
842 }
843 };
844
845 class TrunkStableService : public aidl::android::aidl::test::trunk::BnTrunkStableTest {
846 public:
TrunkStableService()847 TrunkStableService() {}
848 virtual ~TrunkStableService() = default;
849
repeatParcelable(const aidl::android::aidl::test::trunk::ITrunkStableTest::MyParcelable & input,aidl::android::aidl::test::trunk::ITrunkStableTest::MyParcelable * _aidl_return)850 ScopedAStatus repeatParcelable(
851 const aidl::android::aidl::test::trunk::ITrunkStableTest::MyParcelable& input,
852 aidl::android::aidl::test::trunk::ITrunkStableTest::MyParcelable* _aidl_return) override {
853 *_aidl_return = input;
854 return ScopedAStatus::ok();
855 }
repeatEnum(aidl::android::aidl::test::trunk::ITrunkStableTest::MyEnum input,aidl::android::aidl::test::trunk::ITrunkStableTest::MyEnum * _aidl_return)856 ScopedAStatus repeatEnum(
857 aidl::android::aidl::test::trunk::ITrunkStableTest::MyEnum input,
858 aidl::android::aidl::test::trunk::ITrunkStableTest::MyEnum* _aidl_return) override {
859 *_aidl_return = input;
860 return ScopedAStatus::ok();
861 }
repeatUnion(const aidl::android::aidl::test::trunk::ITrunkStableTest::MyUnion & input,aidl::android::aidl::test::trunk::ITrunkStableTest::MyUnion * _aidl_return)862 ScopedAStatus repeatUnion(
863 const aidl::android::aidl::test::trunk::ITrunkStableTest::MyUnion& input,
864 aidl::android::aidl::test::trunk::ITrunkStableTest::MyUnion* _aidl_return) override {
865 *_aidl_return = input;
866 return ScopedAStatus::ok();
867 }
callMyCallback(const std::shared_ptr<aidl::android::aidl::test::trunk::ITrunkStableTest::IMyCallback> & cb)868 ScopedAStatus callMyCallback(
869 const std::shared_ptr<aidl::android::aidl::test::trunk::ITrunkStableTest::IMyCallback>& cb)
870 override {
871 if (!cb) return ScopedAStatus::fromStatus(android::UNEXPECTED_NULL);
872 MyParcelable a, b;
873 MyEnum c = MyEnum::ZERO, d = MyEnum::ZERO;
874 MyUnion e, f;
875 auto status = cb->repeatParcelable(a, &b);
876 if (!status.isOk()) {
877 return status;
878 }
879 status = cb->repeatEnum(c, &d);
880 if (!status.isOk()) {
881 return status;
882 }
883 status = cb->repeatUnion(e, &f);
884 if (!status.isOk()) {
885 return status;
886 }
887 MyOtherParcelable g, h;
888 status = cb->repeatOtherParcelable(g, &h);
889 return ScopedAStatus::ok();
890 }
891
repeatOtherParcelable(const aidl::android::aidl::test::trunk::ITrunkStableTest::MyOtherParcelable & input,aidl::android::aidl::test::trunk::ITrunkStableTest::MyOtherParcelable * _aidl_return)892 ScopedAStatus repeatOtherParcelable(
893 const aidl::android::aidl::test::trunk::ITrunkStableTest::MyOtherParcelable& input,
894 aidl::android::aidl::test::trunk::ITrunkStableTest::MyOtherParcelable* _aidl_return)
895 override {
896 *_aidl_return = input;
897 return ScopedAStatus::ok();
898 }
899 };
900
901 } // namespace
902
main(int,char * [])903 int main(int /* argc */, char* /* argv */[]) {
904 std::vector<SpAIBinder> binders = {
905 SharedRefBase::make<NativeService>()->asBinder(),
906 SharedRefBase::make<VersionedService>()->asBinder(),
907 SharedRefBase::make<LoggableInterfaceService>()->asBinder(),
908 SharedRefBase::make<NestedService>()->asBinder(),
909 SharedRefBase::make<FixedSizeArrayService>()->asBinder(),
910 SharedRefBase::make<TrunkStableService>()->asBinder(),
911 };
912
913 for (const SpAIBinder& binder : binders) {
914 const char* desc = AIBinder_Class_getDescriptor(AIBinder_getClass(binder.get()));
915 if (STATUS_OK != AServiceManager_addService(binder.get(), desc)) {
916 ALOGE("Failed to add service %s", desc);
917 return EXIT_FAILURE;
918 }
919 }
920
921 ABinderProcess_joinThreadPool();
922 return EXIT_FAILURE; // should not reach
923 }
924