summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/binder/Android.bp7
-rw-r--r--libs/binder/Binder.cpp20
-rw-r--r--libs/binder/BpBinder.cpp43
-rw-r--r--libs/binder/BufferedTextOutput.cpp4
-rw-r--r--libs/binder/IAppOpsCallback.cpp2
-rw-r--r--libs/binder/IAppOpsService.cpp2
-rw-r--r--libs/binder/IBatteryStats.cpp2
-rw-r--r--libs/binder/IPCThreadState.cpp41
-rw-r--r--libs/binder/IPermissionController.cpp2
-rw-r--r--libs/binder/IResultReceiver.cpp2
-rw-r--r--libs/binder/IServiceManager.cpp80
-rw-r--r--libs/binder/IShellCallback.cpp2
-rw-r--r--libs/binder/Parcel.cpp159
-rw-r--r--libs/binder/ParcelValTypes.h (renamed from libs/binder/include/private/binder/ParcelValTypes.h)0
-rw-r--r--libs/binder/PersistableBundle.cpp3
-rw-r--r--libs/binder/ProcessState.cpp99
-rw-r--r--libs/binder/Static.cpp11
-rw-r--r--libs/binder/Static.h (renamed from libs/binder/include/private/binder/Static.h)12
-rw-r--r--libs/binder/TEST_MAPPING16
-rw-r--r--libs/binder/Value.cpp420
-rw-r--r--libs/binder/aidl/android/os/IServiceManager.aidl80
-rw-r--r--libs/binder/include/binder/BpBinder.h3
-rw-r--r--libs/binder/include/binder/IPCThreadState.h2
-rw-r--r--libs/binder/include/binder/Map.h39
-rw-r--r--libs/binder/include/binder/Parcel.h35
-rw-r--r--libs/binder/include/binder/ProcessState.h14
-rw-r--r--libs/binder/include/binder/Value.h186
-rw-r--r--libs/binder/ndk/Android.bp10
-rw-r--r--libs/binder/ndk/libbinder_ndk.map.txt12
-rw-r--r--libs/binder/tests/Android.bp36
-rw-r--r--libs/binder/tests/binderDriverInterfaceTest.cpp1
-rw-r--r--libs/binder/tests/binderLibTest.cpp59
-rw-r--r--libs/binder/tests/binderSafeInterfaceTest.cpp3
-rw-r--r--libs/binder/tests/binderValueTypeTest.cpp110
-rw-r--r--libs/binder/tests/schd-dbg.cpp1
-rw-r--r--libs/dumputils/Android.bp1
-rw-r--r--libs/gui/ISurfaceComposer.cpp4
-rw-r--r--libs/gui/LayerState.cpp4
-rw-r--r--libs/sensorprivacy/Android.bp12
-rw-r--r--libs/ui/Android.bp1
-rw-r--r--libs/vr/libbufferhubqueue/Android.bp2
41 files changed, 290 insertions, 1252 deletions
diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp
index aedf6b0d18..b23094396c 100644
--- a/libs/binder/Android.bp
+++ b/libs/binder/Android.bp
@@ -73,7 +73,6 @@ cc_library_shared {
"Status.cpp",
"TextOutput.cpp",
"IpPrefix.cpp",
- "Value.cpp",
":libbinder_aidl",
],
@@ -94,7 +93,6 @@ cc_library_shared {
"PermissionController.cpp",
"ProcessInfoService.cpp",
"IpPrefix.cpp",
- ":libbinder_aidl",
],
},
},
@@ -116,7 +114,6 @@ cc_library_shared {
},
shared_libs: [
- "libbase",
"liblog",
"libcutils",
"libutils",
@@ -142,7 +139,7 @@ filegroup {
name: "libbinder_aidl",
srcs: [
"aidl/android/content/pm/IPackageManagerNative.aidl",
+ "aidl/android/os/IServiceManager.aidl",
],
+ path: "aidl",
}
-
-subdirs = ["tests"]
diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp
index cb0e08d123..c1d916c62b 100644
--- a/libs/binder/Binder.cpp
+++ b/libs/binder/Binder.cpp
@@ -17,12 +17,15 @@
#include <binder/Binder.h>
#include <atomic>
-#include <utils/misc.h>
#include <binder/BpBinder.h>
#include <binder/IInterface.h>
+#include <binder/IPCThreadState.h>
#include <binder/IResultReceiver.h>
#include <binder/IShellCallback.h>
#include <binder/Parcel.h>
+#include <cutils/android_filesystem_config.h>
+#include <cutils/compiler.h>
+#include <utils/misc.h>
#include <stdio.h>
@@ -125,10 +128,23 @@ status_t BBinder::transact(
{
data.setDataPosition(0);
+ // Shell command transaction is conventionally implemented by
+ // overriding onTransact by copy/pasting the parceling code from
+ // this file. So, we must check permissions for it before we call
+ // onTransact. This check is here because shell APIs aren't
+ // guaranteed to be stable, and so they should only be used by
+ // developers.
+ if (CC_UNLIKELY(code == SHELL_COMMAND_TRANSACTION)) {
+ uid_t uid = IPCThreadState::self()->getCallingUid();
+ if (uid != AID_SHELL && uid != AID_ROOT) {
+ return PERMISSION_DENIED;
+ }
+ }
+
status_t err = NO_ERROR;
switch (code) {
case PING_TRANSACTION:
- reply->writeInt32(pingBinder());
+ err = pingBinder();
break;
default:
err = onTransact(code, data, reply, flags);
diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp
index ec170f7a65..5ceb218b8b 100644
--- a/libs/binder/BpBinder.cpp
+++ b/libs/binder/BpBinder.cpp
@@ -148,6 +148,10 @@ BpBinder::BpBinder(int32_t handle, int32_t trackedUid)
IPCThreadState::self()->incWeakHandle(handle, this);
}
+int32_t BpBinder::handle() const {
+ return mHandle;
+}
+
bool BpBinder::isDescriptorCached() const {
Mutex::Autolock _l(mLock);
return mDescriptorCache.size() ? true : false;
@@ -186,10 +190,7 @@ status_t BpBinder::pingBinder()
{
Parcel send;
Parcel reply;
- status_t err = transact(PING_TRANSACTION, send, &reply);
- if (err != NO_ERROR) return err;
- if (reply.dataSize() < sizeof(status_t)) return NOT_ENOUGH_DATA;
- return (status_t)reply.readInt32();
+ return transact(PING_TRANSACTION, send, &reply);
}
status_t BpBinder::dump(int fd, const Vector<String16>& args)
@@ -387,21 +388,6 @@ BpBinder::~BpBinder()
}
}
- mLock.lock();
- Vector<Obituary>* obits = mObituaries;
- if(obits != nullptr) {
- if (ipc) ipc->clearDeathNotification(mHandle, this);
- mObituaries = nullptr;
- }
- mLock.unlock();
-
- if (obits != nullptr) {
- // XXX Should we tell any remaining DeathRecipient
- // objects that the last strong ref has gone away, so they
- // are no longer linked?
- delete obits;
- }
-
if (ipc) {
ipc->expungeHandle(mHandle, this);
ipc->decWeakHandle(mHandle);
@@ -423,6 +409,25 @@ void BpBinder::onLastStrongRef(const void* /*id*/)
}
IPCThreadState* ipc = IPCThreadState::self();
if (ipc) ipc->decStrongHandle(mHandle);
+
+ mLock.lock();
+ Vector<Obituary>* obits = mObituaries;
+ if(obits != nullptr) {
+ if (!obits->isEmpty()) {
+ ALOGI("onLastStrongRef automatically unlinking death recipients");
+ }
+
+ if (ipc) ipc->clearDeathNotification(mHandle, this);
+ mObituaries = nullptr;
+ }
+ mLock.unlock();
+
+ if (obits != nullptr) {
+ // XXX Should we tell any remaining DeathRecipient
+ // objects that the last strong ref has gone away, so they
+ // are no longer linked?
+ delete obits;
+ }
}
bool BpBinder::onIncStrongAttempted(uint32_t /*flags*/, const void* /*id*/)
diff --git a/libs/binder/BufferedTextOutput.cpp b/libs/binder/BufferedTextOutput.cpp
index 857bbf9510..a7d52409f6 100644
--- a/libs/binder/BufferedTextOutput.cpp
+++ b/libs/binder/BufferedTextOutput.cpp
@@ -23,12 +23,12 @@
#include <utils/RefBase.h>
#include <utils/Vector.h>
-#include <private/binder/Static.h>
-
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
+#include "Static.h"
+
// ---------------------------------------------------------------------------
namespace android {
diff --git a/libs/binder/IAppOpsCallback.cpp b/libs/binder/IAppOpsCallback.cpp
index aba49673b1..4c151e7a65 100644
--- a/libs/binder/IAppOpsCallback.cpp
+++ b/libs/binder/IAppOpsCallback.cpp
@@ -22,8 +22,6 @@
#include <binder/Parcel.h>
#include <utils/String8.h>
-#include <private/binder/Static.h>
-
namespace android {
// ----------------------------------------------------------------------
diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp
index 66d6e31902..c426f3a31f 100644
--- a/libs/binder/IAppOpsService.cpp
+++ b/libs/binder/IAppOpsService.cpp
@@ -22,8 +22,6 @@
#include <binder/Parcel.h>
#include <utils/String8.h>
-#include <private/binder/Static.h>
-
namespace android {
// ----------------------------------------------------------------------
diff --git a/libs/binder/IBatteryStats.cpp b/libs/binder/IBatteryStats.cpp
index b307e3e7b5..cc0022a875 100644
--- a/libs/binder/IBatteryStats.cpp
+++ b/libs/binder/IBatteryStats.cpp
@@ -20,8 +20,6 @@
#include <binder/Parcel.h>
#include <utils/String8.h>
-#include <private/binder/Static.h>
-
namespace android {
// ----------------------------------------------------------------------
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp
index 9a561cba64..cfb86f021c 100644
--- a/libs/binder/IPCThreadState.cpp
+++ b/libs/binder/IPCThreadState.cpp
@@ -31,8 +31,8 @@
#include <utils/threads.h>
#include <private/binder/binder_module.h>
-#include <private/binder/Static.h>
+#include <atomic>
#include <errno.h>
#include <inttypes.h>
#include <pthread.h>
@@ -43,6 +43,8 @@
#include <sys/resource.h>
#include <unistd.h>
+#include "Static.h"
+
#if LOG_NDEBUG
#define IF_LOG_TRANSACTIONS() if (false)
@@ -116,7 +118,7 @@ static const int64_t kWorkSourcePropagatedBitIndex = 32;
static const char* getReturnString(uint32_t cmd)
{
- size_t idx = cmd & 0xff;
+ size_t idx = cmd & _IOC_NRMASK;
if (idx < sizeof(kReturnStrings) / sizeof(kReturnStrings[0]))
return kReturnStrings[idx];
else
@@ -278,14 +280,14 @@ static const void* printCommand(TextOutput& out, const void* _cmd)
}
static pthread_mutex_t gTLSMutex = PTHREAD_MUTEX_INITIALIZER;
-static bool gHaveTLS = false;
+static std::atomic<bool> gHaveTLS(false);
static pthread_key_t gTLS = 0;
-static bool gShutdown = false;
-static bool gDisableBackgroundScheduling = false;
+static std::atomic<bool> gShutdown = false;
+static std::atomic<bool> gDisableBackgroundScheduling = false;
IPCThreadState* IPCThreadState::self()
{
- if (gHaveTLS) {
+ if (gHaveTLS.load(std::memory_order_acquire)) {
restart:
const pthread_key_t k = gTLS;
IPCThreadState* st = (IPCThreadState*)pthread_getspecific(k);
@@ -293,13 +295,14 @@ restart:
return new IPCThreadState;
}
- if (gShutdown) {
+ // Racey, heuristic test for simultaneous shutdown.
+ if (gShutdown.load(std::memory_order_relaxed)) {
ALOGW("Calling IPCThreadState::self() during shutdown is dangerous, expect a crash.\n");
return nullptr;
}
pthread_mutex_lock(&gTLSMutex);
- if (!gHaveTLS) {
+ if (!gHaveTLS.load(std::memory_order_relaxed)) {
int key_create_value = pthread_key_create(&gTLS, threadDestructor);
if (key_create_value != 0) {
pthread_mutex_unlock(&gTLSMutex);
@@ -307,7 +310,7 @@ restart:
strerror(key_create_value));
return nullptr;
}
- gHaveTLS = true;
+ gHaveTLS.store(true, std::memory_order_release);
}
pthread_mutex_unlock(&gTLSMutex);
goto restart;
@@ -315,7 +318,7 @@ restart:
IPCThreadState* IPCThreadState::selfOrNull()
{
- if (gHaveTLS) {
+ if (gHaveTLS.load(std::memory_order_acquire)) {
const pthread_key_t k = gTLS;
IPCThreadState* st = (IPCThreadState*)pthread_getspecific(k);
return st;
@@ -325,9 +328,9 @@ IPCThreadState* IPCThreadState::selfOrNull()
void IPCThreadState::shutdown()
{
- gShutdown = true;
+ gShutdown.store(true, std::memory_order_relaxed);
- if (gHaveTLS) {
+ if (gHaveTLS.load(std::memory_order_acquire)) {
// XXX Need to wait for all thread pool threads to exit!
IPCThreadState* st = (IPCThreadState*)pthread_getspecific(gTLS);
if (st) {
@@ -335,18 +338,18 @@ void IPCThreadState::shutdown()
pthread_setspecific(gTLS, nullptr);
}
pthread_key_delete(gTLS);
- gHaveTLS = false;
+ gHaveTLS.store(false, std::memory_order_release);
}
}
void IPCThreadState::disableBackgroundScheduling(bool disable)
{
- gDisableBackgroundScheduling = disable;
+ gDisableBackgroundScheduling.store(disable, std::memory_order_relaxed);
}
bool IPCThreadState::backgroundSchedulingDisabled()
{
- return gDisableBackgroundScheduling;
+ return gDisableBackgroundScheduling.load(std::memory_order_relaxed);
}
sp<ProcessState> IPCThreadState::process()
@@ -674,11 +677,11 @@ status_t IPCThreadState::transact(int32_t handle,
if ((flags & TF_ONE_WAY) == 0) {
if (UNLIKELY(mCallRestriction != ProcessState::CallRestriction::NONE)) {
if (mCallRestriction == ProcessState::CallRestriction::ERROR_IF_NOT_ONEWAY) {
- ALOGE("Process making non-oneway call but is restricted.");
+ ALOGE("Process making non-oneway call (code: %u) but is restricted.", code);
CallStack::logStack("non-oneway call", CallStack::getCurrent(10).get(),
ANDROID_LOG_ERROR);
} else /* FATAL_IF_NOT_ONEWAY */ {
- LOG_ALWAYS_FATAL("Process may not make oneway calls.");
+ LOG_ALWAYS_FATAL("Process may not make oneway calls (code: %u).", code);
}
}
@@ -996,7 +999,7 @@ status_t IPCThreadState::talkWithDriver(bool doReceive)
if (err >= NO_ERROR) {
if (bwr.write_consumed > 0) {
if (bwr.write_consumed < mOut.dataSize())
- mOut.remove(0, bwr.write_consumed);
+ LOG_ALWAYS_FATAL("Driver did not consume write buffer");
else {
mOut.setDataSize(0);
processPostWriteDerefs();
@@ -1060,7 +1063,7 @@ status_t IPCThreadState::writeTransactionData(int32_t cmd, uint32_t binderFlags,
sp<BBinder> the_context_object;
-void setTheContextObject(sp<BBinder> obj)
+void IPCThreadState::setTheContextObject(sp<BBinder> obj)
{
the_context_object = obj;
}
diff --git a/libs/binder/IPermissionController.cpp b/libs/binder/IPermissionController.cpp
index 6b99150edf..bf2f20aa0b 100644
--- a/libs/binder/IPermissionController.cpp
+++ b/libs/binder/IPermissionController.cpp
@@ -22,8 +22,6 @@
#include <binder/Parcel.h>
#include <utils/String8.h>
-#include <private/binder/Static.h>
-
namespace android {
// ----------------------------------------------------------------------
diff --git a/libs/binder/IResultReceiver.cpp b/libs/binder/IResultReceiver.cpp
index 159763d5bf..1e11941023 100644
--- a/libs/binder/IResultReceiver.cpp
+++ b/libs/binder/IResultReceiver.cpp
@@ -22,8 +22,6 @@
#include <binder/Parcel.h>
#include <utils/String8.h>
-#include <private/binder/Static.h>
-
namespace android {
// ----------------------------------------------------------------------
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp
index 4ba6c2a923..74f1f47c7a 100644
--- a/libs/binder/IServiceManager.cpp
+++ b/libs/binder/IServiceManager.cpp
@@ -18,6 +18,7 @@
#include <binder/IServiceManager.h>
+#include <android/os/IServiceManager.h>
#include <utils/Log.h>
#include <binder/IPCThreadState.h>
#ifndef __ANDROID_VNDK__
@@ -28,14 +29,20 @@
#include <utils/String8.h>
#include <utils/SystemClock.h>
-#include <private/binder/Static.h>
+#include "Static.h"
#include <unistd.h>
namespace android {
+using AidlServiceManager = android::os::IServiceManager;
+using android::binder::Status;
+
sp<IServiceManager> defaultServiceManager()
{
+ static Mutex gDefaultServiceManagerLock;
+ static sp<IServiceManager> gDefaultServiceManager;
+
if (gDefaultServiceManager != nullptr) return gDefaultServiceManager;
{
@@ -74,10 +81,13 @@ bool checkCallingPermission(const String16& permission, int32_t* outPid, int32_t
bool checkPermission(const String16& permission, pid_t pid, uid_t uid)
{
+ static Mutex gPermissionControllerLock;
+ static sp<IPermissionController> gPermissionController;
+
sp<IPermissionController> pc;
- gDefaultServiceManagerLock.lock();
+ gPermissionControllerLock.lock();
pc = gPermissionController;
- gDefaultServiceManagerLock.unlock();
+ gPermissionControllerLock.unlock();
int64_t startTime = 0;
@@ -101,11 +111,11 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid)
}
// Object is dead!
- gDefaultServiceManagerLock.lock();
+ gPermissionControllerLock.lock();
if (gPermissionController == pc) {
gPermissionController = nullptr;
}
- gDefaultServiceManagerLock.unlock();
+ gPermissionControllerLock.unlock();
}
// Need to retrieve the permission controller.
@@ -121,9 +131,9 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid)
} else {
pc = interface_cast<IPermissionController>(binder);
// Install the new permission controller, and try again.
- gDefaultServiceManagerLock.lock();
+ gPermissionControllerLock.lock();
gPermissionController = pc;
- gDefaultServiceManagerLock.unlock();
+ gPermissionControllerLock.unlock();
}
}
}
@@ -136,12 +146,15 @@ class BpServiceManager : public BpInterface<IServiceManager>
{
public:
explicit BpServiceManager(const sp<IBinder>& impl)
- : BpInterface<IServiceManager>(impl)
+ : BpInterface<IServiceManager>(impl),
+ mTheRealServiceManager(interface_cast<AidlServiceManager>(impl))
{
}
- virtual sp<IBinder> getService(const String16& name) const
+ sp<IBinder> getService(const String16& name) const override
{
+ static bool gSystemBootCompleted = false;
+
sp<IBinder> svc = checkService(name);
if (svc != nullptr) return svc;
@@ -171,43 +184,36 @@ public:
return nullptr;
}
- virtual sp<IBinder> checkService( const String16& name) const
- {
- Parcel data, reply;
- data.writeInterfaceToken(IServiceManager::getInterfaceDescriptor());
- data.writeString16(name);
- remote()->transact(CHECK_SERVICE_TRANSACTION, data, &reply);
- return reply.readStrongBinder();
+ sp<IBinder> checkService(const String16& name) const override {
+ sp<IBinder> ret;
+ if (!mTheRealServiceManager->checkService(String8(name).c_str(), &ret).isOk()) {
+ return nullptr;
+ }
+ return ret;
}
- virtual status_t addService(const String16& name, const sp<IBinder>& service,
- bool allowIsolated, int dumpsysPriority) {
- Parcel data, reply;
- data.writeInterfaceToken(IServiceManager::getInterfaceDescriptor());
- data.writeString16(name);
- data.writeStrongBinder(service);
- data.writeInt32(allowIsolated ? 1 : 0);
- data.writeInt32(dumpsysPriority);
- status_t err = remote()->transact(ADD_SERVICE_TRANSACTION, data, &reply);
- return err == NO_ERROR ? reply.readExceptionCode() : err;
+ status_t addService(const String16& name, const sp<IBinder>& service,
+ bool allowIsolated, int dumpsysPriority) override {
+ Status status = mTheRealServiceManager->addService(String8(name).c_str(), service, allowIsolated, dumpsysPriority);
+ return status.exceptionCode();
}
virtual Vector<String16> listServices(int dumpsysPriority) {
- Vector<String16> res;
- int n = 0;
+ std::vector<std::string> ret;
+ if (!mTheRealServiceManager->listServices(dumpsysPriority, &ret).isOk()) {
+ return {};
+ }
- for (;;) {
- Parcel data, reply;
- data.writeInterfaceToken(IServiceManager::getInterfaceDescriptor());
- data.writeInt32(n++);
- data.writeInt32(dumpsysPriority);
- status_t err = remote()->transact(LIST_SERVICES_TRANSACTION, data, &reply);
- if (err != NO_ERROR)
- break;
- res.add(reply.readString16());
+ Vector<String16> res;
+ res.setCapacity(ret.size());
+ for (const std::string& name : ret) {
+ res.push(String16(name.c_str()));
}
return res;
}
+
+private:
+ sp<AidlServiceManager> mTheRealServiceManager;
};
IMPLEMENT_META_INTERFACE(ServiceManager, "android.os.IServiceManager");
diff --git a/libs/binder/IShellCallback.cpp b/libs/binder/IShellCallback.cpp
index 6c697decca..88cc603b6f 100644
--- a/libs/binder/IShellCallback.cpp
+++ b/libs/binder/IShellCallback.cpp
@@ -25,8 +25,6 @@
#include <binder/Parcel.h>
#include <utils/String8.h>
-#include <private/binder/Static.h>
-
namespace android {
// ----------------------------------------------------------------------
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index afa3d33349..85822efa09 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -37,7 +37,6 @@
#include <binder/ProcessState.h>
#include <binder/Status.h>
#include <binder/TextOutput.h>
-#include <binder/Value.h>
#include <cutils/ashmem.h>
#include <utils/Debug.h>
@@ -48,7 +47,7 @@
#include <utils/String16.h>
#include <private/binder/binder_module.h>
-#include <private/binder/Static.h>
+#include "Static.h"
#ifndef INT32_MAX
#define INT32_MAX ((int32_t)(2147483647))
@@ -93,7 +92,7 @@ enum {
BLOB_ASHMEM_MUTABLE = 2,
};
-void acquire_object(const sp<ProcessState>& proc,
+static void acquire_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who, size_t* outAshmemSize)
{
switch (obj.hdr.type) {
@@ -135,12 +134,6 @@ void acquire_object(const sp<ProcessState>& proc,
ALOGD("Invalid object type 0x%08x", obj.hdr.type);
}
-void acquire_object(const sp<ProcessState>& proc,
- const flat_binder_object& obj, const void* who)
-{
- acquire_object(proc, obj, who, nullptr);
-}
-
static void release_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who, size_t* outAshmemSize)
{
@@ -189,19 +182,13 @@ static void release_object(const sp<ProcessState>& proc,
ALOGE("Invalid object type 0x%08x", obj.hdr.type);
}
-void release_object(const sp<ProcessState>& proc,
- const flat_binder_object& obj, const void* who)
-{
- release_object(proc, obj, who, nullptr);
-}
-
inline static status_t finish_flatten_binder(
const sp<IBinder>& /*binder*/, const flat_binder_object& flat, Parcel* out)
{
return out->writeObject(flat, false);
}
-status_t flatten_binder(const sp<ProcessState>& /*proc*/,
+static status_t flatten_binder(const sp<ProcessState>& /*proc*/,
const sp<IBinder>& binder, Parcel* out)
{
flat_binder_object obj;
@@ -243,7 +230,7 @@ status_t flatten_binder(const sp<ProcessState>& /*proc*/,
return finish_flatten_binder(binder, obj, out);
}
-status_t flatten_binder(const sp<ProcessState>& /*proc*/,
+static status_t flatten_binder(const sp<ProcessState>& /*proc*/,
const wp<IBinder>& binder, Parcel* out)
{
flat_binder_object obj;
@@ -299,7 +286,7 @@ inline static status_t finish_unflatten_binder(
return NO_ERROR;
}
-status_t unflatten_binder(const sp<ProcessState>& proc,
+static status_t unflatten_binder(const sp<ProcessState>& proc,
const Parcel& in, sp<IBinder>* out)
{
const flat_binder_object* flat = in.readObject(false);
@@ -318,7 +305,7 @@ status_t unflatten_binder(const sp<ProcessState>& proc,
return BAD_TYPE;
}
-status_t unflatten_binder(const sp<ProcessState>& proc,
+static status_t unflatten_binder(const sp<ProcessState>& proc,
const Parcel& in, wp<IBinder>* out)
{
const flat_binder_object* flat = in.readObject(false);
@@ -679,11 +666,6 @@ bool Parcel::enforceInterface(const String16& interface,
}
}
-const binder_size_t* Parcel::objects() const
-{
- return mObjects;
-}
-
size_t Parcel::objectsCount() const
{
return mObjectsSize;
@@ -1175,10 +1157,6 @@ status_t Parcel::writeParcelable(const Parcelable& parcelable) {
return parcelable.writeToParcel(this);
}
-status_t Parcel::writeValue(const binder::Value& value) {
- return value.writeToParcel(this);
-}
-
status_t Parcel::writeNativeHandle(const native_handle* handle)
{
if (!handle || handle->version != sizeof(native_handle))
@@ -1416,125 +1394,6 @@ status_t Parcel::writeNoException()
return status.writeToParcel(this);
}
-status_t Parcel::writeMap(const ::android::binder::Map& map_in)
-{
- using ::std::map;
- using ::android::binder::Value;
- using ::android::binder::Map;
-
- Map::const_iterator iter;
- status_t ret;
-
- ret = writeInt32(map_in.size());
-
- if (ret != NO_ERROR) {
- return ret;
- }
-
- for (iter = map_in.begin(); iter != map_in.end(); ++iter) {
- ret = writeValue(Value(iter->first));
- if (ret != NO_ERROR) {
- return ret;
- }
-
- ret = writeValue(iter->second);
- if (ret != NO_ERROR) {
- return ret;
- }
- }
-
- return ret;
-}
-
-status_t Parcel::writeNullableMap(const std::unique_ptr<binder::Map>& map)
-{
- if (map == nullptr) {
- return writeInt32(-1);
- }
-
- return writeMap(*map.get());
-}
-
-status_t Parcel::readMap(::android::binder::Map* map_out)const
-{
- using ::std::map;
- using ::android::String16;
- using ::android::String8;
- using ::android::binder::Value;
- using ::android::binder::Map;
-
- status_t ret = NO_ERROR;
- int32_t count;
-
- ret = readInt32(&count);
- if (ret != NO_ERROR) {
- return ret;
- }
-
- if (count < 0) {
- ALOGE("readMap: Unexpected count: %d", count);
- return (count == -1)
- ? UNEXPECTED_NULL
- : BAD_VALUE;
- }
-
- map_out->clear();
-
- while (count--) {
- Map::key_type key;
- Value value;
-
- ret = readValue(&value);
- if (ret != NO_ERROR) {
- return ret;
- }
-
- if (!value.getString(&key)) {
- ALOGE("readMap: Key type not a string (parcelType = %d)", value.parcelType());
- return BAD_VALUE;
- }
-
- ret = readValue(&value);
- if (ret != NO_ERROR) {
- return ret;
- }
-
- (*map_out)[key] = value;
- }
-
- return ret;
-}
-
-status_t Parcel::readNullableMap(std::unique_ptr<binder::Map>* map) const
-{
- const size_t start = dataPosition();
- int32_t count;
- status_t status = readInt32(&count);
- map->reset();
-
- if (status != OK || count == -1) {
- return status;
- }
-
- setDataPosition(start);
- map->reset(new binder::Map());
-
- status = readMap(map->get());
-
- if (status != OK) {
- map->reset();
- }
-
- return status;
-}
-
-
-
-void Parcel::remove(size_t /*start*/, size_t /*amt*/)
-{
- LOG_ALWAYS_FATAL("Parcel::remove() not yet implemented!");
-}
-
status_t Parcel::validateReadData(size_t upperBound) const
{
// Don't allow non-object reads on object data
@@ -2239,10 +2098,6 @@ status_t Parcel::readParcelable(Parcelable* parcelable) const {
return parcelable->readFromParcel(this);
}
-status_t Parcel::readValue(binder::Value* value) const {
- return value->readFromParcel(this);
-}
-
int32_t Parcel::readExceptionCode() const
{
binder::Status status;
@@ -2594,7 +2449,7 @@ void Parcel::print(TextOutput& to, uint32_t /*flags*/) const
} else if (dataSize() > 0) {
const uint8_t* DATA = data();
to << indent << HexDump(DATA, dataSize()) << dedent;
- const binder_size_t* OBJS = objects();
+ const binder_size_t* OBJS = mObjects;
const size_t N = objectsCount();
for (size_t i=0; i<N; i++) {
const flat_binder_object* flat
diff --git a/libs/binder/include/private/binder/ParcelValTypes.h b/libs/binder/ParcelValTypes.h
index 666d22a57f..666d22a57f 100644
--- a/libs/binder/include/private/binder/ParcelValTypes.h
+++ b/libs/binder/ParcelValTypes.h
diff --git a/libs/binder/PersistableBundle.cpp b/libs/binder/PersistableBundle.cpp
index c0aec0a979..97a6c94635 100644
--- a/libs/binder/PersistableBundle.cpp
+++ b/libs/binder/PersistableBundle.cpp
@@ -17,7 +17,6 @@
#define LOG_TAG "PersistableBundle"
#include <binder/PersistableBundle.h>
-#include <private/binder/ParcelValTypes.h>
#include <limits>
@@ -26,6 +25,8 @@
#include <log/log.h>
#include <utils/Errors.h>
+#include "ParcelValTypes.h"
+
using android::BAD_TYPE;
using android::BAD_VALUE;
using android::NO_ERROR;
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp
index 63f49ddba7..a07b3a043b 100644
--- a/libs/binder/ProcessState.cpp
+++ b/libs/binder/ProcessState.cpp
@@ -24,11 +24,10 @@
#include <cutils/atomic.h>
#include <utils/Log.h>
#include <utils/String8.h>
-#include <utils/String8.h>
#include <utils/threads.h>
#include <private/binder/binder_module.h>
-#include <private/binder/Static.h>
+#include "Static.h"
#include <errno.h>
#include <fcntl.h>
@@ -108,58 +107,11 @@ sp<ProcessState> ProcessState::selfOrNull()
return gProcess;
}
-void ProcessState::setContextObject(const sp<IBinder>& object)
-{
- setContextObject(object, String16("default"));
-}
-
sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& /*caller*/)
{
return getStrongProxyForHandle(0);
}
-void ProcessState::setContextObject(const sp<IBinder>& object, const String16& name)
-{
- AutoMutex _l(mLock);
- mContexts.add(name, object);
-}
-
-sp<IBinder> ProcessState::getContextObject(const String16& name, const sp<IBinder>& caller)
-{
- mLock.lock();
- sp<IBinder> object(
- mContexts.indexOfKey(name) >= 0 ? mContexts.valueFor(name) : nullptr);
- mLock.unlock();
-
- //printf("Getting context object %s for %p\n", String8(name).string(), caller.get());
-
- if (object != nullptr) return object;
-
- // Don't attempt to retrieve contexts if we manage them
- if (mManagesContexts) {
- ALOGE("getContextObject(%s) failed, but we manage the contexts!\n",
- String8(name).string());
- return nullptr;
- }
-
- IPCThreadState* ipc = IPCThreadState::self();
- {
- Parcel data, reply;
- // no interface token on this magic transaction
- data.writeString16(name);
- data.writeStrongBinder(caller);
- status_t result = ipc->transact(0 /*magic*/, 0, data, &reply, 0);
- if (result == NO_ERROR) {
- object = reply.readStrongBinder();
- }
- }
-
- ipc->flushCommands();
-
- if (object != nullptr) setContextObject(object, name);
- return object;
-}
-
void ProcessState::startThreadPool()
{
AutoMutex _l(mLock);
@@ -169,41 +121,33 @@ void ProcessState::startThreadPool()
}
}
-bool ProcessState::isContextManager(void) const
-{
- return mManagesContexts;
-}
-
bool ProcessState::becomeContextManager(context_check_func checkFunc, void* userData)
{
- if (!mManagesContexts) {
- AutoMutex _l(mLock);
- mBinderContextCheckFunc = checkFunc;
- mBinderContextUserData = userData;
+ AutoMutex _l(mLock);
+ mBinderContextCheckFunc = checkFunc;
+ mBinderContextUserData = userData;
- flat_binder_object obj {
- .flags = FLAT_BINDER_FLAG_TXN_SECURITY_CTX,
- };
+ flat_binder_object obj {
+ .flags = FLAT_BINDER_FLAG_TXN_SECURITY_CTX,
+ };
- status_t result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR_EXT, &obj);
+ int result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR_EXT, &obj);
- // fallback to original method
- if (result != 0) {
- android_errorWriteLog(0x534e4554, "121035042");
+ // fallback to original method
+ if (result != 0) {
+ android_errorWriteLog(0x534e4554, "121035042");
- int dummy = 0;
- result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &dummy);
- }
+ int dummy = 0;
+ result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &dummy);
+ }
- if (result == 0) {
- mManagesContexts = true;
- } else if (result == -1) {
- mBinderContextCheckFunc = nullptr;
- mBinderContextUserData = nullptr;
- ALOGE("Binder ioctl to become context manager failed: %s\n", strerror(errno));
- }
+ if (result == -1) {
+ mBinderContextCheckFunc = nullptr;
+ mBinderContextUserData = nullptr;
+ ALOGE("Binder ioctl to become context manager failed: %s\n", strerror(errno));
}
- return mManagesContexts;
+
+ return result == 0;
}
// Get references to userspace objects held by the kernel binder driver
@@ -430,7 +374,6 @@ ProcessState::ProcessState(const char *driver)
, mExecutingThreadsCount(0)
, mMaxThreads(DEFAULT_MAX_BINDER_THREADS)
, mStarvationStartTimeMs(0)
- , mManagesContexts(false)
, mBinderContextCheckFunc(nullptr)
, mBinderContextUserData(nullptr)
, mThreadPoolStarted(false)
@@ -449,7 +392,7 @@ ProcessState::ProcessState(const char *driver)
}
}
- LOG_ALWAYS_FATAL_IF(mDriverFD < 0, "Binder driver could not be opened. Terminating.");
+ LOG_ALWAYS_FATAL_IF(mDriverFD < 0, "Binder driver '%s' could not be opened. Terminating.", driver);
}
ProcessState::~ProcessState()
diff --git a/libs/binder/Static.cpp b/libs/binder/Static.cpp
index bd0e6f9a11..a6fd8c49e9 100644
--- a/libs/binder/Static.cpp
+++ b/libs/binder/Static.cpp
@@ -17,7 +17,7 @@
// All static variables go here, to control initialization and
// destruction order in the library.
-#include <private/binder/Static.h>
+#include "Static.h"
#include <binder/BufferedTextOutput.h>
#include <binder/IPCThreadState.h>
@@ -75,13 +75,4 @@ TextOutput& aerr(gStderrTextOutput);
Mutex& gProcessMutex = *new Mutex;
sp<ProcessState> gProcess;
-// ------------ IServiceManager.cpp
-
-Mutex gDefaultServiceManagerLock;
-sp<IServiceManager> gDefaultServiceManager;
-#ifndef __ANDROID_VNDK__
-sp<IPermissionController> gPermissionController;
-#endif
-bool gSystemBootCompleted = false;
-
} // namespace android
diff --git a/libs/binder/include/private/binder/Static.h b/libs/binder/Static.h
index 171be7791e..f8e0ee5f8d 100644
--- a/libs/binder/include/private/binder/Static.h
+++ b/libs/binder/Static.h
@@ -21,10 +21,6 @@
#include <binder/IBinder.h>
#include <binder/ProcessState.h>
-#ifndef __ANDROID_VNDK__
-#include <binder/IPermissionController.h>
-#endif
-#include <binder/IServiceManager.h>
namespace android {
@@ -35,12 +31,4 @@ extern Vector<int32_t> gTextBuffers;
extern Mutex& gProcessMutex;
extern sp<ProcessState> gProcess;
-// For IServiceManager.cpp
-extern Mutex gDefaultServiceManagerLock;
-extern sp<IServiceManager> gDefaultServiceManager;
-#ifndef __ANDROID_VNDK__
-extern sp<IPermissionController> gPermissionController;
-#endif
-extern bool gSystemBootCompleted;
-
} // namespace android
diff --git a/libs/binder/TEST_MAPPING b/libs/binder/TEST_MAPPING
new file mode 100644
index 0000000000..01e57d361e
--- /dev/null
+++ b/libs/binder/TEST_MAPPING
@@ -0,0 +1,16 @@
+{
+ "presubmit": [
+ {
+ "name": "binderSafeInterfaceTest"
+ },
+ {
+ "name": "binderDriverInterfaceTest"
+ },
+ {
+ "name": "binderTextOutputTest"
+ },
+ {
+ "name": "binderLibTest"
+ }
+ ]
+}
diff --git a/libs/binder/Value.cpp b/libs/binder/Value.cpp
deleted file mode 100644
index 19c57ba128..0000000000
--- a/libs/binder/Value.cpp
+++ /dev/null
@@ -1,420 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "Value"
-
-#include <binder/Value.h>
-
-#include <limits>
-
-#include <binder/IBinder.h>
-#include <binder/Parcel.h>
-#include <binder/Map.h>
-#include <private/binder/ParcelValTypes.h>
-#include <log/log.h>
-#include <utils/Errors.h>
-
-using android::BAD_TYPE;
-using android::BAD_VALUE;
-using android::NO_ERROR;
-using android::UNEXPECTED_NULL;
-using android::Parcel;
-using android::sp;
-using android::status_t;
-using std::map;
-using std::set;
-using std::vector;
-using android::binder::Value;
-using android::IBinder;
-using android::os::PersistableBundle;
-using namespace android::binder;
-
-// ====================================================================
-
-#define RETURN_IF_FAILED(calledOnce) \
- do { \
- status_t returnStatus = calledOnce; \
- if (returnStatus) { \
- ALOGE("Failed at %s:%d (%s)", __FILE__, __LINE__, __func__); \
- return returnStatus; \
- } \
- } while(false)
-
-// ====================================================================
-
-/* These `internal_type_ptr()` functions allow this
- * class to work without C++ RTTI support. This technique
- * only works properly when called directly from this file,
- * but that is OK because that is the only place we will
- * be calling them from. */
-template<class T> const void* internal_type_ptr()
-{
- static const T *marker;
- return (void*)&marker;
-}
-
-/* Allows the type to be specified by the argument
- * instead of inside angle brackets. */
-template<class T> const void* internal_type_ptr(const T&)
-{
- return internal_type_ptr<T>();
-}
-
-// ====================================================================
-
-namespace android {
-
-namespace binder {
-
-class Value::ContentBase {
-public:
- virtual ~ContentBase() = default;
- virtual const void* type_ptr() const = 0;
- virtual ContentBase * clone() const = 0;
- virtual bool operator==(const ContentBase& rhs) const = 0;
-
-#ifdef LIBBINDER_VALUE_SUPPORTS_TYPE_INFO
- virtual const std::type_info &type() const = 0;
-#endif
-
- template<typename T> bool get(T* out) const;
-};
-
-/* This is the actual class that holds the value. */
-template<typename T> class Value::Content : public Value::ContentBase {
-public:
- Content() = default;
- explicit Content(const T & value) : mValue(value) { }
-
- virtual ~Content() = default;
-
-#ifdef LIBBINDER_VALUE_SUPPORTS_TYPE_INFO
- virtual const std::type_info &type() const override
- {
- return typeid(T);
- }
-#endif
-
- virtual const void* type_ptr() const override
- {
- return internal_type_ptr<T>();
- }
-
- virtual ContentBase * clone() const override
- {
- return new Content(mValue);
- };
-
- virtual bool operator==(const ContentBase& rhs) const override
- {
- if (type_ptr() != rhs.type_ptr()) {
- return false;
- }
- return mValue == static_cast<const Content<T>* >(&rhs)->mValue;
- }
-
- T mValue;
-};
-
-template<typename T> bool Value::ContentBase::get(T* out) const
-{
- if (internal_type_ptr(*out) != type_ptr())
- {
- return false;
- }
-
- *out = static_cast<const Content<T>*>(this)->mValue;
-
- return true;
-}
-
-// ====================================================================
-
-Value::Value() : mContent(nullptr)
-{
-}
-
-Value::Value(const Value& value)
- : mContent(value.mContent ? value.mContent->clone() : nullptr)
-{
-}
-
-Value::~Value()
-{
- delete mContent;
-}
-
-bool Value::operator==(const Value& rhs) const
-{
- const Value& lhs(*this);
-
- if (lhs.empty() && rhs.empty()) {
- return true;
- }
-
- if ( (lhs.mContent == nullptr)
- || (rhs.mContent == nullptr)
- ) {
- return false;
- }
-
- return *lhs.mContent == *rhs.mContent;
-}
-
-Value& Value::swap(Value &rhs)
-{
- std::swap(mContent, rhs.mContent);
- return *this;
-}
-
-Value& Value::operator=(const Value& rhs)
-{
- if (this != &rhs) {
- delete mContent;
- mContent = rhs.mContent
- ? rhs.mContent->clone()
- : nullptr;
- }
- return *this;
-}
-
-bool Value::empty() const
-{
- return mContent == nullptr;
-}
-
-void Value::clear()
-{
- delete mContent;
- mContent = nullptr;
-}
-
-int32_t Value::parcelType() const
-{
- const void* t_info(mContent ? mContent->type_ptr() : nullptr);
-
- if (t_info == internal_type_ptr<bool>()) return VAL_BOOLEAN;
- if (t_info == internal_type_ptr<uint8_t>()) return VAL_BYTE;
- if (t_info == internal_type_ptr<int32_t>()) return VAL_INTEGER;
- if (t_info == internal_type_ptr<int64_t>()) return VAL_LONG;
- if (t_info == internal_type_ptr<double>()) return VAL_DOUBLE;
- if (t_info == internal_type_ptr<String16>()) return VAL_STRING;
-
- if (t_info == internal_type_ptr<vector<bool>>()) return VAL_BOOLEANARRAY;
- if (t_info == internal_type_ptr<vector<uint8_t>>()) return VAL_BYTEARRAY;
- if (t_info == internal_type_ptr<vector<int32_t>>()) return VAL_INTARRAY;
- if (t_info == internal_type_ptr<vector<int64_t>>()) return VAL_LONGARRAY;
- if (t_info == internal_type_ptr<vector<double>>()) return VAL_DOUBLEARRAY;
- if (t_info == internal_type_ptr<vector<String16>>()) return VAL_STRINGARRAY;
-
- if (t_info == internal_type_ptr<Map>()) return VAL_MAP;
- if (t_info == internal_type_ptr<PersistableBundle>()) return VAL_PERSISTABLEBUNDLE;
-
- return VAL_NULL;
-}
-
-#ifdef LIBBINDER_VALUE_SUPPORTS_TYPE_INFO
-const std::type_info& Value::type() const
-{
- return mContent != nullptr
- ? mContent->type()
- : typeid(void);
-}
-#endif // ifdef LIBBINDER_VALUE_SUPPORTS_TYPE_INFO
-
-#define DEF_TYPE_ACCESSORS(T, TYPENAME) \
- bool Value::is ## TYPENAME() const \
- { \
- return mContent \
- ? internal_type_ptr<T>() == mContent->type_ptr() \
- : false; \
- } \
- bool Value::get ## TYPENAME(T* out) const \
- { \
- return mContent \
- ? mContent->get(out) \
- : false; \
- } \
- void Value::put ## TYPENAME(const T& in) \
- { \
- *this = in; \
- } \
- Value& Value::operator=(const T& rhs) \
- { \
- delete mContent; \
- mContent = new Content< T >(rhs); \
- return *this; \
- } \
- Value::Value(const T& value) \
- : mContent(new Content< T >(value)) \
- { }
-
-DEF_TYPE_ACCESSORS(bool, Boolean)
-DEF_TYPE_ACCESSORS(int8_t, Byte)
-DEF_TYPE_ACCESSORS(int32_t, Int)
-DEF_TYPE_ACCESSORS(int64_t, Long)
-DEF_TYPE_ACCESSORS(double, Double)
-DEF_TYPE_ACCESSORS(String16, String)
-
-DEF_TYPE_ACCESSORS(std::vector<bool>, BooleanVector)
-DEF_TYPE_ACCESSORS(std::vector<uint8_t>, ByteVector)
-DEF_TYPE_ACCESSORS(std::vector<int32_t>, IntVector)
-DEF_TYPE_ACCESSORS(std::vector<int64_t>, LongVector)
-DEF_TYPE_ACCESSORS(std::vector<double>, DoubleVector)
-DEF_TYPE_ACCESSORS(std::vector<String16>, StringVector)
-
-DEF_TYPE_ACCESSORS(::android::binder::Map, Map)
-DEF_TYPE_ACCESSORS(PersistableBundle, PersistableBundle)
-
-bool Value::getString(String8* out) const
-{
- String16 val;
- bool ret = getString(&val);
- if (ret) {
- *out = String8(val);
- }
- return ret;
-}
-
-bool Value::getString(::std::string* out) const
-{
- String8 val;
- bool ret = getString(&val);
- if (ret) {
- *out = val.string();
- }
- return ret;
-}
-
-status_t Value::writeToParcel(Parcel* parcel) const
-{
- // This implementation needs to be kept in sync with the writeValue
- // implementation in frameworks/base/core/java/android/os/Parcel.java
-
-#define BEGIN_HANDLE_WRITE() \
- do { \
- const void* t_info(mContent?mContent->type_ptr():nullptr); \
- if (false) { }
-#define HANDLE_WRITE_TYPE(T, TYPEVAL, TYPEMETHOD) \
- else if (t_info == internal_type_ptr<T>()) { \
- RETURN_IF_FAILED(parcel->writeInt32(TYPEVAL)); \
- RETURN_IF_FAILED(parcel->TYPEMETHOD(static_cast<const Content<T>*>(mContent)->mValue)); \
- }
-#define HANDLE_WRITE_PARCELABLE(T, TYPEVAL) \
- else if (t_info == internal_type_ptr<T>()) { \
- RETURN_IF_FAILED(parcel->writeInt32(TYPEVAL)); \
- RETURN_IF_FAILED(static_cast<const Content<T>*>(mContent)->mValue.writeToParcel(parcel)); \
- }
-#define END_HANDLE_WRITE() \
- else { \
- ALOGE("writeToParcel: Type not supported"); \
- return BAD_TYPE; \
- } \
- } while (false);
-
- BEGIN_HANDLE_WRITE()
-
- HANDLE_WRITE_TYPE(bool, VAL_BOOLEAN, writeBool)
- HANDLE_WRITE_TYPE(int8_t, VAL_BYTE, writeByte)
- HANDLE_WRITE_TYPE(int8_t, VAL_BYTE, writeByte)
- HANDLE_WRITE_TYPE(int32_t, VAL_INTEGER, writeInt32)
- HANDLE_WRITE_TYPE(int64_t, VAL_LONG, writeInt64)
- HANDLE_WRITE_TYPE(double, VAL_DOUBLE, writeDouble)
- HANDLE_WRITE_TYPE(String16, VAL_STRING, writeString16)
-
- HANDLE_WRITE_TYPE(vector<bool>, VAL_BOOLEANARRAY, writeBoolVector)
- HANDLE_WRITE_TYPE(vector<uint8_t>, VAL_BYTEARRAY, writeByteVector)
- HANDLE_WRITE_TYPE(vector<int8_t>, VAL_BYTEARRAY, writeByteVector)
- HANDLE_WRITE_TYPE(vector<int32_t>, VAL_INTARRAY, writeInt32Vector)
- HANDLE_WRITE_TYPE(vector<int64_t>, VAL_LONGARRAY, writeInt64Vector)
- HANDLE_WRITE_TYPE(vector<double>, VAL_DOUBLEARRAY, writeDoubleVector)
- HANDLE_WRITE_TYPE(vector<String16>, VAL_STRINGARRAY, writeString16Vector)
-
- HANDLE_WRITE_PARCELABLE(PersistableBundle, VAL_PERSISTABLEBUNDLE)
-
- END_HANDLE_WRITE()
-
- return NO_ERROR;
-
-#undef BEGIN_HANDLE_WRITE
-#undef HANDLE_WRITE_TYPE
-#undef HANDLE_WRITE_PARCELABLE
-#undef END_HANDLE_WRITE
-}
-
-status_t Value::readFromParcel(const Parcel* parcel)
-{
- // This implementation needs to be kept in sync with the readValue
- // implementation in frameworks/base/core/java/android/os/Parcel.javai
-
-#define BEGIN_HANDLE_READ() \
- switch(value_type) { \
- default: \
- ALOGE("readFromParcel: Parcel type %d is not supported", value_type); \
- return BAD_TYPE;
-#define HANDLE_READ_TYPE(T, TYPEVAL, TYPEMETHOD) \
- case TYPEVAL: \
- mContent = new Content<T>(); \
- RETURN_IF_FAILED(parcel->TYPEMETHOD(&static_cast<Content<T>*>(mContent)->mValue)); \
- break;
-#define HANDLE_READ_PARCELABLE(T, TYPEVAL) \
- case TYPEVAL: \
- mContent = new Content<T>(); \
- RETURN_IF_FAILED(static_cast<Content<T>*>(mContent)->mValue.readFromParcel(parcel)); \
- break;
-#define END_HANDLE_READ() \
- }
-
- int32_t value_type = VAL_NULL;
-
- delete mContent;
- mContent = nullptr;
-
- RETURN_IF_FAILED(parcel->readInt32(&value_type));
-
- BEGIN_HANDLE_READ()
-
- HANDLE_READ_TYPE(bool, VAL_BOOLEAN, readBool)
- HANDLE_READ_TYPE(int8_t, VAL_BYTE, readByte)
- HANDLE_READ_TYPE(int32_t, VAL_INTEGER, readInt32)
- HANDLE_READ_TYPE(int64_t, VAL_LONG, readInt64)
- HANDLE_READ_TYPE(double, VAL_DOUBLE, readDouble)
- HANDLE_READ_TYPE(String16, VAL_STRING, readString16)
-
- HANDLE_READ_TYPE(vector<bool>, VAL_BOOLEANARRAY, readBoolVector)
- HANDLE_READ_TYPE(vector<uint8_t>, VAL_BYTEARRAY, readByteVector)
- HANDLE_READ_TYPE(vector<int32_t>, VAL_INTARRAY, readInt32Vector)
- HANDLE_READ_TYPE(vector<int64_t>, VAL_LONGARRAY, readInt64Vector)
- HANDLE_READ_TYPE(vector<double>, VAL_DOUBLEARRAY, readDoubleVector)
- HANDLE_READ_TYPE(vector<String16>, VAL_STRINGARRAY, readString16Vector)
-
- HANDLE_READ_PARCELABLE(PersistableBundle, VAL_PERSISTABLEBUNDLE)
-
- END_HANDLE_READ()
-
- return NO_ERROR;
-
-#undef BEGIN_HANDLE_READ
-#undef HANDLE_READ_TYPE
-#undef HANDLE_READ_PARCELABLE
-#undef END_HANDLE_READ
-}
-
-} // namespace binder
-
-} // namespace android
-
-/* vim: set ts=4 sw=4 tw=0 et :*/
diff --git a/libs/binder/aidl/android/os/IServiceManager.aidl b/libs/binder/aidl/android/os/IServiceManager.aidl
new file mode 100644
index 0000000000..50a72aa9e4
--- /dev/null
+++ b/libs/binder/aidl/android/os/IServiceManager.aidl
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.os;
+
+/**
+ * Basic interface for finding and publishing system services.
+ *
+ * You likely want to use android.os.ServiceManager in Java or
+ * android::IServiceManager in C++ in order to use this interface.
+ *
+ * @hide
+ */
+interface IServiceManager {
+ /*
+ * Must update values in IServiceManager.h
+ */
+ /* Allows services to dump sections according to priorities. */
+ const int DUMP_FLAG_PRIORITY_CRITICAL = 1; // 1 << 0
+ const int DUMP_FLAG_PRIORITY_HIGH = 2; // 1 << 1
+ const int DUMP_FLAG_PRIORITY_NORMAL = 4; // 1 << 2
+ /**
+ * Services are by default registered with a DEFAULT dump priority. DEFAULT priority has the
+ * same priority as NORMAL priority but the services are not called with dump priority
+ * arguments.
+ */
+ const int DUMP_FLAG_PRIORITY_DEFAULT = 8; // 1 << 3
+
+ const int DUMP_FLAG_PRIORITY_ALL = 15;
+ // DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PRIORITY_HIGH
+ // | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PRIORITY_DEFAULT;
+
+ /* Allows services to dump sections in protobuf format. */
+ const int DUMP_FLAG_PROTO = 16; // 1 << 4
+
+ /**
+ * Retrieve an existing service called @a name from the
+ * service manager.
+ *
+ * This is the same as checkService (returns immediately) but
+ * exists for legacy purposes.
+ *
+ * Returns null if the service does not exist.
+ */
+ @UnsupportedAppUsage
+ IBinder getService(@utf8InCpp String name);
+
+ /**
+ * Retrieve an existing service called @a name from the service
+ * manager. Non-blocking. Returns null if the service does not
+ * exist.
+ */
+ @UnsupportedAppUsage
+ IBinder checkService(@utf8InCpp String name);
+
+ /**
+ * Place a new @a service called @a name into the service
+ * manager.
+ */
+ void addService(@utf8InCpp String name, IBinder service,
+ boolean allowIsolated, int dumpPriority);
+
+ /**
+ * Return a list of all currently running services.
+ */
+ @utf8InCpp String[] listServices(int dumpPriority);
+}
diff --git a/libs/binder/include/binder/BpBinder.h b/libs/binder/include/binder/BpBinder.h
index 1d4f88113a..b3a1d0b7e9 100644
--- a/libs/binder/include/binder/BpBinder.h
+++ b/libs/binder/include/binder/BpBinder.h
@@ -34,7 +34,7 @@ class BpBinder : public IBinder
public:
static BpBinder* create(int32_t handle);
- inline int32_t handle() const { return mHandle; }
+ int32_t handle() const;
virtual const String16& getInterfaceDescriptor() const;
virtual bool isBinderAlive() const;
@@ -67,7 +67,6 @@ public:
virtual BpBinder* remoteBinder();
- status_t setConstantData(const void* data, size_t size);
void sendObituary();
static uint32_t getBinderProxyCount(uint32_t uid);
diff --git a/libs/binder/include/binder/IPCThreadState.h b/libs/binder/include/binder/IPCThreadState.h
index 614b0b33dd..b810f7e8ee 100644
--- a/libs/binder/include/binder/IPCThreadState.h
+++ b/libs/binder/include/binder/IPCThreadState.h
@@ -110,6 +110,8 @@ public:
// the maximum number of binder threads threads allowed for this process.
void blockUntilThreadAvailable();
+ // Service manager registration
+ void setTheContextObject(sp<BBinder> obj);
// Is this thread currently serving a binder call. This method
// returns true if while traversing backwards from the function call
diff --git a/libs/binder/include/binder/Map.h b/libs/binder/include/binder/Map.h
deleted file mode 100644
index 96a4f8a2a5..0000000000
--- a/libs/binder/include/binder/Map.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2005 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_MAP_H
-#define ANDROID_MAP_H
-
-#include <map>
-#include <string>
-
-// ---------------------------------------------------------------------------
-namespace android {
-namespace binder {
-
-class Value;
-
-/**
- * Convenience typedef for ::std::map<::std::string,::android::binder::Value>
- */
-typedef ::std::map<::std::string, Value> Map;
-
-} // namespace binder
-} // namespace android
-
-// ---------------------------------------------------------------------------
-
-#endif // ANDROID_MAP_H
diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h
index e5219a5590..ecce6d71e2 100644
--- a/libs/binder/include/binder/Parcel.h
+++ b/libs/binder/include/binder/Parcel.h
@@ -17,6 +17,7 @@
#ifndef ANDROID_PARCEL_H
#define ANDROID_PARCEL_H
+#include <map> // for legacy reasons
#include <string>
#include <vector>
@@ -32,7 +33,6 @@
#include <binder/IInterface.h>
#include <binder/Parcelable.h>
-#include <binder/Map.h>
// ---------------------------------------------------------------------------
namespace android {
@@ -97,10 +97,6 @@ public:
void freeData();
-private:
- const binder_size_t* objects() const;
-
-public:
size_t objectsCount() const;
status_t errorCheck() const;
@@ -172,8 +168,6 @@ public:
status_t writeParcelable(const Parcelable& parcelable);
- status_t writeValue(const binder::Value& value);
-
template<typename T>
status_t write(const Flattenable<T>& val);
@@ -185,9 +179,6 @@ public:
template<typename T>
status_t writeVectorSize(const std::unique_ptr<std::vector<T>>& val);
- status_t writeMap(const binder::Map& map);
- status_t writeNullableMap(const std::unique_ptr<binder::Map>& map);
-
// Place a native_handle into the parcel (the native_handle's file-
// descriptors are dup'ed, so it is safe to delete the native_handle
// when this function returns).
@@ -244,8 +235,6 @@ public:
// Currently the native implementation doesn't do any of the StrictMode
// stack gathering and serialization that the Java implementation does.
status_t writeNoException();
-
- void remove(size_t start, size_t amt);
status_t read(void* outData, size_t len) const;
const void* readInplace(size_t len) const;
@@ -297,8 +286,6 @@ public:
template<typename T>
status_t readParcelable(std::unique_ptr<T>* parcelable) const;
- status_t readValue(binder::Value* value) const;
-
template<typename T>
status_t readStrongBinder(sp<T>* val) const;
@@ -344,9 +331,6 @@ public:
template<typename T>
status_t resizeOutVector(std::unique_ptr<std::vector<T>>* val) const;
- status_t readMap(binder::Map* map)const;
- status_t readNullableMap(std::unique_ptr<binder::Map>* map) const;
-
// Like Parcel.java's readExceptionCode(). Reads the first int32
// off of a Parcel's header, returning 0 or the negative error
// code on exceptions, but also deals with skipping over rich
@@ -932,23 +916,6 @@ inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel)
return to;
}
-// ---------------------------------------------------------------------------
-
-// Generic acquire and release of objects.
-void acquire_object(const sp<ProcessState>& proc,
- const flat_binder_object& obj, const void* who);
-void release_object(const sp<ProcessState>& proc,
- const flat_binder_object& obj, const void* who);
-
-void flatten_binder(const sp<ProcessState>& proc,
- const sp<IBinder>& binder, flat_binder_object* out);
-void flatten_binder(const sp<ProcessState>& proc,
- const wp<IBinder>& binder, flat_binder_object* out);
-status_t unflatten_binder(const sp<ProcessState>& proc,
- const flat_binder_object& flat, sp<IBinder>* out);
-status_t unflatten_binder(const sp<ProcessState>& proc,
- const flat_binder_object& flat, wp<IBinder>* out);
-
}; // namespace android
// ---------------------------------------------------------------------------
diff --git a/libs/binder/include/binder/ProcessState.h b/libs/binder/include/binder/ProcessState.h
index 224cb36807..3af9eed9c6 100644
--- a/libs/binder/include/binder/ProcessState.h
+++ b/libs/binder/include/binder/ProcessState.h
@@ -45,21 +45,14 @@ public:
*/
static sp<ProcessState> initWithDriver(const char *driver);
- void setContextObject(const sp<IBinder>& object);
sp<IBinder> getContextObject(const sp<IBinder>& caller);
-
- void setContextObject(const sp<IBinder>& object,
- const String16& name);
- sp<IBinder> getContextObject(const String16& name,
- const sp<IBinder>& caller);
void startThreadPool();
typedef bool (*context_check_func)(const String16& name,
const sp<IBinder>& caller,
void* userData);
-
- bool isContextManager(void) const;
+
bool becomeContextManager(
context_check_func checkFunc,
void* userData);
@@ -124,14 +117,9 @@ private:
Vector<handle_entry>mHandleToObject;
- bool mManagesContexts;
context_check_func mBinderContextCheckFunc;
void* mBinderContextUserData;
- KeyedVector<String16, sp<IBinder> >
- mContexts;
-
-
String8 mRootDir;
bool mThreadPoolStarted;
volatile int32_t mThreadPoolSeq;
diff --git a/libs/binder/include/binder/Value.h b/libs/binder/include/binder/Value.h
deleted file mode 100644
index 735f40eb1f..0000000000
--- a/libs/binder/include/binder/Value.h
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_VALUE_H
-#define ANDROID_VALUE_H
-
-#include <stdint.h>
-#include <map>
-#include <set>
-#include <vector>
-#include <string>
-
-#include <binder/Parcelable.h>
-#include <binder/PersistableBundle.h>
-#include <binder/Map.h>
-#include <utils/String8.h>
-#include <utils/String16.h>
-#include <utils/StrongPointer.h>
-
-namespace android {
-
-class Parcel;
-
-namespace binder {
-
-/**
- * A limited C++ generic type. The purpose of this class is to allow C++
- * programs to make use of (or implement) Binder interfaces which make use
- * the Java "Object" generic type (either via the use of the Map type or
- * some other mechanism).
- *
- * This class only supports a limited set of types, but additional types
- * may be easily added to this class in the future as needed---without
- * breaking binary compatability.
- *
- * This class was written in such a way as to help avoid type errors by
- * giving each type their own explicity-named accessor methods (rather than
- * overloaded methods).
- *
- * When reading or writing this class to a Parcel, use the `writeValue()`
- * and `readValue()` methods.
- */
-class Value {
-public:
- Value();
- virtual ~Value();
-
- Value& swap(Value &);
-
- bool empty() const;
-
- void clear();
-
-#ifdef LIBBINDER_VALUE_SUPPORTS_TYPE_INFO
- const std::type_info& type() const;
-#endif
-
- int32_t parcelType() const;
-
- bool operator==(const Value& rhs) const;
- bool operator!=(const Value& rhs) const { return !this->operator==(rhs); }
-
- Value(const Value& value);
- Value(const bool& value); // NOLINT(google-explicit-constructor)
- Value(const int8_t& value); // NOLINT(google-explicit-constructor)
- Value(const int32_t& value); // NOLINT(google-explicit-constructor)
- Value(const int64_t& value); // NOLINT(google-explicit-constructor)
- Value(const double& value); // NOLINT(google-explicit-constructor)
- Value(const String16& value); // NOLINT(google-explicit-constructor)
- Value(const std::vector<bool>& value); // NOLINT(google-explicit-constructor)
- Value(const std::vector<uint8_t>& value); // NOLINT(google-explicit-constructor)
- Value(const std::vector<int32_t>& value); // NOLINT(google-explicit-constructor)
- Value(const std::vector<int64_t>& value); // NOLINT(google-explicit-constructor)
- Value(const std::vector<double>& value); // NOLINT(google-explicit-constructor)
- Value(const std::vector<String16>& value); // NOLINT(google-explicit-constructor)
- Value(const os::PersistableBundle& value); // NOLINT(google-explicit-constructor)
- Value(const binder::Map& value); // NOLINT(google-explicit-constructor)
-
- Value& operator=(const Value& rhs);
- Value& operator=(const int8_t& rhs);
- Value& operator=(const bool& rhs);
- Value& operator=(const int32_t& rhs);
- Value& operator=(const int64_t& rhs);
- Value& operator=(const double& rhs);
- Value& operator=(const String16& rhs);
- Value& operator=(const std::vector<bool>& rhs);
- Value& operator=(const std::vector<uint8_t>& rhs);
- Value& operator=(const std::vector<int32_t>& rhs);
- Value& operator=(const std::vector<int64_t>& rhs);
- Value& operator=(const std::vector<double>& rhs);
- Value& operator=(const std::vector<String16>& rhs);
- Value& operator=(const os::PersistableBundle& rhs);
- Value& operator=(const binder::Map& rhs);
-
- void putBoolean(const bool& value);
- void putByte(const int8_t& value);
- void putInt(const int32_t& value);
- void putLong(const int64_t& value);
- void putDouble(const double& value);
- void putString(const String16& value);
- void putBooleanVector(const std::vector<bool>& value);
- void putByteVector(const std::vector<uint8_t>& value);
- void putIntVector(const std::vector<int32_t>& value);
- void putLongVector(const std::vector<int64_t>& value);
- void putDoubleVector(const std::vector<double>& value);
- void putStringVector(const std::vector<String16>& value);
- void putPersistableBundle(const os::PersistableBundle& value);
- void putMap(const binder::Map& value);
-
- bool getBoolean(bool* out) const;
- bool getByte(int8_t* out) const;
- bool getInt(int32_t* out) const;
- bool getLong(int64_t* out) const;
- bool getDouble(double* out) const;
- bool getString(String16* out) const;
- bool getBooleanVector(std::vector<bool>* out) const;
- bool getByteVector(std::vector<uint8_t>* out) const;
- bool getIntVector(std::vector<int32_t>* out) const;
- bool getLongVector(std::vector<int64_t>* out) const;
- bool getDoubleVector(std::vector<double>* out) const;
- bool getStringVector(std::vector<String16>* out) const;
- bool getPersistableBundle(os::PersistableBundle* out) const;
- bool getMap(binder::Map* out) const;
-
- bool isBoolean() const;
- bool isByte() const;
- bool isInt() const;
- bool isLong() const;
- bool isDouble() const;
- bool isString() const;
- bool isBooleanVector() const;
- bool isByteVector() const;
- bool isIntVector() const;
- bool isLongVector() const;
- bool isDoubleVector() const;
- bool isStringVector() const;
- bool isPersistableBundle() const;
- bool isMap() const;
-
- // String Convenience Adapters
- // ---------------------------
-
- explicit Value(const String8& value): Value(String16(value)) { }
- explicit Value(const ::std::string& value): Value(String8(value.c_str())) { }
- void putString(const String8& value) { return putString(String16(value)); }
- void putString(const ::std::string& value) { return putString(String8(value.c_str())); }
- Value& operator=(const String8& rhs) { return *this = String16(rhs); }
- Value& operator=(const ::std::string& rhs) { return *this = String8(rhs.c_str()); }
- bool getString(String8* out) const;
- bool getString(::std::string* out) const;
-
-private:
-
- // This allows ::android::Parcel to call the two methods below.
- friend class ::android::Parcel;
-
- // This is called by ::android::Parcel::writeValue()
- status_t writeToParcel(Parcel* parcel) const;
-
- // This is called by ::android::Parcel::readValue()
- status_t readFromParcel(const Parcel* parcel);
-
- template<typename T> class Content;
- class ContentBase;
-
- ContentBase* mContent;
-};
-
-} // namespace binder
-
-} // namespace android
-
-#endif // ANDROID_VALUE_H
diff --git a/libs/binder/ndk/Android.bp b/libs/binder/ndk/Android.bp
index 21bef2e930..6da30866d8 100644
--- a/libs/binder/ndk/Android.bp
+++ b/libs/binder/ndk/Android.bp
@@ -16,7 +16,6 @@
cc_library {
name: "libbinder_ndk",
- vendor_available: true,
export_include_dirs: [
"include_ndk",
@@ -74,3 +73,12 @@ ndk_library {
symbol_file: "libbinder_ndk.map.txt",
first_version: "29",
}
+
+llndk_library {
+ name: "libbinder_ndk",
+ symbol_file: "libbinder_ndk.map.txt",
+ export_include_dirs: [
+ "include_ndk",
+ "include_apex",
+ ],
+}
diff --git a/libs/binder/ndk/libbinder_ndk.map.txt b/libs/binder/ndk/libbinder_ndk.map.txt
index 7e6581736f..4f685d1241 100644
--- a/libs/binder/ndk/libbinder_ndk.map.txt
+++ b/libs/binder/ndk/libbinder_ndk.map.txt
@@ -89,12 +89,12 @@ LIBBINDER_NDK { # introduced=29
AStatus_getStatus;
AStatus_isOk;
AStatus_newOk;
- ABinderProcess_joinThreadPool; # apex
- ABinderProcess_setThreadPoolMaxThreadCount; # apex
- ABinderProcess_startThreadPool; # apex
- AServiceManager_addService; # apex
- AServiceManager_checkService; # apex
- AServiceManager_getService; # apex
+ ABinderProcess_joinThreadPool; # apex vndk
+ ABinderProcess_setThreadPoolMaxThreadCount; # apex vndk
+ ABinderProcess_startThreadPool; # apex vndk
+ AServiceManager_addService; # apex vndk
+ AServiceManager_checkService; # apex vndk
+ AServiceManager_getService; # apex vndk
local:
*;
};
diff --git a/libs/binder/tests/Android.bp b/libs/binder/tests/Android.bp
index c451780dd7..44a691d594 100644
--- a/libs/binder/tests/Android.bp
+++ b/libs/binder/tests/Android.bp
@@ -19,45 +19,34 @@ cc_defaults {
cflags: [
"-Wall",
"-Werror",
- "-Wno-unused-private-field",
- "-Wno-unused-variable",
],
}
cc_test {
name: "binderDriverInterfaceTest_IPC_32",
- srcs: ["binderDriverInterfaceTest.cpp"],
defaults: ["binder_test_defaults"],
+ srcs: ["binderDriverInterfaceTest.cpp"],
compile_multilib: "32",
cflags: ["-DBINDER_IPC_32BIT=1"],
}
cc_test {
+ name: "binderDriverInterfaceTest",
+ defaults: ["binder_test_defaults"],
product_variables: {
binder32bit: {
cflags: ["-DBINDER_IPC_32BIT=1"],
},
},
- name: "binderDriverInterfaceTest",
srcs: ["binderDriverInterfaceTest.cpp"],
- defaults: ["binder_test_defaults"],
-}
-
-cc_test {
- name: "binderValueTypeTest",
- srcs: ["binderValueTypeTest.cpp"],
- defaults: ["binder_test_defaults"],
- shared_libs: [
- "libbinder",
- "libutils",
- ],
+ test_suites: ["device-tests"],
}
cc_test {
name: "binderLibTest_IPC_32",
- srcs: ["binderLibTest.cpp"],
defaults: ["binder_test_defaults"],
+ srcs: ["binderLibTest.cpp"],
shared_libs: [
"libbinder",
"libutils",
@@ -67,25 +56,26 @@ cc_test {
}
cc_test {
+ name: "binderLibTest",
+ defaults: ["binder_test_defaults"],
product_variables: {
binder32bit: {
cflags: ["-DBINDER_IPC_32BIT=1"],
},
},
- defaults: ["binder_test_defaults"],
- name: "binderLibTest",
srcs: ["binderLibTest.cpp"],
shared_libs: [
"libbinder",
"libutils",
],
+ test_suites: ["device-tests"],
}
cc_test {
name: "binderThroughputTest",
- srcs: ["binderThroughputTest.cpp"],
defaults: ["binder_test_defaults"],
+ srcs: ["binderThroughputTest.cpp"],
shared_libs: [
"libbinder",
"libutils",
@@ -101,19 +91,20 @@ cc_test {
cc_test {
name: "binderTextOutputTest",
- srcs: ["binderTextOutputTest.cpp"],
defaults: ["binder_test_defaults"],
+ srcs: ["binderTextOutputTest.cpp"],
shared_libs: [
"libbinder",
"libutils",
"libbase",
],
+ test_suites: ["device-tests"],
}
cc_test {
name: "schd-dbg",
- srcs: ["schd-dbg.cpp"],
defaults: ["binder_test_defaults"],
+ srcs: ["schd-dbg.cpp"],
shared_libs: [
"libbinder",
"libutils",
@@ -123,8 +114,8 @@ cc_test {
cc_test {
name: "binderSafeInterfaceTest",
- srcs: ["binderSafeInterfaceTest.cpp"],
defaults: ["binder_test_defaults"],
+ srcs: ["binderSafeInterfaceTest.cpp"],
cppflags: [
"-Weverything",
@@ -144,4 +135,5 @@ cc_test {
"liblog",
"libutils",
],
+ test_suites: ["device-tests"],
}
diff --git a/libs/binder/tests/binderDriverInterfaceTest.cpp b/libs/binder/tests/binderDriverInterfaceTest.cpp
index 77ebac8f5a..f3ed6a613c 100644
--- a/libs/binder/tests/binderDriverInterfaceTest.cpp
+++ b/libs/binder/tests/binderDriverInterfaceTest.cpp
@@ -230,7 +230,6 @@ TEST_F(BinderDriverInterfaceTest, IncRefsAcquireReleaseDecRefs) {
}
TEST_F(BinderDriverInterfaceTest, Transaction) {
- binder_uintptr_t cookie = 1234;
struct {
uint32_t cmd1;
struct binder_transaction_data arg1;
diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp
index 78f11594b9..e51bcebba2 100644
--- a/libs/binder/tests/binderLibTest.cpp
+++ b/libs/binder/tests/binderLibTest.cpp
@@ -553,50 +553,6 @@ TEST_F(BinderLibTest, AddServer)
ASSERT_TRUE(server != nullptr);
}
-TEST_F(BinderLibTest, DeathNotificationNoRefs)
-{
- status_t ret;
-
- sp<TestDeathRecipient> testDeathRecipient = new TestDeathRecipient();
-
- {
- sp<IBinder> binder = addServer();
- ASSERT_TRUE(binder != nullptr);
- ret = binder->linkToDeath(testDeathRecipient);
- EXPECT_EQ(NO_ERROR, ret);
- }
- IPCThreadState::self()->flushCommands();
- ret = testDeathRecipient->waitEvent(5);
- EXPECT_EQ(NO_ERROR, ret);
-#if 0 /* Is there an unlink api that does not require a strong reference? */
- ret = binder->unlinkToDeath(testDeathRecipient);
- EXPECT_EQ(NO_ERROR, ret);
-#endif
-}
-
-TEST_F(BinderLibTest, DeathNotificationWeakRef)
-{
- status_t ret;
- wp<IBinder> wbinder;
-
- sp<TestDeathRecipient> testDeathRecipient = new TestDeathRecipient();
-
- {
- sp<IBinder> binder = addServer();
- ASSERT_TRUE(binder != nullptr);
- ret = binder->linkToDeath(testDeathRecipient);
- EXPECT_EQ(NO_ERROR, ret);
- wbinder = binder;
- }
- IPCThreadState::self()->flushCommands();
- ret = testDeathRecipient->waitEvent(5);
- EXPECT_EQ(NO_ERROR, ret);
-#if 0 /* Is there an unlink api that does not require a strong reference? */
- ret = binder->unlinkToDeath(testDeathRecipient);
- EXPECT_EQ(NO_ERROR, ret);
-#endif
-}
-
TEST_F(BinderLibTest, DeathNotificationStrongRef)
{
status_t ret;
@@ -1015,9 +971,6 @@ TEST_F(BinderLibTest, WorkSourceRestored)
TEST_F(BinderLibTest, PropagateFlagSet)
{
- status_t ret;
- Parcel data, reply;
-
IPCThreadState::self()->clearPropagateWorkSource();
IPCThreadState::self()->setCallingWorkSourceUid(100);
EXPECT_EQ(true, IPCThreadState::self()->shouldPropagateWorkSource());
@@ -1025,9 +978,6 @@ TEST_F(BinderLibTest, PropagateFlagSet)
TEST_F(BinderLibTest, PropagateFlagCleared)
{
- status_t ret;
- Parcel data, reply;
-
IPCThreadState::self()->setCallingWorkSourceUid(100);
IPCThreadState::self()->clearPropagateWorkSource();
EXPECT_EQ(false, IPCThreadState::self()->shouldPropagateWorkSource());
@@ -1035,9 +985,6 @@ TEST_F(BinderLibTest, PropagateFlagCleared)
TEST_F(BinderLibTest, PropagateFlagRestored)
{
- status_t ret;
- Parcel data, reply;
-
int token = IPCThreadState::self()->setCallingWorkSourceUid(100);
IPCThreadState::self()->restoreCallingWorkSource(token);
@@ -1136,7 +1083,6 @@ class BinderLibTestService : public BBinder
case BINDER_LIB_TEST_ADD_POLL_SERVER:
case BINDER_LIB_TEST_ADD_SERVER: {
int ret;
- uint8_t buf[1] = { 0 };
int serverid;
if (m_id != 0) {
@@ -1399,7 +1345,6 @@ class BinderLibTestService : public BBinder
bool m_serverStartRequested;
sp<IBinder> m_serverStarted;
sp<IBinder> m_strongRef;
- bool m_callbackPending;
sp<IBinder> m_callback;
};
@@ -1461,7 +1406,7 @@ int run_server(int index, int readypipefd, bool usePoll)
* We simulate a single-threaded process using the binder poll
* interface; besides handling binder commands, it can also
* issue outgoing transactions, by storing a callback in
- * m_callback and setting m_callbackPending.
+ * m_callback.
*
* processPendingCall() will then issue that transaction.
*/
@@ -1488,8 +1433,6 @@ int run_server(int index, int readypipefd, bool usePoll)
}
int main(int argc, char **argv) {
- int ret;
-
if (argc == 4 && !strcmp(argv[1], "--servername")) {
binderservername = argv[2];
} else {
diff --git a/libs/binder/tests/binderSafeInterfaceTest.cpp b/libs/binder/tests/binderSafeInterfaceTest.cpp
index 3b1db27749..09f58cc833 100644
--- a/libs/binder/tests/binderSafeInterfaceTest.cpp
+++ b/libs/binder/tests/binderSafeInterfaceTest.cpp
@@ -75,7 +75,7 @@ public:
private:
int32_t mValue = 0;
- uint8_t mPadding[4] = {}; // Avoids a warning from -Wpadded
+ __attribute__((unused)) uint8_t mPadding[4] = {}; // Avoids a warning from -Wpadded
};
struct TestFlattenable : Flattenable<TestFlattenable> {
@@ -743,6 +743,7 @@ TEST_F(SafeInterfaceTest, TestIncremementParcelableVector) {
const std::vector<TestParcelable> a{TestParcelable{1}, TestParcelable{2}};
std::vector<TestParcelable> aPlusOne;
status_t result = mSafeInterfaceTest->increment(a, &aPlusOne);
+ ASSERT_EQ(NO_ERROR, result);
ASSERT_EQ(a.size(), aPlusOne.size());
for (size_t i = 0; i < a.size(); ++i) {
ASSERT_EQ(a[i].getValue() + 1, aPlusOne[i].getValue());
diff --git a/libs/binder/tests/binderValueTypeTest.cpp b/libs/binder/tests/binderValueTypeTest.cpp
deleted file mode 100644
index f8922b0784..0000000000
--- a/libs/binder/tests/binderValueTypeTest.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits>
-#include <cstddef>
-#include <vector>
-
-#include "android-base/file.h"
-#include <gtest/gtest.h>
-
-#include <binder/Parcel.h>
-#include <binder/Value.h>
-#include <binder/Debug.h>
-
-using ::android::binder::Value;
-using ::android::os::PersistableBundle;
-using ::android::String16;
-using ::std::vector;
-
-#define VALUE_TYPE_TEST(T, TYPENAME, VAL) \
- TEST(ValueType, Handles ## TYPENAME) { \
- T x = VAL; \
- T y = T(); \
- Value value = VAL; \
- ASSERT_FALSE(value.empty()); \
- ASSERT_TRUE(value.is ## TYPENAME ()); \
- ASSERT_TRUE(value.get ## TYPENAME (&y)); \
- ASSERT_EQ(x, y); \
- ASSERT_EQ(value, Value(y)); \
- value.put ## TYPENAME (x); \
- ASSERT_EQ(value, Value(y)); \
- value = Value(); \
- ASSERT_TRUE(value.empty()); \
- ASSERT_NE(value, Value(y)); \
- value = y; \
- ASSERT_EQ(value, Value(x)); \
- }
-
-#define VALUE_TYPE_VECTOR_TEST(T, TYPENAME, VAL) \
- TEST(ValueType, Handles ## TYPENAME ## Vector) { \
- vector<T> x; \
- vector<T> y; \
- x.push_back(VAL); \
- x.push_back(T()); \
- Value value(x); \
- ASSERT_FALSE(value.empty()); \
- ASSERT_TRUE(value.is ## TYPENAME ## Vector()); \
- ASSERT_TRUE(value.get ## TYPENAME ## Vector(&y)); \
- ASSERT_EQ(x, y); \
- ASSERT_EQ(value, Value(y)); \
- value.put ## TYPENAME ## Vector(x); \
- ASSERT_EQ(value, Value(y)); \
- value = Value(); \
- ASSERT_TRUE(value.empty()); \
- ASSERT_NE(value, Value(y)); \
- value = y; \
- ASSERT_EQ(value, Value(x)); \
- }
-
-VALUE_TYPE_TEST(bool, Boolean, true)
-VALUE_TYPE_TEST(int32_t, Int, 31337)
-VALUE_TYPE_TEST(int64_t, Long, 13370133701337L)
-VALUE_TYPE_TEST(double, Double, 3.14159265358979323846)
-VALUE_TYPE_TEST(String16, String, String16("Lovely"))
-
-VALUE_TYPE_VECTOR_TEST(bool, Boolean, true)
-VALUE_TYPE_VECTOR_TEST(int32_t, Int, 31337)
-VALUE_TYPE_VECTOR_TEST(int64_t, Long, 13370133701337L)
-VALUE_TYPE_VECTOR_TEST(double, Double, 3.14159265358979323846)
-VALUE_TYPE_VECTOR_TEST(String16, String, String16("Lovely"))
-
-VALUE_TYPE_TEST(PersistableBundle, PersistableBundle, PersistableBundle())
-
-TEST(ValueType, HandlesClear) {
- Value value;
- ASSERT_TRUE(value.empty());
- value.putInt(31337);
- ASSERT_FALSE(value.empty());
- value.clear();
- ASSERT_TRUE(value.empty());
-}
-
-TEST(ValueType, HandlesSwap) {
- Value value_a, value_b;
- int32_t int_x;
- value_a.putInt(31337);
- ASSERT_FALSE(value_a.empty());
- ASSERT_TRUE(value_b.empty());
- value_a.swap(value_b);
- ASSERT_FALSE(value_b.empty());
- ASSERT_TRUE(value_a.empty());
- ASSERT_TRUE(value_b.getInt(&int_x));
- ASSERT_EQ(31337, int_x);
-}
diff --git a/libs/binder/tests/schd-dbg.cpp b/libs/binder/tests/schd-dbg.cpp
index ec9534abac..ab4c56a6af 100644
--- a/libs/binder/tests/schd-dbg.cpp
+++ b/libs/binder/tests/schd-dbg.cpp
@@ -290,6 +290,7 @@ static void* thread_start(void* p) {
sta = tickNow();
status_t ret = workers[target]->transact(BINDER_NOP, data, &reply);
+ ASSERT(ret == NO_ERROR);
end = tickNow();
results_fifo->add_time(tickNano(sta, end));
diff --git a/libs/dumputils/Android.bp b/libs/dumputils/Android.bp
index 3412e14f17..e23de8e389 100644
--- a/libs/dumputils/Android.bp
+++ b/libs/dumputils/Android.bp
@@ -17,7 +17,6 @@ cc_library {
shared_libs: [
"libbase",
- "libbinder",
"libhidlbase",
"libhidltransport",
"liblog",
diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp
index 6c9d81ab57..9590df7c8f 100644
--- a/libs/gui/ISurfaceComposer.cpp
+++ b/libs/gui/ISurfaceComposer.cpp
@@ -88,7 +88,7 @@ public:
data.writeStrongBinder(applyToken);
commands.write(data);
data.writeInt64(desiredPresentTime);
- data.writeWeakBinder(uncacheBuffer.token);
+ data.writeStrongBinder(uncacheBuffer.token.promote());
data.writeUint64(uncacheBuffer.id);
if (data.writeVectorSize(listenerCallbacks) == NO_ERROR) {
@@ -1035,7 +1035,7 @@ status_t BnSurfaceComposer::onTransact(
int64_t desiredPresentTime = data.readInt64();
client_cache_t uncachedBuffer;
- uncachedBuffer.token = data.readWeakBinder();
+ uncachedBuffer.token = data.readStrongBinder();
uncachedBuffer.id = data.readUint64();
std::vector<ListenerCallbacks> listenerCallbacks;
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index 6066421faf..42eb9213d6 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -87,7 +87,7 @@ status_t layer_state_t::write(Parcel& output) const
colorTransform.asArray(), 16 * sizeof(float));
output.writeFloat(cornerRadius);
output.writeBool(hasListenerCallbacks);
- output.writeWeakBinder(cachedBuffer.token);
+ output.writeStrongBinder(cachedBuffer.token.promote());
output.writeUint64(cachedBuffer.id);
output.writeParcelable(metadata);
@@ -157,7 +157,7 @@ status_t layer_state_t::read(const Parcel& input)
colorTransform = mat4(static_cast<const float*>(input.readInplace(16 * sizeof(float))));
cornerRadius = input.readFloat();
hasListenerCallbacks = input.readBool();
- cachedBuffer.token = input.readWeakBinder();
+ cachedBuffer.token = input.readStrongBinder();
cachedBuffer.id = input.readUint64();
input.readParcelable(&metadata);
diff --git a/libs/sensorprivacy/Android.bp b/libs/sensorprivacy/Android.bp
index e0e3469fbb..4a606ffec2 100644
--- a/libs/sensorprivacy/Android.bp
+++ b/libs/sensorprivacy/Android.bp
@@ -28,8 +28,7 @@ cc_library_shared {
],
srcs: [
- "aidl/android/hardware/ISensorPrivacyListener.aidl",
- "aidl/android/hardware/ISensorPrivacyManager.aidl",
+ ":libsensorprivacy_aidl",
"SensorPrivacyManager.cpp",
],
@@ -45,3 +44,12 @@ cc_library_shared {
export_shared_lib_headers: ["libbinder"],
}
+
+filegroup {
+ name: "libsensorprivacy_aidl",
+ srcs: [
+ "aidl/android/hardware/ISensorPrivacyListener.aidl",
+ "aidl/android/hardware/ISensorPrivacyManager.aidl",
+ ],
+ path: "aidl",
+}
diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp
index 0407d8802c..2cc6857744 100644
--- a/libs/ui/Android.bp
+++ b/libs/ui/Android.bp
@@ -95,7 +95,6 @@ cc_library_shared {
"android.hardware.graphics.mapper@3.0",
"libbase",
"libcutils",
- "libhardware",
"libhidlbase",
"libhidltransport",
"libhwbinder",
diff --git a/libs/vr/libbufferhubqueue/Android.bp b/libs/vr/libbufferhubqueue/Android.bp
index 9f72c05f0c..77c79112de 100644
--- a/libs/vr/libbufferhubqueue/Android.bp
+++ b/libs/vr/libbufferhubqueue/Android.bp
@@ -26,10 +26,8 @@ staticLibraries = [
]
sharedLibraries = [
- "libbase",
"libbinder",
"libcutils",
- "libhardware",
"liblog",
"libui",
"libutils",