summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Steven Moreland <smoreland@google.com> 2020-09-30 18:28:07 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2020-09-30 18:28:07 +0000
commitbc0eef555d5d0235d814de91c197bbf46ee987de (patch)
tree060a7788593d59109887ab9f0bbe46c1e10cf9b9
parent165ecc000523f636f0a7f24eaf1a53a6f884c8ad (diff)
parent11c276ec69142d9868f6bd163982427809276e5f (diff)
Merge "Lock accesses to mClazz in AIBinder with a mutex" am: 11c276ec69
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1433074 Change-Id: I13b802a818ea930ba0b3ab7ccc0de41ba601d669
-rw-r--r--libs/binder/ndk/ibinder.cpp28
-rw-r--r--libs/binder/ndk/ibinder_internal.h5
2 files changed, 25 insertions, 8 deletions
diff --git a/libs/binder/ndk/ibinder.cpp b/libs/binder/ndk/ibinder.cpp
index 6995e77667..d7075b2ede 100644
--- a/libs/binder/ndk/ibinder.cpp
+++ b/libs/binder/ndk/ibinder.cpp
@@ -73,12 +73,11 @@ void clean(const void* id, void* obj, void* cookie) {
AIBinder::AIBinder(const AIBinder_Class* clazz) : mClazz(clazz) {}
AIBinder::~AIBinder() {}
-bool AIBinder::associateClass(const AIBinder_Class* clazz) {
- if (clazz == nullptr) return false;
+std::optional<bool> AIBinder::associateClassInternal(const AIBinder_Class* clazz,
+ const String8& newDescriptor, bool set) {
+ std::lock_guard<std::mutex> lock(mClazzMutex);
if (mClazz == clazz) return true;
- String8 newDescriptor(clazz->getInterfaceDescriptor());
-
if (mClazz != nullptr) {
String8 currentDescriptor(mClazz->getInterfaceDescriptor());
if (newDescriptor == currentDescriptor) {
@@ -97,6 +96,22 @@ bool AIBinder::associateClass(const AIBinder_Class* clazz) {
return false;
}
+ if (set) {
+ // if this is a local object, it's not one known to libbinder_ndk
+ mClazz = clazz;
+ }
+
+ return {};
+}
+
+bool AIBinder::associateClass(const AIBinder_Class* clazz) {
+ if (clazz == nullptr) return false;
+
+ String8 newDescriptor(clazz->getInterfaceDescriptor());
+
+ auto result = associateClassInternal(clazz, newDescriptor, false);
+ if (result.has_value()) return *result;
+
CHECK(asABpBinder() != nullptr); // ABBinder always has a descriptor
String8 descriptor(getBinder()->getInterfaceDescriptor());
@@ -112,10 +127,7 @@ bool AIBinder::associateClass(const AIBinder_Class* clazz) {
return false;
}
- // if this is a local object, it's not one known to libbinder_ndk
- mClazz = clazz;
-
- return true;
+ return associateClassInternal(clazz, newDescriptor, true).value_or(true);
}
ABBinder::ABBinder(const AIBinder_Class* clazz, void* userData)
diff --git a/libs/binder/ndk/ibinder_internal.h b/libs/binder/ndk/ibinder_internal.h
index 57794279f2..f4e2704882 100644
--- a/libs/binder/ndk/ibinder_internal.h
+++ b/libs/binder/ndk/ibinder_internal.h
@@ -22,6 +22,7 @@
#include <atomic>
#include <mutex>
+#include <optional>
#include <vector>
#include <binder/Binder.h>
@@ -52,10 +53,14 @@ struct AIBinder : public virtual ::android::RefBase {
}
private:
+ std::optional<bool> associateClassInternal(const AIBinder_Class* clazz,
+ const ::android::String8& newDescriptor, bool set);
+
// AIBinder instance is instance of this class for a local object. In order to transact on a
// remote object, this also must be set for simplicity (although right now, only the
// interfaceDescriptor from it is used).
const AIBinder_Class* mClazz;
+ std::mutex mClazzMutex;
};
// This is a local AIBinder object with a known class.