1 #undef LOG_TAG
2 #define LOG_TAG "gralloc-allocator"
3 
4 #include <android/binder_ibinder_platform.h>
5 #include <android/binder_manager.h>
6 #include <android/binder_process.h>
7 #include <android/binder_status.h>
8 #include <log/log.h>
9 
10 #if defined(GRALLOC_MAPPER_4)
11 #include "aidl/GrallocAllocator.h"
12 #elif defined (GRALLOC_MAPPER_5)
13 #include "aidl/GrallocAllocator2.h"
14 #endif
15 
16 using namespace android;
17 
18 using pixel::allocator::GrallocAllocator;
19 
main()20 int main() {
21     auto service = ndk::SharedRefBase::make<GrallocAllocator>();
22     auto binder = service->asBinder();
23 
24     AIBinder_setInheritRt(binder.get(), true);
25     AIBinder_setMinSchedulerPolicy(binder.get(), SCHED_NORMAL, -20);
26 
27     const auto instance = std::string() + GrallocAllocator::descriptor + "/default";
28     auto status = AServiceManager_addServiceWithFlags(binder.get(), instance.c_str(),
29                                         AServiceManager_AddServiceFlag::ADD_SERVICE_ALLOW_ISOLATED);
30     if (status != STATUS_OK) {
31         ALOGE("Failed to start AIDL gralloc allocator service");
32         return -EINVAL;
33     }
34 
35     ABinderProcess_setThreadPoolMaxThreadCount(4);
36     ABinderProcess_startThreadPool();
37     ABinderProcess_joinThreadPool();
38 
39     return EXIT_FAILURE; // Unreachable
40 }
41