Android 框架层AIDL 添加接口
文章目录
- AIDL的原理
- 构建AIDL的流程
- 往冻结的AIDL中加接口
AIDL的原理
可以利用ALDL定义客户端与服务均认可的编程接口,以便二者使用进程间通信 (IPC) 进行相互通信。在 Android 中,一个进程通常无法访问另一个进程的内存。因此,为进行通信,进程需将其对象分解成可供操作系统理解的原语,并将其编组为可供您操作的对象。编写执行该编组操作的代码较为繁琐,因此 Android 会使用 AIDL 为您处理此问题。
AIDL 可以理解成是一个范式, 通过这个范式编写接口文件, 然后利用Android的AIDL工具 会生成继承binder所需要能力的头文件。
构建AIDL的流程
以automotive的audiocontrol模块为例
- 编写AIDL接口文件,编写Android.bp, 通过AIDL 生成头文件
其aidl的文件位于下面的目录
hardware/interfaces/automotive/audiocontrol/aidl/android/hardware/automotive/audiocontrol/
编译会在下面的目录生成实现binder通信的接口文件。
接口文件有java cpp ndk三种类型。 使得能够被不同的客户端和服务端的代码引用到。
out/soong/.intermediates/hardware/interfaces/automotive/audiocontrol/aidl/android.hardware.automotive.audiocontrol-V2-cpp-source/gen/include/android/hardware/automotive/audiocontrol$ ls
AudioFocusChange.h BnFocusListener.h BpDuckingInfo.h IAudioControl.h
BnAudioControl.h BnMutingInfo.h BpFocusListener.h IFocusListener.h
BnAudioFocusChange.h BpAudioControl.h BpMutingInfo.h MutingInfo.h
BnDuckingInfo.h BpAudioFocusChange.h DuckingInfo.h
- 实现service,实现service对应的bin,以及rc,注册服务到servicemananger
AudioContro 实现的demo bin位于hardware/interfaces/automotive/audiocontrol/aidl/default
目录下,编译会生成
android.hardware.automotive.audiocontrol-service.example这样的bin 这个bin在 audiocontrol-default.rc 中启动。
当然服务端的是 就是把audiocontrol的服务注册到servicemanger中。
std::shared_ptr<AudioControl> audioControl = ::ndk::SharedRefBase::make<AudioControl>();const std::string instance = std::string() + AudioControl::descriptor + "/default";binder_status_t status =AServiceManager_addService(audioControl->asBinder().get(), instance.c_str());CHECK_EQ(status, STATUS_OK);
服务的名字在audiocontrol-default.xml中定义为
android.hardware.automotive.audiocontrol.IAudioControl/default
- 实现client,获取service,调用service相关的接口。
clinet 端 主要是通过名字从serviceManager 中获取到audioControl的服务。然后通过服务调用其接口。
如下通过getService 获取服务,然后通过名字获取IAudioControl对象。然后就可以调用其函数了
private static final String AUDIO_CONTROL_SERVICE ="android.hardware.automotive.audiocontrol.IAudioControl/default";private IBinder mBinder;private IAudioControl mAudioControl;private boolean mListenerRegistered = false;private AudioControlDeathRecipient mDeathRecipient;static @Nullable IBinder getService() {return Binder.allowBlocking(ServiceManager.waitForDeclaredService(AUDIO_CONTROL_SERVICE));}AudioControlWrapperAidl(IBinder binder) {mBinder = Objects.requireNonNull(binder);mAudioControl = IAudioControl.Stub.asInterface(binder);}IBinder binder = AudioControlWrapperAidl.getService();
if (binder != null) {return new AudioControlWrapperAidl(binder);
}@Overridepublic void onAudioFocusChange(@AttributeUsage int usage, int zoneId, int focusChange) {if (Slogf.isLoggable(TAG, Log.DEBUG)) {Slogf.d(TAG, "onAudioFocusChange: usage " + usageToString(usage)+ ", zoneId " + zoneId + ", focusChange " + focusChange);}try {String usageName = usageToXsdString(usage);mAudioControl.onAudioFocusChange(usageName, zoneId, focusChange);} catch (RemoteException e) {throw new IllegalStateException("Failed to query IAudioControl#onAudioFocusChange", e);}}
往冻结的AIDL中加接口
按照Android规则来说 发布之后的AIDL接口是不能修改的。 有相应的Freeze AIDL APIs处理。 从提交记录看 freeze 的操作是加hash值。
diff --git a/automotive/audiocontrol/aidl/Android.bp b/automotive/audiocontrol/aidl/Android.bp
index 7a947d3ab..4acfd82d6 100644
--- a/automotive/audiocontrol/aidl/Android.bp
+++ b/automotive/audiocontrol/aidl/Android.bp
@@ -19,4 +19,5 @@ aidl_interface {
sdk_version: "module_current",
},
},
+ versions: ["1"],
}
diff --git a/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/1/.hash b/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/1/.hash
new file mode 100644
index 000000000..c4bb36b47
--- /dev/null
+++ b/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/1/.hash
@@ -0,0 +1 @@
+ba2a7caca61683385b3b100e4faab1b4139fc547
看提交记录加接口的地方:
- /aidl/android/hardware/automotive/audiocontrol/IAudioControl.aidl
- /aidl/default/AudioControl.h
- /aidl/default/AudioControl.cpp
diff --git a/automotive/audiocontrol/aidl/android/hardware/automotive/audiocontrol/IAudioControl.aidl b/automotive/audiocontrol/aidl/android/hardware/automotive/audiocontrol/IAudioControl.aidl
index 4b03af11a..3a0224557 100644
--- a/automotive/audiocontrol/aidl/android/hardware/automotive/audiocontrol/IAudioControl.aidl
+++ b/automotive/audiocontrol/aidl/android/hardware/automotive/audiocontrol/IAudioControl.aidldiff --git a/automotive/audiocontrol/aidl/default/AudioControl.cpp b/automotive/audiocontrol/aidl/default/AudioControl.cpp
index 748947cb2..b076d0128 100644
--- a/automotive/audiocontrol/aidl/default/AudioControl.cpp
+++ b/automotive/audiocontrol/aidl/default/AudioControl.cppdiff --git a/automotive/audiocontrol/aidl/default/AudioControl.h b/automotive/audiocontrol/aidl/default/AudioControl.h
index cf5694762..ab0b1b305 100644
--- a/automotive/audiocontrol/aidl/default/AudioControl.h
+++ b/automotive/audiocontrol/aidl/default/AudioControl.h
- 出现AIDL修改报错
Above AIDL file(s) has changed and this is NEVER allowed on a release platform
(i.e., PLATFORM_VERSION_CODENAME is REL). If a device is shipped with this
change by ignoring this message, it has a high risk of breaking later when a
module using the interface is updated, e.g., Maineline modules.
11:47:01 ninja failed with: exit status 1
报错的原因解释:
stability :此接口的稳定性承诺的可选标志。目前仅支持"vintf" 。如果未设置,则对应于在此编译上下文中具有稳定性的接口(因此此处加载的接口只能与一起编译的东西一起使用,例如在 system.img 上)。如果将其设置为"vintf" ,则这对应于稳定性承诺:接口必须在使用期间保持稳定。
解决: 所有的AIDL有关地方的接口都要增加。
- 出现hash校验错误:
hardware/interfaces/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocont FAILED: out/soong/.intermediates/hardware/interfaces/automotive/audiocontrol/aidl/android.hardware.automotive.audiocontrol-api/checkhash_1.timestamp if [ $(cd 'hardware/interfaces/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/1' && { find ./ -name "*.aidl" -print0 | LC_ALL=C sort -z | xargs -0 sha1sum && echo latest-version; } | sha1sum | cut -d " " -f 1) = $(read -r <'hardware/interfaces/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/1/.hash' hash extra; printf %s $hash) ]; then touch out/soong/.intermediates/hardware/interfaces/automotive/audiocontrol/aidl/android.hardware.automotive.audiocontrol-api/checkhash_1.timestamp; else cat 'system/tools/aidl/build/message_check_integrity.txt' && exit 1; fi ############################################################################### # ERROR: Modification detected of stable AIDL API file # ############################################################################### Above AIDL file(s) has changed, resulting in a different hash. Hash values may be checked at runtime to verify interface stability. If a device is shipped with this change by ignoring this message, it has a high risk of breaking later when a module using the interface is updated, e.g., Mainline modules. 16:41:52 ninja failed with: exit status 1
错误原因:
构建过程未能验证 AIDL 文件的哈希值,表明发生了修改。
哈希检查脚本:bash
if [ $(cd 'hardware/interfaces/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/1' && { find ./ -name "*.aidl" -print0 | LC_ALL=C sort -z | xargs -0 sha1sum && echo latest-version; } | sha1sum | cut -d " " -f 1) = $(read -r <'hardware/interfaces/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/1/.hash' hash extra; printf %s $hash) ]; then touch out/soong/.intermediates/hardware/interfaces/automotive/audiocontrol/aidl/android.hardware.automotive.audiocontrol-api/checkhash_1.timestamp; else cat 'system/tools/aidl/build/message_check_integrity.txt' && exit 1; fi
这是检查 AIDL 文件哈希值是否与预期哈希值匹配的脚本。如果哈希值匹配,构建过程将继续进行;否则,将引发错误。错误消息:makefile
ERROR: Modification detected of stable AIDL API file
- 修改hash值。
根据报错的提交脚本。使用下面的脚本在对应的目录下生成hash 值, 将这个hash值替换到.hash文件即可
目录hardware/interfaces/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/1
{ find ./ -name "*.aidl" -print0 | LC_ALL=C sort -z | xargs -0 sha1sum && echo latest-version; } | sha1sum | cut -d " " -f 1
- 出现这个错误
Android will be dropped but finished with status UNKNOWN_TRANSACTION
需要push 所有system/lib底下有关的audiocontrol的so、
使用版本化接口接口方法在运行时,当尝试在旧服务器上调用新方法时,新客户端会收到错误或异常,具体取决于后端。
cpp后端获取::android::UNKNOWN_TRANSACTION 。
ndk后端获取STATUS_UNKNOWN_TRANSACTION 。
java后端获取android.os.RemoteException并显示一条消息,说明 API 未实现。
总结: 在冻结的AIDL接口上面加新的接口 需要做的步骤。 但是强烈不建议这么做,可以自己单独实现一个AIDL接口、AIDL的服务、以及上层的实现
- 修改AIDL文件 添加接口
- 计算Hash,修改hash 值
- 编译push 生成的so
- 在应用上层获取服务就可以调用到新的接口了。
相关文章:
Android 框架层AIDL 添加接口
文章目录 AIDL的原理构建AIDL的流程往冻结的AIDL中加接口 AIDL的原理 可以利用ALDL定义客户端与服务均认可的编程接口,以便二者使用进程间通信 (IPC) 进行相互通信。在 Android 中,一个进程通常无法访问另一个进程的内存。因此,为进行通信&a…...
ubuntu命令行下中文乱码怎么解决
大家好,今天来介绍ubuntu命令行中文乱码怎么解决(ubuntu中文文件名乱码)的问题,以下是渲大师小编对此问题的归纳和整理,感兴趣的来一起看看吧! ubuntu命令行下中文乱码怎么解决 我也呀见过这个问题 一. Ubuntu默认的中文字符编码 Ubuntu默认的中文字谈码符编码为zh_CN.UT…...

