(turn) know Android phone-from MIUI

Source: Internet
Author: User

============ Problem Description ============


MIUI began today to release the MIUI ROM adaptation tutorial, this is the first, outlining the Android partition and architecture, personally think it is helpful to understand Android, so reprint.
Original address: http://www.miui.com/thread-402322-1-1.html
Http://www.miui.com/thread-402302-1-1.html

Hello everyone, Welcome to the MIUI ROM adaptation tour. Before we begin our journey, let us introduce our general arrangements and requirements to you.

Our journey will be divided into six parts, completed within the next six days:

The first part: first of all, to understand the Android phone software structure, introduce some basic concepts.

Part II: Preparation, including the construction of tools and environments.

The third part: Anti-compilation, introduction APK structure, resource modification, Smali files and so on.

Part IV: porting the MIUI Framework

Part V: porting the MIUI APP

Part VI: Making a brush bag

This series of articles requires you to learn some Linux basics, understand the Java language, and have some Android programming experience better. This series of articles by MIUI all, please forward the time to indicate the reprint address. Due to the level of limitations, there are inevitably some errors in these articles, we welcome criticism.


MIUI ROM Adaptation Tour first day-Learn about Android phones


Write this article when I think of my first Android phone HTC Hero. After I bought it, my colleague told me I could go to the machine to play. Brush machine, how to brush? Colleagues said, you are a native, brush machine do not know, a lot of brush machine forum, you go to stroll, quite simple. I went to stroll around the Jifeng forum (not yet known miui), open a look, what recovery, radio, root all kinds of words rushing, oh my Lady Gaga, so complex. But in order not to be despised, and idle is also idle, or brush to play it. Later on to meet MIUI came to the millet. This is a digression, let's get down to the problem.

In this chaos of the Android world, how to find the brush Machine Avenue, perhaps it is just a legend, we just have been exploring. Let's look at it from scratch and see what we can find.

1. bootloader
When we get a phone, the first thing to do is to press the power button to boot, then from the boot to the desktop program, what happened in the middle of it, we start from the following simplified phone structure chart:



Note: The chart does not reflect the actual partition order and location of the phone, just a logical structure diagram.

We can simply compare the ROM storage of the phone to the hard disk on our computer, this hard disk is divided into several partitions: bootloader partition, boot partition, system partition and so on. Later, we will introduce the purpose of each partition gradually. The so-called brush machine we can simply understand that the software installed in certain sections of the phone, similar to the installation of our Windows system on the computer.

When the phone is powered up after pressing the power button, first executes the instruction from a fixed address in the bootloader partition, and the bootloader partition is divided into two parts, respectively called primary bootloader and secondary stage bootloader. The Primary bootloader primarily performs hardware detection to ensure that the hardware is working properly and then the secondary stage bootloader copied to memory (RAM) starts executing. Secondary stage bootloader will perform some hardware initialization work, get memory size information, and then enter into some startup mode according to the user's key. For example, we are familiar with the combination of the power key and some other keys, you can enter into the Recovery,fastboot or select the startup mode of the Start screen. The bootloader we see on the forums usually refer to secondary stage bootloader. However, we do not need to care about too much detail, can be simply understood as bootloader is a startup code, according to the user keys have a choice to enter some kind of boot mode.

FastBoot mode: FastBoot is a simple brush-machine protocol that is defined by Android, and can be brushed by fastboot command-line tools. For example, FastBoot flash boot boot.img This command is to write boot.img content brush to the boot partition. General handset manufacturers do not directly provide FastBoot mode brush machine, but to show their cattle B, will always provide their own proprietary brush machine tools and brush method. For example, Samsung's Odin, the motor's RSD, Huawei's powder screen and so on. But the essence is essentially the same, which is to flash the software directly into each partition.

