SlideShare una empresa de Scribd logo
1 de 26
Android Binder IPC
Chethan Palakshamurthy
Outline
• What is Binder IPC?
• High level design
• Communication between participants
• Low level design
• Creation of proxy and native binders
Index
• What is Binder IPC?
Binder IPC
• The features of Binder are comparable to functionality
provided by any mature traditional client/server
architecture or IPC mechanisms.
– Symbian IPC, Linux D-Bus are couple of the examples.
• Binder takes a different approach with the constructs
used, to better support Android Interface Definition
Language (AIDL) and its implementation
• The main feature of Binder is that, instead of sharing
enumerated command/request ids, the client and server
sides share a common abstract service interface
– There exist two objects which implement the same interface.
(1) Local proxy – for use by application in the same process
and (2) Remote service object – which has the actual service
implementation, resides in service’s process
– Invoking an API on the local proxy object, translates to a call
on the remote object
Index
• What is Binder IPC?
• High level design
Binder IPC – High level design
Service
Manager
Service
Register/
Deregister by service
name
Application
Get Service0..* 1
1
0..*
0..*
0..*
Via
Kernel Driver
IServiceManager
IAbcService
Binder IPC – High level view
• Binder framework uses a kernel driver for IPC - /dev/binder
• Clients to the driver are
– App (Service user)
– Services
– Service Manager (Also a service – a special one)
• Driver assigns and maintains IDs or handles (and much more info)
of each.
• Service manager (Id = 0)
– Registers itself with binder driver, as ‘Manager’ on device startup
– Manages a list of services.
• Services
– Services register themselves with SVC manager on service startup
– Provide an abstract service interface
Binder IPC – Using a service
• First, application gets IServiceManager handle.
– Using the globally known identifier – 0.
– There are helper functions to get this object
• App invokes IServiceManager::GetService to get
a handle of IAbcService for a service “Abc”
– IServiceManager object is implemented by
framework and is part of binder library
• Invokes IAbcService::PerformSomething call
– The call gets translated to PerformSomething call on
the service object
– Service provider needs to implement the
IAbcService
Binder IPC – High level design
Service Object
Application
Local Proxy Object
ProxyAbcService
Remote Native Object
NativeAbcService
IAbcService::
PerformSomething()
Driver
IAbcService::
PerformSomething()
IAbcService
App process Service process
Index
• What is Binder IPC?
• High level design
• Communication
Binder IPC Design – Messaging
…
Service
Manager
Application Service 1
Service 2
Service N
Kernel
Driver
fd=/dev/binder
“Media.Player”
Id: 0
2.
ioctl(fd, params{fd,params{
cmd=ADDSERVICE,
service=“Media.Player”
target=0})
//on startup of process
4.
ioctl(fd, params
{cmd=CREATE,
target=1})
3.
ioctl(fd, params
{cmd=GET,
srv=“media.player”
target=0
outHandle=})
Binder IPC Design - Messaging
1. Service manager opens ‘/dev/binder’ and registers itself (handle
= 0) as manager using ioctl
2. Media Player Service, on process startup, creates an object
instance (MediaPlayerService) and registers it (instance as
handle, say 0x70FF) along with a name, with SVC Mgr.
– By calling ioctl with target handle = 0, in parameter
– Driver knows ‘0’. It directs it to SVC Mgr.
– Seeing ADD_SERVICE in param, SVC Mgr, registers the service along
with provided handle.
– Now, SVC manager knows “Media.Player”. Driver knows media
player service handle – 0x70FF.
3. Application asks SVC Mgr for “Media.Player” service
– By calling ioctl with target handle = 0, cmd=“GET_SERVICE”,
name=“Media.Player”
– SVC Mgr returns the handle associated with “Media.Player”, in ioctl
out params.
Binder IPC Design - Messaging
4.Application asks the service to create one
instance of media player. (Media Player Service supports
multiple player instances)
– By calling ioctl with target handle = ‘0x70FF’
(say)
– Media Player Service on seeing command
‘CREATE’ creates a player instance and embeds
the instance handle in the reply.
Binder IPC Design – Send/Receive
Impl.
• Each client of the driver has 1 or more threads.
• A thread on the server waits on a loop on an ioctl waiting for a
service request.
• The driver puts the thread to sleep using
wait_event_interruptible.
• When an app calls ioctl on its end targeting a service, the driver
wakes up a thread of that service
• ioctl on service end, comes out of the wait, services the request
• Now, if it’s a sync request, app makes another ioctl call waiting
for reply.
• The services sends a reply parcel back by calling ioctl, waking up
the app; and goes back to sleep with another ioctl call (typically
in a loop)
• If the request is Async, service calls ioctl sometime later. But this
time, one of the threads waiting with ioctl will pick it up
Binder IPC Design – Send/Receive -
Sync
App SVC1::Thread1
ioctl(fd,params)
ioctl blocks the thread
and puts into sleep
Kern Driver
ioctl(fd, params)
Thread is resumed,
as ioctl returns
Process(params)
ioctl(fd, ..)
//reply
calls ioctl again to go
back to waiting mode,
suspending the
thread
ioctl(fd,params)
Sending request
mesg
Waiting
for reply
Process
Reply data
Binder IPC Design – Async call from
Service
SVCApp::Thread1
ioctl(fd,params)
ioctl blocks the thread
and puts into sleep
Kern Driver
ioctl(fd, params)
Thread is resumed,
ioctl returns
Process(params)
ioctl(fd, params)
//reply
calls ioctl again to go
back to waiting mode,
suspending the
thread
Sending request
mesg
Waiting
for reply
Process
Reply data
ioctl(fd,params)
Index
• What is Binder IPC?
• High level design
• Communication
• Low level design
Binder IPC – LLD
• Application or service do not call ioctl directly.
• There are layers of objects before an application
intent gets translated to an ioctl. Some important
ones are -
1. Local proxy object  Implements a service specific
abstract interface
– E.g., BpMediaPlayerService (B=binder, p=proxy)
– Each API implementation creates `Parcels` that
encapsulate command/request ID etc.
– Forwards Parcel to proxy helper.
2. Proxy Helper 
– Flattens & converts the parcels into ioctl parameter
objects and makes the ioctl call.
– BpBinder, IPCThreadState
Binder IPC – LLD
3. Remote helper 
– Receives and unflattens the ioctl parameters
– Delegates parcel to remote native object.
– IPCThreadState, BBinder
4. Remote native object
– Does the exact opposite of local proxy object
– Receives the parcel and calls the appropriate service
object
– BnMediaPlayerService
5. Service Object
– Has the ‘real’ implementation of the service
– E.g., MediaPlayerService : BnMediaPlayerService
(B=binder, n=proxy)
– MediaPlayerService
Binder IPC – LLD
IABCInterfaceApplication
Local Proxy object
Remote Helper
Binder Driver
Proxy Helper
<<Extends>>
IPC Message
IPC Message
Remote Native object
Google
Service Implementer
Transact(Parcel*)
onTransact(Parcel*)
Service Object
Binder IPC – LLD
Application
Binder Driver
BpMediaPlayerService
setDataSource(…)
Transact(SET_DATA_SOURCE_URL, Parcel*)
BpBinder
MediaPlayerService::Client
BnMediaPlayerService
setDataSource(…)
OnTransact(SET_DATA_SOURCE_URL, Parcel*)
BBinder
ioctl
resume ioctl
Thread
transact()
IPCThreadState
transact()
IMediaPlayerService
Index
• What is Binder IPC?
• High level design
• Communication
• Low level design
• Creation of proxy and native binders
Binder IPC – Creation of proxy and
native binders
• Getting Service Manager object
– Use sp<IServiceManager> defaultServiceManager() to get handle.
– This function creates a BpBinder(0) and wraps it
with BpServiceManager
– BpBinder is the helper object which can send IPC to
the desired handle. In this case handle = 0.
– BpServiceManager translates manager calls to IPC
using BpBinder object
– That is, a service proxy object wraps a BpBinder
– Wrapping is done with interface_cast<>
Binder IPC – Creation of proxy and
native binders
• Getting service object
– App gets a desired service using sp<IBinder>
IServiceManager::GetService (“Media.Player”)
– When GetService calls ioctl, it gets a virtual
handle to MediaPlayerService.
– A BpBinder(handle) is created and wrapped
with BpMediaPlayerService
– Thus sp<BpMediaPlayerService> is obtained for
App’s use.
Binder IPC – Creation of proxy and
native binders
• Creating a media player instance
– sp<BpMediaPlayerService>.create(…)
– create() sends ioctl message to MediaPlayerService
instance on Media server process
– create API is invoked on MediaPlayerService instance.
– Based on parameters, the service creates a media player
instance - BnMediaPlayer.
– The instance handle is returned embedded in the ioctl
call as a ‘cookie’
– Driver notes the cookie (in binder node inside driver)
and in future transactions to Media Player, it sends the
cookie, along with any msg from Application.
– On app side, sp<BpMediaPlayerService>.create()
method again creates a BpBinder with that handle of
MediaPlayer
Binder IPC – Creation of proxy and
native binders
• Calling API on media player instance
– sp<BpMediaPlayer>.setDataSource(…)
– The implementation creates a Parcel and passes it
on to BpBinder
– The IPC message is delivered to the media server.
– The driver adds the ‘proxy’ pointer along with the
message
– The binder framework on the media server on
receiving the cookie, fetches the native service
instance and passes on the Parcel.
– The instance eventually calls setDataSource on
itself.

Más contenido relacionado

La actualidad más candente

Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveBin Chen
 
Understanding binder in android
Understanding binder in androidUnderstanding binder in android
Understanding binder in androidHaifeng Li
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Opersys inc.
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in AndroidOpersys inc.
 
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)Nanik Tolaram
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessNanik Tolaram
 
