当前位置: 首页 > 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;…...

ardupilot 开发环境eclipse 中import 缺少C++

目录 文章目录 目录摘要1.修复过程摘要 本节主要解决ardupilot 开发环境eclipse 中import 缺少C++,无法导入ardupilot代码,会引起查看不方便的问题。如下图所示 1.修复过程 0.安装ubuntu 软件中自带的eclipse 1.打开eclipse—Help—install new software 2.在 Work with中…...

IT供电系统绝缘监测及故障定位解决方案

随着新能源的快速发展&#xff0c;光伏电站、储能系统及充电设备已广泛应用于现代能源网络。在光伏领域&#xff0c;IT供电系统凭借其持续供电性好、安全性高等优势成为光伏首选&#xff0c;但在长期运行中&#xff0c;例如老化、潮湿、隐裂、机械损伤等问题会影响光伏板绝缘层…...

七、数据库的完整性

七、数据库的完整性 主要内容 7.1 数据库的完整性概述 7.2 实体完整性 7.3 参照完整性 7.4 用户定义的完整性 7.5 触发器 7.6 SQL Server中数据库完整性的实现 7.7 小结 7.1 数据库的完整性概述 数据库完整性的含义 正确性 指数据的合法性 有效性 指数据是否属于所定…...

【前端异常】JavaScript错误处理:分析 Uncaught (in promise) error

在前端开发中&#xff0c;JavaScript 异常是不可避免的。随着现代前端应用越来越多地使用异步操作&#xff08;如 Promise、async/await 等&#xff09;&#xff0c;开发者常常会遇到 Uncaught (in promise) error 错误。这个错误是由于未正确处理 Promise 的拒绝&#xff08;r…...

Ubuntu系统复制(U盘-电脑硬盘)

所需环境 电脑自带硬盘&#xff1a;1块 (1T) U盘1&#xff1a;Ubuntu系统引导盘&#xff08;用于“U盘2”复制到“电脑自带硬盘”&#xff09; U盘2&#xff1a;Ubuntu系统盘&#xff08;1T&#xff0c;用于被复制&#xff09; &#xff01;&#xff01;&#xff01;建议“电脑…...

大数据驱动企业决策智能化的路径与实践

&#x1f4dd;个人主页&#x1f339;&#xff1a;慌ZHANG-CSDN博客 &#x1f339;&#x1f339;期待您的关注 &#x1f339;&#x1f339; 一、引言&#xff1a;数据驱动的企业竞争力重构 在这个瞬息万变的商业时代&#xff0c;“快者胜”的竞争逻辑愈发明显。企业如何在复杂环…...

day51 python CBAM注意力

目录 一、CBAM 模块简介 二、CBAM 模块的实现 &#xff08;一&#xff09;通道注意力模块 &#xff08;二&#xff09;空间注意力模块 &#xff08;三&#xff09;CBAM 模块的组合 三、CBAM 模块的特性 四、CBAM 模块在 CNN 中的应用 一、CBAM 模块简介 在之前的探索中…...

信息系统分析与设计复习

2024试卷 单选题&#xff08;20&#xff09; 1、在一个聊天系统(类似ChatGPT)中&#xff0c;属于控制类的是&#xff08;&#xff09;。 A. 话语者类 B.聊天文字输入界面类 C. 聊天主题辨别类 D. 聊天历史类 ​解析 B-C-E备选架构中分析类分为边界类、控制类和实体类。 边界…...

JS设计模式(5): 发布订阅模式

解锁JavaScript发布订阅模式&#xff1a;让代码沟通更优雅 在JavaScript的世界里&#xff0c;我们常常会遇到这样的场景&#xff1a;多个模块之间需要相互通信&#xff0c;但是又不想让它们产生过于紧密的耦合。这时候&#xff0c;发布订阅模式就像一位优雅的信使&#xff0c;…...

Go 并发编程基础:select 多路复用

select 是 Go 并发编程中非常强大的语法结构&#xff0c;它允许程序同时等待多个通道操作的完成&#xff0c;从而实现多路复用机制&#xff0c;是协程调度、超时控制、通道竞争等场景的核心工具。 一、什么是 select select 类似于 switch 语句&#xff0c;但它用于监听多个通…...