service相关文件的创建
1、例如:在vendor目录下创建文件夹,如vendor\xxx\xxx\hardware\interfaces:
a、添加配置文件Android.bp:
subdirs = [
"event"
]
b、Android.mk :
include $(call all-subdir-makefiles)
c、update-makefiles.sh :
#!/bin/bash
source system/tools/hidl/update-makefiles-helper.sh
do_makefiles_update \
"vendor.xxx.hardware:vendor/xxx/xxx/hardware/interfaces" \
"android.hardware:hardware/interfaces" \
"android.hidl:system/libhidl/transport"
2、创建文件夹event\1.0
a\在event目录下同样添加Android.bp、Android.mk文件
b\在1.0目录下添加types.hal(可选)、ITvEvent.hal、IEventInfoHw .hal、IEventListenerHw.hal
package [email protected];
import IEventListenerHw;
import IEventInfoHw;
interface ITvEvent {
oneway RegisterEventListener(uint8_t event,IEventListenerHw listener);
oneway UnregisterEventListener(uint8_t event,IEventListenerHw listener);
oneway SendEvent(IEventInfoHw info,string listener);
oneway SendBroadcast(IEventInfoHw info);
oneway DisableSystemTimeEvent(uint8_t event);
oneway EnableSystemTimeEvent(IEventInfoHw info,uint32_t time_usec);
};
package [email protected];
//这两个接口会在client传给service,他的实现我在后面default的c++文件中,并且打包成libXXX的动态库,生成到system\lib\libXXX.so;给jni的c++文件使用
interface IEventInfoHw {
getListenerName() generates (string name);
setListenerName(string name);
getString() generates (string name);
getU32Number() generates (uint32_t result);
getInfoType() generates (EN_EVENT_INFO_TYPE result);
getEventType() generates (uint8_t result);
setMsgType(bool type);
getMsgType() generates (bool result);
};
package [email protected];
import IEventInfoHw;
interface IEventListenerHw {
getListenerName() generates (string name);
OnEvent(IEventInfoHw info);
};
=============================================================================
添加完hal文件之后,需要在1.0的目录生成对应的Android.bp、Android.mk
可以执行android\o-base $:source vendor\xxx\xxx\hardware\interfaces\update-makefiles.sh
如果hal有语法错误,该脚本是执行fail的,需要检查hal的语法;
到vendor\xxx\xxx\hardware\interfaces 或者直接到1.0的目录,执行局部编译mm/mm -B,就会在out\target\common\gen\JAVA_LIBRARIES 下生成Android.bp中要out的文件
3、创建文件夹event\1.0\default
在Ubuntu分别执行以下命令,
croot
PKG_ROOT=vendor/xxx/xxx/hardware/interfaces
HIDL_GEN_OUT=$PKG_ROOT/event/1.0/default/
//可以生成C,java的文件,下面是我用到C++实现
hidl-gen -o $HIDL_GEN_OUT -Lc++-impl -rvendor.xxx.hardware:$PKG_ROOT -randroid.hidl:system/libhidl/transport $PACKAGE
此时可以在default目录自动生成:
TvEvent.h\TvEvent.cpp\EventInfoHw.h\EventInfoHw.cpp\EventListenerHw.h\EventListenerHw.cpp
4、default目录下添加service.cpp
#define LOG_TAG "[email protected]"
#include
#include "TvEvent.h"
#include
#include
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using android::sp;
using android::status_t;
using android::OK;
using android::hardware::defaultPassthroughServiceImplementation;
using xxx::xxx::hardware::event::V1_0::ITvEvent;
using Oceanus::TvEvent;
int main() {
//configureRpcThreadpool(10, true);
//参考https://source.android.google.cn/devices/architecture/configstore/add-class-item
// sp
// status_t status = myTvEvent->registerAsService();
// LOG_ALWAYS_FATAL_IF(status != OK, "Could not register Foo as service");
// other interface registration comes here
// joinRpcThreadpool();
==》》实现是在[email protected]中,TvEvent需要把
ITvEvent* HIDL_FETCH_ITvEvent(const char* /* name */) {
return new Oceanus::TvEvent();
}
去掉。
return defaultPassthroughServiceImplementation
//是打包在[email protected]中;
系统起来后会调用HIDL_FETCH_ITvEvent的接口对TvEvent进行初始化
// Methods from ::android::hidl::base::V1_0::IBase follow.
}
5、default目录下添加[email protected]
service event-hal-1-0 /vendor/bin/hw/[email protected]
class hal
user system
group system
6、default目录下添加Android.mk
LOCAL_PATH := $(call my-dir)
################################################################################
include $(CLEAR_VARS)
LOCAL_MODULE := [email protected]
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := \
EventInfoHw.cpp \
TvEvent.cpp \
EventListenerHw.cpp
LOCAL_SHARED_LIBRARIES := libThreadPool\
libbase \
liblog \
libhardware \
libhidlbase \
libhidltransport \
libutils \
[email protected]_vendor \
LOCAL_C_INCLUDES += EventInfoHw.h\
EventListenerHw.h\
LOCAL_STATIC_LIBRARIES += libmxml \
libevent_static \
include $(BUILD_SHARED_LIBRARY)
##################################################
include $(CLEAR_VARS)
include $(OCEANUS_ROOT)/Build/AndroidCommon.mk
MODULE_NAME := EventHw
LOCAL_SRC_FILES := \
EventInfoHw.cpp \
EventListenerHw.cpp
LOCAL_SHARED_LIBRARIES := libThreadPool\
libbase \
liblog \
libhardware \
libhidlbase \
libhidltransport \
libutils \
[email protected]_vendor \
LOCAL_C_INCLUDES += EventInfoHw.h\
EventListenerHw.h\
LOCAL_STATIC_LIBRARIES += libmxml \
libevent_static \
LOCAL_MODULE := libOClt_$(MODULE_NAME)Manager
include $(BUILD_SHARED_LIBRARY)
#################################################
include $(CLEAR_VARS)
LOCAL_MODULE := [email protected]
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_INIT_RC := [email protected]
LOCAL_SRC_FILES:= \
service.cpp \
TvEvent.cpp
LOCAL_SHARED_LIBRARIES := libThreadPool\
[email protected]_vendor \
libhidlbase \
libhidltransport \
libbase \
liblog \
libutils \
libhardware \
LOCAL_C_INCLUDES += \
TvEvent.h\
LOCAL_STATIC_LIBRARIES += libmxml \
libevent_static \
include $(BUILD_EXECUTABLE)
此时去编译就可以在system\lib\hw、system\lib、system\bin\hw生成对应的so文件;注意:因为是自己开启的服务,在安卓8.0需要把对应的so文件生成到ventor目录下,否则vts认证会fail,或者so找不到情况。
我们还需要讨论该service的启动,另外发文章说明