以下测试验证平台MSM8909 android8.1
一. sepolicy 部分添加
1. \system\sepolicy\public\service.te 定义服务名称和属性
type xxx_service,app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
2.\system\sepolicy\private\service_contexts 添加服务名称
xxx u:object_r:xxx_service:s0
3.\system\sepolicy\private\compat\26.0\26.0.cil 文件最后添加
(typeattributeset xxx_service_26_0 (xxx_service))
4.\system\sepolicy\prebuilts\api\26.0\public\service.te 定义服务名称和属性
type xxx_service,app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
5.\system\sepolicy\prebuilts\api\26.0\private\
service_contexts 添加服务名称
xxx u:object_r:xxx_service:s0
6.\system\sepolicy\prebuilts\api\26.0\nonplat_sepolicy.cil 添加相应配置
6.1 typeattributeset system_server_service 在最后添加自定义的服务 xxx_service_26_0
6.2 typeattributeset app_api_service 在最后添加自定义的服务 xxx_service_26_0
6.3 typeattributeset ephemeral_app_api_service 在最后添加自定义的服务 xxx_service_26_0
6.4 typeattributeset service_manager_type 在最后添加自定义的服务 xxx_service_26_0
6.5 添加一对 配置
(typeattribute xxx_service_26_0)
(roletype object_r xxx_service_26_0)
二. 添加aidl文件
1.定义aidl文件
package com.xxx.aidl;
interface ISecurityServer {
void startLockAppSevice();
}
2.实现aidl接口
package com.xxx.aidl;
public class SecurityServer extends ISecurityServer.Stub{
public void startLockAppSevice() {
}
}
3.提供对外接口类
package com.xxx.security;
public class SecurityManager {
private final ISecurityServer mService;
public SecurityManager(ISecurityServer service) {
mService = service;
}
public void startLockAppSevice(){
try {
mService.startLockAppSevice();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
4.注册服务
SystemServiceRegistry.java 添加
registerService("xxx", com.xxx.SecurityManager.class,
new CachedServiceFetcher
@Override
public com.xxx.SecurityManager createService(ContextImpl ctx) {
IBinder b = ServiceManager.getService("xxx");
return new com.xxx.SecurityManager(com.xxx.aidl.ISecurityServer.Stub.asInterface(b));
}
});
5. SystemServer.java 将服务添加进ServiceManager
try {
//
com.xxx.aidl.SecurityServer Security = new com.xxx.aidl.SecurityServer(mContext);
ServiceManager.addService("xxx", Security);
} catch (Throwable e) {
Log.e(TAG, "Failure starting olc_service_security", e);
}
6. 服务调用
SecurityManager securityManager = (SecurityManager)getSystemService("xxx");