Android 8.1添加系统服务,sepolicy相关配置
- 写.aidl文件
- 将.aidl文件添加到 frameworks/base/Android.mk 下的 LOCAL_SRC_FILES(此处 先make update-api 生成对应的文件 )
3.新建 xxx service 和 xxx service manager - context.java添加服务注册名称, 添加该服务名称, 用于快捷注册和快捷引用
/** @hide */
@StringDef({
SYSTEM_STATUS_SERVICE,
POWER_SERVICE,
...})
public static final String SYSTEM_STATUS_SERVICE = "system_status";
- 注册该service
5.1 SystemService.java 中注册该service
5.1.1 main -> run() -> startOtherService 中添加注册该service
/**
* Starts a miscellaneous grab bag of stuff that has yet to be refactored
* and organized.
*/
private void startOtherServices() {
...
traceBeginAndSlog("xxxService");
ServiceManager.addService(Context.xxx,
new xxxService(context));
traceEnd();
...
}
5.2 找到SystemServiceRegistry的static{}, 并在其中注册该service
registerService(Context.xxx, xxxServiceManager.class,
new CachedServiceFetcher< xxxServiceManager>() {
@Override
public xxxServiceManager createService(ContextImpl ctx) {
IBinder b = ServiceManager.getService(Context.SYSTEM_STATUS_SERVICE);
return new xxxServiceManager(ctx, I xxxServiceManager.Stub.asInterface(b));
}
});
===========================================
系统service注册,添加完毕,后续是selinux相关配置
============================================
一. sepolicy 部分添加
- \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)