BSP Developer Must Know about Android.pdf

1zqe3ng06 73 views 55 slides Nov 12, 2024
Slide 1
Slide 1 of 55
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55

About This Presentation

BSP Developer Must Know about Android.pdf


Slide Content

F-3697 F-3697



BSP Developer Must Know about
Android

F-3697
Revision History
Revision No. Description Date
V1.0 •Android concepts for BSP developer, by Yone Xie 2012-07-19
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 2
F-3697 Security Level: Confidential A

F-3697
Agenda
Intro⊿
Android Architecture
Linux Kernel
Native Libraries
Android Runtime
Application Framework
Android Applications
Android Concepts
Key Concepts
Start-up Walkthrough
Layer Interaction
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 3 Security Level: Confidential A

F-3697
History

1.0 - September 23, 2008
1.5 - Cupcake
1.6 - Donut
2.1 - Eclair
2.2 - Froyo
2.3 - Gingerbread
3.x - Honeycomb
4.0 - Ice Scream Sandwich
4.1 - Jelly Bean
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 4 Security Level: Confidential A

F-3697
AOSP(Android Open Source Project)
At every new version, Google releases its source code through this
project so that community and vendors can work with it.
One major exception: Honeycomb has not been released because Google
stated that its source code was not clean enough to release it.
One can fetch the source code and contribute to it, even though
the development process is very locked by Google
Only a few devices are supported through AOSP though, only the
two most recent Android development phones, the Panda board
and the Motorola Xoom.
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 5 Security Level: Confidential A

F-3697
Agenda
Intro
Android Architecture ⊿
Linux Kernel
Native Libraries
Android Runtime
Application Framework
Android Applications
Android Concepts
Key Concepts
Start-up Walkthrough
Layer Interaction
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 6 Security Level: Confidential A

F-3697
Android Architecture
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 7 Security Level: Confidential A
Applications
Launcher2 Contacts Phone Browser ...
Libraries
Surface Manager Media Framework SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver
Application Framework
Activity Manager Window Manager
Content
Provider
View System
Package Manager
Telephony
Manager
Resource
Manager
… Location Manager
Notification
Manager

F-3697
Linux Kernel
Used as the foundation of the Android system
Why Linux kernel?
But, Android is not Linux
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 8 Security Level: Confidential A
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver

F-3697
Linux Kernel
Android vs. Linux Distributions
XNo native window GUI system (GNOME/KDE)
XNo glibc support
XDoes not include the full set of standard Linux utilities
Standard Linux Kernel (version 2.6+)
XPatches of “kernel enhancements” to support Android

Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 9 Security Level: Confidential A
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver

F-3697
Kernel Patches
Kernel patches for Android by Google
Alarm
Ashmem
Binder
Power Management
Low Memory Killer
Kernel Debugger
Logger
These changes are beginning to go into the staging/ area of the kernel, as of
3.3, after being a complete fork for a long time

Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 10 Security Level: Confidential A
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver

F-3697
Binder : Problem
Why need Binder IPC mechanisms?
Applications and Services may run in separate processes but must
communicate and share data
Inter-process communication (IPC) can introduce significant processing
overhead and security holes
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 11 Security Level: Confidential A
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver

F-3697
Binder : Solution
Binder IPC mechanisms
Driver to facilitate 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
“In the Android platform, the binder is used for nearly everything that
happens across processes in the core platform. "
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 12 Security Level: Confidential A
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver

F-3697
Binder in Action
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 13 Security Level: Confidential A
Process A
App A Context Binder Driver
Process B
Service B
Get service
Service
Call foo (object)
Call Return
Marshal proxy
object
Relay to
IPC threads

F-3697
Binder
How to use Binder from App developer’s view?
Intent
Android Interface Definition Language (AIDL)
http://developer.android.com/guide/components/aidl.html
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 14 Security Level: Confidential A
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver

F-3697
PM : Problem
Why Android need special power management?
Mobile devices run on battery power
Batteries have limited capacity
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 15 Security Level: Confidential A
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver

F-3697
PM : Solution
Why Android need special power management?
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
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 16 Security Level: Confidential A
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver

F-3697
Android PM in Action
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 17 Security Level: Confidential A
App A Power Manager PM Driver
New Wake Lock
PARTIAL
Create Wake Lock
Release
Release
Turn Off
CPU
Turn Off
LCD

