From a05b9cee0b83ef04274adf7f41e3e434ca0462d7 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Thu, 3 Nov 2022 12:11:42 +0900 Subject: rust: support interface names without I- Mangled aliases should use proper interface names even for interfaces whose name doesn't start with I-. Bug: 257146768 Test: atest aidl_unittests Test: m aidl_integration_test (compiler test) Change-Id: I8093652345b4a74035b71a79e0e97839195a6868 --- tests/android/aidl/tests/ITestService.aidl | 5 +- .../gen/android/aidl/tests/ITestService.cpp | 56 +++++++++++++ .../gen/include/android/aidl/tests/BnTestService.h | 1 + .../gen/include/android/aidl/tests/ITestService.h | 34 ++++++++ .../gen/android/aidl/tests/ITestService.java | 97 ++++++++++++++++++++++ .../gen/android/aidl/tests/ITestService.cpp | 78 +++++++++++++++++ .../include/aidl/android/aidl/tests/ITestService.h | 38 +++++++++ .../gen/android/aidl/tests/ITestService.rs | 78 +++++++++++++++++ 8 files changed, 386 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/android/aidl/tests/ITestService.aidl b/tests/android/aidl/tests/ITestService.aidl index 91b6e5b7..1f2e6c3b 100644 --- a/tests/android/aidl/tests/ITestService.aidl +++ b/tests/android/aidl/tests/ITestService.aidl @@ -31,7 +31,7 @@ import android.aidl.tests.extension.ExtendableParcelable; /** * interface comment */ -@SuppressWarnings(value={"inout-parameter", "mixed-oneway", "out-array"}) +@SuppressWarnings(value={"inout-parameter", "mixed-oneway", "out-array", "interface-name"}) @SensitiveData @JavaDefault @JavaDelegator @@ -293,5 +293,8 @@ interface ITestService { @nullable Empty[] nullable_parcel_array; List parcel_list; @nullable List nullable_parcel_list; + + // interface without I- + interface Foo {} } } diff --git a/tests/golden_output/aidl-test-interface-cpp-source/gen/android/aidl/tests/ITestService.cpp b/tests/golden_output/aidl-test-interface-cpp-source/gen/android/aidl/tests/ITestService.cpp index 7e7aa09b..7e524331 100644 --- a/tests/golden_output/aidl-test-interface-cpp-source/gen/android/aidl/tests/ITestService.cpp +++ b/tests/golden_output/aidl-test-interface-cpp-source/gen/android/aidl/tests/ITestService.cpp @@ -5220,3 +5220,59 @@ namespace tests { } // namespace tests } // namespace aidl } // namespace android +#include +#include +namespace android { +namespace aidl { +namespace tests { +DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_NESTED_INTERFACE(ITestService::CompilerChecks, Foo, "android.aidl.tests.ITestService.CompilerChecks.Foo") +} // namespace tests +} // namespace aidl +} // namespace android +#include +#include +#include +#include + +namespace android { +namespace aidl { +namespace tests { + +ITestService::CompilerChecks::BpFoo::BpFoo(const ::android::sp<::android::IBinder>& _aidl_impl) + : BpInterface(_aidl_impl){ +} + +} // namespace tests +} // namespace aidl +} // namespace android +#include +#include +#include + +namespace android { +namespace aidl { +namespace tests { + +ITestService::CompilerChecks::BnFoo::BnFoo() +{ + ::android::internal::Stability::markCompilationUnit(this); +} + +::android::status_t ITestService::CompilerChecks::BnFoo::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) { + ::android::status_t _aidl_ret_status = ::android::OK; + switch (_aidl_code) { + default: + { + _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags); + } + break; + } + if (_aidl_ret_status == ::android::UNEXPECTED_NULL) { + _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeOverParcel(_aidl_reply); + } + return _aidl_ret_status; +} + +} // namespace tests +} // namespace aidl +} // namespace android diff --git a/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/BnTestService.h b/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/BnTestService.h index ab9eb8b2..9db2c7ec 100644 --- a/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/BnTestService.h +++ b/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/BnTestService.h @@ -6,6 +6,7 @@ #include #include #include +#include #include diff --git a/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/ITestService.h b/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/ITestService.h index 2555b286..ca85400d 100644 --- a/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/ITestService.h +++ b/tests/golden_output/aidl-test-interface-cpp-source/gen/include/android/aidl/tests/ITestService.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -72,6 +73,39 @@ public: }; // class Empty class CompilerChecks : public ::android::Parcelable { public: + class IFooDelegator; + + class IFoo : public ::android::IInterface { + public: + typedef IFooDelegator DefaultDelegator; + DECLARE_META_INTERFACE(Foo) + }; // class IFoo + + class IFooDefault : public IFoo { + public: + ::android::IBinder* onAsBinder() override { + return nullptr; + } + }; // class IFooDefault + class BpFoo : public ::android::BpInterface { + public: + explicit BpFoo(const ::android::sp<::android::IBinder>& _aidl_impl); + virtual ~BpFoo() = default; + }; // class BpFoo + class BnFoo : public ::android::BnInterface { + public: + explicit BnFoo(); + ::android::status_t onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) override; + }; // class BnFoo + + class IFooDelegator : public BnFoo { + public: + explicit IFooDelegator(const ::android::sp &impl) : _aidl_delegate(impl) {} + + ::android::sp getImpl() { return _aidl_delegate; } + private: + ::android::sp _aidl_delegate; + }; // class IFooDelegator ::android::sp<::android::IBinder> binder; ::android::sp<::android::IBinder> nullable_binder; ::std::vector<::android::sp<::android::IBinder>> binder_array; diff --git a/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/ITestService.java b/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/ITestService.java index 15a6989f..4ef380bb 100644 --- a/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/ITestService.java +++ b/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/ITestService.java @@ -3869,5 +3869,102 @@ public interface ITestService extends android.os.IInterface } return 0; } + // interface without I- + public interface Foo extends android.os.IInterface + { + /** Default implementation for Foo. */ + public static class Default implements android.aidl.tests.ITestService.CompilerChecks.Foo + { + @Override + public android.os.IBinder asBinder() { + return null; + } + } + /** Local-side IPC implementation stub class. */ + public static abstract class Stub extends android.os.Binder implements android.aidl.tests.ITestService.CompilerChecks.Foo + { + /** Construct the stub at attach it to the interface. */ + public Stub() + { + this.attachInterface(this, DESCRIPTOR); + } + /** + * Cast an IBinder object into an android.aidl.tests.ITestService.CompilerChecks.Foo interface, + * generating a proxy if needed. + */ + public static android.aidl.tests.ITestService.CompilerChecks.Foo asInterface(android.os.IBinder obj) + { + if ((obj==null)) { + return null; + } + android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR); + if (((iin!=null)&&(iin instanceof android.aidl.tests.ITestService.CompilerChecks.Foo))) { + return ((android.aidl.tests.ITestService.CompilerChecks.Foo)iin); + } + return new android.aidl.tests.ITestService.CompilerChecks.Foo.Stub.Proxy(obj); + } + @Override public android.os.IBinder asBinder() + { + return this; + } + /** @hide */ + public static java.lang.String getDefaultTransactionName(int transactionCode) + { + switch (transactionCode) + { + default: + { + return null; + } + } + } + /** @hide */ + public java.lang.String getTransactionName(int transactionCode) + { + return this.getDefaultTransactionName(transactionCode); + } + @Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException + { + java.lang.String descriptor = DESCRIPTOR; + switch (code) + { + case INTERFACE_TRANSACTION: + { + reply.writeString(descriptor); + return true; + } + } + switch (code) + { + default: + { + return super.onTransact(code, data, reply, flags); + } + } + } + private static class Proxy implements android.aidl.tests.ITestService.CompilerChecks.Foo + { + private android.os.IBinder mRemote; + Proxy(android.os.IBinder remote) + { + mRemote = remote; + } + @Override public android.os.IBinder asBinder() + { + return mRemote; + } + public java.lang.String getInterfaceDescriptor() + { + return DESCRIPTOR; + } + } + /** @hide */ + public int getMaxTransactionId() + { + return 0; + } + } + public static final java.lang.String DESCRIPTOR = "android$aidl$tests$ITestService$CompilerChecks$Foo".replace('$', '.'); + } } } diff --git a/tests/golden_output/aidl-test-interface-ndk-source/gen/android/aidl/tests/ITestService.cpp b/tests/golden_output/aidl-test-interface-ndk-source/gen/android/aidl/tests/ITestService.cpp index 1d67d109..89138f89 100644 --- a/tests/golden_output/aidl-test-interface-ndk-source/gen/android/aidl/tests/ITestService.cpp +++ b/tests/golden_output/aidl-test-interface-ndk-source/gen/android/aidl/tests/ITestService.cpp @@ -4793,3 +4793,81 @@ binder_status_t ITestService::CompilerChecks::writeToParcel(AParcel* _aidl_parce } // namespace aidl } // namespace android } // namespace aidl +namespace aidl { +namespace android { +namespace aidl { +namespace tests { +static binder_status_t _aidl_android_aidl_tests_ITestService_CompilerChecks_Foo_onTransact(AIBinder* _aidl_binder, transaction_code_t _aidl_code, const AParcel* _aidl_in, AParcel* _aidl_out) { + (void)_aidl_in; + (void)_aidl_out; + binder_status_t _aidl_ret_status = STATUS_UNKNOWN_TRANSACTION; + (void)_aidl_binder; + (void)_aidl_code; + return _aidl_ret_status; +} + +static AIBinder_Class* _g_aidl_android_aidl_tests_ITestService_CompilerChecks_Foo_clazz = ::ndk::ICInterface::defineClass(ITestService::CompilerChecks::IFoo::descriptor, _aidl_android_aidl_tests_ITestService_CompilerChecks_Foo_onTransact); + +ITestService::CompilerChecks::BpFoo::BpFoo(const ::ndk::SpAIBinder& binder) : BpCInterface(binder) {} +ITestService::CompilerChecks::BpFoo::~BpFoo() {} + +// Source for BnFoo +ITestService::CompilerChecks::BnFoo::BnFoo() {} +ITestService::CompilerChecks::BnFoo::~BnFoo() {} +::ndk::SpAIBinder ITestService::CompilerChecks::BnFoo::createBinder() { + AIBinder* binder = AIBinder_new(_g_aidl_android_aidl_tests_ITestService_CompilerChecks_Foo_clazz, static_cast(this)); + #ifdef BINDER_STABILITY_SUPPORT + AIBinder_markCompilationUnitStability(binder); + #endif // BINDER_STABILITY_SUPPORT + return ::ndk::SpAIBinder(binder); +} +// Source for IFoo +const char* ITestService::CompilerChecks::IFoo::descriptor = "android.aidl.tests.ITestService.CompilerChecks.Foo"; +ITestService::CompilerChecks::IFoo::IFoo() {} +ITestService::CompilerChecks::IFoo::~IFoo() {} + + +std::shared_ptr ITestService::CompilerChecks::IFoo::fromBinder(const ::ndk::SpAIBinder& binder) { + if (!AIBinder_associateClass(binder.get(), _g_aidl_android_aidl_tests_ITestService_CompilerChecks_Foo_clazz)) { return nullptr; } + std::shared_ptr<::ndk::ICInterface> interface = ::ndk::ICInterface::asInterface(binder.get()); + if (interface) { + return std::static_pointer_cast(interface); + } + return ::ndk::SharedRefBase::make(binder); +} + +binder_status_t ITestService::CompilerChecks::IFoo::writeToParcel(AParcel* parcel, const std::shared_ptr& instance) { + return AParcel_writeStrongBinder(parcel, instance ? instance->asBinder().get() : nullptr); +} +binder_status_t ITestService::CompilerChecks::IFoo::readFromParcel(const AParcel* parcel, std::shared_ptr* instance) { + ::ndk::SpAIBinder binder; + binder_status_t status = AParcel_readStrongBinder(parcel, binder.getR()); + if (status != STATUS_OK) return status; + *instance = IFoo::fromBinder(binder); + return STATUS_OK; +} +bool ITestService::CompilerChecks::IFoo::setDefaultImpl(const std::shared_ptr& impl) { + // Only one user of this interface can use this function + // at a time. This is a heuristic to detect if two different + // users in the same process use this function. + assert(!IFoo::default_impl); + if (impl) { + IFoo::default_impl = impl; + return true; + } + return false; +} +const std::shared_ptr& ITestService::CompilerChecks::IFoo::getDefaultImpl() { + return IFoo::default_impl; +} +std::shared_ptr ITestService::CompilerChecks::IFoo::default_impl = nullptr; +::ndk::SpAIBinder ITestService::CompilerChecks::IFooDefault::asBinder() { + return ::ndk::SpAIBinder(); +} +bool ITestService::CompilerChecks::IFooDefault::isRemote() { + return false; +} +} // namespace tests +} // namespace aidl +} // namespace android +} // namespace aidl diff --git a/tests/golden_output/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/ITestService.h b/tests/golden_output/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/ITestService.h index 708b8378..c307dbc2 100644 --- a/tests/golden_output/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/ITestService.h +++ b/tests/golden_output/aidl-test-interface-ndk-source/gen/include/aidl/android/aidl/tests/ITestService.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -80,6 +81,43 @@ public: typedef std::false_type fixed_size; static const char* descriptor; + class IFooDelegator; + + class IFoo : public ::ndk::ICInterface { + public: + typedef IFooDelegator DefaultDelegator; + static const char* descriptor; + IFoo(); + virtual ~IFoo(); + + + static std::shared_ptr fromBinder(const ::ndk::SpAIBinder& binder); + static binder_status_t writeToParcel(AParcel* parcel, const std::shared_ptr& instance); + static binder_status_t readFromParcel(const AParcel* parcel, std::shared_ptr* instance); + static bool setDefaultImpl(const std::shared_ptr& impl); + static const std::shared_ptr& getDefaultImpl(); + private: + static std::shared_ptr default_impl; + }; + class IFooDefault : public IFoo { + public: + ::ndk::SpAIBinder asBinder() override; + bool isRemote() override; + }; + class BpFoo : public ::ndk::BpCInterface { + public: + explicit BpFoo(const ::ndk::SpAIBinder& binder); + virtual ~BpFoo(); + + }; + class BnFoo : public ::ndk::BnCInterface { + public: + BnFoo(); + virtual ~BnFoo(); + protected: + ::ndk::SpAIBinder createBinder() override; + private: + }; ::ndk::SpAIBinder binder; ::ndk::SpAIBinder nullable_binder; std::vector<::ndk::SpAIBinder> binder_array; diff --git a/tests/golden_output/aidl-test-interface-rust-source/gen/android/aidl/tests/ITestService.rs b/tests/golden_output/aidl-test-interface-rust-source/gen/android/aidl/tests/ITestService.rs index 867d0950..b46835fd 100644 --- a/tests/golden_output/aidl-test-interface-rust-source/gen/android/aidl/tests/ITestService.rs +++ b/tests/golden_output/aidl-test-interface-rust-source/gen/android/aidl/tests/ITestService.rs @@ -4329,9 +4329,87 @@ pub mod r#CompilerChecks { impl binder::binder_impl::ParcelableMetadata for r#CompilerChecks { fn get_descriptor() -> &'static str { "android.aidl.tests.ITestService.CompilerChecks" } } + pub mod r#Foo { + #![allow(non_upper_case_globals)] + #![allow(non_snake_case)] + #[allow(unused_imports)] use binder::binder_impl::IBinderInternal; + use binder::declare_binder_interface; + declare_binder_interface! { + IFoo["android.aidl.tests.ITestService.CompilerChecks.Foo"] { + native: BnFoo(on_transact), + proxy: BpFoo { + }, + async: IFooAsync, + } + } + pub trait IFoo: binder::Interface + Send { + fn get_descriptor() -> &'static str where Self: Sized { "android.aidl.tests.ITestService.CompilerChecks.Foo" } + fn getDefaultImpl() -> IFooDefaultRef where Self: Sized { + DEFAULT_IMPL.lock().unwrap().clone() + } + fn setDefaultImpl(d: IFooDefaultRef) -> IFooDefaultRef where Self: Sized { + std::mem::replace(&mut *DEFAULT_IMPL.lock().unwrap(), d) + } + } + pub trait IFooAsync

