当前位置:网站首页>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 .
边栏推荐
- Complete code of C language neural network and its meaning
- Is PMP really useful?
- 2.证券投资基金的概述
- 与利润无关的背包问题(深度优先搜索)
- Analysis -- MySQL statement execution process & MySQL architecture
- Dbsync adds support for mongodb and ES
- No experts! Growth secrets for junior and intermediate programmers and "quasi programmers" who are still practicing in Universities
- 2039: [Bluebridge cup 2022 preliminaries] Li Bai's enhanced version (dynamic planning)
- torch optimizer小解析
- 基于Bevy游戏引擎和FPGA的双人游戏
猜你喜欢
pmp真的有用吗?
AOSP ~Binder 通信原理 (一) - 概要
Error: No named parameter with the name ‘foregroundColor‘
Operand of null-aware operation ‘!‘ has type ‘SchedulerBinding‘ which excludes null.
U++4 interface learning notes
If you‘re running pod install manually, make sure flutter pub get is executed first.
Ansible中的inventory主機清單(預祝你我有數不盡的鮮花和浪漫)
Autowired注解用于List时的现象解析
window定时计划任务
Is it necessary to renew the PMP certificate?
随机推荐
2.证券投资基金的概述
Function pointer and pointer function in C language
Talk about the importance of making it clear
[ArcGIS tutorial] thematic map production - population density distribution map - population density analysis
Redis如何实现多可用区?
创始人负债10亿,开课吧即将“下课”?
Window scheduled tasks
If you‘re running pod install manually, make sure flutter pub get is executed first.
10 distributed databases that take you to the galaxy
[736. LISP syntax parsing]
Ansible reports an error: "MSG": "invalid/incorrect password: permission denied, please try again“
最长公共子序列(LCS)(动态规划,递归)
vector和类拷贝构造函数
Development thoughts of adding new requirements in secondary development
《二》标签
Operand of null-aware operation ‘!‘ has type ‘SchedulerBinding‘ which excludes null.
When knative meets webassembly
【opencv】图像形态学操作-opencv标记不同连通域的位置
QT控件样式系列(一)之QSlider
Sublime tips