当前位置:网站首页>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 .
边栏推荐
- Array initialization of local variables
- sublime使用技巧
- U++4 interface learning notes
- 使用知云阅读器翻译统计遗传学书籍
- Disk monitoring related commands
- The most complete learning rate adjustment strategy in history LR_ scheduler
- npm ERR! 400 Bad Request - PUT xxx - “devDependencies“ dep “xx“ is not a valid dependency name
- Longest non descent subsequence (LIS) (dynamic programming)
- PLC Analog output analog output FB analog2nda (Mitsubishi FX3U)
- 人体传感器好不好用?怎么用?Aqara绿米、小米之间到底买哪个
猜你喜欢

sublime使用技巧

LabVIEW在打开一个新的引用,提示内存已满

How to choose an offer and what factors should be considered

U++ 元数据说明符 学习笔记

全链路压测:影子库与影子表之争

Autowired注解用于List时的现象解析

ThinkPHP关联预载入with

Flask project uses flask socketio exception: typeerror: function() argument 1 must be code, not str

一个酷酷的“幽灵”控制台工具

AttributeError: module ‘torch._ C‘ has no attribute ‘_ cuda_ setDevice‘
随机推荐
【问道】编译原理
Creation and use of thread pool
基于Bevy游戏引擎和FPGA的双人游戏
腾讯云数据库公有云市场稳居TOP 2!
How to choose an offer and what factors should be considered
Longest palindrome substring (dynamic programming)
【QT】自定义控件-Loading
Servicemesh mainly solves three pain points
Liste des hôtes d'inventaire dans ansible (je vous souhaite des fleurs et de la romance sans fin)
Why is the salary of test and development so high?
app内嵌h5---iphone软键盘遮挡输入文字
Auto.js 获取手机所有app名字
HarmonyOS第四次培训
AOSP ~Binder 通信原理 (一) - 概要
装饰器基础学习02
Test interview | how much can you answer the real test interview question of an Internet company?
【最佳网页宽度及其实现】「建议收藏」
Linkedblockingqueue source code analysis - initialization
全链路压测:影子库与影子表之争
动态生成表格