[G2 and Desire Z Android Development] ajhavery:
Index

Edify or Updater-Script tutorial in 1st Post

Device specific fixes for vision in first post

Build.prop tweaks in 1st Post

MIUI Porting Guide In 1st Post

Sense 4.0/3.5 prting Guide in 2nd Post

Icecoldsandwich port | LewaOS Port | AOKP Port in 3rd Post

Hi,

First of all this thread is a compilation of all possible resources I am able to find from all possible sources.

Big credits to proxuser for his general MIUI rom porting guide, thanks to cjward for helping me out fix the Autorotation issue, Autobrightness Levels and for adding additional symbols to the "sym" key and big thanks to dekky to help me fix the "libandroid.runtime.so" error.

I've tried to cover all the basic aspects of ROM porting and modding including using smali/backsmali and modding apks with the help of apktool. I hope it will help those who are wiling to learn.

I request all the devs around there to take a look and suggest what else I can add there to make it more friendly.

Ok so there it is:

Here is the Updater-Script tutorial : Credits to Edify scripting from E. Pete Karelis and Free your android for original guides from where I learnt this.

[B]Function Name: mount[/B]

Function Syntax: mount(fs_type, partition_type, location, mount_point)

Parameter Details:

fs_type = "yaffs2" | "ext4"
partition_type="MTD" | "EMMC"
location = partition | device
mount_point = target folder to mount FS.

Action: Mounts a filesystem to the defined mount point

Returns: The mount point if successful, null if failed

[B]Function Name: is_mounted[/B]

Function Syntax: is_mounted(mount_point)

Parameter Details: mount_point = string, mount point to check if is mounted

Action: Checks if a filesystem is mounted.

Returns: The mount point if mounted, otherwise, returns null

[B]Function Name: unmount[/B]

Function Syntax: unmount(mount_point)

Parameter Details: mount_point = string, mount point to unmount

Action: Unmounts the filesystem

Returns: The mount point that was dismounted if successful, otherwise it returns null

[B]Function Name: format[/B]

Function Syntax: format(fs_type, partition_type, location)

Parameter Details:

fs_type = string,"yaffs2" | "ext4"
partition_type= string, "MTD" | "EMMC"
location = string, partition | device

Action: Formats a filesystem as specified

[B]Function Name: delete[/B]

Function Syntax: delete(file1, file2, ..., fileN)

Parameter Details: string, file to delete

Action: Deletes a file. Must specify at least one file; multiple files can be specified as multiple arguments

[B]Function Name: delete_recursive[/B]

Function Syntax: delete_recursive(dir1, dir2,...,dirN)

Parameter Details: string, directory to recursively delete

Action: Deletes a folder and all of its contents. At least 1 directory must be specified; multiple directories can be specified as additional arguments.

[B]Function Name: show_progress[/B]

Function Syntax: show_progress(frac, sec)

Parameter Details:

frac = fraction of progress completed
sec = total seconds

Action: Displays flashing progress in the recovery system

[B]Function Name: set_progress[/B]

Function Syntax: set_prograss(frac)

Parameter Details: frac=fraction of progress

[B]Function Name: package_extract_dir[/B]

Function Syntax: package_extract_dir(package_path, destination_path)

Parameter Details:

package_path = string, directory in package to extract
destination_path = string, target point to extract files to

Action: Extract the all of the files in a directory in the package to the target specified.

[B]Function Name: package_extract_file[/B]

Function Syntax:

package_extract_file(package_path)
or
package_extract_file(package_path, destination_path)

Parameter Details:

package_path = string, file in the package you want to extract
destination_path, target folder to extract the file to.

Action: Extracts a single file from your update package to the target specified
[B]
Function Name: file_getprop[/B]

Function Syntax: file_getprop(file, key)

Parameter Details:

file = string, filename to check
key = string, key in file to return the value of

Action: Checks for a value in a file?

[B]Function Name: symlink[/B]

Function Syntax: symlink(target, src1, src2, ..., srcN)

Parameter Details:

target = string, the target of the symbolic link
srcX = the symbolic link to create that points to the target

Action: Unlinks any existing symbolic links before creating the new symbolic links.
[B]
Function Name: set_perm[/B]

Function Syntax: set_perm(uid, gid, mode, file1, file2, ..., fileN)

