Some Miscellaneous Notes on Android

来源:互联网 发布:p双眼皮的软件 编辑:程序博客网 时间:2024/06/06 03:41

Origal:  http://elinux.org/Android_Notes

Android Notes


Here are some miscellaneous notes on Android. See Android on OMAP, too.


Contents

[hide]
  • 1Technical Info about system components
    • 1.1oom killer info
    • 1.2init sequence
    • 1.3kernel power management
    • 1.4C Library (bionic) info
      • 1.4.1threads
  • 2Development Tools
    • 2.1Busybox
    • 2.2Bootchart
    • 2.3Benchmarks
  • 3Development Tips
    • 3.1debugging tips
    • 3.2Using 'fastboot'
    • 3.3Re-flashing a device
      • 3.3.1Tutorial on Android flash partitions
      • 3.3.2Nandroid (NAND flash backup tool)
    • 3.4Compiling native applications
  • 4Building
    • 4.1Building the kernel from scratch
  • 5Organizations
  • 6Android taxonomy

Technical Info about system components

oom killer info

Google (Android) developer Arve Hjonevag added a lowmemorykiller feature to the staging area of theLinux kernel in January of 2009. This feature tries to reclaim memory before the systemruns out (acting as a kind of cache manager, according to Arve). In Linus' 2.6.28-rc tree thisappears in

Application lifecycle (and activity states) can be found here:http://code.google.com/android/intro/lifecycle.html

Applications in different stages of their lifecycle receive a different oom_adj value, which affectsthe probability of their being reaped.

Initial lowmemorykiller thresholds are set by /etc/init.rc (with the following lines):

# Define the oom_adj values for the classes of processes that can be# killed by the kernel.  These are used in ActivityManagerService.   setprop ro.FOREGROUND_APP_ADJ 0   setprop ro.VISIBLE_APP_ADJ 1   setprop ro.SECONDARY_SERVER_ADJ 2   setprop ro.HIDDEN_APP_MIN_ADJ 7   setprop ro.CONTENT_PROVIDER_ADJ 14   setprop ro.EMPTY_APP_ADJ 15# Define the memory thresholds at which the above process classes will# be killed.  These numbers are in pages (4k).   setprop ro.FOREGROUND_APP_MEM 1536   setprop ro.VISIBLE_APP_MEM 2048   setprop ro.SECONDARY_SERVER_MEM 4096   setprop ro.HIDDEN_APP_MEM 5120   setprop ro.CONTENT_PROVIDER_MEM 5632   setprop ro.EMPTY_APP_MEM 6144# Write value must be consistent with the above properties.   write /sys/module/lowmemorykiller/parameters/adj 0,1,2,7,14,15   write /proc/sys/vm/overcommit_memory 1   write /sys/module/lowmemorykiller/parameters/minfree 1536,2048,4096,5120,5632,6144   class_start default   # Set init its forked children's oom_adj.   write /proc/1/oom_adj -16

Routines to actually calculate the oom_adj value, based on application stateare in the ActivityManager. See frameworks/base/services/java/com/android/server/am/ActivityManagerService.java:UpdateOomAdjLocked(...)

andframeworks/base/core/java/android/os/Process.java:setOomAdj() =>frameworks/base/core/jni/android_util_Process.cpp:android_os_Process_setOomAdj()

init sequence

See this blog entry for an overview of the sequence of operations performed by the 'init' program:http://blog.csdn.net/loughsky/archive/2008/11/13/3293922.aspx

kernel power management

See http://mjg59.livejournal.com/100221.html for a discussion of kernel modifications to support power management.

(Also, the comments are interesting, in that they delve into (and speculate about) the possible history ofcertain components of the Android system.)

C Library (bionic) info

See the excellent article: http://codingrelic.geekhold.com/2008/11/six-million-dollar-libc.htmlfor an overview of bionic.

From: http://discuz-android.blogspot.com/2008/10/google-android-native-libc-bionic.html

