[Android Software/Hacking General [Developers Only]] whitegaia:
Yes, rom cooking with any kitchen is easy enough for anyone to start with but I think it's better to have a clear tutorial for the newbie like me. As I've tried searching for sometimes, I came up with this post. It may not be a perfect guide but at least, it's better than start from nothing.

This guide is made in Thailand, that's why I add the Thai keyboard.

Sorry, if I made any mistakes, and please tell me to fix.

Thanks: pj from droidsans, eRobot from pdamobiz (these two guys are Thai dev who help me so much)

For dsixda, your kitchen is amazing, love it so much.

For what?

GoLauncherEX -> default(ADWLauncher)

There are many reasons why I would say GoLauncherEX is better than ADWLauncher; having task manager and uninstaller within itself prevent us from wating any more space on the applications. GoLauncherEX also provide a lot of FREE widgets, while some other launchers may ask you yo pay extra, and the best characteristic of all is "this-thing-flows-fluently" you may not believe how small of RAM it is consuming.

MIUI music player -> default(Music)

MIUI (Me-U-I) is one of the most popular chinese ROM as you can see from Andriod phone recently, what imprest me the most in MIUI is the music player, it allows you to shuffle the music my just shaking a phone (as you have seen in many apple products) and provide playlist function which I found very convienient.

Gallery2D -> default(Gallery3D)

To be honest with you, the Gallery3D is not going to be use in this article. Due to the beautiful effects from this program (which has not done any good but being beautiful) which consume a lot of resources and took you for-ever to load the pictures, this issue brings me down to Gallery2D, with the same abilities except for the affected effects.

DroidSansThaiKeyboard -> default

Another sweetener in the recipe from Thai Andriod developer. Custom rom usually does not provide Thai keyboard indeed, and since I am cooking my own rom right now, I decided to drop it in!

CPU 19,710 smartassV2 -> default(264, 518)

Kernel that I use is called "flykernel-13" many versions has been released and this guy has never disappoint me. We are going to overclock at the speed of 19-710 MHz., I use smartassV2 as a CPU governor. The reason why I choose smartassV2 instead of ondemand is because; smartassV2 is not running at the maximum speed or minimum speed all the time, it has the ideal frequencies that store two CPU value, it is set for 518 and 352 for scree on and off sequentially.

Minimum free memory optimization

Theoritically, Andriod is going to clear and retrieve the memory automatically, but this operation is too slow sometime. What we can do is, change the minimum and maximim limits of the CPU before Andriod will recall to use ram. Unfortunately, HTC hero has such a tiny memory capacity comparing to recent Andriod phones, therefore, the background application should be terminate inorder to save memory for the currently using application.

Let’s get is started, shall we?

Prepare ingredients

Base rom: Mine is Elelinux-7.1.0-RC1-Hero-v3.5-Light

Android SDK: Just in case we have to use the ADB

dsixda Android kitchen:

Other packages such as .apk application and kernel (in case you want to change it))

Set up the kitchen

First of all, you can download dsixda kitchen from here:

http://xdaforums.com/showthread.php?t=633246v

Although the owner of dsixda has stopped developing this guy a while ago, dsixda is still very popular among the developers. So far I haven’t seen any kitchen work as easy as this one.

Steps of installation here, works well on windows, linux and mac:

http://xdaforums.com/showpost.php?p=5626300&postcount=3

Find your base rom

