2014年3月25日 星期二

Linux - data transfer between kernel/user space


  • put_user(x, ptr)
    - Write a simple value into user space
    • x - Value to copy to user space
    • ptr - Destination address in user space
  • get_user(x, ptr)
    - Get a simple variable from user space
    • x - Variable to store result
    • ptr - Source address in user space
  • copy_to_user(void __user *to, const void *from, unsigned long n);
    - Copy a block of data into user space
  • copy_from_user(void *to, const void __user *from, unsigned long n);
    - Copy a block of data from user space

2014年3月18日 星期二

Android build instruction


  1. build
    1. m - build all modules from the top of the tree
    2. mm - build all of the modules in current directory
    3. mmm - build all of the modules in the supplied directory
  2. make
    1. make systemimage - system.img
    2. make ramdisk - ramdisk.img
    3. make userdataimage - userdata.img
    4. make snod - build system.img quickly without checking the dependency
  3. misc
    1. croot - change directory to the top of the tree
    2. cgrep - grep on all local c/c++ files
    3. jgrep - grep on all local java files
    4. resgrep - grep on all local res/*.xml files
    5. godir - go to directory containing a file.
    6. printconfig - print the current build configuraiton

2014年3月17日 星期一

Linux init.rc (android)


Trigger sequence
   "early-init" -> "init" -> "early-fs" -> "fs" -> "post-fs" -> "early-boot" -> "boot"

At the end of "boot" trigger, start corresponding services
   class_start core
   class_start main




Android Zygote



  1. Linux kernel start the 1st process - init
  2. init fork a child process - ServiceManager 
  3. init fork a child process - Zygote
  4. Zygote 
    1. Fork an child process for SystemServer (register to ServiceManager)
    2. Main process is waiting to fork child processes of user applications from ActivityManagerService via socket



  • Linux - fork() function
    • return child pid in parent process
    • return 0 in child process

2014年3月16日 星期日

Process/Thread in each OS


  1. MS DOS
    1. Single-Process
    2. Single-Thread
  2. Java VM
    1. Single Process
    2. Multi-Thread
  3. Unix - traditional
    1. Multi-Process
    2. Single-Thread
  4. Linux, Windows, Solaris, ...
    1. Multi-Process
    2. Multi-Thread



2014年3月10日 星期一

Android App components

4 types of Android application components.

  • Activities - foreground UI handler
  • Services - background service routine
  • Content Providers - share app data, such as SQLite or data in filesystem.
  • Broadcast Receivers - response to system-wide broadcast

Android useful commands

am - Activity Manager
  example:
    $ am start -n com.android.browser/com.android.browser.BrowserActivity

dumpsys - Dump interesting information about the status of system service.
  example:
    $ dumpsys | grep "mFocusedApp"

aapt - Android Asset Packaging Tool
  usage:
 aapt l[ist] [-v] [-a] file.{zip,jar,apk}
   List contents of Zip-compatible archive.

 aapt d[ump] [--values] WHAT file.{apk} [asset [asset ...]]
   badging          Print the label and icon for the app declared in APK.
   permissions      Print the permissions from the APK.
   resources        Print the resource table from the APK.
   configurations   Print the configurations in the APK.
   xmltree          Print the compiled xmls in the given assets.
   xmlstrings       Print the strings of the given compiled xml assets.

 aapt p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] \
        [-0 extension [-0 extension ...]] [-g tolerance] [-j jarfile] \
        [--min-sdk-version VAL] [--target-sdk-version VAL] \
        [--max-sdk-version VAL] [--app-version VAL] \
        [--app-version-name TEXT] [--custom-package VAL] \
        [-I base-package [-I base-package ...]] \
        [-A asset-source-dir]  [-G class-list-file] [-P public-definitions-file] \
        [-S resource-sources [-S resource-sources ...]]         [-F apk-file] [-J R-file-dir] \
        [raw-files-dir [raw-files-dir] ...]

   Package the android resources.  It will read assets and resources that are
   supplied with the -M -A -S or raw-files-dir arguments.  The -J -P -F and -R
   options control which files are output.

 aapt r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]
   Delete specified files from Zip-compatible archive.

 aapt a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]
   Add specified files to Zip-compatible archive.

 aapt v[ersion]
   Print program version.