0% found this document useful (0 votes)
4K views23 pages

Inside The Android Framework 2

In Android Anatomy – System Service (Subtitle: Inside the Android Framework 2), the authors analyze in depth the operating principles behind Android’s native system services, the essential components that constitute the Android platform. The authors, who have extensive work experience in related IT industries, analyzed the source codes themselves and verified their findings on Android smartphones (Nexus OneTM, Nexus STM). The book provides abundant technical discussions on Android application development for interested IT professionals or SDK/NDK/PDK developers. This book focuses on the components that comprise the software stack in the Android platform known as “Android Anatomy.” To be specific, the following native system services are discussed: Surface Flinger, which deals with the screen; Audio Flinger, which deals with sounds; Camera Service, used when taking photos or recording videos; and Media Player and Media Record Service, which play and record MP3 and video files. Using this book, readers will obtain an in-depth understanding of the inner workings of Android, add and modify new functions and develop applications with advanced functions.

Uploaded by

agile_excy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX or read online on Scribd
0% found this document useful (0 votes)
4K views23 pages

Inside The Android Framework 2

In Android Anatomy – System Service (Subtitle: Inside the Android Framework 2), the authors analyze in depth the operating principles behind Android’s native system services, the essential components that constitute the Android platform. The authors, who have extensive work experience in related IT industries, analyzed the source codes themselves and verified their findings on Android smartphones (Nexus OneTM, Nexus STM). The book provides abundant technical discussions on Android application development for interested IT professionals or SDK/NDK/PDK developers. This book focuses on the components that comprise the software stack in the Android platform known as “Android Anatomy.” To be specific, the following native system services are discussed: Surface Flinger, which deals with the screen; Audio Flinger, which deals with sounds; Camera Service, used when taking photos or recording videos; and Media Player and Media Record Service, which play and record MP3 and video files. Using this book, readers will obtain an in-depth understanding of the inner workings of Android, add and modify new functions and develop applications with advanced functions.

Uploaded by

agile_excy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX or read online on Scribd
You are on page 1/ 23

This document includes the following contents:

Inside the Android Framework 1, 2 Introduction Authors Preface Publishers Review Intended Readers Introducing the authors Table of Contents

Inside the Android Framework 2


This is the first book to examine the operating principles behind critical components of the Android platform.

Introduction
In Android Anatomy System Service (Subtitle: Inside the Android Framework 2), the authors analyze in depth the operating principles behind Androids native system services, the essential components that constitute the Android platform. The authors, who have extensive work experience in related IT industries, analyzed the source codes themselves and verified their findings on Android smartphones (Nexus OneTM, Nexus STM). The book provides abundant technical discussions on Android application development for interested IT professionals or SDK/NDK/PDK developers. This book focuses on the components that comprise the software stack in the Android platform known as Android Anatomy. To be specific, the following native system services are discussed: Surface Flinger, which deals with the screen; Audio Flinger, which deals with sounds; Camera Service, used when taking photos or recording videos; and Media Player and Media Record Service, which play and record MP3 and video files. Using this book, readers will obtain an in-depth understanding of the inner workings of Android, add and modify new functions and develop applications with advanced functions.

Authors Preface
After writing the book Inside the Android Framework, which covered the fundamental operating principles behind Android platform, our intellectual curiosity shifted to the subject of how the system services actually operate on those principles. However, analyzing the Android platform source codes required a study group with diverse technical backgrounds and experiences. In addition, the number of codes required in actual service implementation, compared to the codes that implement basic service components, was much more extensive in real life than expected, being anywhere between 10 to 100 times larger in terms of size. However, we were undaunted by the magnitude of the task in front of us and pursued our challenge with determination. So we looked everywhere to find some help to get things going and eventually discovered a reference book the only book in the market at the time and even until now

that explained the workings of Android native system services.

So we recruited members for a study group, hired professional translators and conducted research and analysis over a three-month period. However, the result was not satisfactory. Unlike the members who had participated in writing Inside the Android Framework the new study members were not familiar with the Android platform and in the end had not developed sufficient interest to pursue the project further. In effect, the project failed. However, undaunted, we decided to give it another chance based on what we had learned from our failure. So we formed another group of people who were actually working on the Android platform in their professional careers and who were also interested writing the book.

This time, however, the reference book that we had discovered and had been using as a reference became an issue. As the analysis progressed and the members knowledge of the subject matter expanded, they started complaining about the limited information contained in the book, the most significant complaint being that the book did not have sufficient explanations about the materials pertinent to our study. Also, the platform version on which the book had been based was already outdated and did not reflect the most recent changes in the platform. As we passed the three-month mark in our study, we were beginning to fear the prospect of another failure, around which time I recalled what Robert Love, the author of Linux Kernel Development, said: Kernel developers are not afraid of rewriting a lot of code for the sake of perfection.

Thats right. Lets write Inside the Android Framework 2, I declared.

