[Hero CDMA General] Nieylana:
I have seen a modified Phone.apk floating around for a while but sadly it stated that it was NOT compatible with the HTC Hero.

Well my phone had a 'feature' that makes it vibrate when the outgoing call connects, and i wanted to remove it.

Note that i'm running DamageControl 2.09 and there is NO option to disable this 'feature'.

Being quite determined and having an OK background in reversing applications i decided to give it a go.

My phone now contains an option in Phone Settings that will enable/disable this vibrate on outgoing connect.

Below i have detailed what I did and why. (I'll spare you all the things i did that didn't work, and only show HOW to modify the APK and get the system to accept it!)

Requistes:

able to run adb from command prompt (SDK in PATH EnVar)

able to run apktool from command prompt (in SDK folder?)

able to run the testsigner from the command prompt as 'java testsign' (ClassPath EnVar)

First things first, anything we do the the Phone.apk is going to require us to resign it. this presents a few problems...

Phone.apk has the following in it's AndroidManifest.xml

This means that there is most likely more .apks that have this same UserId (7 to be exact on DC 2.09)

All APKs sharing the same UserID MUST be signed with the same certificate or the OS wont let 'em load.

The second problem is that it is a system application, and if we change it's Certificate it will no longer be granted certain SYSTEM permissions like DEVICE_POWER

The easiest solution was for me to resign every apk in /system/app and /system/framework

Here is a little batch script for windows that i used (you may have to execute the commands individually, sometimes it's tempermental)

echo off
adb shell stop
mkdir SystemApp
adb pull /system/app SystemApp
mkdir SystemFramework
adb pull /system/framework SystemFramework

for /R %%x in (*.apk) do java testsign "%%x"

adb remount
adb push SystemApp /system/app
adb push SystemFramework /system/framework

rmdir /S /Q SystemApp
rmdir /S /Q SystemFramework

adb reboot recovery

echo Wipe Dalvik-Cache and Perform Factory Reset
echo execute 'adb shell chmod -R 777 /system' from adb
echo reboot and enjoy!
echo on

This code will take care of resigning all system apps, effectively changing the system certificate. Now we are free to modify the Phone.apk all we want!

Please remember that anytime we push a system app like Phone.apk which is 'always' running we should either be in recovery or use the following script:

adb shell stop
adb remount
adb push Phone.apk /system/app/Phone.apk
adb shell start
del Phone.apk
pause

after a short while the phone will seem to do a soft reset and will be running the new Phone.apk

Now that we have certificate issues out of the way lets look into the actual application itself.

once decompiled with apktool you can run this script to rename all the files to .txt (this is for being able to search the file contents via Windows Search)

note: the command prompt must be CD'd into the output directory of apktool

for /R %%x in (*.smali) do REN "%%x" *.txt

having searched through all the code for various keyphrases, i'll only show the correct ones here. We need to find where shouldVibrateOut() is located.

after searching for that we should see that it's located in Ringer.smali and looks like this:

.method shouldVibrateOut()Z
.locals 1

.prologue
.line 430
const/4 v0, 0x1

return v0
.end method

the code above effectively says return true; clearly someone was taking an easy way out here ;)... but this does confirm that there is no option to disable the 'feature'.

To disable it we could simply change the 0x1 to a 0x0 and recompile/push/reboot and be done with it. But the goal here is to extend the features of the phone, and doing what the dev should have done (giving users the option).

So, next we need to find the Preferences Activity that lists the options, and modify it's XML file to add our own there :D

looking again in the AndroidManifest.xml we find this:

So we know the activity is named PhonePreference

now we navigate to the /res/xml folder of apktool's output and find phone_preference.xml

it seems the last Checkbox is:

so we're going to take this line and copy paste it underneath and make it look like this (changes are bolded)

now we need to edit the strings.xml file to add values for the above checkbox

add these 2 lines to the strings.xml file:

If we were to compile it and push it to the phone now we would see a new menu option!

Sadly the Phone application is unaware of how to use this new setting to determine whether or not to vibrate. so we must teach it by editing the code.

I'm not going to go into great detail of what each line does they're pretty self explanatory. however i will go over the important pieces...

we need to change the shouldVibrateOut() routine to this:

the string in v1 is the same string as the android:key="pref_key_vibrate_out" we used when making the new checkbox.

the rest of the code basically grabs a hold of the instance's Context variable and uses some built in APIs to read the setting of that checkbox and return it's value:

Checked == True

Unchecked == False

This will enable the shouldVibrateOut routine to detect whether or not it SHOULD rather than just saying yes.

Come to think of it, why make a routine whose name suggests there's an option and then not give one!! anywayz let's finish up...

next if you did rename all the files you'll need to put them back to .smali

and then recompile it using apktool, resign it, push it to the /system/app folder AFTER issuing the STOP command as shown above.

once it's pushed you should be able to simply use

to do a 'soft' reboot of the phone.

If the app crashes try going into recovery mode and wiping out the dalvik cache!

I hope those who have read this got something out of it, and that i wasn't too confusing or too vague. any questions or comments you may have are welcome.

Enjoy!