Project meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewProject meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewYu-Hsin Hung
 
Learning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverLearning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverNanik Tolaram
 
Android internals By Rajesh Khetan
Android internals By Rajesh KhetanAndroid internals By Rajesh Khetan
Android internals By Rajesh KhetanRajesh Khetan
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time OptimizationKan-Ru Chen
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux DevelopersOpersys inc.
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALOpersys inc.
 

La actualidad más candente (20)

Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
 
Understanding binder in android
Understanding binder in androidUnderstanding binder in android
Understanding binder in android
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Embedded Android : System Development - Part IV (Android System Services)
Embedded Android : System Development - Part IV (Android System Services)Embedded Android : System Development - Part IV (Android System Services)
Embedded Android : System Development - Part IV (Android System Services)
 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in Android
 
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
 
Project meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewProject meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture Overview
 
Learning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverLearning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device Driver
 
Android internals By Rajesh Khetan
Android internals By Rajesh KhetanAndroid internals By Rajesh Khetan
Android internals By Rajesh Khetan
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Android ipm 20110409
Android ipm 20110409Android ipm 20110409
Android ipm 20110409
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 

Destacado

Inter-process communication of Android
Inter-process communication of AndroidInter-process communication of Android
Inter-process communication of AndroidTetsuyuki Kobayashi
 