Flashing a photo of Robert Love for moral support and using some half-coercive measures, I eventually succeeded in convincing our study group members that we too could become programming heroes like those legendary Linux kernel developers. So began our new adventure. Inside the Android Framework 2 is a compilation of knowledge and experience that we gained against all odds the new and unfamiliar intellectual territory called the Android platform, Googles rapid version upgrade and the users constant demand to catch up with the latest update. This is also a precious outcome resulting from many failures in our search for a successful analysis of the Android platform.

Like the previous volume, Inside the Android Platform 2 is based on Patrick Bradys Anatomy & Physiology of an Android, presented at the 2008 Google IO. If the previous volume focused on Android physiology, this book concentrates on its anatomy. In particular, it concentrates on the operating principles of Media Framework Service such as Surface Flinger and Audio Flinger, the unique native services of the Android platform.

In addition, this book provides explanations of topics that are critical to Android platform development Binder IPC, data sharing techniques among processes, simultaneous control, permission, power management, native library and debugging methods. There were no changes in these from platform

version 1.6 to 2.3 and we expect no significant changes in the future either. For developers who work in the fields related to Android, we sincerely hope that this book will be of great use to their work.

Publishers Review
A must-read for those who are interested in Android platform analysis: A great sequel to the highly successful Inside the Android Platform.

For those who found Inside the Android Platform exciting, this is a must-read. In particular, this book will be pleasure to those who are curious to learn about the operating principles of the Android platform and put them in use. Most of the authors who participated in writing Inside the Android Platform got together again to tell untold stories from the first volume. Also, all of our authors are working professionals in the relevant subject fields, and the book is filled with knowledge that can be applied to your tasks at work. The Anatomy of Android System Service section concentrates on describing the software stack component of the Android platform, which is also known as the Anatomy of Android. Each group member was assigned a section of the system services for which he was responsible, analyzed the platform source codes, examined the references, discussed the findings with each other and verified the results of the analysis on Nexus OneTM and Nexus STM, the Android smartphones. Also, the book selects and explains in detail only the most critical subjects among fundamental Android programming principles and key points in the development process that encompass the entire platform.

This book is the precious result of much trial and error the authors labored through.

It also contains all

of our excitement and joy as we spent thousands of hours analyzing platform source codes, setting up hypotheses, and proving them true one by one. We wrote this book with Android developers in mind and from their perspective. We wanted to reduce as much as possible any of their fears about starting Android applications development, and wrote this book so that they wouldnt have to go through the same trial and error we did.

This book covers essential Android system services using Android platform source codes. For developers who are involved in the development of embedded system applications built on the Android platform, we hope this book will help them to customize the Android platform for their specific development goals and produce products that are differentiated from those of their competitors. We also recommend this book for those who would like to gain a deeper understanding of the Android platform or develop their own customized products.

Intended Readers
Readers are expected to have either a computer science degree or some background knowledge in Linux, C, C++ and Java. They dont have to be a specialist in each area but must have fundamental computer science knowledge. Accordingly, coverage of the above-mentioned topics was limited to a minimum level in this book. The subject of the Android platform being vast, it was hard enough to treat the main subject

alone. Also, there are many good references in the market treating the subjects of Linux, C, C++ and Java, so we assumed that readers would be able to acquire relevant knowledge and information without difficulty, if necessary.

Also, we did not assume that readers are application developers who use SDK or NDK, or platform developers who work on platform source code modification themselves. This book focuses on the essential operating principles of Android system services Surface, Audio, Camera, etc. and introduces various ways these services can be implemented. Regardless of the roles that readers assume in the application development process, we thought such a structure for the book was worth trying. We believe that this book will help readers understand Android platforms system services better. We strictly adhered to this principle as we were writing this book.

The focus of the book is on engineering students and engineers, but it is good enough to interest advanced application developers wanting to build a solid foundation in Android. If you are a platform developer,

the knowledge contained in this book is a must because an in-depth understanding of the Android platform is absolutely necessary in order to develop products that are differentiated from those of other competitors. Also, in general, if you are curious and want to know more about the Android platform, this is a good book to read. Readers are guaranteed to understand the basic operating principles behind the Android platform.

No matter what your motivations are for choosing this book, we hope you will find it exciting and interesting above all else.

Topics covered in this book Overview of Android Anatomy Configuring the Android platform development environment and debugging method. Introducing essential knowledge needed for Android platform development Binder IPC, ashmem, Service Framework, JNI, HAL. Analyzing critical services such as Surface Flinger, Audio Flinger, Camera Service, Media Framework. Providing background knowledge to facilitate understanding of system service operations.

Introducing the authors


Author: Edward T. Kim He was Software Engineer at LG Electronics, where he was a member of the team that built Android devices which are LU-2300 and SU-950. Edward received the BS and MS degrees in Computer Science from the Pusan National University, Korea, in 2007 and 2009, respectively. He is currently working toward the PhD degree in Object Oriented System Lab. at the same university and leading the Seoul Android Platform Study Group. His research interests include Android, GUI and Compatibility Testing,

Object Oriented systems, Relational Database.

Author: Peter Park Graduated from Kyungsung University with a degree in Computer Science. While at school, worked on a project related to embedded Linux application at Samsung Software Membership. Currently working on SOC verification task in the semi-conductor industry. Interested in multi-core environment in embedded OS area.

