SlideShare a Scribd company logo
Inter-process communication of Android Tetsuyuki Kobayashi 2011.6.3  updated
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)
http://kobablog.wordpress.com/ (English) Twitter @tetsu_koba new
Today's topic Inter process communications in Android
Inter process method invocation using Binder
Ashmem
System Properties
Processes running on Android $ ps ... root  37  1  248  156  c00aef2c 0000875c S /sbin/ueventd system  42  1  768  260  c022950c afd0b6fc S /system/bin/servicemanager root  43  1  3824  564  ffffffff afd0bdac S /system/bin/vold root  44  1  3796  560  ffffffff afd0bdac S /system/bin/netd root  45  1  628  264  c02588c0 afd0c0cc S /system/bin/debuggerd radio  46  1  4336  672  ffffffff afd0bdac S /system/bin/rild root  47  1  62224  27576 c00aef2c afd0b844 S zygote media  48  1  16828  3736  ffffffff afd0b6fc S /system/bin/mediaserver bluetooth 49  1  1216  572  c00aef2c afd0c59c S /system/bin/dbus-daemon root  50  1  776  316  c02a8424 afd0b45c S /system/bin/installd keystore  51  1  1704  432  c02588c0 afd0c0cc S /system/bin/keystore shell  52  1  696  336  c0050934 afd0c3ac S /system/bin/sh root  53  1  3356  160  ffffffff 00008294 S /sbin/adbd system  67  47  172464 32596 ffffffff afd0b6fc S system_server system  115  47  80028  20728 ffffffff afd0c51c S com.android.systemui app_24  124  47  80732  20720 ffffffff afd0c51c S com.android.inputmethod.latin radio  135  47  87848  20324 ffffffff afd0c51c S com.android.phone app_18  144  47  89136  24160 ffffffff afd0c51c S com.android.launcher app_7  165  47  86136  22736 ffffffff afd0c51c S android.process.acore app_0  197  47  73996  17472 ffffffff afd0c51c S com.android.deskclock app_14  208  47  75000  18464 ffffffff afd0c51c S android.process.media app_3  219  47  72228  17652 ffffffff afd0c51c S com.android.bluetooth app_25  234  47  85336  17836 ffffffff afd0c51c S com.android.mms app_26  254  47  74656  19080 ffffffff afd0c51c S com.android.email app_27  266  47  74912  18100 ffffffff afd0c51c S com.android.providers.calendar app_1  285  47  71616  16280 ffffffff afd0c51c S com.android.protips app_19  293  47  72184  16572 ffffffff afd0c51c S com.android.music app_21  301  47  74728  17208 ffffffff afd0c51c S com.android.quicksearchbox app_28  311  47  75408  18040 ffffffff afd0c51c S com.cooliris.media shell  323  52  856  316  00000000 afd0b45c R ps $ More than 30 processes (200+ threads).
Kernel Inter Process Communication
Abstraction of Inter Process Communication Binder AIDL Intent More abstract
Inter Process Communication of Android Intent The highest level abstraction Inter process method invocation AIDL: Android Interface Definition Language binder kernel driver ashmem shared memory
Intent (1) The highest level abstraction IPC in Android
Requests are queued and handled sequentially.
Powerful enough between applications
Implemented using inter process method invocation
Intent (2) Loosely coupling The sender need not choose the receiver
The sender can specify ”action”. Then proper receiver is chosen and handles it. VIEW + http://... -> Browser opens the url.
VIEW + geo:0,0?q=Tokyo -> Map app shows a map of Tokyo.
CALL + tel:01234567 -> Phone app dials the number.
Inter process method invocation used for system services
needs multi-thread programming
wrapped by AIDL to hide complexity
implemented using binder
Invoking method via interface In the same process
Inter-process invocation interface interface interface How?
Inter-process invocation Binder Thread interface interface interface
android.os.Parcel ” flatten” ” unflatten” transmit Delivering arguments of method
Describing in UML ... implements

More Related Content

