当前位置:网站首页>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 .
边栏推荐
- Longest non descent subsequence (LIS) (dynamic programming)
- Autowired注解用于List时的现象解析
- 想要选择一些部门优先使用 OKR, 应该如何选择试点部门?
- 高数中值定理总结
- Complete code of C language neural network and its meaning
- Redis如何实现多可用区?
- DFS, BFS and traversal search of Graphs
- Comparison between thread and runnable in creating threads
- App embedded H5 --- iPhone soft keyboard blocks input text
- QT simple layout box model with spring
猜你喜欢
Window scheduled tasks
Complete code of C language neural network and its meaning
动态生成表格
torch optimizer小解析
Why do many people misunderstand technical debt
SQL injection cookie injection
记录一次压测经验总结
全链路压测:影子库与影子表之争
Salesforce 容器化 ISV 场景下的软件供应链安全落地实践
No experts! Growth secrets for junior and intermediate programmers and "quasi programmers" who are still practicing in Universities
随机推荐
Linkedblockingqueue source code analysis - initialization
3. Type of fund
Operand of null-aware operation ‘!‘ has type ‘SchedulerBinding‘ which excludes null.
The founder has a debt of 1billion. Let's start the class. Is it about to "end the class"?
全链路压测:影子库与影子表之争
SQL injection - secondary injection and multi statement injection
Salesforce 容器化 ISV 场景下的软件供应链安全落地实践
DFS, BFS and traversal search of Graphs
Comparison between thread and runnable in creating threads
【愚公系列】2022年7月 Go教学课程 005-变量
01 machine learning related regulations
Simulate thread communication
Clickhouse (03) how to install and deploy Clickhouse
DBSync新增对MongoDB、ES的支持
Longest palindrome substring (dynamic programming)
[opencv] image morphological operation opencv marks the positions of different connected domains
Autowired注解用于List时的现象解析
npm ERR! 400 Bad Request - PUT xxx - “devDependencies“ dep “xx“ is not a valid dependency name
装饰器基础学习02
If you‘re running pod install manually, make sure flutter pub get is executed first.