Loading libs/binder/BpBinder.cpp +6 −3 Original line number Diff line number Diff line Loading @@ -194,10 +194,13 @@ bool BpBinder::isDescriptorCached() const { const String16& BpBinder::getInterfaceDescriptor() const { if (isDescriptorCached() == false) { Parcel send, reply; sp<BpBinder> thiz = const_cast<BpBinder*>(this); Parcel data; data.markForBinder(thiz); Parcel reply; // do the IPC without a lock held. status_t err = const_cast<BpBinder*>(this)->transact( INTERFACE_TRANSACTION, send, &reply); status_t err = thiz->transact(INTERFACE_TRANSACTION, data, &reply); if (err == NO_ERROR) { String16 res(reply.readString16()); Mutex::Autolock _l(mLock); Loading libs/binder/ndk/parcel_internal.h +8 −5 Original line number Diff line number Diff line Loading @@ -27,10 +27,13 @@ struct AParcel { const ::android::Parcel* get() const { return mParcel; } ::android::Parcel* get() { return mParcel; } explicit AParcel(const AIBinder* binder) : AParcel(binder, new ::android::Parcel, true /*owns*/) {} AParcel(const AIBinder* binder, ::android::Parcel* parcel, bool owns) : mBinder(binder), mParcel(parcel), mOwns(owns) {} explicit AParcel(AIBinder* binder) : AParcel(binder, new ::android::Parcel, true /*owns*/) {} AParcel(AIBinder* binder, ::android::Parcel* parcel, bool owns) : mBinder(binder), mParcel(parcel), mOwns(owns) { if (binder != nullptr) { parcel->markForBinder(binder->getBinder()); } } ~AParcel() { if (mOwns) { Loading @@ -38,7 +41,7 @@ struct AParcel { } } static const AParcel readOnly(const AIBinder* binder, const ::android::Parcel* parcel) { static const AParcel readOnly(AIBinder* binder, const ::android::Parcel* parcel) { return AParcel(binder, const_cast<::android::Parcel*>(parcel), false); } Loading libs/binder/tests/Android.bp +29 −3 Original line number Diff line number Diff line Loading @@ -104,6 +104,21 @@ cc_test { require_root: true, } aidl_interface { name: "binderRpcTestIface", host_supported: true, unstable: true, srcs: [ "IBinderRpcSession.aidl", "IBinderRpcTest.aidl", ], backend: { java: { enabled: false, }, }, } cc_test { name: "binderRpcTest", host_supported: true, Loading @@ -112,20 +127,26 @@ cc_test { enabled: false, }, }, defaults: ["binder_test_defaults"], defaults: [ "binder_test_defaults", "libbinder_ndk_host_user", ], srcs: [ "IBinderRpcSession.aidl", "IBinderRpcTest.aidl", "binderRpcTest.cpp", ], shared_libs: [ "libbinder", "libbinder_ndk", "libbase", "libutils", "libcutils", "liblog", ], static_libs: [ "binderRpcTestIface-cpp", "binderRpcTestIface-ndk_platform", ], test_suites: ["general-tests"], require_root: true, } Loading Loading @@ -216,6 +237,11 @@ aidl_interface { srcs: [ "IBinderStabilityTest.aidl", ], backend: { java: { enabled: false, }, }, } cc_test { Loading libs/binder/tests/binderRpcTest.cpp +33 −0 Original line number Diff line number Diff line Loading @@ -16,7 +16,10 @@ #include <BnBinderRpcSession.h> #include <BnBinderRpcTest.h> #include <aidl/IBinderRpcTest.h> #include <android-base/logging.h> #include <android/binder_auto_utils.h> #include <android/binder_libbinder.h> #include <binder/Binder.h> #include <binder/BpBinder.h> #include <binder/IServiceManager.h> Loading Loading @@ -383,6 +386,12 @@ TEST_P(BinderRpc, Ping) { EXPECT_EQ(OK, proc.rootBinder->pingBinder()); } TEST_P(BinderRpc, GetInterfaceDescriptor) { auto proc = createRpcTestSocketServerProcess(1); ASSERT_NE(proc.rootBinder, nullptr); EXPECT_EQ(IBinderRpcTest::descriptor, proc.rootBinder->getInterfaceDescriptor()); } TEST_P(BinderRpc, TransactionsMustBeMarkedRpc) { auto proc = createRpcTestSocketServerProcess(1); Parcel data; Loading Loading @@ -786,6 +795,30 @@ TEST_P(BinderRpc, Die) { } } TEST_P(BinderRpc, WorksWithLibbinderNdkPing) { auto proc = createRpcTestSocketServerProcess(1); ndk::SpAIBinder binder = ndk::SpAIBinder(AIBinder_fromPlatformBinder(proc.rootBinder)); ASSERT_NE(binder, nullptr); ASSERT_EQ(STATUS_OK, AIBinder_ping(binder.get())); } TEST_P(BinderRpc, WorksWithLibbinderNdkUserTransaction) { auto proc = createRpcTestSocketServerProcess(1); ndk::SpAIBinder binder = ndk::SpAIBinder(AIBinder_fromPlatformBinder(proc.rootBinder)); ASSERT_NE(binder, nullptr); auto ndkBinder = aidl::IBinderRpcTest::fromBinder(binder); ASSERT_NE(ndkBinder, nullptr); std::string out; ndk::ScopedAStatus status = ndkBinder->doubleString("aoeu", &out); ASSERT_TRUE(status.isOk()) << status.getDescription(); ASSERT_EQ("aoeuaoeu", out); } ssize_t countFds() { DIR* dir = opendir("/proc/self/fd/"); if (dir == nullptr) return -1; Loading Loading
libs/binder/BpBinder.cpp +6 −3 Original line number Diff line number Diff line Loading @@ -194,10 +194,13 @@ bool BpBinder::isDescriptorCached() const { const String16& BpBinder::getInterfaceDescriptor() const { if (isDescriptorCached() == false) { Parcel send, reply; sp<BpBinder> thiz = const_cast<BpBinder*>(this); Parcel data; data.markForBinder(thiz); Parcel reply; // do the IPC without a lock held. status_t err = const_cast<BpBinder*>(this)->transact( INTERFACE_TRANSACTION, send, &reply); status_t err = thiz->transact(INTERFACE_TRANSACTION, data, &reply); if (err == NO_ERROR) { String16 res(reply.readString16()); Mutex::Autolock _l(mLock); Loading
libs/binder/ndk/parcel_internal.h +8 −5 Original line number Diff line number Diff line Loading @@ -27,10 +27,13 @@ struct AParcel { const ::android::Parcel* get() const { return mParcel; } ::android::Parcel* get() { return mParcel; } explicit AParcel(const AIBinder* binder) : AParcel(binder, new ::android::Parcel, true /*owns*/) {} AParcel(const AIBinder* binder, ::android::Parcel* parcel, bool owns) : mBinder(binder), mParcel(parcel), mOwns(owns) {} explicit AParcel(AIBinder* binder) : AParcel(binder, new ::android::Parcel, true /*owns*/) {} AParcel(AIBinder* binder, ::android::Parcel* parcel, bool owns) : mBinder(binder), mParcel(parcel), mOwns(owns) { if (binder != nullptr) { parcel->markForBinder(binder->getBinder()); } } ~AParcel() { if (mOwns) { Loading @@ -38,7 +41,7 @@ struct AParcel { } } static const AParcel readOnly(const AIBinder* binder, const ::android::Parcel* parcel) { static const AParcel readOnly(AIBinder* binder, const ::android::Parcel* parcel) { return AParcel(binder, const_cast<::android::Parcel*>(parcel), false); } Loading
libs/binder/tests/Android.bp +29 −3 Original line number Diff line number Diff line Loading @@ -104,6 +104,21 @@ cc_test { require_root: true, } aidl_interface { name: "binderRpcTestIface", host_supported: true, unstable: true, srcs: [ "IBinderRpcSession.aidl", "IBinderRpcTest.aidl", ], backend: { java: { enabled: false, }, }, } cc_test { name: "binderRpcTest", host_supported: true, Loading @@ -112,20 +127,26 @@ cc_test { enabled: false, }, }, defaults: ["binder_test_defaults"], defaults: [ "binder_test_defaults", "libbinder_ndk_host_user", ], srcs: [ "IBinderRpcSession.aidl", "IBinderRpcTest.aidl", "binderRpcTest.cpp", ], shared_libs: [ "libbinder", "libbinder_ndk", "libbase", "libutils", "libcutils", "liblog", ], static_libs: [ "binderRpcTestIface-cpp", "binderRpcTestIface-ndk_platform", ], test_suites: ["general-tests"], require_root: true, } Loading Loading @@ -216,6 +237,11 @@ aidl_interface { srcs: [ "IBinderStabilityTest.aidl", ], backend: { java: { enabled: false, }, }, } cc_test { Loading
libs/binder/tests/binderRpcTest.cpp +33 −0 Original line number Diff line number Diff line Loading @@ -16,7 +16,10 @@ #include <BnBinderRpcSession.h> #include <BnBinderRpcTest.h> #include <aidl/IBinderRpcTest.h> #include <android-base/logging.h> #include <android/binder_auto_utils.h> #include <android/binder_libbinder.h> #include <binder/Binder.h> #include <binder/BpBinder.h> #include <binder/IServiceManager.h> Loading Loading @@ -383,6 +386,12 @@ TEST_P(BinderRpc, Ping) { EXPECT_EQ(OK, proc.rootBinder->pingBinder()); } TEST_P(BinderRpc, GetInterfaceDescriptor) { auto proc = createRpcTestSocketServerProcess(1); ASSERT_NE(proc.rootBinder, nullptr); EXPECT_EQ(IBinderRpcTest::descriptor, proc.rootBinder->getInterfaceDescriptor()); } TEST_P(BinderRpc, TransactionsMustBeMarkedRpc) { auto proc = createRpcTestSocketServerProcess(1); Parcel data; Loading Loading @@ -786,6 +795,30 @@ TEST_P(BinderRpc, Die) { } } TEST_P(BinderRpc, WorksWithLibbinderNdkPing) { auto proc = createRpcTestSocketServerProcess(1); ndk::SpAIBinder binder = ndk::SpAIBinder(AIBinder_fromPlatformBinder(proc.rootBinder)); ASSERT_NE(binder, nullptr); ASSERT_EQ(STATUS_OK, AIBinder_ping(binder.get())); } TEST_P(BinderRpc, WorksWithLibbinderNdkUserTransaction) { auto proc = createRpcTestSocketServerProcess(1); ndk::SpAIBinder binder = ndk::SpAIBinder(AIBinder_fromPlatformBinder(proc.rootBinder)); ASSERT_NE(binder, nullptr); auto ndkBinder = aidl::IBinderRpcTest::fromBinder(binder); ASSERT_NE(ndkBinder, nullptr); std::string out; ndk::ScopedAStatus status = ndkBinder->doubleString("aoeu", &out); ASSERT_TRUE(status.isOk()) << status.getDescription(); ASSERT_EQ("aoeuaoeu", out); } ssize_t countFds() { DIR* dir = opendir("/proc/self/fd/"); if (dir == nullptr) return -1; Loading