沈阳陪诊系统|陪诊软件开发功能
陪诊小程序的出现它可以帮助患者或家属解决就医过程中的各种问题。根据数据显示,2021年中国陪诊市场规模约为36.7亿元,预计到2025年将达到100亿元。同时,在医疗行业数字化转型的大背景下,陪诊微信小程序作为一种创新的医疗服务模式…...
Element-Plus 表格 el-table 如何支持分页多选
🚀 作者主页: 有来技术 🔥 开源项目: youlai-mall 🍃 vue3-element-admin 🍃 youlai-boot 🌺 仓库主页: Gitee 💫 Github 💫 GitCode 💖 欢迎点赞…...
网站被流量攻击了,该怎么处理
几乎每个网站都面临被攻击或者入侵的风险,无论是简单的博客论坛、投资平台、小型的独立电商网站还是动态电子商务平台都有被攻击的情况出现,只是或大或小,或多或少罢了 为什么网站会被攻击?黑客如何来入侵这些网站?如何才能有效保护我的网站不…...
配置特定 IP 地址走指定网关
公司有两个日常上网用的路由器,分别接不同的两条网线,虽然都是电信的,但是一条偶尔会抽风,我的 VPS 会连不上,也就是挂在上面的 SS 无法使用。恰好这根线是公司接台式机的,也就是说平时上班偶尔会无法科学上…...

