Jaeyong Chung
Systems-on-Chips (SoC) Laboratory
Incheon National University
Embedded System Design
Lecture 11
Android
An operating system based on the Linux kernel
Java is the first-class citizen in Android
Chung EPC6071 2
Java
Java is a computer programming language
Objective-oriented language like C++
Intended to let application developer “write once, run
anywhere (WORA)”
Code that runs on one platform does not need to be recompiled
to run on another
Java applications are compiled to bytecode (class file)
that can run on any Java virtual machine (JVM)
regardless of computer architecture
Java Standard Libraries: Java ME, Java SE, Java EE
Chung EPC6071 3
Java
JNI (Java Native Interface) is a programming framework
that enables Java code running in a Java Virtual
Machine to call and be called by native applications
Chung EPC6071 4
Porting android to your embedded system
Let’s say you create a novel ES and you want to run
android on your ES
As of January 2014, current Android versions are built
upon Linux Kernel 3.4 or later
Chung EPC6071 5
Porting android to your embedded system
Download the kernel source
(http://source.android.com/source/building-kernels.html)
$ git clone https://android.googlesource.com/kernel/exynos.git
The exynos project has the kernel sources for Nexus 10, and can be
used as a starting point for work on Samsung Exynos chipsets
Download the toolchain
$ git clone
https://android.googlesource.com/platform/prebuilts/gcc/linux-
x86/arm/arm-eabi-4.6
Make
Chung EPC6071 6
Android 4.0 ICS on Raspberry PI
Chung EPC6071 7
System Architecture
An application framework consists of a software
framework used by software developers to implement the
standard structure of an application
Chung EPC6071 8
Typical Directory Tree of Android
Chung EPC6071 9
Inter-process Communication
In GNU/ Linux Signal
Pipe
Socket
Semaphore
Message Queue
Shared memory
In Android Binder: lightweight Remote Procedure Call (RPC)
mechanism
Chung EPC6071 10
Binder IPC
Driver to facilitate inter-process communication
High performance through shared memory
Synchronous calls between processes
“In the Android platform, the binder is used for nearly
everything that happens across processes in the
core platform” – Dianne Hackborn
Chung EPC6071 11
Low-level System Architecture
If you have a new IO device
Develop a linux device driver
Develop hardware abstraction layer
Linux Kernel
For the most part, developing your
device drivers is the same as
developing a typical Linux device
driver
Hardware abstraction layer (HAL)
Hides the lower-level implementations
of your drivers and hardware
Built into shared library modules (.so
files)
Chung EPC6071 12
Bluetooth Example
Chung EPC6071 13
Sensor Example
If you have a new type of sensor in your ES, you need to
implement the following the HAL interface in addition to
your device driver:
Chung EPC6071 14
Developing Android Applications
Android applications are written in Java
Download SDK
(http://developer.android.com/sdk/index.html)
Includes Android API and tools
Eclipse is a java-based integrated development
environment (IDE)
Android Develop Tools (ADT) is an Eclipse plugin
Android applications are usually developed using Eclipse
+ ADT plugin
ADT bundle includes
A version of Eclipse
ADT plugin
Chung EPC6071 15
Dalvik VM
Dalvik is a java virtual machine in Google’s android
operating system
Takes .dex (Dalvi Excutable) and odex (Optimized Dalvik
Exectuable) files instead of .class (Java bytecodes)
A tool called dx is used to convert some Java .class files into the
.dex format
Unlike Java VMs, which are stack machines, the Dalvik
VM uses a register-based architecture
/system/bin/dalvikvm
Similar to usual ‘java’ command
Try ‘dalvikvm –h’ to show command line help
Chung EPC6071 16
App Component: Activity
An application component that provides a screen with
which users can interact in order to do something, such
as dial the phone, take a photo, send an email, or view a
map.
An activity can start other activities, including activities that live
in separate applications.
Unlike other programming paradigms in which apps are
launched with a main() method, android applications
should be implemented using an application framework
called activity
Chung EPC6071 17
App Component: Service
A Service is an application component that can perform
long-running operations in the background without a user
interface. For example, a service can handle network
transactions, play music, or work with a content provider
without the user being aware of the work going on
Chung EPC6071 18
Developing Android Applications in C or C++
Native Development Kit (NDK)
Allows you to implement parts of your app using native-code
languages such as C and C++
The purpose is to create native libraries, not programs
The native libraries are called from Java via JNI
Even if you really want an app to be in C or C++ entirely,
you need to write at least a tiny Java class that will call
your native library immediately
Google already made a generic java class like that
which is NativeActivity
Chung EPC6071 19
Developing Android Applications in C or C++
Porting existing applications into android platform using
NDK would be a fun project
Although it is not recommended by Google
http://blog.stuff-o-matic.com/
Chung EPC6071 20
Boot Sequence
Daemon is a computer program that runs as a background process
Chung EPC6071 21
System Services
Chung EPC6071 22
Zygote
Chung EPC6071 23
Zygote
Zygote process preloads typical (approx. 1800) classes
and dynamic libraries so that children start quickly
Copy-on-write
Only when new process writes page, new page is allocated
All pages not be written are shared among all zygote children
Exec system call is not used in zygote
Exec wipes the page mapping table of the process
It means exec discards zygote cache
Chung EPC6071 24
Bionic
Standard C/C++ library
Libc, libm, ptrhead, dynamic linker
BSD license is a non-copyleft license and Google wished
to isolate Android applications from the effects of both
the GPL and the LGPL
The most widespread standard C libraries for the Linux kernel
are the GNU C Library and uClibc, which are both subject to the
GNU Lesser General Public License (LGPL); in contrast to the
GPL, the LGPL explicitly allows for dynamic linking but it does
not allow static linking of proprietary software
Smaller size than GNU C library
Bonic is designed for CPUs at relatively low clock frequencies
Chung EPC6071 25
UID, GID of applications
UID(user id) and GID (group id) is used for managing
multi-user in usual Linux system
Android use this mechanism to isolate applications
Each application has UID
Can not read/write other application’s files
Zygote is running as UID=0 (root)
After forking child process, its UID is changed by setuid system
call
Chung EPC6071 26
adb
Android Debug Bridge (adb) is a versatile command line tool
that lets you communicate with an emulator instance or
connected Android-powered device
A client-server program that includes three components
A client, which runs on your development machine. You can invoke a
client from a shell by issuing an adb command.
A server, which runs as a background process on your development
machine. The server manages communication between the client and
the adb daemon running on an emulator or device
A daemon, which runs as a background process on each emulator or
device instance
Adb is usually used over USB. However, it is also possible to
use over Wi-FI
After forking child process, its UID is changed by setuid system call
Chung EPC6071 27
adb
Data
$ adb install <path-to-apk>
$ adb pull <remote> <local>
$ adb push <local> <remote>
Debug
$ adb logcat [option] [filter-specs]
Shell
$ adb shell
$ adb shell [shellCommand]
Chung EPC6071 28
Android Logging System
Chung EPC6071 29