Table of Contents: Inside the Android Framework 2(2011)


Chapter Android Anatomy Android Development Environment Description A brief introduction to Android Anatomy. Explains the subjects and the scope of the book. Builds a development environment for Android applications. Includes useful information for developers with reference to programming, debugging, logging and building for devices under the Android platform. Provides basic knowledge necessary to understand Androids native system. First, this chapter introduces the concept of Android system services, describes their initialization processes and then explains them from the process point of view. Next, Android System Services describes JNI and HAL, which are critical background knowledge for understanding Overview system services as they operate freely across complex Android platform stacks. The chapter uses Camera applications as an example to illustrate layer interaction processes. This chapter explains the advanced Binder technique used in the Android platform. First, it shows that the Binder IPC is really a streamlined RPC. Then it describes the interaction among various applications and system services. It treats Remote Advanced Binder IPC Service in three parts forward, backward and transmission which is one of the most critical parts of Android system service analysis. Finally, the chapter focuses heavily on how to use the binder to transmit and share large size data among processes. MemoryHeapBase is used as an example to illustrate how easy it is to use shared memory. This chapter describes Surface Flinger Service responsible for screen control in the Android platform. First, it explains graphic HAL, EGL, OPENGL ES and shared Surface memory configuration by going over Surface Flinger Service initialization process. Flinger Service management, surface management and surface composition. Finally, the chapter illustrates how Activity Screen is really displayed using Surface Flinger, and it uses Then, it delves into Surface Flingers native functions application connection it introduces service framework to explain how to create system services. Then it

HelloWorld as an illustrative example.

With respect to audio data playback and recording, Audio System handles transmission and control of data stream, and manages audio devices. This chapter Audio treats audio data transmission method and the relationship between AudioTrack and System AudioFlinger in Audio System, with separate sections for explaining audio input and output. It also describes Audio Policy Service overseeing Audio Focus and Pass. Camera Service is critical in supporting multimedia functions in Android. In particular, it is needed for high-resolution photo shoot, video recording, augmented Camera reality, object recognition and other application utilizations. This chapter explains in Service detail the operating mechanisms behind photo shoot, video recording, camera preview, overlay and others. Media Framework is a key component of the Android system services that combines Surface Flinger, Audio Flinger, Camera Service and others that allow playing and recording of media data. This chapter focuses on interactions among system services in order to facilitate a better understanding of Media Framework. First, the chapter explains the structure and functions of Stagefright Media Player, which is responsible for the playback of media data in Media Player Service. It also Media Player Service extraction, event handling, media buffer management, audio player and video renderer. Readers gain practical understanding of Media Player by tracing real data and the flow of function calls based on a simple example. Finally, this chapter explains the operation of Metadata Service related to Media Player and illustrates the relationship between multimedia codec and parser, making possible a comprehensive understanding of multimedia playback functions in Android. describes the interactions among several critical Media Player functions metadata

Table of Contents
Chapter 1 Anatomy of Android Introducing Anatomy of Android Introducing Physiology of Android

Chapter 2 Building an Android Development Environment 2.1 Building a host environment 2.1.1 Installing VirtualBox 2.1.2 Installing Ubuntu (64 bit) 2.2 Constructing an Android system build environment

2.2.1 Utilities needed for platform-build 2.2.2 Installing JDK 2.2.3 Installing necessary packages 2.2.4 Installing Report 2.2.5 Android system-build 2.3 Uploading Android to NexusOne 2.3.1 Configuring an environment for NexusOne build 2.3.2 Configuring USB devices 2.3.3 Uploading Android to NexusOne 2.4 Building an Android SDK development environment 2.4.1 Downloading Android SDK starter package 2.4.2 Adding platform and example programs to Android SDK 2.4.3 Building an Eclipse development environment 2.4.4 Building an ADT plug-in for Eclipse 2.4.5 Configuring an Android SDK file path 2.5 Developing Android applications 2.5.1 Creating a Hello application 2.6 Debugging an Android system source label 2.6.1 Loading Application framework source codes 2.6.2 Debugging Hello application source codes

Chapter 3 Android System Service 3.1 System services 3.1.1 Native system services 3.1.2 Java system services 3.2 Creating system services 3.2.1 Analyzing media system source codes 3.2.2 Analyzing system server source codes 3.2.3 Summary 3.3. Process and thread in system services 3.3.1 Media Server and thread 3.3.2 System Server and thread 3.3.3 Communication among threads 3.3.4 Summary 3.4 System framework 3.4.1 Overview of the Android service framework 3.4.2 Understanding the Android service framework via examples 3.4.3 Summary 3.5 Java Native Interface

3.5.1 Registering native method 3.5.2 Calling native method from Java 3.5.3 Using Java class from Native System 3.6 Hardware Abstract Layer 3.6.1 Classification of HAL 3.6.2 Structure of HAL 3.6.3 Initialization of HAL 3.7 Layer Interactions 3.7.1 Classification of layer interactions 3.7.2 Examples of Camera applications 3.7.3 Layer interactions in Camera applications