Intentの概要
Intentの概要Intentの概要
Intentの概要l_b__
 
Android Multimedia Framework
Android Multimedia FrameworkAndroid Multimedia Framework
Android Multimedia FrameworkPicker Weng
 
Androidのリカバリシステム (Androidのシステムアップデート)
Androidのリカバリシステム (Androidのシステムアップデート)Androidのリカバリシステム (Androidのシステムアップデート)
Androidのリカバリシステム (Androidのシステムアップデート)l_b__
 
Binderのはじめの一歩とAndroid
Binderのはじめの一歩とAndroidBinderのはじめの一歩とAndroid
Binderのはじめの一歩とAndroidl_b__
 
Android crash debugging
Android crash debuggingAndroid crash debugging
Android crash debuggingAshish Agrawal
 
Dense Bituminous macadam
Dense Bituminous macadamDense Bituminous macadam
Dense Bituminous macadampradip dangar
 
Mastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental pluginMastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental pluginXavier Hallade
 
Using the Presentation API and external screens on Android
Using the Presentation API and external screens on AndroidUsing the Presentation API and external screens on Android
Using the Presentation API and external screens on AndroidXavier Hallade
 
Flow of events during Media Player creation in Android
Flow of events during Media Player creation in AndroidFlow of events during Media Player creation in Android
Flow of events during Media Player creation in AndroidSomenath Mukhopadhyay
 
