Documente Academic
Documente Profesional
Documente Cultură
Android System
Development Embedded Linux
Experts
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 1/443
Rights to copy
Your fair use and other rights are in no way aected by the above.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 2/443
Hyperlinks in the document
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 3/443
Free Electrons at a glance
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 4/443
Free Electrons on-line resources
information
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 6/443
Hardware used in this training session
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 7/443
Do not damage your BeagleBone Black!
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 8/443
Course outline - Day 1
Building Android
Introduction to Android
Getting Android sources
Building and booting Android
Introduction to the Linux kernel
Compiling and booting the Linux kernel
Labs: download Android sources, compile them and boot them
with the Android emulator. Recompile the Linux kernel.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 9/443
Course outline - Day 2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 10/443
Course outline - Day 3
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 11/443
Course outline - Day 4
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 12/443
Participate!
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 13/443
Practical lab guidelines
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 14/443
Advise: write down your commands!
During practical labs, write down all your commands in a text le.
You can save a lot of time re-using
commands in later labs.
This helps to replay your work if Lab commands
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 15/443
Cooperate!
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 16/443
Command memento sheet
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 19/443
Introduction to Android
Android
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 20/443
Introduction to Android
Features
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 21/443
Features
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 22/443
Introduction to Android
History
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 23/443
Early Years
Began as a start-up in Palo Alto, CA, USA in 2003
Focused from the start on software for mobile devices
Very secretive at the time, even though founders achieved a
lot in the targeted area before founding it
Finally bought by Google in 2005
Andy Rubin, founder of Android, Inc was also CEO of Danger,
Inc, a company producing one of the early smartphones, the
Sidekick
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 24/443
Opening Up
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 25/443
Android Open Source Project (AOSP)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 26/443
Android Releases
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 27/443
Android Versions
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 28/443
Introduction to Android
Architecture
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 29/443
Architecture
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 30/443
The Linux Kernel
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 31/443
Android Libraries
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 32/443
Android Runtime
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 33/443
Android Framework
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 34/443
Android Applications
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 35/443
Introduction to Android
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 36/443
Android Hardware Requirements
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 37/443
SoC requirements
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 38/443
Storage and RAM needed
The required RAM size is also quite huge, 340MB are required
for the kernel and user space memory
Required storage is quite huge as well. An image of the
system is around 200-300MB, and you must have 350MB of
data space for the user plus 1GB of shared storage for the
applications.
This is the minimum, and Google actually strongly suggest to
have at least 2GB dedicated to the applications in order to be
able to upgrade to a later version
Google recommends to use block devices for storage and not
ash devices.
The shared space has to be accessible from a host computer
by some way, like NFS, USB Mass Storage, MTP, etc.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 39/443
External Peripherals 1/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 40/443
External Peripherals 2/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 41/443
Unusual Android Devices: Nook E-Book Reader
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 42/443
Unusual Android Devices: Portable Console
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 43/443
Unusual Android Devices: Microwave Oven
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 44/443
Unusual Android Devices: Treadmill
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 45/443
When to choose Android
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 47/443
Android Source Code and Compilation
Android Source
Code and Embedded Linux
Experts
Compilation
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 48/443
Android Source Code and Compilation
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 49/443
Source Code Location
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 50/443
Source code licenses
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 51/443
Repo
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 52/443
Repo's manifest
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 53/443
Manifests syntax
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 54/443
Android Source Code and Compilation
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 55/443
Source Code organization 1/3
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 56/443
Source Code Organization 2/3
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 57/443
Source Code Organization 3/3
Compilation
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 59/443
Android Compilation Process
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 60/443
Prepare the process
Now, we can get a list of all the products available and select
them with the lunch command
lunch will also ask for a build variant, to choose between eng,
user and userdebug, which corresponds to which kind of
build we want, and which packages it will add
You can also select variants by passing directly the combo
product-variant as argument to lunch
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 61/443
Compilation
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 62/443
Android Source Code and Compilation
Contribute
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 63/443
Gerrit
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 64/443
Practical lab - First Compilation
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 65/443
Linux kernel introduction
introduction
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 66/443
Linux kernel introduction
Linux features
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 67/443
History
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 68/443
Linux kernel key features
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 69/443
Linux kernel in the system
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 70/443
Linux kernel main roles
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 71/443
System calls
The main interface between the kernel and user space is the
set of system calls
About 300 system calls that provide the main kernel services
File and device operations, networking operations,
inter-process communication, process management, memory
mapping, timers, threads, synchronization primitives, etc.
This interface is stable over time: only new system calls can
be added by the kernel developers
This system call interface is wrapped by the C library, and
user space applications usually never make a system call
directly but rather use the corresponding C library function
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 72/443
Pseudo lesystems
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 73/443
Inside the Linux kernel
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 74/443
Linux license
The whole Linux sources are Free Software released under the
GNU General Public License version 2 (GPL v2).
For the Linux kernel, this basically implies that:
When you receive or buy a device with Linux on it, you should
receive the Linux sources, with the right to study, modify and
redistribute them.
When you produce Linux based devices, you must release the
sources to the recipient, with the same rights, with no
restriction.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 75/443
Supported hardware architectures
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 76/443
Linux kernel introduction
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 77/443
Until 2.6 (1)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 78/443
Until 2.6 (2)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 79/443
Changes since Linux 2.6
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 80/443
Versions since 2.6.0
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 81/443
New development model
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 82/443
More stability for the kernel source tree
The ocial list of changes for each Linux release is just a huge list
of individual patches!
commit aa6e52a35d388e730f4df0ec2ec48294590cc459
Author: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Date: Wed Jul 13 11:29:17 2011 +0200
Very dicult to nd out the key changes and to get the global
picture out of individual changes.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 84/443
What's new in each Linux release? (2)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 85/443
Linux kernel introduction
Kernel conguration
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 86/443
Kernel conguration and build system
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 87/443
Kernel conguration (1)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 88/443
Kernel conguration (2)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 89/443
Kernel or module?
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 90/443
Kernel option types
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 91/443
Kernel option dependencies
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 92/443
make xcong
make xconfig
The most common graphical interface to congure the kernel.
Make sure you read
help -> introduction: useful options!
File browser: easier to load conguration les
Search interface to look for parameters
Required Debian / Ubuntu packages: qt5-default g++
pkg-config
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 93/443
make xcong screenshot
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 94/443
make xcong search interface
Looks for a keyword in the parameter name. Allows to select or
unselect found parameters.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 95/443
Kernel conguration options
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 96/443
Corresponding .cong le excerpt
Options are grouped by sections and are prexed with CONFIG_.
#
# CD-ROM/DVD Filesystems
#
CONFIG_ISO9660_FS=m
CONFIG_JOLIET=y
CONFIG_ZISOFS=y
CONFIG_UDF_FS=y
CONFIG_UDF_NLS=y
#
# DOS/FAT/NT Filesystems
#
# CONFIG_MSDOS_FS is not set
# CONFIG_VFAT_FS is not set
CONFIG_NTFS_FS=m
# CONFIG_NTFS_DEBUG is not set
CONFIG_NTFS_RW=y
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 97/443
make gcong
make gconfig
GTK based graphical
conguration interface.
Functionality similar to that
of make xconfig.
Just lacking a search
functionality.
Required Debian packages:
libglade2-dev
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 98/443
make menucong
make menuconfig
Useful when no graphics are
available. Pretty convenient
too!
Same interface found in
other tools: BusyBox,
Buildroot...
Required Debian packages:
libncurses-dev
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 99/443
make ncong
make nconfig
A newer, similar text
interface
More user friendly (for
example, easier to access
help information).
Required Debian packages:
libncurses-dev
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 100/443
make oldcong
make oldconfig
Needed very often!
Useful to upgrade a .config le from an earlier kernel release
Issues warnings for conguration parameters that no longer
exist in the new kernel.
Asks for values for new parameters (while xconfig and
menuconfig silently set default values for new parameters).
If you edit a .config le by hand, it's strongly recommended to
run make oldconfig afterwards!
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 101/443
Undoing conguration changes
A frequent problem:
After changing several kernel conguration settings, your
kernel no longer works.
If you don't remember all the changes you made, you can get
back to your previous conguration:
$ cp .config.old .config
All the conguration interfaces of the kernel (xconfig,
menuconfig, oldconfig...) keep this .config.old backup
copy.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 102/443
Conguration per architecture
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 103/443
Linux kernel introduction
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 104/443
Kernel compilation
make
in the main kernel source directory
Remember to run multiple jobs in parallel if you have multiple
CPU cores. Example: make -j 4
No need to run as root!
Generates
vmlinux, the raw uncompressed kernel image, in the ELF
format, useful for debugging purposes, but cannot be booted
arch/<arch>/boot/*Image, the nal, usually compressed,
kernel image that can be booted
bzImage for x86, zImage for ARM, vmImage.gz for Blackn,
etc.
arch/<arch>/boot/dts/*.dtb, compiled Device Tree les (on
some architectures)
All kernel modules, spread over the kernel source tree, as .ko
(Kernel Object) les.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 105/443
Kernel installation
make install
Does the installation for the host system by default, so needs
to be run as root. Generally not used when compiling for an
embedded system, as it installs les on the development
workstation.
Installs
/boot/vmlinuz-<version>
Compressed kernel image. Same as the one in
arch/<arch>/boot
/boot/System.map-<version>
Stores kernel symbol addresses
/boot/config-<version>
Kernel conguration for this version
Typically re-runs the bootloader conguration utility to take
the new kernel into account.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 106/443
Module installation
make modules_install
Does the installation for the host system by default, so needs
to be run as root
Installs all modules in /lib/modules/<version>/
kernel/
Module .ko (Kernel Object) les, in the same directory
structure as in the sources.
modules.alias
Module aliases for module loading utilities. Example line:
alias sound-service-?-0 snd_mixer_oss
modules.dep, modules.dep.bin (binary hashed)
Module dependencies
modules.symbols, modules.symbols.bin (binary hashed)
Tells which module a given symbol belongs to.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 107/443
Kernel cleanup targets
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 108/443
Linux kernel introduction
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 109/443
Cross-compiling the kernel
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 110/443
Specifying cross-compilation (1)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 111/443
Specifying cross-compilation (2)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 112/443
Predened conguration les
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 113/443
Conguring the kernel
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 114/443
Device Tree
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 116/443
Building and installing the kernel
Run make
Copy the nal kernel image to the target storage
can be zImage, vmlinux, bzImage in arch/<arch>/boot
copying the Device Tree Blob might be necessary as well, they
are available in arch/<arch>/boot/dts
make install is rarely used in embedded development, as the
kernel image is a single le, easy to handle
It is however possible to customize the make install
behaviour in arch/<arch>/boot/install.sh
make modules_install is used even in embedded
development, as it installs many modules and description les
make INSTALL_MOD_PATH=<dir>/ modules_install
The INSTALL_MOD_PATH variable is needed to install the
modules in the target root lesystem instead of your host root
lesystem.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 117/443
Booting with U-Boot
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 118/443
Kernel command line
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 119/443
Practical lab - Compile and Boot an Android Kernel
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 120/443
The Android Kernel
Changes
introduced in the Embedded Linux
Experts
Android Kernel
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 121/443
The Android Kernel
Wakelocks
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 122/443
Power management basics
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 123/443
Wakelocks
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 124/443
Wakelocks API
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 125/443
The Android Kernel
Binder
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 126/443
Binder
RPC/IPC mechanism
Takes its roots from BeOS and the OpenBinder project, which
some of the current Android engineers worked on
Adds remote object invocation capabilities to the Linux Kernel
One of the very basic functionalities of Android. Without it,
Android cannot work.
Every call to the system servers go through Binder, just like
every communication between applications, and even
communication between the components of a single
application.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 127/443
Binder
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 128/443
The Android Kernel
klogger
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 129/443
Logging
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 130/443
Logger
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 131/443
The Android Kernel
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 132/443
Shared memory mechanism in Linux
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 133/443
Ashmem
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 134/443
The Android Kernel
Alarm Timers
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 135/443
The alarm driver
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 136/443
The Android Kernel
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 137/443
Low Memory Killer
When the system goes out of memory, Linux throws the OOM
Killer to cleanup memory greedy processes
However, this behaviour is not predictable at all, and can kill
very important components of a phone (Telephony stack,
Graphic subsystem, etc) instead of low priority processes
(Angry Birds)
The main idea is to have another process killer, that kicks in
before the OOM Killer and takes into account the time since
the application was last used and the priority of the
component for the system
It uses various thresholds, so that it rst noties applications
so that they can save their state, then begins to kill
non-critical background processes, and then the foreground
applications
As it is run to free memory before the OOM Killer, the latter
will never be run, as the system will never run out of memory
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 138/443
The Android Kernel
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 139/443
ION 1/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 140/443
ION 2/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 141/443
Comparison with mainline equivalents
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 142/443
The Android Kernel
Network Security
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 143/443
Paranoid Network
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 144/443
The Android Kernel
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 145/443
Various additions
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 146/443
The Android Kernel
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 147/443
History
The Android Kernel patches were kept for a long time out of
the ocial Linux release
They were rst integrated in 2.6.29, in
drivers/staging/android
They were then removed from the kernel 2.6.35, because
Google was unwilling to help the mainlining process
They were then added back in 3.3 (around 2 years later) and
are still there at the time
While Google did a great job at keeping most of their changes
as isolated from the core as possible, making this easy to
merge in the staging area, it wasn't true for the wakelocks,
due to their invasive nature.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 148/443
Wakelocks Support
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 149/443
Current State: Merged Patches
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 150/443
Current State: Missing Patches
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 151/443
Android Bootloaders
Bootloaders
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 152/443
Android Bootloaders
Boot Sequence
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 153/443
Bootloaders
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 154/443
Bootloaders on BIOS-based x86 (1)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 156/443
Booting on embedded CPUs: case 1
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 157/443
Booting on embedded CPUs: case 2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 158/443
Booting on ARM Atmel AT91
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 159/443
Booting on ARM TI OMAP3
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 160/443
Booting on Marvell SoC
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 161/443
Generic bootloaders for embedded CPUs
Fastboot
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 163/443
Denition
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 164/443
The Fastboot protocol
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 165/443
Session example
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 166/443
Booting into Fastboot
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 167/443
Major Fastboot Commands
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 168/443
getvar Variables
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 169/443
Android Build System: Basics
System: Basics
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 170/443
Android Build System: Basics
Basics
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 171/443
Build Systems
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 172/443
First compilation
$ source build/envsetup.sh
$ lunch
You're building on Linux
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 173/443
Android Build System: Basics
envsetup.sh
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 174/443
Purpose
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 175/443
Environments variables exported 1/2
ANDROID_EABI_TOOLCHAIN
Path to the Android prebuilt toolchain (.../prebuilt/linux-
x86/toolchain/arm-eabi-4.4.3/bin)
ANDROID_TOOLCHAIN
Equals to ANDROID_EABI_TOOLCHAIN
ANDROID_QTOOLS
Tracing tools for qemu (.../development/emulator/qtools).
This is weird however, since this path doesn't exist at all
ANDROID_BUILD_PATHS
Path containing all the folders containing tools for the build
(.../out/host/linux-x86/bin:$ANDROID_TOOLCHAIN:
$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:
$ANDROID_EABI_TOOLCHAIN)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 176/443
Environments variables exported 2/2
JAVA_HOME
Path to the Java environment (/usr/lib/jvm/java-6-sun)
ANDROID_JAVA_TOOLCHAIN
Path to the Java toolchain ($JAVA_HOME/bin)
ANDROID_PRE_BUILD_PATHS
Alias to ANDROID_JAVA_TOOLCHAIN
ANDROID_PRODUCT_OUT
Path to where the generated les will be for this product
(.../out/target/product/<product_name>)
OUT
Alias to ANDROID_PRODUCT_OUT
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 177/443
Dened Commands 1/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 178/443
Dened Commands 2/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 179/443
Android Build System: Basics
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 180/443
Conguration
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 181/443
lunch
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 182/443
Variables Exported by Lunch
TARGET_PRODUCT
Which product to build. To build for the emulator, you will
have aosp_<arch>
TARGET_BUILD_VARIANT
Select which set of modules to build, among
user: Includes modules tagged user (Phone)
userdebug: Includes modules tagged user or debug (strace)
eng: Includes modules tagged user, debug or eng:
(e2fsprogs)
TARGET_BUILD_TYPE
Either release or debug. If debug is set, it will enable some
debug options across the whole system.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 183/443
buildspec.mk
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 184/443
Android Build System: Basics
Results
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 185/443
Output
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 186/443
Images
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 187/443
Android Boot Images
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 188/443
Android boot and recovery images
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 189/443
Boot sequence
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 190/443
Cleaning
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 191/443
Practical lab - Supporting a New Board
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 192/443
Android Debug Bridge
Developing and
Debugging with Embedded Linux
Experts
ADB
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 193/443
Android Debug Bridge
Introduction
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 194/443
ADB
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 195/443
Implementation
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 196/443
ADB Architecture
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 197/443
Android Debug Bridge
Use of ADB
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 198/443
ADB commands: Basics
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 199/443
ADB commands: Files and applications
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 200/443
ADB commands: Debugging
logcat Prints the device logs. You can lter either on the
source of the logs or their on their priority level
shell Runs a remote shell with a command line interface.
If an argument is given, runs it as a command and
prints out the result
bugreport Gets all the relevant information to generate a bug
report from the device: logs, internal state of the
device, etc.
jdwp Lists the processes that support the JDWP protocol
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 201/443
ADB commands: Scripting 1/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 202/443
ADB commands: Scripting 2/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 203/443
ADB commands: Easter eggs
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 204/443
Android Debug Bridge
Examples
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 205/443
ADB forward and gdb
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 208/443
Practical lab - Use ADB
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 209/443
Android Filesystem
Filesystem
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 210/443
Android Filesystem
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 211/443
Filesystems
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 212/443
Filesystems (2)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 213/443
mount / umount
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 214/443
Root lesystem
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 215/443
Location of the root lesystem
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 216/443
Mounting rootfs from storage devices
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 217/443
rootfs in memory: initramfs (1)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 219/443
rootfs in memory: initramfs (3)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 220/443
Android Filesystem
Contents
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 221/443
Filesystem organization on GNU/Linux
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 222/443
Filesystem organization on Android
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 223/443
/system
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 224/443
Other directories
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 225/443
android_lesystem_cong.h
Located in system/core/include/private/
Contains the full lesystem setup, and is written as a C
header
UID/GID
Permissions for system directories
Permissions for system les
Processed at compilation time to enforce the permissions
throughout the lesystem
Useful in other parts of the framework as well, such as ADB
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 226/443
Android Filesystem
Device Files
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 227/443
Devices
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 228/443
Types of devices
Block devices
A device composed of xed-sized blocks, that can be read and
written to store data
Used for hard disks, USB keys, SD cards, etc.
Character devices
Originally, an innite stream of bytes, with no beginning, no
end, no size. The pure example: a serial port.
Used for serial ports, terminals, but also sound cards, video
acquisition devices, frame buers
Most of the devices that are not block devices are represented
as character devices by the Linux kernel
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 229/443
Android Filesystem
Minimal lesystem
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 230/443
Basic applications
and /bin/sh.
In the case of an initramfs, it will only look for /init. Another
process is stopped.
The init application is responsible for starting all other user
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 231/443
Overall booting process
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 232/443
Android Build System: Advanced
System: Advanced
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 233/443
Android Build System: Advanced
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 234/443
Modules
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 235/443
Hello World
LOCAL_SRC_FILES = hello_world.c
LOCAL_MODULE = HelloWorld
LOCAL_MODULE_TAGS = optional
include $(BUILD_EXECUTABLE)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 236/443
Hello World
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 237/443
Tags
Tags are used to dene several sets of modules to be built
through the build variant selected by lunch
We have 3 build variants:
user
Installs modules tagged with user
Installs non-packaged modules that have no tags specied
ro.secure = 1
ro.debuggable = 0
ADB is disabled by default
userdebug is user plus
Installs modules tagged with debug
ro.debuggable = 1
ADB is enabled by default
eng is userdebug, plus
Installs modules tagged as eng and development
ro.secure = 0
ro.kernel.android.checkjni = 1
Finally, we have a fourth tag, optional, that will never be
directly integrated by a build variant, but deprecates user
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 238/443
Build Targets 1/3
BUILD_EXECUTABLE
Builds a normal ELF binary to be run on the target
BUILD_HOST_EXECUTABLE
Builds an ELF binary to be run on the host
BUILD_RAW_EXECUTABLE
Builds a binary to be run on bare metal
BUILD_JAVA_LIBRARY
Builds a Java library (.jar) to be used on the target
BUILD_STATIC_JAVA_LIBRARY
Builds a static Java library to be used on the target
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 239/443
Build Targets 2/3
BUILD_HOST_JAVA_LIBRARY
Builds a Java library to be used on the host
BUILD_SHARED_LIBRARY
Builds a shared library for the target
BUILD_STATIC_LIBRARY
Builds a static library for the target
BUILD_HOST_SHARED_LIBRARY
Builds a shared library for the host
BUILD_HOST_STATIC_LIBRARY
Builds a static library for the host
BUILD_RAW_STATIC_LIBRARY
Builds a static library to be used on bare metal
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 240/443
Build Targets 3/3
BUILD_PREBUILT
Used to install prebuilt les on the target (conguration les,
kernel)
BUILD_HOST_PREBUILT
Used to install prebuilt les on the host
BUILD_MULTI_PREBUILT
Used to install prebuilt les of multiple modules of known types
BUILD_PACKAGE
Builds a standard Android package (.apk)
BUILD_KEY_CHAR_MAP
Builds a device character map
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 241/443
Other useful variables
LOCAL_CFLAGS
Extra C compiler ags to use to build the module
LOCAL_SHARED_LIBRARIES
List of shared libraries this module depends on at compilation
time
LOCAL_PACKAGE_NAME
Equivalent to LOCAL_MODULE for Android packages
LOCAL_C_INCLUDES
List of paths to extra headers used by this module
LOCAL_REQUIRED_MODULES
Express that a given module depends on another at runtime,
and therefore should be included in the image as well
Many other similar options depending on what you want to do
You can get a complete list by reading
build/core/clear_vars.mk
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 242/443
Useful Make Macros
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 243/443
Prebuilt Package Example
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := configuration_files.txt
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 244/443
Making and cleaning a module (1/2)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 246/443
Practical lab - Building a Library
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 247/443
Practical lab - Add a Native Application to the Build
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 248/443
Android Build System: Advanced
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 249/443
Dening new products
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 250/443
Product, devices and boards
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 251/443
Minimal Product Declaration
PRODUCT_NAME := full_MyDevice
PRODUCT_DEVICE := MyDevice
PRODUCT_MODEL := Full flavor of My Brand New Device
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 252/443
Copy les to the target
PRODUCT_COPY_FILES += \
device/mybrand/mydevice/vold.fstab:system/etc/vold.fstab
PRODUCT_NAME := full_MyDevice
PRODUCT_DEVICE := MyDevice
PRODUCT_MODEL := Full flavor of My Brand New Device
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 253/443
Add a package to the build for this product
PRODUCT_PACKAGES += FooBar
PRODUCT_COPY_FILES += \
device/mybrand/mydevice/vold.fstab:system/etc/vold.fstab
PRODUCT_NAME := full_mydevice
PRODUCT_DEVICE := mydevice
PRODUCT_MODEL := Full flavor of My Brand New Device
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 254/443
Overlays
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 255/443
Add a device overlay
PRODUCT_PACKAGES += FooBar
PRODUCT_COPY_FILES += \
device/mybrand/mydevice/vold.fstab:system/etc/vold.fstab
DEVICE_PACKAGE_OVERLAYS := device/mybrand/mydevice/overlay
PRODUCT_NAME := full_mydevice
PRODUCT_DEVICE := mydevice
PRODUCT_MODEL := Full flavor of My Brand New Device
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 256/443
Board Denition
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 257/443
Minimal Board Denition
TARGET_NO_BOOTLOADER := true
TARGET_NO_KERNEL := true
TARGET_CPU_ABI := armeabi
HAVE_HTC_AUDIO_DRIVER := true
BOARD_USES_GENERIC_AUDIO := true
USE_CAMERA_STUB := true
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 258/443
Other Board Variables 1/2
TARGET_ARCH_VARIANT
Variant of the selected architecture (for example
armv7-a-neon for most Cortex-A8 and A9 CPUs)
TARGET_EXTRA_CFLAGS
Extra C compiler ags to use during the whole build
TARGET_CPU_SMP
Does the CPU have multiple cores?
TARGET_USERIMAGES_USE_EXT4
We want to use ext4 lesystems for our generated partitions
BOARD_SYSTEMIMAGE_PARTITION_SIZE
Size of the system partitions in bytes.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 259/443
Other Board Variables 2/2
BOARD_NAND_PAGE_SIZE
For NAND ash, size of the pages as given by the datasheet
TARGET_NO_RECOVERY
We don't want to build the recovery image
BOARD_KERNEL_CMDLINE
Boot arguments of the kernel
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 260/443
Kernel Integration into Android
PRODUCT_COPY_FILES := \
$(LOCAL_KERNEL):kernel
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 261/443
Practical lab - System Customization
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 262/443
Android Native Layer
Layer
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 263/443
Android Native Layer
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 264/443
Denition (1)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 265/443
Denition (2)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 266/443
Machines in build procedures
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 267/443
Dierent toolchain build procedures
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 268/443
Components
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 269/443
Binutils
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 270/443
Kernel headers (1)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 271/443
Kernel headers (2)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 272/443
Kernel headers (3)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 273/443
GCC
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 274/443
C library
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 275/443
Android Native Layer
Bionic
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 276/443
Whole Android Stack
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 277/443
Bionic 1/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 278/443
Bionic 2/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 279/443
Android Native Layer
Toolbox
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 280/443
Whole Android Stack
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 281/443
Why Toolbox?
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 282/443
General purpose toolbox: BusyBox
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 283/443
BusyBox commands!
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 284/443
Toolbox
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 285/443
Android Native Layer
Init
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 286/443
Whole Android Stack
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 287/443
Init
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 288/443
Android's init
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 289/443
Init part
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 290/443
init.rc le interpretation
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 291/443
Syntax
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 292/443
Actions
on <trigger>
command
command
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 293/443
Init triggers
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 294/443
Example
import /init.${ro.hardware}.rc
on boot
export PATH /sbin:/system/sbin:/system/bin
export LD_LIBRARY_PATH /system/lib
mkdir /dev
mkdir /proc
mkdir /sys
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 296/443
Example
on device-added-/dev/compass
start akmd
on device-removed-/dev/compass
stop akmd
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 297/443
Uevent
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 298/443
ueventd.rc syntax
Example
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 299/443
Properties
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 300/443
Modifying Properties
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 301/443
Permissions on the Properties
Android, by default, only allows any given process to read the
properties.
You can set write permissions on a particular property or a group of
them using the le system/core/init/property_service.c
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 303/443
Android Native Layer
Various daemons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 304/443
Whole Android Stack
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 305/443
Vold
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 306/443
rild
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 307/443
Others
netd
netd manages the various network connections: Bluetooth,
Wi, USB
Also takes any associated actions: detect new connections, set
up the tethering, etc.
It really is an equivalent to NetworkManager
On a security perspective, it also allows to isolate
network-related privileges in a single process
installd
Handles package installation and removal
Also checks package integrity, installs the native libraries on
the system, etc.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 308/443
Android Native Layer
SurfaceFlinger
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 309/443
Introduction to graphical stacks
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 310/443
Compositing window managers
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 311/443
SurfaceFlinger
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 312/443
SurfaceFlinger
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 313/443
Android Native Layer
Stagefright
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 314/443
Stagefright
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 315/443
StageFright Architecture
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 316/443
StageFright plugins
<Decoders>
<MediaCodec name="OMX.google.vorbis.decoder" type="audio/vorbis" />
<MediaCodec name="OMX.qcom.video.decoder.avc" type="video/avc" />
</Decoders>
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 317/443
Android Native Layer
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 318/443
Whole Android Stack
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 319/443
Dalvik
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 320/443
Zygote
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 321/443
Android Native Layer
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 322/443
Whole Android Stack
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 323/443
Hardware Abstraction Layers
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 324/443
Library naming
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 325/443
Various layers
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 326/443
Various layers
Lights (liblights.so) Backlight and LEDs management
hardware/libhardware/include/lights.h
Sensors (libsensors.so) handles the various sensors on the
device: Accelerometer, Proximity Sensor, etc.
hardware/libhardware/include/sensors.h
Radio Interface (libril-vendor-version.so) manages all
communication between the baseband and rild
You can set the name of the library with the rild.lib and
rild.libargs properties to nd the library
hardware/ril/include/telephony/ril.h
Bluetooth (libbluetooth.so) Discovery and communication
with Bluetooth devices
hardware/libhardware/include/bluetooth.h
NFC (libnfc.so) Discover NFC devices, communicate with
it, etc.
hardware/libhardware/include/nfc.h
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 327/443
Example: rild
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 328/443
Android Native Layer
JNI
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 329/443
Whole Android Stack
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 330/443
What is JNI?
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 331/443
C Code
#include "jni.h"
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 332/443
JNI arguments
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 333/443
Types
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 334/443
Java Code
package com.example;
class Print
{
private static native void print(String str);
static
{
System.loadLibrary("print");
}
}
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 335/443
Calling a method of a Java object from C
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 336/443
Instantiating a Java object from C
return array;
}
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 337/443
Practical lab - Develop a JNI library
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 338/443
Android Framework and Applications
Android
Framework and Embedded Linux
Experts
Applications
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 339/443
Android Framework and Applications
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 340/443
Whole Android Stack
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 341/443
System Server boot
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 342/443
The rst step: system_server.c
Located in frameworks/base/cmds/system_server
Started by Zygote through the SystemServer
Starts all the various native services:
SurfaceFlinger
SensorService
It then calls back the SystemServer object's init2 function to
go on with the initialization
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 343/443
Java Services Initialization
Located in frameworks/base/services/java/com/android/
server/SystemServer.java
Starts all the dierent Java services in a dierent thread by
registering them into the Service Manager
PowerManager, ActivityManager (also handles the
ContentProviders), PackageManager, BatteryService,
LightsService, VibratorService, AlarmManager,
WindowManager, BluetoothService, DevicePolicyManager,
StatusBarManager, InputMethodManager,
ConnectivityService, MountService,
NotificationManager, LocationManager, AudioService,
...
If you wish to add a new system service, you will need to add
it to one of these two parts to register it at boot time
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 344/443
Android Framework and Applications
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 345/443
Whole Android Stack
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 346/443
IPCs
Semaphores
Sockets
Message queues
Pipes
Shared memory
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 347/443
Binder 1/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 348/443
Binder 2/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 349/443
Binder Mechanism
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 350/443
Binder Implementation 1/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 351/443
Binder Implementation 2/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 352/443
Android Interface Denition Language (AIDL)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 353/443
AIDLs HelloWorld
package com.example.android;
interface IRemoteService {
void HelloPrint(String aString);
}
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 354/443
Parcelable Objects
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 355/443
Implement Parcelable Classes
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 356/443
Intents
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 357/443
Android Framework and Applications
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 358/443
Whole Android Stack
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 359/443
Android Java Services
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 360/443
ActivityManager
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 361/443
PackageManager
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 362/443
PowerManager
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 363/443
AlarmManager
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 364/443
ConnectivityManager and WiManager
ConnectivityManager
Manages the various network connections
Falls back to other connections when one fails
Noties the system when one becomes available/unavailable
Allows the applications to retrieve various information about
connectivity
WiManager
Provides an API to manage all aspects of WiFi networks
List, modify or delete already congured networks
Get information about the current WiFi network if any
List currently available WiFi networks
Sends Intents for every change in WiFi state
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 365/443
Example: Vibrator Service
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 366/443
Android Framework and Applications
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 367/443
Why extend it?
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 368/443
PlatformLibraries
LOCAL_SRC_FILES := \
$(call all-subdir-java-files)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE:= com.example.android.pl
include $(BUILD_JAVA_LIBRARY)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 370/443
PlatformLibrary permissions le
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 371/443
PlatformLibrary Client Makele
LOCAL_MODULE_TAGS := optional
LOCAL_PACKAGE_NAME := PlatformLibraryClient
LOCAL_JAVA_LIBRARIES := com.example.android.pl
include $(BUILD_PACKAGE)
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 372/443
Practical lab - Develop a Framework Component
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 373/443
Android Application Development
Android
Application Embedded Linux
Experts
Development
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 374/443
Android Application Development
Basics
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 375/443
Whole Android Stack
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 376/443
Android applications
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 377/443
Applications Security
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 380/443
Manifest HelloWorld
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 381/443
NDK
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 382/443
Android Application Development
Activities
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 383/443
Activities
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 384/443
Back Stack
Credits: http://developer.android.com
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 385/443
Back Stack
Credits: http://developer.android.com
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 386/443
Activity Lifecycle 1/3
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 387/443
Activity Lifecycle 2/3
There are callbacks for every change from one of these states
to another
The most important ones are onCreate and onPause
All components of an application run in the same thread. If
you do long operations in the callbacks, you will block the
entire application (UI included). You should always use
threads for every long-running task.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 388/443
Activity Lifecycle 3/3
Credits: http://developer.android.com
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 389/443
Saving Activity State 1/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 390/443
Saving Activity State 2/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 391/443
Activity Lifecycle
Credits: http://developer.android.com
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 392/443
Activity Callbacks
Credits: http://developer.android.com
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 393/443
Activity HelloWorld
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 394/443
Android Application Development
Services
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 395/443
Services
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 396/443
Service Manifest
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 397/443
Services Types
We can see services as a set including:
Started Services, that are created when other components call
startService. Such a service runs as long as needed, whether
the calling component is still alive or not, and can stop itself or
be stopped. When the service is stopped, it is destroyed by the
system
You can also subclass IntentService to have a started
service. However, while much easier to implement, this service
will not handle multiple requests simultaneously.
Bound Services, that are bound to by other components by
calling bindService. They oer a client/server like interface,
interacting with each other. Multiple components can bind to
it, and a service is destroyed only when no more components
are bound to it
Services can be of both types, given that callbacks for these
two do not overlap completely
Services are started by passing Intents either to the
startService or bindService commands
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 398/443
Services Lifecycle
Credits: http://developer.android.com
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 399/443
Bound Services
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 400/443
Bound Services and Started Lifecycle
Credits: http://developer.android.com
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 401/443
Android Application Development
Content Providers
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 402/443
Content Providers
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 403/443
Content URIs
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 404/443
Implementing a Content Provider
static {
sUriMatcher.addURI("com.example.android.provider", "table1", 1);
sUriMatcher.addURI("com.example.android.provider", "table1/#", 2);
}
switch (sUriMatcher.match(uri)) {
default:
System.out.println("Hello World!");
break;
}
}
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 405/443
Implementing a Content Provider
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 406/443
Android Application Development
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 407/443
Intents
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 408/443
Intent Resolution
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 409/443
Intent Filters 1/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 410/443
Intent Filters 2/2
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 411/443
Real Life Manifest Example: Notepad
<manifest package="com.example.android.notepad">
<application android:icon="@drawable/app_notes"
android:label="@string/app_name" >
<activity android:name="NotesList"
android:label="@string/title_notes_list">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
</intent-filter>
</activity>
</application>
</manifest>
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 412/443
Broadcasted intents
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 413/443
Broadcast Receivers
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 414/443
Android Application Development
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 415/443
Process Management in Android
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 416/443
Processes priority
Foreground processes have the topmost priority. They host
either
An activity the user is interacting with
A service bound to such an activity
A service running in the foreground (started with
startForeground)
A service running one of its lifecycle callbacks
A broadcast receiver running its onReceive method
Visible processes host
An activity that is no longer in the foreground but still is
visible on the screen
A service that is bound to a visible activity
Service Processes host a service that has been started by
startService
Background Processes host activities that are no longer visible
to the user
Empty Processes
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 417/443
Threads
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 418/443
Threads in Android
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 419/443
Android Application Development
Resources
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 420/443
Applications Resources
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 421/443
Resources Directory
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 422/443
Resources
Credits: http://developer.android.com
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 423/443
Alternative Resources
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 424/443
Resources Selection
Credits: http://developer.android.com
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 425/443
Android Application Development
Data Storage
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 426/443
Data Storage on Android
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 427/443
Shared Preferences
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 428/443
Internal Storage
You can also save les directly to the internal storage device
These les are not accessible by default by other applications
Such les are deleted when the user removes the application
You can request a FileOutputStream class to such a new le
by calling the method openFileOutput
You can pass extra ags to this method to either change the
way the le is opened or its permissions
These les will be created at runtime. If you want to have
les at compile time, use resources instead
You can also use internal storage for caching purposes. To do
so, call getCacheDir that will return a File object allowing
you to manage the cache folder the way you want to. Cache
les may be deleted by Android when the system is low on
internal storage.
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 429/443
External Storage
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 432/443
Content of an APK
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 433/443
APK Building
Credits: http://developer.android.com
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 434/443
APK Building
Credits: http://developer.android.com
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 435/443
Practical lab - Write an Application with the SDK
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 436/443
Advices and Resources
Resources
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 437/443
Android Internals
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 438/443
Android Development
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 439/443
Websites
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 440/443
Conferences
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 441/443
Last slides
Embedded Linux
Experts
Last slides
free electrons
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 442/443
Last slide
Thank you!
And may the Source be with you
free electrons - Embedded Linux, kernel, drivers - Development, consulting, training and support. http://free-electrons.com 443/443