当前位置:网站首页>AOSP ~binder communication principle (I) - Overview
AOSP ~binder communication principle (I) - Overview
2022-07-07 05:17:00 【Nanke is cute】
summary
stay Android In the middle , We know that each application is an independent process , There is a separate virtual machine , Memory between applications cannot share data , But we use Activity、Service、Context、provider And so on , Just do a lot of data transmission , Why is that ?
This involves what we know Interprocess communication mechanism -IPC(Inter-Process Communication).
stay Android Interprocess communication commonly used in is Shared memory 、 The Conduit 、 signal processing 、socket、Binder etc. . Each communication mode has its own advantages and disadvantages ,Android Usually use the right communication method in the right place , such as : Shared memory mechanism is commonly used in kernel and user space , Some low-speed data transmission uses socket Handle , Transmission between application processes uses Binder Mechanism .
This section begins , Let's study it together Binder The mechanism and principle of .
Binder Division
stay Android 8.0 Before ,Binder The mechanism is relatively simple , There is only one driving device "/dev/binder", A guardian goes "/system/bin/servicemanager", One binder library "/system/lib64/libbinder.so".
stay Android 8.0 Start ,Android Introduced Treble The mechanism of , For convenience Android Rapid transplantation of the system 、 upgrade , Lifting system stability ,Binder The mechanism has been expanded into "/dev/binder", “/dev/hwbinder”,“/dev/vndbinder”.
We used "/dev/binder", Become a proprietary node of the framework process , This means that the vendor process can no longer access this node . The supplier process can access /dev/hwbinder, But it must be AIDL Interface to use HIDL.
For those who want to continue to use between supplier processes AIDL Supplier of the interface , Need to use /dev/vndbinder( Instead of /dev/binder).
Android8.0 And later Binder The domain is shown in the following figure :
Three Binder Introduction and connection
Binder
stay Android 8.0 Before , This is what we are most familiar with and have been using Binder.Java Layers of inheritance Binder,Native C/C++ Layers of inheritance Bbbinder, And then through servicemanager Process registration real name Binder, Then through the already created Binder Interface passing anonymity Binder object , Get BinderProxy perhaps BpBinder in the future , Can Binder The communication .
stay Android 8.0 after , This Binder The mechanism remains ,/dev/binder The device node becomes the exclusive node of the framework process , This means that the vendor process can no longer access this node .
If you are a system manufacturer , stay system Partition has processes ,/dev/biner The mechanism can still be used , But your progress is vendor Partition , You can only use /dev/hwbinder perhaps /dev/vndbinder.
Binder The mechanism requires that both processes belong to System Partition
VndBinder
ndroid8.0 Support new Binder Domain , Access to this domain requires /dev/vndbinder( Instead of /dev/binder). To show /dev/vndbinder, Please make sure that the kernel configuration item CONFIG_ANDROID_BINDER_DEVICES Set to “binder,hwbinder,vndbinder”( This is a Android Default setting of general kernel tree ).vndbinder and binder share libbinder This system library , There are only some differences between daemon and kernel space , The overall code flow and usage are basically the same .
Java Layers of inheritance Binder,Native C/C++ Layers of inheritance Bbbinder, adopt vndservicemanager Process registration real name Binder, Then through the already created Binder Interface passing anonymity Binder object , Get BinderProxy perhaps BpBinder in the future , Can Binder The communication .
and Binder The difference between , Namely device Turned into "/dev/vndbinder", The daemon becomes "vndservicemanager"
Usually , The supplier process does not open directly Binder The driver , Instead, link to open Binder Driver's libbinder User space Library . by ::android::ProcessState() The addition method can be libbinder choice Binder The driver . The supplier process should call ProcessState,、IPCThreadState Or send any ordinary Binder Call this method before calling . To use this method , Please check the supplier process ( Client and server ) Of main() After placing the following call :
ProcessState::initWithDriver("/dev/vndbinder");
dev/binder and dev/vndbinder Cannot use in one process at the same time
binder and vndbiner All mechanisms share one set libbinder, So when using both , Only one device node can be specified at a time , Can't be used at the same time .
VndBinder The mechanism requires that both processes belong to Vendor Partition
vndservicemanager
before ,Binder Service pass servicemanager register , Other processes can retrieve these services . stay Android 8 in ,servicemanager It is now dedicated to the framework , Application processes and vendor processes can no longer access it .
however , Vendor services are now available vndservicemanager, This is a use of /dev/vndbinder( Source code and framework as the basis of compilation servicemanager In the same ) Instead of /dev/binder Of servicemanager New examples .
The supplier process can communicate with vndservicemanager signal communication ; When the supplier process opens /dev/vndbinder when , Service query will automatically go to vndservicemanager.
vndservicemanager Binary files are contained in Android Default device Android.bp in .
HwBinder
hwbinder and binder\vndbinder It's different ,hwbinder It's a new process , There is a separate drive device "/dev/hwbinder", Independent daemon "hwservicemanager", independent SDK-“libhwbinder”
HwBinder The mechanism can span System and Vendor Partition use
Why introduce hwbinder
Android 8.0 Introduced in Treble Mechanism ,Treble The project realizes from the bottom supplier Android From the kernel framework , send Android Updating becomes easier . This modular design allows the platform and the components provided by the supplier to be updated independently . Make updating easier 、 It's great to be faster , However ,Treble There is another purpose of strengthening modular design : Improve safety .
Treble After introduction , I added a new one vendor.img, The original system Partition , Split into system Zoning and vendor Partition ,soc And the function realization of suppliers need to be put into vendor Partition , This will system and vendor Related images separate , Easy to update and upgrade system, And don't rely on vendor Wait for the bottom .
stay Android 8.0 Before ,HAL One by one .so library , adopt dlopen To open , Kuhe framework In the same process , Before Android System architecture ,Android Framework And Android HAL It's packaged into a system.img Of , and Framework And HAL Are tightly coupled , Use the corresponding hardware related functions through links so library .
Android 8.0 The previous communication mechanism is shown in the figure below :
So every time Android framework The upgrade of requires corresponding Android HAL upgrade , This requires suppliers to spend a lot of manpower to upgrade the corresponding Vendor HAL Implemetation, This is what leads to Android The version upgrade is slow , A few years later, many users ,Android Can't be updated in time .
stay Android8.0 And later ,Android A new mechanism is designed to isolate HAL layer , Introduced a HIDL To define Framework and HAL Interface between
stay Android 8.0 And later versions ,Android Updated the new framework design in the new framework design , Introduced a system called HIDL To define Freamework And HAL Interface between ,Android Framework Will be in system In the middle of the Division , and VendorHAL Implemetation In a newly defined partition (Vendor.img) among , Refresh like this system.img Will not affect Vendor HAL Implemetation.
stay Android 8.0 And after ,HAL Kuhe framework Not in the same process , They use hwbinder Communication between processes .
Android 8.0 introduce Treble after , The communication mechanism of each layer is as follows :
Binder Library changes
Binder and VndBinder The common use libbinder, HwBinder Use libhwbinder, The directory differences of the code are as follows :
servicemanager The directory differences of are as follows :
summary
Android introduce Treble After the mechanism , Expanded one vendor Partition , In order to upgrade quickly , It's isolated HAL Layer mechanism , in order to System/System、System/Vendor、Vendor/Vendor Between different processes , Put the original Binder The mechanism is split into Binder、HwBinder、VndBinder.
Binder and VndBinder Share a set libbinder、servicemanager Code for , Use AIDL Interface , The two cannot coexist .
HwBinder A separate libhwbinder、hwservicemanager Code for , Manage alone , Use HIDL Interface .
The three do not interfere with each other , While facilitating system upgrade , It also improves the security and stability of the system .
Next , I will separate different sections , To share alone Binder、HwBinder、VndBinder How it works .
边栏推荐
- Error: No named parameter with the name ‘foregroundColor‘
- 高手勿进!写给初中级程序员以及还在大学修炼的“准程序员”的成长秘籍
- Disk monitoring related commands
- Timer create timer
- Knapsack problem unrelated to profit (depth first search)
- If you‘re running pod install manually, make sure flutter pub get is executed first.
- PMP证书有没有必要续期?
- Weebly移动端网站编辑器 手机浏览新时代
- 最长回文子串(动态规划)
- Y58. Chapter III kubernetes from entry to proficiency - continuous integration and deployment (Sany)
猜你喜欢
If you‘re running pod install manually, make sure flutter pub get is executed first.
带你遨游银河系的 10 种分布式数据库
PMP证书有没有必要续期?
Batch normalization (Standardization) processing
Inventory host list in ansible (I wish you countless flowers and romance)
AOSP ~Binder 通信原理 (一) - 概要
Understand common network i/o models
[email protected] Mapping relatio"/>
Why JSON is used for calls between interfaces, how fastjson is assigned, fastjson 1.2 [email protected] Mapping relatio
c语言神经网络基本代码大全及其含义
Liste des hôtes d'inventaire dans ansible (je vous souhaite des fleurs et de la romance sans fin)
随机推荐
2. Overview of securities investment funds
Autowired注解用于List时的现象解析
Leetcode minimum difference in student scores
Weebly移动端网站编辑器 手机浏览新时代
Batch normalization (Standardization) processing
What changes will PMP certification bring?
拿到PMP认证带来什么改变?
模拟线程通信
【opencv】图像形态学操作-opencv标记不同连通域的位置
U++ 游戏类 学习笔记
基于Bevy游戏引擎和FPGA的双人游戏
vector和类拷贝构造函数
Operand of null-aware operation ‘!‘ has type ‘SchedulerBinding‘ which excludes null.
Pointer and array are input in function to realize reverse order output
Creation and use of thread pool
[Yugong series] go teaching course 005 variables in July 2022
DBSync新增对MongoDB、ES的支持
Two methods of thread synchronization
CentOS 7.9安装Oracle 21c历险记
STM32F103 realize IAP online upgrade application