Merge "libbinder: remove Map"
diff --git a/cmds/lshal/ListCommand.cpp b/cmds/lshal/ListCommand.cpp
index c706d91..ad7e4c4 100644
--- a/cmds/lshal/ListCommand.cpp
+++ b/cmds/lshal/ListCommand.cpp
@@ -975,7 +975,8 @@
" - DM: if the HAL is in the device manifest\n"
" - DC: if the HAL is in the device compatibility matrix\n"
" - FM: if the HAL is in the framework manifest\n"
- " - FC: if the HAL is in the framework compatibility matrix"});
+ " - FC: if the HAL is in the framework compatibility matrix\n"
+ " - X: if the HAL is in none of the above lists"});
mOptions.push_back({'S', "service-status", no_argument, v++, [](ListCommand* thiz, const char*) {
thiz->mSelectedColumns.push_back(TableColumnType::SERVICE_STATUS);
return OK;
diff --git a/libs/android_runtime_lazy/Android.bp b/libs/android_runtime_lazy/Android.bp
index 84a4f3a..9284acb 100644
--- a/libs/android_runtime_lazy/Android.bp
+++ b/libs/android_runtime_lazy/Android.bp
@@ -48,6 +48,7 @@
shared_libs: [
"liblog",
+ "libutils",
],
required: [
diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp
index 96ee295..967ffd5 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 @@
{
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 67f968a..f35803c 100644
--- a/libs/binder/BpBinder.cpp
+++ b/libs/binder/BpBinder.cpp
@@ -186,10 +186,7 @@
{
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)
diff --git a/libs/binder/BufferedTextOutput.cpp b/libs/binder/BufferedTextOutput.cpp
index 857bbf9..a7d5240 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 2f4dbee..41a0111 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 fb0d521..c839ba5 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 b307e3e..cc0022a 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 bf107d0..acc6bf4 100644
--- a/libs/binder/IPCThreadState.cpp
+++ b/libs/binder/IPCThreadState.cpp
@@ -31,7 +31,6 @@
#include <utils/threads.h>
#include <private/binder/binder_module.h>
-#include <private/binder/Static.h>
#include <atomic>
#include <errno.h>
@@ -44,6 +43,8 @@
#include <sys/resource.h>
#include <unistd.h>
+#include "Static.h"
+
#if LOG_NDEBUG
#define IF_LOG_TRANSACTIONS() if (false)
diff --git a/libs/binder/IPermissionController.cpp b/libs/binder/IPermissionController.cpp
index 6b99150..bf2f20a 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 159763d..1e11941 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 0203d41..9d816e8 100644
--- a/libs/binder/IServiceManager.cpp
+++ b/libs/binder/IServiceManager.cpp
@@ -28,7 +28,7 @@
#include <utils/String8.h>
#include <utils/SystemClock.h>
-#include <private/binder/Static.h>
+#include "Static.h"
#include <unistd.h>
diff --git a/libs/binder/IShellCallback.cpp b/libs/binder/IShellCallback.cpp
index 6c697de..88cc603 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 916ba38..7ccb171 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -47,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))
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp
index b25cd7b..a07b3a0 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>
@@ -40,7 +39,7 @@
#include <sys/stat.h>
#include <sys/types.h>
-#define DEFAULT_BINDER_VM_SIZE ((1 * 1024 * 1024) - sysconf(_SC_PAGE_SIZE) * 2)
+#define BINDER_VM_SIZE ((1 * 1024 * 1024) - sysconf(_SC_PAGE_SIZE) * 2)
#define DEFAULT_MAX_BINDER_THREADS 15
#ifdef __ANDROID_VNDK__
@@ -77,13 +76,7 @@
if (gProcess != nullptr) {
return gProcess;
}
- gProcess = new ProcessState(kDefaultDriver, DEFAULT_BINDER_VM_SIZE);
- return gProcess;
-}
-
-sp<ProcessState> ProcessState::selfOrNull()
-{
- Mutex::Autolock _l(gProcessMutex);
+ gProcess = new ProcessState(kDefaultDriver);
return gProcess;
}
@@ -104,25 +97,14 @@
driver = "/dev/binder";
}
- gProcess = new ProcessState(driver, DEFAULT_BINDER_VM_SIZE);
+ gProcess = new ProcessState(driver);
return gProcess;
}
-sp<ProcessState> ProcessState::initWithMmapSize(size_t mmap_size) {
- Mutex::Autolock _l(gProcessMutex);
- if (gProcess != nullptr) {
- LOG_ALWAYS_FATAL_IF(mmap_size != gProcess->getMmapSize(),
- "ProcessState already initialized with a different mmap size.");
- return gProcess;
- }
-
- gProcess = new ProcessState(kDefaultDriver, mmap_size);
- return gProcess;
-}
-
-void ProcessState::setContextObject(const sp<IBinder>& object)
+sp<ProcessState> ProcessState::selfOrNull()
{
- setContextObject(object, String16("default"));
+ Mutex::Autolock _l(gProcessMutex);
+ return gProcess;
}
sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& /*caller*/)
@@ -130,48 +112,6 @@
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);
@@ -181,41 +121,33 @@
}
}
-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);
- }
-
- 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));
- }
+ int dummy = 0;
+ result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &dummy);
}
- return mManagesContexts;
+
+ if (result == -1) {
+ mBinderContextCheckFunc = nullptr;
+ mBinderContextUserData = nullptr;
+ ALOGE("Binder ioctl to become context manager failed: %s\n", strerror(errno));
+ }
+
+ return result == 0;
}
// Get references to userspace objects held by the kernel binder driver
@@ -249,10 +181,6 @@
return count;
}
-size_t ProcessState::getMmapSize() {
- return mMmapSize;
-}
-
void ProcessState::setCallRestriction(CallRestriction restriction) {
LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull(), "Call restrictions must be set before the threadpool is started.");
@@ -437,7 +365,7 @@
return fd;
}
-ProcessState::ProcessState(const char *driver, size_t mmap_size)
+ProcessState::ProcessState(const char *driver)
: mDriverName(String8(driver))
, mDriverFD(open_driver(driver))
, mVMStart(MAP_FAILED)
@@ -446,17 +374,15 @@
, mExecutingThreadsCount(0)
, mMaxThreads(DEFAULT_MAX_BINDER_THREADS)
, mStarvationStartTimeMs(0)
- , mManagesContexts(false)
, mBinderContextCheckFunc(nullptr)
, mBinderContextUserData(nullptr)
, mThreadPoolStarted(false)
, mThreadPoolSeq(1)
- , mMmapSize(mmap_size)
, mCallRestriction(CallRestriction::NONE)
{
if (mDriverFD >= 0) {
// mmap the binder, providing a chunk of virtual address space to receive transactions.
- mVMStart = mmap(nullptr, mMmapSize, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0);
+ mVMStart = mmap(nullptr, BINDER_VM_SIZE, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0);
if (mVMStart == MAP_FAILED) {
// *sigh*
ALOGE("Using %s failed: unable to mmap transaction memory.\n", mDriverName.c_str());
@@ -473,7 +399,7 @@
{
if (mDriverFD >= 0) {
if (mVMStart != MAP_FAILED) {
- munmap(mVMStart, mMmapSize);
+ munmap(mVMStart, BINDER_VM_SIZE);
}
close(mDriverFD);
}
diff --git a/libs/binder/Static.cpp b/libs/binder/Static.cpp
index 8625c6f..a6fd8c4 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>
diff --git a/libs/binder/include/private/binder/Static.h b/libs/binder/Static.h
similarity index 100%
rename from libs/binder/include/private/binder/Static.h
rename to libs/binder/Static.h
diff --git a/libs/binder/TEST_MAPPING b/libs/binder/TEST_MAPPING
index 3938fe6..01e57d3 100644
--- a/libs/binder/TEST_MAPPING
+++ b/libs/binder/TEST_MAPPING
@@ -1,10 +1,16 @@
{
"presubmit": [
{
+ "name": "binderSafeInterfaceTest"
+ },
+ {
"name": "binderDriverInterfaceTest"
},
{
"name": "binderTextOutputTest"
+ },
+ {
+ "name": "binderLibTest"
}
]
}
diff --git a/libs/binder/include/binder/ProcessState.h b/libs/binder/include/binder/ProcessState.h
index 1622ba2..3af9eed 100644
--- a/libs/binder/include/binder/ProcessState.h
+++ b/libs/binder/include/binder/ProcessState.h
@@ -36,8 +36,6 @@
public:
static sp<ProcessState> self();
static sp<ProcessState> selfOrNull();
- // Note: don't call self() or selfOrNull() before initWithMmapSize()
- static sp<ProcessState> initWithMmapSize(size_t mmapSize); // size in bytes
/* initWithDriver() can be used to configure libbinder to use
* a different binder driver dev node. It must be called *before*
@@ -47,21 +45,14 @@
*/
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);
@@ -78,7 +69,6 @@
String8 getDriverName();
ssize_t getKernelReferences(size_t count, uintptr_t* buf);
- size_t getMmapSize();
enum class CallRestriction {
// all calls okay
@@ -95,7 +85,7 @@
private:
friend class IPCThreadState;
- explicit ProcessState(const char* driver, size_t mmap_size);
+ explicit ProcessState(const char* driver);
~ProcessState();
ProcessState(const ProcessState& o);
@@ -124,23 +114,15 @@
int64_t mStarvationStartTimeMs;
mutable Mutex mLock; // protects everything below.
- // TODO: mManagesContexts is often accessed without the lock.
- // Explain why that's safe.
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;
- const size_t mMmapSize;
CallRestriction mCallRestriction;
};
diff --git a/libs/binder/tests/binderDriverInterfaceTest.cpp b/libs/binder/tests/binderDriverInterfaceTest.cpp
index 6508bb1..77ebac8 100644
--- a/libs/binder/tests/binderDriverInterfaceTest.cpp
+++ b/libs/binder/tests/binderDriverInterfaceTest.cpp
@@ -286,13 +286,7 @@
EXPECT_EQ(0u, br.arg2.cookie);
EXPECT_EQ(0u, br.arg2.code);
EXPECT_EQ(0u, br.arg2.flags);
-
- // ping returns a 4 byte header in libbinder, but the original
- // C implementation of servicemanager returns a 0 byte header
- if (br.arg2.data_size != 0 && br.arg2.data_size != 4) {
- ADD_FAILURE() << br.arg2.data_size << " is expected to be 0 or 4";
- }
-
+ EXPECT_EQ(0u, br.arg2.data_size);
EXPECT_EQ(0u, br.arg2.offsets_size);
SCOPED_TRACE("3rd WriteRead");
diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp
index 99a71bd..cf83faa 100644
--- a/libs/binder/tests/binderLibTest.cpp
+++ b/libs/binder/tests/binderLibTest.cpp
@@ -550,50 +550,6 @@
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;
diff --git a/libs/dumputils/Android.bp b/libs/dumputils/Android.bp
index 3412e14..e23de8e 100644
--- a/libs/dumputils/Android.bp
+++ b/libs/dumputils/Android.bp
@@ -17,7 +17,6 @@
shared_libs: [
"libbase",
- "libbinder",
"libhidlbase",
"libhidltransport",
"liblog",
diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp
index ec7f927..6f570af 100644
--- a/libs/ui/Android.bp
+++ b/libs/ui/Android.bp
@@ -84,7 +84,6 @@
"android.hardware.configstore-utils",
"libbase",
"libcutils",
- "libhardware",
"libhidlbase",
"libhidltransport",
"libhwbinder",