From 4a5441fe4d60ce20f8de052d4439d4c549e300c4 Mon Sep 17 00:00:00 2001 From: Yu-Ting Tseng Date: Thu, 20 Jun 2024 13:33:55 -0700 Subject: Placeholder for binder freeze notification API. Adding the placeholder APIs to validate whether this breaks existing prebuilts. Bug: 338097747 Change-Id: Id7357076ad98c1f220a78186fe509326047cf922 Test: m --- libs/binder/Binder.cpp | 8 ++++++++ libs/binder/BpBinder.cpp | 8 ++++++++ libs/binder/include/binder/Binder.h | 7 +++++++ libs/binder/include/binder/BpBinder.h | 6 ++++++ libs/binder/include/binder/IBinder.h | 17 ++++++++++++++--- 5 files changed, 43 insertions(+), 3 deletions(-) (limited to 'libs') diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp index c57c9cdd62..6185b7baf8 100644 --- a/libs/binder/Binder.cpp +++ b/libs/binder/Binder.cpp @@ -441,6 +441,14 @@ status_t BBinder::unlinkToDeath( return INVALID_OPERATION; } +status_t BBinder::addFrozenStateChangeCallback(const wp&) { + return INVALID_OPERATION; +} + +status_t BBinder::removeFrozenStateChangeCallback(const wp&) { + return INVALID_OPERATION; +} + status_t BBinder::dump(int /*fd*/, const Vector& /*args*/) { return NO_ERROR; diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp index 6594aa6309..59c5be75ac 100644 --- a/libs/binder/BpBinder.cpp +++ b/libs/binder/BpBinder.cpp @@ -557,6 +557,14 @@ void BpBinder::sendObituary() } } +status_t BpBinder::addFrozenStateChangeCallback(const wp&) { + return INVALID_OPERATION; +} + +status_t BpBinder::removeFrozenStateChangeCallback(const wp&) { + return INVALID_OPERATION; +} + void BpBinder::reportOneDeath(const Obituary& obit) { sp recipient = obit.recipient.promote(); diff --git a/libs/binder/include/binder/Binder.h b/libs/binder/include/binder/Binder.h index 135be89c6c..802a3bcd06 100644 --- a/libs/binder/include/binder/Binder.h +++ b/libs/binder/include/binder/Binder.h @@ -50,6 +50,13 @@ public: void* cookie = nullptr, uint32_t flags = 0, wp* outRecipient = nullptr); + // Placeholders to test if adding virtual functions here breaks things. + // Will be replaced by an actual API once things are verified to work. + LIBBINDER_EXPORTED virtual status_t addFrozenStateChangeCallback( + const wp& callback); + LIBBINDER_EXPORTED virtual status_t removeFrozenStateChangeCallback( + const wp& callback); + LIBBINDER_EXPORTED virtual void* attachObject(const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) final; diff --git a/libs/binder/include/binder/BpBinder.h b/libs/binder/include/binder/BpBinder.h index d7f74c4152..0f52f6df52 100644 --- a/libs/binder/include/binder/BpBinder.h +++ b/libs/binder/include/binder/BpBinder.h @@ -66,6 +66,12 @@ public: void* cookie = nullptr, uint32_t flags = 0, wp* outRecipient = nullptr); + [[nodiscard]] virtual status_t addFrozenStateChangeCallback( + const wp& recipient); + + [[nodiscard]] virtual status_t removeFrozenStateChangeCallback( + const wp& recipient); + LIBBINDER_EXPORTED virtual void* attachObject(const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) final; diff --git a/libs/binder/include/binder/IBinder.h b/libs/binder/include/binder/IBinder.h index 17248ce289..62d7354387 100644 --- a/libs/binder/include/binder/IBinder.h +++ b/libs/binder/include/binder/IBinder.h @@ -198,9 +198,14 @@ public: virtual void binderDied(const wp& who) = 0; }; - #if defined(__clang__) - #pragma clang diagnostic pop - #endif + class FrozenStateChangeCallback : public virtual RefBase { + public: + virtual void onStateChanged(const wp& who, bool isFrozen) = 0; + }; + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif /** * Register the @a recipient for a notification if this binder @@ -249,6 +254,12 @@ public: uint32_t flags = 0, wp* outRecipient = nullptr) = 0; + // Placeholders. See Binder.h for details. + [[nodiscard]] virtual status_t addFrozenStateChangeCallback( + const wp& callback) = 0; + [[nodiscard]] virtual status_t removeFrozenStateChangeCallback( + const wp& callback) = 0; + virtual bool checkSubclass(const void* subclassID) const; typedef void (*object_cleanup_func)(const void* id, void* obj, void* cleanupCookie); -- cgit v1.2.3-59-g8ed1b