"Android Anatomy and Physiology",: http://download.csdn.net/detail/wuxiaoer717/6839427
Outline:
1. Android Profiling
- Linux kernel
- Local library (Native Libraries)
- Android Runtime (Android runtime)
- Application Framework
2. Android operating mechanism
- Start process
- Interlayer interaction (Layer Interaction)
First, Android anatomy
As shown in the architecture diagram for Android
1. Linux kernel
- The Android system is based on the Linux kernel, but Android is not Linux.
- There is no local windowing system.
- There is no support for the GLIBC library.
- The complete standard Linux toolset is not included.
- The standard Linux 2.6.24 kernel.
- Kernel enhancement patches to support Android.
1) Why choose the Linux kernel?
- Powerful kernel and process management.
- A permissions-based security model.
- A reliable drive model.
- Supports shared libraries.
- It's already open source.
2) Kernel Enhancements
- Alarm
- Ashmem
- Binder
- Power Management
- Low Memory Killer
- Kernel Debugger
- Logger
Binder IntroductionProblem: Applications and services run in their own processes, and processes must communicate and share data. IPC (interprocess communication) introduces a huge amount of processing overhead and security vulnerabilities. Workaround:
- Use drivers to assist interprocess communication (IPC).
- Gain high performance through shared memory.
- For processing requests, one thread pool per process.
- Reference count, the reference to the object is mapped across processes.
- Between processes is a synchronous call.
The implementation mechanism of binder is as follows: Android Interface Definition language (AIDL) See: http://developer.android.com/guide/components/aidl.html PM describes the problem: mobile devices are dependent on battery power to run, the battery has limited capacity. Workaround:
- Linux-based power Management (PM) building
- A more powerful power management strategy
- Power management via "wake locks"
- supports different types of wake locks
PM implementation in Android: as shown in the Android kernel source code can be obtained by the following http://git.android.com2 Local LibrariesThe local libraries include:
- Bionic LIBC
- Function Libraries
- Native Servers
- Hardware Abstraction Libraries
What is Bionic? Custom LIBC implementation, optimized for embedded. Why Choose Bionic? Why build a custom libc library? Mainly consider the following aspects:
- License: Keep the GPL licensed from the user's perspective.
- Size: It needs to be small because it will be loaded into each process.
- Rate: Limited CPU capacity means that we need to be fast enough.
For Bionic libc:
- BSD License
- A small and Fast code path
- Very fast and small custom pthread implementations
- Built-in support for critical specific Androud services like 1) System Properties, Getprop ("My.system.property", buff, default); 2) log capability, Logi ("Logging a message with priority ' Info '");
- Some POSIX features are not supported.
- Incompatible with GNU LIBC (GLIBC).
- Because the native code must rely on bionic to compile.
Feature library (function Libraries) WebKit
- Open Source-based WebKit browser: http://www.webkit.org
- Render pages in full view
- Full support Css,javascript,dom,ajax
- Supports single-column and adaptive view rendering
Media Framework
- Based on PacketVideo Opencore platform
- Support for standard video,audio,still-frame formats
- Support for hardware/software encoder plugins
Sqlite
- Lightweight Transactional data storage
- Back-end data storage for most platforms
Native Servers has two major categories of surface Flinger and audio flinger for surface Flinger
- Provides a system-wide appearance of the "combo" that handles all appearance rendering to the frame buffer device.
- You can combine 2D and 3D appearances and the appearance of multiple apps.
- Surfaces is passed as buffer to be called through the binder IPC.
- OpenGL ES and 2D hardware accelerators can be used as part of it.
- Use the Page-flip double buffer mechanism.
As shown in the show
For audio Flinger
- Manage all audio output devices.
- Process multiple audio streams to the PCM audio output path.
- Handles audio routing to each output.
As shown in the location of the hardware abstraction layer (HAL) hardware abstraction layer in the Android system hierarchy. The hardware abstraction layer has the following characteristics:
- User space C/C + + library layer.
- Defines an interface that allows Android to request hardware "drivers" to implement.
- Separate the Android platform logic and hardware interfaces.
So why do you need a user-space Hal in Android? The main reasons are as follows:
- Not all components have a standard kernel-driven interface;
- The kernel driver is the GPL, which exposes all intellectual property rights;
- Android has specific requirements for hardware drivers.
HAL Header Example:[CPP]View Plaincopy
- Must be provided by each ACME hardware implementation
- typedef struct {
- Int (*foo) ( void);
- char (*bar) ( void);
- ...
- } acmefunctions;
- Const Acmefunctions *acme_init (const struct ENV *env, int argc, char
- **ARGV);
Library dynamically loaded on demand when runtime[CPP]View Plaincopy
- Dlhandle = Dlopen ("/system/lib/libacme.so", Rtld_now);
- ...
- Acmeinit = (const acmefunctions * (*) (const struct ENV *,
- int, char * *)) Dlsym (Dlhandle, "acme_init");
- ...
- Acmefuncs = Acmeinit (&env, argc, argv);
3.Android RuntimeDalvik virtual machines are virtual machines that are customized for purification in Android, due to the following features:
- Provides application portability and run-time consistency
- Run optimized file format (. dex) and Dalvik bytes
- Java. class/. jar files are converted to. dex format at build time
Dalvik Designed for embedded environments
- Support for multiple virtual machine processes on each device;
- Highly optimized byte-code interpreter for CPU;
- Efficient use of runtime memory.
Core APIs in the kernel Libraries Java language provide a powerful, yet simple and familiar development platform.
- Data structure (data Structure)
- Tools (Utilities)
- File access
- Network access
- Graphic (graphics)
- ...
4. Application framework (application frameworks)Core Platform services with the following features:
- Services are required for Android platforms.
- Behind the scenes-apps don't directly access them.
The main services are as follows:
- Activity Manager
- Package Manager
- Window Manager
- Resource Manager
- Content Provider
- View System
Hardware service (Hardware services)
- Provides access to the underlying hardware APIs.
- Typically accessed through a local manager object. For example:
[Java]View Plaincopy
- Locationmanager lm = (locationmanager) context.getsystemservice (Context.location_service);
The main hardware services are as follows:
- Telephony Service
- Location Service
- Bluetooth Service
- WIFI Service
- USB Service
- Sensor Service
For more information on application frameworks, refer to:
- Google I/o: "Inside the androoid application Framework"
- Online:http://code.google.com/android
Second, the Android operating mechanism1. Start the processAll start from init ... Similar to most Linux-based systems in the boot phase, bootloader loads the Linux kernel and then starts the init process. Init launches the Linux daemon, including:
- USB Daemon (USBD) to manage USB connections
- Android Debug Bridge Daemon (ADBD) to manage ADB connections
- Debugger Daemon (debuggerd) to manage debug process requests (dump memory, etc.)
- RF Interface Layer Daemon (rild) to manage communication with RF
The init process starts the zygote process:
- A new process Initializes a Dalvik VM instance
- Load class, and listen for socket port for request to create VMS instance
- Forks request to create VM instances for managing processes
- Write-time replication (copy-on-write) to maximize reuse and minimize overrides
The init process starts the runtime process:
- Initializing the service manager--context manager for Binder to process service registrations and queries
- Registering Service Manager as the default context management for binder
The runtime process sends a request to zygote to start the system service and then the zygote process fork A new VM instance for the system service process and then start the service. The system service starts the LocalSystem server, including:
- Surface Flinger
- Audio Flinger
The local system servers registers Servicee Manager as the IPC service target: System service launches Android Managed Service: Android Management Service is registered to Service Manager: here, After startup of the entire Android system: System server is ready after loading all services ...2. Inter-tier interaction (layer Interaction)There are three main types of interactions:
- APP, Runtime Service, Lib
- APP, Runtime Service, Native service-Lib
- APP--Runtime Service, Native Daemon, Lib
Android Runtime Services: Example: Location Manager Android Native Services: Example: Daemon Connection: Example: Rild