android ipm 20110409
DESCRIPTION
Inter-process method invocation using Binder in Android.TRANSCRIPT
![Page 1: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/1.jpg)
1
Inter-process method invocationin Android
Tetsuyuki Kobayashi
2011.4.9
![Page 2: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/2.jpg)
2
Who am I?
20+ years involved in embedded systems 10 years in real time OS, such as iTRON 10 years in embedded Java Virtual Machine Now GCC, Linux, QEMU, Android, …
Blogs http://d.hatena.ne.jp/embedded/ (Personal) http://blog.kmckk.com/ (Corporate)
Twitter @tetsu_koba
![Page 3: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/3.jpg)
3
Today's topic
inter process communications in Android
Inter process method invocation using Binder
AIDL Example of inter process
method invocation
![Page 4: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/4.jpg)
4
ActivityManager
WindowManager
AlarmManager
Activity
Kernel
Inter Process Communication
![Page 5: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/5.jpg)
5
Abstraction of Inter Process Communication
Binder
AIDL
Intent
No need to use Binder directly.AIDL requires multi-thread programmingIn most case Intent is easy and powerful enough.
More abstract
![Page 6: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/6.jpg)
6
Invoking method via interface
caller
callee
In the same process
![Page 7: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/7.jpg)
7
Inter-process invocation
caller
callee
callee
caller
interface
interface
interface
How?
![Page 8: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/8.jpg)
8
Inter-process invocation
caller
callee
Binder in kernel
callee
caller
Proxy
Binder Thread
Stub
interface
interface
interface
![Page 9: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/9.jpg)
9
android.os.Parcel
”flatten” ”unflatten”
transmit
Delivering arguments of method
![Page 10: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/10.jpg)
10
<<interface>>
Proxy Stub
Describing in UML ...
![Page 11: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/11.jpg)
11
<<interface>>
Proxy Stub
Describing in UML ...caller
callee
calls
implements
extends
![Page 12: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/12.jpg)
12
<<interface>>
Proxy Stub
AIDLcaller
callee
Auto generated from .aidl file
![Page 13: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/13.jpg)
13
ActivityManager
Kernel
Binder Thread #1Binder
Thread #1
Main ThreadMain
Thread
Looperqueue
3:”onPause”is called in mainthread
1:Call ”schedulePauseActivity”across process
Use case: Who calls ”onPause” in Activity?
2:Send messageby Handler
Activity
![Page 14: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/14.jpg)
14
Binder
/etc/binder Not for general purpose. Tuned for specific
transaction. Multi-thread aware
Have internal data per thead (CF. Socket have internal data per fd.)
Not use ”write” and ”read”. Write and read at once by ”ioctl”.
![Page 15: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/15.jpg)
15
Transaction of Binder
Process AProcess B
Binder
Process A
BinderProcess B
Copy memory by copy_from _user
Copy memory by copy_to_user
Then, wake up process B
Process A and B have different memory space.They can not see each other.
Kernel
Kernel
![Page 16: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/16.jpg)
16
See also 3rd session of Yokohama Android Platform club
http://www.yokohama.android-pf.org/study/dai-san-kai-benkyou-kai
1st session of Android SDK work group http://www.android-group.jp/index.php?%CA%D9%B6%AF%B2%F1%2FAndroid ...
KMC blog http://blog.kmckk.com/archives/3611344.html http://blog.kmckk.com/archives/3613707.html http://blog.kmckk.com/archives/3627888.html http://blog.kmckk.com/archives/3645070.html http://blog.kmckk.com/archives/3647635.html http://blog.kmckk.com/archives/3617229.html
![Page 17: Android ipm 20110409](https://reader036.vdocuments.site/reader036/viewer/2022080210/555c439cd8b42a2c068b4f24/html5/thumbnails/17.jpg)
17
Q & A
Thank you for listening!Any comments to blogs are welcome.