Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
jonasl
Old
#1  
Senior Member - OP
Thanks Meter 133
Posts: 378
Join Date: Nov 2009
Location: San Francisco, CA
Default Howto enable Gmail notifications for all new mail with smali/baksmali

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
Code:
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
Code:
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.

Code:
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:

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

or-int/lit8 p0, p0, 0x1

and-int/lit8 p0, p0, 0xf7

iput p0, v5, Landroid/app/Notification;->flags:I
When new mail arrived I noted this with logcat:

Code:
New email for xyz@gmail.com unreadCount:5 getAttention:true
...
New email for xyz@gmail.com unreadCount:5 getAttention:false
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.

Code:
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:

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

move-result v2

const/4 v2, 0x1

.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:
Code:
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!).

Code:
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/mydro...-bytecode.html
http://www.netmite.com/android/mydro...n-formats.html
 
kendong2
Old
#2  
kendong2's Avatar
Recognized Developer
Thanks Meter 27
Posts: 1,547
Join Date: Sep 2009
this is a really cool hack, and dalvik hacking sounds quite interesting, but too high for me...

good job!
 
ratcom
Old
#3  
ratcom's Avatar
Senior Member
Thanks Meter 97
Posts: 1,136
Join Date: Mar 2005
Location: Nottingham, England
Great hack.... however having tried to do this myself ...... I'll leave it for you experts lol
(º·.¸(¨*·.¸ ¸.·*¨)¸.·º)
«.·°·.ratcom.·°·.»
(¸.·º(¸.·¨* *¨·.¸)º·.¸) Flashing Since 2004
 
penguin
Old
#4  
Junior Member
Thanks Meter 0
Posts: 23
Join Date: Jun 2005
Location: Vienna
This is an old thread - but super work!

"Gmail Notifier" in Android store now replaces this (I think that is also from you?) but your detective skills are an inspiration!

Thanks
Thanks
Penguin
 
Post Reply+
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

report this ad
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...