android ipm 20110409

17
1 Inter-process method invocation in Android Tetsuyuki Kobayashi 2011.4.9

Upload: tetsuyuki-kobayashi

Post on 20-May-2015

13.569 views

Category:

Technology


3 download

DESCRIPTION

Inter-process method invocation using Binder in Android.

TRANSCRIPT

Page 1: Android ipm 20110409

1

Inter-process method invocationin Android

Tetsuyuki Kobayashi

2011.4.9

Page 2: Android ipm 20110409

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

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

4

ActivityManager

WindowManager

AlarmManager

Activity

Kernel

Inter Process Communication

Page 5: Android ipm 20110409

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

6

Invoking method via interface

caller

callee

In the same process

Page 7: Android ipm 20110409

7

Inter-process invocation

caller

callee

callee

caller

interface

interface

interface

How?

Page 8: Android ipm 20110409

8

Inter-process invocation

caller

callee

Binder in kernel

callee

caller

Proxy

Binder Thread

Stub

interface

interface

interface

Page 9: Android ipm 20110409

9

android.os.Parcel

”flatten” ”unflatten”

transmit

Delivering arguments of method

Page 10: Android ipm 20110409

10

<<interface>>

Proxy Stub

Describing in UML ...

Page 11: Android ipm 20110409

11

<<interface>>

Proxy Stub

Describing in UML ...caller

callee

calls

implements

extends

Page 12: Android ipm 20110409

12

<<interface>>

Proxy Stub

AIDLcaller

callee

Auto generated from .aidl file

Page 13: Android ipm 20110409

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

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

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

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

17

Q & A

Thank you for listening!Any comments to blogs are welcome.