如何创建一个Hidl Service?

1. 工具

 创建工具脚本:hello_word1_0-hidl-gen.sh

#!/bin/bash
PACKAGE=android.hardware.hello_word@1.0
LOC=hardware/interfaces/hello_word/1.0/default/
#SS=android.hardware:hardware/interfaces
#TT=android.hidl:system/libhidl/transport

#hidl-gen -o . -Landroidbp -r$SS -r$TT $PACKAGE
#hidl-gen -L hash -r$SS -r$TT $PACKAGE
#hidl-gen -o $LOC -Lc++-impl -r$SS -r$TT $PACKAGE
#hidl-gen -o $LOC -Landroidbp-impl -r$SS -r$TT $PACKAGE
out/soong/host/linux-x86/bin/hidl-gen -o . -Landroidbp -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport $PACKAGE
out/soong/host/linux-x86/bin/hidl-gen -L hash -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport $PACKAGE
out/soong/host/linux-x86/bin/hidl-gen -o $LOC -Lc++-impl -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport $PACKAGE
out/soong/host/linux-x86/bin/hidl-gen -o $LOC -Landroidbp-impl -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport $PACKAGE

2. 创建.hal文件

#mkdir -p hardware/interfaces/hello_word/1.0

#cd hardware/interfaces/hello_word/1.0

#touch IHelloWordHidl.hal

#touch IHelloWordCallback.hal

 2.1 修改文件

IHelloWordHidl.hal

package android.hardware.hello_word@1.0;

import @1.0::IHelloWordCallback;
import @1.0::types;

/**
 * hello_word HAL, first modern version
 *
 * Supports the netlink API
 * API at LIMITED or better hardware level.
 *
 */

interface IHelloWordHidl {
	HelloWordSetCallback(IHelloWordCallback callback);
	HelloWordHidlInit() generates(uint32_t status);
	HelloWordHidlDeInit() generates(uint32_t status);
    HelloWordHidlStart() generates(uint32_t status);
    HelloWordHidlStop() generates(uint32_t status);
    oneway HelloWordHidlSend(hellword_packet_msg msg);//
};

HelloWordCallback.hal:

package android.hardware.hello_word@1.0;

import @1.0::types;

/**
 * hello_word HAL, first modern version
 *
 * Supports the netlink API
 * API at LIMITED or better hardware level.
 *
 */

interface IHelloWordCallback {
 	
	oneway notify(helloword_packet_msg msg);//for msg notify.
 	
};

 types.hal

package android.hardware.hello_word@1.0;

struct helloword_packet_msg
{
	uint32_t length;
	string msg;//msg;
	//memory data;
};

2.2 运行脚本

#./hello_word1_0-hidl-gen.sh

2.3  修改default/*.c文件

2.4  修改default/Android.bp文件

// FIXME: your file license if you have one
cc_binary {
    name: "android.hardware.hello_word@1.0-service",
    init_rc: ["android.hardware.hello_word@1.0-service.rc"],
    vintf_fragments: ["android.hardware.hello_word@1.0-service.xml"],
    relative_install_path: "hw",
    vendor: true,
    srcs: [
        "HelloWordHidl.cpp",
	    "service.cpp",
    ],
    shared_libs: [
        "liblog",
        "libdl",
        "libutils",
        "libcutils",
        "libhardware",
        "libhidlbase",
	    "libhidlmemory",
        "libhidltransport",
	    "android.hidl.allocator@1.0",
	    "android.hidl.memory@1.0",
        "android.hardware.hello_word@1.0",
    ],
}

2.5  增加服务相关文件

        service.cpp

        android.hardware.hello_word@1.0-service.rc

        android.hardware.hello_word@1.0-service.xml

  service.cpp:

#define LOG_TAG "android.hardware.hello_word@1.0-service"

#include <android/hardware/hello_word/1.0/IHelloWordHidl.h>
#include <hidl/LegacySupport.h>
#include <hidl/HidlTransportSupport.h>
#include "HelloWordHidl.h"

using android::hardware::hello_word::V1_0::IHelloWordHidl;
using android::hardware::hello_word::V1_0::implementation::IHelloWordHidl;
//using android::hardware::defaultPassthroughServiceImplementation;
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using android::sp;
using android::status_t;
using android::OK;


int main() {
    configureRpcThreadpool(3, true);//max thread number for request.
	
    sp<IHelloWordHidl> hello_word = new HelloWordHidl;
    status_t status = kevent_comm->registerAsService();
    ALOGW_IF(status != OK, "Could not register HelloWordHidl v1.0");
    ALOGD("Default service is ready.");

    joinRpcThreadpool();
    return 1;

}

  android.hardware.hello_word@1.0-service.rc:

service hello_word_1_0 /vendor/bin/hw/android.hardware.hello_word@1.0-service
    class hal
    user system
    group system

  android.hardware.kevent_comm@1.0-service:

<manifest version="1.0" type="device">
    <hal format="hidl">
        <name>android.hardware.hello_word</name>
        <transport>hwbinder</transport>
        <version>1.0</version>
        <interface>
            <name>IHelloWordHidl</name>
            <instance>default</instance>
        </interface>
    </hal>
</manifest>

3. 配置

3.1 device/<board>/目录下

manifest.xml://增加如下

<hal format="hidl">
    <name>android.hardware.hello_word</name>
    <transport>hwbinder</transport>
    <version>1.0</version>
    <interface>
        <name>IHelloWordHidl</name>
        <instance>default</instance>
    </interface>
</hal>

<board>.mk 文件增加:

PRODUCT_PACKAGES += android.hardware.hello_word@1.0 \
                    android.hardware.hello_word@1.0-service

3.2  build/make/target/product 目录下vndk api接口

修改current.txt //增加内容

VNDK-core: android.hardware.hello_word@1.0.so

修改<api_level>.txt //增加内容

VNDK-core: android.hardware.hello_word@1.0.so

编译报错:

ory
checkvintf E 01-31 15:33:30 3609151 3609151 check_vintf.cpp:554] files are incompatible: The following instances are in the device manifest but not specified in framework compatibility matrix:
checkvintf E 01-31 15:33:30 3609151 3609151 check_vintf.cpp:554]     android.hardware.hello_word@1.0::IHelloWordHidl/default
checkvintf E 01-31 15:33:30 3609151 3609151 check_vintf.cpp:554] Suggested fix:
checkvintf E 01-31 15:33:30 3609151 3609151 check_vintf.cpp:554] 1. Update deprecated HALs to the latest version.
checkvintf E 01-31 15:33:30 3609151 3609151 check_vintf.cpp:554] 2. Check for any typos in device manifest or framework compatibility matrices with FCM version >= 5.
checkvintf E 01-31 15:33:30 3609151 3609151 check_vintf.cpp:554] 3. For new platform HALs, add them to any framework compatibility matrix with FCM version >= 5 where applicable.
checkvintf E 01-31 15:33:30 3609151 3609151 check_vintf.cpp:554] 4. For device-specific HALs, add to DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE or DEVICE_PRODUCT_COMPATIBILITY_MATRIX_FILE.: Success
INCOMPATIBLE
 

修改:

 hardware/interfaces/compatibility_matrices/compatibility_matrix.5.xml

增加如下内容:

<hal format="hidl" optional="true">
    <name>android.hardware.hello_word</name>
    <version>1.0</version>
    <interface>
       <name>IHelloWordHidl</name>
       <instance>default</instance>
    </interface>
</hal>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

村里小码农

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值