You are on page 1of 12

The MIUI MIUI MIUI MIUI ROM, ROM, ROM, ROM, custom tutorial

MIUI ROM customization tutorial .................................... .................................................. ................................. a preamble ............... .................................................. .................................................. ................................ 2 to build the development environment ............ .................................................. .................................................. ..... 31 operating system ........................................ .................................................. .................................... 32 Installing the Android SDK ........ .................................................. .................................................. .. 3 2.1 Installing the JDK ............................................ .................................................. ...................... 3 2.2 download the Android SDK package ...................... .................................................. ........................ 3 2.3 installation ....................... .................................................. .................................................. .4 2.4 adb .............................................. .................................................. .............................. 4 3. patchrom project .......... .................................................. .................................................. Android phone .... 5 Chapter II recognized ....................................... .................................................. ..................... 6 1. the bootloader .................... .................................................. .................................................. .6 2. start ............................................ .................................................. ................................ 7 3. System partition ............. .................................................. .................................................. ......... 8 4. Zygote (app_process) .................................. .................................................. ....................... 10 5. data and cache partitions ................. .................................................. ........................................ 106 Summary ... .................................................. .................................................. .......................... 10 Chapter III to find the original ROM ............... .................................................. .................................... 111 familiar with transplant models ... .................................................. .................................................. ...... 11 1.1 browsing forums Brush ...................................... .................................................. ...................... 11 1.2 appropriate original ROM, ..................... .................................................. ......................... 11 1.3 the adb logcat ................. .................................................. .................................................. ..... 122 modified with boot.img on ................................... .................................................. ............................ 12 3. deodex .................. .................................................. .................................................. ........... 14 Chapter decompile ................................. .................................................. ............................................ 141 decompilation. .................................................. .................................................. ........................... 15 2. AndroidManifest.xml ................. .................................................. ....................................... 153. ... .................................................. .................................................. ......................... 16 4. smali ..................... .................................................. .................................................. ........... 18 Chapter transplantation MIUI Framework, ................................ .................................................. .................... 201. Why use code Instrumentation ...................... .................................................. ................................ 202 transplant specification ............. .................................................. .................................................. ........... 20 2.1 android .................................... .................................................. ................................. 20 2.2 miui .............. .................................................. .................................................. .......... 21 2.3 i9100 ..................................... .................................................. ................................... 21 3. transplant resources .......... .................................................. .................................................. .............. 224. modify the smali ............................... .................................................. ......................................... 22 4.1 Comparison of difference ..... .................................................. .................................................. ......... 22 4.2 direct replacement ..................................... .................................................. ........................... 23 4.3 linear code .................. .................................................. .............................................. 23

4.4 conditions to determine .................................................. .................................................. .............. 23 4.5 logical reasoning ........................... .................................................. ................................ 255 is recommended .......... .................................................. .................................................. .................. 26 Chapter VI transplant MIUI APP ......................... .................................................. ...................................... 27 1. MIUI APP at a glance ...... .................................................. .................................................. ........ 272 one regret: call program ................................. .................................................. ................. 273. regrets the problems caused by ......................... .................................................. ............................. 284 system notifications bar ............... .................................................. .................................................. ..... 285. other procedures ........................................ .................................................. .................................. 29 Chapter VII of the production of Brush package ........ .................................................. .................................................. ........... 291 Brush packet structure ............................... .................................................. ...................................... 29 2. updatersrcript cases solution .... .................................................. .................................................. .... 303. produced Brush package ....................................... .................................................. ............................... 35

preamble
in order to help the majority of the MIUI enthusiasts will MIUI ROM ported to their favorite models on the the MIUI development group create and open source projects patchrom also released this matching tutorial. This tutorial focuses on is customize their own MIUI ROM (original ROM refers to the official ROM is released by the mobile phone health companies, with the best stability) on the basis of the original ROM, that is what we project the name of the origin of (modify the existing ROM, similar to the software to play the patch, so called patchrom). While this tutorial focuses on how to customize the MIUI ROM, but which relates to the technologies and concepts are generic, applicable to any ROM customization. To fully grasp this tutorial, you need to have experience in the use of the Linux operating system, to understand the Java language, there are some Android programming experience is the best. If you want to modify resources (such as Chinese, etc.), basically do not need any programming knowledge. This tutorial is divided into six chapters: Chapter 1: Building the development environment, and briefly describes how to prepare the necessary development environment. Chapter II: Understanding the Android phone, the structure of the Android mobile phone system from the point of view of the ROM developers. Chapter 3: find the original ROM, patchrom project is modified based on the original ROM, this chapter will introduce some criteria to judge what is appropriate ROM. Chapter IV: basic knowledge of to decompile, introduced apktool tools and decompilation. Chapter V: Transplantation the MIUI Framework, and tell how to port the the MIUI framework layer code. Chapter VI: transplantation MIUI App, tells how to transplant the MIUI the application program. Chapter VII: production of ZIP brush package about how to make a ZIP Brush package. patchrom project website: https://github.com/MiCode/PatchRom you can visit the site to download all the code to patchrom, including this tutorial.

