memory: IAllocator is always binderized.
Benefits:
- single process allocates all of the shared memory (allows us to get
statitistics).
- prevents us from having to open up the allocator in passthrough mode
forever.
- prevents us from having to include/require android.hidl.memory@1.0-impl
elsewhere
Bug: 32185232
Test: hidl_test
Change-Id: I37be6a4afb14a79df457e166aa4b99de416b8f40
diff --git a/transport/memory/1.0/default/Android.bp b/transport/memory/1.0/default/Android.bp
index 4bc24a2..2b89f07 100644
--- a/transport/memory/1.0/default/Android.bp
+++ b/transport/memory/1.0/default/Android.bp
@@ -16,7 +16,6 @@
name: "android.hidl.memory@1.0-impl",
relative_install_path: "hw",
srcs: [
- "AshmemAllocator.cpp",
"AshmemMapper.cpp",
"AshmemMemory.cpp",
"HidlFetch.cpp"
@@ -39,7 +38,10 @@
cc_binary {
name: "android.hidl.memory@1.0-service",
relative_install_path: "hw",
- srcs: ["service.cpp"],
+ srcs: [
+ "AshmemAllocator.cpp",
+ "service.cpp"
+ ],
init_rc: ["android.hidl.memory@1.0-service.rc"],
shared_libs: [
@@ -48,8 +50,10 @@
"libhidlbase",
"libhidltransport",
"libhwbinder",
+ "libbase",
"liblog",
"libutils",
+ "libcutils",
],
required: [
diff --git a/transport/memory/1.0/default/HidlFetch.cpp b/transport/memory/1.0/default/HidlFetch.cpp
index 8236055..adb55d3 100644
--- a/transport/memory/1.0/default/HidlFetch.cpp
+++ b/transport/memory/1.0/default/HidlFetch.cpp
@@ -27,14 +27,6 @@
namespace V1_0 {
namespace implementation {
-IAllocator* HIDL_FETCH_IAllocator(const char* name) {
- if (name == kAshmemMemoryName) {
- return new AshmemAllocator;
- }
-
- return nullptr;
-}
-
IMapper* HIDL_FETCH_IMapper(const char* name) {
if (name == kAshmemMemoryName) {
return new AshmemMapper;
diff --git a/transport/memory/1.0/default/HidlFetch.h b/transport/memory/1.0/default/HidlFetch.h
index a9d366f..389ca30 100644
--- a/transport/memory/1.0/default/HidlFetch.h
+++ b/transport/memory/1.0/default/HidlFetch.h
@@ -26,9 +26,6 @@
namespace V1_0 {
namespace implementation {
-// TODO: disable passthrough allocator. It's much better if it's in a centralized location
-extern "C" IAllocator* HIDL_FETCH_IAllocator(const char* name);
-
extern "C" IMapper* HIDL_FETCH_IMapper(const char* name);
} // namespace implementation
diff --git a/transport/memory/1.0/default/service.cpp b/transport/memory/1.0/default/service.cpp
index ff3a8e8..8ea8b8a 100644
--- a/transport/memory/1.0/default/service.cpp
+++ b/transport/memory/1.0/default/service.cpp
@@ -1,12 +1,31 @@
#define LOG_TAG "android.hidl.memory@1.0-service"
+#include "AshmemAllocator.h"
+
+#include <android-base/logging.h>
#include <android/hidl/memory/1.0/IAllocator.h>
+#include <hwbinder/IPCThreadState.h>
+#include <hwbinder/ProcessState.h>
-#include <hidl/LegacySupport.h>
-
+using android::hardware::IPCThreadState;
+using android::hardware::ProcessState;
using android::hidl::memory::V1_0::IAllocator;
-using android::hardware::defaultPassthroughServiceImplementation;
+using android::hidl::memory::V1_0::implementation::AshmemAllocator;
+using android::sp;
+using android::status_t;
int main() {
- return defaultPassthroughServiceImplementation<IAllocator>("ashmem");
+ sp<IAllocator> allocator = new AshmemAllocator();
+
+ status_t status = allocator->registerAsService("ashmem");
+
+ if (android::OK != status) {
+ LOG(FATAL) << "Unable to register allocator service: " << status;
+ }
+
+ ProcessState::self()->setThreadPoolMaxThreadCount(0);
+ ProcessState::self()->startThreadPool();
+ IPCThreadState::self()->joinThreadPool();
+
+ return -1;
}