当前位置: 代码迷 >> 综合 >> ServiceManager add_service SELinux Permission Denied
  详细解决方案

ServiceManager add_service SELinux Permission Denied

热度:22   发布时间:2024-01-17 08:16:12.0

问题点:

在systemserver.java中添加如下代码,向servicemanager进程中添加一个service

<span style="font-size:18px;">			try {Slog.i(TAG, "Hello Service");ServiceManager.addService("hello", new HelloService());// } catch (Throwable e) {Slog.e(TAG, "Failure starting Hello Service", e);} </span>

servicemanager是BINDER的管理者,负责协调Android里的进程通信。这里添加的helloservice是一个硬件管理服务,运行在单独的进程里,如果APP想要使用这个服务就必须通过servicemanager查询和调用。

执行代码的时候出现了如下错误:

<span style="font-size:18px;"> E SELinux : avc:  denied  { add } for service=hello scontext=u:r:system_server:s0 tcontext=u:object_r:default_android_service:s0 tclass=service_managerE ServiceManager: add_service('hello',62) uid=1000 - PERMISSION DENIED</span>
提示为SELinux Permission Denied 。解决办法参考:http://stackoverflow.com/questions/30165852/selinux-permission-denied-for-a-new-framework-service-in-android 

解决办法:

To file:

android-dev\external\sepolicy\service.te

Add:

type mytest_service, system_api_service, system_server_service, service_manager_type;

To file:

android-dev\external\sepolicy\service_contexts

Add:

mytestservice u:object_r:mytest_service:s0

where mytestservice your name service

我的hello 在\external\sepolicy\service.te 添加了:

<span style="font-size:18px;">type hello_service, system_api_service, system_server_service, service_manager_type;</span>
在 \external\sepolicy\service_contexts
添加

<span style="font-size:18px;">hello	 		u:object_r:hello_service:s0</span>
然后重新编译 

make -j32 

就不会有

<span style="font-size:18px;">E ServiceManager: add_service('hello',62) uid=1000 - PERMISSION DENIED</span>
的提示了!!


  相关解决方案