Chapter 4 Advanced Binder IPC 4.1 Overview of Binder IPC 4.1.1 Service and service user 4.1.2 Context Manager and Service Manager 4.1.3 Binder Driver 4.2 Interactions among various components 4.2.1 Registering system services 4.2.2 Searching for system services 4.2.3 Using system services 4.2.4 Summary 4.3 Native Remote Service 4.3.1 Creating Remote Services (forward) 4.3.2 Creating Remote Services (backward) 4.3.3 Transmitting Remote Services 4.3.4 Examples of Native Remote Service 4.3.5 Summary 4.4 Android Shared Memory 4.4.1 Overview of Android Shared Memory 4.4.2 Overview of ASHMEM 4.4.3 Creating ASHMEM 4.4.4 Controlling ASHMEM 4.4.5 Mapping ASHMEM 4.5 MemoryHeapBase Class 4.5.1 Class structure 4.5.2 Examples 4.6 File identifier transmission mechanism 4.6.1 Overview of file identifier transmission

4.6.2 Calling ASHMEM file identifier 4.6.3 Returning ASHMEM file identifier 4.7 IMemory 4.8 MemoryDealer

Chapter 5 Surface Flinger Service 5.1 Introducing Surface Flinger Service 5.1.1 Various screens of Android 5.1.2 Roles of Surface Flinger Service 5.1.3 Properties of Surface Flinger 5.2 Structure of Surface Flinger Service 5.2.1 Surface Flinger class diagram 5.2.2 Graphics HAL Interface 5.3 Initializing Surface Flinger Service 5.3.1 Creating Surface Flinger 5.3.2 Initializing Main Display 5.3.3 Creating Native Window 5.3.4 Creating display shared control block 5.3.5 Initializing EGL 5.3.6 Boot animation 5.4 Analyzing Surface Flingers critical functions 5.4.1 Managing client connection 5.4.2 Maintaining layers 5.4.3 Maintaining layer conditions 5.5 Layer composition and screen output 5.6 Understanding Surface Flinger operation using examples 5.6.1 Creating activities and window 5.6.2 Basic screen (Canvas) 5.6.3 Screen that requires rapid processing (SurfaceView) 5.6.4 Drawing 3D screen (GSSurfaceView)

Chapter 6 Android Audio System 6.1 Overview of Audio System 6.1.1 Role of Audio System 6.1.2 PCM data 6.2 Structure of Audio system 6.2.1 Audio System components and Audio System Layer analysis 6.2.2 Analyzing interlayer operations 6.2.3 Initializing Audio Flinger and Audio HAL

6.3 Audio Output 6.3.1 Examples of Audio Output application 6.3.2 Audio Output components 6.3.3 Creating playback tracks 6.3.4 Securing shared memory and creating control block 6.3.5 Inserting playback track 6.3.6 Preparing playback track 6.3.7 Transmitting PCM data 6.3.8 PCM data re-sampling and composition 6.3.9 PCM data output 6.4 Audio input 6.4.1 Examples of application using audio input 6.4.2 Audio input components 6.4.3 Creating record track 6.4.4 Audio input stream and RecordThread creation 6.4.5 Inserting record track and preparation process 6.4.6 PCM data input 6.5 Audio Policy Service 6.5.1 Operating Audio Policy Service 6.5.2 Audio I/O stream 6.5.3 Controlling stream volume 6.5.4 Audio routing

Chapter 7 Camera Service 7.1 Introducing Camera Service 7.1.1 Understanding Camera hardware 7.1.2 Role of Camera Service 7.2 Structure of Camera Service 7.3 Initializing Camera Service 7.3.1 Creating Camera Service 7.3.2 Connecting to Camera Service 7.3.3 Understanding Camera call-back functions 7.4 Preparing Camera Preview 7.4.1 Configuring Camera 7.4.2 Configuring Camera Frame Memory 7.4.3 Configuring Camera Video Surface 7.5 Understanding Camera Preview operations 7.5.1 Starting Camera Preview 7.5.2 Creating PreviewThread

7.5.3 Registering Preview Images Buffer 7.5.4 Transmitting Preview Image Frame 7.6 Understanding Camera operation 7.6.1 Configuring Auto-Focus 7.6.2 Creating PictureThread 7.6.3 Understanding data transmission process when taking photos

Chapter 8 Media Player Service 8.1 Media Framework 8.1.1 Organization of Media Framework 8.1.2 Communication among the system services 8.2 Overview of Media Player Service 8.3 Structure/Initialization of Media Player Service 8.3.1 Class structure 8.3.2 Initialization 8.3.3 Event-driven operation control 8.4 Handling Media Data 8.4.1 Media File and Stream DataSource Class 8.4.2 Media Extractor 8.4.3 Decoding MediaSource Class 8.5 Audio output AudioPlayer Class 8.6 Video output AwesomeRenderer Class 8.6.1 Movement control using Video Event 8.6.2 Obtaining video information using Decoder 8.6.3 Creating VideoRenderer 8.6.4 Synchronizing video and audio data playback 8.6.5 Rendering video information to screen 8.7 Understanding Media Player using examples 8.7.1 Stagefright Media Player diagram 8.7.2 Analyzing source codes for illustration 8.7.3 Function call sequence in media playback 8.8 Metadata Service 8.8.1 Role of Metadata Extractor 8.8.2 Metadata Extractor operation 8.9 OpenMax Codec Support 8.9.1 Understanding OpenMax Interface 8.9.2 Initializing OpenMax interface 8.9.3 Media playback and hardware support