Linux的基本指令(四)
目录 前言 时间相关的指令 date指令 时间戳 日志 时间戳转化为具体的时间 cal指令 find指令(十分重要) grep指令(行文本过滤工具) 学前补充 什么是打包和压缩? 为什么要打包和压缩? 怎么打包和…...

vue+elementui如何实现在表格中点击按钮预览图片?
效果图如上: 使用el-image-viewer 重点 : 引入 import ElImageViewer from "element-ui/packages/image/src/image-viewer"; <template><div class"preview-table"><el-table border :data"tableData" …...

LLaMA 2:开源的预训练和微调语言模型推理引擎 | 开源日报 No.86
facebookresearch/llama Stars: 36.0k License: NOASSERTION LLaMA 2 是一个开源项目,用于加载 LLaMA 模型并进行推理。 该项目的主要功能是提供预训练和微调后的 LLaMA 语言模型的权重和起始代码。这些模型参数范围从 7B 到 70B 不等。 以下是该项目的关键特性…...

01-AI大模型智能客服 V0.1「上」
你好,我是悦创。 首发:https://mp.weixin.qq.com/s/6MTkpWZCEbFWOcUn0Vexvw V0.1 版本我将分为上中下三篇进行书写和发布,欢迎分享和我微信进讨论群:Jiabcdefh。 计划: 会迭代好几个版本,看阅读量和点赞…...