The first chapter set up the development


environment,"we must first sharpen his tools. Prior to the start customizing MIUI ROM, we need to build the necessary development environment. The main thrust of this tutorial is how to modify the original ROM. We are dealing with changes in theory does not require source code, source developers interested can refer to http://source.android.com. ROM developer, we recommend that you download a google android source code released, this is not required, but for the great help to understand some of the errors in the investigation and ROM adapter.

1.1.1.1 operating system operating system operating system operating system


customization MIUI ROM technology involved in itself no special requirements for the operating system, Windows, Linux and Mac systems can be. But patchrom project is the development of Linuxbased, precisely, is developed based on Ubuntu, we recommend the above Ubuntu10 version.

2.2.2.2. Install install install install the Android SDK, the Android the Android Android SDK the SDK the SDK
This section briefly describes how to install the Android SDK on Ubuntu systems. Windows and Mac users, please reference http://developer.android.com/sdk/installing.html

2.1 2.1 2.1 2.1 Install the JDK JDK the JDK JDK
first need to install the Java Development Kit and unified convention in this article $ represents the command prompt in the Terminal subsequent text input command. $ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner" $ sudo apt-get update $ sudo apt-get install sun-java6-jdk

, Ndroid ndroid ndroid,2.2 2.2 2.2 2.2 Download the Android SDK SDKSDK SDK package
Download the Android SDK package http://dl.google.com/android/android-sdk_r16-linux.tgzfrom the following address, extract it to your home directory, assume that after extracting the directory / home / the patcher / the android-sdk-linux. Next, edit the home directory. Bashrc file, modify the PATH environment variable: export PATH = ~ / android-sdk-linux/platform-tools: ~ / android-sdk-linux/tools: $ PATH. Run the command .. bashrc to make the changes to take effect on the PATH environment variable. $ ~ /. The bashrc

2.3 2.3 2.3 2.3 install and


run the command android to start the Android SDK Manager the android start the results as shown below: select the Android SDK Tools and the Android SDK Platform-tools, and then click Install, then follow the application instructions for installation. After this step, we need the Android SDK installed. Note: http://developer.android.com/sdk/installing.html pages, we will see the need to install Eclipse, custom MIUI ROM do not need to install Eclipse, this is needed to develop Android applications, but is strongly recommended that you Android application development foundation.

The the 2.2.2.2.4 adb adb adb adb


Android SDK, our most important tool is the adb (the android debug bridge,). Transplantation MIUI ROM, the most commonly used command is the adb logcat, this command will print out the detailed debugging information to help us locate errors. In order to verify the adb whether work, but also verify that the above steps, open the phone system settings, select the application - development, make sure that "USB debugging", then use the USB cable to connect your phone to run the Ubuntu the Shell command the adb devices, and similar to the following information, I congratulate you, adb can identify your mobile phone. List of devices attached 304D1955996BE28E device Note: (1) Under Windows, you must install the phone drivers in order to successfully identify the phone.
Pa has ka Once the eS Too of the SDK has th P = nr mouth '5DKMana-chang 0mE_Jfwan and WEnjunilfand [oid an S [generation k a giant summer nU)

(strange
Pa [ka once to BS l Youth l NamE v The District! Mouth Too sexual _ I back: l: Android SDKTno fear of the three I weeks Android SDK Platfo "m-tooI rich" mouth of Solid And "[) id 4.D.3 the bighead Lu L Ran the 5} port l Youth l touch the twisted Emperor Yan plant death described series of "mouthconvex treasure described using waist refused three cargo series of" three to avoid the extension magpie mouth quick fix dead um that is, plusGan mouth door beam port piece door had "mouth-resistant interface. Rui piece depiction session inmouth l Youth l describe ankle M The drama summer described Xia Wei weighing Department with lag more door packagemanagement directors weightmouth Wang expansion death of a white cargo port on the door over flaring Laos three K.JIAO P | RE apple. Statu5 is really regrettable that jI Kawaguchi death heavier plus he had the

case accounted for, the IN Mo] queue summer doors weighing up to management bundle refused to describe is really regrettable the jI Kawaguchi death heavier twist him over the case of accounts, IN Mo] queue summer door weighing resigned beam shot description is really regrettable that the the jI Kawaguchi perish increase plus he had the Show: Tian UpdatES. llrNEw the Tian lnSta "Ed mouth [) (t NeW re the UI the work dateSbSoletE Sele Sort by,= back to ammonia P | le!lfel

