Download - IPC: AIDL is not a curse
![Page 1: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/1.jpg)
IPC: AIDL is not a curse
Or how to eat it a binder and stay alive
![Page 2: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/2.jpg)
Yonatan Levin
![Page 3: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/3.jpg)
> 10M users
Ruby, Golang, Python, Android,
iOS
52cities
![Page 4: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/4.jpg)
> 500 members
Google Supported
Largest StudyJam
in the World
![Page 5: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/5.jpg)
What we going to do?
Having fun!
![Page 6: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/6.jpg)
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
![Page 7: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/7.jpg)
Source Code
https://github.com/parahall/AIDLServiceExample.git
![Page 8: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/8.jpg)
What is IPC
Inter-process communication (IPC) is a framework for the exchange of signals and data across multiple processes
![Page 9: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/9.jpg)
Binder, IPC best friend
![Page 10: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/10.jpg)
Binder, IPC best friend
![Page 11: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/11.jpg)
Binder, IPC best friend
Bin
der
![Page 12: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/12.jpg)
Why Binder?
PerformanceSecurityStabilityMemory managementSingle app with separate process
![Page 13: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/13.jpg)
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! :)
![Page 14: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/14.jpg)
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
![Page 15: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/15.jpg)
We already using binder today!
LifeCycle callbacks (onResume, OnDestroy) invoked by ActivityManagerService
Intents
Content Provider
![Page 16: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/16.jpg)
IPC with Intents and Content Provider
![Page 17: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/17.jpg)
Example of Intent
![Page 18: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/18.jpg)
So why not to use only intents
Not really OOPAsync onlyLoosely-definedNot so fastHigh Level Abstraction of Binder
![Page 19: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/19.jpg)
Other alternatives
IPC with Messenger!!!
![Page 20: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/20.jpg)
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
![Page 21: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/21.jpg)
Messenger IPC
git checkout MessengerIPC
![Page 22: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/22.jpg)
DarthVaderActivity
![Page 23: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/23.jpg)
DarthVaderActivity - Cont’
![Page 24: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/24.jpg)
EmpireService
![Page 25: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/25.jpg)
EmpireService - Cont’
![Page 26: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/26.jpg)
But what if?
We want sync calls?Very fast. Like really fast!Full OOPBusiness Transparent
![Page 27: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/27.jpg)
AIDLbut … first let’s dive into Binder
![Page 28: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/28.jpg)
Binder API
![Page 29: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/29.jpg)
A long time ago in a galaxy far, far away....
![Page 30: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/30.jpg)
A new hope - Builder
![Page 31: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/31.jpg)
Steel the plans of binder
![Page 32: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/32.jpg)
A manager that can save galaxy
![Page 33: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/33.jpg)
And restore freedom to the galaxy....
![Page 34: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/34.jpg)
Now you can breath easily
we have AIDL
![Page 35: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/35.jpg)
AIDL
Our business operation on top of Binder object
Java-like interface
Defined in separate .aidl file
Aidl Generate code of real java interface
![Page 36: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/36.jpg)
.AIDL interface and result
![Page 37: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/37.jpg)
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.
![Page 38: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/38.jpg)
AIDL Data Types
All primitives and arrays of primitivesFileDescriptionSerializable/Parcelable****MapBundleListSparseArray
![Page 39: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/39.jpg)
Ladies and Gentlemen - Full
Solution
git checkout ServiceViaAIDL
![Page 40: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/40.jpg)
Sync Call - Death Star
![Page 41: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/41.jpg)
IStarWarsImplementation
![Page 42: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/42.jpg)
EmpireService
![Page 43: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/43.jpg)
DarthVaderActivity
![Page 44: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/44.jpg)
DarthVaderActivity
![Page 45: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/45.jpg)
ASync Call - Find a luke
![Page 46: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/46.jpg)
AIDL Interfaces
![Page 47: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/47.jpg)
IStarWarsImplementation
![Page 48: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/48.jpg)
DarthVaderActivity
![Page 49: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/49.jpg)
So what we got?
Services running on separate processEasy expandable communicationFun :)
![Page 50: IPC: AIDL is not a curse](https://reader035.vdocument.in/reader035/viewer/2022062313/55d0b874bb61ebd5718b458e/html5/thumbnails/50.jpg)
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