libbinder use stronger refbase semantics
As a larger example of how to use
ANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION.
Bug: 184190315
Test: boot (relevant tests in TEST_MAPPING)
Change-Id: I88283543e1f63fd1010f9cd3f63baefec84e6a84
diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp
index 53b36ff..fdcf94a 100644
--- a/libs/binder/BpBinder.cpp
+++ b/libs/binder/BpBinder.cpp
@@ -107,8 +107,7 @@
// ---------------------------------------------------------------------------
-
-BpBinder* BpBinder::create(int32_t handle) {
+sp<BpBinder> BpBinder::create(int32_t handle) {
int32_t trackedUid = -1;
if (sCountByUidEnabled) {
trackedUid = IPCThreadState::self()->getCallingUid();
@@ -134,10 +133,10 @@
}
sTrackingMap[trackedUid]++;
}
- return new BpBinder(BinderHandle{handle}, trackedUid);
+ return sp<BpBinder>::make(BinderHandle{handle}, trackedUid);
}
-BpBinder* BpBinder::create(const sp<RpcConnection>& connection, const RpcAddress& address) {
+sp<BpBinder> BpBinder::create(const sp<RpcConnection>& connection, const RpcAddress& address) {
LOG_ALWAYS_FATAL_IF(connection == nullptr, "BpBinder::create null connection");
// These are not currently tracked, since there is no UID or other
@@ -145,7 +144,7 @@
// needed, connection objects keep track of all BpBinder objects on a
// per-connection basis.
- return new BpBinder(SocketHandle{connection, address});
+ return sp<BpBinder>::make(SocketHandle{connection, address});
}
BpBinder::BpBinder(Handle&& handle)
@@ -194,7 +193,7 @@
const String16& BpBinder::getInterfaceDescriptor() const
{
if (isDescriptorCached() == false) {
- sp<BpBinder> thiz = const_cast<BpBinder*>(this);
+ sp<BpBinder> thiz = sp<BpBinder>::fromExisting(const_cast<BpBinder*>(this));
Parcel data;
data.markForBinder(thiz);
@@ -226,7 +225,7 @@
status_t BpBinder::pingBinder()
{
Parcel data;
- data.markForBinder(this);
+ data.markForBinder(sp<BpBinder>::fromExisting(this));
Parcel reply;
return transact(PING_TRANSACTION, data, &reply);
}
@@ -403,7 +402,7 @@
ALOGV("Reporting death to recipient: %p\n", recipient.get());
if (recipient == nullptr) return;
- recipient->binderDied(this);
+ recipient->binderDied(wp<BpBinder>::fromExisting(this));
}