: binder::Interface + Send { + fn get_descriptor() -> &'static str where Self: Sized { "android.aidl.tests.ITestService.CompilerChecks.Foo" } + } + #[::async_trait::async_trait] + pub trait IFooAsyncServer: binder::Interface + Send { + fn get_descriptor() -> &'static str where Self: Sized { "android.aidl.tests.ITestService.CompilerChecks.Foo" } + } + impl BnFoo { + /// Create a new async binder service. + pub fn new_async_binder(inner: T, rt: R, features: binder::BinderFeatures) -> binder::Strong + where + T: IFooAsyncServer + binder::Interface + Send + Sync + 'static, + R: binder::binder_impl::BinderAsyncRuntime + Send + Sync + 'static, + { + struct Wrapper { + _inner: T, + _rt: R, + } + impl binder::Interface for Wrapper where T: binder::Interface, R: Send + Sync { + fn as_binder(&self) -> binder::SpIBinder { self._inner.as_binder() } + fn dump(&self, _file: &std::fs::File, _args: &[&std::ffi::CStr]) -> std::result::Result<(), binder::StatusCode> { self._inner.dump(_file, _args) } + } + impl IFoo for Wrapper + where + T: IFooAsyncServer + Send + Sync + 'static, + R: binder::binder_impl::BinderAsyncRuntime + Send + Sync + 'static, + { + } + let wrapped = Wrapper { _inner: inner, _rt: rt }; + Self::new_binder(wrapped, features) + } + } + pub trait IFooDefault: Send + Sync { + } + pub mod transactions { + } + pub type IFooDefaultRef = Option>; + use lazy_static::lazy_static; + lazy_static! { + static ref DEFAULT_IMPL: std::sync::Mutex = std::sync::Mutex::new(None); + } + impl BpFoo { + } + impl IFoo for BpFoo { + } + impl IFooAsync

for BpFoo { + } + impl IFoo for binder::binder_impl::Binder { + } + fn on_transact(_aidl_service: &dyn IFoo, _aidl_code: binder::binder_impl::TransactionCode, _aidl_data: &binder::binder_impl::BorrowedParcel<'_>, _aidl_reply: &mut binder::binder_impl::BorrowedParcel<'_>) -> std::result::Result<(), binder::StatusCode> { + match _aidl_code { + _ => Err(binder::StatusCode::UNKNOWN_TRANSACTION) + } + } + } } pub(crate) mod mangled { pub use super::r#ITestService as _7_android_4_aidl_5_tests_12_ITestService; pub use super::r#Empty::r#Empty as _7_android_4_aidl_5_tests_12_ITestService_5_Empty; pub use super::r#CompilerChecks::r#CompilerChecks as _7_android_4_aidl_5_tests_12_ITestService_14_CompilerChecks; + pub use super::r#CompilerChecks::r#Foo::r#IFoo as _7_android_4_aidl_5_tests_12_ITestService_14_CompilerChecks_3_Foo; } -- cgit v1.2.3