Inside the Android Framework


An excellent reference book for studying the Android framework!

Introduction
The main focus of Inside the Android Framework is the initialization of the Android framework during the booting process and the operating principles behind the frameworks major components. In this book, the authors analyze and summarize the frameworks major source codes and provide the basic knowledge needed to understand the frameworks operating principles. In addition, the book also provides detailed descriptions of the Android Service framework, which constitutes the foundation of the Android applications development platform.

Some of the major topics contained in this book are: An overview of the Android framework through examination of the booting process. The basic knowledge and concepts behind developing Android applications and porting them to Android devices. Analyzing essential Android components JNI (Java Native Interface), Binder, Zygote, Service Manager and Service Server. Understanding the structure of the Android Service Framework. Some examples of Android system services, e.g., Camera Service and Activity Manager Service.

Authors Preface
What are some of the important abilities mobile application developers must have?

Many answers are possible, but we think the most important one is to understand the framework applied to a given target device. It is for the same reason that programmers with a solid understanding of the Windows or Linux operating system and web browsers are considered better programmers.

Likewise, understanding a given frameworks operating principles under a mobile platform is a key to becoming an advanced-level mobile applications programmer, which is certainly true for Android applications developers. However, it is very hard to find good resources that deal with this subject in the bookstore or on the Internet. To make it worse, there arent any clear and sufficiently extensive explanations of the subject of the Android framework itself, other than some very limited information made available by Google or at Google IO (the annual technical conference held by Google for applications developers).

When we wrote this book, the only way to learn about the Android frameworks operating principles was to examine the source codes at the most foundational level. Certainly we were not endowed with

sufficient resources to do an independent study on the Android framework in the beginning. Therefore, we were forced to acquire any knowledge they needed from direct examination of Android source codes. As you might expect, we were initially at a loss to know where to even begin our study because of the sheer vastness of the Android source codes universe.

Fortunately, we were able to get some ideas from the resources given out during the Anatomy & Physiology of an Android presentation at the Android session of the 2008 Google IO Conference, including the treatment on the subject of Android framework initialization and other relevant topics. It gave us a direction for our research and jump-started our project.

When we started out, we were basing our analysis on Android version 1.5 (Cupcake). By the time we were finalizing the manuscript for this book, however, Google had introduced version 2.2 (Froyo). Of course, the book was revised to reflect the most updated Android version, but the nature of the framework being what it is, there had been very limited changes in the source codes, which eliminated any concern about version differences in Android. Even for version 3.3 (Gingerbread), to be introduced in late 2010, we do not foresee any major changes in source codes and expect the integrity of our book to be preserved under the new version.

Finally, please keep in mind that our treatment of the Android framework in this book is not an exhaustive explanation of the inner workings of Android but only a guide to the internal operating principles of the Android framework. We recommend that you use this book as a starting point for source codes analysis for the project that you are involved in. We are confident that it will be of great use to whatever project you are working on.

Publishers Review
The best reference book for studying the Android framework in Korea

This book is like a sweet rain for those who have been searching for a book that deals with the structure of the Android framework. It is easy to find books on application development using Android SDK in the bookstore or on the Internet, but a book that deals with the structure and operating principles of the Android framework is virtually non-existent at this point. Even Google is not making information readily available to pertain specifically to the internal workings of the Android framework.

The main focus of Inside the Android Framework is the initialization of the Android framework during the booting process and the operating principles behind the frameworks major components. In this book, the authors analyze and summarize the frameworks major source codes and provide the basic knowledge needed to understand the frameworks operating principles. In addition, the book also provides detailed

descriptions of the Android Service Framework, which constitutes the foundation of the Android applications development platform.

This book is also a journal kept by a handful of intellectual pioneers who recorded their discoveries as they were exploring the unknown territory of the Android framework. Together, they spent hundreds of hours poring over millions of lines of source codes projected on the screen for group study, and now they want to share with readers the excitement they experienced deciphering Googles secrete codes.

You could certainly develop Android applications without an in-depth understanding of the Android framework. However, if you are familiar with the framework and have a solid understanding of its operating principles, you wont be intimidated by difficult development scenarios, no matter how complicated they are, and will have confidence that you can write codes that are optimized for the Android framework.

Also, Android being an open source platform, each hardware vendor is introducing products that are differentiated from those of its competitors by customizing the Android framework to its own specification. In order to develop customized solutions using the Android framework, it is now necessary to understand the Android framework in depth.