Parameter Details:

uid = user id
gid = group id
mode = permission mode
fileX = file to set permission on

Action: Sets permissions of a file or set of files specified. At least one file must be specified (the first four parameters are required)

[B]Function Name: set_perm_recursive[/B]

Function Syntax: set_perm_recursive(uid, gid, dirmode, filemode, dir1, dir2, ...dirN)

Parameter Details:

uid = user id
gid = group id
dirmode = permission to set to directories contained within the specified directory
filemode = permission to set to files contained within the specified directory
dirX = directory to set permission on

Action: Set permissions of a directory or set of directories and all files and folders within them. At least one directory must be specified (The first 5 parameters are required)

[B]Function Name: getprop[/B]

Function Syntax: getprop(key)

Parameter Details: key = string, the property you want the system to return

Action: This function returns the value of the property specified. This is used to query platform information from the build.props file.

[B]Function Name: write_raw_image[/B]

Function Syntax: write_raw_image(file, partition)

Parameter Details:

file - string, the source .img file to be read from
partition - string, the destination partition to write the .img file to

Description: This function writes an img file to a partition.

[B]Function Name: apply_patch[/B]

Function Syntax: apply_patch(srcfile, tgtfile, tgtsha1, tgtsize, sha1_1, patch_1, ..., sha1_x, patch1_x)

Parameter Details:

srcfile - string, source file to be patched (file to read in)
tgtfile - string, destination file to write the patched file to
tgtsha1 - string, sha1 hash of the target file as it should hash out after the patches apply properly
sha1_x - string, sha1 hash of the patch data that's to be written to the target file
patch1_x- string, actual patch to apply to the target file

Action: This function is used to apply patches to a file.

[B]Function Name: apply_patch_check[/B]

Function Syntax: apply_patch_check(file, sha1_1, ..., sha1_x)

Parameter Details:

file - string, file to check
sha1_x - hash to check for?

Action: Either checks if a file has been properly patched, or checks if a file can be patched. Need to check the source code of the "applypatch_check" function that is called from here.

[B]Function Name: apply_patch_space[/B]

Function Syntax: apply_patch_space(bytes)

Parameter Details: bytes = number of bytes to check for

Action: Checks the cache to verify that there is enough space to write the patched files to it and returns something. Need to test this function to verify.

[B]Function Name: read_file[/B]

Function Syntax: read_file(filename)

Parameter Details: filename - string, the filename to read the contents of

Action: This function returns the contents of a file.

[B]Function Name: sha1_check[/B]

Function Syntax:

sha1_check(data)
or
sha1_check(data, sha1_hex, ..., sha1_hexN)

Parameter Details:

data - the contents of file to calculate the sha1 hash of - must be in the read_file format
sha1_hexN - A particular sha1_hex string that you want the file data to match

Action: If only data is specified, then the function returns the sha1_hex string of the data. The optional parameters are used if you want to verify that the file you are checking for is one of a list of hashes. It reutrns the hash it matches, or returns nothing if it doesn't match any of the mentioned hashses.

[B]Function Name: ui_print[/B]

Function Syntax: ui_print(msg1, ..., msgN)

Example : ui_print("===============================================");

to print ===============================================

Parameter Details: msg - String, message to be outputted to the user during the patch process

Action: This function prints/echos a message to the console while the script is running. At least 1 parameter needs to be specified, you can specify additional msg parameters and they will be concatenated to the output.

Function Name: run_program

Function Syntax: run_program(prog, arg1, .., argN)

Parameter Details:

prog - string, program to execute
argN - string, arguments for the program that is being executed
Description: Executes a program with the arguments specified. Returns a string, I assume it is the buffer of the stdout of the program executed, need to test.

[B]Function Name: ifelse[/B]

Function Syntax: ifelse(condition, truecondition, falsecondition)

Parameter Details:

condition - an expression to evaluate
truecondition - Edify script block to execute if true
falsecodnition - Edify script block to execute if false

Description: This is the if-then construct of the Edify scripting language. The truecondition or falsecondition arguments can be a single edify command or a script block. Script blocks can be formed by enclosing the parameter with parenthesis, and seperating the commands with semicolons\

[B]Function Name: abort[/B]

Function Syntax: abort()

Parameter Details: no paremeters