Google developed a custom library for the C compiler (libc) called Bionic. This was necessary for three main reasons:

  • License: they wanted to keep GPL out of user-space. Bionic code uses the BSD license.
  • Size: the library has to be loaded in each process, so it needs to be small. Bionic is about 200K, or half the size of glibc (the GNU version of libc).
  • Speed: limited CPU power means it needs to be fast. Bionic has a small size and fast code paths, including a very fast and small custom pthread implementation.

Bionic has built-in support for important Android-specific services such as system properties and logging. It doesn’t support certain POSIX features, like C++ exceptions and wide chars, which were not needed on Android. Thus it’s not quite compatible with the gnu libc. All native code must be compiled against bionic, not glibc.

threads

The bionic C library has its own thread API, not the same as either original LinuxThreads orNPTL.

From: http://www.mail-archive.com/uclibc@uclibc.org/msg02787.html

android thread library (from bionic libc) is minimalist : - use most of the linux kernel thread features (futex, CLONE_THREAD) unlike old linuxpthread.- it doesn't support thread cancellation (see CAVEATS file)- it misses some pthread functions : for example no barrier, missing *timedwait variant, ...- very basic gdb support that only work through gdbserver- some theoretic race

Development Tools

Busybox

Android ships with a utility suite (called 'toolbox') that is not busybox.

You can get a binary busybox for Android hereThe site includes instructions for easy installation on your device.

Bootchart

The 'init' program in Android has built-in capability to gather the data needed to produce abootchart image. See README.BOOTCHART in the directory system/core/init directory of the Androidsource repository for details.

See Using Bootchart on Android

Benchmarks

Apparently, droidbench is an integrated benchmark programfor Android.

Development Tips

debugging tips

Quick stack dump - "kill -3 <pid>" will put a stack trace in the log file. (Use logcat to view)

Using 'fastboot'

  • Fastboot quick overview
  • Fastboot cheat sheet

Re-flashing a device

See How (not) to brick the Android Developer Phone, Feb. 2009, LWN.net

Android 101 by Haykuro - describes basic re-flashing ofa G1 (so has some non-ADP1 information).

Tutorial on Android flash partitions

HOWTO: Unpack, Edit, and Repack Boot Images is agood tutorial on Android Flash partitions.

Nandroid (NAND flash backup tool)

Nandroid is a tool forbacking up your flash partitions. It is highly recommended if you plan to experiment with customizationsof your system software. It requires busybox (not in regular Android images).

Compiling native applications

Because Android uses its own C library (not glibc), it is tricky to compile native applicationsfor.

Here are some instructions for compiling "hello world" on the android phone:http://android-tricks.blogspot.com/2009/02/hello-world-c-program-on-using-android.html

Building

See Updating and rebuilding Android LWN.net, May 2009

Building the kernel from scratch

See http://honeypod.blogspot.com/2007/12/compile-android-kernel-from-source.html

Organizations

  • http://www.rethink-wireless.com/?article_id=1264 - Japan Consortium with 25 members - Open Embedded Software Foundation (OESF)- started in March to promote non-phone Android devices in Japan.

Android taxonomy

The information in this wiki needs to be better organized. So I'm creating a taxonomy of topics for Android systemdevelopers.NOTE: This section of the page is a work-in-progress.

Categories of information:

  • kernel
    • where to obtain
    • how to install on phone, on emulator
    • what version to use
    • kernel features unique to android (wakelocks, binder)
    • code names for boards/hardware
    • msm bsp highlights
  • libc (bionic)
    • where to obtain
    • license
    • how to install on phone, on emulator
    • comparison with glibc, uclibc
  • development tools
    • eclipse (I still can't use it)
    • traceview
    • logs
    • toolchains
    • repo
    • adb, android, emulator
  • booting
    • boot sequences (firmware, partitions, images)
    • bootchart
    • init
  • power management
    • wakelocks
    • application life-cycle
  • memory usage
    • oom killer, app life-cycle
    • smem reports
    • dalvik memory usage
  • security
  • programs (outside scope of this wiki - many other resources available)
    • API
    • toolchains
    • dalvik
    • DEX
    • JNI
  • scripts
    • ASE
  • hardware
  • distros