PDF
Embedded Android : System Development - Part IV (Android System Services)
PPTX
Overview of Android binder IPC implementation
PPTX
Binder: Android IPC
PDF
Low Level View of Android System Architecture
PDF
Understanding the Android System Server
PDF
Inside Android's UI
PDF
Android Internals
PDF
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part IV (Android System Services)
Overview of Android binder IPC implementation
Binder: Android IPC
Low Level View of Android System Architecture
Understanding the Android System Server
Inside Android's UI
Android Internals
Embedded Android : System Development - Part II (HAL)

What's hot (20)

PDF
Android Things : Building Embedded Devices
PDF
Android Binder IPC for Linux
PDF
Design and Concepts of Android Graphics
PPTX
Android Binder: Deep Dive
PPTX
Android Booting Sequence
PDF
Embedded Android : System Development - Part I
PDF
Understanding binder in android
PPT
Learning AOSP - Android Linux Device Driver
ODP
Embedded Android : System Development - Part III
PDF
Android device driver structure introduction
PDF
Android IPC Mechanism
PDF
Introduction to Android Window System
PPTX
Android+init+process
PDF
The Android graphics path, in depth
PPTX
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
PDF
Explore Android Internals
PDF
Aosp+
PDF
Android OS Porting: Introduction
PDF
Android binder introduction
Android Things : Building Embedded Devices
Android Binder IPC for Linux
Design and Concepts of Android Graphics
Android Binder: Deep Dive
Android Booting Sequence
Embedded Android : System Development - Part I
Understanding binder in android
Learning AOSP - Android Linux Device Driver
Embedded Android : System Development - Part III
Android device driver structure introduction
Android IPC Mechanism
Introduction to Android Window System
Android+init+process
The Android graphics path, in depth
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Explore Android Internals
Aosp+
Android OS Porting: Introduction
Android binder introduction
Ad

Viewers also liked (20)

PDF
Android binder-ipc
PDF
Binderのはじめの一歩とAndroid
PDF
Android起動周りのノウハウ
PDF
Etsy - Android & Design
PDF
Advanced Android Design Implementation
PDF
June 2014 - IPC in android
PDF
Binderのはじめの一歩
PDF
Android local sockets in native code
PDF
AIDL - Android Interface Definition Language
PPTX
Inter Process Communication-R.D.Sivakumar
PPTX
Permission use analysis for vetting undesirable behavior in
PPTX
Java & The Android Stack: A Security Analysis
PPTX
Intents and PendingIntents in Android application development
PPTX
Understanding open max il
PDF
Android Material Design APIs/Tips
PDF
Android Crash analysis and The Dalvik Garbage collector – Tools and Tips
PPTX
Desgn&imp authentctn.ppt by Jaseela
PPTX
Inter process communication
PDF
Manipulating Android tasks and back stack
PDF
Inter process communication using Linux System Calls
Android binder-ipc
Binderのはじめの一歩とAndroid
Android起動周りのノウハウ
Etsy - Android & Design
Advanced Android Design Implementation
June 2014 - IPC in android
Binderのはじめの一歩
Android local sockets in native code
AIDL - Android Interface Definition Language
Inter Process Communication-R.D.Sivakumar
Permission use analysis for vetting undesirable behavior in
Java & The Android Stack: A Security Analysis
Intents and PendingIntents in Android application development
Understanding open max il
Android Material Design APIs/Tips
Android Crash analysis and The Dalvik Garbage collector – Tools and Tips
Desgn&imp authentctn.ppt by Jaseela
Inter process communication
Manipulating Android tasks and back stack
Inter process communication using Linux System Calls
Ad

Similar to Inter-process communication of Android (20)