An Introduction to Android Internals
An Introduction to Android InternalsAn Introduction to Android Internals
An Introduction to Android InternalsAnjana Somathilake
 
Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013Charles Nutter
 
Permission use analysis for vetting undesirable behavior in
Permission use analysis for vetting undesirable behavior inPermission use analysis for vetting undesirable behavior in
Permission use analysis for vetting undesirable behavior inchaitrabhat777
 

Destacado (20)

Inter-process communication of Android
Inter-process communication of AndroidInter-process communication of Android
Inter-process communication of Android
 
Android binder-ipc
Android binder-ipcAndroid binder-ipc
Android binder-ipc
 
Understanding open max il
Understanding open max ilUnderstanding open max il
Understanding open max il
 
Intentの概要
Intentの概要Intentの概要
Intentの概要
 
Android Multimedia Framework
Android Multimedia FrameworkAndroid Multimedia Framework
Android Multimedia Framework
 
Androidのリカバリシステム (Androidのシステムアップデート)
Androidのリカバリシステム (Androidのシステムアップデート)Androidのリカバリシステム (Androidのシステムアップデート)
Androidのリカバリシステム (Androidのシステムアップデート)
 
Binderのはじめの一歩とAndroid
Binderのはじめの一歩とAndroidBinderのはじめの一歩とAndroid
Binderのはじめの一歩とAndroid
 
IOMX in Android
IOMX in AndroidIOMX in Android
IOMX in Android
 
Android crash debugging
Android crash debuggingAndroid crash debugging
Android crash debugging
 
Dense Bituminous macadam
Dense Bituminous macadamDense Bituminous macadam
Dense Bituminous macadam
 
Mastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental pluginMastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
 
Using the Presentation API and external screens on Android
Using the Presentation API and external screens on AndroidUsing the Presentation API and external screens on Android
Using the Presentation API and external screens on Android
 
Bituminous pavement
Bituminous pavementBituminous pavement
Bituminous pavement
 
Knee biomechanic
Knee biomechanicKnee biomechanic
Knee biomechanic
 
Android IPC: Binder
Android IPC: BinderAndroid IPC: Binder
Android IPC: Binder
 
Flow of events during Media Player creation in Android
Flow of events during Media Player creation in AndroidFlow of events during Media Player creation in Android
Flow of events during Media Player creation in Android
 
An Introduction to Android Internals
An Introduction to Android InternalsAn Introduction to Android Internals
An Introduction to Android Internals
 
Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013
 
Android Hacks - Hack57
Android Hacks - Hack57Android Hacks - Hack57
Android Hacks - Hack57
 
Permission use analysis for vetting undesirable behavior in
Permission use analysis for vetting undesirable behavior inPermission use analysis for vetting undesirable behavior in
Permission use analysis for vetting undesirable behavior in
 

Similar a Overview of Android binder IPC implementation

Overview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technologyOverview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technologyPeter R. Egli
 
Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...
Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...
Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...VMware Tanzu
 
