summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jooyung Han <jooyung@google.com> 2020-05-13 17:24:09 +0900
committer Jooyung Han <jooyung@google.com> 2020-05-19 22:59:49 +0000
commit01097e2410e75f1883f4e48af6a7889bd8cda052 (patch)
tree68556acf26c3904bdaa76e4adc302bc52aae283d
parent9b5bf0f42d57387a3451aa9eb9bfb1075fcb91a4 (diff)
setDefaultImpl aborts on a second call
The actual problem is that default implementation is set globally. setDefaultImpl might not work as expected when it is called twice with different instances. Because we don't have a proper solution for the problem, we prevent calling setDefaultImpl() twice by aborting. Exempt-From-Owner-Approval: approved Bug: 140139809 Test: ./runtests.sh (in /system/tools/aidl) Merged-In: I659d3eaad3a45dcba608fa79a08f083f84bc4d58 Change-Id: I659d3eaad3a45dcba608fa79a08f083f84bc4d58 (cherry picked from commit 81087399e99984db8049d1b319522536bac6f557)
-rw-r--r--libs/binder/include/binder/IInterface.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/libs/binder/include/binder/IInterface.h b/libs/binder/include/binder/IInterface.h
index 3a401adfa5..7116154951 100644
--- a/libs/binder/include/binder/IInterface.h
+++ b/libs/binder/include/binder/IInterface.h
@@ -20,6 +20,8 @@
#include <binder/Binder.h>
+#include <assert.h>
+
namespace android {
// ----------------------------------------------------------------------
@@ -155,7 +157,11 @@ public: \
std::unique_ptr<I##INTERFACE> I##INTERFACE::default_impl; \
bool I##INTERFACE::setDefaultImpl(std::unique_ptr<I##INTERFACE> impl)\
{ \
- if (!I##INTERFACE::default_impl && impl) { \
+ /* Only one user of this interface can use this function */ \
+ /* at a time. This is a heuristic to detect if two different */ \
+ /* users in the same process use this function. */ \
+ assert(!I##INTERFACE::default_impl); \
+ if (impl) { \
I##INTERFACE::default_impl = std::move(impl); \
return true; \
} \