Android System Development Learning notes (GO)

Source: Internet
Author: User

http://blog.csdn.net/shagoo/article/details/6709430

> Development Environment
1. Install Eclipse and ANDROID-SDK and unzip the installation
2. Eclipse Install AVD plugin https://dl-ssl.google.com/android/eclipse/and configure SDK location
3. Open SDK Manager to install Android packages and configure Virtual device (for example, named: android_2.2)
4. Start Virtual device, execute: EMULATOR.EXE-AVD android_2.2, or launch directly from Eclipse

> installation program
1. Installation: adb install xxx.apk
2. Reload: adb install-r xxx.apk
3. Uninstall: adb uninstall com.android.xxx
Program installation Location:/data/app/, configuration file under/data/data

> System Partitioning
# adb Shell
# mount
Rootfs/rootfs RO 0 0
Tmpfs/dev Tmpfs rw,mode=755 0 0
Devpts/dev/pts devpts rw,mode=600 0 0
PROC/PROC proc RW 0 0
Sysfs/sys Sysfs RW 0 0
None/acct cgroup RW,CPUACCT 0 0
Tmpfs/mnt/asec Tmpfs rw,mode=755,gid=1000 0 0
None/dev/cpuctl cgroup rw,cpu 0 0
/dev/block/mtdblock0/system YAFFS2 RO 0 0
/dev/block/mtdblock1/data YAFFS2 Rw,nosuid,nodev 0 0
/dev/block/mtdblock2/cache YAFFS2 Rw,nosuid,nodev 0 0
/dev/block/vold/179:0/mnt/sdcard vfat rw,dirsync,nosuid,nodev,noexec,uid=1000,gid=1015,fmask=0702,dmask=0702, Allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
/dev/block/vold/179:0/mnt/secure/asec vfat rw,dirsync,nosuid,nodev,noexec,uid=1000,gid=1015,fmask=0702,dmask= 0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
Tmpfs/mnt/sdcard/.android_secure Tmpfs ro,size=0k,mode=000 0 0
The above is the partition structure of the Android system, it can be seen that the way the mount and Linux very similar, familiar with the Linux friends should be able to easily see what the role of these partitions is probably. It is possible to explain the/dev/block/mtdblock* of these core partitions (write ROM), they are using the YAFFS2 file system (based on FLASH storage), which is/system this partition only special RO read-only permissions, this shows and Some of the roid in security design. In addition,/dev/block/vold is said to be designed to replace Udev's functions, mainly used to support some hot-swappable devices.

> Catalogue Overview
# ls-l
dr-x------root root 2011-08-18 10:36 Config
DRWXRWX---system cache 2011-06-21 05:32 Cache
lrwxrwxrwx root root 2011-08-18 10:36 sdcard/mnt/sdcard
Drwxr-xr-x root root 2011-08-18 10:36 Acct
Drwxrwxr-x root system 2011-08-18 10:36 mnt
lrwxrwxrwx root root 2011-08-18 10:36 D-/sys/kernel/debug
lrwxrwxrwx root root 2011-08-18 10:36 etc,/system/etc
Drwxr-xr-x root root 2010-06-30 21:06 system
Drwxr-xr-x root root 1970-01-01 00:00 sys
Drwxr-x---root root 1970-01-01 00:00 sbin
Dr-xr-xr-x root root 1970-01-01 00:00 proc
-rwxr-x---root root 12995 1970-01-01 00:00 init.rc
-rwxr-x---root root 1677 1970-01-01 00:00 init.goldfish.rc
-rwxr-x---root root 107412 1970-01-01 00:00 Init
-rw-r--r--root root 118 1970-01-01 00:00 Default.prop
Drwxrwx--x System system 2011-08-12 06:54 data
drwx------root root 2010-01-28 00:59 root
Drwxr-xr-x root root 2011-08-18 10:36 Dev
The above is the directory of the Android root directory, according to the previous partition structure can be seen in the location and approximate function of each directory, the following is a description of several important directories/files:
1. List of mnt mount points
2, ETC system main configuration file
3. system files for Android
4. SYS Linux kernel file
5. Proc Run-time file
6. init.rc Startup script
7. Default.prop System Property Profile
8. Data User Program Directory
9. Dev Device file

