系统服务亲测有效"/>
android8.1增加服务,android8.1增加系统服务亲测有效
以下测试验证平台MSM8996 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文件frameworks/base/core/java/android/security/ISecurityServer.aidl
package android.security;
interface ISecurityServer {
void startLockAppSevice();
}
2.实现aidl接口frameworks/base/services/core/java/com/android/server/SecurityServer.java
package com.android.server;
import android.security.ISecurityServer;
public class SecurityServer extends ISecurityServer.Stub{
public void startLockAppSevice() {
}
}
3.提供对外接口类
frameworks/base/core/java/android/security/SecurityManager.java
package android.security;
public class SecurityManager {
private final ISecurityServer mService;
public SecurityManager(ISecurityServer service) {
mService = service;
}
public void startLockAppSevice(){
try {
mService.startLockAppSevice();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
4.添加编译
frameworks/base/Android.mk 在aidl配置处添加
core/java/android/security/ISecurityServer.aidl \
5.注册服务
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));
}
});
6. SystemServer.java 将服务添加进ServiceManager
try {
//
SecurityServer securityServer = new SecurityServer();
ServiceManager.addService("wzf", securityServer);
} catch (Throwable e) {
Log.e(TAG, "Failure starting olc_service_security", e);
}
7. 服务调用
SecurityManager securityManager = (SecurityManager)getSystemService("xxx");
更多推荐
android8.1增加服务,android8.1增加系统服务亲测有效
发布评论