如果想要了解selinux
的介绍可以戳AOSP安全策略SElinux_android以及问题排查思路,有助于更深的理解和应用。
关于HAL服务
Android 8.0推出了新的hwservice,具体概念请参考Google官⽹。⼀般⽤来增加新的硬件,如NFC/指
纹/虹膜识别等模块。
这⾥以添加NXP公司的NFC模块为例,说明如何增加新的HAL服务
添加instance
get_build_var DEVICE_MANIFEST_FILE,
修改执⾏结果列出的⽂件,增加⾃⼰的服务节点,如: device/rockchip/common/manifest.xml
<hal format="hidl">
<name>vendor.nxp.nxpnfc</name>
<transport>hwbinder</transport>
<version>1.0</version>
<interface>
<name>INxpNfc</name>
<instance>default</instance>
</interface>
</hal>
通过hwservice统⼀调⽤,rc⽂件写法
service vendor.nxp.nxpnfc-1-0 /vendor/bin/hw/vendor.nxp.nxpnfc@1.0-service
class hal
user system
group system
# 如果在rc⽂件中添加了 'class hal',即归类为hal服务,会在init的start hal阶段通过
# hwservice启动所有的hal服务
声明为hwservice
get_build_var BOARD_SEPOLICY_DIRS
修改执⾏结果列出的⽂件夹中的
hwservice.te:
type vnd_nxpnfc_hwservice, hwservice_manager_type;
给service⽂件打标签绑定
get_build_var BOARD_SEPOLICY_DIRS
修改执⾏结果列出的⽂件夹中的
file_contexts:
/vendor/bin/hw/vendor\.nxp\.nxpnfc@1\.0-service u:object_r:nxpnfc_hal_exec:s0
绑定到manifest 的instance节点
get_build_var BOARD_SEPOLICY_DIRS
修改执⾏结果列出的⽂件夹中的
hwservice_contexts:
vendor.nxp.nxpnfc::INxpNfc (对照manifest中增加的instance,别写错)
u:object_r:vnd_nxpnfc_hwservice:s0
服务的声明
get_build_var BOARD_SEPOLICY_DIRS
执⾏结果列出的⽂件夹中新建
nxpnfc.te:
type nxpnfc_hal, domain;
type nxpnfc_hal_exec, exec_type, vendor_file_type, file_type;
init_daemon_domain(nxpnfc_hal)
add_hwservice(nfc, vnd_nxpnfc_hwservice) # 如果是通过nfc进程启动新加的服务,才需要添