系统相关
首页 > 系统相关> > Android HIDL第一个demo编写: HIDL Test——实现Framework&App层与HAL进程IPC~Binderized模式

Android HIDL第一个demo编写: HIDL Test——实现Framework&App层与HAL进程IPC~Binderized模式

作者:互联网

基于上一篇文章:
Android HIDL第一个demo编写: HIDL Test——实现Framework&App层与HAL进程IPC
使用的是Passthrough模式,这里修改为使用Binderized模式:
service.cpp文件写法:

#define LOG_TAG "vendor.mobis.hidltest@1.0-service"

#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
#include <hidl/LegacySupport.h>
#include "HidlTest.h"

// libhwbinder
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;

using vendor::mobis::hidltest::V1_0::IHidlTest;
using vendor::mobis::hidltest::V1_0::implementation::HidlTest;

using android::sp;
using android::OK;
using android::status_t;

int main() {
    //和dev/hwbinder进行通信,设置最大的线程个数为4
    configureRpcThreadpool(1, true);

    // register HidlTest service
    sp<IHidlTest> mHidlTestService = new HidlTest();
    status_t status = mHidlTestService->registerAsService();
    if (status != OK) {
        ALOGE("Cannot register HidlTest HAL service");
        return 1;
    }
    ALOGI("TRIMBLE HidlTest HAL Ready.");

    //把当前线程加入到线程池
    joinRpcThreadpool();
    return 1;
}

该service对应的bp文件中要增加HidlTest.cpp:

cc_binary {
    proprietary: true,
    relative_install_path: "hw",
    defaults: ["hidl_defaults"],
    name: "vendor.mobis.hidltest@1.0-service",
    init_rc: ["vendor.mobis.hidltest@1.0-service.rc"],
    srcs: ["service.cpp", "HidlTest.cpp"],

    cflags: [
        "-Wall",
        "-Werror",
    ],

    shared_libs: [
        "liblog",
        "libdl",
        "libutils",
        "libhardware",
        "libhidlbase",
        "libhidltransport",
        "vendor.mobis.hidltest@1.0",
    ],

}

打印log查看结果:

junmatek@junmatek-HP-EliteDesk-800-G3-TWR:~$ adb logcat | grep -Ei "hello|HidlTest"
03-03 11:11:51.707  4546  4546 I vendor.mobis.hidltest@1.0-service: TRIMBLE HidlTest HAL Ready.
03-03 11:12:24.921  4460  4460 I android_os_HwBinder: HwBinder: Starting thread pool for default::vendor.mobis.hidltest@1.0::IHidlTest
03-03 11:12:24.921  4546  4546 I HidlTest: SLOGI HidlTest::helloWorld: Hello World, Mr.White
03-03 11:12:24.922  4460  4460 E EngineeringModeMainActivity: IHidlTestService.helloWorld:Hello World, Mr.White

标签:IPC,mobis,vendor,service,03,HIDL,hidltest,HAL,HidlTest
来源: https://blog.csdn.net/Heisenberg_Li/article/details/123228526