Inside the Android Framework deals with the Android framework in depth by examining Androids system source codes. This book is recommended for developers who want either to have a deeper understanding of the Android system or to develop Android solutions that are optimized to the framework.

Topics covered in this book. An overview of the Android framework during the booting process The basic concepts and knowledge behind developing and porting Android applications to a target device. Analyzing essential Android components JNI (Java Native Interface), Binder, Zygote, Service Manager, Service Server. Understanding the structure of the Android system service framework Analyzing actual examples of Android system services using Camera Service and Activity Manager.

Intended readers
Readers are expected to have either a computer science degree or some background knowledge in Linux, C, C++ and Java. They dont have to be a specialist in each area but must have some computer science background. Accordingly, coverage of the above-mentioned topics was limited to a minimum level in this book. We must admit that, the subject of the Android platform being vast, treating the main subject was challenging enough. Also, there are many good reference books in the market that deal with the subjects

of Linux, C, C++ and Java, so we assumed that readers would be able to acquire relevant knowledge and obtain necessary information without difficulty, if necessary.

Also, we did not assume that readers were application developers who use SDK or NDK or platform developers who work on platform source code modification themselves. This book closely follows the booting process of Android-based devices and explains a sequence of software-like hardware operations that take place inside the device. Regardless of the roles that readers assume in the application development process in their respective jobs, we thought that the strategy we used to write this book was worth trying. We believe that this book will help readers better understand the Android platforms system services. We strictly adhered to this principle as we were writing this book.

The focus of the book is on engineering students and engineers, but it is broad enough to interest advanced-level application developers wanting to build a solid foundation in Android. If you are a platform developer, the knowledge contained in this book is a must because an in-depth understanding of Android is absolutely necessary in order to develop products that are differentiated from those of other competitors. Also, in general, if you are curious and want to know more about the Android platform, this is a good book to read. Readers are guaranteed to understand the basic operating principles behind the Android platform.

No matter what your motivations are for choosing this book, we hope you will find it exciting and interesting above all else.

The value of this book


The book treats some of the more controversial issues of the Android mobile operating system. The book was introduced in Korea and became the bestselling IT book. It is a proven winner with enthusiastic approval from readers. The book was selected as the 2011 Best Academic Paper (Science and Technology Area) by the Korea Ministry of Culture and Tourism. Ten thousand copies were printed in Korea alone, and five thousand copies are expected to be printed once the copyright contract with China is completed. So far, there have been no books published in the US and Japan on the subject of the Android platform. Most of the authors work at Samsung Electronics and LG Electronics, the combined mobile phone sales of which dominate the world market.

Introducing the authors


Author: Edward T. Kim Studied Computer Engineering / Computer Software Engineering in graduate school at Pusan National

University. Participated in LG Electronics Android mobile phone development. Currently leads the Seoul Android Platform Study Group, which succeeded the Suwon Android Platform Study Group.

Author: Song Hyungju Graduated from KAIST with a major in Sensor Network Platform. Interested in software platform structure and operating principles, in particular Android. Currently working on HTLML 5-based web platform development after having been involved in next-generation mobile communication systems and widget development. Has a dream of rejuvenating the software development community through the sharing of applications development-related knowledge on- and off line.

Author: Park Jihoon Graduated from Kyungsung University with a degree in Computer Science. While at school, worked on a project related to embedded Linux application at Samsung Software Membership. Currently working on SOC verification task in the semi-conductor industry. Interested in multi-core environment in embedded OS area.

Author: Lee Baek Interested in embedded OS and platform development. Currently developing Android applications porting and system program development.

Author: Lim Kiyoung Interested in structural analysis of Linux-based device platform. Currently working on porting embedded OS applications and device driver implementation.

Table of Contents, Inside the Android Framework (2010)


Chapter Android Framework Android Development Environment Init Process Description A brief introduction to the Android framework with a description of the books content and its coverage. How to build a development environment for the Android platform. Explains how to download and compile Android platform source codes, install SDK and use Eclipse to do Application framework debugging. The init process in the Android platform configures the environment for system operations during the system booting process and sequentially executes critical system processes. This chapter describes how the init process analyzes init.rc file, executes instructions and creates device driver nodes. Also, the chapter examines the property service that completes child processes, stores system environmental variables and executes a given process. JNI & NDK Android can generally be divided into two parts, the Java layer and the Androids