RepoSito" y
D chu S [the guitar e Officials _t focus " - the UI the date ! lfaiIabI chu = re dirty '! T4' Maximum P the Updat Pakistan allllailabIE = "ETllI. T6,

[Don
bar , Dadin eup pa weight once ES_

ka}-

(2) In Ubuntu, you may be prompted to" no such permissions ", this time there are two ways, first is run as root the adb second approach: a) run lsusb command for my Samsung phone, the output is as follows: Bus, 002 Device 001: ID 1d6b: 0002 Linux Foundation 2.0 root hub Bus 001 Device 098: ID 04e8: 685e Samsung Electronics Co., Ltd... to find the corresponding phone line to record 04e8: 685e, this respectively the vendorId of the equipment and the productId. If you are unsure phone corresponds to which line can be connected to the phone before and after running lsusb, find the difference between the line b) in the / etc / udev / rules.d directory, create a new file 99-android.rules be edited as follows: SUBSYSTEMS == " usb ", ATTRS {idVendor} =" 04e8 ", ATTRS {idProduct} =" 685e ", MODE =" 0666 ", the OWNER =" logged-on user name "c) to restart the usb service, the sudo restart udev heavy phone.

3.3.3.3. patchrom patchrom patchrom patchrom project project project project


below theintroduction patchrom the directory structure as well as each directory of the role. the android: this directory there are two subdirectories: system and the src. which the src directory and will be introduced miui / src directory is a on a relationship. the android / src google android source code released miui / src miui in google code based on changes made in order to save space in these two directories, we only put the file miui modified to download the full android source code, please refer to the directory http://source.android.com/source/downloading.html. system storage is released by google android source code compiled with the three jar files: framework.jar, Android . policy.jar and services.jar the role of these jar files in the following chapters will elaborate. build: This directory is compiled script. tools: This directory contains some utilities and scripts in Custom ROM need to use these procedures and the compilation process. miui: This directory has two subdirectories: system and src stored in the system directory is part of the file in the by miui source code is compiled, these files are our custom MIUI ROM required to use all the files to the later chapters will elaborate i9100: create a separate directory for each custom models. This directory contains some of the changes and file and Samsung i9100. later chapters will i9100 for example described in detail. Next we compiled i9100 custom MIUI ROM in, assuming current directory is / home / the patcher / patchrom directory, $. the build / envsetup.sh The zipfile more than $ cd i9100 $ the make command has finished running, i9100 catalog will generate a. the build subdirectory, the subdirectory MIUI_9100.zip file that we released the i9100 Brush package.

Chapter II recognizes the Android ndroid ndroid ndroid phone


writing this article, I think of my first Android phone HTC Hero. buy it back, my colleagues told me that brush machine can go play. Brush, how brush? colleagues said, you natives, Brush did not know, Brush Forum, you go shopping. very simple. around town visiting the machine Feng forum (did not know MIUI), open the look, what recovery, radio, root blowing variety of vocabulary, oh my lady gaga is so complex, but in order not to contempt, but idle is idle, or brush with play later on to get to know MIUI came to the millet in the chaos of the Android world, how to find a piece of Brush Avenue, perhaps it's just a legend, we just have been exploring. Let's take a look from scratch and see if I can find something.

1.1.1.1 bootloader the bootloader the bootloader the bootloader


when we get a cell phone, the first thing is to press the power button to boot, then the boot into the desktop program, the middle of what was happening then, we are below this simplifies the mobile phone chart: Note: The chart does not reflect the actual order of the partitions and location of the mobile phone, just a logical structure.can simply store the phone's ROM analog computer hard disk, hard disk is divided into several partitions: the bootloader partition, boot partition, system partition, etc. We will gradually introduce the use of each partition. the so-called brush We can simply be understood as the software is installed in a certain partition of the phone, like weon the computer

saidm mouth d m sub-rescue


officials b mouth I mouth der responsibility l YingI the Wataru

tb mouth partition
[White} mouth Hui ll re "y-sub | re-the

SyStem partition

da fear of partition
c che partition

