summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin Moore <devinmoore@google.com>2023-12-20 18:43:12 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-12-20 18:43:12 +0000
commit64ef97791897ce31a6352796f92178f2b3767446 (patch)
treef4b329bd3fd3b50ca15499426cbcef1212c961e2
parentfdbbd0af752fd6b67ec7bc2d4f0002f1be74a23e (diff)
parent6bfea81ec0fe6301e85cd656381b5d15d3702f28 (diff)
downloadlibhidl-64ef97791897ce31a6352796f92178f2b3767446.tar.gz
Prepare for android.hidl.allocator deprecation am: 4ed17b5f7c am: fe4d3522c6 am: 6bfea81ec0
Original change: https://android-review.googlesource.com/c/platform/system/libhidl/+/2853457 Change-Id: I753525dcbab9fe51beacb96678a27f8bb42f9111 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--transport/allocator/1.0/default/android.hidl.allocator@1.0-service.rc3
-rw-r--r--transport/allocator/1.0/default/service.cpp31
2 files changed, 28 insertions, 6 deletions
diff --git a/transport/allocator/1.0/default/android.hidl.allocator@1.0-service.rc b/transport/allocator/1.0/default/android.hidl.allocator@1.0-service.rc
index c648aff..a0ffbad 100644
--- a/transport/allocator/1.0/default/android.hidl.allocator@1.0-service.rc
+++ b/transport/allocator/1.0/default/android.hidl.allocator@1.0-service.rc
@@ -2,3 +2,6 @@ service hidl_memory /system/system_ext/bin/hw/android.hidl.allocator@1.0-service
class hal
user system
group system
+
+on property:hidl_memory.disabled=true
+ stop hidl_memory
diff --git a/transport/allocator/1.0/default/service.cpp b/transport/allocator/1.0/default/service.cpp
index 63babd3..d918aae 100644
--- a/transport/allocator/1.0/default/service.cpp
+++ b/transport/allocator/1.0/default/service.cpp
@@ -4,24 +4,43 @@
#include <android-base/logging.h>
#include <android/hidl/allocator/1.0/IAllocator.h>
+#include <android/hidl/manager/1.2/IServiceManager.h>
+#include <cutils/properties.h>
#include <hidl/HidlTransportSupport.h>
+using android::sp;
+using android::status_t;
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using android::hidl::allocator::V1_0::IAllocator;
using android::hidl::allocator::V1_0::implementation::AshmemAllocator;
-using android::sp;
-using android::status_t;
+using android::hidl::manager::V1_2::IServiceManager;
+
+static constexpr char kInstanceName[] = "ashmem";
int main() {
configureRpcThreadpool(1, true /* callerWillJoin */);
sp<IAllocator> allocator = new AshmemAllocator();
- status_t status = allocator->registerAsService("ashmem");
-
- if (android::OK != status) {
- LOG(FATAL) << "Unable to register allocator service: " << status;
+ IServiceManager::Transport transport =
+ android::hardware::defaultServiceManager1_2()->getTransport(IAllocator::descriptor,
+ kInstanceName);
+ if (transport == IServiceManager::Transport::HWBINDER) {
+ status_t status = allocator->registerAsService(kInstanceName);
+ if (android::OK != status) {
+ LOG(FATAL) << "Unable to register allocator service: " << status;
+ return -1;
+ }
+ } else {
+ LOG(INFO) << IAllocator::descriptor << "/" << kInstanceName
+ << " is not registered in the VINTF manifest as it is deprecated.";
+ // The transport won't change at run time, so make sure we don't restart
+ int rc = property_set("hidl_memory.disabled", "true");
+ if (rc) {
+ LOG_ALWAYS_FATAL("Failed to set \"hidl_memory.disabled\" (error %d).\"", rc);
+ }
+ return 0;
}
joinRpcThreadpool();