PDF
Android Internals
PDF
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
PDF
Android is NOT just 'Java on Linux'
PDF
Android Internals at Linaro Connect Asia 2013
PDF
Headless Android at AnDevCon3
PDF
Reusing your existing software on Android
PDF
Discover System Facilities inside Your Android Phone
PDF
Binding android piece by piece
PDF
Android for Embedded Linux Developers
ODP
Android crash debugging
PDF
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
PDF
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
PDF
Android Attacks
PDF
Applied Computer Science Concepts in Android
PDF
Android memory analysis Debug slides.pdf
PDF
Embedded Android
PDF
PDF
Leveraging Android's Linux Heritage at ELC-E 2011
PDF
Jaime Blasco & Pablo Rincón - Lost in translation: WTF is happening inside m...
PDF
Wtf is happening_inside_my_android_phone_public
Android Internals
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Android is NOT just 'Java on Linux'
Android Internals at Linaro Connect Asia 2013
Headless Android at AnDevCon3
Reusing your existing software on Android
Discover System Facilities inside Your Android Phone
Binding android piece by piece
Android for Embedded Linux Developers
Android crash debugging
Bringing up Android on your favorite X86 Workstation or VM (AnDevCon Boston, ...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Android Attacks
Applied Computer Science Concepts in Android
Android memory analysis Debug slides.pdf
Embedded Android
Leveraging Android's Linux Heritage at ELC-E 2011
Jaime Blasco & Pablo Rincón - Lost in translation: WTF is happening inside m...
Wtf is happening_inside_my_android_phone_public

More from Tetsuyuki Kobayashi (20)

PDF
some topic of ffmpeg
PDF
New VIdeo CODEC AV1
PDF
Try new transport protocol SRT (ver. 2)
PDF
Try new transport protocol SRT
PDF
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
PDF
WebOS Open Source Edition を試してみた
PDF
Linuxのユーザーランドをinitから全てまるごとgolangで書く
PDF
組み込みLinuxでのGolangのススメ(Go con版)
PDF
組み込みLinuxでのGolangのススメ
PDF
Tricky implementation of Go ARM soft float
PDF
ARM 64bit has come!
PDF
Virtual memory 20070222-en
PDF
Simple and efficient way to get the last log using MMAP
PDF
Tips of Malloc & Free
PDF
Basic of virtual memory of Linux
PDF
PDF
ADB(Android Debug Bridge): How it works?
PDF
Tweaking Google TV emulator
PDF
Android ipm 20110409
PDF
Init of Android
some topic of ffmpeg
New VIdeo CODEC AV1
Try new transport protocol SRT (ver. 2)
Try new transport protocol SRT
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
WebOS Open Source Edition を試してみた
Linuxのユーザーランドをinitから全てまるごとgolangで書く
組み込みLinuxでのGolangのススメ(Go con版)
組み込みLinuxでのGolangのススメ
Tricky implementation of Go ARM soft float
ARM 64bit has come!
Virtual memory 20070222-en
Simple and efficient way to get the last log using MMAP
Tips of Malloc & Free
Basic of virtual memory of Linux
ADB(Android Debug Bridge): How it works?
Tweaking Google TV emulator
Android ipm 20110409
Init of Android

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Machine learning based COVID-19 study performance prediction
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
Teaching material agriculture food technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PDF
Approach and Philosophy of On baking technology
PPTX
Cloud computing and distributed systems.
PDF
KodekX | Application Modernization Development
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Mobile App Security Testing_ A Comprehensive Guide.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Big Data Technologies - Introduction.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Machine learning based COVID-19 study performance prediction
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Empathic Computing: Creating Shared Understanding
Digital-Transformation-Roadmap-for-Companies.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Teaching material agriculture food technology
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
Approach and Philosophy of On baking technology
Cloud computing and distributed systems.
KodekX | Application Modernization Development
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx

Inter-process communication of Android

  • 1. Inter-process communication of Android Tetsuyuki Kobayashi 2011.6.3 updated
  • 2. Who am I? 20+ years involved in embedded systems 10 years in real time OS, such as iTRON
  • 3. 10 years in embedded Java Virtual Machine
  • 4. Now GCC, Linux, QEMU, Android, … Blogs http://d.hatena.ne.jp/embedded/ (Personal)
  • 7. Today's topic Inter process communications in Android
  • 8. Inter process method invocation using Binder
  • 11. Processes running on Android $ ps ... root 37 1 248 156 c00aef2c 0000875c S /sbin/ueventd system 42 1 768 260 c022950c afd0b6fc S /system/bin/servicemanager root 43 1 3824 564 ffffffff afd0bdac S /system/bin/vold root 44 1 3796 560 ffffffff afd0bdac S /system/bin/netd root 45 1 628 264 c02588c0 afd0c0cc S /system/bin/debuggerd radio 46 1 4336 672 ffffffff afd0bdac S /system/bin/rild root 47 1 62224 27576 c00aef2c afd0b844 S zygote media 48 1 16828 3736 ffffffff afd0b6fc S /system/bin/mediaserver bluetooth 49 1 1216 572 c00aef2c afd0c59c S /system/bin/dbus-daemon root 50 1 776 316 c02a8424 afd0b45c S /system/bin/installd keystore 51 1 1704 432 c02588c0 afd0c0cc S /system/bin/keystore shell 52 1 696 336 c0050934 afd0c3ac S /system/bin/sh root 53 1 3356 160 ffffffff 00008294 S /sbin/adbd system 67 47 172464 32596 ffffffff afd0b6fc S system_server system 115 47 80028 20728 ffffffff afd0c51c S com.android.systemui app_24 124 47 80732 20720 ffffffff afd0c51c S com.android.inputmethod.latin radio 135 47 87848 20324 ffffffff afd0c51c S com.android.phone app_18 144 47 89136 24160 ffffffff afd0c51c S com.android.launcher app_7 165 47 86136 22736 ffffffff afd0c51c S android.process.acore app_0 197 47 73996 17472 ffffffff afd0c51c S com.android.deskclock app_14 208 47 75000 18464 ffffffff afd0c51c S android.process.media app_3 219 47 72228 17652 ffffffff afd0c51c S com.android.bluetooth app_25 234 47 85336 17836 ffffffff afd0c51c S com.android.mms app_26 254 47 74656 19080 ffffffff afd0c51c S com.android.email app_27 266 47 74912 18100 ffffffff afd0c51c S com.android.providers.calendar app_1 285 47 71616 16280 ffffffff afd0c51c S com.android.protips app_19 293 47 72184 16572 ffffffff afd0c51c S com.android.music app_21 301 47 74728 17208 ffffffff afd0c51c S com.android.quicksearchbox app_28 311 47 75408 18040 ffffffff afd0c51c S com.cooliris.media shell 323 52 856 316 00000000 afd0b45c R ps $ More than 30 processes (200+ threads).
  • 12. Kernel Inter Process Communication
  • 13. Abstraction of Inter Process Communication Binder AIDL Intent More abstract
  • 14. Inter Process Communication of Android Intent The highest level abstraction Inter process method invocation AIDL: Android Interface Definition Language binder kernel driver ashmem shared memory
  • 15. Intent (1) The highest level abstraction IPC in Android
  • 16. Requests are queued and handled sequentially.
  • 17. Powerful enough between applications
  • 18. Implemented using inter process method invocation
  • 19. Intent (2) Loosely coupling The sender need not choose the receiver
  • 20. The sender can specify ”action”. Then proper receiver is chosen and handles it. VIEW + http://... -> Browser opens the url.
  • 21. VIEW + geo:0,0?q=Tokyo -> Map app shows a map of Tokyo.
  • 22. CALL + tel:01234567 -> Phone app dials the number.
  • 23. Inter process method invocation used for system services
  • 25. wrapped by AIDL to hide complexity
  • 27. Invoking method via interface In the same process
  • 28. Inter-process invocation interface interface interface How?
  • 29. Inter-process invocation Binder Thread interface interface interface
  • 30. android.os.Parcel ” flatten” ” unflatten” transmit Delivering arguments of method
  • 31. Describing in UML ... implements
  • 32. Describing in UML ... calls implements extends
  • 33. AIDL Auto generated from .aidl file
  • 34. Kernel Use case: Who calls ”onPause” in Activity? Activity queue 3:”onPause” is called in main thread 1:Call ”schedulePauseActivity” across process 2:Send message by Handler
  • 36. Not for general purpose. Tuned for specific transaction.
  • 37. Multi-thread aware Have internal status per thead
  • 38. (CF. Socket have internal status per fd.)
  • 39. Comparing binder with socket socket binder internal status associated to FD associated to PID (FD can be shared among threads in the same process) read & write operation as a stream done at once by ”ioctl” network transparency Yes No expects local only
  • 40. Transaction of Binder (1) if ( ioctl (fd, BINDER_WRITE_READ, &bwt ) >= 0) err = NO_ERROR; else err = -errno; write_size write_consumed write_buffer read_size read_consumed read_buffer binder_write_read
  • 41. Transaction of Binder (2) Process A Process B Binder Process A Binder Process 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
  • 42. Ashmem Android / Anonymous SHared MEMory subsystem $(ANDROID_TOP)/system/core/cutils/ashmem.h int ashmem_create_region(const char *name, size_t size) -> returns fd
  • 44. int ashmem_pin_region(int fd, size_t offset, size_t len)
  • 45. int ashmem_unpin_region(int fd, size_t offset, size_t len) kernel reclaim not ‘pin’ ed memory
  • 46. Similar to weak reference of Java. useful to implement cache.
  • 48. System Properties of Android 'Key-Value store' type data base for basic system information.
  • 49. Shared among all processes.
  • 50. Init process has the master data.
  • 51. The other processes have read-only copy.
  • 52. Init process handles write request to the master data.
  • 53. implemented using ashmem before Gingerbread.
  • 54. At Gingerbread changed not to use ashmem.
  • 55. Example of System Properties ... [ro.bt.bdaddr_path]: [/sys/module/board_mahimahi/parameters/bdaddr] [ro.ril.def.agps.mode]: [2] [ro.ril.fast.dormancy.rule]: [1] [ro.ril.fd.scron.timeout]: [4] [ro.ril.fd.scroff.timeout]: [3] [ro.ril.gprsclass]: [10] [init.svc.adbd]: [running] [ril.reload.count]: [1] [init.svc.bootanim]: [stopped] [hw.keyboards.0.devname]: [mahimahi-keypad] [hw.keyboards.65537.devname]: [mahimahi-keypad] [hw.keyboards.131075.devname]: [h2w headset] [net.hostname]: [android_200142d4dfd0d25c] [dev.bootcomplete]: [1] [gsm.version.ril-impl]: [HTC-RIL 2.2.1001G (Jul 16 2010,21:52:13)] [gsm.sim.operator.numeric]: [] [gsm.sim.operator.alpha]: [] [gsm.sim.operator.iso-country]: [] [gsm.sim.state]: [ABSENT] [gsm.current.phone-type]: [1] [wlan.driver.status]: [ok] [init.svc.wpa_supplicant]: [running] ...
  • 56. Special Key of System Properties Starts from ”ro.” is read-only.
  • 57. ” ctl.start” / ”ctl.stop” is command to start/stop the service. property_set("ctl.stop", "bootanim"); stops boot animation service Starts from ”init.svc.” shows the state of the service.
  • 58. Reading System Property Kernel init Other processes /dev/__properties__ (on tmpfs) mmap (read/write) mmap (read only) Just read the property in each process.
  • 59. Writing System Property Kernel init Other processes /dev/__properties__ (on tmpfs) mmap (read/write) mmap (read only) Send write request to init through socket
  • 60. Actual code of initialize System Properties fd = open (&quot;/dev/__properties__&quot;, O_RDWR | O_CREAT, 0600); if (fd < 0) return -1; if ( ftruncate (fd, size) < 0) goto out; data = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if(data == MAP_FAILED) goto out; close (fd); fd = open (&quot;/dev/__properties__&quot;, O_RDONLY); if (fd < 0) return -1; unlink (&quot;/dev/__properties__&quot;); $(ANDROID_TOP)/system/core/init/property_service.c Give this fd to other processes. No longer access by file name. /dev is a tmpfs
  • 61. Resources 3 rd session of Yokohama Android Platform club http://www.yokohama.android-pf.org/study/dai-san-kai-benkyou-kai 1 st 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
  • 67. Q&A and demo http://www.kmckk.co.jp/eng/kzma9/ http://www.kmckk.co.jp/eng/jet_index.html