install Windows system. When you press the power button electric start on the phone, the first from the bootloader partition a fixed address begins executing instructions, bootloader partition into two parts, respectively called the bootloader of the primary and secondary the stage the bootloader, the bootloader of the Primary hardware detection, to ensure that the hardware will work properly after the secondary the stage bootloader to copy to memory (RAM) started. Secondary the stage the bootloader will be the beginning of some hardware the beginning of the work, to obtain information on the memory size, etc., based on the user's key to enter into some kind of startup mode for example, known to everyone through the power button and some other key combination, you can enter into recovery, to fastboot or select the startup boot mode interface we see the bootloader on the forum is usually refers to the secondary the stage the bootloader. but we do not need to worry about too many details can be simply understood as the bootloader is a start code, selected according to user keys into some kind of start mode to fastboot mode: to fastboot Android definition of a simple brush agreement fastboot commandline tool, users can brush machine for example, to fastboot flash boot as boot.img, this command is the brush writes the contents of boot.img boot partition. the mobile phone manufacturers in general do not directly provide the fastboot mode brush, but in order to show their place of cow B, will always provide the Brush tool and brush their own proprietary methods. For example, Samsung's Odin, motorcycle the RSD of Huawei powder screen, etc. but its essence is actually the same, is the software flash directly to each partition recovery mode: When entering the recovery mode, secondary stage the bootloader from the recovery partition to start the recovery partition is an independent Linux systems, when the recovery partition on the Linux kernel starts after the start the first program the init (init program is a Linux system, the ancestors of all programs). init starts a program called recovery (recovery mode name hence). recovery program, the user can clear the data, install the brush package, and other operations. general mobile phone manufacturers to provide a simple recovery procedure, and the famous CWM Recovery is an added many enhancements to the recovery procedures, in order to spend the CWM the Recovery premise that the recovery partition can be brush write. we see in the forum to unlock the bootloader, usually refers to unlock recovery or fastboot, allows the brush to write the recovery partition, so we can spend favorite CWM the Recovery of the phone in addition to the normal outside the CPU chip, as well as MODEM processor chips. the functionality of the chip is to realize the communication functions of mobile phone necessary, we usually brush RADIO is to reflash the modem partition

2.2.2.2. normal start the normal start normal start to start properly
when we just press the power button to turn into the normal startup mode. the Secondary the stage the bootloader is started from the boot partition Boot partition format is fixed, the first is a head, then Linux kernel, and finally the ramdisk as root file system. Linux kernel start after you started the init program in the root filesystem, the init program reads the startup script file (init.rc, and init.xxxx.rc). startup script file format, we can find a lot of reference material on the Internet, do not write here, and we transplanted-MIUI the principle on the original ROM does not modify the boot partition, because there are some models can not modify the boot partition root file system there is an important configuration file the called default.prop, the contents of the document in general: #

#ADDITIONAL_DEFAULT_PROPERTIES # ro.secure = 1 ro.allow.mock.location = 1 ro.debuggable = 0 persist.service.adb.enable =a assignment of each line infile on a property, in a subsequent article we will discuss the properties which we need to pay attention to two property: ro.secure, and ro.debuggable. if ro.secure = 0 is allowed We run the adb root command. usually all right to the core ROOT refers to the ro.secure = 0. general said ROOT permission is a license management program (Superuser.apk) grant program root on the phone user's permissions. the init program reads the startup script, execute the script specified in the action and command, part of the script is to run the system partition of the program, the next section we take a look at the structure of the system partition.

3.3.3.3 System System System the System partition partition partition partition
speak before the system partition, let's look at the following this Android software system architecture diagram from top to bottom as: core application layer: This layer is usually in contact with every system comes with applications such as contacts, phone, music and other application layer down to contact the developer. framework layer: This layer is the core of the Android system, which provides the operational mechanism of the entire Android system like the window manager, the application installation package management developers by contact with the Activity, the Service, broadcast and so on. JNI to layer: of JNI layer is a Java program and the underlying operating system, communication of a mechanism, it makes the Java code can call in C / C + + code to access the underlying operating system APIs. Dalvik virtual machine: Android development using the Java language, Java application code will be compiled into dalvik virtual machine bytecode, bytecode explained by dalvik virtual machine execution.

beam Xia Yang has, redemption beam Lane mesh layer


port force

JNI layer daIVik virtual bundle several

village? ~ Guests also library two


H mane convex tail L,

J Yu family fitness unitary own layer

Linux wooden Hai