DEVNET-1128 Cisco Intercloud Fabric NB Api's for Business & Providers
DEVNET-1128	Cisco Intercloud Fabric NB Api's for Business & ProvidersDEVNET-1128	Cisco Intercloud Fabric NB Api's for Business & Providers
DEVNET-1128 Cisco Intercloud Fabric NB Api's for Business & ProvidersCisco DevNet
 
Fiware Developers Week IoT Agents (Advanced)
Fiware Developers Week IoT Agents (Advanced)Fiware Developers Week IoT Agents (Advanced)
Fiware Developers Week IoT Agents (Advanced)dmoranj
 
Make Java Microservices Resilient with Istio - Mangesh - IBM - CC18
Make Java Microservices Resilient with Istio - Mangesh - IBM - CC18Make Java Microservices Resilient with Istio - Mangesh - IBM - CC18
Make Java Microservices Resilient with Istio - Mangesh - IBM - CC18CodeOps Technologies LLP
 
Wifi direct p2p app
Wifi direct p2p appWifi direct p2p app
Wifi direct p2p appgeniushkg
 
FIWARE NGSI: Managing Context Information at Large Scale
FIWARE NGSI: Managing Context Information at Large ScaleFIWARE NGSI: Managing Context Information at Large Scale
FIWARE NGSI: Managing Context Information at Large ScaleFIWARE
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetesrajdeep
 
AngularJSTO presentation
AngularJSTO presentationAngularJSTO presentation
AngularJSTO presentationAlan Hietala
 
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...MongoDB
 
Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes Weaveworks
 
Impact 2014 1147 - Bridging Business Process Management and Integration use c...
Impact 2014 1147 - Bridging Business Process Management and Integration use c...Impact 2014 1147 - Bridging Business Process Management and Integration use c...
Impact 2014 1147 - Bridging Business Process Management and Integration use c...Brian Petrini
 
IoT Toolkit and the Smart Object API - Architecture for Interoperability
IoT Toolkit and the Smart Object API - Architecture for InteroperabilityIoT Toolkit and the Smart Object API - Architecture for Interoperability
IoT Toolkit and the Smart Object API - Architecture for InteroperabilityMichael Koster
 
IoT Toolkit and the Smart Object API - Architecture for Interoperability
IoT Toolkit and the Smart Object API - Architecture for InteroperabilityIoT Toolkit and the Smart Object API - Architecture for Interoperability
IoT Toolkit and the Smart Object API - Architecture for InteroperabilityMichael Koster
 
Iot Toolkit and the Smart Object API - Architecture for Interoperability
Iot Toolkit and the Smart Object API - Architecture for InteroperabilityIot Toolkit and the Smart Object API - Architecture for Interoperability
Iot Toolkit and the Smart Object API - Architecture for InteroperabilityMichael Koster
 
How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks Weaveworks
 
IoT Physical Servers and Cloud Offerings.pdf
IoT Physical Servers and Cloud Offerings.pdfIoT Physical Servers and Cloud Offerings.pdf
IoT Physical Servers and Cloud Offerings.pdfGVNSK Sravya
 

Similar a Overview of Android binder IPC implementation (20)

Aidl service
Aidl serviceAidl service
Aidl service
 
Overview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technologyOverview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technology
 
Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...
Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...
Communication Amongst Microservices: Kubernetes, Istio, and Spring Cloud with...
 
DEVNET-1128 Cisco Intercloud Fabric NB Api's for Business & Providers
DEVNET-1128	Cisco Intercloud Fabric NB Api's for Business & ProvidersDEVNET-1128	Cisco Intercloud Fabric NB Api's for Business & Providers
DEVNET-1128 Cisco Intercloud Fabric NB Api's for Business & Providers
 
Fiware Developers Week IoT Agents (Advanced)
Fiware Developers Week IoT Agents (Advanced)Fiware Developers Week IoT Agents (Advanced)
Fiware Developers Week IoT Agents (Advanced)
 
