1 /* 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 "tests/test_data.h" 18 19 namespace android { 20 namespace aidl { 21 namespace test_data { 22 namespace ping_responder { 23 24 // clang-format off 25 const char kCanonicalName[] = "android.os.IPingResponder"; 26 const char kInterfaceDefinition[] = R"( 27 package android.os; 28 29 import bar.Unused; 30 31 interface IPingResponder { 32 String Ping(String input); 33 34 @nullable 35 String NullablePing(@nullable String input); 36 37 @utf8InCpp 38 String Utf8Ping(@utf8InCpp String input); 39 40 @utf8InCpp @nullable 41 String NullableUtf8Ping(@utf8InCpp @nullable String input); 42 } 43 )"; 44 45 const char kCppOutputPath[] = "some/path/to/output.cpp"; 46 47 const char kCppParcelableHeader[] = "cpp-header-str"; 48 49 const char* kImportedParcelables[] = { 50 "bar.Unused", 51 nullptr, 52 }; 53 54 const char* kImportedInterfaces[] = { 55 nullptr, 56 }; 57 58 const char kGenHeaderDir[] = "some/path"; 59 const char kGenInterfaceHeaderPath[] = "some/path/android/os/IPingResponder.h"; 60 const char kGenClientHeaderPath[] = "some/path/android/os/BpPingResponder.h"; 61 const char kGenServerHeaderPath[] = "some/path/android/os/BnPingResponder.h"; 62 63 const char kExpectedCppDepsOutput[] = 64 R"(some/path/to/output.cpp : \ 65 android/os/IPingResponder.aidl \ 66 ./bar/Unused.aidl 67 68 android/os/IPingResponder.aidl : 69 ./bar/Unused.aidl : 70 71 some/path/android/os/BpPingResponder.h \ 72 some/path/android/os/BnPingResponder.h \ 73 some/path/android/os/IPingResponder.h : \ 74 android/os/IPingResponder.aidl \ 75 ./bar/Unused.aidl 76 )"; 77 78 const char kExpectedCppOutput[] = 79 R"(#include <android/os/IPingResponder.h> 80 #include <android/os/BpPingResponder.h> 81 82 namespace android { 83 84 namespace os { 85 86 DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_INTERFACE(PingResponder, "android.os.IPingResponder") 87 88 } // namespace os 89 90 } // namespace android 91 #include <android/os/BpPingResponder.h> 92 #include <binder/Parcel.h> 93 #include <android-base/macros.h> 94 95 namespace android { 96 97 namespace os { 98 99 BpPingResponder::BpPingResponder(const ::android::sp<::android::IBinder>& _aidl_impl) 100 : BpInterface<IPingResponder>(_aidl_impl){ 101 } 102 103 ::android::binder::Status BpPingResponder::Ping(const ::android::String16& input, ::android::String16* _aidl_return) { 104 ::android::Parcel _aidl_data; 105 ::android::Parcel _aidl_reply; 106 ::android::status_t _aidl_ret_status = ::android::OK; 107 ::android::binder::Status _aidl_status; 108 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); 109 if (((_aidl_ret_status) != (::android::OK))) { 110 goto _aidl_error; 111 } 112 _aidl_ret_status = _aidl_data.writeString16(input); 113 if (((_aidl_ret_status) != (::android::OK))) { 114 goto _aidl_error; 115 } 116 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Ping */, _aidl_data, &_aidl_reply); 117 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IPingResponder::getDefaultImpl())) { 118 return IPingResponder::getDefaultImpl()->Ping(input, _aidl_return); 119 } 120 if (((_aidl_ret_status) != (::android::OK))) { 121 goto _aidl_error; 122 } 123 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); 124 if (((_aidl_ret_status) != (::android::OK))) { 125 goto _aidl_error; 126 } 127 if (!_aidl_status.isOk()) { 128 return _aidl_status; 129 } 130 _aidl_ret_status = _aidl_reply.readString16(_aidl_return); 131 if (((_aidl_ret_status) != (::android::OK))) { 132 goto _aidl_error; 133 } 134 _aidl_error: 135 _aidl_status.setFromStatusT(_aidl_ret_status); 136 return _aidl_status; 137 } 138 139 ::android::binder::Status BpPingResponder::NullablePing(const ::std::optional<::android::String16>& input, ::std::optional<::android::String16>* _aidl_return) { 140 ::android::Parcel _aidl_data; 141 ::android::Parcel _aidl_reply; 142 ::android::status_t _aidl_ret_status = ::android::OK; 143 ::android::binder::Status _aidl_status; 144 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); 145 if (((_aidl_ret_status) != (::android::OK))) { 146 goto _aidl_error; 147 } 148 _aidl_ret_status = _aidl_data.writeString16(input); 149 if (((_aidl_ret_status) != (::android::OK))) { 150 goto _aidl_error; 151 } 152 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* NullablePing */, _aidl_data, &_aidl_reply); 153 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IPingResponder::getDefaultImpl())) { 154 return IPingResponder::getDefaultImpl()->NullablePing(input, _aidl_return); 155 } 156 if (((_aidl_ret_status) != (::android::OK))) { 157 goto _aidl_error; 158 } 159 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); 160 if (((_aidl_ret_status) != (::android::OK))) { 161 goto _aidl_error; 162 } 163 if (!_aidl_status.isOk()) { 164 return _aidl_status; 165 } 166 _aidl_ret_status = _aidl_reply.readString16(_aidl_return); 167 if (((_aidl_ret_status) != (::android::OK))) { 168 goto _aidl_error; 169 } 170 _aidl_error: 171 _aidl_status.setFromStatusT(_aidl_ret_status); 172 return _aidl_status; 173 } 174 175 ::android::binder::Status BpPingResponder::Utf8Ping(const ::std::string& input, ::std::string* _aidl_return) { 176 ::android::Parcel _aidl_data; 177 ::android::Parcel _aidl_reply; 178 ::android::status_t _aidl_ret_status = ::android::OK; 179 ::android::binder::Status _aidl_status; 180 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); 181 if (((_aidl_ret_status) != (::android::OK))) { 182 goto _aidl_error; 183 } 184 _aidl_ret_status = _aidl_data.writeUtf8AsUtf16(input); 185 if (((_aidl_ret_status) != (::android::OK))) { 186 goto _aidl_error; 187 } 188 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* Utf8Ping */, _aidl_data, &_aidl_reply); 189 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IPingResponder::getDefaultImpl())) { 190 return IPingResponder::getDefaultImpl()->Utf8Ping(input, _aidl_return); 191 } 192 if (((_aidl_ret_status) != (::android::OK))) { 193 goto _aidl_error; 194 } 195 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); 196 if (((_aidl_ret_status) != (::android::OK))) { 197 goto _aidl_error; 198 } 199 if (!_aidl_status.isOk()) { 200 return _aidl_status; 201 } 202 _aidl_ret_status = _aidl_reply.readUtf8FromUtf16(_aidl_return); 203 if (((_aidl_ret_status) != (::android::OK))) { 204 goto _aidl_error; 205 } 206 _aidl_error: 207 _aidl_status.setFromStatusT(_aidl_ret_status); 208 return _aidl_status; 209 } 210 211 ::android::binder::Status BpPingResponder::NullableUtf8Ping(const ::std::optional<::std::string>& input, ::std::optional<::std::string>* _aidl_return) { 212 ::android::Parcel _aidl_data; 213 ::android::Parcel _aidl_reply; 214 ::android::status_t _aidl_ret_status = ::android::OK; 215 ::android::binder::Status _aidl_status; 216 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); 217 if (((_aidl_ret_status) != (::android::OK))) { 218 goto _aidl_error; 219 } 220 _aidl_ret_status = _aidl_data.writeUtf8AsUtf16(input); 221 if (((_aidl_ret_status) != (::android::OK))) { 222 goto _aidl_error; 223 } 224 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableUtf8Ping */, _aidl_data, &_aidl_reply); 225 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IPingResponder::getDefaultImpl())) { 226 return IPingResponder::getDefaultImpl()->NullableUtf8Ping(input, _aidl_return); 227 } 228 if (((_aidl_ret_status) != (::android::OK))) { 229 goto _aidl_error; 230 } 231 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); 232 if (((_aidl_ret_status) != (::android::OK))) { 233 goto _aidl_error; 234 } 235 if (!_aidl_status.isOk()) { 236 return _aidl_status; 237 } 238 _aidl_ret_status = _aidl_reply.readUtf8FromUtf16(_aidl_return); 239 if (((_aidl_ret_status) != (::android::OK))) { 240 goto _aidl_error; 241 } 242 _aidl_error: 243 _aidl_status.setFromStatusT(_aidl_ret_status); 244 return _aidl_status; 245 } 246 247 } // namespace os 248 249 } // namespace android 250 #include <android/os/BnPingResponder.h> 251 #include <binder/Parcel.h> 252 #include <binder/Stability.h> 253 254 namespace android { 255 256 namespace os { 257 258 BnPingResponder::BnPingResponder() 259 { 260 ::android::internal::Stability::markCompilationUnit(this); 261 } 262 263 ::android::status_t BnPingResponder::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) { 264 ::android::status_t _aidl_ret_status = ::android::OK; 265 switch (_aidl_code) { 266 case ::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Ping */: 267 { 268 ::android::String16 in_input; 269 ::android::String16 _aidl_return; 270 if (!(_aidl_data.checkInterface(this))) { 271 _aidl_ret_status = ::android::BAD_TYPE; 272 break; 273 } 274 _aidl_ret_status = _aidl_data.readString16(&in_input); 275 if (((_aidl_ret_status) != (::android::OK))) { 276 break; 277 } 278 ::android::binder::Status _aidl_status(Ping(in_input, &_aidl_return)); 279 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); 280 if (((_aidl_ret_status) != (::android::OK))) { 281 break; 282 } 283 if (!_aidl_status.isOk()) { 284 break; 285 } 286 _aidl_ret_status = _aidl_reply->writeString16(_aidl_return); 287 if (((_aidl_ret_status) != (::android::OK))) { 288 break; 289 } 290 } 291 break; 292 case ::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* NullablePing */: 293 { 294 ::std::optional<::android::String16> in_input; 295 ::std::optional<::android::String16> _aidl_return; 296 if (!(_aidl_data.checkInterface(this))) { 297 _aidl_ret_status = ::android::BAD_TYPE; 298 break; 299 } 300 _aidl_ret_status = _aidl_data.readString16(&in_input); 301 if (((_aidl_ret_status) != (::android::OK))) { 302 break; 303 } 304 ::android::binder::Status _aidl_status(NullablePing(in_input, &_aidl_return)); 305 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); 306 if (((_aidl_ret_status) != (::android::OK))) { 307 break; 308 } 309 if (!_aidl_status.isOk()) { 310 break; 311 } 312 _aidl_ret_status = _aidl_reply->writeString16(_aidl_return); 313 if (((_aidl_ret_status) != (::android::OK))) { 314 break; 315 } 316 } 317 break; 318 case ::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* Utf8Ping */: 319 { 320 ::std::string in_input; 321 ::std::string _aidl_return; 322 if (!(_aidl_data.checkInterface(this))) { 323 _aidl_ret_status = ::android::BAD_TYPE; 324 break; 325 } 326 _aidl_ret_status = _aidl_data.readUtf8FromUtf16(&in_input); 327 if (((_aidl_ret_status) != (::android::OK))) { 328 break; 329 } 330 ::android::binder::Status _aidl_status(Utf8Ping(in_input, &_aidl_return)); 331 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); 332 if (((_aidl_ret_status) != (::android::OK))) { 333 break; 334 } 335 if (!_aidl_status.isOk()) { 336 break; 337 } 338 _aidl_ret_status = _aidl_reply->writeUtf8AsUtf16(_aidl_return); 339 if (((_aidl_ret_status) != (::android::OK))) { 340 break; 341 } 342 } 343 break; 344 case ::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableUtf8Ping */: 345 { 346 ::std::optional<::std::string> in_input; 347 ::std::optional<::std::string> _aidl_return; 348 if (!(_aidl_data.checkInterface(this))) { 349 _aidl_ret_status = ::android::BAD_TYPE; 350 break; 351 } 352 _aidl_ret_status = _aidl_data.readUtf8FromUtf16(&in_input); 353 if (((_aidl_ret_status) != (::android::OK))) { 354 break; 355 } 356 ::android::binder::Status _aidl_status(NullableUtf8Ping(in_input, &_aidl_return)); 357 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); 358 if (((_aidl_ret_status) != (::android::OK))) { 359 break; 360 } 361 if (!_aidl_status.isOk()) { 362 break; 363 } 364 _aidl_ret_status = _aidl_reply->writeUtf8AsUtf16(_aidl_return); 365 if (((_aidl_ret_status) != (::android::OK))) { 366 break; 367 } 368 } 369 break; 370 default: 371 { 372 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags); 373 } 374 break; 375 } 376 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) { 377 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply); 378 } 379 return _aidl_ret_status; 380 } 381 382 } // namespace os 383 384 } // namespace android 385 )"; 386 387 const char kExpectedIHeaderOutput[] = 388 R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_ 389 #define AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_ 390 391 #include <binder/IBinder.h> 392 #include <binder/IInterface.h> 393 #include <binder/Status.h> 394 #include <optional> 395 #include <string> 396 #include <utils/String16.h> 397 #include <utils/StrongPointer.h> 398 399 namespace android { 400 401 namespace os { 402 403 class IPingResponder : public ::android::IInterface { 404 public: 405 DECLARE_META_INTERFACE(PingResponder) 406 virtual ::android::binder::Status Ping(const ::android::String16& input, ::android::String16* _aidl_return) = 0; 407 virtual ::android::binder::Status NullablePing(const ::std::optional<::android::String16>& input, ::std::optional<::android::String16>* _aidl_return) = 0; 408 virtual ::android::binder::Status Utf8Ping(const ::std::string& input, ::std::string* _aidl_return) = 0; 409 virtual ::android::binder::Status NullableUtf8Ping(const ::std::optional<::std::string>& input, ::std::optional<::std::string>* _aidl_return) = 0; 410 }; // class IPingResponder 411 412 class IPingResponderDefault : public IPingResponder { 413 public: 414 ::android::IBinder* onAsBinder() override { 415 return nullptr; 416 } 417 ::android::binder::Status Ping(const ::android::String16&, ::android::String16*) override { 418 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION); 419 } 420 ::android::binder::Status NullablePing(const ::std::optional<::android::String16>&, ::std::optional<::android::String16>*) override { 421 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION); 422 } 423 ::android::binder::Status Utf8Ping(const ::std::string&, ::std::string*) override { 424 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION); 425 } 426 ::android::binder::Status NullableUtf8Ping(const ::std::optional<::std::string>&, ::std::optional<::std::string>*) override { 427 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION); 428 } 429 }; // class IPingResponderDefault 430 431 } // namespace os 432 433 } // namespace android 434 435 #endif // AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_ 436 )"; 437 438 const char kExpectedBpHeaderOutput[] = 439 R"(#ifndef AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_ 440 #define AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_ 441 442 #include <binder/IBinder.h> 443 #include <binder/IInterface.h> 444 #include <utils/Errors.h> 445 #include <android/os/IPingResponder.h> 446 447 namespace android { 448 449 namespace os { 450 451 class BpPingResponder : public ::android::BpInterface<IPingResponder> { 452 public: 453 explicit BpPingResponder(const ::android::sp<::android::IBinder>& _aidl_impl); 454 virtual ~BpPingResponder() = default; 455 ::android::binder::Status Ping(const ::android::String16& input, ::android::String16* _aidl_return) override; 456 ::android::binder::Status NullablePing(const ::std::optional<::android::String16>& input, ::std::optional<::android::String16>* _aidl_return) override; 457 ::android::binder::Status Utf8Ping(const ::std::string& input, ::std::string* _aidl_return) override; 458 ::android::binder::Status NullableUtf8Ping(const ::std::optional<::std::string>& input, ::std::optional<::std::string>* _aidl_return) override; 459 }; // class BpPingResponder 460 461 } // namespace os 462 463 } // namespace android 464 465 #endif // AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_ 466 )"; 467 468 const char kExpectedBnHeaderOutput[] = 469 R"(#ifndef AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_ 470 #define AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_ 471 472 #include <binder/IInterface.h> 473 #include <android/os/IPingResponder.h> 474 475 namespace android { 476 477 namespace os { 478 479 class BnPingResponder : public ::android::BnInterface<IPingResponder> { 480 public: 481 explicit BnPingResponder(); 482 ::android::status_t onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) override; 483 }; // class BnPingResponder 484 485 } // namespace os 486 487 } // namespace android 488 489 #endif // AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_ 490 )"; 491 492 const char kExpectedCppOutputWithVersionAndHash[] = 493 R"(#include <android/os/IPingResponder.h> 494 #include <android/os/BpPingResponder.h> 495 496 namespace android { 497 498 namespace os { 499 500 DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_INTERFACE(PingResponder, "android.os.IPingResponder") 501 502 } // namespace os 503 504 } // namespace android 505 #include <android/os/BpPingResponder.h> 506 #include <binder/Parcel.h> 507 #include <android-base/macros.h> 508 509 namespace android { 510 511 namespace os { 512 513 BpPingResponder::BpPingResponder(const ::android::sp<::android::IBinder>& _aidl_impl) 514 : BpInterface<IPingResponder>(_aidl_impl){ 515 } 516 517 ::android::binder::Status BpPingResponder::Ping(const ::android::String16& input, ::android::String16* _aidl_return) { 518 ::android::Parcel _aidl_data; 519 ::android::Parcel _aidl_reply; 520 ::android::status_t _aidl_ret_status = ::android::OK; 521 ::android::binder::Status _aidl_status; 522 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); 523 if (((_aidl_ret_status) != (::android::OK))) { 524 goto _aidl_error; 525 } 526 _aidl_ret_status = _aidl_data.writeString16(input); 527 if (((_aidl_ret_status) != (::android::OK))) { 528 goto _aidl_error; 529 } 530 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Ping */, _aidl_data, &_aidl_reply); 531 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IPingResponder::getDefaultImpl())) { 532 return IPingResponder::getDefaultImpl()->Ping(input, _aidl_return); 533 } 534 if (((_aidl_ret_status) != (::android::OK))) { 535 goto _aidl_error; 536 } 537 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); 538 if (((_aidl_ret_status) != (::android::OK))) { 539 goto _aidl_error; 540 } 541 if (!_aidl_status.isOk()) { 542 return _aidl_status; 543 } 544 _aidl_ret_status = _aidl_reply.readString16(_aidl_return); 545 if (((_aidl_ret_status) != (::android::OK))) { 546 goto _aidl_error; 547 } 548 _aidl_error: 549 _aidl_status.setFromStatusT(_aidl_ret_status); 550 return _aidl_status; 551 } 552 553 ::android::binder::Status BpPingResponder::NullablePing(const ::std::optional<::android::String16>& input, ::std::optional<::android::String16>* _aidl_return) { 554 ::android::Parcel _aidl_data; 555 ::android::Parcel _aidl_reply; 556 ::android::status_t _aidl_ret_status = ::android::OK; 557 ::android::binder::Status _aidl_status; 558 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); 559 if (((_aidl_ret_status) != (::android::OK))) { 560 goto _aidl_error; 561 } 562 _aidl_ret_status = _aidl_data.writeString16(input); 563 if (((_aidl_ret_status) != (::android::OK))) { 564 goto _aidl_error; 565 } 566 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* NullablePing */, _aidl_data, &_aidl_reply); 567 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IPingResponder::getDefaultImpl())) { 568 return IPingResponder::getDefaultImpl()->NullablePing(input, _aidl_return); 569 } 570 if (((_aidl_ret_status) != (::android::OK))) { 571 goto _aidl_error; 572 } 573 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); 574 if (((_aidl_ret_status) != (::android::OK))) { 575 goto _aidl_error; 576 } 577 if (!_aidl_status.isOk()) { 578 return _aidl_status; 579 } 580 _aidl_ret_status = _aidl_reply.readString16(_aidl_return); 581 if (((_aidl_ret_status) != (::android::OK))) { 582 goto _aidl_error; 583 } 584 _aidl_error: 585 _aidl_status.setFromStatusT(_aidl_ret_status); 586 return _aidl_status; 587 } 588 589 ::android::binder::Status BpPingResponder::Utf8Ping(const ::std::string& input, ::std::string* _aidl_return) { 590 ::android::Parcel _aidl_data; 591 ::android::Parcel _aidl_reply; 592 ::android::status_t _aidl_ret_status = ::android::OK; 593 ::android::binder::Status _aidl_status; 594 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); 595 if (((_aidl_ret_status) != (::android::OK))) { 596 goto _aidl_error; 597 } 598 _aidl_ret_status = _aidl_data.writeUtf8AsUtf16(input); 599 if (((_aidl_ret_status) != (::android::OK))) { 600 goto _aidl_error; 601 } 602 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* Utf8Ping */, _aidl_data, &_aidl_reply); 603 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IPingResponder::getDefaultImpl())) { 604 return IPingResponder::getDefaultImpl()->Utf8Ping(input, _aidl_return); 605 } 606 if (((_aidl_ret_status) != (::android::OK))) { 607 goto _aidl_error; 608 } 609 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); 610 if (((_aidl_ret_status) != (::android::OK))) { 611 goto _aidl_error; 612 } 613 if (!_aidl_status.isOk()) { 614 return _aidl_status; 615 } 616 _aidl_ret_status = _aidl_reply.readUtf8FromUtf16(_aidl_return); 617 if (((_aidl_ret_status) != (::android::OK))) { 618 goto _aidl_error; 619 } 620 _aidl_error: 621 _aidl_status.setFromStatusT(_aidl_ret_status); 622 return _aidl_status; 623 } 624 625 ::android::binder::Status BpPingResponder::NullableUtf8Ping(const ::std::optional<::std::string>& input, ::std::optional<::std::string>* _aidl_return) { 626 ::android::Parcel _aidl_data; 627 ::android::Parcel _aidl_reply; 628 ::android::status_t _aidl_ret_status = ::android::OK; 629 ::android::binder::Status _aidl_status; 630 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); 631 if (((_aidl_ret_status) != (::android::OK))) { 632 goto _aidl_error; 633 } 634 _aidl_ret_status = _aidl_data.writeUtf8AsUtf16(input); 635 if (((_aidl_ret_status) != (::android::OK))) { 636 goto _aidl_error; 637 } 638 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableUtf8Ping */, _aidl_data, &_aidl_reply); 639 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IPingResponder::getDefaultImpl())) { 640 return IPingResponder::getDefaultImpl()->NullableUtf8Ping(input, _aidl_return); 641 } 642 if (((_aidl_ret_status) != (::android::OK))) { 643 goto _aidl_error; 644 } 645 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); 646 if (((_aidl_ret_status) != (::android::OK))) { 647 goto _aidl_error; 648 } 649 if (!_aidl_status.isOk()) { 650 return _aidl_status; 651 } 652 _aidl_ret_status = _aidl_reply.readUtf8FromUtf16(_aidl_return); 653 if (((_aidl_ret_status) != (::android::OK))) { 654 goto _aidl_error; 655 } 656 _aidl_error: 657 _aidl_status.setFromStatusT(_aidl_ret_status); 658 return _aidl_status; 659 } 660 661 int32_t BpPingResponder::getInterfaceVersion() { 662 if (cached_version_ == -1) { 663 ::android::Parcel data; 664 ::android::Parcel reply; 665 data.writeInterfaceToken(getInterfaceDescriptor()); 666 ::android::status_t err = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 16777214 /* getInterfaceVersion */, data, &reply); 667 if (err == ::android::OK) { 668 ::android::binder::Status _aidl_status; 669 err = _aidl_status.readFromParcel(reply); 670 if (err == ::android::OK && _aidl_status.isOk()) { 671 cached_version_ = reply.readInt32(); 672 } 673 } 674 } 675 return cached_version_; 676 } 677 678 std::string BpPingResponder::getInterfaceHash() { 679 std::lock_guard<std::mutex> lockGuard(cached_hash_mutex_); 680 if (cached_hash_ == "-1") { 681 ::android::Parcel data; 682 ::android::Parcel reply; 683 data.writeInterfaceToken(getInterfaceDescriptor()); 684 ::android::status_t err = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 16777213 /* getInterfaceHash */, data, &reply); 685 if (err == ::android::OK) { 686 ::android::binder::Status _aidl_status; 687 err = _aidl_status.readFromParcel(reply); 688 if (err == ::android::OK && _aidl_status.isOk()) { 689 reply.readUtf8FromUtf16(&cached_hash_); 690 } 691 } 692 } 693 return cached_hash_; 694 } 695 696 } // namespace os 697 698 } // namespace android 699 #include <android/os/BnPingResponder.h> 700 #include <binder/Parcel.h> 701 #include <binder/Stability.h> 702 703 namespace android { 704 705 namespace os { 706 707 BnPingResponder::BnPingResponder() 708 { 709 ::android::internal::Stability::markCompilationUnit(this); 710 } 711 712 ::android::status_t BnPingResponder::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) { 713 ::android::status_t _aidl_ret_status = ::android::OK; 714 switch (_aidl_code) { 715 case ::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Ping */: 716 { 717 ::android::String16 in_input; 718 ::android::String16 _aidl_return; 719 if (!(_aidl_data.checkInterface(this))) { 720 _aidl_ret_status = ::android::BAD_TYPE; 721 break; 722 } 723 _aidl_ret_status = _aidl_data.readString16(&in_input); 724 if (((_aidl_ret_status) != (::android::OK))) { 725 break; 726 } 727 ::android::binder::Status _aidl_status(Ping(in_input, &_aidl_return)); 728 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); 729 if (((_aidl_ret_status) != (::android::OK))) { 730 break; 731 } 732 if (!_aidl_status.isOk()) { 733 break; 734 } 735 _aidl_ret_status = _aidl_reply->writeString16(_aidl_return); 736 if (((_aidl_ret_status) != (::android::OK))) { 737 break; 738 } 739 } 740 break; 741 case ::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* NullablePing */: 742 { 743 ::std::optional<::android::String16> in_input; 744 ::std::optional<::android::String16> _aidl_return; 745 if (!(_aidl_data.checkInterface(this))) { 746 _aidl_ret_status = ::android::BAD_TYPE; 747 break; 748 } 749 _aidl_ret_status = _aidl_data.readString16(&in_input); 750 if (((_aidl_ret_status) != (::android::OK))) { 751 break; 752 } 753 ::android::binder::Status _aidl_status(NullablePing(in_input, &_aidl_return)); 754 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); 755 if (((_aidl_ret_status) != (::android::OK))) { 756 break; 757 } 758 if (!_aidl_status.isOk()) { 759 break; 760 } 761 _aidl_ret_status = _aidl_reply->writeString16(_aidl_return); 762 if (((_aidl_ret_status) != (::android::OK))) { 763 break; 764 } 765 } 766 break; 767 case ::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* Utf8Ping */: 768 { 769 ::std::string in_input; 770 ::std::string _aidl_return; 771 if (!(_aidl_data.checkInterface(this))) { 772 _aidl_ret_status = ::android::BAD_TYPE; 773 break; 774 } 775 _aidl_ret_status = _aidl_data.readUtf8FromUtf16(&in_input); 776 if (((_aidl_ret_status) != (::android::OK))) { 777 break; 778 } 779 ::android::binder::Status _aidl_status(Utf8Ping(in_input, &_aidl_return)); 780 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); 781 if (((_aidl_ret_status) != (::android::OK))) { 782 break; 783 } 784 if (!_aidl_status.isOk()) { 785 break; 786 } 787 _aidl_ret_status = _aidl_reply->writeUtf8AsUtf16(_aidl_return); 788 if (((_aidl_ret_status) != (::android::OK))) { 789 break; 790 } 791 } 792 break; 793 case ::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableUtf8Ping */: 794 { 795 ::std::optional<::std::string> in_input; 796 ::std::optional<::std::string> _aidl_return; 797 if (!(_aidl_data.checkInterface(this))) { 798 _aidl_ret_status = ::android::BAD_TYPE; 799 break; 800 } 801 _aidl_ret_status = _aidl_data.readUtf8FromUtf16(&in_input); 802 if (((_aidl_ret_status) != (::android::OK))) { 803 break; 804 } 805 ::android::binder::Status _aidl_status(NullableUtf8Ping(in_input, &_aidl_return)); 806 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); 807 if (((_aidl_ret_status) != (::android::OK))) { 808 break; 809 } 810 if (!_aidl_status.isOk()) { 811 break; 812 } 813 _aidl_ret_status = _aidl_reply->writeUtf8AsUtf16(_aidl_return); 814 if (((_aidl_ret_status) != (::android::OK))) { 815 break; 816 } 817 } 818 break; 819 case ::android::IBinder::FIRST_CALL_TRANSACTION + 16777214 /* getInterfaceVersion */: 820 { 821 _aidl_data.checkInterface(this); 822 _aidl_reply->writeNoException(); 823 _aidl_reply->writeInt32(IPingResponder::VERSION); 824 } 825 break; 826 case ::android::IBinder::FIRST_CALL_TRANSACTION + 16777213 /* getInterfaceHash */: 827 { 828 _aidl_data.checkInterface(this); 829 _aidl_reply->writeNoException(); 830 _aidl_reply->writeUtf8AsUtf16(IPingResponder::HASH); 831 } 832 break; 833 default: 834 { 835 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags); 836 } 837 break; 838 } 839 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) { 840 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply); 841 } 842 return _aidl_ret_status; 843 } 844 845 int32_t BnPingResponder::getInterfaceVersion() { 846 return IPingResponder::VERSION; 847 } 848 849 std::string BnPingResponder::getInterfaceHash() { 850 return IPingResponder::HASH; 851 } 852 853 } // namespace os 854 855 } // namespace android 856 )"; 857 858 const char kExpectedIHeaderOutputWithVersionAndHash[] = 859 R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_ 860 #define AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_ 861 862 #include <binder/IBinder.h> 863 #include <binder/IInterface.h> 864 #include <binder/Status.h> 865 #include <cstdint> 866 #include <optional> 867 #include <string> 868 #include <utils/String16.h> 869 #include <utils/StrongPointer.h> 870 871 namespace android { 872 873 namespace os { 874 875 class IPingResponder : public ::android::IInterface { 876 public: 877 DECLARE_META_INTERFACE(PingResponder) 878 const int32_t VERSION = 10; 879 const std::string HASH = "abcdefg"; 880 virtual ::android::binder::Status Ping(const ::android::String16& input, ::android::String16* _aidl_return) = 0; 881 virtual ::android::binder::Status NullablePing(const ::std::optional<::android::String16>& input, ::std::optional<::android::String16>* _aidl_return) = 0; 882 virtual ::android::binder::Status Utf8Ping(const ::std::string& input, ::std::string* _aidl_return) = 0; 883 virtual ::android::binder::Status NullableUtf8Ping(const ::std::optional<::std::string>& input, ::std::optional<::std::string>* _aidl_return) = 0; 884 virtual int32_t getInterfaceVersion() = 0; 885 virtual std::string getInterfaceHash() = 0; 886 }; // class IPingResponder 887 888 class IPingResponderDefault : public IPingResponder { 889 public: 890 ::android::IBinder* onAsBinder() override { 891 return nullptr; 892 } 893 ::android::binder::Status Ping(const ::android::String16&, ::android::String16*) override { 894 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION); 895 } 896 ::android::binder::Status NullablePing(const ::std::optional<::android::String16>&, ::std::optional<::android::String16>*) override { 897 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION); 898 } 899 ::android::binder::Status Utf8Ping(const ::std::string&, ::std::string*) override { 900 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION); 901 } 902 ::android::binder::Status NullableUtf8Ping(const ::std::optional<::std::string>&, ::std::optional<::std::string>*) override { 903 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION); 904 } 905 int32_t getInterfaceVersion() override { 906 return 0; 907 } 908 std::string getInterfaceHash() override { 909 return ""; 910 } 911 }; // class IPingResponderDefault 912 913 } // namespace os 914 915 } // namespace android 916 917 #endif // AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_ 918 )"; 919 920 const char kExpectedBpHeaderOutputWithVersionAndHash[] = 921 R"(#ifndef AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_ 922 #define AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_ 923 924 #include <binder/IBinder.h> 925 #include <binder/IInterface.h> 926 #include <utils/Errors.h> 927 #include <android/os/IPingResponder.h> 928 929 namespace android { 930 931 namespace os { 932 933 class BpPingResponder : public ::android::BpInterface<IPingResponder> { 934 public: 935 explicit BpPingResponder(const ::android::sp<::android::IBinder>& _aidl_impl); 936 virtual ~BpPingResponder() = default; 937 ::android::binder::Status Ping(const ::android::String16& input, ::android::String16* _aidl_return) override; 938 ::android::binder::Status NullablePing(const ::std::optional<::android::String16>& input, ::std::optional<::android::String16>* _aidl_return) override; 939 ::android::binder::Status Utf8Ping(const ::std::string& input, ::std::string* _aidl_return) override; 940 ::android::binder::Status NullableUtf8Ping(const ::std::optional<::std::string>& input, ::std::optional<::std::string>* _aidl_return) override; 941 int32_t getInterfaceVersion() override; 942 std::string getInterfaceHash() override; 943 private: 944 int32_t cached_version_ = -1; 945 std::string cached_hash_ = "-1"; 946 std::mutex cached_hash_mutex_; 947 }; // class BpPingResponder 948 949 } // namespace os 950 951 } // namespace android 952 953 #endif // AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_ 954 )"; 955 956 const char kExpectedBnHeaderOutputWithVersionAndHash[] = 957 R"(#ifndef AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_ 958 #define AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_ 959 960 #include <binder/IInterface.h> 961 #include <android/os/IPingResponder.h> 962 963 namespace android { 964 965 namespace os { 966 967 class BnPingResponder : public ::android::BnInterface<IPingResponder> { 968 public: 969 explicit BnPingResponder(); 970 ::android::status_t onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) override; 971 int32_t getInterfaceVersion() final override; 972 std::string getInterfaceHash(); 973 }; // class BnPingResponder 974 975 } // namespace os 976 977 } // namespace android 978 979 #endif // AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_ 980 )"; 981 982 // clang-format on 983 } // namespace ping_responder 984 } // namespace test_data 985 } // namespace aidl 986 } // namespace android 987