Description: Aborts script execution.

[B]Function Name: assert[/B]

Function Syntax: assert(condition)

Parameter Details: condition - boolean

Description: If condition evaluates to false, stops script execution, otherwise continues processing.

Here is some device specific instructions :

mmcblk0p25 refers to system partition of the device

mmcblk0p26 refers to data partition of the device

mmcblk0p27 refers to cache partition of the device

Refer to following if you get error during flashing in recovery :

Error 6 : The updater-script is not in proper unix format (Happens when you edit file in windows)

More to come

Keyboard Fix:

Since Desire Z has a keyboard, we need to modify the android.policy.jar to tell it the lid open state.

Here's what you need to do (thanks cjward):

FIX KEYBOARD ROTATION AND AUTO ROTATE :

Go into android.policy.jar\smali\com\android\internal\poli cy\impl\PhoneWindowManager.smali

ORIGINAL
.line 1094
const/4 v1, 0x1
CHANGE TO
.line 1094
const/4 v1, 0x0
ORIGINAL
.line 1096
const/4 v1, 0x0
CHANGE TO
.line 1096
const/4 v1, 0x1

These line number need not be same, but what you need to notice is that these states will differ with a value of 2 and it should have a comment :

<------------ mLidOpen .....

To search this line, hit "ctrl + f" and type "const/4 v1, 0x1", probably in one or two hits, you will get to this.

If it doesn't gets fixed by this then you need to make one more modification:

(thanks NeverGone\RU for pointing this out)

Change the following line in framework-res/res/values/bools.xml:

<bool name="config_forceDisableHardwareKeyboard">true</bool>

Setting this value to false fixed the keyboard issue completely.

Trackpad Wake : (big thanks to lms24 for pointing this out):

Open libinput.so with a hex editor and search for these 4 numbers: A1 F5 88 72. Change the 88 to 89 and save it.

Decompile android.policy.jar. open keyguardviewmediator.smali and fo down to method "isWakeKeyWhenKeyguardShowing(IZ)Z"

You need to modify the 0x18 and 0x19 values to enable tp wake.

If you want volume rocker wake also then just delete the lines of 0x18 and 0x19.

I haven't been able to figure out exactly what you need to do to enable only tp wake and not the volume rocker, so for time being just swap the above listed method from a rom which has got working tp-wake, like Sabsa bliss by lms24 for sense 3.6 and Gen.Y R3 for Sense 4 roms.

The method should look like this:

.method public isWakeKeyWhenKeyguardShowing(IZ)Z
.locals 3
.parameter "keyCode"
.parameter "isDocked"

.prologue
const/4 v2, 0x0

iget-object v0, p0, Lcom/android/internal/policy/impl/KeyguardViewMediator;->mContext:Landroid/content/Context;

invoke-virtual {v0}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v0

const-string v1, "tweaks_lockscreen_volumekey"

invoke-static {v0, v1, v2}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v0

if-nez v0, :cond_0

.line 1242
sparse-switch p1, :sswitch_data_0

goto :goto_0

.line 1273
:cond_0
sparse-switch p1, :sswitch_data_1

:goto_0
const/4 v0, 0x1

move p2, v0

.line 1269
.end local p2
:goto_1
:sswitch_0
return p2

.line 1265
.restart local p2
:sswitch_1
sget-short v1, Lcom/htc/htcjavaflag/HtcBuildFlag;->Htc_DEVICE_flag:S

const/16 v2, 0x1c

if-eq v1, v2, :cond_1

sget-short v1, Lcom/htc/htcjavaflag/HtcBuildFlag;->Htc_DEVICE_flag:S

const/16 v2, 0x89

if-ne v1, v2, :cond_2

.line 1269
:cond_1
move p2, v0

.line 1263
goto :goto_1

.line 1265
:cond_2
const/4 p2, 0x0

goto :goto_1

.line 1238
nop

.line 1242
:sswitch_data_0
.sparse-switch
0x18 -> :sswitch_0
0x19 -> :sswitch_0
0x1b -> :sswitch_1
0x4f -> :sswitch_1
0x55 -> :sswitch_1
0x56 -> :sswitch_1
0x57 -> :sswitch_1
0x58 -> :sswitch_1
0x59 -> :sswitch_1
0x5a -> :sswitch_1
0x5b -> :sswitch_1
0x7e -> :sswitch_1
0x7f -> :sswitch_1
0x82 -> :sswitch_1
0xa4 -> :sswitch_0
0xe4 -> :sswitch_1
.end sparse-switch
.end method

