Book Image

Instant Android Systems Development How-to

By : Earlence Fernandes
Book Image

Instant Android Systems Development How-to

By: Earlence Fernandes

Overview of this book

<p>Android is by far the most popular open source mobile operating system. Learning to write high quality code at the platform level and learning how the systems works internally is a vital skill. This book teaches you these skills with clear and concise explanations and code examples.</p> <p>Instant Android Systems Development How-to provides a gentle introduction to the platform internals without sacrificing depth. Source code examples are designed to be meaningful, but at the same time, do not disguise their real purpose, which is to illustrate systems development techniques and common design patterns in android systems programming. Readers will be guided through several examples that give a hands-on experience.</p> <p>Readers begin by downloading the android source code, which is a topic of much discussion on android forums. They are then guided through the android boot process, and later on learn various common android systems development paradigms. More importantly, the book provides advice on when to use certain techniques which is often a mystery for the novice developer. Readers who complete the book will have high confidence in developing good systems code for Android.</p> <p>The book discusses how to setup a development machine and how to obtain the android source code and kernel code. It describes the source code organization and how the system boots up with precise references to various points in the source code. It highlights the common systems design patterns followed and how to create a custom system service. It then covers the all important flashing of phones. This is a topic of much confusion and the book provides direct steps to achieve safe flashing of developer phones. It describes the user application library mechanism and the platform library mechanism. Native code is needed for certain operations and an example service utilizing native code is explained. Modification of core system applications is explained and useful tips are provided on how to speed up the build-test cycle. The book concludes with a case study of two real world android platform extensions which give the user a reference while developing their own extensions.</p> <p>Instant Android Systems Development How-to is a well rounded book on platform internals that provides simple explanations without sacrificing depth and rigor.</p>
Table of Contents (7 chapters)
Instant Android Systems Development How-to
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Instant Android Systems Development How-to

Analyzing Android system partitions (Must know)


An Android phone contains a few basic partitions along with other supporting partitions. This knowledge is vital to understanding how and where code is flashed to devices.

Getting ready

On our test device—Samsung Galaxy Nexus (or emulator)—we can view these partitions with the following command executed inside an adb shell. To obtain a shell on the device, you should connect the device via USB and you should make sure that the USB Debugging option is enabled (located at Settings | Developer Options).

Note

If you are using Jellybean or higher, the option is hidden, so you need to go to Settings | About Phone and keep tapping on the build number until a Toast pops up saying that you are now a developer. The Developer Options will appear at the usual location.

Finally, to actually obtain a shell, while the device is connected, fire up a terminal and type in adb shell and press Enter.

Note

Sometimes, Linux does not detect the Android device, and in these cases, you need to edit the USB rules file. Since this is not a systems development issue and is commonly encountered by SDK developers, we will not detail the steps here.

How to do it…

  1. Execute the following command in a terminal with Samsung Galaxy Nexus connected and with debugging enabled. The following output is generated when we list the device's partitions:

    shell@android:/ $ ls -l /dev/block/platform/omap/omap_hsmmc.0/by-name          
    lrwxrwxrwx root     root              2012-06-28 22:03 boot -> /dev/block/mmcblk0p7 
    lrwxrwxrwx root     root              2012-06-28 22:03 cache -> /dev/block/mmcblk0p11 
    lrwxrwxrwx root     root              2012-06-28 22:03 dgs -> /dev/block/mmcblk0p6 
    lrwxrwxrwx root     root              2012-06-28 22:03 efs -> /dev/block/mmcblk0p3 
    lrwxrwxrwx root     root              2012-06-28 22:03 metadata -> /dev/block/mmcblk0p13 
    lrwxrwxrwx root     root              2012-06-28 22:03 misc -> /dev/block/mmcblk0p5 
    lrwxrwxrwx root     root              2012-06-28 22:03 param -> /dev/block/mmcblk0p4 
    lrwxrwxrwx root     root              2012-06-28 22:03 radio -> /dev/block/mmcblk0p9 
    lrwxrwxrwx root     root              2012-06-28 22:03 recovery -> /dev/block/mmcblk0p8 
    lrwxrwxrwx root     root              2012-06-28 22:03 sbl -> /dev/block/mmcblk0p2 
    lrwxrwxrwx root     root              2012-06-28 22:03 system -> /dev/block/mmcblk0p10 
    lrwxrwxrwx root     root              2012-06-28 22:03 userdata -> /dev/block/mmcblk0p12 
    lrwxrwxrwx root     root              2012-06-28 22:03 xloader -> /dev/block/mmcblk0p1 
    
  2. Similarly, on the Nexus S and Nexus One device, we can view the partitions mounted with the command. The following command lists the contents of the mtd proc file:

    cat /proc/mtd
    

    The output looks similar to the following:

    dev:    size   erasesize  name 
    mtd0: 00200000 00040000 "bootloader" 
    mtd1: 00140000 00040000 "misc" 
    mtd2: 00800000 00040000 "boot" 
    mtd3: 00800000 00040000 "recovery" 
    mtd4: 1d580000 00040000 "cache" 
    mtd5: 00d80000 00040000 "radio" 
    mtd6: 006c0000 00040000 "efs"
    
  3. The following output is observed when the same command is executed on Nexus One:

    dev:    size   erasesize  name 
    mtd0: 00040000 00020000 "misc" 
    mtd1: 00500000 00020000 "recovery" 
    mtd2: 00280000 00020000 "boot" 
    mtd3: 04380000 00020000 "system" 
    mtd4: 04380000 00020000 "cache" 
    mtd5: 04ac0000 00020000 "userdata"
    

    Note

    Note the output you see for your device may differ slightly.

How it works…

The main thing to notice here is the existence of a few common partitions which are important to flashing new software. The following are major partitions on most Android devices:

  • /boot: This contains the kernel image and the associated RAM disk. This is executed by the bootloader during the startup process. Any newly built kernel is written to this partition. The phone will not boot if this partition is empty.

  • /system: This contains the Android framework and the related system applications. During system operation, this is mounted as read-only so that critical system files are never modified.

  • /recovery: Is an alternative boot partition used to boot the device into recovery mode. The recovery code is located at ANDROID_SRC/bootable/recovery. There are many custom recovery firmware images available. A notable example is ClockWorkMod.

There's more...

The three partitions just mentioned are the ones involved in flashing a new build of Android on to a device. In addition to these, there are a few other partitions that exist:

  • /data: This contains user data and is sometimes called the user-data partition. All user-installed applications, settings, and personal data are stored in this partition.

  • /cache: Will contain frequently accessed applications.

  • /sdcard: This is the SD card attached to the phone. It is not a partition on the internal device memory.