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

Android 11新增系统服务

1.编写.aidl文件

存放位置:frameworks/base/core/java/android/os

package android.os;interface ISystemVoiceServer {void setHeightVoice(int flag);void setBassVoice(int flag);void setReverbVoice(int flag);}

2.将.aidl文件添加到frameworks/base/Android.bp

filegroup {name: "framework-core-sources",srcs: ["core/java/**/*.java","core/java/**/*.aidl",],path: "core/java",
}

说明:android.bp文件中默认把core/java/目录下的aidl文件添加到编译文件中,所以这一步不需要操作.

由于Android 11对语法检测比较严格,所以针对我们新增的文件先加入忽略:

// TODO(b/145644363): move this to under StubLibraries.bp or ApiDocs.bp
metalava_framework_docs_args = "--manifest $(location core/res/AndroidManifest.xml) " +"--ignore-classes-on-classpath " +"--hide-package com.android.server " +"--error UnhiddenSystemApi " +"--hide RequiresPermission " +"--hide CallbackInterface " +"--hide MissingPermission --hide BroadcastBehavior " +"--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " +"--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo " +"--force-convert-to-warning-nullability-annotations +*:-android.*:+android.icu.*:-dalvik.* " +"--api-lint-ignore-prefix android.icu. " +"--api-lint-ignore-prefix java. " +"--api-lint-ignore-prefix android.os. " +   //新增这一行 "--api-lint-ignore-prefix android.app. " +  //新增这一行  "--api-lint-ignore-prefix junit. " +"--api-lint-ignore-prefix org. "

3、Context.java添加服务注册名称, 添加该服务名称, 用于快捷注册和快捷引用

修改位置:frameworks/base/core/java/android/content/

  //增加新增定义服务名称  /*** Use with {@link #getSystemService(String)} to retrieve a* {@link  android.app.SystemVoiceManager} for accessing* text services.** @see #getSystemService(String)*/public static final String SYSTEMVOCIE_SERVICER = "systemvoice";/** @hide */@StringDef(suffix = { "_SERVICE" }, value = {POWER_SERVICE,SYSTEMVOCIE_SERVICER,   //此处新增服务WINDOW_SERVICE,LAYOUT_INFLATER_SERVICE,......}

4、新建SystemVoiceService.java和SystemVoiceManager.java

存放位置:frameworks\base\services\core\java\com\android\server\SystemVoiceService.java

frameworks\base\core\java\android\app\SystemVoiceManager.java

package com.android.server;import android.app.SystemVoiceManager;
import android.content.Context;
import android.os.ISystemVoiceServer;
import android.os.RemoteException;
import com.android.server.SystemService;
import com.android.internal.app.IAppOpsService;public class SystemVoiceService extends SystemService {private final String TAG = "SystemVoiceService";private Context mContext;private IAppOpsService mAppOps;private SystemVoiceManager mManager;public SystemVoiceService(Context context) {super(context);this.mContext = context;}public void systemReady(IAppOpsService appOps) {mAppOps = appOps;if (mManager == null) {mManager = (SystemVoiceManager) mContext.getSystemService(Context.SYSTEMVOICE_SERVICE);}}@Overridepublic void onStart() {publishBinderService(Context.SYSTEMVOICE_SERVICE, new BinderService());}private final class BinderService extends ISystemVoiceServer.Stub {@Overridepublic void setHeightVoice(int flag) throws RemoteException {}@Overridepublic void setBassVoice(int flag) throws RemoteException {}@Overridepublic void setReverbVoice(int flag) throws RemoteException {}}
}
package android.app;import android.content.Context;
import android.os.ISystemVoiceServer;
import android.util.Log;
import android.annotation.SystemService;
import android.os.RemoteException;@SystemService(Context.SYSTEMVOICE_SERVICE)
public class SystemVoiceManager {private static final String TAG = "SystemVoiceManager";private ISystemVoiceServer mService;private Context context;public SystemVoiceManager(Context ctx, ISystemVoiceServer service) {mService = service;context = ctx;}public void setHeightVoice(int flag) {try {mService.setHeightVoice(flag);} catch (Exception e) {e.printStackTrace();}}public void setBassVoice(int flag) {try {mService.setBassVoice(flag);} catch (Exception e) {e.printStackTrace();}}public void setReverbVoice(int flag) {try {mService.setReverbVoice(flag);} catch (Exception e) {e.printStackTrace();}}}

