当前位置:网站首页>Aidl for Hal
Aidl for Hal
2022-07-16 06:24:00 【Xintianjun 9527】
Android 11 Introduced in Android Use in AIDL Realization HAL The function of . So you can use it without HIDL In the case of Android Part of the code . We strongly recommend that you try to HAL Convert to use only AIDL( If upstream HAL Use HIDL, Must be used HIDL).
If HAL Use AIDL In frame assembly ( for example system.img Components in ) And hardware components ( for example vendor.img Components in ) Communicate with each other , You must use stable AIDL. however , If you need to communicate in the partition ( For example, from a HAL To another ), For the used IPC There are no restrictions on the mechanism .
motivation
AIDL Appear in the HIDL Before , And in Android It is used in many other places, such as between framework components or in applications . Now? , because AIDL With stability support , You can use only one IPC The runtime environment implements the entire stack . Besides ,AIDL The version control system of is also better than HIDL.
- Use only one IPC Language means only knowing 、 debugging 、 Optimize and protect a runtime environment .
- AIDL It can provide the interface owner with a built-in version control mechanism .
- Owners can add methods to Parcelable End of interface or field of . This means that version control of code can be simplified in the development process that lasts for many years , And reduce the cost year by year ( You can modify the type in place , And there is no need to add additional libraries to update the interface version ).
- Extension interfaces can be attached at run time , Instead of appending , Therefore, there is no need to expand downstream rebase To the new interface .
- If existing AIDL The owner of the interface chooses to stabilize it , This kind of interface can be used directly . If it was before , Must use HIDL Create a complete copy of the interface .
To write AIDL HAL Interface
In order for the system and suppliers to use a AIDL Interface , Two changes need to be made to this interface :
- Every type definition needs to have
@VintfStabilitynotes aidl_interfaceThe declaration needs to containstability: "vintf",
Only the interface owner can make these changes .
Besides , To maximize code portability and avoid potential problems ( For example, unnecessary additional libraries ), It is recommended that you disable CPP Back end .
aidl_interface: {
...
backends: {
cpp: {
enabled: false,
},
},
}lookup AIDL HAL Interface
AOSP in HAL The stability of the AIDL The basic directory where the interface is located is the same as HIDL The basic directory of the interface is the same , be located aidl In the folder .
- hardware/interfaces
- frameworks/hardware/interfaces
- system/hardware/interfaces
You should put the extension interface into vendor or hardware In the other hardware/interfaces subdirectories . It is strongly recommended that you maintain a consistent interface between all devices . Extensions can be registered in two different ways :
- Register at runtime
- Independent registration ( Register globally and at VINTF Internal registration )
in the light of AIDL Build the runtime environment
AIDL There are three different back ends :Java、NDK、CPP. If you need to use stable AIDL, You must always use at system/lib*/libbinder.so Of libbinder System copy of , And be able to access /dev/binder. For the code in the vendor image , It means libbinder( come from VNDK) Can't use : This library contains unstable C++ API And unstable internals . The native vendor code must use AIDL Of NDK Back end , link to libbinder_ndk( By system libbinder.so Provide support ), And link to by aidl_interface Items created -ndk_platform library .
AIDL HAL Server instance name
By convention ,AIDL HAL The instance name of the service should be in the following format :$package.$type/$instance. for example , Vibrator HAL The registered name of the instance is android.hardware.vibrator.IVibrator/default.
To write AIDL HAL The server
Must be in VINTF The manifest States AIDL The server , Examples are as follows :
<hal format="aidl">
<name>android.hardware.vibrator</name>
<fqname>IVibrator/default</fqname>
</hal>otherwise , They should be registered normally AIDL service . function VTS When testing , All declared AIDL HAL Should be available
To write AIDL client
AIDL The client must declare itself in the compatibility matrix , Examples are as follows :
<name>android.hardware.vibrator</name>
<interface>
<name>IVibrator</name>
<instance>default</instance>
</interface>Put the existing HAL from HIDL Convert to AIDL
Use hidl2aidl Tools will HIDL Interface to AIDL. Follow the steps below , take .hal The package is converted to .aidl file :
Build the tool ( be located
system/tools/hidl/hidl2aidlinm hidl2aidlUse the following command to execute the tool : The output directory , Followed by the package to be converted
hidl2aidl -o <output directory> <package>Read the generated file carefully , And solve any conversion problems .
conversion.logInclude all unresolved issues that should be resolved first .
Generated.aidlThe file may contain some warnings and suggestions that you need to deal with accordingly . These notes are in//start .
Please seize this opportunity , Clean up and improve the package .
Apply to AIDL HAL Of sepolicy
Visible to supplier code AIDL The service type must have vendor_service attribute . otherwise ,sepolicy Configuration will work with any other AIDL The service is the same
type hal_power_service, service_manager_type, vendor_service;
For most services defined by the platform , A service context with the correct type has been added ( for example ,android.hardware.power.IPower/default Has been marked as hal_power_service). however , If the framework client supports multiple instance names , Must be dedicated to the equipment service_contexts Add other instance names to the file
android.hardware.power.IPower/custom_instance u:object_r:hal_power_service:s0
AIDL And HIDL The main difference between
Use AIDL HAL Or use AIDL HAL Interface , Please note and write HIDL HAL The difference of .
- AIDL The grammar of language is closer Java.HIDL The grammar of a language is similar to C++.
- all AIDL Interfaces have built-in error states . Do not create custom state types , Instead, create a constant state in the interface file int, And in CPP/NDK The back-end using
EX_SERVICE_SPECIFIC, stay Java The back-end usingServiceSpecificException. - Unchecked transmission errors do not cause AIDL Terminate run ( Unchecked errors can lead to HIDL
ReturnTerminate run ). - AIDL Only one type can be declared for each file .
- except output Out of parameters ,AIDL Parameters can also be specified as in/out/inout( No, “ Synchronous callback ”).
- AIDL take fd Used as primitive type , Not the handle .
- HIDL Use for incompatible changes Major edition , Use for compatible changes Minor edition . stay AIDL in , Backward compatible changes are in place . AIDL No, right Major The version is clearly defined , Instead, it is incorporated into the package name . for example ,AIDL The package name may be used
bluetooth2.
边栏推荐
- 【ICCV2021】Tokens-to-Token ViT: Training Vision Transformers From Scratch on ImageNet
- RT_thread信号量的使用
- EasyCVR国标协议接入设备,设备在线、通道却不在线的原因是什么?
- Customize breadcrumb navigation
- 论文阅读笔记——Crop yield prediction using deep neural networks
- [notes de thèse] - réseau vgg - 2014 - ICLR
- RT_thread空闲线程及两个常用的钩子函数
- C语言经典100题练习(1~21)
- 第二章 SYN6288语音合成模块的使用
- 常用学术文献数据库界面及导出参考文献方法
猜你喜欢
随机推荐
Do you really understand JS event cycle
[paper notes] - low illumination image enhancement - zero samples - ruas Network - 2021-cvpr
如何分析粉丝兴趣?
Alibaba cloud centos7 installation and remote link MySQL
HDU 1530 Maximum Clique (最大团)
【代码笔记】RRDNet 网络
GAN:Generative Adversarial Nets——论文分析及其背后的数学概念
数据不平衡:反欺诈模型(数据不平衡)综合采样
【ARXIV2205】Inception Transformer
[missing session L5] command line environment (process control, TMUX, alias, configuration, SSH)
CPU及内存占用过高,如何修改RTSP轮巡检测参数以降低服务器消耗?
董军宇教授在 “同心坚守 研学战疫”学术系列活动做报告
2021-07-19
第二章 SYN6288语音合成模块的使用
HTTP 缓存机制详解
【MIT Missing Semester 2】Shell Tools
【论文笔记】—低照度图像增强—ZeroShot—RetinexDIP网络—2021-TCSVT
Cgrect, cgpoint, etc. cannot be added to the array problem
【ARXIV2204】Simple Baselines for Image Restoration
Nine features of microservice architecture









