IPC: AIDL is not a curse

51
IPC: AIDL is not a curse Or how to eat it a binder and stay alive

Transcript of IPC: AIDL is not a curse

Page 1: IPC: AIDL is not a curse

IPC: AIDL is not a curse

Or how to eat it a binder and stay alive

Page 2: IPC: AIDL is not a curse

Yonatan Levin

Page 3: IPC: AIDL is not a curse

> 10M users

Ruby, Golang, Python, Android,

iOS

52cities

Page 4: IPC: AIDL is not a curse

> 500 members

Google Supported

Largest StudyJam

in the World

Page 5: IPC: AIDL is not a curse

What we going to do?

Having fun!

Page 6: IPC: AIDL is not a curse

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

Source Code

https://github.com/parahall/AIDLServiceExample.git

Page 8: IPC: AIDL is not a curse

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

Binder, IPC best friend

Page 10: IPC: AIDL is not a curse

Binder, IPC best friend

Page 11: IPC: AIDL is not a curse

Binder, IPC best friend

Bin

der

Page 12: IPC: AIDL is not a curse

Why Binder?

PerformanceSecurityStabilityMemory managementSingle app with separate process

Page 13: IPC: AIDL is not a curse

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

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

We already using binder today!

LifeCycle callbacks (onResume, OnDestroy) invoked by ActivityManagerService

Intents

Content Provider

Page 16: IPC: AIDL is not a curse

IPC with Intents and Content Provider

Page 17: IPC: AIDL is not a curse

Example of Intent

Page 18: IPC: AIDL is not a curse

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

Other alternatives

IPC with Messenger!!!

Page 20: IPC: AIDL is not a curse

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

Messenger IPC

git checkout MessengerIPC

Page 22: IPC: AIDL is not a curse

DarthVaderActivity

Page 23: IPC: AIDL is not a curse

DarthVaderActivity - Cont’

Page 24: IPC: AIDL is not a curse

EmpireService

Page 25: IPC: AIDL is not a curse

EmpireService - Cont’

Page 26: IPC: AIDL is not a curse

But what if?

We want sync calls?Very fast. Like really fast!Full OOPBusiness Transparent

Page 27: IPC: AIDL is not a curse

AIDLbut … first let’s dive into Binder

Page 28: IPC: AIDL is not a curse

Binder API

Page 29: IPC: AIDL is not a curse

A long time ago in a galaxy far, far away....

Page 30: IPC: AIDL is not a curse

A new hope - Builder

Page 31: IPC: AIDL is not a curse

Steel the plans of binder

Page 32: IPC: AIDL is not a curse

A manager that can save galaxy

Page 33: IPC: AIDL is not a curse

And restore freedom to the galaxy....

Page 34: IPC: AIDL is not a curse

Now you can breath easily

we have AIDL

Page 35: IPC: AIDL is not a curse

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

.AIDL interface and result

Page 37: IPC: AIDL is not a curse

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

AIDL Data Types

All primitives and arrays of primitivesFileDescriptionSerializable/Parcelable****MapBundleListSparseArray

Page 39: IPC: AIDL is not a curse

Ladies and Gentlemen - Full

Solution

git checkout ServiceViaAIDL

Page 40: IPC: AIDL is not a curse

Sync Call - Death Star

Page 41: IPC: AIDL is not a curse

IStarWarsImplementation

Page 42: IPC: AIDL is not a curse

EmpireService

Page 43: IPC: AIDL is not a curse

DarthVaderActivity

Page 44: IPC: AIDL is not a curse

DarthVaderActivity

Page 45: IPC: AIDL is not a curse

ASync Call - Find a luke

Page 46: IPC: AIDL is not a curse

AIDL Interfaces

Page 47: IPC: AIDL is not a curse

IStarWarsImplementation

Page 48: IPC: AIDL is not a curse

DarthVaderActivity

Page 49: IPC: AIDL is not a curse

So what we got?

Services running on separate processEasy expandable communicationFun :)

Page 51: IPC: AIDL is not a curse

[email protected]+972503456408

facebook.com/levin.yonatan