[Hero, G2 Touch Q&A, Help & Troubleshooting] jonasl:
The Gmail app on my Hero (possibly on all Android devices?) has one big annoyance: I only get audio and vibration notifications for the first mail received after clearing notifications. If I missed the first notification for some reason, the phone will sit quiet for all subsequent incoming mail until I attend to the existing notification (the notification text will be updated on subsequent mail but no vibration/sound).

This is reported here

http://code.google.com/p/android/issues/detail?id=4190

Since Google seems to ignore this issue I decided to fix it my self. Here is a summary of how I did it, in case someone is interested in doing something similar.

Required knowledge is basic understanding of the Android SDK and some basic knowledge of the concepts of assembler. The latter is required since this involves modifying Dalvik assembly. Don't worry too much, it's MUCH easier than assembly for real CPUs.

Download smali/baksmali from http://code.google.com/p/smali/ (Thank you JesusFreke, you ROCK!).

Get hold of Gmail.apk either by pulling from your device or extracting it from your current ROM update.zip. Disassemble it with

java -jar baksmali.jar Gmail.apk

Now you have the Gmail source code in a subfolder called out. Use a descent search tool to search for a relevant section in the resulting files. I searched for "NotificationManager" since that handles Android notifications (using UltraEdit's Find in files).

There is one line found

invoke-virtual {v4, p0, v5}, Landroid/app/NotificationManager;->notify(ILandroid/app/Notification;)V

Register v5 contains the notification to be set (check SDK docs, it's the last argument of the method call). Scroll up to see what's being done to the Notification prior to showing it.

iget p0, v5, Landroid/app/Notification;->flags:I

or-int/lit8 p0, p0, 0x1

iput p0, v5, Landroid/app/Notification;->flags:I

This is the manipulation of the flags controlling notification properties. Here I cleared the FLAG_ONLY_ALERT_ONCE (check SDK docs) flag by adding a line:

iget p0, v5, Landroid/app/Notification;->flags:I

or-int/lit8 p0, p0, 0x1

[B]and-int/lit8 p0, p0, 0xf7[/B]

iput p0, v5, Landroid/app/Notification;->flags:I

When new mail arrived I noted this with logcat:

New email for xyz@gmail.com unreadCount:5 [B]getAttention:true[/B]
...
New email for xyz@gmail.com unreadCount:5 [B]getAttention:false[/B]

The first case gave me notifications, the other didn't. Let's make getAttention always true! Search for "getAttention". It's slightly above the previous edited section.

invoke-virtual {p2, v1, v2}, Landroid/content/Intent;->getBooleanExtra(Ljava/lang/String;Z)Z

move-result v2

.line 287
.local v2, getAttention:Z

A local variable called getAttention is in register v2. Check some lines later to see that it's used to output the logs above. The right place! Now make the variable always true by loading 0x1 in register v2:

invoke-virtual {p2, v1, v2}, Landroid/content/Intent;->getBooleanExtra(Ljava/lang/String;Z)Z

move-result v2

[B]const/4 v2, 0x1[/B]

.line 287
.local v2, getAttention:Z

Done! Save the file (Utils.smali) and assemble it back into a classes.dex file. Back at the console:

java -jar smali.jar -o classes.dex out

You end up with a shiny new classes.dex. Replace the original one in Gmail.apk with the new file using your favorite zip manager. Also, remove the folder "META-INF" found in the apk. Now follow some guide on the net for signing the apk. This process adds a new "META-INF" folder.

Now push it to the phone, and reboot (make a nandroid backup first!).

adb remount
adb push Gmail.apk /system/app/Gmail.apk
adb shell rm /data/dalvik-cache/*Gmail*
adb shell reboot

Now my phone beeps and vibrates for every incoming mail. This process is not for everyone, but works for me. The adventurous can download my modified apk (based on MCR 3.0, which is based on 2.73.405.66)

http://www.mediafire.com/?uuzwhkc5nzy

http://www.filefactory.com/file/a1h98eh/n/Gmail.apk

http://www.filedropper.com/gmail

Obviously root required and nandroid recomended. No warranties.

Anyone have suggestions for other modifications or want to collaborate on some Dalvik hacking? This turned out to be quite fun :-)

Dalvik info can be found here:

http://www.netmite.com/android/mydroid/dalvik/docs/dalvik-bytecode.html

http://www.netmite.com/android/mydroid/dalvik/docs/instruction-formats.html