5、SystemServer.java 中注册该service

修改位置: frameworks\base\services\java\com\android\server

import com.android.server.SystemVoiceService ;//导包private SystemVoiceService  mSystemVoiceService; //定义//系统服务加入的位置加入以下内容t.traceBegin("StartSystemVoiceManager");mSystemVoiceService = mSystemServiceManager.startService(SystemVoiceService.class);t.traceEnd();//系统服务加入的位置加入以下内容t.traceBegin("MakeSystemVoiceManagerServiceReady");try {// TODO: use boot phasemSystemVoiceService.systemReady(mActivityManagerService.getAppOpsService());} catch (Throwable e) {reportWtf("making SystemVoice Manager Service ready", e);}t.traceEnd();

6、SystemServiceRegistry的static{}, 并在其中注册该service

修改位置:frameworks\base\core\java\android\app

import android.os.ISystemVoiceServer;//导包

//SystemVoiceManager在同一目录下所以不用导包

   registerService(Context.SYSTEMVOICE_SERVICE, SystemVoiceManager.class,new CachedServiceFetcher<SystemVoiceManager>() {@Overridepublic SystemVoiceManager createService(ContextImpl ctx)throws ServiceNotFoundException {IBinder b = ServiceManager.getServiceOrThrow(Context.SYSTEMVOICE_SERVICE);return new SystemVoiceManager(ctx.getOuterContext(),ISystemVoiceService.Stub.asInterface(b));}});

以上步骤完成我们的自定义系统服务就完成了90% 但是我们还有最后一步,也是最重要的一步:

然后我们只需要添加这个自定义服务SystemVoiceService相关的 SELinux 规则。为了方便之后验证,打开selinux

要记住这个命令 adb shell setenforce 1 # 1为打开 #0为关闭

Android 11 的 selinux 规则是放在 system/sepolicy 目录下的:

service.te 和 service_contexts 都要加上SystemVoiceService的配置:

//在以下目录文件
./prebuilts/api/30.0/public/service.te   # 需要
./public/service.te                 # 需要
//添加以下内容
type systemvoice_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;

//在以下目录文件
./prebuilts/api/30.0/private/service_contexts   # 需要
./private/service_contexts         # 需要
//添加以下内容
systemvoice_service                      u:object_r:isystemvoice_service:s0

添加完配置后,Android11版本还要需要在以下目录修改以下忽略配置,才能正常编译

在以下目录
./prebuilts/api/30.0/private/compat/29.0/29.0.ignore.cil
./prebuilts/api/30.0/private/compat/28.0/28.0.ignore.cil
./prebuilts/api/30.0/private/compat/27.0/27.0.ignore.cil
./prebuilts/api/30.0/private/compat/26.0/26.0.ignore.cil
./private/compat/29.0/29.0.ignore.cil
./private/compat/28.0/28.0.ignore.cil
./private/compat/27.0/27.0.ignore.cil
./private/compat/26.0/26.0.ignore.cil

到此,android 11 系统服务已经添加完成!.

8、验证:

编译完成后,输入adb shell

#service list

查看服务列表中 是否存在有添加服务 :itest

如果不存在 逐步排查 参照上一步看哪一步错误

如果存在 就在代码中验证

找到编译最新生成的class.jar文件,导入Androidstudio(如何导入自行百度)

编译后的class.jar目录\out\target\common\obj\JAVA_LIBRARIES\framework_intermediates

如果未生成 执行下make javac-check-framework 这个命令 就会生成!!!