native layer, and JNI bridges these two layers. This chapter explains in detail the operating principles of JNI. In particular, the chapter explains how to call a C program from Java programs, and vice versa, and introduces critical JNI functions. Then the authors describe how to utilize JNI in the Android platform and optimize it. Finally, the chapter provides some examples on how to install NDK and execute emulators. Zygote Like an unfertilized egg that fuses with a nucleus to start cell division, a new application in the Android platform is executed when Zygote, which represents an unfertilized state and stores all necessary elements for executing a process, fuses with a new application. This chapter introduces a special way to start a new application using Zygote in the Android platform. In particular, it focuses on explaining add_process and ZygoteInit class. Android Overview Service There are various application services in the Android platform ranging from application services using SDK to system services that are essential to the platforms critical functions. This chapter introduces various services running on the Android platform and analyzes the operating principles behind applications and the system services. In addition, terminology related to the concept of Binder IPC and System Service framework is defined and explained. Android IPC Binder At the heart of the core technology supporting the Android platform is the Binder. The Binder in Android is an IPC that supports communication among processes, and is light and fast. In this chapter, a Linux Binder driver is examined first. Then the chapter introduces a Binder model, basic knowledge about the Binder, a Binder protocol, some transaction codes and data and a Binder addressing. Next, based on the basic knowledge obtained, this chapter analyzes service-use mechanism using the Binder from the process perspective and then from the Binder driver perspective. Finally, this chapter explains how the Context Manager, a special Binder process, manages system services. Android Framework Service The Java layer in the Android platform also provides Java Service Manager that creates system services and uses them in applications. For this, Java service framework uses JNI to reuse the functions that reside in Androids native framework. This chapter provides in-depth explanations on the various components that comprise Java Service framework and the interactions among them. Also, it analyzes Alarm Manager Service from the service frameworks point of view and explains how to use AIDL to implement HelloWorld system services, which work on Java layer. Finally, the chapter examines the operating principles behind Java Service Manager. Analysis of Native System Service Camera Service, one of the components that make up the Android platform, is analyzed in this chapter. Based on the concepts of the Binder and the System Service framework explained in the previous chapters, this chapter analyzes

Camera Service, which directly operates on the Android platform, with respect to initialization, connection, control and event-handling processes. Android Java This chapter provides a detailed description of Java layers System Service framework components and their interactions. Also, the authors examine Alarm Manager Service from the System Service frameworks point of view and explain how to use AIDL to implement the HelloWorld program that operates on Java layer. Finally, the chapter explains the operating principles behind Java Service Manager. Analysis of Java System Service In this chapter, the Activity Manager, one of the Java system services that comprise the Android platform, is examined. From various functions belonging to Activity Manager Service, the authors select and explain in detail how to create application services. To illustrate this, the book focuses on binder communication among ActivityManagerService, ActivityThread and ApplicationsThread classes.

Service Framework

Table of Contents: Inside the Android Framework


Chapter 1 Overview of the Android Framework Structure of the Android frameworks source codes Exploring the Android framework by studying the booting process

Chapter 2 Building a Development Environment for Android 2.1 Configuring the host environment 2.1.1 Installing VirtualBox 2.1.2 Installing Ubuntu 2.2 Configuring an Android System-build environment 2.2.1 Build utility 2.2.2 Installing Repo 2.2.3 Downloading Android system source codes 2.3 Configuring an Android SDK development environment 2.3.1 Setting up an Eclipse development environment 2.3.2 Downloading the Android SDK starter package 2.3.3 Installing the ADT plug-in for Eclipse 2.3.4 Designating an Android SDK path 2.3.5 Adding platform and sample programs to Android 2.4 Developing Android applications. 2.4.1 Create HelloWorld applications 2.5 Debugging Android system source label 2.5.1 Loading Application framework source codes 2.5.2 Debugging HelloWorld framework source labels

Chapter 3 nit rocess 3.1 Executing init process 3.2 Init process source code analysis 3.3 Analyzing and executing init.rc file 3.3.1 action_list 3.3.2 service_list 3.3.3 Parsing code for analyzing init.rc file 3.3.4 Executing action_list and service_list 3.4 Creating device node file 3.4.1 Create static device node 3.4.2 Sensing dynamic device (HOT PLUG) 3.5 Starting and ending a process 3.5.1 Analyzing restart_process( ) 3.6 Property Service 3.6.1 Initializing property 3.6.2 Handling property change request 3.7 Summary

Chapter 4 JNI and NDK 4.1 Android and JNI 4.1.1 Why do we need to know JNI in Android? 4.2 Understanding JNIs fundamental principles 4.2.1 Calling C library functions from Java 4.2.2 Summary 4.3 Using JNI functions 4.3.1 Structure of sample programs using JNI functions 4.3.2 Examining Java codes 4.3.3 Compilation and execution results 4.3.4 Example of Android application 4.4 Executing Java class in C programs 4.4.1 Example of calling API 4.4.2 Compilation and execution 4.4.3 Example of Android applications: Zygote process 4.5 Directly registering JNI native functions 4.5.1 Registering JNI native functions while loading library 4.5.2 Example of Android applications: app_process( ) 4.6 Developing Android NDK (Native Development Kit) 4.6.1 Android NDK environment configuration 4.6.2 Emulating Android NDK development

Chapter 5 Zygote 5.1 What is Zygote? 5.1.1 Creating a process using Zygote 5.2 From app_process to executing ZygoteInit class 5.2.1 Creating AppRuntime object 5.2.2 Executing AppRuntime object 5.2.3 Creating Dalvik virtual machine 5.2.4 Executing ZygoteInit class 5.3 Functions in ZygoteInit class 5.3.1 /dev/socket/zygote socket binding 5.3.2 Loading platform resources and Application framework classes 5.3.3 Execute System Server 5.3.4 Executing new Android applications

