【发布时间】:2018-01-30 12:42:33
【问题描述】:
我正在尝试将用 C++ 编写的本机服务添加到 AOSP 构建中。
我做的第一件事是为 AOSP 构建创建本机服务和客户端。
这按预期工作。我可以在 adb shell 中启动服务并通过 adb shell 上的 binder 调用它。
当我想用 init 启动我的服务时,问题就开始了。
我在构建中添加了一个 .rc 文件
service myp /system/bin/myp_service
class main
这成功了,因此 init 尝试启动它,但由于 SELinux 政策而失败。
所以我在设备树中添加了file_contexts 并添加了:
/system/bin/myp_service u:object_r:myp_exec:s0
接下来我添加了一个myp.te文件并添加了:
type myp, domain;
type myp_exec, exec_type, file_type;
type myp_service, service_manager_type;
init_daemon_domain(myp)
net_domain(myp)
binder_use(myp)
binder_service(myp)
add_service(myp, myp_service)
binder_call(myp, binderservicedomain)
binder_call(myp, appdomain)
allow myp myp_service:service_manager add;
最后我添加了一个service_contexts 文件:
myp u:object_r:myp_service:s0
这终于使我的服务在启动时成功启动。 不幸的是,我不能对这项服务使用活页夹。当我尝试使用我的客户端连接到服务时,调用
defaultServiceManager()->getService(String16("Demo"))
返回一个空指针。
我在dmesg 中找不到任何提示。
所以我认为我仍然缺少 SElinux 的一些东西,但我不知道我缺少什么。
如果我用setenforce 关闭 SELinux 并重新启动服务,那么它工作正常。
谁能给我一个提示,我在 SELinux 中缺少什么,或者我可以在哪里获得有关哪个策略阻止某些内容的更多信息?
【问题讨论】: