android8.1增加服务,android8.1增加系统服务亲测有效

编程入门 行业动态 更新时间:2024-10-10 06:17:06

android8.1增加服务,android8.1增加<a href=https://www.elefans.com/category/jswz/34/1770742.html style=系统服务亲测有效"/>

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增加系统服务亲测有效

本文发布于:2024-02-13 14:41:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759090.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:系统

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!