ipc: aidl is not a curse
TRANSCRIPT
IPC: AIDL is not a curse
Or how to eat it a binder and stay alive
Yonatan Levin
> 10M users
Ruby, Golang, Python, Android,
iOS
52cities
> 500 members
Google Supported
Largest StudyJam
in the World
What we going to do?
Having fun!
What we going to do?
● Good fellows with IPC
● Best friends with Binder
● Fall in love with AIDL
● Service with AIDL on separate process
example
Source Code
https://github.com/parahall/AIDLServiceExample.git
What is IPC
Inter-process communication (IPC) is a framework for the exchange of signals and data across multiple processes
Binder, IPC best friend
Binder, IPC best friend
Binder, IPC best friend
Bin
der
Why Binder?
PerformanceSecurityStabilityMemory managementSingle app with separate process
Why separate process?
- GC not affecting your app- Less chance to be killed:
- Process that serve others ranking at least as someone he serve
- Process with Service > Process with Background activities
- Crashing not affecting others- New Heap Space- We can! :)
Binder benefits
● Thread migration● Identifying senders to receivers● Unique object-mapping across process● AIDL!!!!● Bult-in support for marshalling● Local execution mode (no IPC) if same
process
We already using binder today!
LifeCycle callbacks (onResume, OnDestroy) invoked by ActivityManagerService
Intents
Content Provider
IPC with Intents and Content Provider
Example of Intent
So why not to use only intents
Not really OOPAsync onlyLoosely-definedNot so fastHigh Level Abstraction of Binder
Other alternatives
IPC with Messenger!!!
Messenger
● A reference to a Handler that can be sent to a remote process via an Intent
● Messages sent by the remote process via the messenger are delivered to the local handler
● Relatively fast
Messenger IPC
git checkout MessengerIPC
DarthVaderActivity
DarthVaderActivity - Cont’
EmpireService
EmpireService - Cont’
But what if?
We want sync calls?Very fast. Like really fast!Full OOPBusiness Transparent
AIDLbut … first let’s dive into Binder
Binder API
A long time ago in a galaxy far, far away....
A new hope - Builder
Steel the plans of binder
A manager that can save galaxy
And restore freedom to the galaxy....
Now you can breath easily
we have AIDL
AIDL
Our business operation on top of Binder object
Java-like interface
Defined in separate .aidl file
Aidl Generate code of real java interface
.AIDL interface and result
Directional FLAG● in means that the object is transferred from client to
service and only used for inputs. If any changes are made to the bar object in the service then they won’t reflect in the client.
● out indicates that the object has no relevant data and will be populated by the service and returned as a response.
● inout means that the data gets copied, i.e., if any changes are made to bar in the service then that’ll also reflect in the client’s bar object.
AIDL Data Types
All primitives and arrays of primitivesFileDescriptionSerializable/Parcelable****MapBundleListSparseArray
Ladies and Gentlemen - Full
Solution
git checkout ServiceViaAIDL
Sync Call - Death Star
IStarWarsImplementation
EmpireService
DarthVaderActivity
DarthVaderActivity
ASync Call - Find a luke
AIDL Interfaces
IStarWarsImplementation
DarthVaderActivity
So what we got?
Services running on separate processEasy expandable communicationFun :)
Special credits
Binder: Communication Mechanism of Android ProcessesDeep Dive into Android IPC/Binder Framework at AnDevCon IV by Aleksandar Gargentahttp://giphy.com/ for amazyng gifsAndroid API Guides