Make Java Microservices Resilient with Istio - Mangesh - IBM - CC18
Make Java Microservices Resilient with Istio - Mangesh - IBM - CC18Make Java Microservices Resilient with Istio - Mangesh - IBM - CC18
Make Java Microservices Resilient with Istio - Mangesh - IBM - CC18
 
Wifi direct p2p app
Wifi direct p2p appWifi direct p2p app
Wifi direct p2p app
 
FIWARE NGSI: Managing Context Information at Large Scale
FIWARE NGSI: Managing Context Information at Large ScaleFIWARE NGSI: Managing Context Information at Large Scale
FIWARE NGSI: Managing Context Information at Large Scale
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetes
 
Micro-services meetup
Micro-services meetupMicro-services meetup
Micro-services meetup
 
AngularJSTO presentation
AngularJSTO presentationAngularJSTO presentation
AngularJSTO presentation
 
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
 
Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes
 
Impact 2014 1147 - Bridging Business Process Management and Integration use c...
Impact 2014 1147 - Bridging Business Process Management and Integration use c...Impact 2014 1147 - Bridging Business Process Management and Integration use c...
Impact 2014 1147 - Bridging Business Process Management and Integration use c...
 
Introduction to Virtual Kubelet
Introduction to Virtual KubeletIntroduction to Virtual Kubelet
Introduction to Virtual Kubelet
 
IoT Toolkit and the Smart Object API - Architecture for Interoperability
IoT Toolkit and the Smart Object API - Architecture for InteroperabilityIoT Toolkit and the Smart Object API - Architecture for Interoperability
IoT Toolkit and the Smart Object API - Architecture for Interoperability
 
IoT Toolkit and the Smart Object API - Architecture for Interoperability
IoT Toolkit and the Smart Object API - Architecture for InteroperabilityIoT Toolkit and the Smart Object API - Architecture for Interoperability
IoT Toolkit and the Smart Object API - Architecture for Interoperability
 
Iot Toolkit and the Smart Object API - Architecture for Interoperability
Iot Toolkit and the Smart Object API - Architecture for InteroperabilityIot Toolkit and the Smart Object API - Architecture for Interoperability
Iot Toolkit and the Smart Object API - Architecture for Interoperability
 
How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks
 
IoT Physical Servers and Cloud Offerings.pdf
IoT Physical Servers and Cloud Offerings.pdfIoT Physical Servers and Cloud Offerings.pdf
IoT Physical Servers and Cloud Offerings.pdf
 

Último

BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 

Último (20)

BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 