觉得我写的好的兄弟 动动你发财的小手 点个赞 !!!

你们的认同将是我继续写下去的动力 !!

相关文章:

Android 11新增系统服务

1.编写.aidl文件存放位置&#xff1a;frameworks/base/core/java/android/ospackage android.os;interface ISystemVoiceServer {void setHeightVoice(int flag);void setBassVoice(int flag);void setReverbVoice(int flag);}2.将.aidl文件添加到frameworks/base/Android.bp f…...

“你要多弄弄算法”

开始瞎掰 ▽ 2月的第一天&#xff0c;猎头Luna给我推荐了字节的机会&#xff0c;菜鸡我呀&#xff0c;还是有自知之明的&#xff0c;赶忙婉拒&#xff1a;能力有限&#xff0c;抱歉抱歉。 根据我为数不多的和猎头交流的经验&#xff0c;一般猎头都会稍微客套一下&#xff1a…...

【数据结构】千字深入浅出讲解队列(附原码 | 超详解)

&#x1f680;write in front&#x1f680; &#x1f4dd;个人主页&#xff1a;认真写博客的夏目浅石. &#x1f381;欢迎各位→点赞&#x1f44d; 收藏⭐️ 留言&#x1f4dd; &#x1f4e3;系列专栏&#xff1a;C语言实现数据结构 &#x1f4ac;总结&#xff1a;希望你看完…...

vue面试题(day04)

vue面试题vue插槽&#xff1f;vue3中如何获取refs&#xff0c;dom对象的方式&#xff1f;vue3中生命周期的和vue2中的区别&#xff1f;说说vue中的diff算法&#xff1f;说说 Vue 中 CSS scoped 的原理&#xff1f;vue3中怎么设置全局变量&#xff1f;Vue中给对象添加新属性时&a…...

自动标注工具 Autolabelimg

原理简介~~ 对于数据量较大的数据集&#xff0c;先对其中一部分图片打标签&#xff0c;Autolabelimg利用已标注好的图片进行训练&#xff0c;并利用训练得到的权重对其余数据进行自动标注&#xff0c;然后保存为xml文件。 一、下载yolov5v6.1 https://github.com/ultralytic…...

2023-03-20干活