【23真题】罕见211!数一配英二!
今天分享的是23年合肥工业大学833的信号与系统数字信号处理试题及解析。合工大833考数一英二,这样的搭配还是很少见的。 本套试卷难度分析:22年合肥工业大学833考研真题,我也发布过,若有需要,戳这里自取!平均分为80和…...

Linux 项目自动化构建工具:make/makefile
什么是 make make 是一个命令,他会在源文件的当前目录下寻找 makefile 或者 Makefile 文件执行这个文件中的代码。 makefile 文件的编写 我们先来见见猪跑,看看 make 怎么用的: 下面是 makefile 文件的内容: 这是 test.c 中的…...

android trace文件的抓取与查看方法
本地手机抓取trace 解压android trace文件的抓取与查看方法 找到config.pbtx文件,连接手机push进去 # push config.pbtx ,/data/local/tmp/为自定义push到的目录 adb push config.pbtx /data/local/tmp/ adb shell # 抓取trace, /data/loc…...

ffmpeg开发 环境配置
ffmpeg开发简图 1 下载ffmpeg开发包 https://ffmpeg.org/download.html 包含三个版本:Static、Shared以及Dev Static --- 包含3个应用程序:ffmpeg.exe , ffplay.exe , ffprobe.exe,体积都很大,相关的DLL已经被编译到exe里面去…...

C++STL——string类详解及其模拟实现
CSTL——string类 1. STL简介 STL全称standard template libaray,译为标准模板库 需要注意,STL不是C的标准库,而是C标准库的重要组成部分STL是一个包含众多数据结构和算法的软件框架 下面展示STL的六大组件: 本章,我…...

使用Three.js创建导航立方体
什么是导航立方体? 导航立方体是一个交互式的3D控件,它允许用户通过点击和拖动立方体的各个面来改变3D视图的方向。这是一种非常直观的方式,让用户能够轻松地在3D空间中导航。 创建导航立方体 下面是一个基本的步骤,说明如何使用Three.js创建一个导航立方体: // 创建场景…...

C++初识类和对象
前言 上一期我们介绍了一些C入门的基础知识,本期我们来介绍面向对象。初步认识一下面向对象和面向过程、类、以及封装! 本期内容介绍 面向过程和面向对象 类的引入 类的定义 类的访问限定符和封装 类的作用域 类的实例化 类对象模型 this指针 一、面向…...