Build.prop Common Tweaks : Credits blindnumb

# Fast Reboot
persist.sys.purgeable_assets=1

# Increasing The Video Recording Quality
ro.media.enc.hprof.vid.bps=8000000

# Screen Rotate To 270 degree
windowsmgr.support_rotation_270=true;

# Increase VM Heap Size(resolve some fc's)
dalvik.vm.heapsize=64m

# Render UI With GPU
debug.sf.hw=1

# Increasing It Will Make Mobile Smoother
windowsmgr.max_events_per_sec=150

# Video Acceleration Enabled
video.accelerate.hw=1

# Increase Performance
debug.performance.tuning=1

# Disable Sending Usage Data
ro.config.nocheckin=1

# Deeper Sleep/Better battery life
ro.ril.disable.power.collapse=1
pm.sleep_mode=1

# Ringing Will Start Immediately
ro.telephony.call_ring.delay=0

# Disable Error Checking
ro.kernel.android.checkjni=0

# Increase Quality Of MediaStreaming
media.stagefright.enable-meta=true
media.stagefright.enable-scan=true
media.stagefright.enable-http=true
media.stagefright.enable-record=false

# Disable BootAnimation
debug.sf.nobootanimation=1

#Force To Remain Launcher In Memory
ro.HOME_APP_ADJ=1

# Disable Waking Up Of Phone By Volume Buttons
ro.config.hwfeature_wakeupkey=0

# Off The Proximity Quiclky After Call
mot.proximity.delay=25

# Signal Tweaks
ro.ril.hsxpa=2
ro.ril.gprsclass=10
ro.ril.hep=1
ro.ril.enable.dtm=1
ro.ril.hsdpa.category=10
ro.ril.enable.a53=1
ro.ril.enable.3g.prefix=1
ro.ril.htcmaskw1.bitmask=4294967295
ro.ril.htcmaskw1=14449
ro.ril.hsupa.category=5

# NetSpeed Tweaks
net.tcp.buffersize.default=4096,87380,256960,4096, 16384,256960
net.tcp.buffersize.wifi=4096,87380,256960,4096,163 84,256960
net.tcp.buffersize.umts=4096,87380,256960,4096,163 84,256960
net.tcp.buffersize.gprs=4096,87380,256960,4096,163 84,256960
net.tcp.buffersize.edge=4096,87380,256960,4096,163 84,256960

# Google DNS Tweak
net.rmnet0.dns1=8.8.8.8
net.rmnet0.dns2=8.8.4.4
net.dns1=8.8.8.8
net.dns2=8.8.4.4

# Photo And Video Quality
ro.media.dec.jpeg.memcap=8000000
ro.media.enc.hprof.vid.bps=8000000
ro.media.enc.jpeg.quality=100

# Touch Responsiveness
debug.performance.tuning=1
video.accelerate.hw=1

# Scrolling Responsiveness
windowsmgr.max_events_per_sec=500

# Power Save Tweaks
ro.ril.disable.power.collapse=1
pm.sleep_mode=1

# Disables Debug Icon On Status Bar
persist.adb.notify=0

For a more complete list, Visit his website, click here.

Its a huge collection of resources and tutorials so do visit it.

Step 1:

You need to choose you base and the rom you want to port. Prefer to choose a rom which shares the same brand or if possible shares the same chipset as HTC Vision. So, choose any MIUI v4 rom from "Desire HD" if possible and If you are not able to get one, Choose one from "Desire S" or "Nexus One" or "Desire".

I would recommend MIUI-Au, since I found their english translations are best but it is not getting updated regularly, so you are free to choose your base rom.

Here is the link to some MIUI ICS roms which you could port:

MIUI-Au for HTC Desire

Dekky's MIUI ICS for Desire HD

MIUI-us ICS for Desire HD

MIUI-us ICS for Nexus One

Choose any cm9 or ics AOSP or AOKP rom as your base for the port here are a few roms you could use as your base are :

Andromadus Audacity Beta 2