transformer复现 from torch.utils.data import Dataset,DataLoader import numpy as np import torch import torch.nn as nn import os import time import math from tqdm import tqdmdef get_data(path,numNone):all_text []all_label []with open(path,"r",e…...

Java 注解(详细学习笔记)

注解 注解英文为Annotation Annotation是JDK5引入的新的技术 Annotation的作用&#xff1a; 不是程序本身&#xff0c;可以对程序做出解释可以被其他程序&#xff08;比如编译器&#xff09;读取。 Annotation的格式&#xff1a; 注解是以注解名在代码中存在的&#xff0c;还…...

LeetCode:35. 搜索插入位置

&#x1f34e;道阻且长&#xff0c;行则将至。&#x1f353; &#x1f33b;算法&#xff0c;不如说它是一种思考方式&#x1f340;算法专栏&#xff1a; &#x1f449;&#x1f3fb;123 一、&#x1f331;35. 搜索插入位置 题目描述&#xff1a;给定一个排序数组和一个目标值&…...

菜鸟刷题Day2

菜鸟刷题Day2 一.判定是否为字符重排&#xff1a;字符重排 描述 给定两个由小写字母组成的字符串 s1 和 s2&#xff0c;请编写一个程序&#xff0c;确定其中一个字符串的字符重新排列后&#xff0c;能否变成另一个字符串。 解题思路&#xff1a; 这题思路与昨天最后两道类似&…...

Selenium基础篇之不打开浏览器运行

文章目录前言一、场景二、设计1.引入库2.引入浏览器配置3.设置无头模式4.启动浏览器实例&#xff0c;添加配置信息5.访问质量分地址6.隐式等待5秒7.定位到输入框8.输入博文地址9.定位到查询按钮10.点击查询按钮11.定位到查询结果模块div12.打印结果13.结束webdriver进程三、结果…...

【数据结构初阶】栈与队列笔试题

前言在我们学习了栈和队列之后&#xff0c;今天来通过几道练习题来巩固一下我们的知识。题目一 用栈实现队列题目链接&#xff1a;232. 用栈实现队列 - 力扣&#xff08;Leetcode&#xff09;这道题难度不是很大&#xff0c;重要的是我们对结构认识的考察&#xff0c;由于这篇文…...

【Linux入门篇】操作系统安装、网络配置

目录 &#x1f341;Linux详解 &#x1f342;1.操作系统 &#x1f342;2.操作系统组成 &#x1f342;3.操作系统历史 &#x1f342;4.常见的Linux系统 &#x1f342;5.centos7下载 &#x1f342;6.安装centos7 &#x1f341;linux初始化配置 &#x1f343;1.虚拟机系统安装后操作…...

Selenium:找不到对应的网页元素?常见的一些坑

目录 1. 用Xpath查找数据时无法直接获取节点属性 2. 使用了WebDriverWait以后仍然无法找到元素 2.1. 分辨率原因 2.2. 需要滚动页面 2.3. 由于其他元素的遮挡 1. 用Xpath查找数据时无法直接获取节点属性 通常在我们使用xpath时&#xff0c;可以使用class的方式直接获取节…...

flex布局优化(两端对齐,从左至右)

文章目录前言方式一 nth-child方式二 gap属性方式三 设置margin左右两边为负值总结前言 flex布局是前端常用的布局方式之一&#xff0c;但在使用过程中&#xff0c;我们总是感觉不太方便&#xff0c;因为日常开发中&#xff0c;大多数时候&#xff0c;我们想要的效果是这样的 …...

【Django 网页Web开发】03. 初识Django(保姆级图文)

目录1. 命令行创建与pycharm创建的区别2. 项目结构信息2.1 项目结构2.2 项目app结构2.3 快速查看项目结构树3. 创建并注册app3.1 创建app3.2 注册app4. 编写URL与视图的对应关系5. 编写视图文件6. 启动项目7. 写多个页面8. templates模板的使用8.1 编写html文件8.3 导入html文件…...

KubeSphere All in one安装配置手册

KubeSphere All in one安装配置手册 1. 初始化 1.1 配置apt源 # vi /etc/apt/sources.list deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiversedeb…...

Spring Boot 核心配置文件

Spring Boot 核心配置文件1、application.properties2、application.yml使用建议3、常用配置项服务器配置数据库配置日志配置其他配置4、配置文件的加载顺序5、配置文件的占位符6、配置文件的动态刷新7、配置文件的属性分组定义属性分组绑定属性分组使用属性分组总结Spring Boo…...

个人小站折腾后记

个人小站折腾后记 &#x1f3e0;个人主页&#xff1a;shark-Gao &#x1f9d1;个人简介&#xff1a;大家好&#xff0c;我是shark-Gao&#xff0c;一个想要与大家共同进步的男人&#x1f609;&#x1f609; &#x1f389;目前状况&#xff1a;23届毕业生&#xff0c;目前在某…...

WebService简单入门

1. JAX-WS发布WebService 创建web工程 创建simple包&#xff0c;和server、client两个子包。正常情况下server和client应该是两个项目&#xff0c;这里我们只是演示效果&#xff0c;所以简化写到一个项目中&#xff1a; 1.1 创建服务类Server package simple.server;import ja…...

「Vue面试题」vue要做权限管理该怎么做?如果控制到按钮级别的权限怎么做?

文章目录一、是什么二、如何做接口权限路由权限控制菜单权限方案一方案二按钮权限方案一方案二小结参考文章一、是什么 权限是对特定资源的访问许可&#xff0c;所谓权限控制&#xff0c;也就是确保用户只能访问到被分配的资源 而前端权限归根结底是请求的发起权&#xff0c;…...

微软PowerBI考试 PL300-选择 Power BI 模型框架【附练习数据】

微软PowerBI考试 PL300-选择 Power BI 模型框架 20 多年来&#xff0c;Microsoft 持续对企业商业智能 (BI) 进行大量投资。 Azure Analysis Services (AAS) 和 SQL Server Analysis Services (SSAS) 基于无数企业使用的成熟的 BI 数据建模技术。 同样的技术也是 Power BI 数据…...

AtCoder 第409​场初级竞赛 A~E题解

A Conflict 【题目链接】 原题链接&#xff1a;A - Conflict 【考点】 枚举 【题目大意】 找到是否有两人都想要的物品。 【解析】 遍历两端字符串&#xff0c;只有在同时为 o 时输出 Yes 并结束程序&#xff0c;否则输出 No。 【难度】 GESP三级 【代码参考】 #i…...

今日科技热点速览

&#x1f525; 今日科技热点速览 &#x1f3ae; 任天堂Switch 2 正式发售 任天堂新一代游戏主机 Switch 2 今日正式上线发售&#xff0c;主打更强图形性能与沉浸式体验&#xff0c;支持多模态交互&#xff0c;受到全球玩家热捧 。 &#x1f916; 人工智能持续突破 DeepSeek-R1&…...

【数据分析】R版IntelliGenes用于生物标志物发现的可解释机器学习

禁止商业或二改转载&#xff0c;仅供自学使用&#xff0c;侵权必究&#xff0c;如需截取部分内容请后台联系作者! 文章目录 介绍流程步骤1. 输入数据2. 特征选择3. 模型训练4. I-Genes 评分计算5. 输出结果 IntelliGenesR 安装包1. 特征选择2. 模型训练和评估3. I-Genes 评分计…...

虚拟电厂发展三大趋势:市场化、技术主导、车网互联

市场化&#xff1a;从政策驱动到多元盈利 政策全面赋能 2025年4月&#xff0c;国家发改委、能源局发布《关于加快推进虚拟电厂发展的指导意见》&#xff0c;首次明确虚拟电厂为“独立市场主体”&#xff0c;提出硬性目标&#xff1a;2027年全国调节能力≥2000万千瓦&#xff0…...

tomcat入门

1 tomcat 是什么 apache开发的web服务器可以为java web程序提供运行环境tomcat是一款高效&#xff0c;稳定&#xff0c;易于使用的web服务器tomcathttp服务器Servlet服务器 2 tomcat 目录介绍 -bin #存放tomcat的脚本 -conf #存放tomcat的配置文件 ---catalina.policy #to…...

Oracle11g安装包

Oracle 11g安装包 适用于windows系统&#xff0c;64位 下载路径 oracle 11g 安装包...

EasyRTC音视频实时通话功能在WebRTC与智能硬件整合中的应用与优势

一、WebRTC与智能硬件整合趋势​ 随着物联网和实时通信需求的爆发式增长&#xff0c;WebRTC作为开源实时通信技术&#xff0c;为浏览器与移动应用提供免插件的音视频通信能力&#xff0c;在智能硬件领域的融合应用已成必然趋势。智能硬件不再局限于单一功能&#xff0c;对实时…...

C++中vector类型的介绍和使用

文章目录 一、vector 类型的简介1.1 基本介绍1.2 常见用法示例1.3 常见成员函数简表 二、vector 数据的插入2.1 push_back() —— 在尾部插入一个元素2.2 emplace_back() —— 在尾部“就地”构造对象2.3 insert() —— 在任意位置插入一个或多个元素2.4 emplace() —— 在任意…...

比特币:固若金汤的数字堡垒与它的四道防线

第一道防线&#xff1a;机密信函——无法破解的哈希加密 将每一笔比特币交易比作一封在堡垒内部传递的机密信函。 解释“哈希”&#xff08;Hashing&#xff09;就是一种军事级的加密术&#xff08;SHA-256&#xff09;&#xff0c;能将信函内容&#xff08;交易细节&#xf…...