June 2014 - IPC in android
-
Upload
blrdroid -
Category
Technology
-
view
423 -
download
7
description
Transcript of June 2014 - IPC in android
![Page 1: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/1.jpg)
IPC in Apps - AndroidLohith
Founder and CTO, Fairket
![Page 2: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/2.jpg)
Basics➔ Default - Each App runs on its own process
◆ Stability, Security, Memory
➔ App can run in two or more process and vice versa
➔ Default - <activity>, <service>, <receiver> and
<provider> run in same process
➔ All communication happen on the Looper (Main) thread
by default
![Page 3: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/3.jpg)
Examples of IPC
➔ Access to Android services like:
◆ Camera, ActivityManager, DownloadManager, Media
etc
➔ External Examples
◆ Google IAP
◆ License Verification Library
![Page 4: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/4.jpg)
IPC Example - Google IAP
App 1
IAB SDK
App n
IAB SDK
GooglePlay Services
IPC
IPCR
emo
te S
ervi
ce Google IAP Cloud
Net
wo
rk In
terf
ace
![Page 5: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/5.jpg)
Android IPC Mechanisms
➔ Using intents
➔ Using services
➔ Using messenger and binder interfaces
➔ Using broadcast receivers
“Underneath all IPC mechanisms use Android IPC Binder”
![Page 6: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/6.jpg)
What is Binder?Android specific IPC mechanism based on shared memory
![Page 7: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/7.jpg)
Why Binder?
➔ Enables RPC style IPC calls
➔ Synchronous and Asynchronous (oneway) model
➔ Security - Receiver can recognize the sender (uid/pid)
➔ Simple Interface Definition Language (AIDL)
➔ Suitable for Android’s hostile environment
➔ Marshalling and Unmarshalling
➔ Local Execution Model
![Page 8: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/8.jpg)
Messenger IPC
➔ Message based communication across process
➔ Client - Implements Handler to receive messages
➔ Service - Uses Messenger to send notification to client
➔ Asynchronous like Intent but lower latency and overhead
➔ Ideal for receiving call-backs from service to client
➔ All underlying communication still uses Binder!
![Page 9: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/9.jpg)
Messenger IPC - Limitations
➔ Only supports Asynchronous
➔ No support for multithreaded IPC
➔ No Interface Definition Language
![Page 10: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/10.jpg)
Binder Interface IPC - 1
➔ RPC kind of API call
➔ Supports Synchronous and Asynchronous calls
➔ Supports multithreaded IPC calls
➔ Facilitated by Remote Service
➔ Interface defined through AIDL
![Page 11: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/11.jpg)
Binder Interface IPC - 2
![Page 12: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/12.jpg)
AIDL➔ AIDL follows Java like syntax
➔ Used both by client and service - Generates Proxy and
Stub
➔ AIDL supports Java basic types, array, list and custom data types
➔ Custom data type needs to have an AIDL file of its own
➔ Specify the direction tag for custom data types - in, out, inout
![Page 13: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/13.jpg)
AIDL Example
![Page 14: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/14.jpg)
Limitations of Binder➔ Maximum of 15 IPC binder threads
➔ No blocking operation - Same restriction as Looper Main
thread
➔ No support to remote calls - Local to device
➔ Limits the transactional buffer to 1 Mb per process
![Page 15: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/15.jpg)
Do’s and Don'ts - 1
➔ Don't use traditional Linux IPC technique like network
sockets, pipes, shared files etc
➔ Security - Use relevant permission declaration on
<service>
➔ Mark android:exported as “false” if <service> is not to be
exposed
➔ Protect each IPC call by calling checkCallingPermission
![Page 16: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/16.jpg)
Do’s and Don'ts - 2
➔ Use bound services - Bind/Unbind as required
➔ Don't start a service unless really required
➔ onStart/onStop is good place to connect/disconnect to a
service
➔ Use the AIDL direction tag judiciously
➔ Mark AIDL callback interface as one way
➔ Don’t send too much data over IPC
![Page 17: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/17.jpg)
Additional References
➔ Android Binder on elinux.org
➔ Android Binder by Thorsten Schrieber from Ruhr-
Universitat Bochum
➔ Deep Dive into Android Binder by Aleksandar Gargenta
![Page 18: June 2014 - IPC in android](https://reader034.fdocuments.in/reader034/viewer/2022042714/55511785b4c905f10b8b4f42/html5/thumbnails/18.jpg)
Questions?Thank you for your patience!
http://www.fairket.com/