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");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值