Overview of Android binder IPC implementation

  • 1. Android Binder IPC Chethan Palakshamurthy
  • 2. Outline • What is Binder IPC? • High level design • Communication between participants • Low level design • Creation of proxy and native binders
  • 3. Index • What is Binder IPC?
  • 4. Binder IPC • The features of Binder are comparable to functionality provided by any mature traditional client/server architecture or IPC mechanisms. – Symbian IPC, Linux D-Bus are couple of the examples. • Binder takes a different approach with the constructs used, to better support Android Interface Definition Language (AIDL) and its implementation • The main feature of Binder is that, instead of sharing enumerated command/request ids, the client and server sides share a common abstract service interface – There exist two objects which implement the same interface. (1) Local proxy – for use by application in the same process and (2) Remote service object – which has the actual service implementation, resides in service’s process – Invoking an API on the local proxy object, translates to a call on the remote object
  • 5. Index • What is Binder IPC? • High level design
  • 6. Binder IPC – High level design Service Manager Service Register/ Deregister by service name Application Get Service0..* 1 1 0..* 0..* 0..* Via Kernel Driver IServiceManager IAbcService
  • 7. Binder IPC – High level view • Binder framework uses a kernel driver for IPC - /dev/binder • Clients to the driver are – App (Service user) – Services – Service Manager (Also a service – a special one) • Driver assigns and maintains IDs or handles (and much more info) of each. • Service manager (Id = 0) – Registers itself with binder driver, as ‘Manager’ on device startup – Manages a list of services. • Services – Services register themselves with SVC manager on service startup – Provide an abstract service interface
  • 8. Binder IPC – Using a service • First, application gets IServiceManager handle. – Using the globally known identifier – 0. – There are helper functions to get this object • App invokes IServiceManager::GetService to get a handle of IAbcService for a service “Abc” – IServiceManager object is implemented by framework and is part of binder library • Invokes IAbcService::PerformSomething call – The call gets translated to PerformSomething call on the service object – Service provider needs to implement the IAbcService
  • 9. Binder IPC – High level design Service Object Application Local Proxy Object ProxyAbcService Remote Native Object NativeAbcService IAbcService:: PerformSomething() Driver IAbcService:: PerformSomething() IAbcService App process Service process
  • 10. Index • What is Binder IPC? • High level design • Communication
  • 11. Binder IPC Design – Messaging … Service Manager Application Service 1 Service 2 Service N Kernel Driver fd=/dev/binder “Media.Player” Id: 0 2. ioctl(fd, params{fd,params{ cmd=ADDSERVICE, service=“Media.Player” target=0}) //on startup of process 4. ioctl(fd, params {cmd=CREATE, target=1}) 3. ioctl(fd, params {cmd=GET, srv=“media.player” target=0 outHandle=})
  • 12. Binder IPC Design - Messaging 1. Service manager opens ‘/dev/binder’ and registers itself (handle = 0) as manager using ioctl 2. Media Player Service, on process startup, creates an object instance (MediaPlayerService) and registers it (instance as handle, say 0x70FF) along with a name, with SVC Mgr. – By calling ioctl with target handle = 0, in parameter – Driver knows ‘0’. It directs it to SVC Mgr. – Seeing ADD_SERVICE in param, SVC Mgr, registers the service along with provided handle. – Now, SVC manager knows “Media.Player”. Driver knows media player service handle – 0x70FF. 3. Application asks SVC Mgr for “Media.Player” service – By calling ioctl with target handle = 0, cmd=“GET_SERVICE”, name=“Media.Player” – SVC Mgr returns the handle associated with “Media.Player”, in ioctl out params.
  • 13. Binder IPC Design - Messaging 4.Application asks the service to create one instance of media player. (Media Player Service supports multiple player instances) – By calling ioctl with target handle = ‘0x70FF’ (say) – Media Player Service on seeing command ‘CREATE’ creates a player instance and embeds the instance handle in the reply.
  • 14. Binder IPC Design – Send/Receive Impl. • Each client of the driver has 1 or more threads. • A thread on the server waits on a loop on an ioctl waiting for a service request. • The driver puts the thread to sleep using wait_event_interruptible. • When an app calls ioctl on its end targeting a service, the driver wakes up a thread of that service • ioctl on service end, comes out of the wait, services the request • Now, if it’s a sync request, app makes another ioctl call waiting for reply. • The services sends a reply parcel back by calling ioctl, waking up the app; and goes back to sleep with another ioctl call (typically in a loop) • If the request is Async, service calls ioctl sometime later. But this time, one of the threads waiting with ioctl will pick it up
  • 15. Binder IPC Design – Send/Receive - Sync App SVC1::Thread1 ioctl(fd,params) ioctl blocks the thread and puts into sleep Kern Driver ioctl(fd, params) Thread is resumed, as ioctl returns Process(params) ioctl(fd, ..) //reply calls ioctl again to go back to waiting mode, suspending the thread ioctl(fd,params) Sending request mesg Waiting for reply Process Reply data
  • 16. Binder IPC Design – Async call from Service SVCApp::Thread1 ioctl(fd,params) ioctl blocks the thread and puts into sleep Kern Driver ioctl(fd, params) Thread is resumed, ioctl returns Process(params) ioctl(fd, params) //reply calls ioctl again to go back to waiting mode, suspending the thread Sending request mesg Waiting for reply Process Reply data ioctl(fd,params)
  • 17. Index • What is Binder IPC? • High level design • Communication • Low level design
  • 18. Binder IPC – LLD • Application or service do not call ioctl directly. • There are layers of objects before an application intent gets translated to an ioctl. Some important ones are - 1. Local proxy object  Implements a service specific abstract interface – E.g., BpMediaPlayerService (B=binder, p=proxy) – Each API implementation creates `Parcels` that encapsulate command/request ID etc. – Forwards Parcel to proxy helper. 2. Proxy Helper  – Flattens & converts the parcels into ioctl parameter objects and makes the ioctl call. – BpBinder, IPCThreadState
  • 19. Binder IPC – LLD 3. Remote helper  – Receives and unflattens the ioctl parameters – Delegates parcel to remote native object. – IPCThreadState, BBinder 4. Remote native object – Does the exact opposite of local proxy object – Receives the parcel and calls the appropriate service object – BnMediaPlayerService 5. Service Object – Has the ‘real’ implementation of the service – E.g., MediaPlayerService : BnMediaPlayerService (B=binder, n=proxy) – MediaPlayerService
  • 20. Binder IPC – LLD IABCInterfaceApplication Local Proxy object Remote Helper Binder Driver Proxy Helper <<Extends>> IPC Message IPC Message Remote Native object Google Service Implementer Transact(Parcel*) onTransact(Parcel*) Service Object
  • 21. Binder IPC – LLD Application Binder Driver BpMediaPlayerService setDataSource(…) Transact(SET_DATA_SOURCE_URL, Parcel*) BpBinder MediaPlayerService::Client BnMediaPlayerService setDataSource(…) OnTransact(SET_DATA_SOURCE_URL, Parcel*) BBinder ioctl resume ioctl Thread transact() IPCThreadState transact() IMediaPlayerService
  • 22. Index • What is Binder IPC? • High level design • Communication • Low level design • Creation of proxy and native binders
  • 23. Binder IPC – Creation of proxy and native binders • Getting Service Manager object – Use sp<IServiceManager> defaultServiceManager() to get handle. – This function creates a BpBinder(0) and wraps it with BpServiceManager – BpBinder is the helper object which can send IPC to the desired handle. In this case handle = 0. – BpServiceManager translates manager calls to IPC using BpBinder object – That is, a service proxy object wraps a BpBinder – Wrapping is done with interface_cast<>
  • 24. Binder IPC – Creation of proxy and native binders • Getting service object – App gets a desired service using sp<IBinder> IServiceManager::GetService (“Media.Player”) – When GetService calls ioctl, it gets a virtual handle to MediaPlayerService. – A BpBinder(handle) is created and wrapped with BpMediaPlayerService – Thus sp<BpMediaPlayerService> is obtained for App’s use.
  • 25. Binder IPC – Creation of proxy and native binders • Creating a media player instance – sp<BpMediaPlayerService>.create(…) – create() sends ioctl message to MediaPlayerService instance on Media server process – create API is invoked on MediaPlayerService instance. – Based on parameters, the service creates a media player instance - BnMediaPlayer. – The instance handle is returned embedded in the ioctl call as a ‘cookie’ – Driver notes the cookie (in binder node inside driver) and in future transactions to Media Player, it sends the cookie, along with any msg from Application. – On app side, sp<BpMediaPlayerService>.create() method again creates a BpBinder with that handle of MediaPlayer
  • 26. Binder IPC – Creation of proxy and native binders • Calling API on media player instance – sp<BpMediaPlayer>.setDataSource(…) – The implementation creates a Parcel and passes it on to BpBinder – The IPC message is delivered to the media server. – The driver adds the ‘proxy’ pointer along with the message – The binder framework on the media server on receiving the cookie, fetches the native service instance and passes on the Parcel. – The instance eventually calls setDataSource on itself.