# ls-l/system
Drwxr-xr-x root root 2010-06-30 21:03 usr
Drwxr-xr-x root root 2010-06-30 21:07 app
Drwxr-xr-x root root 2010-06-30 21:05 Lib
Drwxr-xr-x root root 2010-06-30 21:07 etc
Drwxr-xr-x root root 2010-06-30 21:06 framework
-rw-r--r--root root 1532 2010-06-30 20:58 Build.prop
Drwxr-xr-x root Shell 2010-06-30 21:04 xbin
Drwxr-xr-x root root 2010-06-30 21:00 TTS
Drwxr-xr-x root root 2010-06-30 21:00 Media
Drwxr-xr-x root root 2010-06-30 21:00 fonts
Drwxr-xr-x root Shell 2010-06-30 21:04 bin
Drw-rw-rw-root Root 2011-08-18 10:36 lost+found
The above is the main file directory under the system directory below is also a brief introduction:
1. USR user folder, including sharing, keyboard layout, time zone files, etc.
2, App download app, these apk packages are protected OH
3, Lib system underlying library, such as Platform runtime library, etc.
4, etc system configuration files, such as APN access point settings and other core configuration, etc.
5. Framework Android platform Core framework Files
6. Build.prop Android System Property profile
7, XBin Common development tools, such as tcpdump/sqlite3, etc.
8, bin system tools, such as PS/CP/PM, etc.

# ls-l/data
drwx------root root 2011-06-22 02:32 property
DRWXRWX--T System Misc 2011-06-21 05:32 Misc
Drwxrwx--x Shell Shell 2011-06-21 05:32 Local
Drwxrwx--x System System 2011-06-21 05:32 App-private
DRWX------System System 2011-06-21 05:33 Backup
Drwxrwxr-x System System 2011-08-12 06:54 ANR
Drwxrwx--x System system 2011-08-20 06:50 app
Drwxrwx--x System system 2011-08-20 06:50 data
Drwxr-x---Root log 2011-06-21 05:32 dontpanic
Drwxrwx--x System System 2011-08-20 06:50 Dalvik-cache
Drwxrwxr-x System System 2011-08-22 06:40 System
drwxrwx---root root 2011-06-21 05:32 lost+found
Can see the/DATA directory structure is related to the application, here we do not do scrutiny, we know that our usual installation of the user application/game programs are installed under the/data/app can be.

# set
Android_assets=/system/app
Android_bootlogo=1
Android_data=/data
android_property_workspace=9,32768
Android_root=/system
Asec_mountpoint=/mnt/asec
bootclasspath=/system/framework/core.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/ Framework/android.policy.jar:/system/framework/services.jar
External_storage=/mnt/sdcard
Ifs= '
‘
Ld_library_path=/system/lib
Optind=1
Path=/sbin:/system/sbin:/system/bin:/system/xbin
ps1= ' # '
Ps2= ' > '
ps4= ' + '
pwd=/
_=/system/xbin
From the system variables we can also see some important directories in the use of the system.

> Process Analysis
# PS
USER PID PPID vsize RSS Wchan PC NAME
Root 1 0 312 c009b74c 0000ca4c s/init
Root 2 0 0 0 c004e72c 00000000 S kthreadd
Root 3 2 0 0 C003fdc8 00000000 S ksoftirqd/0
Root 4 2 0 0 C004b2c4 00000000 S events/0
... ...
Root 1 740 196 c0158eb0 AFD0D8AC s/system/bin/sh
System 1 808 204 C01A94A4 afd0db4c S/system/bin/servicemanager
Root 1 3736 372 ffffffff AFD0E1BC s/system/bin/vold
Root 1 3716 336 ffffffff AFD0E1BC s/system/bin/netd
... ...
System 183396 25580 ffffffff afd0db4c S system_server
App_0 108 134184 14876 ffffffff afd0eb08 S com.android.inputmethod.pinyin
Radio 147300 15804 ffffffff afd0eb08 S com.android.phone
APP_25 122 149408 19932 ffffffff afd0eb08 S com.android.launcher
System 124 136708 13172 ffffffff afd0eb08 S com.android.settings
App_0 148 148892 18044 ffffffff afd0eb08 S android.process.acore
... ...
From here we can see the same as Linux all the process portal is init, the next system process is similar to Linux, followed by some system daemon (Native Service), and finally the system important applications. With this list you can also see some clues to the Android startup process.

