Android development and learning-Basics

Source: Internet
Author: User

This article aims to record the stars learned during the study and development of the Android system for future use ~ The content includes: development environment, installation program, system partition, Directory Overview, process analysis, and kernel comparison.

> Development Environment
1. Install eclipse and Android-SDK, decompress and install
2. Install the AVD plug-in https://dl-ssl.google.com/android/eclipse/ in eclipse and configure the SDK location
3. Open SDK manager to install Android packages and configure Virtual Device (for example, android_2.2)
4. Start virtual device, run emulator.exe-AVD android_2.2, or directly start from eclipse.

> Installer
1. Installation: ADB install xxx.apk
2. reinstall ADB install-r xxx.apk
3. Uninstall: ADB uninstall com. Android. xxx
The installation path of the program is/data/APP/. The configuration file is under/data.

> System partition
# ADB Shell
# Mount
Rootfs/rootfs Ro 0 0
Tmpfs/dev tmpfs RW, mode = 755 0 0
Devpts/dev/PTS devpts RW, pattern = 600 0 0
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 = 0 k, mode = 000 0 0
The above is the partition structure of the Android system. It can be seen that the mounting method is very similar to that of Linux. friends familiar with Linux should be able to easily see what the role of these partitions is. It should be noted that the core partitions/dev/block/mtdblock * (written to Rom) are all using the yaffs2 File System (based on flash storage ), among them, the/system partition only has special Ro read-only permissions. This shows that android has made some efforts in security design. In addition,/dev/block/vold is said to be designed to replace udev functions and is mainly used to support some hot swapping devices.

> Directory Overview
# Ls-l
Dr-x ------ Root config
Drwxrwx --- system cache 2011-06-21 05:32 Cache
Lrwxrwxrwx Root sdcard->/mnt/sdcard
Drwxr-XR-x Root Acct
Drwxrwxr-x root system mnt
Lrwxrwxrwx Root D->/sys/kernel/debug
Lrwxrwxrwx Root etc->/system/etc
Drwxr-XR-x Root 2010-06-30 21:06 System
Drwxr-XR-x Root 1970-01-01 00:00 sys
Drwxr-x --- Root 1970-01-01 sbin
Dr-XR-x Root 1970-01-01 00:00 proc
-Rwxr-x --- Root 12995 init. RC
-Rwxr-x --- Root 1677 1970-01-01 00:00 init. Goldfish. RC
-Rwxr-x --- Root 107412 init
-RW-r -- root Root 118 default. Prop
Drwxrwx -- X system System Data
Drwx ------ Root 2010-01-28 00:59 Root
Drwxr-XR-x Root Dev
The above is the file directory under the android root directory. According to the previous partition structure, we can roughly see the location and functions of each directory. The following describes several important directories/files:
1. MNT mount point directory
2. Main configuration files of the ETC System
3. System Android System File
4. sys Linux Kernel File
5. Proc runtime File
6. init. RC Startup Script
7. Default. Prop system property configuration file
8. Data User Program directory
9. Dev Device File

# Ls-L/System
Drwxr-XR-x Root 2010-06-30 21:03 USR
Drwxr-XR-x Root 2010-06-30 app
Drwxr-XR-x Root 2010-06-30 21:05 lib
Drwxr-XR-x Root 2010-06-30 etc
Drwxr-XR-x Root 2010-06-30 framework
-RW-r -- root Root 1532 2010-06-30 build. Prop
Drwxr-XR-x root shell 2010-06-30 21:04 xbin
Drwxr-XR-x Root 2010-06-30 21:00 TTS
Drwxr-XR-x Root 2010-06-30 21:00 Media
Drwxr-XR-x Root 2010-06-30 21:00 Fonts
Drwxr-XR-x root shell 2010-06-30 21:04 Bin
Drw-RW-Root lost + found
The above is a brief introduction to the main file directories under the system directory:
1. USR user folders, including sharing, keyboard layout, and time zone files
2. apps that are routinely downloaded by the app. These APK packages are all protected.
3. Underlying library of the Lib system, such as the Runtime Library of the platform.
4. The configuration file of the ETC system, such as the core configuration of the APN Access Point settings.
5. files of the core framework of the Framework Android system
6. Build. Prop Android system property configuration file
7. Common xbin development tools, such as tcpdump and sqlite3
8. Bin system tools, such as PS, CP, and PM

# Ls-L/Data
Drwx ------ Root Property
Drwxrwx -- T system MISC 2011-06-21 05:32 Misc
Drwxrwx -- X shell 2011-06-21 05:32 local
Drwxrwx -- X system app-Private
Drwx ------ system 2011-06-21 05:33 backup
Drwxrwxr-x System system ANR
Drwxrwx -- X system app
Drwxrwx -- X system System Data
Drwxr-x --- root log 2011-06-21 05:32 dontpanic
Drwxrwx -- X system Dalvik-Cache
Drwxrwxr-x System system System
Drwxrwx --- Root 2011-06-21 05:32 lost + found
We can see that the structure in the/data directory is related to the application. We will not go into details here, as you can see, the user applications and game programs we usually install are installed under/data/app.