Before cooking, we need to prepare the ingredients, and the most important thing in this process is base rom. I suggest that you should find some base rom to work with, but if not, this kitchen is able to work with official rom and nandriod backup. The instruction of importing rom into the kitchen should be at the bottom of the forum. (http://xdaforums.com/showpost.php?p=5626300&postcount=3)

Extract the base rom

After you have import the base rom into the kitchen, unzip the file and follow these steps:

open the terminal, go to directory of kitchen image we have created previously by using command:

cd /Volumes/kitchen

then type:

./menu

to activate the kitchen, the sceen will be as shown below.

insert 1 and press Enter, kitchen will ask about setuo WORKING folder, follow the provided instructions and default. At the end, we are going to have a folder named WORKING_*****_***** which contain our rom inside, every configurations will be done in here.

Add more applications

We have two choices for adding applications in rom; one is to add it before the installation (which means it will become part of the system application, note that you won’t be able to uninstall the application unless you use titanium backup to take out the root access and uninstall from that), second is to install it as a user application (which is able to uninstall later on).

System applications

In WORKING_xxx, go to folder system > app you will see many .apk files, these are base applications in your phone; Settings.apk, Calendar.apk, etc.

Erase .apk files that you don’t want it to be in rom (caution: you many erase some important base applpications, so pick out the one you really know, and leave out all the rest.)

Copy .apk from other sources in here, if I was going to add GoLauncherEX, I’m going to browse for WORKING_xxx > system > app and erase a file name Launcher2.apk (this is the default launcher that comes with my base rom) then insert GoLaunherEX.apk into this folder (haven’t got the GoLauncherEX file? Google it!)

User applications

Open kitchen at the main menu.

type 0 to get to the Advanced options

type 13 to Enable /data/app

Follow the instructions of System applications except for the path, change it to:

WORKING_xxx > data > app

Minfree memory scripting

There are many applications in Andriod market that is able to work with this part, but since we are going to build your own rom, it make more sense to manage it before we flash the rom, it may be complicate, but I guarantee this is worth to do.

Kitchen has a function to do this for us, but it’s kind of mess up for me, somehow after you restart the phone, every setup is running back to default, so I decided to write them a script to make it actually work even after we restart the machine.

We are going to add the script in the system/etc/init.d/02memcputweak, if you couldn’t find a file name 02memcputeak, then create one of your own.

We are going to use the script from Juwe11 from XDA to be a default of minfree memory (http://xdaforums.com/showthread.php?t=1111145) according to the link, you will see a script like this:

#!/system/bin/sh
# Copyright© 2011 Juwe11
# 13.8.2011 Updated VM values - Thanks to [Kalis] for help
# 18.8.2011 Added oom_adj values
# 19.9.2011 Updated VM and LMK values

if [ -e /sys/module/lowmemorykiller/parameters/adj ]; then
echo "0,1,2,4,6,15" > /sys/module/lowmemorykiller/parameters/adj
fi

if [ -e /sys/module/lowmemorykiller/parameters/minfree ]; then
echo "2560,4096,5632,10240,11776,14848" > /sys/module/lowmemorykiller/parameters/minfree
fi

if [ -e /proc/sys/vm/swappiness ]; then
echo "20" > /proc/sys/vm/swappiness
fi

if [ -e /proc/sys/vm/vfs_cache_pressure ]; then
echo "70" > /proc/sys/vm/vfs_cache_pressure
fi

if [ -e /proc/sys/vm/dirty_expire_centisecs ]; then
echo "3000" > /proc/sys/vm/dirty_expire_centisecs
fi

if [ -e /proc/sys/vm/dirty_writeback_centisecs ]; then
echo "500" > /proc/sys/vm/dirty_writeback_centisecs
fi

if [ -e /proc/sys/vm/dirty_ratio ]; then
echo "15" > /proc/sys/vm/dirty_ratio
fi

if [ -e /proc/sys/vm/dirty_background_ratio ]; then
echo "3" > /proc/sys/vm/dirty_background_ratio
fi

Let’s take a look at this part.

if [ -e /sys/module/lowmemorykiller/parameters/minfree ]; then
echo "2560,4096,5632,10240,11776,14848" > /sys/module/lowmemorykiller/parameters/minfree
fi

There are 6 sets of number, each one response to different part of work, which are

position 1 : 2560 -> foreground app ; applications that is now currently using.

position 2 : 4096 -> visible app ; applications that is not currently using, but haven’t finish the execution

position 3 : 5632 -> Secondary server ; service of the Operation Systems that applications needed to use.

position 4 : 10240 -> hidden app ; service that applications may needed to use, but not right now

position 5 : 11776 -> content provider ; connections between applications and the content

position 6 : 14848 -> empty app ; applications that are purposely left out in ram, in case you are going to use it again.

*FYI: number you above are the amount of page, if you want it in MB, multiply by 4 and divvided by 1024 (or X*4/1024) i.e. foreground app is 2560; 2560*4/1024 = 10 MB means that, if the free ram in total is less than 10MB, the foreground application will be terminated.

Next problem is, how are we going to manage

if [ -e /sys/module/lowmemorykiller/parameters/minfree ]; then
echo "1536,4096,4096,25000,25000,25000" > /sys/module/lowmemorykiller/parameters/minfree
fi

position 1 : 1536 -> foreground app ; applications which are being used right now, pour out some more ram please.

position 2 : 4096 -> visible app ; applications that haven’t stop working, so leave them alone.

position 3 : 4096 -> Secondary server ; service that still in use and should not be terminate.	ชุดที่ 4 : 25000 -> hidden app ; service that applications may or may not use, we are not going to keep this one for too long.

position 5 : 25000 -> content provider ; we haven’t use much content from other applications.

position 6 : 25000 -> empty app ; applications that may be left out, just in case we are going to use it, which we occasionally do.

OC memory scripting

We are still going to mess with file 02memcputweak. After we have prepared the memory part, we are further going to manipulate the speed and the governor of CPU. The scripts within this part are easy scripts that will go to configuration file of the kernel during the OS boosting.

#!/system/bin/sh
#
echo 19200 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo 710400 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
echo smartassV2 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
chmod 0755 /system/etc/init.d/*

Set the value of 19200 in /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq to be a minimum frequency, as well as the value of 710400 in /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq to be the maximum frequency.

After we adjust the speed of CPU, we are going to adjust the govenor as well. For the best performance, I pick smartassV2 and put it in:

/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

Then set the permission of files in init.d by using a command:

chmod 0755 /system/etc/init.d/*

Now we are eventually done with 02memcputweak.

#!/system/bin/sh
#
# Copyright© 2011 Juwe11
# 13.8.2011 Updated VM values - Thanks to [Kalis] for help
# 18.8.2011 Added oom_adj values
# 19.9.2011 Updated VM and LMK values

if [ -e /sys/module/lowmemorykiller/parameters/adj ]; then
echo "0,1,2,4,6,15" > /sys/module/lowmemorykiller/parameters/adj
fi

if [ -e /sys/module/lowmemorykiller/parameters/minfree ]; then
echo "1536,4096,4096,25000,25000,25000" > /sys/module/lowmemorykiller/parameters/minfree
fi

if [ -e /proc/sys/vm/swappiness ]; then
echo "20" > /proc/sys/vm/swappiness
fi

if [ -e /proc/sys/vm/vfs_cache_pressure ]; then
echo "70" > /proc/sys/vm/vfs_cache_pressure
fi

if [ -e /proc/sys/vm/dirty_expire_centisecs ]; then
echo "3000" > /proc/sys/vm/dirty_expire_centisecs
fi

if [ -e /proc/sys/vm/dirty_writeback_centisecs ]; then
echo "500" > /proc/sys/vm/dirty_writeback_centisecs
fi

if [ -e /proc/sys/vm/dirty_ratio ]; then
echo "15" > /proc/sys/vm/dirty_ratio
fi

if [ -e /proc/sys/vm/dirty_background_ratio ]; then
echo "3" > /proc/sys/vm/dirty_background_ratio
fi

echo 19200 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo 710400 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
echo smartassV2 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
chmod 0755 /system/etc/init.d/*

Last steps, to make our script works in boot stage of Andriod, we have to insert

service script /system/etc/init.d/02memcputweak

oneshot

into file init.rc, which is located in WORKING_xxx > system > etc, the file will look similar to the text below::

# CyanogenMod Extras

# Compcache - handle at boot
service compcache /system/bin/handle_compcache
user root
group root
oneshot

service script /system/etc/init.d/02memcputweak
oneshot

Build rom from working directory

Back in the kitchen again, we are now going to pack rom back to .zip file so we could further test it.

In main menu of kitchen, there are options what to do with rom, type 99 to build the rom

After you have chosen a build option, change yourself to be an Interactive Mode (better for the new cooker).

Continue pressing Enter, throughout the process zipalign for optimize to reduce ram usage, and writting updater-script into rom (this part is the one who work with recovery and tell what to do in flashing.)

After every process is finished, we will get our rom in the folder OUTPUT_ZIP.

The next thing you have to do is flash and test the rom, enjoy.