当前位置: 首页 > news >正文

Android 13 Framework 添加自定义的系统服务CustomService

目的: 添加自定义的系统服务,在自定义的服务中开发定制的API接口和功能,独立于系统核心服务,方便开发和维护。

开发环境:Android 13 MTK平台

涉及修改的文件如下

device/mediatek/sepolicy/base/private/service_contexts
device/mediatek/sepolicy/base/vendor/platform_app.te
device/mediatek/sepolicy/base/vendor/priv_app.te
device/mediatek/sepolicy/base/vendor/service_contexts
device/mediatek/sepolicy/base/vendor/system_app.te
device/mediatek/sepolicy/base/vendor/untrusted_app.te
device/mediatek/sepolicy/base/vendor/untrusted_app_27.te
frameworks/base/Android.bp
frameworks/base/core/api/current.txt
frameworks/base/core/java/android/app/SystemServiceRegistry.java
frameworks/base/core/java/android/content/Context.java
frameworks/base/services/java/com/android/server/SystemServer.java
system/sepolicy/prebuilts/api/33.0/private/service_contexts
system/sepolicy/private/service_contexts
system/sepolicy/private/untrusted_app_30.te
system/sepolicy/public/service.te
frameworks/base/core/java/android/app/CustomServiceManager.java
frameworks/base/core/java/android/os/custom/ICustomService.aidl
frameworks/base/services/core/java/com/android/server/CustomService.java

功能实现:

1.添加自定义服务AIDL文件:ICustomService.aidl,定义接口

路径:frameworks/base/core/java/android/os/custom/ICustomService.aidl

package android.os.custom;interface ICustomService {String getTestTime();
}

2.添加自定义服务管理类:CustomServiceManager.java,Context.CUSTOM_SERVICE 是新增服务的标识,见下面的 Context.java的修改。

路径:frameworks/base/core/java/android/app/CustomServiceManager.java

package android.app;import android.content.Context;
import android.os.custom.ICustomService;
import android.annotation.SystemService;
import android.util.Log;@SystemService(Context.CUSTOM_SERVICE)
public class CustomServiceManager {private static final String TAG = "CustomServiceManager";ICustomService mService;public CustomServiceManager(Context context,ICustomService service){mService=service;}public String getTestTime(){try{return mService.getTestTime();}catch(Exception e){Log.d(TAG,"getTestTime e.getMessage()="+e.getMessage());return "";}}
}

3.添加自定义服务实现类:CustomService.java,实现具体的功能。

路径:frameworks/base/services/core/java/com/android/server/CustomService.java

package com.android.server;import java.lang.*;
import java.util.Date;
import java.util.Locale;import android.icu.text.SimpleDateFormat;
import android.os.RemoteException;
import android.os.custom.ICustomService;
import android.content.Context;
import android.util.Log;public class CustomService extends ICustomService.Stub {private static final String TAG="CustomService";private final Context mContext;public CustomService
http://www.lryc.cn/news/133800.html

相关文章:

  • 前端食堂技术周刊第 95 期:Fresh 1.4、Rollup 迁移至 SWC计划、RSC Devtools、使用开源库的边界、AI 帮你讲论文
  • 【TypeScript】枚举类型
  • 快速通过华为HCIP认证
  • 派森 #P124. 公式计算
  • opencv进阶14-Harris角点检测-cv2.cornerHarris
  • JVM中对象和GC Root之间的四种引用关系
  • 【李宏毅机器学习】注意力机制
  • Nginx使用keepalived配置VIP
  • C语言编写图形界面
  • K8s学习笔记3
  • ceph集群的扩容缩容
  • gremlin安装使用 详细步骤
  • Java语言怎么编写一个程序计算出租车的运输费用:出租车起步15公里以内20块钱,需要支付调头费用
  • 十、flume的安装
  • 互联网广告及产品变现认知分析整理
  • item_search_img-按图搜索淘宝商品(拍立淘)
  • OWASP Top 10(2021)漏洞学习(最新)
  • mysql 、sql server 游标 cursor
  • dockers搭建基本服务
  • 微信小程序纯前端从阿里云OSS下载json数据-完整版
  • 【微服务实战】01-工程结构概览
  • 论文导读|European Journal of Operational Research近期文章精选:旅行商问题专题
  • playwright迭代元素
  • 65 | 增长模型案例
  • Django视图-HttpRequest请求对象和HttpResponse响应对象
  • 原来Lambda表达式是这样写的
  • smartsofthelp 5.0 最专业的数据库优化工具,数据库配置优化,数据库高并发优化,SQL 语句优化...
  • 智影 R100:首款三维Mesh建模的SLAM激光扫描仪
  • Next.js - Loading UI and Streaming
  • 快速解决Ubuntu 中 wine 程序 中文显示为方块/显示错误/无法显示中文(2023)