OSDN Git Service

Fix order of hidl unlinkToDeath.
authorSteven Moreland <smoreland@google.com>
Tue, 24 Jul 2018 20:11:53 +0000 (13:11 -0700)
committerSteven Moreland <smoreland@google.com>
Tue, 24 Jul 2018 20:11:53 +0000 (13:11 -0700)
Calling unlinkToDeath after linking to death multiple
times will unregister the most recently registered
death recipient as expected.

Bug: 67503915
Test: hidl_test_java
Change-Id: Ia7774c3d1f8932660890716e0edb7a1180430de7

core/jni/android_os_HwRemoteBinder.cpp
core/jni/android_os_HwRemoteBinder.h

index ca5e1e4..f8f841c 100644 (file)
@@ -189,8 +189,7 @@ void HwBinderDeathRecipientList::add(const sp<HwBinderDeathRecipient>& recipient
 void HwBinderDeathRecipientList::remove(const sp<HwBinderDeathRecipient>& recipient) {
     AutoMutex _l(mLock);
 
-    List< sp<HwBinderDeathRecipient> >::iterator iter;
-    for (iter = mList.begin(); iter != mList.end(); iter++) {
+    for (auto iter = mList.begin(); iter != mList.end(); iter++) {
         if (*iter == recipient) {
             mList.erase(iter);
             return;
@@ -201,12 +200,13 @@ void HwBinderDeathRecipientList::remove(const sp<HwBinderDeathRecipient>& recipi
 sp<HwBinderDeathRecipient> HwBinderDeathRecipientList::find(jobject recipient) {
     AutoMutex _l(mLock);
 
-    for (const sp<HwBinderDeathRecipient>& deathRecipient : mList) {
-        if (deathRecipient->matches(recipient)) {
-            return deathRecipient;
+    for(auto iter = mList.rbegin(); iter != mList.rend(); iter++) {
+        if ((*iter)->matches(recipient)) {
+            return (*iter);
         }
     }
-    return NULL;
+
+    return nullptr;
 }
 
 Mutex& HwBinderDeathRecipientList::lock() {
index 63aad0a..4b5a4c8 100644 (file)
@@ -20,9 +20,9 @@
 #include <android-base/macros.h>
 #include <hwbinder/Binder.h>
 #include <jni.h>
-#include <utils/List.h>
 #include <utils/Mutex.h>
 #include <utils/RefBase.h>
+#include <vector>
 
 namespace android {
 
@@ -33,7 +33,7 @@ namespace android {
 class HwBinderDeathRecipient;
 
 class HwBinderDeathRecipientList : public RefBase {
-    List< sp<HwBinderDeathRecipient> > mList;
+    std::vector<sp<HwBinderDeathRecipient>> mList;
     Mutex mLock;
 
 public:
@@ -42,6 +42,8 @@ public:
 
     void add(const sp<HwBinderDeathRecipient>& recipient);
     void remove(const sp<HwBinderDeathRecipient>& recipient);
+
+    // finds the most recently added matching death recipient
     sp<HwBinderDeathRecipient> find(jobject recipient);
 
     Mutex& lock();  // Use with care; specifically for mutual exclusion during binder death