MYSQL where 子句
文章目录 前言MySQL where 子句语法 从命令提示符中读取数据使用PHP脚本读取数据后言 前言 hello world欢迎来到前端的新世界 😜当前文章系列专栏:Mysql 🐱👓博主在前端领域还有很多知识和技术需要掌握,正在不断努力…...

系列十六、Spring IOC容器的扩展点
一、概述 Spring IOC容器的扩展点是指在IOC加载的过程中,如何对即将要创建的bean进行扩展。 二、扩展点 2.1、BeanDefinitionRegistryPostProcessor 2.1.1、概述 BeanDefinitionRegistryPostProcessor是bean定义的后置处理器,在BeanDefinition加载后&a…...

eclipse项目移到idea上部署运行
1.配置web模块 另外,模块这里,也要加上Spring 2.配置Artifact (用于tomcat) 就是从上面配置的web模块,产生的工件 3.添加lib 一般是在web-inf/lib , 遇到的坑: jdk版本问题,这里…...

【Axure高保真原型】引导弹窗
今天和大家中分享引导弹窗的原型模板,载入页面后,会显示引导弹窗,适用于引导用户使用页面,点击完成后,会显示下一个引导弹窗,直至最后一个引导弹窗完成后进入首页。具体效果可以点击下方视频观看或打开下方…...

C++_核心编程_多态案例二-制作饮品
#include <iostream> #include <string> using namespace std;/*制作饮品的大致流程为:煮水 - 冲泡 - 倒入杯中 - 加入辅料 利用多态技术实现本案例,提供抽象制作饮品基类,提供子类制作咖啡和茶叶*//*基类*/ class AbstractDr…...

Xshell远程连接Kali(默认 | 私钥)Note版
前言:xshell远程连接,私钥连接和常规默认连接 任务一 开启ssh服务 service ssh status //查看ssh服务状态 service ssh start //开启ssh服务 update-rc.d ssh enable //开启自启动ssh服务 任务二 修改配置文件 vi /etc/ssh/ssh_config //第一…...
Linux云原生安全:零信任架构与机密计算
Linux云原生安全:零信任架构与机密计算 构建坚不可摧的云原生防御体系 引言:云原生安全的范式革命 随着云原生技术的普及,安全边界正在从传统的网络边界向工作负载内部转移。Gartner预测,到2025年,零信任架构将成为超…...
LLM基础1_语言模型如何处理文本
基于GitHub项目:https://github.com/datawhalechina/llms-from-scratch-cn 工具介绍 tiktoken:OpenAI开发的专业"分词器" torch:Facebook开发的强力计算引擎,相当于超级计算器 理解词嵌入:给词语画"…...
Angular微前端架构:Module Federation + ngx-build-plus (Webpack)
以下是一个完整的 Angular 微前端示例,其中使用的是 Module Federation 和 npx-build-plus 实现了主应用(Shell)与子应用(Remote)的集成。 🛠️ 项目结构 angular-mf/ ├── shell-app/ # 主应用&…...

华硕a豆14 Air香氛版,美学与科技的馨香融合
在快节奏的现代生活中,我们渴望一个能激发创想、愉悦感官的工作与生活伙伴,它不仅是冰冷的科技工具,更能触动我们内心深处的细腻情感。正是在这样的期许下,华硕a豆14 Air香氛版翩然而至,它以一种前所未有的方式&#x…...

嵌入式学习笔记DAY33(网络编程——TCP)
一、网络架构 C/S (client/server 客户端/服务器):由客户端和服务器端两个部分组成。客户端通常是用户使用的应用程序,负责提供用户界面和交互逻辑 ,接收用户输入,向服务器发送请求,并展示服务…...
ubuntu22.04 安装docker 和docker-compose
首先你要确保没有docker环境或者使用命令删掉docker sudo apt-get remove docker docker-engine docker.io containerd runc安装docker 更新软件环境 sudo apt update sudo apt upgrade下载docker依赖和GPG 密钥 # 依赖 apt-get install ca-certificates curl gnupg lsb-rel…...

对象回调初步研究
_OBJECT_TYPE结构分析 在介绍什么是对象回调前,首先要熟悉下结构 以我们上篇线程回调介绍过的导出的PsProcessType 结构为例,用_OBJECT_TYPE这个结构来解析它,0x80处就是今天要介绍的回调链表,但是先不着急,先把目光…...