Loading Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -105,7 +105,13 @@ aidl_library { cc_library_headers { name: "libandroid_headers_private", host_supported: true, export_include_dirs: ["include/private"], target: { windows: { enabled: true, }, }, } filegroup { Loading include/android/choreographer.h +10 −0 Original line number Diff line number Diff line Loading @@ -48,9 +48,19 @@ #ifndef ANDROID_CHOREOGRAPHER_H #define ANDROID_CHOREOGRAPHER_H #include <stddef.h> #include <stdint.h> #include <sys/cdefs.h> // This file may also be built on glibc or on Windows/MacOS libc's, so no-op // and deprecated definitions are provided. #if !defined(__INTRODUCED_IN) #define __INTRODUCED_IN(__api_level) /* nothing */ #endif #if !defined(__DEPRECATED_IN) #define __DEPRECATED_IN(__api_level) __attribute__((__deprecated__)) #endif __BEGIN_DECLS struct AChoreographer; Loading libs/binder/ndk/ibinder.cpp +35 −3 Original line number Diff line number Diff line Loading @@ -258,11 +258,24 @@ status_t ABBinder::onTransact(transaction_code_t code, const Parcel& data, Parce } } void ABBinder::addDeathRecipient(const ::android::sp<AIBinder_DeathRecipient>& /* recipient */, void* /* cookie */) { LOG_ALWAYS_FATAL("Should not reach this. Can't linkToDeath local binders."); } ABpBinder::ABpBinder(const ::android::sp<::android::IBinder>& binder) : AIBinder(nullptr /*clazz*/), mRemote(binder) { LOG_ALWAYS_FATAL_IF(binder == nullptr, "binder == nullptr"); } ABpBinder::~ABpBinder() {} ABpBinder::~ABpBinder() { for (auto& recip : mDeathRecipients) { sp<AIBinder_DeathRecipient> strongRecip = recip.recipient.promote(); if (strongRecip) { strongRecip->pruneThisTransferEntry(getBinder(), recip.cookie); } } } sp<AIBinder> ABpBinder::lookupOrCreateFromBinder(const ::android::sp<::android::IBinder>& binder) { if (binder == nullptr) { Loading Loading @@ -301,6 +314,11 @@ sp<AIBinder> ABpBinder::lookupOrCreateFromBinder(const ::android::sp<::android:: return ret; } void ABpBinder::addDeathRecipient(const ::android::sp<AIBinder_DeathRecipient>& recipient, void* cookie) { mDeathRecipients.emplace_back(recipient, cookie); } struct AIBinder_Weak { wp<AIBinder> binder; }; Loading Loading @@ -426,6 +444,17 @@ AIBinder_DeathRecipient::AIBinder_DeathRecipient(AIBinder_DeathRecipient_onBinde LOG_ALWAYS_FATAL_IF(onDied == nullptr, "onDied == nullptr"); } void AIBinder_DeathRecipient::pruneThisTransferEntry(const sp<IBinder>& who, void* cookie) { std::lock_guard<std::mutex> l(mDeathRecipientsMutex); mDeathRecipients.erase(std::remove_if(mDeathRecipients.begin(), mDeathRecipients.end(), [&](const sp<TransferDeathRecipient>& tdr) { auto tdrWho = tdr->getWho(); return tdrWho != nullptr && tdrWho.promote() == who && cookie == tdr->getCookie(); }), mDeathRecipients.end()); } void AIBinder_DeathRecipient::pruneDeadTransferEntriesLocked() { mDeathRecipients.erase(std::remove_if(mDeathRecipients.begin(), mDeathRecipients.end(), [](const sp<TransferDeathRecipient>& tdr) { Loading Loading @@ -554,8 +583,11 @@ binder_status_t AIBinder_linkToDeath(AIBinder* binder, AIBinder_DeathRecipient* return STATUS_UNEXPECTED_NULL; } // returns binder_status_t return recipient->linkToDeath(binder->getBinder(), cookie); binder_status_t ret = recipient->linkToDeath(binder->getBinder(), cookie); if (ret == STATUS_OK) { binder->addDeathRecipient(recipient, cookie); } return ret; } binder_status_t AIBinder_unlinkToDeath(AIBinder* binder, AIBinder_DeathRecipient* recipient, Loading libs/binder/ndk/ibinder_internal.h +12 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,8 @@ struct AIBinder : public virtual ::android::RefBase { ::android::sp<::android::IBinder> binder = const_cast<AIBinder*>(this)->getBinder(); return binder->remoteBinder() != nullptr; } virtual void addDeathRecipient(const ::android::sp<AIBinder_DeathRecipient>& recipient, void* cookie) = 0; private: // AIBinder instance is instance of this class for a local object. In order to transact on a Loading Loading @@ -78,6 +80,8 @@ struct ABBinder : public AIBinder, public ::android::BBinder { ::android::status_t dump(int fd, const ::android::Vector<::android::String16>& args) override; ::android::status_t onTransact(uint32_t code, const ::android::Parcel& data, ::android::Parcel* reply, binder_flags_t flags) override; void addDeathRecipient(const ::android::sp<AIBinder_DeathRecipient>& /* recipient */, void* /* cookie */) override; private: ABBinder(const AIBinder_Class* clazz, void* userData); Loading Loading @@ -106,12 +110,19 @@ struct ABpBinder : public AIBinder { bool isServiceFuzzing() const { return mServiceFuzzing; } void setServiceFuzzing() { mServiceFuzzing = true; } void addDeathRecipient(const ::android::sp<AIBinder_DeathRecipient>& recipient, void* cookie) override; private: friend android::sp<ABpBinder>; explicit ABpBinder(const ::android::sp<::android::IBinder>& binder); ::android::sp<::android::IBinder> mRemote; bool mServiceFuzzing = false; struct DeathRecipientInfo { android::wp<AIBinder_DeathRecipient> recipient; void* cookie; }; std::vector<DeathRecipientInfo> mDeathRecipients; }; struct AIBinder_Class { Loading Loading @@ -183,6 +194,7 @@ struct AIBinder_DeathRecipient : ::android::RefBase { binder_status_t linkToDeath(const ::android::sp<::android::IBinder>&, void* cookie); binder_status_t unlinkToDeath(const ::android::sp<::android::IBinder>& binder, void* cookie); void setOnUnlinked(AIBinder_DeathRecipient_onBinderUnlinked onUnlinked); void pruneThisTransferEntry(const ::android::sp<::android::IBinder>&, void* cookie); private: // When the user of this API deletes a Bp object but not the death recipient, the Loading libs/binder/ndk/tests/iface.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ using ::android::wp; const char* IFoo::kSomeInstanceName = "libbinder_ndk-test-IFoo"; const char* IFoo::kInstanceNameToDieFor = "libbinder_ndk-test-IFoo-to-die"; const char* IFoo::kInstanceNameToDieFor2 = "libbinder_ndk-test-IFoo-to-die2"; const char* IFoo::kIFooDescriptor = "my-special-IFoo-class"; struct IFoo_Class_Data { Loading Loading
Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -105,7 +105,13 @@ aidl_library { cc_library_headers { name: "libandroid_headers_private", host_supported: true, export_include_dirs: ["include/private"], target: { windows: { enabled: true, }, }, } filegroup { Loading
include/android/choreographer.h +10 −0 Original line number Diff line number Diff line Loading @@ -48,9 +48,19 @@ #ifndef ANDROID_CHOREOGRAPHER_H #define ANDROID_CHOREOGRAPHER_H #include <stddef.h> #include <stdint.h> #include <sys/cdefs.h> // This file may also be built on glibc or on Windows/MacOS libc's, so no-op // and deprecated definitions are provided. #if !defined(__INTRODUCED_IN) #define __INTRODUCED_IN(__api_level) /* nothing */ #endif #if !defined(__DEPRECATED_IN) #define __DEPRECATED_IN(__api_level) __attribute__((__deprecated__)) #endif __BEGIN_DECLS struct AChoreographer; Loading
libs/binder/ndk/ibinder.cpp +35 −3 Original line number Diff line number Diff line Loading @@ -258,11 +258,24 @@ status_t ABBinder::onTransact(transaction_code_t code, const Parcel& data, Parce } } void ABBinder::addDeathRecipient(const ::android::sp<AIBinder_DeathRecipient>& /* recipient */, void* /* cookie */) { LOG_ALWAYS_FATAL("Should not reach this. Can't linkToDeath local binders."); } ABpBinder::ABpBinder(const ::android::sp<::android::IBinder>& binder) : AIBinder(nullptr /*clazz*/), mRemote(binder) { LOG_ALWAYS_FATAL_IF(binder == nullptr, "binder == nullptr"); } ABpBinder::~ABpBinder() {} ABpBinder::~ABpBinder() { for (auto& recip : mDeathRecipients) { sp<AIBinder_DeathRecipient> strongRecip = recip.recipient.promote(); if (strongRecip) { strongRecip->pruneThisTransferEntry(getBinder(), recip.cookie); } } } sp<AIBinder> ABpBinder::lookupOrCreateFromBinder(const ::android::sp<::android::IBinder>& binder) { if (binder == nullptr) { Loading Loading @@ -301,6 +314,11 @@ sp<AIBinder> ABpBinder::lookupOrCreateFromBinder(const ::android::sp<::android:: return ret; } void ABpBinder::addDeathRecipient(const ::android::sp<AIBinder_DeathRecipient>& recipient, void* cookie) { mDeathRecipients.emplace_back(recipient, cookie); } struct AIBinder_Weak { wp<AIBinder> binder; }; Loading Loading @@ -426,6 +444,17 @@ AIBinder_DeathRecipient::AIBinder_DeathRecipient(AIBinder_DeathRecipient_onBinde LOG_ALWAYS_FATAL_IF(onDied == nullptr, "onDied == nullptr"); } void AIBinder_DeathRecipient::pruneThisTransferEntry(const sp<IBinder>& who, void* cookie) { std::lock_guard<std::mutex> l(mDeathRecipientsMutex); mDeathRecipients.erase(std::remove_if(mDeathRecipients.begin(), mDeathRecipients.end(), [&](const sp<TransferDeathRecipient>& tdr) { auto tdrWho = tdr->getWho(); return tdrWho != nullptr && tdrWho.promote() == who && cookie == tdr->getCookie(); }), mDeathRecipients.end()); } void AIBinder_DeathRecipient::pruneDeadTransferEntriesLocked() { mDeathRecipients.erase(std::remove_if(mDeathRecipients.begin(), mDeathRecipients.end(), [](const sp<TransferDeathRecipient>& tdr) { Loading Loading @@ -554,8 +583,11 @@ binder_status_t AIBinder_linkToDeath(AIBinder* binder, AIBinder_DeathRecipient* return STATUS_UNEXPECTED_NULL; } // returns binder_status_t return recipient->linkToDeath(binder->getBinder(), cookie); binder_status_t ret = recipient->linkToDeath(binder->getBinder(), cookie); if (ret == STATUS_OK) { binder->addDeathRecipient(recipient, cookie); } return ret; } binder_status_t AIBinder_unlinkToDeath(AIBinder* binder, AIBinder_DeathRecipient* recipient, Loading
libs/binder/ndk/ibinder_internal.h +12 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,8 @@ struct AIBinder : public virtual ::android::RefBase { ::android::sp<::android::IBinder> binder = const_cast<AIBinder*>(this)->getBinder(); return binder->remoteBinder() != nullptr; } virtual void addDeathRecipient(const ::android::sp<AIBinder_DeathRecipient>& recipient, void* cookie) = 0; private: // AIBinder instance is instance of this class for a local object. In order to transact on a Loading Loading @@ -78,6 +80,8 @@ struct ABBinder : public AIBinder, public ::android::BBinder { ::android::status_t dump(int fd, const ::android::Vector<::android::String16>& args) override; ::android::status_t onTransact(uint32_t code, const ::android::Parcel& data, ::android::Parcel* reply, binder_flags_t flags) override; void addDeathRecipient(const ::android::sp<AIBinder_DeathRecipient>& /* recipient */, void* /* cookie */) override; private: ABBinder(const AIBinder_Class* clazz, void* userData); Loading Loading @@ -106,12 +110,19 @@ struct ABpBinder : public AIBinder { bool isServiceFuzzing() const { return mServiceFuzzing; } void setServiceFuzzing() { mServiceFuzzing = true; } void addDeathRecipient(const ::android::sp<AIBinder_DeathRecipient>& recipient, void* cookie) override; private: friend android::sp<ABpBinder>; explicit ABpBinder(const ::android::sp<::android::IBinder>& binder); ::android::sp<::android::IBinder> mRemote; bool mServiceFuzzing = false; struct DeathRecipientInfo { android::wp<AIBinder_DeathRecipient> recipient; void* cookie; }; std::vector<DeathRecipientInfo> mDeathRecipients; }; struct AIBinder_Class { Loading Loading @@ -183,6 +194,7 @@ struct AIBinder_DeathRecipient : ::android::RefBase { binder_status_t linkToDeath(const ::android::sp<::android::IBinder>&, void* cookie); binder_status_t unlinkToDeath(const ::android::sp<::android::IBinder>& binder, void* cookie); void setOnUnlinked(AIBinder_DeathRecipient_onBinderUnlinked onUnlinked); void pruneThisTransferEntry(const ::android::sp<::android::IBinder>&, void* cookie); private: // When the user of this API deletes a Bp object but not the death recipient, the Loading
libs/binder/ndk/tests/iface.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ using ::android::wp; const char* IFoo::kSomeInstanceName = "libbinder_ndk-test-IFoo"; const char* IFoo::kInstanceNameToDieFor = "libbinder_ndk-test-IFoo-to-die"; const char* IFoo::kInstanceNameToDieFor2 = "libbinder_ndk-test-IFoo-to-die2"; const char* IFoo::kIFooDescriptor = "my-special-IFoo-class"; struct IFoo_Class_Data { Loading