Android Architecture
Agenda●   Linux Kernel●   Native Libraries●   Android Runtime●   Application Framework●   Inside The System    Connectivit...
Android System Architecture
Agenda●   Linux Kernel●   Native Libraries●   Android Runtime●   Application Framework●   Inside The System    Connectivit...
Linux Kernel● Android is built on the Linux kernel, but  Android is not Linux● No native windowing system● Does not includ...
Why Linux Kernel?●   Great memory and process management●   Permissions-based security model●   Proven driver model●   Sup...
Kernel Enhancements• Binder• Power Management
Binder: Problem● Applications and Services may run in separate  processes but must communicate and share  data● IPC can in...
Binder: Solution● Driver to facilitate inter-process communication  (IPC)● High performance through shared memory● Per-pro...
Binder in Action
Binder in Action
Binder in Action
Binder in Action
Binder in Action
Binder in Action
Binder in Action
BinderAndroid Interface Definition Language (AIDL)http://developer.android.com/guide/components/aidl.html
PM Problem● Mobile devices run on battery power● Batteries have limited capacity
PM Solution● Built on top of standard Linux Power  Management (PM)● More aggressive power management policy● Components ma...
Android PM in Action
Android PM in Action
Android PM in Action
Android PM in Action
Android PM in Action
Android PM in Action
Android PM● Use wake locks carefully!● sysfs entries for wakelocks in android  "/sys/power/wake_lock",  "/sys/power/wake_u...
KernelDownload and Build android kernel from:http://source.android.com/source/building-kernels.html
Agenda●   Linux Kernel●   Native Libraries●   Android Runtime●   Application Framework●   Inside The System    Connectivit...
Native Libraries
Native Libraries●   Bionic Libc●   Function Libraries●   Native Servers●   Hardware Abstraction Libraries
Native Libraries●   Bionic Libc●   Function Libraries●   Native Servers●   Hardware Abstraction Libraries
What is Bionic?● What is bionic?  Custom libc implementation, optimized for  embedded use.
What is Bionic?Why build a custom libc library?● License: we want to keep GPL out of user-  space● Size: will load in each...
Bionic libc● BSD License● Small size and fast code paths● Very fast and small custom pthread  implementation
Bionic libc● Built-in support for important Android-  specific services  a. system properties     getprop(“my.system.prope...
Native Libraries●   Bionic Libc●   Function Libraries●   Native Servers●   Hardware Abstraction Libraries
WebKit● Based on open source WebKit browser: http:  //webkit.org● Renders pages in full (desktop) view● Full CSS, Javascri...
Media Framework● Based on PacketVideo OpenCORE platform● Supports standard video, audio, still-frame  formats● Support for...
SQLite● Light-weight transactional data store● Back end for most platform data storage
Native Libraries●   Bionic Libc●   Function Libraries●   Native Servers●   Hardware Abstraction Libraries
Surface Flinger● Provides system-wide surface “composer”, handling all    surface rendering to frame buffer device●   Can ...
Surface Manager● Surfaces passed as buffers via Binder IPC  calls● Can use OpenGL ES and 2D hardware  accelerator for its ...
Audio Flinger● Manages all audio output devices● Processes multiple audio streams into PCM audio out    paths●   Handles a...
Native Libraries●   Bionic Libc●   Function Libraries●   Native Servers●   Hardware Abstraction Libraries
Hardware Abstraction Layer
Hardware Abstraction Libraries● Why do we need a user-space HAL?  ○ Not all components have standardized kernel driver    ...
Hardware Abstraction Libraries● Libraries are loaded dynamically at runtime  as needed  QualcommCameraHardware.cpp  ...  l...
Agenda●   Linux Kernel●   Native Libraries●   Android Runtime●   Application Framework●   Inside The System    Connectivit...
Android Runtime
What is the Dalvik VM?● Androids custom clean-room  implementation virtual machine● run on a slow CPU● with relatively lit...
Dalvik Virtual Machine● Provides application portability and runtime  consistency● Runs optimized file format (.dex) and D...
Core Libraries● Core APIs for Java language provide a  powerful, yet simple and familiar development  platform  ○   Data s...
.dex file
.jar Vs .dex
.class files
.dex file
Agenda●   Linux Kernel●   Native Libraries●   Android Runtime●   Application Framework●   Inside The System    Connectivit...
Application Framework
Core Platform Services● Services that are essential to the Android  platform● Behind the scenes - applications typically  ...
Core Platform Services● Activity Manager
Core Platform Services● Activity Manager● Package Manager
Core Platform Services● Activity Manager● Package Manager● Window Manager
Core Platform Services●   Activity Manager●   Package Manager●   Window Manager●   Resource Manager
Core Platform Services●   Activity Manager●   Package Manager●   Window Manager●   Resource Manager●   Content Providers
Core Platform Services●   Activity Manager●   Package Manager●   Window Manager●   Resource Manager●   Content Providers● ...
Hardware Services● Provide access to lower-level hardware APIs● Typically accessed through local Manager  object  Location...
Hardware Services● Telephony Service
Hardware Services● Telephony Service● Location Service
Hardware Services● Telephony Service● Location Service● Bluetooth Service
Hardware Services●   Telephony Service●   Location Service●   Bluetooth Service●   WiFi Service
Hardware Services●   Telephony Service●   Location Service●   Bluetooth Service●   WiFi Service●   USB Service
Hardware Services●   Telephony Service●   Location Service●   Bluetooth Service●   WiFi Service●   USB Service●   Sensor S...
Android System
Agenda●   Linux Kernel●   Native Libraries●   Android Runtime●   Application Framework●   Inside The System    Connectivit...
Inside The System● Connectivity  ○ Bluetooth  ○ WiFi● Power Management● Display & Multimedia  ○ Display Subsystem  ○ Audio...
Connectivity● Bluetooth● Wi-Fi
BluetoothNote: Android 4.2 introduces a new Bluetooth stack optimized for use withAndroid devices. The new Bluetooth stack...
Wi-Fi● Android uses wpa_supplicant as the platform  interface to the Wi-Fi device.● Your Wi-Fi driver must be compatible w...
Wi-Fi
Inside The System● Connectivity  ○ Bluetooth  ○ WiFi● Power Management● Display & Multimedia  ○ Display Subsystem  ○ Audio...
Power Management
Inside The System● Connectivity  ○ Bluetooth  ○ WiFi● Power Management● Display & Multimedia  ○ Display Subsystem  ○ Audio...
Display & Multimedia● Display Subsystem● Audio Subsystem● Camera/Video Subsystem
Display Subsystem
Audio Subsystem
Camera/Video Subsystem
Android Multimedia Framework
Inside The System● Connectivity  ○ Bluetooth  ○ WiFi● Power Management● Display & Multimedia  ○ Display Subsystem  ○ Audio...
Telephony● Radio Interface Layer  Androids Radio Interface Layer (RIL) provides an  abstraction layer between Android tele...
Radio Interface Layer
Agenda●   Linux Kernel●   Native Libraries●   Android Runtime●   Application Framework●   Inside The System    Connectivit...
Runtime WalkthroughIt all starts with init…Similar to most Linux-based systems at startup,the bootloader loads the Linux k...
Runtime Walkthrough● Init starts Linux daemons, including:   ○ USB Daemon (usbd) to manage USB connections   ○ Android Deb...
Runtime Walkthrough● Init process starts the zygote process:   ○ A nascent process which initializes a Dalvik VM instance ...
Runtime Walkthrough● Init starts runtime process:   ○ Initializes Service Manager – the context manager for Binder that   ...
Runtime Walkthrough● Runtime process sends request for Zygote to start  System Service
Runtime Walkthrough● Runtime process sends request for Zygote to start  System Server  ○ Zygote forks a new VM instance fo...
Runtime Walkthrough● System Service starts the native system servers,  including:   ○   Surface Flinger   ○   Audio Flinger
Runtime Walkthrough● Native system servers register with Service Manager as  IPC service targets:
Runtime Walkthrough● System Service starts the Android managed services:
Runtime Walkthrough● Android managed Services register with Service  Manager:
Runtime Walkthrough
Runtime WalkthroughAfter system server loads all services, the system isready…
Runtime WalkthroughAfter system server loads all services, the system isready…
Runtime WalkthroughAfter system server loads all services, the system isready…
Runtime WalkthroughEach subsequent application is launched in its ownprocess
Agenda●   Linux Kernel●   Native Libraries●   Android Runtime●   Application Framework●   Inside The System    Connectivit...
Layer InteractionThere are 3 main flavors of Android layer cake:  ○ App   Runtime Service   lib  ○ App   Runtime Service  ...
Layer InteractionThere are 3 main flavors of Android layer cake:  ○ App   Runtime Service   lib  ○ App   Runtime Service  ...
Android Runtime Services
Android Runtime Services
Android Runtime Services
Android Runtime Services
Example: Location Manager
Layer InteractionThere are 3 main flavors of Android layer cake:  ○ App   Runtime Service   lib  ○ App   Runtime Service  ...
Android Native Services
Android Native Services
Android Native Services
Android Native Services
Android Native Services
Android Native Services
Android Native Services
Layer InteractionThere are 3 main flavors of Android layer cake:  ○ App   Runtime Service   lib  ○ App   Runtime Service  ...
Daemon Connection
Daemon Connection
Daemon Connection
Daemon Connection
Questions
Upcoming SlideShare
Loading in...5
×

Android presentation

1,735

Published on

0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,735
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
132
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

Android presentation

  1. 1. Android Architecture
  2. 2. Agenda● Linux Kernel● Native Libraries● Android Runtime● Application Framework● Inside The System Connectivity(Bluetooth,WiFi...) Power Management Display & Multimedia (Surfaceflinger, Audioflinger,Camera/Video) Telephony (Radio Interface Layer)● Android Boot sequence● Layer Interaction
  3. 3. Android System Architecture
  4. 4. Agenda● Linux Kernel● Native Libraries● Android Runtime● Application Framework● Inside The System Connectivity(Bluetooth,WiFi...) Power Management Display & Multimedia (Surfaceflinger, Audioflinger,Camera/Video) Telephony (Radio Interface Layer)● Android Boot sequence● Layer Interaction
  5. 5. Linux Kernel● Android is built on the Linux kernel, but Android is not Linux● No native windowing system● Does not include the full set of standard Linux utilities● Patch of “kernel enhancements” to support Android
  6. 6. Why Linux Kernel?● Great memory and process management● Permissions-based security model● Proven driver model● Support for shared libraries● Its already open source!
  7. 7. Kernel Enhancements• Binder• Power Management
  8. 8. Binder: Problem● Applications and Services may run in separate processes but must communicate and share data● IPC can introduce significant processing overhead and security holes
  9. 9. Binder: Solution● Driver to facilitate inter-process communication (IPC)● High performance through shared memory● Per-process thread pool for processing requests● Reference counting, and mapping of object references across processes● Synchronous calls between processes
  10. 10. Binder in Action
  11. 11. Binder in Action
  12. 12. Binder in Action
  13. 13. Binder in Action
  14. 14. Binder in Action
  15. 15. Binder in Action
  16. 16. Binder in Action
  17. 17. BinderAndroid Interface Definition Language (AIDL)http://developer.android.com/guide/components/aidl.html
  18. 18. PM Problem● Mobile devices run on battery power● Batteries have limited capacity
  19. 19. PM Solution● Built on top of standard Linux Power Management (PM)● More aggressive power management policy● Components make requests to keep the power on through “wake locks”● Supports different types of wake locks
  20. 20. Android PM in Action
  21. 21. Android PM in Action
  22. 22. Android PM in Action
  23. 23. Android PM in Action
  24. 24. Android PM in Action
  25. 25. Android PM in Action
  26. 26. Android PM● Use wake locks carefully!● sysfs entries for wakelocks in android "/sys/power/wake_lock", "/sys/power/wake_unlock", "/sys/power/state"
  27. 27. KernelDownload and Build android kernel from:http://source.android.com/source/building-kernels.html
  28. 28. Agenda● Linux Kernel● Native Libraries● Android Runtime● Application Framework● Inside The System Connectivity(Bluetooth,WiFi...) Power Management Display & Multimedia (Surfaceflinger, Audioflinger,Camera/Video) Telephony (Radio Interface Layer)● Android Boot sequence● Layer Interaction
  29. 29. Native Libraries
  30. 30. Native Libraries● Bionic Libc● Function Libraries● Native Servers● Hardware Abstraction Libraries
  31. 31. Native Libraries● Bionic Libc● Function Libraries● Native Servers● Hardware Abstraction Libraries
  32. 32. What is Bionic?● What is bionic? Custom libc implementation, optimized for embedded use.
  33. 33. What is Bionic?Why build a custom libc library?● License: we want to keep GPL out of user- space● Size: will load in each process, so it needs to be small● Fast: limited CPU power means we need to be fast
  34. 34. Bionic libc● BSD License● Small size and fast code paths● Very fast and small custom pthread implementation
  35. 35. Bionic libc● Built-in support for important Android- specific services a. system properties getprop(“my.system.property”, buff, default); b. log capabilities LOGI(“Logging a message with priority ‘Info’”);
  36. 36. Native Libraries● Bionic Libc● Function Libraries● Native Servers● Hardware Abstraction Libraries
  37. 37. WebKit● Based on open source WebKit browser: http: //webkit.org● Renders pages in full (desktop) view● Full CSS, Javascript, DOM, AJAX support● Support for single-column and adaptive view rendering
  38. 38. Media Framework● Based on PacketVideo OpenCORE platform● Supports standard video, audio, still-frame formats● Support for hardware / software codec plug- ins
  39. 39. SQLite● Light-weight transactional data store● Back end for most platform data storage
  40. 40. Native Libraries● Bionic Libc● Function Libraries● Native Servers● Hardware Abstraction Libraries
  41. 41. Surface Flinger● Provides system-wide surface “composer”, handling all surface rendering to frame buffer device● Can combine 2D and 3D surfaces and surfaces from multiple applications
  42. 42. Surface Manager● Surfaces passed as buffers via Binder IPC calls● Can use OpenGL ES and 2D hardware accelerator for its compositions● Double-buffering using page-flip
  43. 43. Audio Flinger● Manages all audio output devices● Processes multiple audio streams into PCM audio out paths● Handles audio routing to various outputs
  44. 44. Native Libraries● Bionic Libc● Function Libraries● Native Servers● Hardware Abstraction Libraries
  45. 45. Hardware Abstraction Layer
  46. 46. Hardware Abstraction Libraries● Why do we need a user-space HAL? ○ Not all components have standardized kernel driver interfaces ○ Kernel drivers are GPL which exposes any proprietary IP ○ Android has specific requirements for hardware drivers
  47. 47. Hardware Abstraction Libraries● Libraries are loaded dynamically at runtime as needed QualcommCameraHardware.cpp ... libqcamera = dlopen(“/system/lib/liboemcamera.so”, TLD_NOW); ... *(void **)&LINK_camera_init = ::dlsym(libqcamera, "camera_init"); ... LINK_camera_init();
  48. 48. Agenda● Linux Kernel● Native Libraries● Android Runtime● Application Framework● Inside The System Connectivity(Bluetooth,WiFi...) Power Management Display & Multimedia (Surfaceflinger, Audioflinger,Camera/Video) Telephony (Radio Interface Layer)● Android Boot sequence● Layer Interaction
  49. 49. Android Runtime
  50. 50. What is the Dalvik VM?● Androids custom clean-room implementation virtual machine● run on a slow CPU● with relatively little RAM● on an OS without swap space● while powered by a battery
  51. 51. Dalvik Virtual Machine● Provides application portability and runtime consistency● Runs optimized file format (.dex) and Dalvik bytecode● Java .class / .jar files converted to .dex at build time
  52. 52. Core Libraries● Core APIs for Java language provide a powerful, yet simple and familiar development platform ○ Data structures ○ Utilities ○ File access ○ Network Access ○ Graphics ○ …
  53. 53. .dex file
  54. 54. .jar Vs .dex
  55. 55. .class files
  56. 56. .dex file
  57. 57. Agenda● Linux Kernel● Native Libraries● Android Runtime● Application Framework● Inside The System Connectivity(Bluetooth,WiFi...) Power Management Display & Multimedia (Surfaceflinger, Audioflinger,Camera/Video) Telephony (Radio Interface Layer)● Android Boot sequence● Layer Interaction
  58. 58. Application Framework
  59. 59. Core Platform Services● Services that are essential to the Android platform● Behind the scenes - applications typically dont access them directly
  60. 60. Core Platform Services● Activity Manager
  61. 61. Core Platform Services● Activity Manager● Package Manager
  62. 62. Core Platform Services● Activity Manager● Package Manager● Window Manager
  63. 63. Core Platform Services● Activity Manager● Package Manager● Window Manager● Resource Manager
  64. 64. Core Platform Services● Activity Manager● Package Manager● Window Manager● Resource Manager● Content Providers
  65. 65. Core Platform Services● Activity Manager● Package Manager● Window Manager● Resource Manager● Content Providers● View System
  66. 66. Hardware Services● Provide access to lower-level hardware APIs● Typically accessed through local Manager object LocationManager lm = (LocationManager) Context.getSystemService (Context.LOCATION_SERVICE);
  67. 67. Hardware Services● Telephony Service
  68. 68. Hardware Services● Telephony Service● Location Service
  69. 69. Hardware Services● Telephony Service● Location Service● Bluetooth Service
  70. 70. Hardware Services● Telephony Service● Location Service● Bluetooth Service● WiFi Service
  71. 71. Hardware Services● Telephony Service● Location Service● Bluetooth Service● WiFi Service● USB Service
  72. 72. Hardware Services● Telephony Service● Location Service● Bluetooth Service● WiFi Service● USB Service● Sensor Service
  73. 73. Android System
  74. 74. Agenda● Linux Kernel● Native Libraries● Android Runtime● Application Framework● Inside The System Connectivity(Bluetooth,WiFi...) Power Management Display & Multimedia (Surfaceflinger, Audioflinger,Camera/Video) Telephony (Radio Interface Layer)● Android Boot sequence● Layer Interaction
  75. 75. Inside The System● Connectivity ○ Bluetooth ○ WiFi● Power Management● Display & Multimedia ○ Display Subsystem ○ Audio Subsystem ○ Camera/Video Subsystem● Telephony
  76. 76. Connectivity● Bluetooth● Wi-Fi
  77. 77. BluetoothNote: Android 4.2 introduces a new Bluetooth stack optimized for use withAndroid devices. The new Bluetooth stack developed in collaboration betweenGoogle and Broadcom replaces the stack based on BlueZ and providesimproved compatibility and reliability.
  78. 78. Wi-Fi● Android uses wpa_supplicant as the platform interface to the Wi-Fi device.● Your Wi-Fi driver must be compatible with the standard wpa_supplicant
  79. 79. Wi-Fi
  80. 80. Inside The System● Connectivity ○ Bluetooth ○ WiFi● Power Management● Display & Multimedia ○ Display Subsystem ○ Audio Subsystem ○ Camera/Video Subsystem● Telephony
  81. 81. Power Management
  82. 82. Inside The System● Connectivity ○ Bluetooth ○ WiFi● Power Management● Display & Multimedia ○ Display Subsystem ○ Audio Subsystem ○ Camera/Video Subsystem● Telephony
  83. 83. Display & Multimedia● Display Subsystem● Audio Subsystem● Camera/Video Subsystem
  84. 84. Display Subsystem
  85. 85. Audio Subsystem
  86. 86. Camera/Video Subsystem
  87. 87. Android Multimedia Framework
  88. 88. Inside The System● Connectivity ○ Bluetooth ○ WiFi● Power Management● Display & Multimedia ○ Display Subsystem ○ Audio Subsystem ○ Camera/Video Subsystem● Telephony
  89. 89. Telephony● Radio Interface Layer Androids Radio Interface Layer (RIL) provides an abstraction layer between Android telephony services (android.telephony) and radio hardware.
  90. 90. Radio Interface Layer
  91. 91. Agenda● Linux Kernel● Native Libraries● Android Runtime● Application Framework● Inside The System Connectivity(Bluetooth,WiFi...) Power Management Display & Multimedia (Surfaceflinger, Audioflinger,Camera/Video) Telephony (Radio Interface Layer)● Android Boot sequence● Layer Interaction
  92. 92. Runtime WalkthroughIt all starts with init…Similar to most Linux-based systems at startup,the bootloader loads the Linux kernel and startsthe init process.
  93. 93. Runtime Walkthrough● Init starts Linux daemons, including: ○ USB Daemon (usbd) to manage USB connections ○ Android Debug Bridge (adbd) to manage ADB connections ○ Debugger Daemon (debuggerd) to manage debug processes requests (dump memory, etc.) ○ Radio Interface Layer Daemon (rild) to manage communication with the radio
  94. 94. Runtime Walkthrough● Init process starts the zygote process: ○ A nascent process which initializes a Dalvik VM instance ○ Loads classes and listens on socket for requests to spawn VMs ○ Forks on request to create VM instances for managed processes ○ Copy-on-write to maximize re-use and minimize footprint
  95. 95. Runtime Walkthrough● Init starts runtime process: ○ Initializes Service Manager – the context manager for Binder that handles service registration and lookup ○ Registers Service Manager as default context manager for Binder services
  96. 96. Runtime Walkthrough● Runtime process sends request for Zygote to start System Service
  97. 97. Runtime Walkthrough● Runtime process sends request for Zygote to start System Server ○ Zygote forks a new VM instance for the System Service process and starts the service
  98. 98. Runtime Walkthrough● System Service starts the native system servers, including: ○ Surface Flinger ○ Audio Flinger
  99. 99. Runtime Walkthrough● Native system servers register with Service Manager as IPC service targets:
  100. 100. Runtime Walkthrough● System Service starts the Android managed services:
  101. 101. Runtime Walkthrough● Android managed Services register with Service Manager:
  102. 102. Runtime Walkthrough
  103. 103. Runtime WalkthroughAfter system server loads all services, the system isready…
  104. 104. Runtime WalkthroughAfter system server loads all services, the system isready…
  105. 105. Runtime WalkthroughAfter system server loads all services, the system isready…
  106. 106. Runtime WalkthroughEach subsequent application is launched in its ownprocess
  107. 107. Agenda● Linux Kernel● Native Libraries● Android Runtime● Application Framework● Inside The System Connectivity(Bluetooth,WiFi...) Power Management Display & Multimedia (Surfaceflinger, Audioflinger,Camera/Video) Telephony (Radio Interface Layer)● Android Boot sequence● Layer Interaction
  108. 108. Layer InteractionThere are 3 main flavors of Android layer cake: ○ App Runtime Service lib ○ App Runtime Service Native Service lib ○ App Runtime Service Native Daemon lib
  109. 109. Layer InteractionThere are 3 main flavors of Android layer cake: ○ App Runtime Service lib ○ App Runtime Service Native Service lib ○ App Runtime Service Native Daemon lib
  110. 110. Android Runtime Services
  111. 111. Android Runtime Services
  112. 112. Android Runtime Services
  113. 113. Android Runtime Services
  114. 114. Example: Location Manager
  115. 115. Layer InteractionThere are 3 main flavors of Android layer cake: ○ App Runtime Service lib ○ App Runtime Service Native Service lib ○ App Runtime Service Native Daemon lib
  116. 116. Android Native Services
  117. 117. Android Native Services
  118. 118. Android Native Services
  119. 119. Android Native Services
  120. 120. Android Native Services
  121. 121. Android Native Services
  122. 122. Android Native Services
  123. 123. Layer InteractionThere are 3 main flavors of Android layer cake: ○ App Runtime Service lib ○ App Runtime Service Native Service lib ○ App Runtime Service Native Daemon lib
  124. 124. Daemon Connection
  125. 125. Daemon Connection
  126. 126. Daemon Connection
  127. 127. Daemon Connection
  128. 128. Questions
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×