summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Android.mk39
-rw-r--r--AppOpsManager.cpp141
-rw-r--r--Binder.cpp10
-rw-r--r--BpBinder.cpp6
-rw-r--r--BufferedTextOutput.cpp4
-rw-r--r--Debug.cpp2
-rw-r--r--IAppOpsCallback.cpp69
-rw-r--r--IAppOpsService.cpp214
-rw-r--r--IBatteryStats.cpp244
-rw-r--r--IInterface.cpp2
-rw-r--r--IMediaResourceMonitor.cpp62
-rw-r--r--IMemory.cpp4
-rw-r--r--IPCThreadState.cpp8
-rw-r--r--IPermissionController.cpp4
-rw-r--r--IProcessInfoService.cpp91
-rw-r--r--IResultReceiver.cpp4
-rw-r--r--IServiceManager.cpp6
-rw-r--r--MemoryBase.cpp2
-rw-r--r--MemoryDealer.cpp6
-rw-r--r--MemoryHeapBase.cpp2
-rw-r--r--Parcel.cpp14
-rw-r--r--PermissionCache.cpp113
-rw-r--r--PersistableBundle.cpp6
-rw-r--r--ProcessInfoService.cpp70
-rw-r--r--ProcessState.cpp8
-rw-r--r--Static.cpp4
-rw-r--r--Status.cpp2
-rw-r--r--TextOutput.cpp4
-rw-r--r--include/hwbinder/AppOpsManager.h118
-rw-r--r--include/hwbinder/Binder.h2
-rw-r--r--include/hwbinder/BinderService.h8
-rw-r--r--include/hwbinder/BpBinder.h2
-rw-r--r--include/hwbinder/BufferedTextOutput.h2
-rw-r--r--include/hwbinder/IAppOpsCallback.h55
-rw-r--r--include/hwbinder/IAppOpsService.h78
-rw-r--r--include/hwbinder/IBatteryStats.h79
-rw-r--r--include/hwbinder/IInterface.h2
-rw-r--r--include/hwbinder/IMediaResourceMonitor.h55
-rw-r--r--include/hwbinder/IMemory.h2
-rw-r--r--include/hwbinder/IPCThreadState.h4
-rw-r--r--include/hwbinder/IPermissionController.h2
-rw-r--r--include/hwbinder/IProcessInfoService.h49
-rw-r--r--include/hwbinder/IResultReceiver.h2
-rw-r--r--include/hwbinder/IServiceManager.h4
-rw-r--r--include/hwbinder/MemoryBase.h2
-rw-r--r--include/hwbinder/MemoryDealer.h4
-rw-r--r--include/hwbinder/MemoryHeapBase.h2
-rw-r--r--include/hwbinder/Parcel.h4
-rw-r--r--include/hwbinder/PermissionCache.h80
-rw-r--r--include/hwbinder/PersistableBundle.h2
-rw-r--r--include/hwbinder/ProcessInfoService.h65
-rw-r--r--include/hwbinder/ProcessState.h2
-rw-r--r--include/hwbinder/Status.h2
-rw-r--r--tests/Android.mk42
-rw-r--r--tests/binderDriverInterfaceTest.cpp353
-rw-r--r--tests/binderLibTest.cpp946
-rw-r--r--tests/binderThroughputTest.cpp317
57 files changed, 79 insertions, 3347 deletions
diff --git a/Android.mk b/Android.mk
index 74bad7a..1d03d5d 100644
--- a/Android.mk
+++ b/Android.mk
@@ -13,62 +13,35 @@
# limitations under the License.
# we have the common sources, plus some device-specific stuff
-sources := \
- AppOpsManager.cpp \
- Binder.cpp \
- BpBinder.cpp \
- BufferedTextOutput.cpp \
- Debug.cpp \
- IAppOpsCallback.cpp \
- IAppOpsService.cpp \
- IBatteryStats.cpp \
- IInterface.cpp \
- IMediaResourceMonitor.cpp \
- IMemory.cpp \
- IPCThreadState.cpp \
- IPermissionController.cpp \
- IProcessInfoService.cpp \
- IResultReceiver.cpp \
- IServiceManager.cpp \
- MemoryBase.cpp \
- MemoryDealer.cpp \
- MemoryHeapBase.cpp \
- Parcel.cpp \
- PermissionCache.cpp \
- PersistableBundle.cpp \
- ProcessInfoService.cpp \
- ProcessState.cpp \
- Static.cpp \
- Status.cpp \
- TextOutput.cpp \
-
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_MODULE := libbinder
+LOCAL_MODULE := libhwbinder
LOCAL_SHARED_LIBRARIES := libbase liblog libcutils libutils
LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := libbase libutils
LOCAL_CLANG := true
LOCAL_SANITIZE := integer
-LOCAL_SRC_FILES := $(sources)
+LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
ifneq ($(TARGET_USES_64_BIT_BINDER),true)
ifneq ($(TARGET_IS_64_BIT),true)
LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1
endif
endif
LOCAL_CFLAGS += -Werror
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
-LOCAL_MODULE := libbinder
+LOCAL_MODULE := libhwbinder
LOCAL_STATIC_LIBRARIES := libbase libutils
LOCAL_EXPORT_STATIC_LIBRARY_HEADERS := libbase libutils
-LOCAL_SRC_FILES := $(sources)
+LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
ifneq ($(TARGET_USES_64_BIT_BINDER),true)
ifneq ($(TARGET_IS_64_BIT),true)
LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1
endif
endif
LOCAL_CFLAGS += -Werror
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
include $(BUILD_STATIC_LIBRARY)
diff --git a/AppOpsManager.cpp b/AppOpsManager.cpp
deleted file mode 100644
index f3b86ae..0000000
--- a/AppOpsManager.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (C) 2013 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 <mutex>
-#include <binder/AppOpsManager.h>
-#include <binder/Binder.h>
-#include <binder/IServiceManager.h>
-
-#include <utils/SystemClock.h>
-
-namespace android {
-
-namespace {
-
-#if defined(__BRILLO__)
-// Because Brillo has no application model, security policy is managed
-// statically (at build time) with SELinux controls.
-// As a consequence, it also never runs the AppOpsManager service.
-const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_ALLOWED;
-#else
-const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_IGNORED;
-#endif // defined(__BRILLO__)
-
-} // namespace
-
-static String16 _appops("appops");
-static pthread_mutex_t gTokenMutex = PTHREAD_MUTEX_INITIALIZER;
-static sp<IBinder> gToken;
-
-static const sp<IBinder>& getToken(const sp<IAppOpsService>& service) {
- pthread_mutex_lock(&gTokenMutex);
- if (gToken == NULL || gToken->pingBinder() != NO_ERROR) {
- gToken = service->getToken(new BBinder());
- }
- pthread_mutex_unlock(&gTokenMutex);
- return gToken;
-}
-
-AppOpsManager::AppOpsManager()
-{
-}
-
-#if defined(__BRILLO__)
-// There is no AppOpsService on Brillo
-sp<IAppOpsService> AppOpsManager::getService() { return NULL; }
-#else
-sp<IAppOpsService> AppOpsManager::getService()
-{
-
- std::lock_guard<Mutex> scoped_lock(mLock);
- int64_t startTime = 0;
- sp<IAppOpsService> service = mService;
- while (service == NULL || !IInterface::asBinder(service)->isBinderAlive()) {
- sp<IBinder> binder = defaultServiceManager()->checkService(_appops);
- if (binder == NULL) {
- // Wait for the app ops service to come back...
- if (startTime == 0) {
- startTime = uptimeMillis();
- ALOGI("Waiting for app ops service");
- } else if ((uptimeMillis()-startTime) > 10000) {
- ALOGW("Waiting too long for app ops service, giving up");
- service = NULL;
- break;
- }
- sleep(1);
- } else {
- service = interface_cast<IAppOpsService>(binder);
- mService = service;
- }
- }
- return service;
-}
-#endif // defined(__BRILLO__)
-
-int32_t AppOpsManager::checkOp(int32_t op, int32_t uid, const String16& callingPackage)
-{
- sp<IAppOpsService> service = getService();
- return service != NULL
- ? service->checkOperation(op, uid, callingPackage)
- : APP_OPS_MANAGER_UNAVAILABLE_MODE;
-}
-
-int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage) {
- sp<IAppOpsService> service = getService();
- return service != NULL
- ? service->noteOperation(op, uid, callingPackage)
- : APP_OPS_MANAGER_UNAVAILABLE_MODE;
-}
-
-int32_t AppOpsManager::startOp(int32_t op, int32_t uid, const String16& callingPackage) {
- sp<IAppOpsService> service = getService();
- return service != NULL
- ? service->startOperation(getToken(service), op, uid, callingPackage)
- : APP_OPS_MANAGER_UNAVAILABLE_MODE;
-}
-
-void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage) {
- sp<IAppOpsService> service = getService();
- if (service != NULL) {
- service->finishOperation(getToken(service), op, uid, callingPackage);
- }
-}
-
-void AppOpsManager::startWatchingMode(int32_t op, const String16& packageName,
- const sp<IAppOpsCallback>& callback) {
- sp<IAppOpsService> service = getService();
- if (service != NULL) {
- service->startWatchingMode(op, packageName, callback);
- }
-}
-
-void AppOpsManager::stopWatchingMode(const sp<IAppOpsCallback>& callback) {
- sp<IAppOpsService> service = getService();
- if (service != NULL) {
- service->stopWatchingMode(callback);
- }
-}
-
-int32_t AppOpsManager::permissionToOpCode(const String16& permission) {
- sp<IAppOpsService> service = getService();
- if (service != NULL) {
- return service->permissionToOpCode(permission);
- }
- return -1;
-}
-
-
-}; // namespace android
diff --git a/Binder.cpp b/Binder.cpp
index c4d47ca..7581d65 100644
--- a/Binder.cpp
+++ b/Binder.cpp
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-#include <binder/Binder.h>
+#include <hwbinder/Binder.h>
#include <atomic>
#include <utils/misc.h>
-#include <binder/BpBinder.h>
-#include <binder/IInterface.h>
-#include <binder/IResultReceiver.h>
-#include <binder/Parcel.h>
+#include <hwbinder/BpBinder.h>
+#include <hwbinder/IInterface.h>
+#include <hwbinder/IResultReceiver.h>
+#include <hwbinder/Parcel.h>
#include <stdio.h>
diff --git a/BpBinder.cpp b/BpBinder.cpp
index c0e0296..f3771bf 100644
--- a/BpBinder.cpp
+++ b/BpBinder.cpp
@@ -17,10 +17,10 @@
#define LOG_TAG "BpBinder"
//#define LOG_NDEBUG 0
-#include <binder/BpBinder.h>
+#include <hwbinder/BpBinder.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IResultReceiver.h>
+#include <hwbinder/IPCThreadState.h>
+#include <hwbinder/IResultReceiver.h>
#include <utils/Log.h>
#include <stdio.h>
diff --git a/BufferedTextOutput.cpp b/BufferedTextOutput.cpp
index a2443c0..7390349 100644
--- a/BufferedTextOutput.cpp
+++ b/BufferedTextOutput.cpp
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#include <binder/BufferedTextOutput.h>
-#include <binder/Debug.h>
+#include <hwbinder/BufferedTextOutput.h>
+#include <hwbinder/Debug.h>
#include <utils/Atomic.h>
#include <utils/Log.h>
diff --git a/Debug.cpp b/Debug.cpp
index a8f2da5..3c20c67 100644
--- a/Debug.cpp
+++ b/Debug.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include <binder/Debug.h>
+#include <hwbinder/Debug.h>
#include <utils/misc.h>
diff --git a/IAppOpsCallback.cpp b/IAppOpsCallback.cpp
deleted file mode 100644
index f9ec593..0000000
--- a/IAppOpsCallback.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2013 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 "AppOpsCallback"
-
-#include <binder/IAppOpsCallback.h>
-
-#include <utils/Log.h>
-#include <binder/Parcel.h>
-#include <utils/String8.h>
-
-#include <private/binder/Static.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------
-
-class BpAppOpsCallback : public BpInterface<IAppOpsCallback>
-{
-public:
- explicit BpAppOpsCallback(const sp<IBinder>& impl)
- : BpInterface<IAppOpsCallback>(impl)
- {
- }
-
- virtual void opChanged(int32_t op, const String16& packageName) {
- Parcel data, reply;
- data.writeInterfaceToken(IAppOpsCallback::getInterfaceDescriptor());
- data.writeInt32(op);
- data.writeString16(packageName);
- remote()->transact(OP_CHANGED_TRANSACTION, data, &reply);
- }
-};
-
-IMPLEMENT_META_INTERFACE(AppOpsCallback, "com.android.internal.app.IAppOpsCallback");
-
-// ----------------------------------------------------------------------
-
-status_t BnAppOpsCallback::onTransact(
- uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
- switch(code) {
- case OP_CHANGED_TRANSACTION: {
- CHECK_INTERFACE(IAppOpsCallback, data, reply);
- int32_t op = data.readInt32();
- String16 packageName = data.readString16();
- opChanged(op, packageName);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- default:
- return BBinder::onTransact(code, data, reply, flags);
- }
-}
-
-}; // namespace android
diff --git a/IAppOpsService.cpp b/IAppOpsService.cpp
deleted file mode 100644
index 638ae5c..0000000
--- a/IAppOpsService.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Copyright (C) 2013 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 "AppOpsService"
-
-#include <binder/IAppOpsService.h>
-
-#include <utils/Log.h>
-#include <binder/Parcel.h>
-#include <utils/String8.h>
-
-#include <private/binder/Static.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------
-
-class BpAppOpsService : public BpInterface<IAppOpsService>
-{
-public:
- explicit BpAppOpsService(const sp<IBinder>& impl)
- : BpInterface<IAppOpsService>(impl)
- {
- }
-
- virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) {
- Parcel data, reply;
- data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
- data.writeInt32(code);
- data.writeInt32(uid);
- data.writeString16(packageName);
- remote()->transact(CHECK_OPERATION_TRANSACTION, data, &reply);
- // fail on exception
- if (reply.readExceptionCode() != 0) return MODE_ERRORED;
- return reply.readInt32();
- }
-
- virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName) {
- Parcel data, reply;
- data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
- data.writeInt32(code);
- data.writeInt32(uid);
- data.writeString16(packageName);
- remote()->transact(NOTE_OPERATION_TRANSACTION, data, &reply);
- // fail on exception
- if (reply.readExceptionCode() != 0) return MODE_ERRORED;
- return reply.readInt32();
- }
-
- virtual int32_t startOperation(const sp<IBinder>& token, int32_t code, int32_t uid,
- const String16& packageName) {
- Parcel data, reply;
- data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
- data.writeStrongBinder(token);
- data.writeInt32(code);
- data.writeInt32(uid);
- data.writeString16(packageName);
- remote()->transact(START_OPERATION_TRANSACTION, data, &reply);
- // fail on exception
- if (reply.readExceptionCode() != 0) return MODE_ERRORED;
- return reply.readInt32();
- }
-
- virtual void finishOperation(const sp<IBinder>& token, int32_t code, int32_t uid,
- const String16& packageName) {
- Parcel data, reply;
- data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
- data.writeStrongBinder(token);
- data.writeInt32(code);
- data.writeInt32(uid);
- data.writeString16(packageName);
- remote()->transact(FINISH_OPERATION_TRANSACTION, data, &reply);
- }
-
- virtual void startWatchingMode(int32_t op, const String16& packageName,
- const sp<IAppOpsCallback>& callback) {
- Parcel data, reply;
- data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
- data.writeInt32(op);
- data.writeString16(packageName);
- data.writeStrongBinder(IInterface::asBinder(callback));
- remote()->transact(START_WATCHING_MODE_TRANSACTION, data, &reply);
- }
-
- virtual void stopWatchingMode(const sp<IAppOpsCallback>& callback) {
- Parcel data, reply;
- data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
- data.writeStrongBinder(IInterface::asBinder(callback));
- remote()->transact(STOP_WATCHING_MODE_TRANSACTION, data, &reply);
- }
-
- virtual sp<IBinder> getToken(const sp<IBinder>& clientToken) {
- Parcel data, reply;
- data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
- data.writeStrongBinder(clientToken);
- remote()->transact(GET_TOKEN_TRANSACTION, data, &reply);
- // fail on exception
- if (reply.readExceptionCode() != 0) return NULL;
- return reply.readStrongBinder();
- }
-
-
- virtual int32_t permissionToOpCode(const String16& permission) {
- Parcel data, reply;
- data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
- data.writeString16(permission);
- remote()->transact(PERMISSION_TO_OP_CODE_TRANSACTION, data, &reply);
- // fail on exception
- if (reply.readExceptionCode() != 0) return -1;
- return reply.readInt32();
- }
-};
-
-IMPLEMENT_META_INTERFACE(AppOpsService, "com.android.internal.app.IAppOpsService");
-
-// ----------------------------------------------------------------------
-
-status_t BnAppOpsService::onTransact(
- uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
- //printf("AppOpsService received: "); data.print();
- switch(code) {
- case CHECK_OPERATION_TRANSACTION: {
- CHECK_INTERFACE(IAppOpsService, data, reply);
- int32_t code = data.readInt32();
- int32_t uid = data.readInt32();
- String16 packageName = data.readString16();
- int32_t res = checkOperation(code, uid, packageName);
- reply->writeNoException();
- reply->writeInt32(res);
- return NO_ERROR;
- } break;
- case NOTE_OPERATION_TRANSACTION: {
- CHECK_INTERFACE(IAppOpsService, data, reply);
- int32_t code = data.readInt32();
- int32_t uid = data.readInt32();
- String16 packageName = data.readString16();
- int32_t res = noteOperation(code, uid, packageName);
- reply->writeNoException();
- reply->writeInt32(res);
- return NO_ERROR;
- } break;
- case START_OPERATION_TRANSACTION: {
- CHECK_INTERFACE(IAppOpsService, data, reply);
- sp<IBinder> token = data.readStrongBinder();
- int32_t code = data.readInt32();
- int32_t uid = data.readInt32();
- String16 packageName = data.readString16();
- int32_t res = startOperation(token, code, uid, packageName);
- reply->writeNoException();
- reply->writeInt32(res);
- return NO_ERROR;
- } break;
- case FINISH_OPERATION_TRANSACTION: {
- CHECK_INTERFACE(IAppOpsService, data, reply);
- sp<IBinder> token = data.readStrongBinder();
- int32_t code = data.readInt32();
- int32_t uid = data.readInt32();
- String16 packageName = data.readString16();
- finishOperation(token, code, uid, packageName);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case START_WATCHING_MODE_TRANSACTION: {
- CHECK_INTERFACE(IAppOpsService, data, reply);
- int32_t op = data.readInt32();
- String16 packageName = data.readString16();
- sp<IAppOpsCallback> callback = interface_cast<IAppOpsCallback>(data.readStrongBinder());
- startWatchingMode(op, packageName, callback);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case STOP_WATCHING_MODE_TRANSACTION: {
- CHECK_INTERFACE(IAppOpsService, data, reply);
- sp<IAppOpsCallback> callback = interface_cast<IAppOpsCallback>(data.readStrongBinder());
- stopWatchingMode(callback);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case GET_TOKEN_TRANSACTION: {
- CHECK_INTERFACE(IAppOpsService, data, reply);
- sp<IBinder> clientToken = data.readStrongBinder();
- sp<IBinder> token = getToken(clientToken);
- reply->writeNoException();
- reply->writeStrongBinder(token);
- return NO_ERROR;
- } break;
- case PERMISSION_TO_OP_CODE_TRANSACTION: {
- CHECK_INTERFACE(IAppOpsService, data, reply);
- String16 permission = data.readString16();
- const int32_t opCode = permissionToOpCode(permission);
- reply->writeNoException();
- reply->writeInt32(opCode);
- return NO_ERROR;
- } break;
- default:
- return BBinder::onTransact(code, data, reply, flags);
- }
-}
-
-}; // namespace android
diff --git a/IBatteryStats.cpp b/IBatteryStats.cpp
deleted file mode 100644
index ad1e69f..0000000
--- a/IBatteryStats.cpp
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Copyright (C) 2013 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 <binder/IBatteryStats.h>
-
-#include <utils/Log.h>
-#include <binder/Parcel.h>
-#include <utils/String8.h>
-
-#include <private/binder/Static.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------
-
-class BpBatteryStats : public BpInterface<IBatteryStats>
-{
-public:
- explicit BpBatteryStats(const sp<IBinder>& impl)
- : BpInterface<IBatteryStats>(impl)
- {
- }
-
- virtual void noteStartSensor(int uid, int sensor) {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- data.writeInt32(uid);
- data.writeInt32(sensor);
- remote()->transact(NOTE_START_SENSOR_TRANSACTION, data, &reply);
- }
-
- virtual void noteStopSensor(int uid, int sensor) {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- data.writeInt32(uid);
- data.writeInt32(sensor);
- remote()->transact(NOTE_STOP_SENSOR_TRANSACTION, data, &reply);
- }
-
- virtual void noteStartVideo(int uid) {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- data.writeInt32(uid);
- remote()->transact(NOTE_START_VIDEO_TRANSACTION, data, &reply);
- }
-
- virtual void noteStopVideo(int uid) {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- data.writeInt32(uid);
- remote()->transact(NOTE_STOP_VIDEO_TRANSACTION, data, &reply);
- }
-
- virtual void noteStartAudio(int uid) {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- data.writeInt32(uid);
- remote()->transact(NOTE_START_AUDIO_TRANSACTION, data, &reply);
- }
-
- virtual void noteStopAudio(int uid) {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- data.writeInt32(uid);
- remote()->transact(NOTE_STOP_AUDIO_TRANSACTION, data, &reply);
- }
-
- virtual void noteResetVideo() {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- remote()->transact(NOTE_RESET_VIDEO_TRANSACTION, data, &reply);
- }
-
- virtual void noteResetAudio() {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- remote()->transact(NOTE_RESET_AUDIO_TRANSACTION, data, &reply);
- }
-
- virtual void noteFlashlightOn(int uid) {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- data.writeInt32(uid);
- remote()->transact(NOTE_FLASHLIGHT_ON_TRANSACTION, data, &reply);
- }
-
- virtual void noteFlashlightOff(int uid) {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- data.writeInt32(uid);
- remote()->transact(NOTE_FLASHLIGHT_OFF_TRANSACTION, data, &reply);
- }
-
- virtual void noteStartCamera(int uid) {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- data.writeInt32(uid);
- remote()->transact(NOTE_START_CAMERA_TRANSACTION, data, &reply);
- }
-
- virtual void noteStopCamera(int uid) {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- data.writeInt32(uid);
- remote()->transact(NOTE_STOP_CAMERA_TRANSACTION, data, &reply);
- }
-
- virtual void noteResetCamera() {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- remote()->transact(NOTE_RESET_CAMERA_TRANSACTION, data, &reply);
- }
-
- virtual void noteResetFlashlight() {
- Parcel data, reply;
- data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
- remote()->transact(NOTE_RESET_FLASHLIGHT_TRANSACTION, data, &reply);
- }
-
-};
-
-IMPLEMENT_META_INTERFACE(BatteryStats, "com.android.internal.app.IBatteryStats");
-
-// ----------------------------------------------------------------------
-
-status_t BnBatteryStats::onTransact(
- uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
- switch(code) {
- case NOTE_START_SENSOR_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- int uid = data.readInt32();
- int sensor = data.readInt32();
- noteStartSensor(uid, sensor);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case NOTE_STOP_SENSOR_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- int uid = data.readInt32();
- int sensor = data.readInt32();
- noteStopSensor(uid, sensor);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case NOTE_START_VIDEO_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- int uid = data.readInt32();
- noteStartVideo(uid);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case NOTE_STOP_VIDEO_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- int uid = data.readInt32();
- noteStopVideo(uid);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case NOTE_START_AUDIO_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- int uid = data.readInt32();
- noteStartAudio(uid);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case NOTE_STOP_AUDIO_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- int uid = data.readInt32();
- noteStopAudio(uid);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case NOTE_RESET_VIDEO_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- noteResetVideo();
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case NOTE_RESET_AUDIO_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- noteResetAudio();
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case NOTE_FLASHLIGHT_ON_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- int uid = data.readInt32();
- noteFlashlightOn(uid);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case NOTE_FLASHLIGHT_OFF_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- int uid = data.readInt32();
- noteFlashlightOff(uid);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case NOTE_START_CAMERA_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- int uid = data.readInt32();
- noteStartCamera(uid);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case NOTE_STOP_CAMERA_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- int uid = data.readInt32();
- noteStopCamera(uid);
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case NOTE_RESET_CAMERA_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- noteResetCamera();
- reply->writeNoException();
- return NO_ERROR;
- } break;
- case NOTE_RESET_FLASHLIGHT_TRANSACTION: {
- CHECK_INTERFACE(IBatteryStats, data, reply);
- noteResetFlashlight();
- reply->writeNoException();
- return NO_ERROR;
- } break;
- default:
- return BBinder::onTransact(code, data, reply, flags);
- }
-}
-
-}; // namespace android
diff --git a/IInterface.cpp b/IInterface.cpp
index 2fcd3d9..5b71d73 100644
--- a/IInterface.cpp
+++ b/IInterface.cpp
@@ -16,7 +16,7 @@
#define LOG_TAG "IInterface"
#include <utils/Log.h>
-#include <binder/IInterface.h>
+#include <hwbinder/IInterface.h>
namespace android {
diff --git a/IMediaResourceMonitor.cpp b/IMediaResourceMonitor.cpp
deleted file mode 100644
index 4800f5b..0000000
--- a/IMediaResourceMonitor.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 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 <binder/IMediaResourceMonitor.h>
-#include <binder/Parcel.h>
-#include <utils/Errors.h>
-#include <sys/types.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------
-
-class BpMediaResourceMonitor : public BpInterface<IMediaResourceMonitor> {
-public:
- BpMediaResourceMonitor(const sp<IBinder>& impl)
- : BpInterface<IMediaResourceMonitor>(impl) {}
-
- virtual void notifyResourceGranted(/*in*/ int32_t pid, /*in*/ const int32_t type)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IMediaResourceMonitor::getInterfaceDescriptor());
- data.writeInt32(pid);
- data.writeInt32(type);
- remote()->transact(NOTIFY_RESOURCE_GRANTED, data, &reply, IBinder::FLAG_ONEWAY);
- }
-};
-
-IMPLEMENT_META_INTERFACE(MediaResourceMonitor, "android.media.IMediaResourceMonitor");
-
-// ----------------------------------------------------------------------
-
-status_t BnMediaResourceMonitor::onTransact( uint32_t code, const Parcel& data, Parcel* reply,
- uint32_t flags) {
- switch(code) {
- case NOTIFY_RESOURCE_GRANTED: {
- CHECK_INTERFACE(IMediaResourceMonitor, data, reply);
- int32_t pid = data.readInt32();
- const int32_t type = data.readInt32();
- notifyResourceGranted(/*in*/ pid, /*in*/ type);
- return NO_ERROR;
- } break;
- default:
- return BBinder::onTransact(code, data, reply, flags);
- }
-}
-
-// ----------------------------------------------------------------------
-
-}; // namespace android
diff --git a/IMemory.cpp b/IMemory.cpp
index 7bf2d17..81d7c02 100644
--- a/IMemory.cpp
+++ b/IMemory.cpp
@@ -25,12 +25,12 @@
#include <sys/types.h>
#include <sys/mman.h>
-#include <binder/IMemory.h>
+#include <hwbinder/IMemory.h>
#include <cutils/log.h>
#include <utils/KeyedVector.h>
#include <utils/threads.h>
#include <utils/Atomic.h>
-#include <binder/Parcel.h>
+#include <hwbinder/Parcel.h>
#include <utils/CallStack.h>
#define VERBOSE 0
diff --git a/IPCThreadState.cpp b/IPCThreadState.cpp
index 9b5f0d7..6c0b7a0 100644
--- a/IPCThreadState.cpp
+++ b/IPCThreadState.cpp
@@ -16,11 +16,11 @@
#define LOG_TAG "IPCThreadState"
-#include <binder/IPCThreadState.h>
+#include <hwbinder/IPCThreadState.h>
-#include <binder/Binder.h>
-#include <binder/BpBinder.h>
-#include <binder/TextOutput.h>
+#include <hwbinder/Binder.h>
+#include <hwbinder/BpBinder.h>
+#include <hwbinder/TextOutput.h>
#include <cutils/sched_policy.h>
#include <utils/Log.h>
diff --git a/IPermissionController.cpp b/IPermissionController.cpp
index 674bddf..403174f 100644
--- a/IPermissionController.cpp
+++ b/IPermissionController.cpp
@@ -16,10 +16,10 @@
#define LOG_TAG "PermissionController"
-#include <binder/IPermissionController.h>
+#include <hwbinder/IPermissionController.h>
#include <utils/Log.h>
-#include <binder/Parcel.h>
+#include <hwbinder/Parcel.h>
#include <utils/String8.h>
#include <private/binder/Static.h>
diff --git a/IProcessInfoService.cpp b/IProcessInfoService.cpp
deleted file mode 100644
index 96e1a8c..0000000
--- a/IProcessInfoService.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 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.
- */
-
-#include <binder/IProcessInfoService.h>
-#include <binder/Parcel.h>
-#include <utils/Errors.h>
-#include <sys/types.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------
-
-class BpProcessInfoService : public BpInterface<IProcessInfoService> {
-public:
- explicit BpProcessInfoService(const sp<IBinder>& impl)
- : BpInterface<IProcessInfoService>(impl) {}
-
- virtual status_t getProcessStatesFromPids(size_t length, /*in*/ int32_t* pids,
- /*out*/ int32_t* states)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IProcessInfoService::getInterfaceDescriptor());
- data.writeInt32Array(length, pids);
- data.writeInt32(length); // write length of output array, used by java AIDL stubs
- status_t err = remote()->transact(GET_PROCESS_STATES_FROM_PIDS, data, &reply);
- if (err != NO_ERROR || ((err = reply.readExceptionCode()) != NO_ERROR)) {
- return err;
- }
- int32_t replyLen = reply.readInt32();
- if (static_cast<size_t>(replyLen) != length) {
- return NOT_ENOUGH_DATA;
- }
- if (replyLen > 0 && (err = reply.read(states, length * sizeof(*states))) != NO_ERROR) {
- return err;
- }
- return reply.readInt32();
- }
-
- virtual status_t getProcessStatesAndOomScoresFromPids(size_t length,
- /*in*/ int32_t* pids, /*out*/ int32_t* states, /*out*/ int32_t* scores)
- {
- Parcel data, reply;
- data.writeInterfaceToken(IProcessInfoService::getInterfaceDescriptor());
- data.writeInt32Array(length, pids);
- // write length of output arrays, used by java AIDL stubs
- data.writeInt32(length);
- data.writeInt32(length);
- status_t err = remote()->transact(
- GET_PROCESS_STATES_AND_OOM_SCORES_FROM_PIDS, data, &reply);
- if (err != NO_ERROR
- || ((err = reply.readExceptionCode()) != NO_ERROR)) {
- return err;
- }
- int32_t replyLen = reply.readInt32();
- if (static_cast<size_t>(replyLen) != length) {
- return NOT_ENOUGH_DATA;
- }
- if (replyLen > 0 && (err = reply.read(
- states, length * sizeof(*states))) != NO_ERROR) {
- return err;
- }
- replyLen = reply.readInt32();
- if (static_cast<size_t>(replyLen) != length) {
- return NOT_ENOUGH_DATA;
- }
- if (replyLen > 0 && (err = reply.read(
- scores, length * sizeof(*scores))) != NO_ERROR) {
- return err;
- }
- return reply.readInt32();
- }
-};
-
-IMPLEMENT_META_INTERFACE(ProcessInfoService, "android.os.IProcessInfoService");
-
-// ----------------------------------------------------------------------
-
-}; // namespace android
diff --git a/IResultReceiver.cpp b/IResultReceiver.cpp
index 2a22b69..559077f 100644
--- a/IResultReceiver.cpp
+++ b/IResultReceiver.cpp
@@ -16,10 +16,10 @@
#define LOG_TAG "ResultReceiver"
-#include <binder/IResultReceiver.h>
+#include <hwbinder/IResultReceiver.h>
#include <utils/Log.h>
-#include <binder/Parcel.h>
+#include <hwbinder/Parcel.h>
#include <utils/String8.h>
#include <private/binder/Static.h>
diff --git a/IServiceManager.cpp b/IServiceManager.cpp
index 2062b3b..0d5a0bf 100644
--- a/IServiceManager.cpp
+++ b/IServiceManager.cpp
@@ -16,11 +16,11 @@
#define LOG_TAG "ServiceManager"
-#include <binder/IServiceManager.h>
+#include <hwbinder/IServiceManager.h>
#include <utils/Log.h>
-#include <binder/IPCThreadState.h>
-#include <binder/Parcel.h>
+#include <hwbinder/IPCThreadState.h>
+#include <hwbinder/Parcel.h>
#include <utils/String8.h>
#include <utils/SystemClock.h>
diff --git a/MemoryBase.cpp b/MemoryBase.cpp
index 033066b..c3a66b4 100644
--- a/MemoryBase.cpp
+++ b/MemoryBase.cpp
@@ -18,7 +18,7 @@
#include <stdlib.h>
#include <stdint.h>
-#include <binder/MemoryBase.h>
+#include <hwbinder/MemoryBase.h>
namespace android {
diff --git a/MemoryDealer.cpp b/MemoryDealer.cpp
index 2a15773..e0a0c0b 100644
--- a/MemoryDealer.cpp
+++ b/MemoryDealer.cpp
@@ -16,9 +16,9 @@
#define LOG_TAG "MemoryDealer"
-#include <binder/MemoryDealer.h>
-#include <binder/IPCThreadState.h>
-#include <binder/MemoryBase.h>
+#include <hwbinder/MemoryDealer.h>
+#include <hwbinder/IPCThreadState.h>
+#include <hwbinder/MemoryBase.h>
#include <utils/Log.h>
#include <utils/SortedVector.h>
diff --git a/MemoryHeapBase.cpp b/MemoryHeapBase.cpp
index 43a01e4..aaa2c90 100644
--- a/MemoryHeapBase.cpp
+++ b/MemoryHeapBase.cpp
@@ -29,7 +29,7 @@
#include <cutils/ashmem.h>
#include <cutils/atomic.h>
-#include <binder/MemoryHeapBase.h>
+#include <hwbinder/MemoryHeapBase.h>
namespace android {
diff --git a/Parcel.cpp b/Parcel.cpp
index 946e217..47ea4bb 100644
--- a/Parcel.cpp
+++ b/Parcel.cpp
@@ -30,13 +30,13 @@
#include <sys/resource.h>
#include <unistd.h>
-#include <binder/Binder.h>
-#include <binder/BpBinder.h>
-#include <binder/IPCThreadState.h>
-#include <binder/Parcel.h>
-#include <binder/ProcessState.h>
-#include <binder/Status.h>
-#include <binder/TextOutput.h>
+#include <hwbinder/Binder.h>
+#include <hwbinder/BpBinder.h>
+#include <hwbinder/IPCThreadState.h>
+#include <hwbinder/Parcel.h>
+#include <hwbinder/ProcessState.h>
+#include <hwbinder/Status.h>
+#include <hwbinder/TextOutput.h>
#include <cutils/ashmem.h>
#include <utils/Debug.h>
diff --git a/PermissionCache.cpp b/PermissionCache.cpp
deleted file mode 100644
index a503be8..0000000
--- a/PermissionCache.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) 2009 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 "PermissionCache"
-
-#include <stdint.h>
-#include <utils/Log.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
-#include <binder/PermissionCache.h>
-#include <utils/String8.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-
-ANDROID_SINGLETON_STATIC_INSTANCE(PermissionCache) ;
-
-// ----------------------------------------------------------------------------
-
-PermissionCache::PermissionCache() {
-}
-
-status_t PermissionCache::check(bool* granted,
- const String16& permission, uid_t uid) const {
- Mutex::Autolock _l(mLock);
- Entry e;
- e.name = permission;
- e.uid = uid;
- ssize_t index = mCache.indexOf(e);
- if (index >= 0) {
- *granted = mCache.itemAt(index).granted;
- return NO_ERROR;
- }
- return NAME_NOT_FOUND;
-}
-
-void PermissionCache::cache(const String16& permission,
- uid_t uid, bool granted) {
- Mutex::Autolock _l(mLock);
- Entry e;
- ssize_t index = mPermissionNamesPool.indexOf(permission);
- if (index > 0) {
- e.name = mPermissionNamesPool.itemAt(index);
- } else {
- mPermissionNamesPool.add(permission);
- e.name = permission;
- }
- // note, we don't need to store the pid, which is not actually used in
- // permission checks
- e.uid = uid;
- e.granted = granted;
- index = mCache.indexOf(e);
- if (index < 0) {
- mCache.add(e);
- }
-}
-
-void PermissionCache::purge() {
- Mutex::Autolock _l(mLock);
- mCache.clear();
-}
-
-bool PermissionCache::checkCallingPermission(const String16& permission) {
- return PermissionCache::checkCallingPermission(permission, NULL, NULL);
-}
-
-bool PermissionCache::checkCallingPermission(
- const String16& permission, int32_t* outPid, int32_t* outUid) {
- IPCThreadState* ipcState = IPCThreadState::self();
- pid_t pid = ipcState->getCallingPid();
- uid_t uid = ipcState->getCallingUid();
- if (outPid) *outPid = pid;
- if (outUid) *outUid = uid;
- return PermissionCache::checkPermission(permission, pid, uid);
-}
-
-bool PermissionCache::checkPermission(
- const String16& permission, pid_t pid, uid_t uid) {
- if ((uid == 0) || (pid == getpid())) {
- // root and ourselves is always okay
- return true;
- }
-
- PermissionCache& pc(PermissionCache::getInstance());
- bool granted = false;
- if (pc.check(&granted, permission, uid) != NO_ERROR) {
- nsecs_t t = -systemTime();
- granted = android::checkPermission(permission, pid, uid);
- t += systemTime();
- ALOGD("checking %s for uid=%d => %s (%d us)",
- String8(permission).string(), uid,
- granted?"granted":"denied", (int)ns2us(t));
- pc.cache(permission, uid, granted);
- }
- return granted;
-}
-
-// ---------------------------------------------------------------------------
-}; // namespace android
diff --git a/PersistableBundle.cpp b/PersistableBundle.cpp
index a20359f..33670b4 100644
--- a/PersistableBundle.cpp
+++ b/PersistableBundle.cpp
@@ -16,12 +16,12 @@
#define LOG_TAG "PersistableBundle"
-#include <binder/PersistableBundle.h>
+#include <hwbinder/PersistableBundle.h>
#include <limits>
-#include <binder/IBinder.h>
-#include <binder/Parcel.h>
+#include <hwbinder/IBinder.h>
+#include <hwbinder/Parcel.h>
#include <log/log.h>
#include <utils/Errors.h>
diff --git a/ProcessInfoService.cpp b/ProcessInfoService.cpp
deleted file mode 100644
index fb28643..0000000
--- a/ProcessInfoService.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 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.
- */
-
-#include <binder/ProcessInfoService.h>
-#include <binder/IServiceManager.h>
-
-#include <utils/Log.h>
-#include <utils/String16.h>
-
-namespace android {
-
-ProcessInfoService::ProcessInfoService() {
- updateBinderLocked();
-}
-
-status_t ProcessInfoService::getProcessStatesImpl(size_t length, /*in*/ int32_t* pids,
- /*out*/ int32_t* states) {
- status_t err = NO_ERROR;
- sp<IProcessInfoService> pis;
- mProcessInfoLock.lock();
- pis = mProcessInfoService;
- mProcessInfoLock.unlock();
-
- for (int i = 0; i < BINDER_ATTEMPT_LIMIT; i++) {
-
- if (pis != NULL) {
- err = pis->getProcessStatesFromPids(length, /*in*/ pids, /*out*/ states);
- if (err == NO_ERROR) return NO_ERROR; // success
- if (IInterface::asBinder(pis)->isBinderAlive()) return err;
- }
- sleep(1);
-
- mProcessInfoLock.lock();
- if (pis == mProcessInfoService) {
- updateBinderLocked();
- }
- pis = mProcessInfoService;
- mProcessInfoLock.unlock();
- }
-
- ALOGW("%s: Could not retrieve process states from ProcessInfoService after %d retries.",
- __FUNCTION__, BINDER_ATTEMPT_LIMIT);
-
- return TIMED_OUT;
-}
-
-void ProcessInfoService::updateBinderLocked() {
- const sp<IServiceManager> sm(defaultServiceManager());
- if (sm != NULL) {
- const String16 name("processinfo");
- mProcessInfoService = interface_cast<IProcessInfoService>(sm->checkService(name));
- }
-}
-
-ANDROID_SINGLETON_STATIC_INSTANCE(ProcessInfoService);
-
-}; // namespace android
diff --git a/ProcessState.cpp b/ProcessState.cpp
index 319d1d9..c452c32 100644
--- a/ProcessState.cpp
+++ b/ProcessState.cpp
@@ -18,14 +18,14 @@
#include <cutils/process_name.h>
-#include <binder/ProcessState.h>
+#include <hwbinder/ProcessState.h>
#include <utils/Atomic.h>
-#include <binder/BpBinder.h>
-#include <binder/IPCThreadState.h>
+#include <hwbinder/BpBinder.h>
+#include <hwbinder/IPCThreadState.h>
#include <utils/Log.h>
#include <utils/String8.h>
-#include <binder/IServiceManager.h>
+#include <hwbinder/IServiceManager.h>
#include <utils/String8.h>
#include <utils/threads.h>
diff --git a/Static.cpp b/Static.cpp
index f0613d1..ef0251c 100644
--- a/Static.cpp
+++ b/Static.cpp
@@ -19,8 +19,8 @@
#include <private/binder/Static.h>
-#include <binder/BufferedTextOutput.h>
-#include <binder/IPCThreadState.h>
+#include <hwbinder/BufferedTextOutput.h>
+#include <hwbinder/IPCThreadState.h>
#include <utils/Log.h>
namespace android {
diff --git a/Status.cpp b/Status.cpp
index 5ae6db2..283ccb7 100644
--- a/Status.cpp
+++ b/Status.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include <binder/Status.h>
+#include <hwbinder/Status.h>
namespace android {
namespace binder {
diff --git a/TextOutput.cpp b/TextOutput.cpp
index 2ed5188..6fc369d 100644
--- a/TextOutput.cpp
+++ b/TextOutput.cpp
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-#include <binder/TextOutput.h>
+#include <hwbinder/TextOutput.h>
-#include <binder/Debug.h>
+#include <hwbinder/Debug.h>
#include <utils/String8.h>
#include <utils/String16.h>
diff --git a/include/hwbinder/AppOpsManager.h b/include/hwbinder/AppOpsManager.h
deleted file mode 100644
index 042927c..0000000
--- a/include/hwbinder/AppOpsManager.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) 2013 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_APP_OPS_MANAGER_H
-#define ANDROID_APP_OPS_MANAGER_H
-
-#include <binder/IAppOpsService.h>
-
-#include <utils/threads.h>
-
-// ---------------------------------------------------------------------------
-namespace android {
-
-class AppOpsManager
-{
-public:
- enum {
- MODE_ALLOWED = IAppOpsService::MODE_ALLOWED,
- MODE_IGNORED = IAppOpsService::MODE_IGNORED,
- MODE_ERRORED = IAppOpsService::MODE_ERRORED
- };
-
- enum {
- OP_NONE = -1,
- OP_COARSE_LOCATION = 0,
- OP_FINE_LOCATION = 1,
- OP_GPS = 2,
- OP_VIBRATE = 3,
- OP_READ_CONTACTS = 4,
- OP_WRITE_CONTACTS = 5,
- OP_READ_CALL_LOG = 6,
- OP_WRITE_CALL_LOG = 7,
- OP_READ_CALENDAR = 8,
- OP_WRITE_CALENDAR = 9,
- OP_WIFI_SCAN = 10,
- OP_POST_NOTIFICATION = 11,
- OP_NEIGHBORING_CELLS = 12,
- OP_CALL_PHONE = 13,
- OP_READ_SMS = 14,
- OP_WRITE_SMS = 15,
- OP_RECEIVE_SMS = 16,
- OP_RECEIVE_EMERGECY_SMS = 17,
- OP_RECEIVE_MMS = 18,
- OP_RECEIVE_WAP_PUSH = 19,
- OP_SEND_SMS = 20,
- OP_READ_ICC_SMS = 21,
- OP_WRITE_ICC_SMS = 22,
- OP_WRITE_SETTINGS = 23,
- OP_SYSTEM_ALERT_WINDOW = 24,
- OP_ACCESS_NOTIFICATIONS = 25,
- OP_CAMERA = 26,
- OP_RECORD_AUDIO = 27,
- OP_PLAY_AUDIO = 28,
- OP_READ_CLIPBOARD = 29,
- OP_WRITE_CLIPBOARD = 30,
- OP_TAKE_MEDIA_BUTTONS = 31,
- OP_TAKE_AUDIO_FOCUS = 32,
- OP_AUDIO_MASTER_VOLUME = 33,
- OP_AUDIO_VOICE_VOLUME = 34,
- OP_AUDIO_RING_VOLUME = 35,
- OP_AUDIO_MEDIA_VOLUME = 36,
- OP_AUDIO_ALARM_VOLUME = 37,
- OP_AUDIO_NOTIFICATION_VOLUME = 38,
- OP_AUDIO_BLUETOOTH_VOLUME = 39,
- OP_WAKE_LOCK = 40,
- OP_MONITOR_LOCATION = 41,
- OP_MONITOR_HIGH_POWER_LOCATION = 42,
- OP_GET_USAGE_STATS = 43,
- OP_MUTE_MICROPHONE = 44,
- OP_TOAST_WINDOW = 45,
- OP_PROJECT_MEDIA = 46,
- OP_ACTIVATE_VPN = 47,
- OP_WRITE_WALLPAPER = 48,
- OP_ASSIST_STRUCTURE = 49,
- OP_ASSIST_SCREENSHOT = 50,
- OP_READ_PHONE_STATE = 51,
- OP_ADD_VOICEMAIL = 52,
- OP_USE_SIP = 53,
- OP_PROCESS_OUTGOING_CALLS = 54,
- OP_USE_FINGERPRINT = 55,
- OP_BODY_SENSORS = 56
- };
-
- AppOpsManager();
-
- int32_t checkOp(int32_t op, int32_t uid, const String16& callingPackage);
- int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage);
- int32_t startOp(int32_t op, int32_t uid, const String16& callingPackage);
- void finishOp(int32_t op, int32_t uid, const String16& callingPackage);
- void startWatchingMode(int32_t op, const String16& packageName,
- const sp<IAppOpsCallback>& callback);
- void stopWatchingMode(const sp<IAppOpsCallback>& callback);
- int32_t permissionToOpCode(const String16& permission);
-
-private:
- Mutex mLock;
- sp<IAppOpsService> mService;
-
- sp<IAppOpsService> getService();
-};
-
-
-}; // namespace android
-// ---------------------------------------------------------------------------
-#endif // ANDROID_APP_OPS_MANAGER_H
diff --git a/include/hwbinder/Binder.h b/include/hwbinder/Binder.h
index f849fd4..f203901 100644
--- a/include/hwbinder/Binder.h
+++ b/include/hwbinder/Binder.h
@@ -19,7 +19,7 @@
#include <atomic>
#include <stdint.h>
-#include <binder/IBinder.h>
+#include <hwbinder/IBinder.h>
// ---------------------------------------------------------------------------
namespace android {
diff --git a/include/hwbinder/BinderService.h b/include/hwbinder/BinderService.h
index ef703bd..3392d24 100644
--- a/include/hwbinder/BinderService.h
+++ b/include/hwbinder/BinderService.h
@@ -22,10 +22,10 @@
#include <utils/Errors.h>
#include <utils/String16.h>
-#include <binder/IServiceManager.h>
-#include <binder/IPCThreadState.h>
-#include <binder/ProcessState.h>
-#include <binder/IServiceManager.h>
+#include <hwbinder/IServiceManager.h>
+#include <hwbinder/IPCThreadState.h>
+#include <hwbinder/ProcessState.h>
+#include <hwbinder/IServiceManager.h>
// ---------------------------------------------------------------------------
namespace android {
diff --git a/include/hwbinder/BpBinder.h b/include/hwbinder/BpBinder.h
index 7ef93aa..cb67693 100644
--- a/include/hwbinder/BpBinder.h
+++ b/include/hwbinder/BpBinder.h
@@ -17,7 +17,7 @@
#ifndef ANDROID_BPBINDER_H
#define ANDROID_BPBINDER_H
-#include <binder/IBinder.h>
+#include <hwbinder/IBinder.h>
#include <utils/KeyedVector.h>
#include <utils/threads.h>
diff --git a/include/hwbinder/BufferedTextOutput.h b/include/hwbinder/BufferedTextOutput.h
index 9a7c43b..81cce31 100644
--- a/include/hwbinder/BufferedTextOutput.h
+++ b/include/hwbinder/BufferedTextOutput.h
@@ -17,7 +17,7 @@
#ifndef ANDROID_BUFFEREDTEXTOUTPUT_H
#define ANDROID_BUFFEREDTEXTOUTPUT_H
-#include <binder/TextOutput.h>
+#include <hwbinder/TextOutput.h>
#include <utils/threads.h>
#include <sys/uio.h>
diff --git a/include/hwbinder/IAppOpsCallback.h b/include/hwbinder/IAppOpsCallback.h
deleted file mode 100644
index 7f8eb01..0000000
--- a/include/hwbinder/IAppOpsCallback.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2013 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_IAPP_OPS_CALLBACK_H
-#define ANDROID_IAPP_OPS_CALLBACK_H
-
-#include <binder/IInterface.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------
-
-class IAppOpsCallback : public IInterface
-{
-public:
- DECLARE_META_INTERFACE(AppOpsCallback);
-
- virtual void opChanged(int32_t op, const String16& packageName) = 0;
-
- enum {
- OP_CHANGED_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION
- };
-};
-
-// ----------------------------------------------------------------------
-
-class BnAppOpsCallback : public BnInterface<IAppOpsCallback>
-{
-public:
- virtual status_t onTransact( uint32_t code,
- const Parcel& data,
- Parcel* reply,
- uint32_t flags = 0);
-};
-
-// ----------------------------------------------------------------------
-
-}; // namespace android
-
-#endif // ANDROID_IAPP_OPS_CALLBACK_H
-
diff --git a/include/hwbinder/IAppOpsService.h b/include/hwbinder/IAppOpsService.h
deleted file mode 100644
index cd81efa..0000000
--- a/include/hwbinder/IAppOpsService.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2013 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_IAPP_OPS_SERVICE_H
-#define ANDROID_IAPP_OPS_SERVICE_H
-
-#include <binder/IAppOpsCallback.h>
-#include <binder/IInterface.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------
-
-class IAppOpsService : public IInterface
-{
-public:
- DECLARE_META_INTERFACE(AppOpsService);
-
- virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) = 0;
- virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName) = 0;
- virtual int32_t startOperation(const sp<IBinder>& token, int32_t code, int32_t uid,
- const String16& packageName) = 0;
- virtual void finishOperation(const sp<IBinder>& token, int32_t code, int32_t uid,
- const String16& packageName) = 0;
- virtual void startWatchingMode(int32_t op, const String16& packageName,
- const sp<IAppOpsCallback>& callback) = 0;
- virtual void stopWatchingMode(const sp<IAppOpsCallback>& callback) = 0;
- virtual sp<IBinder> getToken(const sp<IBinder>& clientToken) = 0;
- virtual int32_t permissionToOpCode(const String16& permission) = 0;
-
- enum {
- CHECK_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
- NOTE_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+1,
- START_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+2,
- FINISH_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+3,
- START_WATCHING_MODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+4,
- STOP_WATCHING_MODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+5,
- GET_TOKEN_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+6,
- PERMISSION_TO_OP_CODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+7,
- };
-
- enum {
- MODE_ALLOWED = 0,
- MODE_IGNORED = 1,
- MODE_ERRORED = 2
- };
-};
-
-// ----------------------------------------------------------------------
-
-class BnAppOpsService : public BnInterface<IAppOpsService>
-{
-public:
- virtual status_t onTransact( uint32_t code,
- const Parcel& data,
- Parcel* reply,
- uint32_t flags = 0);
-};
-
-// ----------------------------------------------------------------------
-
-}; // namespace android
-
-#endif // ANDROID_IAPP_OPS_SERVICE_H
diff --git a/include/hwbinder/IBatteryStats.h b/include/hwbinder/IBatteryStats.h
deleted file mode 100644
index 5f38186..0000000
--- a/include/hwbinder/IBatteryStats.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2013 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_IBATTERYSTATS_H
-#define ANDROID_IBATTERYSTATS_H
-
-#include <binder/IInterface.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------
-
-class IBatteryStats : public IInterface
-{
-public:
- DECLARE_META_INTERFACE(BatteryStats);
-
- virtual void noteStartSensor(int uid, int sensor) = 0;
- virtual void noteStopSensor(int uid, int sensor) = 0;
- virtual void noteStartVideo(int uid) = 0;
- virtual void noteStopVideo(int uid) = 0;
- virtual void noteStartAudio(int uid) = 0;
- virtual void noteStopAudio(int uid) = 0;
- virtual void noteResetVideo() = 0;
- virtual void noteResetAudio() = 0;
- virtual void noteFlashlightOn(int uid) = 0;
- virtual void noteFlashlightOff(int uid) = 0;
- virtual void noteStartCamera(int uid) = 0;
- virtual void noteStopCamera(int uid) = 0;
- virtual void noteResetCamera() = 0;
- virtual void noteResetFlashlight() = 0;
-
- enum {
- NOTE_START_SENSOR_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
- NOTE_STOP_SENSOR_TRANSACTION,
- NOTE_START_VIDEO_TRANSACTION,
- NOTE_STOP_VIDEO_TRANSACTION,
- NOTE_START_AUDIO_TRANSACTION,
- NOTE_STOP_AUDIO_TRANSACTION,
- NOTE_RESET_VIDEO_TRANSACTION,
- NOTE_RESET_AUDIO_TRANSACTION,
- NOTE_FLASHLIGHT_ON_TRANSACTION,
- NOTE_FLASHLIGHT_OFF_TRANSACTION,
- NOTE_START_CAMERA_TRANSACTION,
- NOTE_STOP_CAMERA_TRANSACTION,
- NOTE_RESET_CAMERA_TRANSACTION,
- NOTE_RESET_FLASHLIGHT_TRANSACTION
- };
-};
-
-// ----------------------------------------------------------------------
-
-class BnBatteryStats : public BnInterface<IBatteryStats>
-{
-public:
- virtual status_t onTransact( uint32_t code,
- const Parcel& data,
- Parcel* reply,
- uint32_t flags = 0);
-};
-
-// ----------------------------------------------------------------------
-
-}; // namespace android
-
-#endif // ANDROID_IBATTERYSTATS_H
diff --git a/include/hwbinder/IInterface.h b/include/hwbinder/IInterface.h
index 4ce3613..fb10cba 100644
--- a/include/hwbinder/IInterface.h
+++ b/include/hwbinder/IInterface.h
@@ -18,7 +18,7 @@
#ifndef ANDROID_IINTERFACE_H
#define ANDROID_IINTERFACE_H
-#include <binder/Binder.h>
+#include <hwbinder/Binder.h>
namespace android {
diff --git a/include/hwbinder/IMediaResourceMonitor.h b/include/hwbinder/IMediaResourceMonitor.h
deleted file mode 100644
index c671f7a..0000000
--- a/include/hwbinder/IMediaResourceMonitor.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 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.
- */
-
-#ifndef ANDROID_I_MEDIA_RESOURCE_MONITOR_H
-#define ANDROID_I_MEDIA_RESOURCE_MONITOR_H
-
-#include <binder/IInterface.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------
-
-class IMediaResourceMonitor : public IInterface {
-public:
- DECLARE_META_INTERFACE(MediaResourceMonitor);
-
- // Values should be in sync with Intent.EXTRA_MEDIA_RESOURCE_TYPE_XXX.
- enum {
- TYPE_VIDEO_CODEC = 0,
- TYPE_AUDIO_CODEC = 1,
- };
-
- virtual void notifyResourceGranted(/*in*/ int32_t pid, /*in*/ const int32_t type) = 0;
-
- enum {
- NOTIFY_RESOURCE_GRANTED = IBinder::FIRST_CALL_TRANSACTION,
- };
-};
-
-// ----------------------------------------------------------------------
-
-class BnMediaResourceMonitor : public BnInterface<IMediaResourceMonitor> {
-public:
- virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
- uint32_t flags = 0);
-};
-
-// ----------------------------------------------------------------------
-
-}; // namespace android
-
-#endif // ANDROID_I_MEDIA_RESOURCE_MONITOR_H
diff --git a/include/hwbinder/IMemory.h b/include/hwbinder/IMemory.h
index 2d0db00..6a8d666 100644
--- a/include/hwbinder/IMemory.h
+++ b/include/hwbinder/IMemory.h
@@ -23,7 +23,7 @@
#include <utils/RefBase.h>
#include <utils/Errors.h>
-#include <binder/IInterface.h>
+#include <hwbinder/IInterface.h>
namespace android {
diff --git a/include/hwbinder/IPCThreadState.h b/include/hwbinder/IPCThreadState.h
index 1853cff..2127fd7 100644
--- a/include/hwbinder/IPCThreadState.h
+++ b/include/hwbinder/IPCThreadState.h
@@ -18,8 +18,8 @@
#define ANDROID_IPC_THREAD_STATE_H
#include <utils/Errors.h>
-#include <binder/Parcel.h>
-#include <binder/ProcessState.h>
+#include <hwbinder/Parcel.h>
+#include <hwbinder/ProcessState.h>
#include <utils/Vector.h>
#if defined(_WIN32)
diff --git a/include/hwbinder/IPermissionController.h b/include/hwbinder/IPermissionController.h
index 4e5fb34..2eb8573 100644
--- a/include/hwbinder/IPermissionController.h
+++ b/include/hwbinder/IPermissionController.h
@@ -18,7 +18,7 @@
#ifndef ANDROID_IPERMISSION_CONTROLLER_H
#define ANDROID_IPERMISSION_CONTROLLER_H
-#include <binder/IInterface.h>
+#include <hwbinder/IInterface.h>
#include <stdlib.h>
namespace android {
diff --git a/include/hwbinder/IProcessInfoService.h b/include/hwbinder/IProcessInfoService.h
deleted file mode 100644
index 69dc9a7..0000000
--- a/include/hwbinder/IProcessInfoService.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 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_I_PROCESS_INFO_SERVICE_H
-#define ANDROID_I_PROCESS_INFO_SERVICE_H
-
-#include <binder/IInterface.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------
-
-class IProcessInfoService : public IInterface {
-public:
- DECLARE_META_INTERFACE(ProcessInfoService);
-
- virtual status_t getProcessStatesFromPids( size_t length,
- /*in*/ int32_t* pids,
- /*out*/ int32_t* states) = 0;
-
- virtual status_t getProcessStatesAndOomScoresFromPids( size_t length,
- /*in*/ int32_t* pids,
- /*out*/ int32_t* states,
- /*out*/ int32_t* scores) = 0;
-
- enum {
- GET_PROCESS_STATES_FROM_PIDS = IBinder::FIRST_CALL_TRANSACTION,
- GET_PROCESS_STATES_AND_OOM_SCORES_FROM_PIDS,
- };
-};
-
-// ----------------------------------------------------------------------
-
-}; // namespace android
-
-#endif // ANDROID_I_PROCESS_INFO_SERVICE_H
diff --git a/include/hwbinder/IResultReceiver.h b/include/hwbinder/IResultReceiver.h
index 02dc6a6..bdb0375 100644
--- a/include/hwbinder/IResultReceiver.h
+++ b/include/hwbinder/IResultReceiver.h
@@ -18,7 +18,7 @@
#ifndef ANDROID_IRESULT_RECEIVER_H
#define ANDROID_IRESULT_RECEIVER_H
-#include <binder/IInterface.h>
+#include <hwbinder/IInterface.h>
namespace android {
diff --git a/include/hwbinder/IServiceManager.h b/include/hwbinder/IServiceManager.h
index 7ccd9fe..caacb7c 100644
--- a/include/hwbinder/IServiceManager.h
+++ b/include/hwbinder/IServiceManager.h
@@ -18,8 +18,8 @@
#ifndef ANDROID_ISERVICE_MANAGER_H
#define ANDROID_ISERVICE_MANAGER_H
-#include <binder/IInterface.h>
-#include <binder/IPermissionController.h>
+#include <hwbinder/IInterface.h>
+#include <hwbinder/IPermissionController.h>
#include <utils/Vector.h>
#include <utils/String16.h>
diff --git a/include/hwbinder/MemoryBase.h b/include/hwbinder/MemoryBase.h
index 463e26d..48ebbaa 100644
--- a/include/hwbinder/MemoryBase.h
+++ b/include/hwbinder/MemoryBase.h
@@ -20,7 +20,7 @@
#include <stdlib.h>
#include <stdint.h>
-#include <binder/IMemory.h>
+#include <hwbinder/IMemory.h>
namespace android {
diff --git a/include/hwbinder/MemoryDealer.h b/include/hwbinder/MemoryDealer.h
index 60a624c..063cdd3 100644
--- a/include/hwbinder/MemoryDealer.h
+++ b/include/hwbinder/MemoryDealer.h
@@ -21,8 +21,8 @@
#include <stdint.h>
#include <sys/types.h>
-#include <binder/IMemory.h>
-#include <binder/MemoryHeapBase.h>
+#include <hwbinder/IMemory.h>
+#include <hwbinder/MemoryHeapBase.h>
namespace android {
// ----------------------------------------------------------------------------
diff --git a/include/hwbinder/MemoryHeapBase.h b/include/hwbinder/MemoryHeapBase.h
index ea9b66c..24200c5 100644
--- a/include/hwbinder/MemoryHeapBase.h
+++ b/include/hwbinder/MemoryHeapBase.h
@@ -20,7 +20,7 @@
#include <stdlib.h>
#include <stdint.h>
-#include <binder/IMemory.h>
+#include <hwbinder/IMemory.h>
namespace android {
diff --git a/include/hwbinder/Parcel.h b/include/hwbinder/Parcel.h
index 2f441ed..14bd3ef 100644
--- a/include/hwbinder/Parcel.h
+++ b/include/hwbinder/Parcel.h
@@ -29,8 +29,8 @@
#include <utils/Flattenable.h>
#include <linux/binder.h>
-#include <binder/IInterface.h>
-#include <binder/Parcelable.h>
+#include <hwbinder/IInterface.h>
+#include <hwbinder/Parcelable.h>
// ---------------------------------------------------------------------------
namespace android {
diff --git a/include/hwbinder/PermissionCache.h b/include/hwbinder/PermissionCache.h
deleted file mode 100644
index bcdf0c2..0000000
--- a/include/hwbinder/PermissionCache.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2009 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 BINDER_PERMISSION_H
-#define BINDER_PERMISSION_H
-
-#include <stdint.h>
-#include <unistd.h>
-
-#include <utils/String16.h>
-#include <utils/Singleton.h>
-#include <utils/SortedVector.h>
-
-namespace android {
-// ---------------------------------------------------------------------------
-
-/*
- * PermissionCache caches permission checks for a given uid.
- *
- * Currently the cache is not updated when there is a permission change,
- * for instance when an application is uninstalled.
- *
- * IMPORTANT: for the reason stated above, only system permissions are safe
- * to cache. This restriction may be lifted at a later time.
- *
- */
-
-class PermissionCache : Singleton<PermissionCache> {
- struct Entry {
- String16 name;
- uid_t uid;
- bool granted;
- inline bool operator < (const Entry& e) const {
- return (uid == e.uid) ? (name < e.name) : (uid < e.uid);
- }
- };
- mutable Mutex mLock;
- // we pool all the permission names we see, as many permissions checks
- // will have identical names
- SortedVector< String16 > mPermissionNamesPool;
- // this is our cache per say. it stores pooled names.
- SortedVector< Entry > mCache;
-
- // free the whole cache, but keep the permission name pool
- void purge();
-
- status_t check(bool* granted,
- const String16& permission, uid_t uid) const;
-
- void cache(const String16& permission, uid_t uid, bool granted);
-
-public:
- PermissionCache();
-
- static bool checkCallingPermission(const String16& permission);
-
- static bool checkCallingPermission(const String16& permission,
- int32_t* outPid, int32_t* outUid);
-
- static bool checkPermission(const String16& permission,
- pid_t pid, uid_t uid);
-};
-
-// ---------------------------------------------------------------------------
-}; // namespace android
-
-#endif /* BINDER_PERMISSION_H */
diff --git a/include/hwbinder/PersistableBundle.h b/include/hwbinder/PersistableBundle.h
index 322fef9..10a457e 100644
--- a/include/hwbinder/PersistableBundle.h
+++ b/include/hwbinder/PersistableBundle.h
@@ -21,7 +21,7 @@
#include <set>
#include <vector>
-#include <binder/Parcelable.h>
+#include <hwbinder/Parcelable.h>
#include <utils/String16.h>
#include <utils/StrongPointer.h>
diff --git a/include/hwbinder/ProcessInfoService.h b/include/hwbinder/ProcessInfoService.h
deleted file mode 100644
index c5ead20..0000000
--- a/include/hwbinder/ProcessInfoService.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 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_PROCESS_INFO_SERVICE_H
-#define ANDROID_PROCESS_INFO_SERVICE_H
-
-#include <binder/IProcessInfoService.h>
-#include <utils/Errors.h>
-#include <utils/Singleton.h>
-#include <sys/types.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------
-
-class ProcessInfoService : public Singleton<ProcessInfoService> {
-
- friend class Singleton<ProcessInfoService>;
- sp<IProcessInfoService> mProcessInfoService;
- Mutex mProcessInfoLock;
-
- ProcessInfoService();
-
- status_t getProcessStatesImpl(size_t length, /*in*/ int32_t* pids, /*out*/ int32_t* states);
- void updateBinderLocked();
-
- static const int BINDER_ATTEMPT_LIMIT = 5;
-
-public:
-
- /**
- * For each PID in the given "pids" input array, write the current process state
- * for that process into the "states" output array, or
- * ActivityManager.PROCESS_STATE_NONEXISTENT * to indicate that no process with the given PID
- * exists.
- *
- * Returns NO_ERROR if this operation was successful, or a negative error code otherwise.
- */
- static status_t getProcessStatesFromPids(size_t length, /*in*/ int32_t* pids,
- /*out*/ int32_t* states) {
- return ProcessInfoService::getInstance().getProcessStatesImpl(length, /*in*/ pids,
- /*out*/ states);
- }
-
-};
-
-// ----------------------------------------------------------------------
-
-}; // namespace android
-
-#endif // ANDROID_PROCESS_INFO_SERVICE_H
-
diff --git a/include/hwbinder/ProcessState.h b/include/hwbinder/ProcessState.h
index 64cf72e..709137c 100644
--- a/include/hwbinder/ProcessState.h
+++ b/include/hwbinder/ProcessState.h
@@ -17,7 +17,7 @@
#ifndef ANDROID_PROCESS_STATE_H
#define ANDROID_PROCESS_STATE_H
-#include <binder/IBinder.h>
+#include <hwbinder/IBinder.h>
#include <utils/KeyedVector.h>
#include <utils/String8.h>
#include <utils/String16.h>
diff --git a/include/hwbinder/Status.h b/include/hwbinder/Status.h
index 7253af8..50dd821 100644
--- a/include/hwbinder/Status.h
+++ b/include/hwbinder/Status.h
@@ -20,7 +20,7 @@
#include <cstdint>
#include <sstream>
-#include <binder/Parcel.h>
+#include <hwbinder/Parcel.h>
#include <utils/String8.h>
namespace android {
diff --git a/tests/Android.mk b/tests/Android.mk
deleted file mode 100644
index a40523d..0000000
--- a/tests/Android.mk
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# Copyright (C) 2014 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.
-#
-
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-ifneq ($(TARGET_USES_64_BIT_BINDER),true)
-ifneq ($(TARGET_IS_64_BIT),true)
-LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1
-endif
-endif
-
-LOCAL_MODULE := binderDriverInterfaceTest
-LOCAL_SRC_FILES := binderDriverInterfaceTest.cpp
-include $(BUILD_NATIVE_TEST)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := binderLibTest
-LOCAL_SRC_FILES := binderLibTest.cpp
-LOCAL_SHARED_LIBRARIES := libbinder libutils
-include $(BUILD_NATIVE_TEST)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := binderThroughputTest
-LOCAL_SRC_FILES := binderThroughputTest.cpp
-LOCAL_SHARED_LIBRARIES := libbinder libutils
-LOCAL_CLANG := true
-LOCAL_CFLAGS += -g -Wall -Werror -std=c++11 -Wno-missing-field-initializers -Wno-sign-compare -O3
-include $(BUILD_NATIVE_TEST)
diff --git a/tests/binderDriverInterfaceTest.cpp b/tests/binderDriverInterfaceTest.cpp
deleted file mode 100644
index 0277550..0000000
--- a/tests/binderDriverInterfaceTest.cpp
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * Copyright (C) 2014 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 <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <gtest/gtest.h>
-#include <linux/binder.h>
-#include <binder/IBinder.h>
-#include <sys/mman.h>
-#include <poll.h>
-
-#define BINDER_DEV_NAME "/dev/binder"
-
-testing::Environment* binder_env;
-
-class BinderDriverInterfaceTestEnv : public ::testing::Environment {
- virtual void SetUp() {
- int ret;
- uint32_t max_threads = 0;
-
- m_binderFd = open(BINDER_DEV_NAME, O_RDWR | O_NONBLOCK | O_CLOEXEC);
- ASSERT_GE(m_binderFd, 0);
- m_buffer = mmap(NULL, 64*1024, PROT_READ, MAP_SHARED, m_binderFd, 0);
- ASSERT_NE(m_buffer, (void *)NULL);
- ret = ioctl(m_binderFd, BINDER_SET_MAX_THREADS, &max_threads);
- EXPECT_EQ(0, ret);
- EnterLooper();
- }
- virtual void TearDown() {
- close(m_binderFd);
- }
- private:
- int m_binderFd;
- void *m_buffer;
- public:
- int getBinderFd(void) {
- return m_binderFd;
- }
- void EnterLooper(void) {
- int ret;
- const uint32_t bc[] = {
- BC_ENTER_LOOPER,
- };
- struct binder_write_read bwr = binder_write_read();
- bwr.write_buffer = (uintptr_t)bc;
- bwr.write_size = sizeof(bc);
- ret = ioctl(m_binderFd, BINDER_WRITE_READ, &bwr);
- EXPECT_EQ(0, ret);
- if (ret < 0) {
- EXPECT_EQ(0, errno);
- }
- EXPECT_EQ(sizeof(bc), bwr.write_consumed);
- }
-};
-
-class BinderDriverInterfaceTest : public ::testing::Test {
- public:
- virtual void SetUp() {
- m_binderFd = static_cast<BinderDriverInterfaceTestEnv *>(binder_env)->getBinderFd();
- }
- virtual void TearDown() {
- }
- protected:
- void binderTestIoctlRetErr2(int cmd, void *arg, int expect_ret, int expect_errno, int accept_errno) {
- int ret;
-
- ret = ioctl(m_binderFd, cmd, arg);
- EXPECT_EQ(expect_ret, ret);
- if (ret < 0) {
- if (errno != accept_errno)
- EXPECT_EQ(expect_errno, errno);
- }
- }
- void binderTestIoctlErr2(int cmd, void *arg, int expect_errno, int accept_errno) {
- binderTestIoctlRetErr2(cmd, arg, -1, expect_errno, accept_errno);
- }
- void binderTestIoctlErr1(int cmd, void *arg, int expect_errno) {
- binderTestIoctlErr2(cmd, arg, expect_errno, expect_errno);
- }
- void binderTestIoctl(int cmd, void *arg) {
- binderTestIoctlRetErr2(cmd, arg, 0, 0, 0);
- }
- void binderTestIoctlUnimplemented(int cmd, void *arg) {
- int ret;
-
- ret = ioctl(m_binderFd, cmd, arg);
- if (ret < 0) {
- /* Not currently implmented. Allow ret == -1, errno == EINVAL */
- EXPECT_EQ(-1, ret);
- EXPECT_EQ(EINVAL, errno);
- }
- }
- void binderTestReadEmpty(void) {
- size_t i;
- uint32_t br[32];
- struct binder_write_read bwr = binder_write_read();
- SCOPED_TRACE("TestReadEmpty");
- bwr.read_buffer = (uintptr_t)br;
- bwr.read_size = sizeof(br);
- binderTestIoctlErr1(BINDER_WRITE_READ, &bwr, EAGAIN);
- EXPECT_EQ(0u, bwr.read_consumed);
- for (i = 0; i * sizeof(uint32_t) < bwr.read_consumed; i++) {
- SCOPED_TRACE(testing::Message() << "i = " << i);
- EXPECT_EQ(BR_NOOP, br[i]);
- }
- }
- void binderWaitForReadData(int timeout_ms) {
- int ret;
- pollfd pfd = pollfd();
-
- pfd.fd = m_binderFd;
- pfd.events = POLLIN;
- ret = poll(&pfd, 1, timeout_ms);
- EXPECT_EQ(1, ret);
- }
- private:
- int m_binderFd;
-};
-
-TEST_F(BinderDriverInterfaceTest, Version) {
- struct binder_version version;
- binderTestIoctl(BINDER_VERSION, &version);
- ASSERT_EQ(BINDER_CURRENT_PROTOCOL_VERSION, version.protocol_version);
-}
-
-TEST_F(BinderDriverInterfaceTest, WriteReadNull) {
- binderTestIoctlErr1(BINDER_WRITE_READ, NULL, EFAULT);
-}
-
-TEST_F(BinderDriverInterfaceTest, SetIdleTimeoutNull) {
- binderTestIoctlErr2(BINDER_SET_IDLE_TIMEOUT, NULL, EFAULT, EINVAL);
-}
-
-TEST_F(BinderDriverInterfaceTest, SetMaxThreadsNull) {
- binderTestIoctlErr2(BINDER_SET_MAX_THREADS, NULL, EFAULT, EINVAL); /* TODO: don't accept EINVAL */
-}
-
-TEST_F(BinderDriverInterfaceTest, SetIdlePriorityNull) {
- binderTestIoctlErr2(BINDER_SET_IDLE_PRIORITY, NULL, EFAULT, EINVAL);
-}
-
-TEST_F(BinderDriverInterfaceTest, VersionNull) {
- binderTestIoctlErr2(BINDER_VERSION, NULL, EFAULT, EINVAL); /* TODO: don't accept EINVAL */
-}
-
-TEST_F(BinderDriverInterfaceTest, SetIdleTimeoutNoTest) {
- int64_t idle_timeout = 100000;
- binderTestIoctlUnimplemented(BINDER_SET_IDLE_TIMEOUT, &idle_timeout);
-}
-
-TEST_F(BinderDriverInterfaceTest, SetMaxThreads) {
- uint32_t max_threads = 0;
- binderTestIoctl(BINDER_SET_MAX_THREADS, &max_threads);
-}
-
-TEST_F(BinderDriverInterfaceTest, SetIdlePriorityNoTest) {
- int idle_priority = 0;
- binderTestIoctlUnimplemented(BINDER_SET_IDLE_PRIORITY, &idle_priority);
-}
-
-TEST_F(BinderDriverInterfaceTest, SetContextMgrBusy) {
- int32_t dummy = 0;
- binderTestIoctlErr1(BINDER_SET_CONTEXT_MGR, &dummy, EBUSY);
-}
-
-TEST_F(BinderDriverInterfaceTest, ThreadExit) {
- int32_t dummy = 0;
- binderTestIoctl(BINDER_THREAD_EXIT, &dummy);
- static_cast<BinderDriverInterfaceTestEnv *>(binder_env)->EnterLooper();
-}
-
-TEST_F(BinderDriverInterfaceTest, WriteReadEmpty) {
- struct binder_write_read bwr = binder_write_read();
- binderTestIoctl(BINDER_WRITE_READ, &bwr);
-}
-
-TEST_F(BinderDriverInterfaceTest, Read) {
- binderTestReadEmpty();
-}
-
-TEST_F(BinderDriverInterfaceTest, IncRefsAcquireReleaseDecRefs) {
- const uint32_t bc[] = {
- BC_INCREFS,
- 0,
- BC_ACQUIRE,
- 0,
- BC_RELEASE,
- 0,
- BC_DECREFS,
- 0,
- };
- struct binder_write_read bwr = binder_write_read();
- bwr.write_buffer = (uintptr_t)bc;
- bwr.write_size = sizeof(bc);
- binderTestIoctl(BINDER_WRITE_READ, &bwr);
- EXPECT_EQ(sizeof(bc), bwr.write_consumed);
- binderTestReadEmpty();
-}
-
-TEST_F(BinderDriverInterfaceTest, Transaction) {
- binder_uintptr_t cookie = 1234;
- struct {
- uint32_t cmd1;
- struct binder_transaction_data arg1;
- } __attribute__((packed)) bc1 = {
- .cmd1 = BC_TRANSACTION,
- .arg1 = {
- .target = { 0 },
- .cookie = 0,
- .code = android::IBinder::PING_TRANSACTION,
- .flags = 0,
- .sender_pid = 0,
- .sender_euid = 0,
- .data_size = 0,
- .offsets_size = 0,
- .data = {0, 0},
- },
- };
- struct {
- uint32_t cmd0;
- uint32_t cmd1;
- uint32_t cmd2;
- binder_transaction_data arg2;
- uint32_t pad[16];
- } __attribute__((packed)) br;
- struct binder_write_read bwr = binder_write_read();
-
- bwr.write_buffer = (uintptr_t)&bc1;
- bwr.write_size = sizeof(bc1);
- bwr.read_buffer = (uintptr_t)&br;
- bwr.read_size = sizeof(br);
-
- {
- SCOPED_TRACE("1st WriteRead");
- binderTestIoctl(BINDER_WRITE_READ, &bwr);
- }
- EXPECT_EQ(sizeof(bc1), bwr.write_consumed);
- if (bwr.read_consumed < offsetof(typeof(br), pad)) {
- SCOPED_TRACE("2nd WriteRead");
- binderWaitForReadData(10000);
- binderTestIoctl(BINDER_WRITE_READ, &bwr);
- }
- EXPECT_EQ(offsetof(typeof(br), pad), bwr.read_consumed);
- if (bwr.read_consumed > offsetof(typeof(br), cmd0))
- EXPECT_EQ(BR_NOOP, br.cmd0);
- if (bwr.read_consumed > offsetof(typeof(br), cmd1))
- EXPECT_EQ(BR_TRANSACTION_COMPLETE, br.cmd1);
- if (bwr.read_consumed > offsetof(typeof(br), cmd2))
- EXPECT_EQ(BR_REPLY, br.cmd2);
- if (bwr.read_consumed >= offsetof(typeof(br), pad)) {
- EXPECT_EQ(0u, br.arg2.target.ptr);
- EXPECT_EQ(0u, br.arg2.cookie);
- EXPECT_EQ(0u, br.arg2.code);
- EXPECT_EQ(0u, br.arg2.flags);
- EXPECT_EQ(0u, br.arg2.data_size);
- EXPECT_EQ(0u, br.arg2.offsets_size);
-
- SCOPED_TRACE("3rd WriteRead");
-
- binderTestReadEmpty();
-
- struct {
- uint32_t cmd1;
- binder_uintptr_t arg1;
- } __attribute__((packed)) bc2 = {
- .cmd1 = BC_FREE_BUFFER,
- .arg1 = br.arg2.data.ptr.buffer,
- };
-
- bwr.write_buffer = (uintptr_t)&bc2;
- bwr.write_size = sizeof(bc2);
- bwr.write_consumed = 0;
- bwr.read_size = 0;
-
- binderTestIoctl(BINDER_WRITE_READ, &bwr);
- EXPECT_EQ(sizeof(bc2), bwr.write_consumed);
- }
- binderTestReadEmpty();
-}
-
-TEST_F(BinderDriverInterfaceTest, RequestDeathNotification) {
- binder_uintptr_t cookie = 1234;
- struct {
- uint32_t cmd0;
- uint32_t arg0;
- uint32_t cmd1;
- struct binder_handle_cookie arg1;
- uint32_t cmd2;
- struct binder_handle_cookie arg2;
- uint32_t cmd3;
- uint32_t arg3;
- } __attribute__((packed)) bc = {
- .cmd0 = BC_INCREFS,
- .arg0 = 0,
- .cmd1 = BC_REQUEST_DEATH_NOTIFICATION,
- .arg1 = {
- .handle = 0,
- .cookie = cookie,
- },
- .cmd2 = BC_CLEAR_DEATH_NOTIFICATION,
- .arg2 = {
- .handle = 0,
- .cookie = cookie,
- },
- .cmd3 = BC_DECREFS,
- .arg3 = 0,
- };
- struct {
- uint32_t cmd0;
- uint32_t cmd1;
- binder_uintptr_t arg1;
- uint32_t pad[16];
- } __attribute__((packed)) br;
- struct binder_write_read bwr = binder_write_read();
-
- bwr.write_buffer = (uintptr_t)&bc;
- bwr.write_size = sizeof(bc);
- bwr.read_buffer = (uintptr_t)&br;
- bwr.read_size = sizeof(br);
-
- binderTestIoctl(BINDER_WRITE_READ, &bwr);
- EXPECT_EQ(sizeof(bc), bwr.write_consumed);
- EXPECT_EQ(sizeof(br) - sizeof(br.pad), bwr.read_consumed);
- EXPECT_EQ(BR_NOOP, br.cmd0);
- EXPECT_EQ(BR_CLEAR_DEATH_NOTIFICATION_DONE, br.cmd1);
- EXPECT_EQ(cookie, br.arg1);
- binderTestReadEmpty();
-}
-
-int main(int argc, char **argv) {
- ::testing::InitGoogleTest(&argc, argv);
-
- binder_env = AddGlobalTestEnvironment(new BinderDriverInterfaceTestEnv());
-
- return RUN_ALL_TESTS();
-}
-
diff --git a/tests/binderLibTest.cpp b/tests/binderLibTest.cpp
deleted file mode 100644
index 17479ca..0000000
--- a/tests/binderLibTest.cpp
+++ /dev/null
@@ -1,946 +0,0 @@
-/*
- * Copyright (C) 2014 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 <errno.h>
-#include <fcntl.h>
-#include <poll.h>
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <gtest/gtest.h>
-
-#include <binder/Binder.h>
-#include <binder/IBinder.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
-
-#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
-
-using namespace android;
-
-static testing::Environment* binder_env;
-static char *binderservername;
-static char binderserverarg[] = "--binderserver";
-
-static String16 binderLibTestServiceName = String16("test.binderLib");
-
-enum BinderLibTestTranscationCode {
- BINDER_LIB_TEST_NOP_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
- BINDER_LIB_TEST_REGISTER_SERVER,
- BINDER_LIB_TEST_ADD_SERVER,
- BINDER_LIB_TEST_CALL_BACK,
- BINDER_LIB_TEST_NOP_CALL_BACK,
- BINDER_LIB_TEST_GET_ID_TRANSACTION,
- BINDER_LIB_TEST_INDIRECT_TRANSACTION,
- BINDER_LIB_TEST_SET_ERROR_TRANSACTION,
- BINDER_LIB_TEST_GET_STATUS_TRANSACTION,
- BINDER_LIB_TEST_ADD_STRONG_REF_TRANSACTION,
- BINDER_LIB_TEST_LINK_DEATH_TRANSACTION,
- BINDER_LIB_TEST_WRITE_FILE_TRANSACTION,
- BINDER_LIB_TEST_PROMOTE_WEAK_REF_TRANSACTION,
- BINDER_LIB_TEST_EXIT_TRANSACTION,
- BINDER_LIB_TEST_DELAYED_EXIT_TRANSACTION,
- BINDER_LIB_TEST_GET_PTR_SIZE_TRANSACTION,
-};
-
-pid_t start_server_process(int arg2)
-{
- int ret;
- pid_t pid;
- status_t status;
- int pipefd[2];
- char stri[16];
- char strpipefd1[16];
- char *childargv[] = {
- binderservername,
- binderserverarg,
- stri,
- strpipefd1,
- NULL
- };
-
- ret = pipe(pipefd);
- if (ret < 0)
- return ret;
-
- snprintf(stri, sizeof(stri), "%d", arg2);
- snprintf(strpipefd1, sizeof(strpipefd1), "%d", pipefd[1]);
-
- pid = fork();
- if (pid == -1)
- return pid;
- if (pid == 0) {
- close(pipefd[0]);
- execv(binderservername, childargv);
- status = -errno;
- write(pipefd[1], &status, sizeof(status));
- fprintf(stderr, "execv failed, %s\n", strerror(errno));
- _exit(EXIT_FAILURE);
- }
- close(pipefd[1]);
- ret = read(pipefd[0], &status, sizeof(status));
- //printf("pipe read returned %d, status %d\n", ret, status);
- close(pipefd[0]);
- if (ret == sizeof(status)) {
- ret = status;
- } else {
- kill(pid, SIGKILL);
- if (ret >= 0) {
- ret = NO_INIT;
- }
- }
- if (ret < 0) {
- wait(NULL);
- return ret;
- }
- return pid;
-}
-
-class BinderLibTestEnv : public ::testing::Environment {
- public:
- BinderLibTestEnv() {}
- sp<IBinder> getServer(void) {
- return m_server;
- }
-
- private:
- virtual void SetUp() {
- m_serverpid = start_server_process(0);
- //printf("m_serverpid %d\n", m_serverpid);
- ASSERT_GT(m_serverpid, 0);
-
- sp<IServiceManager> sm = defaultServiceManager();
- //printf("%s: pid %d, get service\n", __func__, m_pid);
- m_server = sm->getService(binderLibTestServiceName);
- ASSERT_TRUE(m_server != NULL);
- //printf("%s: pid %d, get service done\n", __func__, m_pid);
- }
- virtual void TearDown() {
- status_t ret;
- Parcel data, reply;
- int exitStatus;
- pid_t pid;
-
- //printf("%s: pid %d\n", __func__, m_pid);
- if (m_server != NULL) {
- ret = m_server->transact(BINDER_LIB_TEST_GET_STATUS_TRANSACTION, data, &reply);
- EXPECT_EQ(0, ret);
- ret = m_server->transact(BINDER_LIB_TEST_EXIT_TRANSACTION, data, &reply, TF_ONE_WAY);
- EXPECT_EQ(0, ret);
- }
- if (m_serverpid > 0) {
- //printf("wait for %d\n", m_pids[i]);
- pid = wait(&exitStatus);
- EXPECT_EQ(m_serverpid, pid);
- EXPECT_TRUE(WIFEXITED(exitStatus));
- EXPECT_EQ(0, WEXITSTATUS(exitStatus));
- }
- }
-
- pid_t m_serverpid;
- sp<IBinder> m_server;
-};
-
-class BinderLibTest : public ::testing::Test {
- public:
- virtual void SetUp() {
- m_server = static_cast<BinderLibTestEnv *>(binder_env)->getServer();
- }
- virtual void TearDown() {
- }
- protected:
- sp<IBinder> addServer(int32_t *idPtr = NULL)
- {
- int ret;
- int32_t id;
- Parcel data, reply;
- sp<IBinder> binder;
-
- ret = m_server->transact(BINDER_LIB_TEST_ADD_SERVER, data, &reply);
- EXPECT_EQ(NO_ERROR, ret);
-
- EXPECT_FALSE(binder != NULL);
- binder = reply.readStrongBinder();
- EXPECT_TRUE(binder != NULL);
- ret = reply.readInt32(&id);
- EXPECT_EQ(NO_ERROR, ret);
- if (idPtr)
- *idPtr = id;
- return binder;
- }
- void waitForReadData(int fd, int timeout_ms) {
- int ret;
- pollfd pfd = pollfd();
-
- pfd.fd = fd;
- pfd.events = POLLIN;
- ret = poll(&pfd, 1, timeout_ms);
- EXPECT_EQ(1, ret);
- }
-
- sp<IBinder> m_server;
-};
-
-class BinderLibTestBundle : public Parcel
-{
- public:
- BinderLibTestBundle(void) {}
- BinderLibTestBundle(const Parcel *source) : m_isValid(false) {
- int32_t mark;
- int32_t bundleLen;
- size_t pos;
-
- if (source->readInt32(&mark))
- return;
- if (mark != MARK_START)
- return;
- if (source->readInt32(&bundleLen))
- return;
- pos = source->dataPosition();
- if (Parcel::appendFrom(source, pos, bundleLen))
- return;
- source->setDataPosition(pos + bundleLen);
- if (source->readInt32(&mark))
- return;
- if (mark != MARK_END)
- return;
- m_isValid = true;
- setDataPosition(0);
- }
- void appendTo(Parcel *dest) {
- dest->writeInt32(MARK_START);
- dest->writeInt32(dataSize());
- dest->appendFrom(this, 0, dataSize());
- dest->writeInt32(MARK_END);
- };
- bool isValid(void) {
- return m_isValid;
- }
- private:
- enum {
- MARK_START = B_PACK_CHARS('B','T','B','S'),
- MARK_END = B_PACK_CHARS('B','T','B','E'),
- };
- bool m_isValid;
-};
-
-class BinderLibTestEvent
-{
- public:
- BinderLibTestEvent(void)
- : m_eventTriggered(false)
- {
- pthread_mutex_init(&m_waitMutex, NULL);
- pthread_cond_init(&m_waitCond, NULL);
- }
- int waitEvent(int timeout_s)
- {
- int ret;
- pthread_mutex_lock(&m_waitMutex);
- if (!m_eventTriggered) {
- struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
- ts.tv_sec += timeout_s;
- pthread_cond_timedwait(&m_waitCond, &m_waitMutex, &ts);
- }
- ret = m_eventTriggered ? NO_ERROR : TIMED_OUT;
- pthread_mutex_unlock(&m_waitMutex);
- return ret;
- }
- protected:
- void triggerEvent(void) {
- pthread_mutex_lock(&m_waitMutex);
- pthread_cond_signal(&m_waitCond);
- m_eventTriggered = true;
- pthread_mutex_unlock(&m_waitMutex);
- };
- private:
- pthread_mutex_t m_waitMutex;
- pthread_cond_t m_waitCond;
- bool m_eventTriggered;
-};
-
-class BinderLibTestCallBack : public BBinder, public BinderLibTestEvent
-{
- public:
- BinderLibTestCallBack()
- : m_result(NOT_ENOUGH_DATA)
- {
- }
- status_t getResult(void)
- {
- return m_result;
- }
-
- private:
- virtual status_t onTransact(uint32_t code,
- const Parcel& data, Parcel* reply,
- uint32_t flags = 0)
- {
- (void)reply;
- (void)flags;
- switch(code) {
- case BINDER_LIB_TEST_CALL_BACK:
- m_result = data.readInt32();
- triggerEvent();
- return NO_ERROR;
- default:
- return UNKNOWN_TRANSACTION;
- }
- }
-
- status_t m_result;
-};
-
-class TestDeathRecipient : public IBinder::DeathRecipient, public BinderLibTestEvent
-{
- private:
- virtual void binderDied(const wp<IBinder>& who) {
- (void)who;
- triggerEvent();
- };
-};
-
-TEST_F(BinderLibTest, NopTransaction) {
- status_t ret;
- Parcel data, reply;
- ret = m_server->transact(BINDER_LIB_TEST_NOP_TRANSACTION, data, &reply);
- EXPECT_EQ(NO_ERROR, ret);
-}
-
-TEST_F(BinderLibTest, SetError) {
- int32_t testValue[] = { 0, -123, 123 };
- for (size_t i = 0; i < ARRAY_SIZE(testValue); i++) {
- status_t ret;
- Parcel data, reply;
- data.writeInt32(testValue[i]);
- ret = m_server->transact(BINDER_LIB_TEST_SET_ERROR_TRANSACTION, data, &reply);
- EXPECT_EQ(testValue[i], ret);
- }
-}
-
-TEST_F(BinderLibTest, GetId) {
- status_t ret;
- int32_t id;
- Parcel data, reply;
- ret = m_server->transact(BINDER_LIB_TEST_GET_ID_TRANSACTION, data, &reply);
- EXPECT_EQ(NO_ERROR, ret);
- ret = reply.readInt32(&id);
- EXPECT_EQ(NO_ERROR, ret);
- EXPECT_EQ(0, id);
-}
-
-TEST_F(BinderLibTest, PtrSize) {
- status_t ret;
- int32_t ptrsize;
- Parcel data, reply;
- sp<IBinder> server = addServer();
- ASSERT_TRUE(server != NULL);
- ret = server->transact(BINDER_LIB_TEST_GET_PTR_SIZE_TRANSACTION, data, &reply);
- EXPECT_EQ(NO_ERROR, ret);
- ret = reply.readInt32(&ptrsize);
- EXPECT_EQ(NO_ERROR, ret);
- RecordProperty("TestPtrSize", sizeof(void *));
- RecordProperty("ServerPtrSize", sizeof(void *));
-}
-
-TEST_F(BinderLibTest, IndirectGetId2)
-{
- status_t ret;
- int32_t id;
- int32_t count;
- Parcel data, reply;
- int32_t serverId[3];
-
- data.writeInt32(ARRAY_SIZE(serverId));
- for (size_t i = 0; i < ARRAY_SIZE(serverId); i++) {
- sp<IBinder> server;
- BinderLibTestBundle datai;
-
- server = addServer(&serverId[i]);
- ASSERT_TRUE(server != NULL);
- data.writeStrongBinder(server);
- data.writeInt32(BINDER_LIB_TEST_GET_ID_TRANSACTION);
- datai.appendTo(&data);
- }
-
- ret = m_server->transact(BINDER_LIB_TEST_INDIRECT_TRANSACTION, data, &reply);
- ASSERT_EQ(NO_ERROR, ret);
-
- ret = reply.readInt32(&id);
- ASSERT_EQ(NO_ERROR, ret);
- EXPECT_EQ(0, id);
-
- ret = reply.readInt32(&count);
- ASSERT_EQ(NO_ERROR, ret);
- EXPECT_EQ(ARRAY_SIZE(serverId), count);
-
- for (size_t i = 0; i < (size_t)count; i++) {
- BinderLibTestBundle replyi(&reply);
- EXPECT_TRUE(replyi.isValid());
- ret = replyi.readInt32(&id);
- EXPECT_EQ(NO_ERROR, ret);
- EXPECT_EQ(serverId[i], id);
- EXPECT_EQ(replyi.dataSize(), replyi.dataPosition());
- }
-
- EXPECT_EQ(reply.dataSize(), reply.dataPosition());
-}
-
-TEST_F(BinderLibTest, IndirectGetId3)
-{
- status_t ret;
- int32_t id;
- int32_t count;
- Parcel data, reply;
- int32_t serverId[3];
-
- data.writeInt32(ARRAY_SIZE(serverId));
- for (size_t i = 0; i < ARRAY_SIZE(serverId); i++) {
- sp<IBinder> server;
- BinderLibTestBundle datai;
- BinderLibTestBundle datai2;
-
- server = addServer(&serverId[i]);
- ASSERT_TRUE(server != NULL);
- data.writeStrongBinder(server);
- data.writeInt32(BINDER_LIB_TEST_INDIRECT_TRANSACTION);
-
- datai.writeInt32(1);
- datai.writeStrongBinder(m_server);
- datai.writeInt32(BINDER_LIB_TEST_GET_ID_TRANSACTION);
- datai2.appendTo(&datai);
-
- datai.appendTo(&data);
- }
-
- ret = m_server->transact(BINDER_LIB_TEST_INDIRECT_TRANSACTION, data, &reply);
- ASSERT_EQ(NO_ERROR, ret);
-
- ret = reply.readInt32(&id);
- ASSERT_EQ(NO_ERROR, ret);
- EXPECT_EQ(0, id);
-
- ret = reply.readInt32(&count);
- ASSERT_EQ(NO_ERROR, ret);
- EXPECT_EQ(ARRAY_SIZE(serverId), count);
-
- for (size_t i = 0; i < (size_t)count; i++) {
- int32_t counti;
-
- BinderLibTestBundle replyi(&reply);
- EXPECT_TRUE(replyi.isValid());
- ret = replyi.readInt32(&id);
- EXPECT_EQ(NO_ERROR, ret);
- EXPECT_EQ(serverId[i], id);
-
- ret = replyi.readInt32(&counti);
- ASSERT_EQ(NO_ERROR, ret);
- EXPECT_EQ(1, counti);
-
- BinderLibTestBundle replyi2(&replyi);
- EXPECT_TRUE(replyi2.isValid());
- ret = replyi2.readInt32(&id);
- EXPECT_EQ(NO_ERROR, ret);
- EXPECT_EQ(0, id);
- EXPECT_EQ(replyi2.dataSize(), replyi2.dataPosition());
-
- EXPECT_EQ(replyi.dataSize(), replyi.dataPosition());
- }
-
- EXPECT_EQ(reply.dataSize(), reply.dataPosition());
-}
-
-TEST_F(BinderLibTest, CallBack)
-{
- status_t ret;
- Parcel data, reply;
- sp<BinderLibTestCallBack> callBack = new BinderLibTestCallBack();
- data.writeStrongBinder(callBack);
- ret = m_server->transact(BINDER_LIB_TEST_NOP_CALL_BACK, data, &reply, TF_ONE_WAY);
- EXPECT_EQ(NO_ERROR, ret);
- ret = callBack->waitEvent(5);
- EXPECT_EQ(NO_ERROR, ret);
- ret = callBack->getResult();
- EXPECT_EQ(NO_ERROR, ret);
-}
-
-TEST_F(BinderLibTest, AddServer)
-{
- sp<IBinder> server = addServer();
- ASSERT_TRUE(server != NULL);
-}
-
-TEST_F(BinderLibTest, DeathNotificationNoRefs)
-{
- status_t ret;
-
- sp<TestDeathRecipient> testDeathRecipient = new TestDeathRecipient();
-
- {
- sp<IBinder> binder = addServer();
- ASSERT_TRUE(binder != NULL);
- 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 != NULL);
- 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;
- sp<IBinder> sbinder;
-
- sp<TestDeathRecipient> testDeathRecipient = new TestDeathRecipient();
-
- {
- sp<IBinder> binder = addServer();
- ASSERT_TRUE(binder != NULL);
- ret = binder->linkToDeath(testDeathRecipient);
- EXPECT_EQ(NO_ERROR, ret);
- sbinder = binder;
- }
- {
- Parcel data, reply;
- ret = sbinder->transact(BINDER_LIB_TEST_EXIT_TRANSACTION, data, &reply, TF_ONE_WAY);
- EXPECT_EQ(0, ret);
- }
- IPCThreadState::self()->flushCommands();
- ret = testDeathRecipient->waitEvent(5);
- EXPECT_EQ(NO_ERROR, ret);
- ret = sbinder->unlinkToDeath(testDeathRecipient);
- EXPECT_EQ(DEAD_OBJECT, ret);
-}
-
-TEST_F(BinderLibTest, DeathNotificationMultiple)
-{
- status_t ret;
- const int clientcount = 2;
- sp<IBinder> target;
- sp<IBinder> linkedclient[clientcount];
- sp<BinderLibTestCallBack> callBack[clientcount];
- sp<IBinder> passiveclient[clientcount];
-
- target = addServer();
- ASSERT_TRUE(target != NULL);
- for (int i = 0; i < clientcount; i++) {
- {
- Parcel data, reply;
-
- linkedclient[i] = addServer();
- ASSERT_TRUE(linkedclient[i] != NULL);
- callBack[i] = new BinderLibTestCallBack();
- data.writeStrongBinder(target);
- data.writeStrongBinder(callBack[i]);
- ret = linkedclient[i]->transact(BINDER_LIB_TEST_LINK_DEATH_TRANSACTION, data, &reply, TF_ONE_WAY);
- EXPECT_EQ(NO_ERROR, ret);
- }
- {
- Parcel data, reply;
-
- passiveclient[i] = addServer();
- ASSERT_TRUE(passiveclient[i] != NULL);
- data.writeStrongBinder(target);
- ret = passiveclient[i]->transact(BINDER_LIB_TEST_ADD_STRONG_REF_TRANSACTION, data, &reply, TF_ONE_WAY);
- EXPECT_EQ(NO_ERROR, ret);
- }
- }
- {
- Parcel data, reply;
- ret = target->transact(BINDER_LIB_TEST_EXIT_TRANSACTION, data, &reply, TF_ONE_WAY);
- EXPECT_EQ(0, ret);
- }
-
- for (int i = 0; i < clientcount; i++) {
- ret = callBack[i]->waitEvent(5);
- EXPECT_EQ(NO_ERROR, ret);
- ret = callBack[i]->getResult();
- EXPECT_EQ(NO_ERROR, ret);
- }
-}
-
-TEST_F(BinderLibTest, PassFile) {
- int ret;
- int pipefd[2];
- uint8_t buf[1] = { 0 };
- uint8_t write_value = 123;
-
- ret = pipe2(pipefd, O_NONBLOCK);
- ASSERT_EQ(0, ret);
-
- {
- Parcel data, reply;
- uint8_t writebuf[1] = { write_value };
-
- ret = data.writeFileDescriptor(pipefd[1], true);
- EXPECT_EQ(NO_ERROR, ret);
-
- ret = data.writeInt32(sizeof(writebuf));
- EXPECT_EQ(NO_ERROR, ret);
-
- ret = data.write(writebuf, sizeof(writebuf));
- EXPECT_EQ(NO_ERROR, ret);
-
- ret = m_server->transact(BINDER_LIB_TEST_WRITE_FILE_TRANSACTION, data, &reply);
- EXPECT_EQ(NO_ERROR, ret);
- }
-
- ret = read(pipefd[0], buf, sizeof(buf));
- EXPECT_EQ(sizeof(buf), ret);
- EXPECT_EQ(write_value, buf[0]);
-
- waitForReadData(pipefd[0], 5000); /* wait for other proccess to close pipe */
-
- ret = read(pipefd[0], buf, sizeof(buf));
- EXPECT_EQ(0, ret);
-
- close(pipefd[0]);
-}
-
-TEST_F(BinderLibTest, PromoteLocal) {
- sp<IBinder> strong = new BBinder();
- wp<IBinder> weak = strong;
- sp<IBinder> strong_from_weak = weak.promote();
- EXPECT_TRUE(strong != NULL);
- EXPECT_EQ(strong, strong_from_weak);
- strong = NULL;
- strong_from_weak = NULL;
- strong_from_weak = weak.promote();
- EXPECT_TRUE(strong_from_weak == NULL);
-}
-
-TEST_F(BinderLibTest, PromoteRemote) {
- int ret;
- Parcel data, reply;
- sp<IBinder> strong = new BBinder();
- sp<IBinder> server = addServer();
-
- ASSERT_TRUE(server != NULL);
- ASSERT_TRUE(strong != NULL);
-
- ret = data.writeWeakBinder(strong);
- EXPECT_EQ(NO_ERROR, ret);
-
- ret = server->transact(BINDER_LIB_TEST_PROMOTE_WEAK_REF_TRANSACTION, data, &reply);
- EXPECT_GE(ret, 0);
-}
-
-class BinderLibTestService : public BBinder
-{
- public:
- BinderLibTestService(int32_t id)
- : m_id(id)
- , m_nextServerId(id + 1)
- , m_serverStartRequested(false)
- {
- pthread_mutex_init(&m_serverWaitMutex, NULL);
- pthread_cond_init(&m_serverWaitCond, NULL);
- }
- ~BinderLibTestService()
- {
- exit(EXIT_SUCCESS);
- }
- virtual status_t onTransact(uint32_t code,
- const Parcel& data, Parcel* reply,
- uint32_t flags = 0) {
- //printf("%s: code %d\n", __func__, code);
- (void)flags;
-
- if (getuid() != (uid_t)IPCThreadState::self()->getCallingUid()) {
- return PERMISSION_DENIED;
- }
- switch (code) {
- case BINDER_LIB_TEST_REGISTER_SERVER: {
- int32_t id;
- sp<IBinder> binder;
- id = data.readInt32();
- binder = data.readStrongBinder();
- if (binder == NULL) {
- return BAD_VALUE;
- }
-
- if (m_id != 0)
- return INVALID_OPERATION;
-
- pthread_mutex_lock(&m_serverWaitMutex);
- if (m_serverStartRequested) {
- m_serverStartRequested = false;
- m_serverStarted = binder;
- pthread_cond_signal(&m_serverWaitCond);
- }
- pthread_mutex_unlock(&m_serverWaitMutex);
- return NO_ERROR;
- }
- case BINDER_LIB_TEST_ADD_SERVER: {
- int ret;
- uint8_t buf[1] = { 0 };
- int serverid;
-
- if (m_id != 0) {
- return INVALID_OPERATION;
- }
- pthread_mutex_lock(&m_serverWaitMutex);
- if (m_serverStartRequested) {
- ret = -EBUSY;
- } else {
- serverid = m_nextServerId++;
- m_serverStartRequested = true;
-
- pthread_mutex_unlock(&m_serverWaitMutex);
- ret = start_server_process(serverid);
- pthread_mutex_lock(&m_serverWaitMutex);
- }
- if (ret > 0) {
- if (m_serverStartRequested) {
- struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
- ts.tv_sec += 5;
- ret = pthread_cond_timedwait(&m_serverWaitCond, &m_serverWaitMutex, &ts);
- }
- if (m_serverStartRequested) {
- m_serverStartRequested = false;
- ret = -ETIMEDOUT;
- } else {
- reply->writeStrongBinder(m_serverStarted);
- reply->writeInt32(serverid);
- m_serverStarted = NULL;
- ret = NO_ERROR;
- }
- } else if (ret >= 0) {
- m_serverStartRequested = false;
- ret = UNKNOWN_ERROR;
- }
- pthread_mutex_unlock(&m_serverWaitMutex);
- return ret;
- }
- case BINDER_LIB_TEST_NOP_TRANSACTION:
- return NO_ERROR;
- case BINDER_LIB_TEST_NOP_CALL_BACK: {
- Parcel data2, reply2;
- sp<IBinder> binder;
- binder = data.readStrongBinder();
- if (binder == NULL) {
- return BAD_VALUE;
- }
- reply2.writeInt32(NO_ERROR);
- binder->transact(BINDER_LIB_TEST_CALL_BACK, data2, &reply2);
- return NO_ERROR;
- }
- case BINDER_LIB_TEST_GET_ID_TRANSACTION:
- reply->writeInt32(m_id);
- return NO_ERROR;
- case BINDER_LIB_TEST_INDIRECT_TRANSACTION: {
- int32_t count;
- uint32_t indirect_code;
- sp<IBinder> binder;
-
- count = data.readInt32();
- reply->writeInt32(m_id);
- reply->writeInt32(count);
- for (int i = 0; i < count; i++) {
- binder = data.readStrongBinder();
- if (binder == NULL) {
- return BAD_VALUE;
- }
- indirect_code = data.readInt32();
- BinderLibTestBundle data2(&data);
- if (!data2.isValid()) {
- return BAD_VALUE;
- }
- BinderLibTestBundle reply2;
- binder->transact(indirect_code, data2, &reply2);
- reply2.appendTo(reply);
- }
- return NO_ERROR;
- }
- case BINDER_LIB_TEST_SET_ERROR_TRANSACTION:
- reply->setError(data.readInt32());
- return NO_ERROR;
- case BINDER_LIB_TEST_GET_PTR_SIZE_TRANSACTION:
- reply->writeInt32(sizeof(void *));
- return NO_ERROR;
- case BINDER_LIB_TEST_GET_STATUS_TRANSACTION:
- return NO_ERROR;
- case BINDER_LIB_TEST_ADD_STRONG_REF_TRANSACTION:
- m_strongRef = data.readStrongBinder();
- return NO_ERROR;
- case BINDER_LIB_TEST_LINK_DEATH_TRANSACTION: {
- int ret;
- Parcel data2, reply2;
- sp<TestDeathRecipient> testDeathRecipient = new TestDeathRecipient();
- sp<IBinder> target;
- sp<IBinder> callback;
-
- target = data.readStrongBinder();
- if (target == NULL) {
- return BAD_VALUE;
- }
- callback = data.readStrongBinder();
- if (callback == NULL) {
- return BAD_VALUE;
- }
- ret = target->linkToDeath(testDeathRecipient);
- if (ret == NO_ERROR)
- ret = testDeathRecipient->waitEvent(5);
- data2.writeInt32(ret);
- callback->transact(BINDER_LIB_TEST_CALL_BACK, data2, &reply2);
- return NO_ERROR;
- }
- case BINDER_LIB_TEST_WRITE_FILE_TRANSACTION: {
- int ret;
- int32_t size;
- const void *buf;
- int fd;
-
- fd = data.readFileDescriptor();
- if (fd < 0) {
- return BAD_VALUE;
- }
- ret = data.readInt32(&size);
- if (ret != NO_ERROR) {
- return ret;
- }
- buf = data.readInplace(size);
- if (buf == NULL) {
- return BAD_VALUE;
- }
- ret = write(fd, buf, size);
- if (ret != size)
- return UNKNOWN_ERROR;
- return NO_ERROR;
- }
- case BINDER_LIB_TEST_PROMOTE_WEAK_REF_TRANSACTION: {
- int ret;
- wp<IBinder> weak;
- sp<IBinder> strong;
- Parcel data2, reply2;
- sp<IServiceManager> sm = defaultServiceManager();
- sp<IBinder> server = sm->getService(binderLibTestServiceName);
-
- weak = data.readWeakBinder();
- if (weak == NULL) {
- return BAD_VALUE;
- }
- strong = weak.promote();
-
- ret = server->transact(BINDER_LIB_TEST_NOP_TRANSACTION, data2, &reply2);
- if (ret != NO_ERROR)
- exit(EXIT_FAILURE);
-
- if (strong == NULL) {
- reply->setError(1);
- }
- return NO_ERROR;
- }
- case BINDER_LIB_TEST_DELAYED_EXIT_TRANSACTION:
- alarm(10);
- return NO_ERROR;
- case BINDER_LIB_TEST_EXIT_TRANSACTION:
- while (wait(NULL) != -1 || errno != ECHILD)
- ;
- exit(EXIT_SUCCESS);
- default:
- return UNKNOWN_TRANSACTION;
- };
- }
- private:
- int32_t m_id;
- int32_t m_nextServerId;
- pthread_mutex_t m_serverWaitMutex;
- pthread_cond_t m_serverWaitCond;
- bool m_serverStartRequested;
- sp<IBinder> m_serverStarted;
- sp<IBinder> m_strongRef;
-};
-
-int run_server(int index, int readypipefd)
-{
- status_t ret;
- sp<IServiceManager> sm = defaultServiceManager();
- {
- sp<BinderLibTestService> testService = new BinderLibTestService(index);
- if (index == 0) {
- ret = sm->addService(binderLibTestServiceName, testService);
- } else {
- sp<IBinder> server = sm->getService(binderLibTestServiceName);
- Parcel data, reply;
- data.writeInt32(index);
- data.writeStrongBinder(testService);
-
- ret = server->transact(BINDER_LIB_TEST_REGISTER_SERVER, data, &reply);
- }
- }
- write(readypipefd, &ret, sizeof(ret));
- close(readypipefd);
- //printf("%s: ret %d\n", __func__, ret);
- if (ret)
- return 1;
- //printf("%s: joinThreadPool\n", __func__);
- ProcessState::self()->startThreadPool();
- IPCThreadState::self()->joinThreadPool();
- //printf("%s: joinThreadPool returned\n", __func__);
- return 1; /* joinThreadPool should not return */
-}
-
-int main(int argc, char **argv) {
- int ret;
-
- if (argc == 3 && !strcmp(argv[1], "--servername")) {
- binderservername = argv[2];
- } else {
- binderservername = argv[0];
- }
-
- if (argc == 4 && !strcmp(argv[1], binderserverarg)) {
- return run_server(atoi(argv[2]), atoi(argv[3]));
- }
-
- ::testing::InitGoogleTest(&argc, argv);
- binder_env = AddGlobalTestEnvironment(new BinderLibTestEnv());
- ProcessState::self()->startThreadPool();
- return RUN_ALL_TESTS();
-}
-
diff --git a/tests/binderThroughputTest.cpp b/tests/binderThroughputTest.cpp
deleted file mode 100644
index 71b96d4..0000000
--- a/tests/binderThroughputTest.cpp
+++ /dev/null
@@ -1,317 +0,0 @@
-#include <binder/Binder.h>
-#include <binder/IBinder.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
-#include <string>
-#include <cstring>
-#include <cstdlib>
-#include <cstdio>
-
-#include <iostream>
-#include <vector>
-#include <tuple>
-
-#include <unistd.h>
-#include <sys/wait.h>
-
-using namespace std;
-using namespace android;
-
-enum BinderWorkerServiceCode {
- BINDER_NOP = IBinder::FIRST_CALL_TRANSACTION,
-};
-
-#define ASSERT_TRUE(cond) \
-do { \
- if (!(cond)) {\
- cerr << __func__ << ":" << __LINE__ << " condition:" << #cond << " failed\n" << endl; \
- exit(EXIT_FAILURE); \
- } \
-} while (0)
-
-class BinderWorkerService : public BBinder
-{
-public:
- BinderWorkerService() {}
- ~BinderWorkerService() {}
- virtual status_t onTransact(uint32_t code,
- const Parcel& data, Parcel* reply,
- uint32_t flags = 0) {
- (void)flags;
- (void)data;
- (void)reply;
- switch (code) {
- case BINDER_NOP:
- return NO_ERROR;
- default:
- return UNKNOWN_TRANSACTION;
- };
- }
-};
-
-class Pipe {
- int m_readFd;
- int m_writeFd;
- Pipe(int readFd, int writeFd) : m_readFd{readFd}, m_writeFd{writeFd} {}
- Pipe(const Pipe &) = delete;
- Pipe& operator=(const Pipe &) = delete;
- Pipe& operator=(const Pipe &&) = delete;
-public:
- Pipe(Pipe&& rval) noexcept {
- m_readFd = rval.m_readFd;
- m_writeFd = rval.m_writeFd;
- rval.m_readFd = 0;
- rval.m_writeFd = 0;
- }
- ~Pipe() {
- if (m_readFd)
- close(m_readFd);
- if (m_writeFd)
- close(m_writeFd);
- }
- void signal() {
- bool val = true;
- int error = write(m_writeFd, &val, sizeof(val));
- ASSERT_TRUE(error >= 0);
- };
- void wait() {
- bool val = false;
- int error = read(m_readFd, &val, sizeof(val));
- ASSERT_TRUE(error >= 0);
- }
- template <typename T> void send(const T& v) {
- int error = write(m_writeFd, &v, sizeof(T));
- ASSERT_TRUE(error >= 0);
- }
- template <typename T> void recv(T& v) {
- int error = read(m_readFd, &v, sizeof(T));
- ASSERT_TRUE(error >= 0);
- }
- static tuple<Pipe, Pipe> createPipePair() {
- int a[2];
- int b[2];
-
- int error1 = pipe(a);
- int error2 = pipe(b);
- ASSERT_TRUE(error1 >= 0);
- ASSERT_TRUE(error2 >= 0);
-
- return make_tuple(Pipe(a[0], b[1]), Pipe(b[0], a[1]));
- }
-};
-
-static const uint32_t num_buckets = 128;
-static const uint64_t max_time_bucket = 50ull * 1000000;
-static const uint64_t time_per_bucket = max_time_bucket / num_buckets;
-static constexpr float time_per_bucket_ms = time_per_bucket / 1.0E6;
-
-struct ProcResults {
- uint64_t m_best = max_time_bucket;
- uint64_t m_worst = 0;
- uint32_t m_buckets[num_buckets] = {0};
- uint64_t m_transactions = 0;
- uint64_t m_total_time = 0;
-
- void add_time(uint64_t time) {
- m_buckets[min(time, max_time_bucket-1) / time_per_bucket] += 1;
- m_best = min(time, m_best);
- m_worst = max(time, m_worst);
- m_transactions += 1;
- m_total_time += time;
- }
- static ProcResults combine(const ProcResults& a, const ProcResults& b) {
- ProcResults ret;
- for (int i = 0; i < num_buckets; i++) {
- ret.m_buckets[i] = a.m_buckets[i] + b.m_buckets[i];
- }
- ret.m_worst = max(a.m_worst, b.m_worst);
- ret.m_best = min(a.m_best, b.m_best);
- ret.m_transactions = a.m_transactions + b.m_transactions;
- ret.m_total_time = a.m_total_time + b.m_total_time;
- return ret;
- }
- void dump() {
- double best = (double)m_best / 1.0E6;
- double worst = (double)m_worst / 1.0E6;
- double average = (double)m_total_time / m_transactions / 1.0E6;
- cout << "average:" << average << "ms worst:" << worst << "ms best:" << best << "ms" << endl;
-
- uint64_t cur_total = 0;
- for (int i = 0; i < num_buckets; i++) {
- float cur_time = time_per_bucket_ms * i + 0.5f * time_per_bucket_ms;
- if ((cur_total < 0.5f * m_transactions) && (cur_total + m_buckets[i] >= 0.5f * m_transactions)) {
- cout << "50%: " << cur_time << " ";
- }
- if ((cur_total < 0.9f * m_transactions) && (cur_total + m_buckets[i] >= 0.9f * m_transactions)) {
- cout << "90%: " << cur_time << " ";
- }
- if ((cur_total < 0.95f * m_transactions) && (cur_total + m_buckets[i] >= 0.95f * m_transactions)) {
- cout << "95%: " << cur_time << " ";
- }
- if ((cur_total < 0.99f * m_transactions) && (cur_total + m_buckets[i] >= 0.99f * m_transactions)) {
- cout << "99%: " << cur_time << " ";
- }
- cur_total += m_buckets[i];
- }
- cout << endl;
-
- }
-};
-
-String16 generateServiceName(int num)
-{
- char num_str[32];
- snprintf(num_str, sizeof(num_str), "%d", num);
- String16 serviceName = String16("binderWorker") + String16(num_str);
- return serviceName;
-}
-
-void worker_fx(
- int num,
- int worker_count,
- int iterations,
- Pipe p)
-{
- // Create BinderWorkerService and for go.
- ProcessState::self()->startThreadPool();
- sp<IServiceManager> serviceMgr = defaultServiceManager();
- sp<BinderWorkerService> service = new BinderWorkerService;
- serviceMgr->addService(generateServiceName(num), service);
-
- srand(num);
- p.signal();
- p.wait();
-
- // Get references to other binder services.
- cout << "Created BinderWorker" << num << endl;
- (void)worker_count;
- vector<sp<IBinder> > workers;
- for (int i = 0; i < worker_count; i++) {
- if (num == i)
- continue;
- workers.push_back(serviceMgr->getService(generateServiceName(i)));
- }
-
- // Run the benchmark.
- ProcResults results;
- chrono::time_point<chrono::high_resolution_clock> start, end;
- for (int i = 0; i < iterations; i++) {
- int target = rand() % workers.size();
- Parcel data, reply;
- start = chrono::high_resolution_clock::now();
- status_t ret = workers[target]->transact(BINDER_NOP, data, &reply);
- end = chrono::high_resolution_clock::now();
-
- uint64_t cur_time = uint64_t(chrono::duration_cast<chrono::nanoseconds>(end - start).count());
- results.add_time(cur_time);
-
- if (ret != NO_ERROR) {
- cout << "thread " << num << " failed " << ret << "i : " << i << endl;
- exit(EXIT_FAILURE);
- }
- }
- // Signal completion to master and wait.
- p.signal();
- p.wait();
-
- // Send results to master and wait for go to exit.
- p.send(results);
- p.wait();
-
- exit(EXIT_SUCCESS);
-}
-
-Pipe make_worker(int num, int iterations, int worker_count)
-{
- auto pipe_pair = Pipe::createPipePair();
- pid_t pid = fork();
- if (pid) {
- /* parent */
- return move(get<0>(pipe_pair));
- } else {
- /* child */
- worker_fx(num, worker_count, iterations, move(get<1>(pipe_pair)));
- /* never get here */
- return move(get<0>(pipe_pair));
- }
-
-}
-
-void wait_all(vector<Pipe>& v)
-{
- for (int i = 0; i < v.size(); i++) {
- v[i].wait();
- }
-}
-
-void signal_all(vector<Pipe>& v)
-{
- for (int i = 0; i < v.size(); i++) {
- v[i].signal();
- }
-}
-
-int main(int argc, char *argv[])
-{
- int workers = 2;
- int iterations = 10000;
- (void)argc;
- (void)argv;
- vector<Pipe> pipes;
-
- // Parse arguments.
- for (int i = 1; i < argc; i++) {
- if (string(argv[i]) == "-w") {
- workers = atoi(argv[i+1]);
- i++;
- continue;
- }
- if (string(argv[i]) == "-i") {
- iterations = atoi(argv[i+1]);
- i++;
- continue;
- }
- }
-
- // Create all the workers and wait for them to spawn.
- for (int i = 0; i < workers; i++) {
- pipes.push_back(make_worker(i, iterations, workers));
- }
- wait_all(pipes);
-
-
- // Run the workers and wait for completion.
- chrono::time_point<chrono::high_resolution_clock> start, end;
- cout << "waiting for workers to complete" << endl;
- start = chrono::high_resolution_clock::now();
- signal_all(pipes);
- wait_all(pipes);
- end = chrono::high_resolution_clock::now();
-
- // Calculate overall throughput.
- double iterations_per_sec = double(iterations * workers) / (chrono::duration_cast<chrono::nanoseconds>(end - start).count() / 1.0E9);
- cout << "iterations per sec: " << iterations_per_sec << endl;
-
- // Collect all results from the workers.
- cout << "collecting results" << endl;
- signal_all(pipes);
- ProcResults tot_results;
- for (int i = 0; i < workers; i++) {
- ProcResults tmp_results;
- pipes[i].recv(tmp_results);
- tot_results = ProcResults::combine(tot_results, tmp_results);
- }
- tot_results.dump();
-
- // Kill all the workers.
- cout << "killing workers" << endl;
- signal_all(pipes);
- for (int i = 0; i < workers; i++) {
- int status;
- wait(&status);
- if (status != 0) {
- cout << "nonzero child status" << status << endl;
- }
- }
- return 0;
-}