Merge "Placeholder for binder freeze notification API." into main am: 370f3da668

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3142056

Change-Id: Ia5589d409e80ed38c89652f6cc5b6c600ec3c019
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp
index c57c9cd..6185b7b 100644
--- a/libs/binder/Binder.cpp
+++ b/libs/binder/Binder.cpp
@@ -441,6 +441,14 @@
     return INVALID_OPERATION;
 }
 
+status_t BBinder::addFrozenStateChangeCallback(const wp<FrozenStateChangeCallback>&) {
+    return INVALID_OPERATION;
+}
+
+status_t BBinder::removeFrozenStateChangeCallback(const wp<FrozenStateChangeCallback>&) {
+    return INVALID_OPERATION;
+}
+
 status_t BBinder::dump(int /*fd*/, const Vector<String16>& /*args*/)
 {
     return NO_ERROR;
diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp
index 6594aa6..59c5be7 100644
--- a/libs/binder/BpBinder.cpp
+++ b/libs/binder/BpBinder.cpp
@@ -557,6 +557,14 @@
     }
 }
 
+status_t BpBinder::addFrozenStateChangeCallback(const wp<FrozenStateChangeCallback>&) {
+    return INVALID_OPERATION;
+}
+
+status_t BpBinder::removeFrozenStateChangeCallback(const wp<FrozenStateChangeCallback>&) {
+    return INVALID_OPERATION;
+}
+
 void BpBinder::reportOneDeath(const Obituary& obit)
 {
     sp<DeathRecipient> recipient = obit.recipient.promote();
diff --git a/libs/binder/include/binder/Binder.h b/libs/binder/include/binder/Binder.h
index 135be89..802a3bc 100644
--- a/libs/binder/include/binder/Binder.h
+++ b/libs/binder/include/binder/Binder.h
@@ -50,6 +50,13 @@
                                                       void* cookie = nullptr, uint32_t flags = 0,
                                                       wp<DeathRecipient>* 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<FrozenStateChangeCallback>& callback);
+    LIBBINDER_EXPORTED virtual status_t removeFrozenStateChangeCallback(
+            const wp<FrozenStateChangeCallback>& 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 d7f74c4..0f52f6d 100644
--- a/libs/binder/include/binder/BpBinder.h
+++ b/libs/binder/include/binder/BpBinder.h
@@ -66,6 +66,12 @@
                                                       void* cookie = nullptr, uint32_t flags = 0,
                                                       wp<DeathRecipient>* outRecipient = nullptr);
 
+    [[nodiscard]] virtual status_t addFrozenStateChangeCallback(
+            const wp<FrozenStateChangeCallback>& recipient);
+
+    [[nodiscard]] virtual status_t removeFrozenStateChangeCallback(
+            const wp<FrozenStateChangeCallback>& 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 17248ce..62d7354 100644
--- a/libs/binder/include/binder/IBinder.h
+++ b/libs/binder/include/binder/IBinder.h
@@ -198,9 +198,14 @@
         virtual void binderDied(const wp<IBinder>& who) = 0;
     };
 
-    #if defined(__clang__)
-    #pragma clang diagnostic pop
-    #endif
+    class FrozenStateChangeCallback : public virtual RefBase {
+    public:
+        virtual void onStateChanged(const wp<IBinder>& 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 @@
                                             uint32_t flags = 0,
                                             wp<DeathRecipient>* outRecipient = nullptr) = 0;
 
+    // Placeholders. See Binder.h for details.
+    [[nodiscard]] virtual status_t addFrozenStateChangeCallback(
+            const wp<FrozenStateChangeCallback>& callback) = 0;
+    [[nodiscard]] virtual status_t removeFrozenStateChangeCallback(
+            const wp<FrozenStateChangeCallback>& callback) = 0;
+
     virtual bool            checkSubclass(const void* subclassID) const;
 
     typedef void (*object_cleanup_func)(const void* id, void* obj, void* cleanupCookie);