Recovery mode: Recovery is a standard brush machine protocol defined by Android. When entering recovery mode, secondary stage bootloader starts from the recovery partition, and the recovery partition is actually a simple Linux system, and when the kernel is booted, it starts executing the first program init ( The INIT program is the ancestor of all Linux system programs). Init initiates a program called recovery (the name of the recovery mode is also derived from this). Through the recovery program, users can perform operations such as purging data, installing brush packs, and so on. General mobile phone manufacturers are providing a simple recovery brush machine, and the famous Cwm Recovery is a add a lot of enhancements to the recovery, to use the CWM recovery premise is recovery partition can be brush write. Everyone in the forum to see the unlock bootloader, usually refers to the unlock recovery or fastboot, allowing the brush to write recovery partition, so that everyone can use the favorite CWM recovery.

Mobile phones In addition to ordinary CPU chips, there are modem processor chip. The function of the chip is to achieve the mobile phone necessary communication function, we usually brush radio is to write the modem partition.

2. Normal start-up

When we just press the power button to boot, it goes into normal boot mode. Secondary stage bootloader starts from the boot partition. The boot partition format is fixed, first a header, then the Linux kernel, and finally the RAMDisk as the root filesystem.

In general, there will be a boot.img file in the complete brush package for each model, which is the boot partition image file. How to edit this image file can refer to this article Http://android-dls.com/wiki/inde ... Re-pack_boot_images.

When the Linux kernel starts, it starts executing the INIT program in the root filesystem, and the INIT program reads the startup script files (init.rc and init.xxxx.rc). The format of the startup script file you can find a lot of resources on the Internet, this is not written, and we have to transplant MIUI on the original ROM principle is not to modify the boot partition, because some models can not modify the boot partition.

There is an important configuration file in the root file system called Default.prop, which is generally the following:
#
# additional_default_properties
#
Ro.secure=1
Ro.allow.mock.location=1
Ro.debuggable=0
Persist.service.adb.enable=1.
Each row in the file assigns a value to a property, and in subsequent articles we also talk about properties. Here are two properties that everyone needs to be aware of: Ro.secure and ro.debuggable. If ro.secure=0 allows us to run the ADB root command. In the next article we will introduce ADB in detail, which is a powerful tool for our ROM transplant. Usually, the kernel root refers to ro.secure=0. Root privileges only on the phone there is a program named Authorization Management (SUPERUSER.APK) that grants permission to the root user of the program. Ro.deguggable=1 allows you to debug your system app.

The INIT program reads the startup script, executes the actions and commands specified in the script, and part of the script is the program that runs the system partition, and in the next section we look at the structure of the system partition.

3. System Partition
Before we talk about the system partition, let's take a look at the Android software architecture diagram below.




From top to bottom:
Core Application layer: This layer is a common contact with a variety of systems to bring their own applications, such as contacts, telephone, music and so on. The application layer is down to the developer's touch.

Framework layer: This layer is the core of Android system, it provides the whole Android system operation mechanism, like window management, program installation package management, developer contact activity, Service, broadcast and so on.

JNI layer: The JNI layer is a mechanism for Java programs to communicate with the underlying operating system, which allows Java code to invoke C + + code to access the underlying operating system's APIs.

Dalvik Virtual machines: Android Development uses the Java language, and the Java code of the application is compiled into Dalvik virtual machine bytecode, which is interpreted by the Dalvik virtual machine.

Local library: The local library is usually developed by the C + + language, directly compiled into the corresponding CPU machine code, which contains the standard C library, used to draw graphics Skia library, browser core engine WebKit and so on.

HAL: Hardware abstraction layer, in order to work with the different hardware of various manufacturers, Android defines a set of hardware interfaces, for example, in order to use the camera, the manufacturer's camera driver must provide the interface method. This allows the upper-level code to run independently of the different hardware.

Factory adaptation Layer: Originally Android-defined HAL layer is directly and manufacturers to provide device driver to deal with, but at present manufacturers do not want to open source HAL part of the code, so many manufacturers have provided a I call the manufacturer of the appropriate layer of code, This implementation of the HAL layer interface is simply a simple call to the manufacturer's adaptation layer interface function.