# 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. 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/bin:/system/xbin
PS1 = '#'
PS2 = '>'
PS4 = '+'
Pwd =/
_ =/System/xbin
From the system variables, we can also see some important directories used by the system.

> Process Analysis
# Ps
User PID ppid vsize RSS wchan PC name
Root 1 0 312 220 c009b74c running ca4c 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 c004b2c400000000 s events/0
......
Root 27 1 740 196 c0158eb0 afd0d8ac S/system/bin/sh
System 28 1 808 204 c01a94a4 afd0db4c S/system/bin/servicemanager
Root 29 1 3736 372 ffffffff afd0e1bc S/system/bin/vold
Root 30 1 3716 336 ffffffff afd0e1bc S/system/bin/netd
......
System 59 33 183396 25580 ffffffff afd0db4c s system_server
App_0 108 33 134184 14876 ffffffff afd0eb08 s com. Android. inputmethod. Pinyin
Radio 112 33 147300 15804 ffffffff afd0eb08 s com. Android. Phone
App_25 122 33 149408 19932 ffffffff afd0eb08 s com. Android. Launcher
System 124 33 136708 13172 ffffffff afd0eb08 s com. Android. Settings
App_0 148 33 148892 18044 ffffffff afd0eb08 s Android. process. acore
......
From this we can see that, like Linux, all processes use init. The following system processes are similar to Linux, followed by some system daemon (native service ), finally, it is an important application of the system. Through this list, we can see some clues about the android startup process.

> Kernel comparison
Like the standard Linux kernel, the android kernel mainly implements memory management, process scheduling, and inter-process communication. For the root directory structure of the kernel source code tree of the latest Android kernel code version cupcake (Linux kernel version 2.6.27), the android kernel source code is no different from the standard Linux kernel, however, after detailed comparison with the source code of the standard Linux kernel, we can find that the android kernel and the standard Linux kernel are different in terms of file system, inter-process communication mechanism, and memory management.
1. File System:
Unlike desktop systems and servers, most mobile devices use flash as the storage media instead of hard disks. Therefore, the android kernel has added the standard Linux File System yaffs2 for flash. Good support for NAND/flash chips. Yaffs2 is a log-structured file system that provides loss balancing and power loss protection to effectively avoid the impact of unexpected power outages on file system consistency and integrity. The hierarchical design of yaffs2 consists of file management interfaces, internal implementation layers, and NAND, which simplifies the EI design of the system and can be easily integrated into the system. Tests show that the performance ratio of yaffs2 is supported.
Nor flash memory jffs2 file system is better.
2. inter-process communication mechanism:
Android adds an inter-process communication mechanism IPC binder. The binder manages the services in the system through the Daemon Service Manager and is responsible for data exchange between processes. Each process accesses the same shared memory through the binder to achieve the data communication mechanism. From the application layer perspective, the process obtains the program framework interface for data exchange by accessing the data daemon, calls and shares data through the interface, while other processes need to access data, it also only needs to interact with the program framework interface, facilitating programmers to develop applications that need to interact with data.
3. Memory Management:
In the memory management module, the android kernel adopts a low memory management policy different from the standard Linux kernel. In the standard Linux kernel, a low memory management policy called out of memory is used. When the memory is insufficient, the system checks all processes and scores the processes, processes with the highest score will be shut down (except kernel processes), while Android uses a mechanism called lmk (low memory killer, this mechanism classifies and groups processes according to their importance. When the memory is insufficient, the processes in the lowest level are disabled. For example, if the UI of a mobile device is at the highest level, the process will never be aborted. In this way, the system runs stably for end users. At the same time, Android
A Memory Sharing processing method, ashmem (anonymous shared memory), is added ). With ashmem, processes can freely share named memory blocks anonymously, which is not supported in standard Linux.
4. Power Management:
Because Android is mainly used for mobile devices, power management is particularly important. Therefore, a new power management policy is added to the android kernel. Currently, Android uses a simple power management strategy, which enables power management by switching the screen, switching the screen backlight, switching the keyboard backlight, switching the button backlight, and adjusting the screen brightness, the sleep and standby functions are not implemented. Currently, there are three ways to determine and adjust the Power Management Policy: RPC call, battery status change, and power supply settings. It connects to other modules by broadcasting intent or directly calling APIs. The power management policy also has an automatic shutdown mechanism. When the power supply is lower than the minimum acceptable level, the system will automatically shut down. In addition, Android
The power management module automatically adjusts the screen brightness based on user behavior.
5. drivers and others:
Compared with the standard kernel, the android kernel also adds drivers for character output devices, image display devices, keyboard input devices, RTC devices, and USB device devices, and adds a logger system, allows applications to access log messages, giving developers greater freedom.

To be continued...

Related Article

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.