Professional Documents
Culture Documents
Textbook Learning Embedded Android N Programming 1St Edition Ivan Morgillo Ebook All Chapter PDF
Textbook Learning Embedded Android N Programming 1St Edition Ivan Morgillo Ebook All Chapter PDF
https://textbookfull.com/product/rxjava-essentials-1st-edition-
morgillo-ivan/
https://textbookfull.com/product/asynchronous-android-
programming-helder-vasconcelos/
https://textbookfull.com/product/prolog-programming-for-
artificial-intelligence-ivan-bratko/
https://textbookfull.com/product/programming-with-micropython-
embedded-programming-with-microcontrollers-and-python-1st-
edition-nicholas-h-tollervey/
Stm32 Arm Programming for Embedded Systems 1st Edition
Muhammad Ali Mazidi
https://textbookfull.com/product/stm32-arm-programming-for-
embedded-systems-1st-edition-muhammad-ali-mazidi/
https://textbookfull.com/product/programming-with-micropython-
embedded-programming-with-microcontrollers-and-python-first-
edition-nicholas-h-tollervey/
https://textbookfull.com/product/intermediate-c-programming-for-
the-pic-microcontroller-simplifying-embedded-programming-hubert-
henry-ward/
https://textbookfull.com/product/android-programming-the-big-
nerd-ranch-guide-2nd-edition-bill-phillips/
https://textbookfull.com/product/programming-microcontrollers-
with-python-experience-the-power-of-embedded-python-1st-edition-
armstrong-subero/
www.allitebooks.com
Learning Embedded Android N
Programming
Ivan Morgillo
Stefano Viola
BIRMINGHAM - MUMBAI
[ FM-1 ]
www.allitebooks.com
Learning Embedded Android N Programming
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78528-288-1
www.packtpub.com
[ FM-2 ]
www.allitebooks.com
Credits
Copy Editors
Dipti Mankame
Laxmi Subramanian
[ FM-3 ]
www.allitebooks.com
About the Authors
He is also the author of RxJava Essentials, by Packt Publishing and Grokking Rx, by
Manning Publications.
[ FM-4 ]
www.allitebooks.com
About the Reviewer
[ FM-5 ]
www.allitebooks.com
www.PacktPub.com
At www.PacktPub.com, you can also read a collection of free technical articles, sign
up for a range of free newsletters and receive exclusive discounts and offers on Packt
books and eBooks.
TM
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser
[ FM-6 ]
www.allitebooks.com
Table of Contents
Preface ix
Chapter 1: Understanding the Architecture 1
An overview of the Android system 2
Linux kernel 3
Hardware abstraction layer – HAL 4
Libraries and the application framework 5
Libraries 5
The application framework 5
Binder IPC 6
The application layer 6
Android compatibility 7
The Android Compatibility Definition Document 8
Device types 8
Software compatibility 9
Beyond Java 10
Native API 10
Maintaining 32-bit support 11
From Dalvik to ART runtime 12
The Android runtime 13
A new old approach – AOT compilation 14
Garbage collection and other improvements 14
Waiting for Android Nougat 15
Meeting the Compatibility Test Suite 16
CTS setup 19
Device setup 19
Media files setup 20
Run! 22
Analyzing the test results 23
[i]
www.allitebooks.com
Table of Contents
[ ii ]
www.allitebooks.com
Table of Contents
[ iii ]
www.allitebooks.com
Table of Contents
[ iv ]
Table of Contents
[v]
Table of Contents
[ vi ]
Table of Contents
[ vii ]
Preface
Android has caused one of the greatest revolutions of our time. Being present
on smartphones, TV, tables, watches, embedded boards, it can be considered
ubiquitous. Its open source nature gives companies, expert users, and hackers the
opportunity to learn from, improve, and customize the system, creating a tailored
version of the most popular mobile operating system.
This book is a journey from the origins of the Android project to what's in the future,
walking through all the phases needed to build a custom Android system from
source and from binary images.
Chapter 2, Obtaining the Source Code – Structure and Philosophy, explains the Android
Open Source Project.
Chapter 3, Set up and Build – the Emulator Way, teaches how to set up the build
environment and build a system image for the Android Emulator.
Chapter 4, Moving to Real-World Hardware, tells you about how to build a real device
and how to flash the system image.
Chapter 5, Customizing Kernel and Boot Sequence, dives into kernel and boot sequence
customization, in order to tailor the perfect system.
Chapter 6, "Cooking" Your First ROM, discusses about custom recovery images,
root privileges, and Android Kitchen.
[ ix ]
Preface
Chapter 7, Tailoring Your Personal Android System, discusses hacking the Android
framework, adding apps, and optimizing the system.
Chapter 8, Beyond the Smartphone, discusses what's next, what the Android
possibilities are once you step away from the smartphone world.
More about Android N Programming: In this chapter, you will find some more
information about Android N Programming at https://www.packtpub.com/
sites/default/files/downloads/MoreaboutAndroidNProgramming.pdf.
Conventions
In this book, you will find a number of text styles that distinguish between different
kinds of information. Here are some examples of these styles and an explanation of
their meaning.
Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows:
"We can include other contexts through the use of the include directive."
New terms and important words are shown in bold. Words that you see on
the screen, for example, in menus or dialog boxes, appear in the text like this:
"Clicking the Next button moves you to the next screen."
[x]
Preface
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or disliked. Reader feedback is important for us as it helps
us develop titles that you will really get the most out of.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide at www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
1. Log in or register to our website using your e-mail address and password.
2. Hover the mouse pointer on the SUPPORT tab at the top.
3. Click on Code Downloads & Errata.
4. Enter the name of the book in the Search box.
5. Select the book for which you're looking to download the code files.
6. Choose from the drop-down menu where you purchased this book from.
7. Click on Code Download.
[ xi ]
Preface
You can also download the code files by clicking on the Code Files button on the
book's webpage at the Packt Publishing website. This page can be accessed by
entering the book's name in the Search box. Please note that you need to be
logged in to your Packt account.
Once the file is downloaded, please make sure that you unzip or extract the folder
using the latest version of:
The code bundle for the book is also hosted on GitHub at https://github.com/
PacktPublishing/Learning-Embedded-Android-N-Programming. We also
have other code bundles from our rich catalog of books and videos available
at https://github.com/PacktPublishing/. Check them out!
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you could report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/submit-errata, selecting your book, clicking on the Errata Submission Form
link, and entering the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded to our website or
added to any list of existing errata under the Errata section of that title.
Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all
media. At Packt, we take the protection of our copyright and licenses very seriously.
If you come across any illegal copies of our works in any form on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
[ xii ]
Preface
We appreciate your help in protecting our authors and our ability to bring you
valuable content.
Questions
If you have a problem with any aspect of this book, you can contact us at
questions@packtpub.com, and we will do our best to address the problem.
[ xiii ]
Understanding the
Architecture
In this chapter, the user will learn about Android hardware and software
architecture. We will provide an overview on the Android Compatibility Definition
Document to properly understand what we need in order to create a fully compliant
and certified device.
The user will learn about the Android Application Framework (AAF), the two
different Android runtime systems—Dalvik, and ART, and a collection on
Google-provided system libraries.
The user will have a first hands-on moment, setting up and running Android
Compatibility Test Suite. We will test together an existing certified device and
we will take the first step on the path towards the creation of a certified device.
[1]
Understanding the Architecture
• Linux kernel
• Hardware abstraction layer
• Core libraries and runtime environment
[2]
Chapter 1
• Application framework
• Binder IPC
• Applications
The software layer closest to the hardware architecture is the Linux kernel. This layer
is in charge of communicating with the hardware components and provides an
easy-to-use interface for the layer above.
Moving up on the architecture path, we have Android runtime and core libraries.
This layer provides the basics tools for the application framework. The application
framework is a collection of ready-to-use components that the system provides to the
Applications layer via the Android SDK. The top layer contains all those applications
we use everyday—games, productivity apps, multimedia, and so on.
Linux kernel
Android is based on the Linux kernel, but it's not a classic Linux-based desktop
system: it's not Ubuntu. However, Android architecture designers and developers
rely on the Linux kernel, because it's open source, it's extensively tested worldwide,
and it can be easily tailored to fit Android-specific hardware needs, on any kind
of device.
From a very pragmatic point of view, choosing to base the system on an open source
heart reinforced the Android philosophy of being an open system, supported by its
community and trusted by enterprise companies, thanks to its transparency. Besides,
this approach saved a lot of development time—they didn't have to start from
scratch and they could focus on the rest of the architecture, taking advantage
of a popular and well-documented core.
The vanilla Linux kernel needed some love to properly fit all the Android
requirements. Most of the contributions by Google were focused on:
• Fixing bugs
• Enabling new hardware
• Improving power management
• Improving error reporting
• Improving performance
• Improving security
[3]
Understanding the Architecture
From a hardware point of view, the Android team made a great effort to add new
goodies to the Linux kernel. Lots of fixes and hacks were released to improve
Bluetooth support and management, lots of General Purpose Input/Output (GPIO)
drivers were added, ARM compatibility was enhanced, as ARM was the primary
Android-supported architecture and also MMC management received lots of
contributions. The new ADB gadget driver was added to help developers
to communicate via USB with external devices.
From a memory point of view, the Android team introduced PMEM, the process
memory allocator. This gave the ability to manage large physically contiguous
memory regions between user space and kernel space. Working in a specific
low-resource hardware domain, the Android team released Ashmem, Android
Shared Memory, which targeted low-memory devices and provided an easy-to-use
file-based API to manage shared memory, especially under memory pressure.
The other interesting contributions were the kernel support for Android logcat
command, that provides logs of system messages, application debug messages, and
exceptions, and Android Binder, an Android-specific interprocess communication
system, used for remote method invocation too.
As a mid-level layer between the hardware and the system, Android HAL is
commonly developed using native technology—C/C++ and shared libraries. There
is no constraint from Google about how we need to implement our HAL and our
device drivers: it's up to us to design it as we think best for our scenario. There is
only one simple rule:
Our implementation must provide the same interface that the system is expecting.
[4]
Chapter 1
Libraries
Android system libraries are a set of libraries, specifically created to work on
Android, to allow and help with system components and app development.
The most important are:
• SQLite: SQLite is the entry point to the SQL world. It's a tiny SQL
implementation for embedded systems and it provides a standard way to
access data published by content providers or SQL DB created by the user.
• SSL: SSL provides the standard security environment for network
communication.
• OpenGL: OpenGL libraries are the link between the Java (and C/C++ JNI)
world and the OpenGL/ES 3D graphics rendering API.
• SGL: SGL provides a way to access 2D rendering engine.
• Media framework: Media framework provides codecs for rendering,
recording, and playback for the most common media formats.
• WebKit: WebKit is the popular HTML rendering engine.
• libc: The libc library is a BSD-derived implementation of the standard C
library, specifically tuned to best perform on embedded Linux-based devices.
• Surface manager: Surface manager manages access to the display subsystem.
• Activity manager: This provides the navigation backstack and manages the
Android activity lifecycle
• Resource manager: This provides access to noncode resources contained in
the apps: graphics, localized string, styles, and colors
[5]
Understanding the Architecture
Everything on Android is achieved using the official Android SDK that provides a
consistent and documented way to use all these system managers, views, and logic
components to let you create the next big hit of the Google Play Store.
Binder IPC
From an Application Framework point of view, the Binder Inter-Process
Communication (IPC) is a hidden layer. It takes care of creating a transparent
communication channel between the high-level Android API, accessible via the
Android SDK, and the actual Android system.
Usually, this relies on a read/write area of the handset solid memory, but for
software provided by manufacturers, typically, it uses a read-only memory area to
be sure that these applications will always be installed no matter what. Apps such as
Google Maps, YouTube, Samsung TouchWiz Nature, and HTC Sense are examples
of apps in this very group: they are shipped with the device's operating system, they
are installed on a read-only memory area of the device, and they are meant to be
uninstallable as a core component of the system.
As we will see, this is not 100% true—once you have the proper skill set, you will
be able to manipulate the whole system. In the following chapters, you will acquire
these skills and you will learn how to heavily modify an already existing Android
version and get rid of those apps, if necessary.
[6]
Chapter 1
Android compatibility
Every successful Android device on the market, before being launched, has been
certified. Manufacturers have designed, developed, and tested their device according
to precise guidelines, rules, and constraints.
To make the task as easy as possible, Google has created the Android Compatibility
Program that defines details and tools that help OEMs to create a device that will
properly support the OS, the SDK, and the developers' expectations:
[7]
Understanding the Architecture
For each release of the Android platform, Google provides a detailed CDD. The CDD
represents the policy aspect of Android compatibility and its role is to codify and
clarify all the requirements and eliminate any ambiguity. The main goal is to provide
rules for manufacturers to let them create complex hardware devices, compatible
with Android SDK and Android apps.
Designing and developing a new device is no easy task. Even the smallest detail
matters. Think about OpenGL support. There is no possible way to be sure that
the graphical experience will be great for the user. The only thing that's possible
is working according to the guidelines and then "test, test, and test". That's why
providing as many details and guidelines as possible is the only way to help the
manufactures to achieve their goal.
However, the CDD does not attempt to be comprehensive—it couldn't be. It just
serves as guidance to approach as easily as possible the final goal—a compatible
device. Further help comes from the source code itself and from the Android SDK
API that can be considered a compatibility-proof test bench. Think about CDD as an
overview of the minimum set of constraints to be compliant with: it's the very first
step of the journey.
Device types
In the beginning, Android was born to run on digital cameras. Luckily for us, a lot
has happened since then: smartphones invaded our world! Then we had tablets and
MP3 players. Nowadays, we have TVs, watches, media centers, glasses, and even
cars, running Android and Android apps. Every device on the market will probably
land in one specific category, according to its features. CDD gives a few pointers
about which category your new device would be placed in:
[8]
Another random document with
no related content on Scribd:
operculum of Limulus (Fig. 153, 10). The form of the operculum,
more particularly of the median process, differs in the male and
female. In that which is believed to be the female (Fig. 162) the
median process is long, and extends beyond the posterior margin of
the operculum; it is formed of two small five-sided parts at the base
which are united at the sides to the two plates of the operculum;
behind this is a long, unpaired part, which is pointed in front; this,
together with the remaining parts, is not joined to the side-plates of
the operculum, so that the latter are here separated from one
another. The third part of the median process is shorter than the
second, and bears at its end a pair of small pointed and diverging
plates, the tips of which reach to the middle of the third plate-like
appendages. On the inner side of the operculum there are, in the
female, a pair of curved, tubular organs, attached to the anterior end
of the median process, where they open, the free ends being closed;
the function of these organs is not known, but was probably sexual.
In the male (Fig. 163, A, a) the median process is formed of two
parts only, and is very short, so that the two plates of the operculum
unite behind the process.
In the female a median process (Fig. 163, B) is also present
between the second pair of appendages (belonging to the third
segment of the mesosoma); it consists of a basal unpaired part, and
of a pair of long pointed pieces which project on to the next segment.
Just as in the case of the genital operculum the basal part is united in
front to the appendages, the remainder being free, and separating
the greater part of the two plate-like appendages. In the complete
animal the median process of this segment is covered by the median
process of the genital operculum. The remaining appendages of the
female, and all the appendages behind the operculum in the male,
are without any median process, and the plates of each pair unite by
a suture in the middle line.
Fig. 163.—Eurypterus fischeri, Eichw. Upper Silurian. (After
Holm.) A, Genital operculum of male; a, median process. B,
Middle part of second appendage of the mesosoma in the female,
showing the median process.
BY
SUB-CLASS II.—EMBOLOBRANCHIATA.[238]
Order I. Scorpionidea.
External Structure.
Internal Anatomy.
Classification.
More than 350 species of scorpions have been described, but many
of these are “doubtful,” and probably the number of known forms
may be put at about 300. These are divided by Kraepelin[247] into six
families and fifty-six genera. The best indications of the family of a
scorpion are to be found in the shape of the sternum, the armature of
the tarsi, and the number of the lateral eyes, while assistance is also
to be derived from the shape of the stigmata and of the pectines, and
from the absence or presence of a spine beneath the aculeus.
The six families are: Buthidae, Scorpionidae, Chaerilidae,
Chactidae, Vejovidae, and Bothriuridae.
Fam. 1. Buthidae.—Sternum small and generally triangular.
Tibial spurs in the third and fourth legs. Generally a spur beneath
the aculeus. Lateral eyes three to five in number.
There are two sub-families: Buthinae and Centrurinae.
The Buthinae, which possess a tibial spur, comprise fourteen
genera, most of them Old World forms. The principal genera are
Buthus, which contains about 25 species, and Archisometrus with 20
species. One genus only, Ananteris, is South American, and it
includes only a single species. The genus Uroplectes, with 16 species,
is almost entirely African.
The Centrurinae, without tibial spur, are New World scorpions,
though Isometrus europaeus (maculatus) is cosmopolitan. The
principal genera are Tityus with 30 species, Centrurus with 13, and
Isometrus with 6.
Fam. 2. Scorpionidae.—Sternum broad and pentagonal, with
sides approximately parallel. No tibial spur, but a single pedal spur.
Generally three lateral eyes.
Nearly a hundred species of Scorpionidae have been described,
distributed among fifteen genera. The following sub-families are
recognised: Diplocentrinae, Urodacinae, Scorpioninae,
Hemiscorpioninae, and Ischnurinae.
The Diplocentrinae have a spur under the aculeus. They form a
small group of only eight species. The principal genus, Diplocentrus,
is entirely Neotropical, but Nebo has a single Old World
representative in Syria.
The Urodacinae, with the single genus Urodacus, are Australian
scorpions. As in the next sub-family, there are rounded lobes on the
tarsi, but there is only a single keel on the “tail,” and the lateral eyes
are two in number. Six good and three doubtful species are
recognised.
The Scorpioninae are Asiatic and African forms, and are
recognised by the tarsi having a large lobe on each side, by the
convex upper surface of the “hand,” by the presence of two median
keels on the “tail,” and by the possession of three lateral eyes.
Palamnaeus (Heterometrus) has sixteen species in the Indian
region. There are about thirty species of Opisthophthalmus, all
natives of South Africa. Pandinus includes about ten species, but
there are only two species of the type genus Scorpio, S. maurus and
S. boehmei.
The sub-family Hemiscorpioninae was formed for the reception of
the single Arabian species Hemiscorpion lepturus. Its most striking
characteristic is the cylindrical vesicle of the tail in the male.
The Ischnurinae differ from the Scorpioninae chiefly in the
absence of the tarsal lobes, the presence of a well-marked finger-keel,
and the generally more depressed form of the body and hand. In the
opinion of some authors they should be separated from the
Scorpionidae as a distinct family, the Ischnuridae. There are more
than twenty species, divided among six genera. The type genus
Ischnurus has only the single species I. ochropus. There are eight
species of Opisthacanthus, which has representatives in Africa and
America.
Fam. 3. Chaerilidae.—Sternum pentagonal with median
depression or “sulcus” rounded posteriorly. Two pedal spurs.
Stigmata circular. Two lateral eyes with a yellow spot behind the
second. Pectines very short.
This small family has the single genus Chaerilus with but seven
species, natives of the Oriental region.
Fam. 4. Chactidae.—Two pedal spurs. Two lateral eyes (or,
rarely, no eyes) but without yellow spot. Characteristic dentition on
movable finger of “hand.”
There are three sub-families, Megacorminae, Euscorpiinae, and
Chactinae.
The Megacorminae include but a single Mexican form,
Megacormus granosus. There is a single toothed keel under the
“tail,” and all the under surface is spiny. There is a row of long
bristles under the tarsus.