Kernel: This layer is familiar with the Linux kernel, the kernel contains a variety of hardware drivers, these drivers of different handset manufacturers different phones are not the same. The Linux kernel is a driver-driven modular mechanism, which is simply to allow users to dynamically load or unload a hardware driver, but for now, mobile phone manufacturers in addition to providing WiFi driver separately loaded, the other drivers are bound together with the kernel.

From this software architecture view, except that the kernel is placed outside the boot partition, the code for the other layers is in the system partition.

The following diagram describes the main directory contents of the system partition:
System/app:app directory is stored in the core application, which is known to the System app, these systems bring the program is not easy to uninstall, to be removed by some special means (you are familiar with a method is to use the RE file manager).

The System/lib:lib directory contains all the dynamic link libraries (. So files) that comprise the JNI layer, the Dalvik virtual machine, the local library, the HAL layer, and the factory adaptation layer.

System/framework: This directory contains the framework layer jar package, which has 3 most important jar packages (Framework.jar, Android.policy.jar, Services.jar) for MIUI porting. The following article will focus on these 3 packages.

System/fonts: The system default font file is stored in this directory.

System/media: This directory is stored in the system used by the various media files, such as boot music, animation, wallpaper files and so on. Different phones The directory may not be organized the same way. How to modify these files please refer to the online model of the various types of tutorials, here no longer redundant.

System/bin: Some executables are stored in this directory and are basically written by C + +. There is an important command called App_process, which is described separately in the next section.

System/xbin: This directory contains some extended executables, both of which can be empty. The common busybox is placed in this directory. The various symbolic link commands created by BusyBox are placed in the directory.

System/build.prop:build.prop and the previous section say that the Default.prop file format in the root filesystem is called a property profile. They all define property values that the code can read or modify. Property values have some naming conventions:
RO begins with a read-only property, which means that the value code of these properties cannot be modified.
Persist the values of these properties are saved in the file, so the values are retained after the restart.
Other properties typically begin with the category they belong to, which are readable and writable, but are not persisted after a restart of their modifications.
Many ROM producers will modify the Build.prop information, some of the properties that start with ro.build are what you see in your phone settings about your phone. The ROM can be modified by modifying the Build.prop file to make it its own imprint (modified by XXX). I've seen a few programs that just deleted System/app, and then modified the ro.build.display.id in Build.prop and the two attribute values in ro.build.version.incremental to play their own name on the ROM.

SYSTEM/ETC: The directory contains some configuration files, unlike the property profile, which may be slightly less regular in the configuration file below. In general, some scripts, as well as familiar GPS profiles (gps.conf) and APN configuration files (apns-conf.xml), are placed in this directory. Some of the files that HTC uses for camera effects are also placed in this directory.

4. Zygote (app_process)
The previous section mentions that Init will execute an important command procedure called App_process, which is commonly referred to as zygote. (Zygote is the egg meaning that all Android processes are produced by it). Zygote first loads the Dalvik virtual machine and then produces a process called system_server. System_server, as the name implies, is called the Android system service program, which mainly manages the entire Android system. System_server started to look for a program called the launcher after the start, find and then started by zygote start execution launcher, this is the desktop program we often see.

Described above is a fairly simplified start-up process, to understand that these are basically enough for adaptation MIUI, if you want to know more about these, please follow the various Android insider books on the market.

5. Data and Cache partitions
This section briefly describes the data and cache partitions. When we boot into the desktop program, generally we will download and install some apps, these apps are installed in the Data/app directory. The data generated by all Android programs is basically stored in the Data/data directory. Wipe data is essentially a formatted data partition so that all of the app and program data we install is lost.

The cache partition is used to cache files from the name, such as some temporary files for music downloads, or download management downloads that are basically on this partition.

6. Summary
This chapter mainly introduces the hard software structure of Android phone and the content of main partition, and briefly introduces some boot-up process. Understanding these content helps us understand ROM porting as a whole.

============ Solution 1============


It's really a good thing.

(turn) know Android phone-from MIUI

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.