F-3697
Android PM
How to use Android PM from App developer’s view?
android.os.PowerManager
Use wake locks carefully!
userActivity(long when, …)
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 18 Security Level: Confidential A
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver

F-3697
Get Linux Kernel for Android
Get kernel source from Google, Depending on which kernel you
want
git clone https://android.googlesource.com/kernel/common.git
git clone https://android.googlesource.com/kernel/exynos.git
git clone https://android.googlesource.com/kernel/goldfish.git
git clone https://android.googlesource.com/kernel/msm.git
git clone https://android.googlesource.com/kernel/omap.git
git clone https://android.googlesource.com/kernel/samsung.git
git clone https://android.googlesource.com/kernel/tegra.git
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 19 Security Level: Confidential A
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver

F-3697
Native Libraries
Gather a lot of Android-specific libraries to interact at a low-level
with the system(such as HAL), but third-parties libraries as well
Bionic LibC
Function Libraries
Native Servers
Hardware Abstraction Libraries
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 20 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Bionic
What is bionic?
Custom libc implementation, optimized for embedded use.
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 21 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Bionic : Problem
Why build a custom libc library?
License: Google wants to keep GPL out of user-space
Size: will load in each process, so it needs to be small
Fast: limited CPU power means it should to be fast
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 22 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Bionic : Solution
Bionic is :
BSD License
Small size and fast code paths
Very fast and small custom pthread implementation
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 23 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Bionic
Built-in support for important Android-specific services
Access to system properties
getprop(“my.system.property”, buff, default);
setprop (“my.system.property”, value);
Logging events in the system logs
LOGD(“Logging a message with priority ‘Debug’”);
LOGW(“Logging a message with priority ‘Warning’”);
LOGE(“Logging a message with priority ‘Error’”);
LOGI(“Logging a message with priority ‘Info’”);
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 24 Security Level: Confidential A

F-3697
Bionic
Bionic C library with the following weirdness :
Non POSIX
No support for locales
No support for wide chars (i.e. multi-byte characters)
Comes with its own smallish implementation of pthreads based on Linux
futexes
C++ exceptions are not supported
pthread cancellation is NOT supported
Several functions are just stubs (i.e. runtime weirdness may happen)
Non standard /etc config files
Dynamic user/groups management (no pam, group, passwd or shadow)
No fstab
No SysV init
All native code must be compiled against bionic
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 25 Security Level: Confidential A

F-3697
Function Libraries
Media Framework
Based on Stagefright platform (Android introduces Stagefright to replace
OpenCORE start from Eclair)
Supports standard video, audio, still-frame formats
Support for hardware / software codec plug-ins
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 26 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Function Libraries
SQLite
Light-weight transactional data store
Back end for most platform data storage
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 27 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Function Libraries
Open GL | ES
3D graphics engine
An implementation based on OpenGL ES 1.0 APIs

Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 28 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Function Libraries
SGL
Scalable Graphics Library (Skia Graphics Library)
2D graphics engine
low-level graphics library implemented in native code that handles
rendering - Text, Geometries, and Images
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 29 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Function Libraries
FreeType
A font rasterization engine, used to render text to bitmaps and provides
support for other font-related operations
http://freetype.org
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 30 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Function Libraries
SSL
Open SSL library, an open-source implementation of the SSL and TLS
protocols
http://openssl.org
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 31 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Function Libraries
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
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 32 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Native Services
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
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 33 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES Audio Manager WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Native Services
Surface Flinger
Surfaces passed as buffers via Binder IPC calls
Can use OpenGL ES and 2D hardware accelerator for its compositions
Double-buffering using page-flip (and Triple-buffering introduced from Jelly
Bean)
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 34 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES Audio Manager WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Typical Graphical Stacks
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 35 Security Level: Confidential A

F-3697
Surface Flinger
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 36 Security Level: Confidential A

F-3697
Native Services
Audio Flinger
Manages all audio output devices
Processes multiple audio streams into PCM audio out paths
Handles audio routing to various outputs
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 37 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES Audio Manager WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Audio Flinger
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 38 Security Level: Confidential A

F-3697
Hardware Abstract Layer
Graphics Audio/Camera
WiFi /GPS/
Bluetooth
RIL ...
HAL
Hardware Abstraction Layer / Libraries
Where is it?
Usually, the kernel already provides a HAL for user-space
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 39 Security Level: Confidential A
Libraries
Surface Manager Media Framework SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver

