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

Android13增加一个systemservice,并允许APP访问

1、在/frameworks/base/core/java/android/os下创建一个AIDL文件,比如IDeviceMgr.aidl

package android.os;
interface IDeviceMgr {int createApn(String apn);boolean deleteApn(int apnId);
}

编译系统,生成AIDL对应的JAVA文件。

2、在//frameworks/base/services/core/java/com/android/server创建包名devicemgr,并创建DeviceMgr,继承IDeviceMgr 

package com.android.server.devicemgr;
import android.content.Context;
import android.os.IDeviceMgr;
import android.os.RemoteException;
public class DeviceMgr extends IDeviceMgr.Stub {private Context mContext;public DeviceMgr (Context context){this.mContext=context;}@Overridepublic int createApn(String apnInfo) throws RemoteException {return 0;}@Overridepublic boolean deleteApn(int apnId) throws RemoteException {return false;}
}

编译,然后,然后就出错了:

Your API changes are triggering API Lint warnings or errors.
To make these errors go away, fix the code according to the
error and/or warning messages above.If it is not possible to do so, there are workarounds:1. You can suppress the errors with @SuppressLint("<id>")where the <id> is given in brackets in the error message above.
2. You can update the baseline by executing the followingcommand:(cd $ANDROID_BUILD_TOP && cp \"out/soong/.intermediates/frameworks/base/api-stubs-docs-non-updatable/android_common/metalava/api_lint_baseline.txt" \"frameworks/base/services/api/lint-baseline.txt")To submit the revised baseline.txt to the main Androidrepository, you will need approval.
************************************************************

服务需要APP可以调用,选择方式2,执行:

cp out/soong/.intermediates/frameworks/base/api-stubs-docs-non-updatable/android_common/metalava/api_lint_baseline.txt  frameworks/base/services/api/lint-baseline.txt

编译后继续出错:

******************************
You have tried to change the API from what has been previously approved.To make these errors go away, you have two choices:1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)to the new methods, etc. shown in the above diff.2. You can update current.txt and/or removed.txt by executing the following command:m api-stubs-docs-non-updatable-update-current-apiTo submit the revised current.txt to the main Android repository,you will need approval.
******************************

选择方法2,lunch相应product,执行:

m api-stubs-docs-non-updatable-update-current-api

这次不报错了

3、打开/frameworks/base/core/java/android/content/Context.java,添加一行对应的服务名称:

 public static final String DEVICEMGR_SERVICE = "devicemgr";

这是APP调用getSystemService对应的服务名称

4、打开/frameworks/base/services/java/com/android/server/SystemServer.java,在中间加上一行代码:

private void startOtherServices(@NonNull TimingsTraceAndSlog t) {.....................................ServiceManager.addService(Context.DEVICEMGR_SERVICE, new DeviceMgr(mSystemContext));.....................................
}

http://www.xdnf.cn/news/2525.html

相关文章:

  • 开源财务软件:企业财务数字化转型的有力工具
  • 图片矫正模型
  • FPGA时钟设计
  • JavaScript之Webpack的模块加载机制
  • 【Linux网络与网络编程】13.五种 IO 模型
  • AIGC(生成式AI)试用 32 -- AI做软件程序测试 3
  • git提交规范记录,常见的提交类型及模板、示例
  • 【音视频】SDL简介
  • 算法题(135):唯一的雪花
  • 大数据系列 | 日志数据采集工具Logstash的架构分析及应用
  • 微信小程序导航栏
  • C++STL(九) :bitset的介绍与使用
  • MCP介绍与使用
  • 第二部分:网页的妆容 —— CSS(上)
  • OpenSSH配置连接远程服务器MS ODBC驱动与Navicat数据库管理
  • 神经网络预测评估机制:损失函数详解
  • adb devices 报权限错误
  • 文件缓冲区(IO与文件 ·III)(linux/C)
  • 使用 malloc 函数模拟开辟一个 3x5 的整型二维数组
  • 基于QT(C++)实现(GUI)旅行查询与模拟系统
  • Python3 (13)循环语句
  • Java SE(3)——程序逻辑控制,输入输出
  • MySQL的锁(InnoDB)【学习笔记】
  • PlatformIO 入门学习笔记(二):开发环境介绍
  • Matlab算例运行
  • MCU ADC参考电压变化怎么办?
  • JS 中call、apply 和 bind使用方法和场景
  • 犬面部检测数据集VOC+YOLO格式987张1类别
  • ST-LINK/V2调试仿真器的接口定义
  • 计算机组成原理系列3--存储系统