HIDL学习笔记_3

HIDL系列四 绑定式的案例及理解(多篇):  https://chendongqi.me/2019/09/08/hidl-binderizd/
Android Treble 架构下的HIDL:https://ruleizhou.github.io/2019/07/25/Android-Treble-%E6%9E%B6%E6%9E%84%E4%B8%8B%E7%9A%84HIDL/  --已看

 

一、passthrough 模式HAL的注册和使用

1. service 注册

使用 HIDL 接口,hidl-gen 产生 cpp 代码后,将下面的注释去掉,使用这个直通式的注册函数

IPerf* HIDL_FETCH_IPerf(const char* /* name */) {
    LOG_D("+");
    return new Perf();
}

然后到生成的 perf.cpp 中实现 Perf 类。

 

2. client 使用

(1) 获取服务

static android::sp<IPerfV1_0> gPerfHalV1_0 = nullptr;
static android::sp<IPerfV1_1> gPerfHalV1_1 = nullptr;
static android::sp<IPerfV1_2> gPerfHalV1_2 = nullptr;

static bool getPerfHal() {
    if (gPerfHalV1_0 == nullptr) {
        gPerfHalV1_0 = IPerfV1_0::getService();
        if (gPerfHalV1_0 != nullptr) {
            ALOGI("Loaded perf HAL 1.0 service");
            gPerfHalV1_1 = IPerfV1_1::castFrom(gPerfHalV1_0);
            if (gPerfHalV1_1 != nullptr) {
                ALOGI("Loaded perf HAL 1.1 service");
                    gPerfHalV1_2 = IPerfV1_2::castFrom(gPerfHalV1_1);
                    if (gPerfHalV1_2 != nullptr)
                        ALOGI("Loaded perf HAL 1.2 service");
            }
        } else {
            ALOGI("Couldn't load power HAL service");
            gPerfHalExists = false;
        }
    }

    if (gPerfHalV1_2 == nullptr) {
        ALOGE("[getPerfHal] nullptr");
        return false;
    }

    return true;
}

(2) 使用服务

gPerfHalV1_2->perfLockAcquire(hdl, duration, rscList, my_tid);
gPerfHalV1_2->perfLockRelease(hdl, my_tid);

 

3. 说明

这种直通式的hal,hal的响应函数是运行在调用者的线程的,没有经过binder跨进程调用。使用 service list 命令也看不到HIDL直通式实现的hal,也说明了其不是一个hal服务。

# service list | grep Perf
//对比:
# service list | grep suspend
269     suspend_control: [android.system.suspend.ISuspendControlService]

 

posted on 2021-11-20 14:37  Hello-World3  阅读(186)  评论(0编辑  收藏  举报

导航