Virtuous Quattro RC3

Virtuous Quattro RC4 leak

So, you grabbed some or all of these roms, lets get to the next step.

Step 2 :

Replace complete folders (those noted below) of your base rom with the MIUI one :

system/app

system/framework

Step 3:

Go to /system/lib :

copy "libandroid_runtime.so" lib from miui 4 (rom you port). without this file rom will not boot. if you get bootloop, try with base "libandroid_runtime.so" file.

If it still doesn't boot, then look at the end of the post, you need to add some modifications to your framework.jar which i'll take at the end of the post.

copy "liblbesec.so" from miui 4 to /system/lib and open the updater-script of your base rom with "notepad++" on windows or with "gedit" on linux and add the following line to it :

set_perm(0, 0, 0755, "/system/lib/liblbesec.so");

(for superuser app from miui work)

copy "content-types.properties" file to /system/lib

Step 4:

replace /system/media folder with base rom (that themes, wallpaper, audio from miui work)

Step 5:

copy "telocation.db" and "yellowpage.db" to /system/etc folder.

Step 6:

copy "invoke-as" from miui4 rom to /system/xbin and give it permissions on updater-script

set_perm(0, 0, 06755, "/system/xbin/invoke-as");

(for backup & themes app work)

Step 7:

change values from build.prop (edit with notepad ++)

ro.build.id=MIUI

ro.build.display.id=MIUI

ro.build.version.incremental=2.x.x (version number)

ro.config.ringtone=MI.ogg

ro.config.notification_sound=FadeIn.ogg

ro.config.alarm_alert=GoodMorning.ogg

ro.config.sms_received_sound=FadeIn.ogg

ro.config.sms_delivered_sound=MessageComplete.ogg

Step 8 :

SInce Desire Z has a keyboard, we need to modify the android.policy.jar to tell it the lid open state.

Here's what you need to do (thanks cjward):

FIX KEYBOARD ROTATION AND AUTO ROTATE :

Go into android.policy.jar\smali\com\android\internal\poli cy\impl\PhoneWindowManager.smali

ORIGINAL
.line 1094
const/4 v1, 0x1
CHANGE TO
.line 1094
const/4 v1, 0x0
ORIGINAL
.line 1096
const/4 v1, 0x0
CHANGE TO
.line 1096
const/4 v1, 0x1

These line number need not be same, but what you need to notice is that these states will differ with a value of 2 and it should have a comment :

<------------ mLidOpen .....

To search this line, hit "ctrl + f" and type "const/4 v1, 0x1", probably in one or two hits, you will get to this.

If you have no idea what I'm talking about then read carefully.

You need to extract android.policy.jar from MIUI rom and decompile it using backsmali.

Go here and download "smali-1.3.2.jar" and "backsmali-1.3.2.jar".

Put them in the same folder you put your extracted android.policy.jar. Then open cmd.exe and browse to that folder and hit the command:

java -jar baksmali.jar -a 15 -x android.policy.jar -o classout

It'll give you a folder named "classout" once it has finished decompiling. Now open that folder and browse to the file mentioned above.

Edit the values and then return back to your command windows and hit the command:

java -Xmx512M -jar smali.jar -a 15 classout -o classes.dex

It'll give you a file named classes.dex.

Now open "android.policy.jar" with 7zip:

Right click on the file --> hit 7zip --> Open archive.

Then drag the classes.dex you created into the window which appeared.

It'll replace the old classes.dex in android.policy.jar

Now use this file for your port.

Step 9:

Now we need to add some modifications to "framework.jar" to add more symbols to the "sym" key and to get the rom boot in case it gets into bootloop with all the available "libandroid.runtime.so" from both MIUI roms and the base rom.

EXTRA SYMBOLS ON "SYM" KEY

Again as explained above, decompile framework.jar and browse to the file mentioned below:

framework.jar\smali\android\text\method\QwertyKeyListener.smali

ORIGINAL
const-string/jumbo v2, "\u2026\u00a5\u2022\u00ae\u00a9\u00b1[]{}\\|"
CHANGE TO
const-string/jumbo v2, "$\u00a5\u2022\u00ae\u00a9\u00b1[]{}<>`^\\|"

This will add some extra symbols on the "sym" key.

Now to get the rom boot in case it is not booting with available "libandroid.runtime.so".

