Android System Programming

Book description

Build, customize, and debug your own Android system

About This Book

  • Master Android system-level programming by integrating, customizing, and extending popular open source projects
  • Use Android emulators to explore the true potential of your hardware
  • Master key debugging techniques to create a hassle-free development environment

Who This Book Is For

This book is for Android system programmers and developers who want to use Android and create indigenous projects with it. You should know the important points about the operating system and the C/C++ programming language.

What You Will Learn

  • Set up the Android development environment and organize source code repositories
  • Get acquainted with the Android system architecture
  • Build the Android emulator from the AOSP source tree
  • Find out how to enable WiFi in the Android emulator
  • Debug the boot up process using a customized Ramdisk
  • Port your Android system to a new platform using VirtualBox
  • Find out what recovery is and see how to enable it in the AOSP build
  • Prepare and test OTA packages

In Detail

Android system programming involves both hardware and software knowledge to work on system level programming. The developers need to use various techniques to debug the different components in the target devices. With all the challenges, you usually have a deep learning curve to master relevant knowledge in this area. This book will not only give you the key knowledge you need to understand Android system programming, but will also prepare you as you get hands-on with projects and gain debugging skills that you can use in your future projects.

You will start by exploring the basic setup of AOSP, and building and testing an emulator image. In the first project, you will learn how to customize and extend the Android emulator. Then you'll move on to the real challenge - building your own Android system on VirtualBox. You'll see how to debug the init process, resolve the bootloader issue, and enable various hardware interfaces. When you have a complete system, you will learn how to patch and upgrade it through recovery. Throughout the book, you will get to know useful tips on how to integrate and reuse existing open source projects such as LineageOS (CyanogenMod), Android-x86, Xposed, and GApps in your own system.

Style and approach

This is an easy-to-follow guide full of hands-on examples and system-level programming tips.