> Core Comparison
The Android kernel, like the standard Linux kernel, mainly implements functions such as memory management, process scheduling, interprocess communication, and so on. Looking at the root structure of the kernel source tree of the latest Android kernel code version cupcake (where the Linux kernel version is 2.6.27), the Android kernel source code is not different from the standard Linux kernel, but is compared in detail with the standard Linux kernel source. It can be found that the Android kernel differs from the standard Linux kernel in the file system, interprocess communication mechanism, memory management, and so on.
1. File system:
Unlike desktop systems and servers, most mobile devices use Flash as storage media instead of hard drives. As a result, the Android kernel adds standard Linux-specific file system YAFFS2 for Flash. The Nand/flash chip has a good support. The YAFFS2 is a log-structured file system that provides loss balancing and power-down protection, which effectively avoids accidental power outages affecting file system consistency and integrity. YAFFS2 is designed according to the hierarchy structure, divided into the file management interface, the internal realization layer and the NAND, simplifies its own and the system's connection EI design, can more conveniently integrate into the system. It has been tested to prove that YAFFS2 performance is better than JFFS2 file systems that support NOR-flash memory.
2. Inter-process communication mechanism:
Android adds an inter-process communication mechanism to IPC binders. Binder is responsible for the data exchange of process questions through the services in the Daemon Service Manager management system. Each process accesses the same piece of shared memory through Binder to achieve the mechanism of data communication. From the application-level perspective, the process accesses the data daemon to obtain the program framework interface for data exchange, invokes and shares data through the interface, and other processes need to interact with the program framework interface to facilitate the programmer to develop applications that require interactive data.
3, Memory management:
In the memory management module, the Android kernel employs a low-memory management strategy that differs from the standard Linux kernel. In the standard Linux kernel, a low memory management strategy called OOM (out of memory) is used, and when there is not enough RAM, the system checks all processes and limits the process to scoring, the process that gets the highest score is closed (except for the kernel process), and the Android The system uses a mechanism called LMK (Low Memory Killer), which processes the process down in the lowest-level group when the process is graded, grouped, and under-memory. For example, in a mobile device, the UI interface is at the highest level, so the process will never be aborted. Thus, in the end-user view, the system is stable operation. At the same time, Android has added a memory-sharing processing mode ASHMEM (Anonymous shared memory anonymous). Through Ashmem, the process can freely share the named memory block anonymously, which is not supported in standard Linux.
4, Power Management:
Because Android is primarily used for mobile devices, power management is particularly important. As a result, a new power management strategy has been added to the Android kernel. Currently, Android uses a simpler power management strategy that enables power management by switching the screen, switching screen backlight, switching keyboard backlight, switching button backlight, and adjusting the screen brightness without the sleep and standby functions. There are currently three ways to determine power management policies: RPC calls, battery status changes, and power settings. It contacts other modules by broadcasting Intent or invoking APIs directly, and the power management policy also has an automatic shutdown mechanism, which shuts down automatically when power is below the minimum acceptable level. In addition, the Android power Management module automatically adjusts the screen brightness based on user behavior.
5. Drive and other:
In contrast to the standard kernel, the Android kernel also adds device drivers such as character output devices, image display devices, keyboard input devices, RTC devices, usbdevice devices, etc., and adds a log (Logger) system that allows applications to access log messages, allowing developers to gain greater freedom.

Android System Development Learning notes (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.