ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

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

2022-03-03 11:33:16  阅读:87  来源: 互联网

标签:IPC mobis vendor service 03 HIDL hidltest HAL HidlTest


基于上一篇文章:
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

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有