F-3697
HAL : Problem
Why do Android need a user-space HAL?
Kernel drivers are GPL which exposes any proprietary IP
Not all components have standardized kernel driver interfaces
Android has specific requirements for hardware drivers
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 40 Security Level: Confidential A
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver
Hardware Abstract Layer
Graphics Audio/Camera
WiFi /GPS/
Bluetooth
RIL ...

F-3697
HAL : Solution
Android HAL :
Defines the interface that Android requires hardware “drivers” to
implement
Separates the Android platform logic from the hardware interface
And Google implemented its HAL with dynamically loaded user-space
libraries
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 41 Security Level: Confidential A
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Binder (IPC)
Driver
USB Driver
Keypad/Touch
Driver
WiFi Driver
Power
Management
Shared Memory
Driver
Audio Driver
Hardware Abstract Layer
Graphics Audio/Camera
WiFi /GPS/
Bluetooth
RIL ...

F-3697
HAL : Details
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 42 Security Level: Confidential A
Loading and Interfacing Methods
dlopen() - loading through HAL
Linker-loaded .so files
Hardcoded dlopen()s
Sockets
Sysfs entries
/dev nodes
D-Bus

F-3697
HAL : Details
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 43 Security Level: Confidential A
HAL Header Example
// must be provided by each Acme hardware implementation


typedef struct {
int (*foo)( void );
char (*bar)( void );
...
} AcmeFunctions;


const AcmeFunctions *Acme_Init(const struct Env *env, int argc,
char **argv);

F-3697
HAL : Details
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 44 Security Level: Confidential A
Libraries are loaded dynamically at runtime as needed
dlHandle = dlopen(“/system/lib/ libacme.so”, RTLD_NOW);

...

acmeInit = (const AcmeFunctions *(*)(const struct Env *,
int, char **))dlsym(dlHandle, ”Acme_Init");

...

acmeFuncs = acmeInit(&env, argc, argv);

F-3697
HAL : Details

Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 45 Security Level: Confidential A

F-3697
HAL : Details
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 46 Security Level: Confidential A

F-3697
Android Runtime
Handles the execution of Android applications
Almost entirely written from scratch by Google
Contains Dalvik, the virtual machine that executes every application that
you run on Android, and the core library for the Java runtime, coming from
Apache Harmony project
Also contains system daemons, init executable, basic binaries, etc.
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 47 Security Level: Confidential A
Libraries
Surface Manager Audio Manager SQLite
Open GL | ES FreeType WebKit
SGL SSL Bionic
Android Runtime
Core
Libraries
Dalvik
Virtual Machine

F-3697
Application Framework






Provides an API for developers to create applications
Exposes all the needed subsystems by providing an abstraction
Allows to easily use databases, create services, expose data to
other applications, receive system events, etc.
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 48 Security Level: Confidential A
Application Framework
Activity Manager Window Manager
Content
Provider
View System
Package Manager
Telephony
Manager
Resource
Manager
… Location Manager
Notification
Manager

F-3697
Application Framework
Activity manager
Manage the life cycle of applications
Content Provider
Share data between applications
Resource Manager
Manager non-code resource
Notification Manager
Display custom alerts in the status bar
Views System
A rich and extensible set, which can construct UI
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 49 Security Level: Confidential A

F-3697
Android Applications



AOSP also comes with a set of applications such as the phone
application, a browser, a contact management application, an
email client, etc.
However, the Google apps and the Android Market app aren’t
free software, so they are not available in AOSP. To obtain them,
you must contact Google and pass a compatibility test.
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 50 Security Level: Confidential A
Applications
Launcher2 Contacts Phone Browser ...

F-3697
Agenda
Intro
Android Architecture
Linux Kernel
Native Libraries
Android Runtime
Application Framework
Android Applications
Android Concepts ⊿
Key Concepts
Start-up Walkthrough
Layer Interaction
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 51 Security Level: Confidential A

F-3697
Android Key Concepts
APP Developer’s View
Component
Activities
Services
Broadcast Receivers
Content Providers
Intent

Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 52 Security Level: Confidential A

F-3697
Start-up Walkthrough
Runtime Walkthrough
It all starts with init…
Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 53 Security Level: Confidential A

F-3697
Layer Interaction
There are 3 main flavors of Android layer cake :
App  Runtime Service  lib
App  Runtime Service  Native Service  lib
App  Runtime Service  Native Daemon  lib

Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 54 Security Level: Confidential A

F-3697 Security Level: Confidential A Copyright © 2012 MStar Semiconductor, Inc. All rights reserved. 55
Tags