Use the "libandroid.runtime.so" from the base rom and do the following modifications:

decompile you base rom "framework.jar" and MIUI "framework.jar" and do the following:

swap Power.smali, Paint.smali, MediaRecorder.smali, GLES20Canvas.smali, PowerManager*.smali... from base framework.jar to MIUI framework.jar

Then recompile it as mentioned above how to recompile jar files and use it in your port. (If it's still not booting then get a logcat to know the error)

Step 10 :

Now to fix the autobrightness values to the correct level, you need to do the following:

Obtain framework-res.apk from the MIUI rom and decompile it using apktool. If you don't know how to do that then read below or skip to next section.

Here is the link to different apktools:

apktool used by cjward : Click here

apktool used by lyapota : Click here

I use a different technique to get things done (thanks to galaxynexusforums):

Download the package of different apktools from here.

Extract these files and the apk you want to mod in the same folder.

Open cmd.exe and browse to that folder.

Install the latest android sdk and grab the latest "aapt.exe" from it. For me, the folder is : C:\Android\android-sdk\platform-tools

Now hit the follow command :

java -jar apktool_1_4_2.jar if framework-res.apk

(you need to rename apktool.jar.1.4.2 to apktool_1_4_2.jar and similarily apktool.jar.1.4.3 to apktool_1_4_3.jar)

java -jar apktool_1_4_2.jar d framework-res.apk

Now do the modding as stated below:

AUTO BRIGHTNES AND KEYBOARD LIGHTS FIX:

browse to the file "framework-res.apk\res\values\arrays.xml"

ORIGINAL
<integer-array name="config_autoBrightnessLevels">
<item>200</item>
<item>400</item>
<item>1000</item>
<item>3000</item>
CHANGE TO
<integer-array name="config_autoBrightnessLevels">
<item>11</item>
<item>41</item>
<item>91</item>
<item>161</item>
<item>226</item>
<item>321</item>
<item>641</item>
<item>1281</item>
<item>2601</item>

ORIGINAL
<integer-array name="config_autoBrightnessLcdBacklightValues">
<item>35</item>
<item>55</item>
<item>70</item>
<item>70</item>
<item>250</item>
CHANGE TO
<integer-array name="config_autoBrightnessLcdBacklightValues">
<item>89</item>
<item>89</item>
<item>126</item>
<item>164</item>
<item>164</item>
<item>164</item>
<item>187</item>
<item>210</item>
<item>233</item>
<item>255</item>
ORIGINAL
<integer-array name="config_autoBrightnessButtonBacklightValues">
<item>255</item>
<item>255</item>
CHANGE TO
<integer-array name="config_autoBrightnessButtonBacklightValues">
<item>30</item>
<item>30</item>
<item>30</item>
<item>30</item>
<item>0</item>
<item>0</item>
<item>0</item>
ORIGINAL
<integer-array name="config_autoBrightnessKeyboardBacklightValues ">
<item>0</item>
<item>0</item>
<item>0</item>
<item>0</item>
<item>0</item>
CHANGE TO
<integer-array name="config_autoBrightnessKeyboardBacklightValues ">
<item>255</item>
<item>255</item>
<item>255</item>
<item>255</item>
<item>0</item>
<item>0</item>
<item>0</item>
<item>0</item>
<item>0</item>
<item>0</item>

After changing these values, hit the following command in the command window:

java -jar apktool_1_4_3.jar b framework-res

It'll take a while to complete. If it gives you error, try with different versions of apktool.

Once you are done:

Go to "framework-res\dist" and right click on the framework-res.apk you find there.

Now ---> 7zip ---- > Open archive

Now copy the resource.arsc from there to your desktop.

Open you original framework-res.apk via 7zip in the same manner as stated above and replace the default resource.arsc file with the once from your desktop.

Use this modded framework-res.apk in your port.

Step 11:

Now you have completed you port. Now zip the file and sign it with the help of dsixda kitchen.

If you don't know how to do so, go there.

If you don't want to get you hands dirty with dsixda kitchen, then just open your base rom with "winrar" or "7zip" and swap the files and mods stated above.

Your ROM is now ready to be flashed.

Credits :

proxuser

cjward

dekkyy

galaxynexusforums

lyapota for his apktool