native libraries: local library in C / C + + language by development, directly translated into the corresponding CPU machine code, which contains the standard C library, of skia library to draw graphics, the browser core engine webkit HAL: Hardware Abstraction Layer, in order and each different hardware manufacturers, Android defines a set of hardware interfaces, for example, in order to use the camera, the camera drive manufacturers must provide an interface method. This allows the top of the code can be independent of the hardware to run. manufacturers adaptation layer: originally the Android defined HAL layer is directly and device drivers provided by the manufacturer to deal with, but manufacturers do not want to open source HAL part of the code, so many manufacturers offer what I call a factory adaptation layer code, so that the HAL layer interface is a simple factory adaptation layer interface function calls. kernel: This layer is known of the Linux kernel, the kernel contains a variety of hardware drivers, these drivers different mobile phone manufacturers cell phone is not the same as the Linux kernel is to support the drive modular mechanism, simple is to allow users to dynamically load or uninstall a hardware drivers, but for now, mobile phone manufacturers in addition to the WIFI driver to load a separate, additional drivers are kernel bind together. from this software chart, in addition to the kernel on the boot partition, the other code in the system partition. the following combination of this map to introduce the system partition of the directory contents: system / app: app directory stored under the core application, which is well-known system of APP, these systems comes with the program can not uninstall, through some special way to remove (a familiar approach is to use the RE File Manager) system / lib: lib directory stored in the composition of the JNI layer, the Dalvik virtual machine, the local library, HAL layer, and manufacturers adaptation layer all dynamic link library (. so files). system / framework: the directory storage JAR package is the framework layer, which the MIUI transplantation for the 3 most important the JAR package (framework.jar, android.policy.jar and, services.jar). follow-up article focuses on the three packages. system / fonts: the directory stored in the system default font file. system / media: is the system used by a variety of media files stored in the directory, such as boot music, animation, wallpaper file. the organization of the phone directory may not be the same. how to modify these files, please refer to the line corresponds to model all kinds of tutorials, here no longer dwell on. system / bin: This directory is stored in a number of executable files, basically the in C / C + + written in an important command called app_process the next section, a separate presentation. system / xbin: This directory is stored in the extension of the executable file, only the directory is empty. we used the busybox in the directory. the Busybox established by a variety of symbolic link command on the directory. system / build.prop: build.prop and put it in the root file system of the previous section default.prop file formats are property known as the configuration file. they have defined a number of property values, the code can be read or modify the values of these properties. property values naming: ro at the beginning of said read-only attribute, the value of the property code can not be modified. persist at the beginning of these attribute values stored in a file, so after restarting These values are also retained. other properties generally at the beginning of the category, these attributes are readable and writable, but restart their modifications

afterwill retain a lot of ROM producers will modify build.prop information inside the property to ro.build beginning is to see you on the cell phone in the phone settings. modify build.prop file this ROM marked with his mark (XXX modified) I have seen one just deleted some of the procedures of the system / app, and then modify build.prop in ro.build.display.id, and ro.build.version.incremental the two property values marked with the ROM name. system / etc: This directory contains configuration files and attribute configuration file, the following configuration file may be a little less regular, generally speaking, some of the script, but also everyone is familiar with the GPS configuration file (gps.conf) and APN configuration file (apns-conf.xml) in this directory. like the HTC camera effects used in some files in this directory.

4.4.4.4. Zygote is(app_process) Zygote (app_process) Zygote (app_process) Zygote (app_process)


referred to inan init will execute a command procedure called app_process, generally called the Zygote is. (Zygote is the meaning of the egg, all of the Android process born) Zygote is the first to load dalvik virtual machine, and then generate a process called system_server. system_server As the name suggests is called the Android system service routine, it is mainly to manage the entire android system startup is complete, the system_server start looking for a launcher called the program, found by the zygote starts to perform the initiator, which is our common desktop applications described above is a very simplified startup process, to understand these adaptation MIUI basically enough, if we of these would like further information then please pay attention to the market a variety of Android insider books.

5.5.5.5 is the data the data the data the data and the cache the cache the cache cache partition partition partition partition
of this section a brief look at data and cache partitions. When we boot into the desktop program, in general, we will download and install some of APP, APP are installed in the data / app directory. data generated by all the Android apps are basically stored in the data / data directory. essentially wipe one the data format partition of the data, so we installed all of the APP and program data is lost. the cache partition name is used to cache some files, such as music downloads temporary files, or download download basically on the partition.

6.6.6.6 Summary Summary Summary Summary This


chapter introduced the Android mobile phone hardware and software structure and contents of the partition, and briefly describes some of the boot process. understanding of the content will help us to understand the overall ROM transplantation.