Modifying a ROM can generally be divided into three categories: trimming, adding, and beautifying. Here, we will mainly discuss trimming and adding. As for beautifying, you can refer to other posts.
1. First, let's take a look at what exactly is in the ROM: By opening the flashing package with WinRAR, you can see several directories. The following lists the directories related to us and their explanations:
- dev_data/apps/: Directory for system program APK files, equivalent to "/data/app_s/" after flashing. Programs in this directory cannot be uninstalled after flashing.
- dev_data/app/: Directory for user program APK files, equivalent to "/data/app/" after flashing. Programs in this directory can be uninstalled after flashing. (This directory exists only in versions after October 28; for previous versions, you can add this directory yourself.)
- META-INF/com/google/android/: Flashing script files
- system/etc/: Stores some configuration files
- system/etc/permissions/: Related to software permissions; some patches require adding files to this directory
- system/lib/: Location where system program library files are stored
2. Next, let's get familiar with the flashing script files: When flashing using recovery, the flashing process is controlled by script files.
The script file is the update-script located in the META-INF/com/google/android directory in the compressed package. It can be opened with a text editor.
There are a few statements in the script file that we care about:
(1) show_progress 0.1 0 : Display progress bar
This is used to display the flashing progress bar. The first number 0.1 indicates the position of the progress bar and can be changed to another value (less than 1). The meaning of the second number is unclear. Generally, except for the last line which is 10, the others are 0. In some ROMs, the progress bar only reaches a little over halfway when flashing completes. You can try changing the last line to show_progress 0.8 10, and the progress bar will then reach the end.(2) Several Keywords (A) "SYSTEM:" represents the system directory after flashing = "/system/" (B) "INTERNAL:" represents the /data directory after flashing = "/data/" (C) "PACKAGE:" represents the root directory of the compressed package. For example, "SYSTEM:etc/" corresponds to the "/system/etc/" directory after flashing, and "PACKAGE:dev_data" corresponds to the dev_data directory in the compressed package. (3) copy_dir PACKAGE:dev_data INTERNAL: copy_dir is used to copy directories. The first parameter is the directory to copy, and the second parameter is the destination. For example, copy_dir PACKAGE:dev_data INTERNAL: is used to copy the contents of the dev_data directory in the ROM package to the "/data/" directory after flashing. (4) set_perm_recursive 0 2000 0755 0755 SYSTEM:bin Sets the permissions of directories or files. The usage method is similar to setting permissions in Linux. (5) delete SYSTEM:app/YouTube.apk Deletes files. This is generally not needed; if you want to delete something, just delete it directly. Okay, now you can start streamlining and adding programs. II. Streamlining System Programs Streamlining essentially means deleting system programs. We can delete the programs we do not need. The benefits of deleting these programs are: (1) Some things are not used by us and showing them in the app list is annoying. If there are too many such programs, it can also slow down opening the app list. (2) Some programs will occupy memory after starting, which we do not use, for example, SMS interception, etc. (3) Some programs that we do not want to use from the original ROM and want to replace with others. For example, if you do not like ADW, you can switch to LAUNCH PRO, etc. The method for streamlining is simple: open the ROM with WinRAR, go to dev_data apps, find the programs you do not need, and delete them. Which programs can be streamlined: This question has been discussed in many posts; you can search online. For example, the following posts. III. Adding Programs There are two methods to add programs: one is to add the program as a system program, and the other is to add it as a user program. The advantage of adding a program as a system program is that the execution speed is fast (this is what people say, though I do not seem to notice it), and the disadvantage is that it cannot be directly uninstalled, only deleted through tools like RE.In fact, directly deleting system program APK files with RE does not completely uninstall them. If you don't believe it, you can take a look at the /data/data/ directory. Each program corresponds to a target, and its directory name is the same as the package name of the program (not the XXX in XXX.APK).
1. Adding System Programs: The simplest method to add system programs is:
(1) Open the ROM compressed file with WinRAR, go to the "dev_data/app_s" directory, and copy the APK files of the programs you want to add into it.
(2) Open the APK files with WinRAR and check the "lib/armeabi" directory for files ending in .so. These are the library files required for the program to run. If they exist, copy them into the "system/lib/" directory of the compressed file. Many users encounter the problem that the programs they added cannot run after modifying the ROM, which is mostly due to this issue. For example, the new version of Google Pinyin Input Method.
2. Adding User Programs: Adding user programs is a bit more complicated, but they can be uninstalled directly after flashing. If you are using a ROM dated after October 28, simply drag the APK into the "dev_data/app/" directory. This step is very simple; the tricky part is when the APK contains library files. The simple solution is the same as step 2 for adding system programs. The downside of this method is that library files will remain in "system/lib/" after uninstallation. Fortunately, most programs do not have library files, and for the few that do, leaving the library files behind does not cause much harm. A more advanced approach is to install them through a script.
For ROMs before October 28, there is no app directory in "dev_data/". You can create it yourself (right-click in WinRAR and select Create a New Folder). After creating the directory, you need to set the directory properties in the flashing script: In the flashing script, locate this section:
copy_dir PACKAGE:dev_data INTERNAL:
set_perm 1000 1000 0771 INTERNAL:app_s
Then add this line after it:
set_perm 1000 1000 0771 INTERNAL:app
The first line copies everything in the dev_data directory of the ROM to the /data directory. The second line sets the permissions for app_s. The line we added sets the permissions for the app directory.
Next, you can patch and adjust the ROM accordingly.The firstboot script can be used to perform more advanced settings on the ROM. You can use the firstboot.sh script, which is located in the dev_data directory of the ROM. The code in the script is executed the first time the device boots after flashing, and it can be used to configure the system, install APKs, and other tasks.
Here's a snippet from the liudidi1028rom script:
# System default settings
/system/xbin/sqlite3 "INSERT INTO system (name, value) VALUES ('trackball_wake_screen', 1);"
/system/xbin/sqlite3 "INSERT INTO system (name, value) VALUES ('trackball_unlock_screen', 1);"
/system/xbin/sqlite3 "INSERT INTO system (name, value) VALUES ('lock_home_in_memory', 1);"
I think everyone can guess what these three lines of code do. As for why the script is written this way, don't ask me—I'm not very familiar with it, but everyone can study it together.
In the script, you can use commands like rm and mv, which allow you to directly overwrite certain configuration files.
For example:
busybox rm /system/etc/somefile
busybox mv /system/etc/somefile
Of course, if you are modifying system files, you first need to gain permissions:
busybox mount -o remount,rw /system
And then change it back to read-only:
busybox mount -o remount,ro /system
firstboot.sh is very useful. It would be great if someone could write a beginner's tutorial for it!