Table of contents

  1. Preface
    1. Virtual hardware platforms
    2. Android version used in this book
    3. What this book covers
    4. What you need for this book
    5. Who this book is for
    6. Conventions
    7. Reader feedback
    8. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Introduction to Android System Programming
    1. What is system programming?
    2. What is the scope of this book?
    3. Overview of the Android system
      1. Kernel
      2. HAL
      3. Android system services
      4. Binder IPC
      5. Application framework
      6. Recovery
    4. The third-party open source projects derived from AOSP
      1. LineageOS (CyanogenMod)
      2. Android-x86
      3. CWM/CMR/TWRP
    5. Strategy of integration
    6. Virtual hardware reference platforms
      1. Introduction to the x86-based Android emulator
      2. Introduction to ranchu
      3. VirtualBox-based Android emulators
    7. Summary
  3. Setting Up the Development Environment
    1. Summary of Android versions
    2. Installing Android SDK and setting up an Android Virtual Device
      1. Creating AVD in an older version of SDK
      2. Creating AVD in the latest version of SDK
      3. Testing the goldfish emulator
      4. Testing ranchu emulator
    3. The AOSP build environment and the Android emulator build
      1. The AOSP build environment
        1. Installing the required packages
        2. Installing Open JDK 7 and 8
        3. Downloading the AOSP source
        4. Installing repo
        5. Initializing a repo client and downloading the AOSP source tree
      2. Building AOSP Android emulator images
      3. Testing AOSP images
    4. Creating your own repository mirror
      1. Repo and manifest
      2. Using a local mirror for AOSP
      3. Creating your own mirror of GitHub
      4. Fetching Git repositories outside GitHub
      5. Creating your own manifest for client download
    5. Summary
  4. Discovering Kernel, HAL, and Virtual Hardware
    1. What is inside the AOSP?
    2. Android emulator HAL
      1. Calling sequence
      2. Goldfish lights HAL
      3. The system service and hardware manager
    3. Android emulator kernel and hardware
      1. Android emulator hardware
        1. Goldfish platform bus
        2. QEMU pipe device
        3. Goldfish audio device
        4. Goldfish serial port
      2. Goldfish kernel
        1. QEMU pipe
    4. Summary
  5. Customizing the Android Emulator
    1. Why customize the Android emulator
    2. Understanding build layers
    3. Build variants
    4. Creating a new x86emu device
      1. Checking out from the AOSP
      2. Checking out from a local mirror
      3. Creating x86emu device
      4. AndroidProducts.mk
      5. BoardConfig.mk
      6. device.mk
    5. Building and testing x86emu
      1. Building x86emu
      2. Testing x86emu
      3. Integrating with Eclipse
    6. Summary
  6. Enabling the ARM Translator and Introducing Native Bridge
    1. Introducing Native Bridge
      1. Setting up Native Bridge as part of the ART initialization
      2. Pre-initializing Native Bridge
      3. Initializing Native Bridge
      4. Loading a native library
    2. Integrating Houdini to the x86emu device
      1. Changing the configuration of the x86emu build
      2. Extending the x86emu device
        1. Changes to BoardConfig.mk
        2. Changes to x86emu_x86.mk
        3. Changes to device.mk
      3. Using the Android-x86 implementation
        1. Analyzing libnb.so
        2. Using binfmt_misc
    3. Building and testing
      1. Testing the command-line application
      2. Testing the Android JNI application
    4. Summary
  7. Debugging the Boot Up Process Using a Customized ramdisk
    1. Analyzing the Android start up process
      1. Bootloader and the kernel
      2. Analyzing the init process and ramdisk
        1. Actions
        2. Services
        3. Device-specific actions and services
    2. Source code and manifest changes
    3. The Android-x86 start up process
      1. The first-stage boot using initrd.img
        1. Inside initrd.img
        2. Inside install.img
    4. Building x86emu with initrd.img
    5. Creating a filesystem image
    6. Kernel changes
    7. Booting a disk image on the Android emulator
    8. Summary
  8. Enabling Wi-Fi on the Android Emulator
    1. Wi-Fi on Android
      1. The Wi-Fi architecture
      2. QEMU networking and wpa_supplicant in Android
    2. Adding Wi-Fi to the emulator
      1. Enabling wpa_supplicant in BoardConfig.mk
      2. Providing a proper wpa_supplicant configuration
      3. Creating services in init scripts
        1. Initializing network interface eth1
        2. Starting up wpa_supplicant
    3. Building the source code
      1. Getting the source code
      2. Enabling boot with initrd.img
    4. Testing Wi-Fi on an emulator
      1. Booting an Android emulator using initrd.img
      2. Booting an Android emulator using ramdisk.img
      3. Debugging Wi-Fi start up processes
    5. Summary
  9. Creating Your Own Device on VirtualBox
    1. HAL of x86vbox
      1. The manifest for x86vbox
    2. Creating a new x86vbox device
      1. Product definition Makefile of x86vbox
      2. Board configuration of x86vbox
      3. Common x86 devices
      4. Getting the source code and building the x86vbox device
    3. Boot up process and device initialization
      1. Device initialization before Android start-up
      2. HAL initialization during the Android start-up
    4. Summary
  10. Booting Up x86vbox Using PXE/NFS
    1. Setting up a PXE boot environment
      1. Preparing PXE Boot ROM
        1. Downloading and building the LAN Boot ROM
        2. Fixing up the ROM image
        3. Configuring the virtual machine to use the LAN Boot ROM
      2. Setting up the PXE boot environment
    2. Configuring and testing the PXE boot
      1. Setting up the virtual machine
      2. Using VirtualBox internal PXE booting with NAT
      3. Configuring pxelinux.cfg
        1. pxelinux.cfg/default
      4. Setting up a serial port for debugging
    3. NFS filesystem
      1. Preparing the kernel
      2. Setting up the NFS server
    4. Configuring the PXE boot menu
      1. Booting to NFS installation
      2. Booting from a hard disk
      3. Booting to recovery
    5. Summary
  11. Enabling Graphics
    1. Introduction to the Android graphics architecture
    2. Delving into graphics HAL
      1. Loading the Gralloc module
      2. Initializing GPU
      3. Initializing framebuffer
      4. Allocating and releasing the graphic buffer
        1. Allocating from framebuffer
        2. Allocating from system memory
        3. Releasing graphic buffers
      5. Rendering framebuffer
    3. Graphics HAL of the Android emulator
      1. Overview of hardware GLES emulation
      2. Initializing GPU0 and FB0 in GLES emulation
      3. GPU0 device implementation
      4. FB0 device implementation
    4. Summary
  12. Enabling VirtualBox-Specific Hardware Interfaces
    1. OpenGL ES and graphics hardware initialization
      1. Loading OpenGL ES libraries
        1. Analyzing the loading process
        2. Loading the driver
        3. Creating the rendering engine
      2. The uvesafb framebuffer driver
        1. What is uvesafb?
        2. Testing the uvesafb framebuffer driver
        3. Initializing uvesafb in x86vbox
    2. Integrating VirtualBox Guest Additions
      1. Building VirtualBox Guest Additions
      2. Integrating vboxsf
      3. Integrating vboxvideo
      4. Building and testing images with VirtualBox Guest Additions
    3. Summary
  13. Introducing Recovery
    1. Recovery introduction
      1. Android device partitions
    2. Analyzing recovery
      1. BCB
      2. Cache partition
      3. Main flow of recovery
      4. Retrieving arguments from BCB and cache files
      5. Factory data reset
      6. OTA update
    3. Building recovery for x86vbox
      1. Building configuration
      2. Changes to x86vbox
      3. Changes to recovery
      4. Changes to newinstaller
      5. Testing recovery
    4. Summary
  14. Creating OTA Packages
    1. What is inside an OTA package
      1. Updater
      2. The updater script
      3. Edify functions
        1. Built-in functions
        2. Installation functions
        3. Block image functions
        4. Device extensions
    2. Preparing an OTA package for x86vbox
    3. Removing dependencies on /system
      1. Hardware initialization in recovery
      2. Minimum execution environment in recovery
    4. Building and testing
    5. Summary
  15. Customizing and Debugging Recovery
    1. Debugging and testing native Android applications
      1. Debugging with GDB
      2. Integration with Eclipse
    2. Extending recovery and the updater
      1. Extending recovery
      2. Extending the updater
      3. Extending the Python module
      4. Building and testing the extended recovery and updater
    3. Supporting the third-party recovery packages
      1. Xposed recovery package
      2. Opening GApps
    4. Summary

Product information

  • Title: Android System Programming
  • Author(s): Roger Ye
  • Release date: May 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781787125360