summaryrefslogtreecommitdiff
path: root/transport/allocator/1.0/default/service.cpp
blob: d918aae35c453fdec4605d76347e63615e7232cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#define LOG_TAG "android.hidl.allocator@1.0-service"

#include "AshmemAllocator.h"

#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::hidl::manager::V1_2::IServiceManager;

static constexpr char kInstanceName[] = "ashmem";

int main() {
    configureRpcThreadpool(1, true /* callerWillJoin */);

    sp<IAllocator> allocator = new AshmemAllocator();

    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();

    return -1;
}