Android System Development PDF
Android System Development PDF
Android System
Development
Maxime Ripard
Free Electrons
Free Electrons
Embedded Linux
Developers
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
1/409
Rights to copy
c Copyright 2004-2012, Free Electrons
License: Creative Commons Attribution - Share Alike 3.0
http://creativecommons.org/licenses/by-sa/3.0/legalcode
You are free:
I to copy, distribute, display, and perform the work
I to make derivative works
I to make commercial use of the work
Under the following conditions:
I Attribution. You must give the original author credit.
I Share Alike. If you alter, transform, or build upon this work, you may distribute
the resulting work only under a license identical to this one.
I For any reuse or distribution, you must make clear to others the license terms of
this work.
I Any of these conditions can be waived if you get permission from the copyright
holder.
Your fair use and other rights are in no way affected by the above.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
2/409
For future reference, see the first slide to see where document
updates will be available.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
3/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
4/409
Created in 2004
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
5/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
6/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
7/409
Technical blog:
http://free-electrons.com/blog/
Quarterly newsletter:
http://lists.freeelectrons.com/mailman/listinfo/newsletter
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
8/409
Generic course
information
Free Electrons
Embedded Linux
Developers
Maxime Ripard
Free Electrons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
9/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
10/409
Participate!
During the lectures...
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
11/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
12/409
Cooperate!
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
13/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
14/409
vi basic commands
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
15/409
Introduction to Android
Introduction to
Android
Free Electrons
Embedded Linux
Developers
Maxime Ripard
Free Electrons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
16/409
Introduction to Android
Features
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
17/409
Features
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
18/409
Introduction to Android
History
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
19/409
Early Years
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
20/409
Opening Up
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
21/409
One can fetch the source code and contribute to it, even
though the development process is very locked by Google
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
22/409
Android Releases
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
23/409
Android Versions
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
24/409
Introduction to Android
Architecture
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
25/409
Architecture
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
26/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
27/409
Android Libraries
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
28/409
Android Runtime
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
29/409
Android Framework
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
30/409
Android Applications
However, the Google apps and the Android Market app arent
free software, so they are not available in AOSP. To obtain
them, you must contact Google and pass a compatibility test.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
31/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
32/409
Android Source
Code and
Compilation
Free Electrons
Embedded Linux
Developers
Maxime Ripard
Free Electrons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
33/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
34/409
On this site, along with the code, you will find some resources
such as technical details, how to setup a machine to build
Android, etc.
Google split the source code into a one Git repository per
component
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
35/409
Repo
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
36/409
While you might expect Googles apps for Android, like the
Android Market (now called Google Play Store), to be in the
AOSP as well, these are actually proprietary and you need to
be approved by Google to get them.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
37/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
38/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
39/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
40/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
41/409
Compilation
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
42/409
To start using the build system, you need to include the file
build/envsetup.sh that defines some useful macros for
Android development or sets the PATH variable to include the
Android-specific commands
source build/envsetup.sh
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
43/409
Now, we can get a list of all the products available and select
them with to the lunch command
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
44/409
Compilation
This will run a full build for the current selected product
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
45/409
Contribute
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
46/409
Gerrit
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
47/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
48/409
Linux kernel
introduction
Free Electrons
Embedded Linux
Developers
Maxime Ripard
Free Electrons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
49/409
Linux features
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
50/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
51/409
History
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
52/409
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:
I
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. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
53/409
Compliance to standards
and interoperability.
Exhaustive networking
support.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
54/409
64 bit architectures:
alpha, ia64, sparc64, tile
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
55/409
System calls
This interface is stable over time: only new system calls can
be added by the kernel developers
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
56/409
Virtual filesystems
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
57/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
58/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
59/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
60/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
61/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
62/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
63/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
64/409
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
65/409
Very difficult to find out the key changes and to get the global
picture out of individual changes.
http://wiki.kernelnewbies.org/LinuxChanges
http://lwn.net
http://linuxfr.org, for French readers
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
66/409
Kernel configuration
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
67/409
I
I
Example
I
I
cd linux-2.6.x/
make <target>
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
68/409
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
69/409
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
70/409
Kernel or module?
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
71/409
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
72/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
73/409
make xconfig
make xconfig
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
74/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
75/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
76/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
77/409
78/409
make gconfig
make gconfig
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
79/409
make menuconfig
make menuconfig
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
80/409
make nconfig
make nconfig
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
81/409
make oldconfig
make oldconfig
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
82/409
make allnoconfig
make allnoconfig
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
83/409
A frequent problem:
I
If you dont remember all the changes you made, you can get
back to your previous configuration:
$ cp .config.old .config
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
84/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
85/409
General setup
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
86/409
Allows to select the CPU or machine for which the kernel must
be compiled
On x86, only optimization-related, on other architectures very
important since theres no compatibility
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
87/409
Kernel features
I
Power management
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
88/409
Networking support
I
I
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
89/409
Device drivers
I
I
I
The SCSI core, needed not only for SCSI devices but also for
USB mass storage devices, SATA and PATA hard drives, etc.
SCSI controller drivers
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
90/409
SATA and PATA, the new stack for hard disks, relies on SCSI
RAID and LVM, to aggregate hard drivers and do replication
Network device support, with the network controller drivers.
Ethernet, Wireless but also PPP
Input device support, for all types of input devices: keyboards,
mice, joysticks, touchscreens, tablets, etc.
Character devices, contains various device drivers, amongst
them
I
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
91/409
I
I
Watchdog support
Multifunction drivers are drivers that do not fit in any other
category because the device offers multiple functionality at the
same time
Multimedia support, contains the V4L and DVB subsystems,
for video capture, webcams, AM/FM cards, DVB adapters
Graphics support, infrastructure and drivers for framebuffers
Sound card support, the OSS and ALSA sound infrastructures
and the corresponding drivers
HID devices, support for the devices that conform to the HID
specification (Human Input Devices)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
92/409
USB support
I
I
I
I
I
I
I
I
I
I
Infrastructure
Host controller drivers
Device drivers, for devices connected to the embedded system
Gadget controller drivers
Gadget drivers, to let the embedded system act as a
mass-storage device, a serial port or an Ethernet adapter
MMC/SD/SDIO support
LED support
Real Time Clock drivers
Voltage and current regulators
Staging drivers, crappy drivers being cleaned up
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
93/409
Printers
Scanners
Graphics drivers used by X.org
Some USB devices
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
94/409
File systems
I
I
I
I
I
Kernel hacking
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
95/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
96/409
Kernel compilation
make
I
I
Generates
I
All kernel modules, spread over the kernel source tree, as .ko
files.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
97/409
Kernel installation
I
make install
I
Installs
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
98/409
Module installation
make modules_install
I
kernel/
Module .ko (Kernel Object) files, 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
Module dependencies
modules.symbols
Tells which module a given symbol belongs to.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
99/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
100/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
101/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
102/409
Specifying cross-compilation
The CPU architecture and cross-compiler prefix are defined through
the ARCH and CROSS_COMPILE variables in the toplevel Makefile.
I
Three solutions
I
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
103/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
104/409
Make sure you have the support for the right CPU, the right
board and the right device drivers.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
105/409
Run make
Copy the final kernel image to the target storage
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
106/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
107/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
108/409
Changes
introduced in the
Android Kernel
Free Electrons
Embedded Linux
Developers
Maxime Ripard
Free Electrons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
109/409
Wakelocks
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
110/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
111/409
Wakelocks
I
The main idea is instead of letting the user decide when the
devices need to go to sleep, the kernel is set to suspend as
soon and as often as possible.
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
112/409
Wakelocks API
User-Space API
$ echo foobar > /sys/power/wake_lock
$ echo foobar > /sys/power/wake_unlock
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
113/409
Binder
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
114/409
Binder
RPC/IPC mechanism
Takes its roots from BeOS and the OpenBinder project, which
some of the current Android engineers worked on
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
115/409
Binder
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
116/409
klogger
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
117/409
Logging
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
118/409
Logger
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
119/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
120/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
121/409
Ashmem
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
122/409
Alarm Timers
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
123/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
124/409
Network Security
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
125/409
Paranoid Network
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
126/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
127/409
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 first notifies 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. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
128/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
129/409
Various additions
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
130/409
Android Bootloaders
Android
Bootloaders
Free Electrons
Embedded Linux
Developers
Maxime Ripard
Free Electrons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
131/409
Android Bootloaders
Boot Sequence
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
132/409
Bootloaders
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
133/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
134/409
Can read many filesystem formats to load the kernel image and
the configuration, provides a powerful shell with various
commands, can load kernel images over the network, etc.
See our dedicated presentation for details:
http://free-electrons.com/docs/grub/
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
135/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
136/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
137/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
138/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
139/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
140/409
Android Bootloaders
Fastboot
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
141/409
Definition
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
142/409
I
I
I
I
Transmit data
Flash the various partitions of the device
Get variables from the bootloader
Control the boot sequence
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
143/409
Session example
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
144/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
145/409
erase:%s Erases the given flash partition (sets all the partition
to 0xFF
boot Means that what was last downloaded is a root
filesystem, and instructs to boot on it.
continue Orders the device to continue booting as usual
reboot Reboots the device
reboot-bootloader Reboots back in the bootloader mode
powerdown Powers off the device
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
146/409
Defined variables
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
147/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
148/409
Developing and
Debugging with
ADB
Free Electrons
Embedded Linux
Developers
Maxime Ripard
Free Electrons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
149/409
Introduction
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
150/409
ADB
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
151/409
Implementation
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
152/409
ADB Architecture
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
153/409
Use of ADB
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
154/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
155/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
156/409
logcat Prints the device logs. You can filter 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. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
157/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
158/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
159/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
160/409
Examples
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
161/409
162/409
163/409
Various commands
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
164/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
165/409
Android Filesystem
Android
Filesystem
Free Electrons
Embedded Linux
Developers
Maxime Ripard
Free Electrons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
166/409
Android Filesystem
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
167/409
Filesystems
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
168/409
Filesystems (2)
It is empty
$ ls /mnt/usbkey
$
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
169/409
mount / umount
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
170/409
Root filesystem
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
171/409
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
172/409
Partitions of an SD card
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
173/409
Can have a big root filesystem even if you dont have support
for internal or external storage yet.
The root filesystem can be huge. You can even build native
compiler tools and build all the tools you need on the target
itself (better to cross-compile though).
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
174/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
175/409
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
176/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
177/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
178/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
179/409
I
I
Documentation/filesystems/ramfs-rootfsinitramfs.txt
Documentation/early-userspace/README
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
180/409
Android Filesystem
Contents
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
181/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
182/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
183/409
/system
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
184/409
Other directories
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
185/409
I
I
Located in system/core/include/private/
Contains the full filesystem setup, and is written as a C
header
I
I
I
UID/GID
Permissions for system directories
Permissions for system files
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
186/409
Android Filesystem
Device Files
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
187/409
Devices
Character device
Block device
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
188/409
Types of devices
Block devices
I
Character devices
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
189/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
190/409
/dev/zero
/dev/sda1
/dev/sda2
/dev/tty1
/dev/ttyS0
/dev/zero
Example C code that uses the usual file API to write data to a
serial port
int fd;
fd = open("/dev/ttyS0", O_RDWR);
write(fd, "Hello", 5);
close(fd);
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
191/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
192/409
Android Filesystem
Virtual Filesystems
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
193/409
man proc
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
194/409
proc contents
I
/proc/<pid>
cat /proc/3840/cmdline
It contains details about the files opened by the process, the
CPU and memory usage, etc.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
195/409
sysfs filesystem
I
$ ls /sys/
block bus class dev devices firmware
fs kernel modulepower
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
196/409
Android Filesystem
Minimal filesystem
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
197/409
Basic applications
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
198/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
199/409
Android Build
System
Free Electrons
Embedded Linux
Developers
Maxime Ripard
Free Electrons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
200/409
Basics
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
201/409
Build Systems
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
202/409
First compilation
$ source build/envsetup.sh
$ lunch
Youre building on Linux
Lunch menu... pick a combo:
1. generic-eng
2. simulator
3. full_passion-userdebug
4. full_crespo-userdebug
Which would you like? [generic-eng]
$ make
$ make showcommands
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
203/409
Output
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
204/409
Cleaning
make clean deletes all generated files for the current combo.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
205/409
envsetup.sh
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
206/409
Purpose
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
207/409
ANDROID_EABI_TOOLCHAIN
I
ANDROID_TOOLCHAIN
I
Equals to ANDROID_EABI_TOOLCHAIN
ANDROID_QTOOLS
I
ANDROID_BUILD_PATHS
I
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. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
208/409
JAVA_HOME
I
ANDROID_JAVA_TOOLCHAIN
I
Alias to ANDROID_JAVA_TOOLCHAIN
ANDROID_PRODUCT_OUT
I
ANDROID_PRE_BUILD_PATHS
I
OUT
I
Alias to ANDROID_PRODUCT_OUT
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
209/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
210/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
211/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
212/409
Configuration
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
213/409
lunch
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
214/409
TARGET_PRODUCT
I
TARGET_BUILD_VARIANT
I
TARGET_SIMULATOR
I
TARGET_BUILD_TYPE
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
215/409
buildspec.mk
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
216/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
217/409
Modules
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
218/409
Hello World
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
219/409
Hello World
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
220/409
Tags
I
I
user
I
I
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
221/409
BUILD_EXECUTABLE
I
BUILD_HOST_EXECUTABLE
I
BUILD_JAVA_LIBRARY
I
BUILD_RAW_EXECUTABLE
I
BUILD_STATIC_JAVA_LIBRARY
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
222/409
BUILD_HOST_JAVA_LIBRARY
I
BUILD_HOST_STATIC_LIBRARY
I
BUILD_HOST_SHARED_LIBRARY
I
BUILD_STATIC_LIBRARY
I
BUILD_SHARED_LIBRARY
BUILD_RAW_STATIC_LIBRARY
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
223/409
BUILD_PREBUILT
I
BUILD_HOST_PREBUILT
I
BUILD_PACKAGE
I
BUILD_MULTI_PREBUILT
I
BUILD_KEY_CHAR_MAP
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
224/409
LOCAL_CFLAGS
I
LOCAL_SHARED_LIBRARIES
I
LOCAL_C_INCLUDES
I
LOCAL_PACKAGE_NAME
I
LOCAL_PRELINK_MODULES
I
Does the module uses library pre-linking? (if you set this to
true, you will have to modify
build/core/prelink-linux-arm.map as well)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
225/409
Find files
I
Transform them
Copy them
I
I
transform-c-to-o, ...
copy-file-to-target, ...
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
226/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
227/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
228/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
229/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
230/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
231/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
232/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
233/409
Overlays
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
234/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
235/409
Board Definition
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
236/409
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. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
237/409
TARGET_ARCH_VARIANT
I
TARGET_EXTRA_CFLAGS
I
TARGET_USERIMAGES_USE_EXT4
I
TARGET_CPU_SMP
I
BOARD_SYSTEMIMAGE_PARTITION_SIZE
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
238/409
BOARD_NAND_PAGE_SIZE
I
TARGET_NO_RECOVERY
I
BOARD_KERNEL_CMDLINE
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
239/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
240/409
Android Native
Layer
Free Electrons
Embedded Linux
Developers
Maxime Ripard
Free Electrons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
241/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
242/409
Definition (1)
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
243/409
Definition (2)
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
244/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
245/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
246/409
Components
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
247/409
Binutils
I
I
I
http://www.gnu.org/software/binutils/
GPL license
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
248/409
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
249/409
1
2
3
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
250/409
The kernel headers are extracted from the kernel sources using
the headers_install kernel Makefile target.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
251/409
GCC compiler
http://gcc.gnu.org/
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
252/409
C library
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
253/409
Bionic
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
254/409
Bionic 1/2
I
I
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
255/409
Bionic 2/2
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
256/409
Toolbox
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
257/409
Why Toolbox?
I
I
I
An init program
A shell
Various basic utilities for file manipulation and system
configuration
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
258/409
http://www.busybox.net/
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
259/409
BusyBox commands!
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
260/409
Toolbox
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
261/409
Init
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
262/409
Init
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
263/409
Androids init
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
264/409
Init part
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
265/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
266/409
Syntax
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
267/409
Actions
on <trigger>
command
command
I
boot
I
<property>=<value>
device-added-<path>
I
I
service-exited-<name>
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
268/409
Init triggers
early-init
init
early-fs
fs
post-fs
early-boot
boot
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
269/409
Example
on boot
export PATH /sbin:/system/sbin:/system/bin
export LD_LIBRARY_PATH /system/lib
mkdir /dev
mkdir /proc
mkdir /sys
mount
mkdir
mkdir
mount
mount
mount
write /proc/cpu/alignment 4
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
270/409
Services
Many options, ranging from which user to run the service as,
rebooting in recovery when the service crashes too frequently,
to launching a command at service reboot.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
271/409
Example
on device-added-/dev/compass
start akmd
on device-removed-/dev/compass
stop akmd
service akmd /sbin/akmd
disabled
user akmd
group akmd
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
272/409
Uevent
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
273/409
ueventd.rc syntax
<path>
I
<permission>
<user>
<group>
Example
/dev/bus/usb/*
0660
root
usb
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
274/409
Various daemons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
275/409
Vold
While init was only creating device files and taking some
configured options, vold actually only cares about storage
devices
Its roles are to:
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
276/409
rild
This daemon drives the telephony stack, both voice and data
communication
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
277/409
Others
netd
I
I
I
installd
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
278/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
279/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
280/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
281/409
SurfaceFlinger
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
282/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
283/409
Stagefright
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
284/409
Stagefright
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
285/409
StageFright Architecture
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
286/409
StageFright plugins
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
287/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
288/409
Dalvik
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
289/409
Zygote
frameworks/base/cmds/app_process
At boot, Zygote is started by init, it then
I
I
I
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
290/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
291/409
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
292/409
Library naming
ro.hardware
ro.product.board
ro.board.platform
ro.arch
/vendor/lib/hw
/system/lib/hw
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
293/409
Various layers
I
hardware/libhardware_legacy/include/hardware_
legacy/AudioHardwareInterface.h
frameworks/base/include/camera/
CameraHardwareInterface.h
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
294/409
Various layers
hardware/libhardware/include/lights.h
hardware/libhardware/include/hardware/gps.h
hardware/libhardware/include/sensors.h
You can set the name of the library with the rild.lib and
rild.libargs properties to find the library
hardware/ril/include/telephony/ril.h
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
295/409
Example: rild
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
296/409
JNI
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
297/409
What is JNI?
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
298/409
C Code
#include "jni.h"
JNIEXPORT void JNICALL Java_com_example_Print_print(JNIEnv *env,
jobject obj,
jstring javaString)
{
const char *nativeString = (*env)->GetStringUTFChars(env,
javaString,
0);
printf("%s", nativeString);
(*env)->ReleaseStringUTFChars(env, javaString, nativeString);
}
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
299/409
JNI arguments
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
300/409
Types
I
I
JNI Type
jboolean
jbyte
jchar
jshort
jint
jlong
jfloat
jdouble
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
301/409
Java Code
package com.example;
class Print
{
private static native void print(String str);
public static void main(String[] args)
{
Print.print("HelloWorld!");
}
static
{
System.loadLibrary("print");
}
}
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
302/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
303/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
304/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
305/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
306/409
Android
Framework and
Applications
Free Electrons
Embedded Linux
Developers
Maxime Ripard
Free Electrons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
307/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
308/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
309/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
310/409
Located in frameworks/base/cmds/system_server
I
I
I
I
I
I
SurfaceFlinger
SensorService
AudioFlinger
MediaPlayerService
CameraService
AudioPolicyService
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
311/409
Located in frameworks/base/services/java/com/
android/server/SystemServer.java
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. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
312/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
313/409
IPCs
I
I
I
Signals
Semaphores
Sockets
Message queues
Pipes
Shared memory
Binder
Ashmem and Sockets
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
314/409
Binder 1/2
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
315/409
Binder 2/2
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
316/409
Binder terminology
The Binder
I
Binder Interface
I
A Binder
I
Binder Object
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
317/409
Binder Mechanism
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
318/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
319/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
320/409
I
I
I
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
321/409
AIDLs HelloWorld
package com.example.android;
interface IRemoteService {
void HelloPrint(String aString);
}
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
322/409
Parcelable Objects
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
323/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
324/409
Intents
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
325/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
326/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
327/409
ActivityManager
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
328/409
PackageManager
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
329/409
PowerManager
I
I
PARTIAL_WAKE_LOCK
I
SCREEN_DIM_WAKE_LOCK
I
SCREEN_BRIGHT_WAKE_LOCK
I
Only the CPU is on, screen and keyboard backlight are off
FULL_WAKE_LOCK
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
330/409
AlarmManager
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
331/409
ConnectivityManager
I
WifiManager
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
332/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
333/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
334/409
As you have the code, you could just hack the source to make
the framework suit your needs
This is quite problematic however:
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
335/409
PlatformLibraries
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
336/409
PlatformLibrary Makefile
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
337/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
338/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
339/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
340/409
Android
Application
Development
Free Electrons
Embedded Linux
Developers
Maxime Ripard
Free Electrons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
341/409
Basics
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
342/409
Android applications
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
343/409
Applications Security
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
344/409
Applications Components
I
I
I
Activities
Broadcast Receivers
Content Providers
Services
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
345/409
Application Manifest
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
346/409
Manifest HelloWorld
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
347/409
NDK
However, there are some drawbacks, the main one being that
you cant access the resources mechanism available from Java
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
348/409
Activities
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
349/409
Activities
I
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
350/409
Back Stack
Credits: http://developer.android.com
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
351/409
Back Stack
Credits: http://developer.android.com
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
352/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
353/409
There are callbacks for every change from one of these states
to another
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
354/409
Credits: http://developer.android.com
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
355/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
356/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
357/409
Activity Lifecycle
Credits: http://developer.android.com
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
358/409
Activity Callbacks
Credits: http://developer.android.com
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
359/409
Activity HelloWorld
public class ExampleActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("ExampleActivity", "Activity created!");
}
protected void onStart() {
super.onStart();
}
protected void onResume() {
super.onResume();
}
protected void onPause() {
super.onPause();
}
protected void onStop() {
super.onStop();
}
protected void onDestroy() {
super.onDestroy();
}
}
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
360/409
Services
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
361/409
Services
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
362/409
Service Manifest
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
363/409
Services Types
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
364/409
Services Lifecycle
Credits: http://developer.android.com
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
365/409
Bound Services
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
366/409
Credits: http://developer.android.com
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
367/409
Content Providers
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
368/409
Content Providers
You can use any storage back-end you want, while exposing a
quite neutral and consistent interface to other applications
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
369/409
Content URIs
content://<package>.provider/<path> to access
particular tables
content://<package>.provider/<path>/<id> to access
single rows inside the given table
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
370/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
371/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
372/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
373/409
Intents
I
Component Name
I
Action
I
Category
I
Data
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
374/409
Intent Resolution
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
375/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
376/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
377/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
378/409
Broadcasted intents
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
379/409
Broadcast Receivers
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
380/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
381/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
382/409
Processes priority
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
383/409
Threads
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
384/409
Threads in Android
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
385/409
Resources
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
386/409
Applications Resources
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
387/409
Resources Directory
I
I
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
388/409
Resources
Credits: http://developer.android.com
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
389/409
Alternative Resources
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
390/409
Resources Selection
Credits: http://developer.android.com
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
391/409
Data Storage
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
392/409
But the system cant just let you read and write to any
random file on the system, this would be a major security flaw
I
I
I
I
Preferences
Internal data
External data
Databases
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
393/409
Shared Preferences
They are stored using key-value pairs, but can only store basic
types: int, float, string, boolean
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
394/409
Internal Storage
I
You can also save files directly to the internal storage device
Such files are deleted when the user removes the application
You can pass extra flags to this method to either change the
way the file is opened or its permissions
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
395/409
External Storage
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
396/409
SQLite Databases
I
I
I
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
397/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
398/409
Content of an APK
I
I
I
AndroidManifest.xml
res contains all the resources, compiled to binary xml for the
relevant resources
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
399/409
APK Building
Credits: http://developer.android.com
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
400/409
APK Building
Credits: http://developer.android.com
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
401/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
402/409
Advices and
Resources
Free Electrons
Embedded Linux
Developers
Maxime Ripard
Free Electrons
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
403/409
Android Internals
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
404/409
Android Development
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
405/409
Websites
Android Documentation:
http://developer.android.com/guide/
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
406/409
Conferences
Useful conferences featuring Android topics:
I Android Builders Summit:
https://events.linuxfoundation.org/events/
android-builders-summit
Organized by the Linux Foundation in California (in the
Silicon Valley) in early Spring. Many talks about the whole
Android stack. Presentation slides are freely available on the
Linux Foundation website.
I Embedded Linux Conference:
http://embeddedlinuxconference.com/
Organized by the Linux Foundation: California (Silicon Valley,
Spring), in Europe (Fall). Mostly about kernel and userspace
Linux development in general, but always some talks about
Android. Presentation slides freely available
I Dont miss our free conference videos on http://freeelectrons.com/community/videos/conferences/!
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
407/409
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
408/409
Last slide
Thank you!
And may the Source be with you
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com
409/409