Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Inter-process method invocation
           in Android

               2011.4.9


         Tetsuyuki Kobayashi

                                  1
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
                                                     2
Today's topic

   inter process communications in
    Android
   Inter process method invocation
    using Binder
   AIDL
   Example of inter process
    method invocation
                                      3
Inter Process Communication



                 Activity
      Activity              Window     Alarm
      Manager               Manager   Manager




 Kernel




                                                4
Abstraction of Inter Process
      Communication
                            More abstract
          Intent


              AIDL


                   Binder




   No need to use Binder directly.
   AIDL requires multi-thread programming
                                                      5
   In most case Intent is easy and powerful enough.
Invoking method via interface


             caller




             callee


       In the same process


                                6
Inter-process invocation

                     caller
                                interface



caller

         interface
                         How?
callee

                                interface


                     callee
                                            7
Inter-process invocation

                        caller
                                         interface


                        Proxy
caller

         interface    Binder in kernel


                     Binder Thread
callee
                          Stub
                                         interface


                        callee
                                                     8
android.os.Parcel


            Delivering arguments of method




”flatten”                                    ”unflatten”


                      transmit
                                                      9
Describing in UML ...


           <<interface>>




   Proxy                   Stub




                                  10
Describing in UML ...
                                    caller



           <<interface>>              calls


                      implements


   Proxy                   Stub

                                  extends

                           callee

                                              11
AIDL
Auto generated from .aidl file                      caller



                           <<interface>>




                   Proxy                   Stub



                                           callee

                                                             12
Use case: Who calls ”onPause”
          in Activity?
                    2:Send message     Activity
                       by Handler
                                                  3:”onPause”
                                                    is called
                  queue                Looper        in main
                                                     thread
   Activity
   Manager                               Main
                                          Main
                   Binder               Thread
                                         Thread
                    Binder
                  Thread #1
                   Thread #1




 Kernel
              1:Call ”schedulePauseActivity”
                      across process

                                                                13
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”.

                                                    14
Transaction of Binder
                          Process A and B have different memory space.
                          They can not see each other.
Kernel                         Process B
                            Process A
         Binder



                  Copy memory by copy_from _user
                  Then, wake up process B

Kernel
                                Process B
         Binder



                            Process A
                  Copy memory by copy_to_user
                                                                         15
See also
        rd

    3 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%2FAndr
   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
                                                                            16
Q&A




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

                                     17

More Related Content

Android ipm 20110409

  • 1. Inter-process method invocation in Android 2011.4.9 Tetsuyuki Kobayashi 1
  • 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 2
  • 3. Today's topic  inter process communications in Android  Inter process method invocation using Binder  AIDL  Example of inter process method invocation 3
  • 4. Inter Process Communication Activity Activity Window Alarm Manager Manager Manager Kernel 4
  • 5. Abstraction of Inter Process Communication More abstract Intent AIDL Binder No need to use Binder directly. AIDL requires multi-thread programming 5 In most case Intent is easy and powerful enough.
  • 6. Invoking method via interface caller callee In the same process 6
  • 7. Inter-process invocation caller interface caller interface How? callee interface callee 7
  • 8. Inter-process invocation caller interface Proxy caller interface Binder in kernel Binder Thread callee Stub interface callee 8
  • 9. android.os.Parcel Delivering arguments of method ”flatten” ”unflatten” transmit 9
  • 10. Describing in UML ... <<interface>> Proxy Stub 10
  • 11. Describing in UML ... caller <<interface>> calls implements Proxy Stub extends callee 11
  • 12. AIDL Auto generated from .aidl file caller <<interface>> Proxy Stub callee 12
  • 13. Use case: Who calls ”onPause” in Activity? 2:Send message Activity by Handler 3:”onPause” is called queue Looper in main thread Activity Manager Main Main Binder Thread Thread Binder Thread #1 Thread #1 Kernel 1:Call ”schedulePauseActivity” across process 13
  • 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”. 14
  • 15. Transaction of Binder Process A and B have different memory space. They can not see each other. Kernel Process B Process A Binder Copy memory by copy_from _user Then, wake up process B Kernel Process B Binder Process A Copy memory by copy_to_user 15
  • 16. See also rd  3 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%2FAndr  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 16
  • 17. Q&A Thank you for listening! Any comments to blogs are welcome. 17