Chapter 6 Overview of Android Service 6.1 Example programs: Understanding Android service operations 6.2 Classifying Android services 6.3 Android application services 6.3.1 Classifying application services 6.3.1.1 Local Service 6.3.1.2 Remote Service 6.4 Android System Service 6.4.1 Classifying Android system services 6.4.1.1 Native System Service 6.4.1.2 Java System Service 6.5 Executing system services 6.5.1 Analyzing Media Server codes 6.5.2 Analyzing System Server codes 6.6 Overview and summary of Android service framework and binder driver

Chapter 7 Android Binder IPC 7.1 Linux memory space and binder driver 7.2 Android Binder Model 7.2.1 Binder IPC data transfer 7.2.2 Binder IPC data flow 7.2.3 Binder protocol 7.2.4 RPC code and RPC data 7.2.5 Binder addressing

7.3 Android binder driver analysis 7.3.1 Using service from process perspective 7.3.2 Using service from binder driver perspective 7.3.3 Analyzing binder driver functions 7.4 Context Manager (Service Manager) 7.4.1 Context Manager operations 7.5 Summary

Chapter 8 Android Service Framework 8.1 Android Service Framework 8.2 Analyzing Service Framework 8.2.1 Arranging components by layers 8.2.2 Interactions of components across different layers 8.2.3 Class structure 8.3 Operating principles 8.3.1 Service interface 8.3.2 Service 8.3.3 Service proxy 8.4 Native Service Manager 8.4.1 Overview of Service Manager 8.4.2 Service Manager class 8.4.3 Service Manager operations 8.5 Creating native services 8.5.1 Designing HelloWorld system service 8.5.2 HelloWorld service interface 8.5.3 HelloWorld service 8.5.4 HelloWorld service proxy 8.5.5 Executing HelloWorld service

Chapter 9 Analyzing Native System Service 9.1 Camera Service 9.2 Camera applications 9.3 Camera Service framework 9.3.1 Interlayer structure of Camera Service framework 9.3.2 Camera Service framework service 9.4 Camera Service framework operation 9.4.1 Initializing Camera Service 9.4.2 Camera Service connection 9.4.3 Analyzing source codes for Camera Service connection

9.4.4 Configuring and controlling Camera 9.4.5 Analyzing configuration and control process of Camera 9.4.6 Handling Camera Event 9.4.7 Analyzing Camera Events event handling process

Chapter 10 Java Service Framework 10.1 Java Service Framework 10.1.1 Components of Java service framework by layer 10.1.2 Java service framework interactions by class 10.2 Operating mechanism 10.2.1 Java service framework initialization 10.2.2 Binder 10.2.3 BinderProxy 10.2.4 Parcel 10.3 Implementing Java system services 10.3.1 Analyzing structure of Alarm Manager Service 10.3.2 Implementing HelloWorldService system service 10.3.3 Using HelloWorldService system service 10.3.4 Building HelloWorldService system service 10.4 Java Service Manager 10.4.1 Introducing Java Service Manager 10.4.2 BinderInternal 10.4.3 Java Service Manager Operation 10.5 Implementing Java proxy and stub using AIDL

Chapter 11 Java System Service Operation 11.1 Activity Service Manager 11.2 Analyzing codes to create services using Activity Manager Service 11.2.1 Controller activity calling startService() method 11.2.2 Process of calling startService() method in Activity Service Manager (using RPC Binder) 11.2.3 Activity Service Manager - Executing startService() stub method 11.2.4 Executing main() method of ActivityThread class 11.2.5 Activity Service Manager handling attachApplication() stub method

We are looking forward to hear from the publisher in USA to publish our books about Android platform. Isn't there anybody who has connections in the publisher?

Briefly, let me introduce our books:

1) The first print of Inside the Android run of 10,000 copies sold out for about a year in Korea, which is bestseller in Computer Section. 2) The authors have studied Android Platform with the source code during nine months. The contents of the book introduce Android Platform of fundamentals, init process, JNI, Zygote, Binder, Service Framework based on 2.2 froyo. 3) Android Anatomy is also being written by experts in this field. They have experience developing Android Platform. The contents of the book introduce Android Platform of core system services, surface flinger, audio flinger, camera service, multimedia framework based on 2.3 gingerbread.

If you have any questions, feedbacks and suggestions about the contents of the books, please send me that. I am ready to accept publishers requests with flexible position.

Thank you for your interesting in my books, again. Yours sincerely, Edward T. Kim

p.s: Let me introduce my agency which is charge of the contact with a US publisher of my books and have experience with translation contacts in this field. The information about my agency is the below. Lauren Kim / EntersKorea Co., Ltd Foreign Rights Agent / English-Europe Department A: 3F, Do Dream Bldg, #375-8, Mangwon-dong, Mapo-gu, Seoul, 121-230, Korea

E-mail: [email protected] P: +82-70-7126-3013 F: +82-2-3142-8139 FR team www.ekagency.co.kr TR team www.ekitc.com DE team www.designbbook.com

You might also like