[App] Patched Gmail to allow permission for third party notification widgets

Tsjoklat

Senior Member
Apr 5, 2010
1,705
2,385
0
This is a modified version of Gmail that fixes the database permissions of Gmail so third party notification widgets (such as Missed It!, Go Notification, and Pure Messenger Widget) can determine which emails are read and which emails are unread for a true unread email count.

Code:
diff -ru Gmail.org/AndroidManifest.xml Gmail/AndroidManifest.xml
--- Gmail.org/AndroidManifest.xml	2011-08-02 22:49:48.356157842 +0200
+++ Gmail/AndroidManifest.xml	2011-08-02 22:52:05.603773155 +0200
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest android:versionCode="169" android:versionName="2.3.5" package="com.google.android.gm"
   xmlns:android="http://schemas.android.com/apk/res/android">
-    <permission android:label="@string/read_perm_label" android:name="com.google.android.gm.permission.READ_GMAIL" android:protectionLevel="signature" android:permissionGroup="android.permission-group.MESSAGES" android:description="@string/read_perm_desc" />
-    <permission android:label="@string/write_perm_label" android:name="com.google.android.gm.permission.WRITE_GMAIL" android:protectionLevel="signature" android:permissionGroup="android.permission-group.MESSAGES" android:description="@string/write_perm_desc" />
-    <permission android:label="@string/auto_send_perm_label" android:name="com.google.android.gm.permission.AUTO_SEND" android:protectionLevel="signature" android:permissionGroup="android.permission-group.MESSAGES" android:description="@string/auto_send_perm_desc" />
+    <permission android:label="@string/read_perm_label" android:name="com.google.android.gm.permission.READ_GMAIL" android:protectionLevel="normal" android:permissionGroup="android.permission-group.MESSAGES" android:description="@string/read_perm_desc" />
+    <permission android:label="@string/write_perm_label" android:name="com.google.android.gm.permission.WRITE_GMAIL" android:protectionLevel="normal" android:permissionGroup="android.permission-group.MESSAGES" android:description="@string/write_perm_desc" />
+    <permission android:label="@string/auto_send_perm_label" android:name="com.google.android.gm.permission.AUTO_SEND" android:protectionLevel="normal" android:permissionGroup="android.permission-group.MESSAGES" android:description="@string/auto_send_perm_desc" />
     <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" android:maxSdkVersion="10" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
Requirements:

a) Your device does not come preinstalled with gmail so the original version can be completely uninstalled first before installing the modified version. After uninstalling original version of Gmail, install modified Gmail.apk as normal by running it.

OR

b) If you have root and your device has Gmail preinstalled in /system/app/Gmail.apk, then you have two choices. Either remove /system/app/Gmail.apk and install the modified version of Gmail normally by running the apk (to /data/app/Gmail.apk) OR replace /system/app/Gmail.apk with the modified version of Gmail. It is probably easier to remove Gmail.apk from the system partition and install it as a normal user application in /data/app/. However you want to do it..Gmail will install as a system or data application. To save space, I would not have it installed in both places.

Note: To simplify the installation of Gmail to the system partition for S-ON devices, I have added Gmail in a recovery flashable zip file format. This method requires busybox to be installed on your device. Make sure you uninstall any Gmail updates first, if possible. This method is only recommended if you have Gmail preinstalled to /system/app/Gmail.apk and you want to replace it with the modified version.


Note: After initially replacing or reinstalling Gmail with the modfied version, the notification widget (ie; Go Notification, Missed It!, or Pure Messenger Widget) needs to be reinstalled to regain premissions.

Note: Gmail 2.x is for Gingerbread. Gmail 3.x is for Honeycomb. Gmail 4.x is for ICS (but version 4.0.1 and 4.0.2 are reported working in Honeycomb too). At the time of this writing, ICS and Honeycomb support is limited. AFAIK, Pure Messenger Widget is the only third party notification widget that supports the ICS/Honeycomb Gmail protocol. Hopefully, more third party notification widgets will add support for ICS/Honeycomb in the future.

Updating from previous modified version of Gmail:

If you already have an older modified version of Gmail installed, the newer modified version of Gmail can be installed on top to perform the update. No need to remove the previously installed modified version of Gmail first.

Sources:

The latest versions of Gmail for ICS/Honeycomb are extracted from firmware from: http://www.sammobile.com/firmware/

Process:

1) Download latest Firmware from link above.

2) Extract files (this process requires linux)
a) Unzip or Unrar accordingly with samsung password (usually it is "samfirmware.com")
b) Extract again (tar -xf filename.tar.md5)
c) Extract again the largest file (a file.tar.md5 that is ~900MB) from the previous extraction. The largest file that is extracted contains the necessary system files. The system files can be found in two formats (system.rfs or factoryfs.img).

3) Process for reading system.rfs format (if system.rfs does not exist, skip to step #4)
a) Mount system.rfs using the following commands:
Code:
mkdir ~/tempdir
sudo losetup /dev/loop0 ./system.rfs
sudo mount -t vfat /dev/loop0 ~/tempdir
b) Copy necessary files to a writable location:
Code:
mkdir ~/workspace
cp -a ~/tempdir/system/framework ~/workspace/
cp -a ~/tempdir/system/apps ~/workspace/
c) Unmount and clean up
Code:
sudo umount /dev/loop0
sudo losetup -a
sudo losetup -d /dev/loop0
4) Process for reading factoryfs.img
a) Build ext4_utils from the following post: http://forum.xda-developers.com/showthread.php?t=1081239
b) Convert factoryfs.img to readable format with simg2img utility found in ext4_utils
Code:
simg2img factoryfs.img output.img
c) Mount output.img
Code:
mkdir ~/tempdir; sudo mount -o loop output.img ~/tempdir
d) Copy necessary files to a writable location:
Code:
mkdir ~/workspace
cp -a ~/tempdir/system/framework ~/workspace/
cp -a ~/tempdir/system/apps ~/workspace/
e) Unmount and clean up
Code:
sudo umount /dev/loop0
5) Creating classes.dex from Gmail.odex
a) Copy Gmail.odex into new framework directory from firmware image
Code:
cp ~/workspace/app/Gmail.odex ~/workspace/framework/
cd ~/workspace/framework/
b) Decompile odex file (api-level must be set accordingly) http://code.google.com/p/smali/
Code:
baksmali --api-levl 14 -x Gmail.odex
c) Compile output into classes.dex (api-level must be set accordingly)
Code:
smali --api-level 14 -o classes.dex out
6) Insert classes.dex into Gmail.apk
Code:
cp ~/workspace/app/Gmail.apk ~/workspace/framework/
mv Gmail.apk Gmail.zip
zip Gmail.zip -d META-INF/*
zip -o Gmail.zip classes.dex
mv Gmail.zip Gmail.apk
7) Decompile Gmail.apk with apktool (at the time of this writing it is apktool v1.4.3) http://code.google.com/p/android-apktool/
Code:
apktool d Gmail.apk
8) Edit AndroidManifest.xml (replacing "signature" with "normal"). See patch above for details.

9) Compile modified version of Gmail with apktool.
Code:
apktool b Gmail Gmail.mod.apk
Note: The current released version of apktool (1.4.3) will not be able to compile the resources for the new ICS api. Therefore, you will have to go into the res directory and delete all the resource directories that cause errors within apktool. After you delete those directories, you will see that apktool will also start showing errors in public.xml because resources are now missing. You will have to edit public.xml and delete the lines that show up as errors when compiling with apktool. Once you get the Gmail.mod.apk to build, extract the apk with unzip tool (unzip Gmail.mod.apk) and copy the extracted AndroidManifest.xml (in binary form) into an unaltered Gmail.apk that includes classes.dex. Rename original Gmail.apk to a zip file and insert the modified AndroidManifest.xml, then rename zip back to apk.

10) Sign Gmail with test keys:
Code:
java -jar /usr/local/bin/signapk.jar /usr/local/bin/testkey.x509.pem /usr/local/bin/testkey.pk8 Gmail.apk Gmail.mod-signed.apk
 
Last edited:

Fr4gg0r

Inactive Recognized Developer
Aug 4, 2010
698
679
0
u sure this can work?
I thought about the same, but gmail surely requires permissions from talk.apk for google connection... which is again signature protected.
 

Paladin2187

Member
Oct 12, 2010
9
0
0
I would assume you have to be rooted and use some kind of file manager to force this into place and even then, if as mentioned, you don't have any of the other files patched that are required... not gonna help so much.

Thanks for trying though.

I'm afraid gmail is sort of dead in the water until google decides to back down or provide some reasonable means of interaction for 3rd party applications.
 

Tsjoklat

Senior Member
Apr 5, 2010
1,705
2,385
0
This will only work if:

a) your phone does not come preinstalled with gmail so that it can be removed first before installing the modified version.

b) if you have root and can rename this file to Gmail.apk and copy it to system/app/ (replacing the original).

This fixes the database permissions of Gmail so third party applications can get the email count (such as Missed It! and Go Notification.

Note: After replacing or reinstalling Gmail, the notification widget (ie; Go Notification or Missed It!) needs to be reinstalled to regain premissions.
 
Last edited:

Bunecarera

Senior Member
Mar 4, 2008
174
47
48
Alright, got it to work.

Updated to 2.3.5 from market from 2.3.4.
FC with "SMS unread count" and "Email Notifier"
Uninstalled these 2 apps.
Deleted gmail.apk from systems/apps (made back up first) with Root Explorer
Renamed modded version from Tsjoklat to gmail.apk and copied to system/apps with Root Explorer and set permissions to rw-rwe-re
Rebooted.
Installed Sms Unread Count and Email Notifier again and it's working. No FC's yet.
 

bartito

Inactive Recognized Developer
Dec 1, 2005
3,891
1,773
253
another workarround

in order to have widgets working with gmail 2.3.5 you only need to resign the gmail 2.3.5 and widgets.

actions:

- download original gmail 2.3.5 from the android market
- copy the apk to your pc
- resign with apkmanager (you don't need to make any change in manifest.xml)
- uninstall original gmail in your android
- install resigned gmail in your android

make the same actions with your widgets...

works fine with "sms unread notifications", "gmail notifier", etc.

note 1: note that this method prevents other applications to access to your messages :)
note 2: when the widgets or gmail are updated in market, you need to uninstall resigned app in order to update. next, make the same actions...
 
Last edited:
  • Like
Reactions: bgx

d88888b

Senior Member
Feb 12, 2011
52
5
0
Alright, got it to work.

Updated to 2.3.5 from market from 2.3.4.
FC with "SMS unread count" and "Email Notifier"
Uninstalled these 2 apps.
Deleted gmail.apk from systems/apps (made back up first) with Root Explorer
Renamed modded version from Tsjoklat to gmail.apk and copied to system/apps with Root Explorer and set permissions to rw-rwe-re
Rebooted.
Installed Sms Unread Count and Email Notifier again and it's working. No FC's yet.
niiice...ive been trying to get this working since the gmail update
 
Last edited:

bartito

Inactive Recognized Developer
Dec 1, 2005
3,891
1,773
253
Alright, got it to work.

Updated to 2.3.5 from market from 2.3.4.
FC with "SMS unread count" and "Email Notifier"
Uninstalled these 2 apps.
Deleted gmail.apk from systems/apps (made back up first) with Root Explorer
Renamed modded version from Tsjoklat to gmail.apk and copied to system/apps with Root Explorer and set permissions to rw-rwe-re
Rebooted.
Installed Sms Unread Count and Email Notifier again and it's working. No FC's yet.
don't need to use the patched version. do you only need to resign the gmail (original)
and resign all your mail based widgets (like "sms unread count", "email notifier", at all)
 

scorpio333

Member
Dec 5, 2010
7
0
0
in order to have widgets working with gmail 2.3.5 you only need to resign the gmail 2.3.5 and widgets.

actions:

- download original gmail 2.3.5 from the android market
- copy the apk to your pc
- resign with apkmanager (you don't need to make any change in manifest.xml)
- uninstall original gmail in your android
- install resigned gmail in your android

make the same actions with your widgets...

works fine with "sms unread notifications", "gmail notifier", etc.

note 1: note that this method prevents other applications to access to your messages :)
note 2: when the widgets or gmail are updated in market, you need to uninstall resigned app in order to update. next, make the same actions...
I can never do things the straight forward simple way. Let's say I've got a 2.3.5 transparent gmail.apk and I want to do the above, will that work? To further complicate things apkmanager always errors out on me, I've been using android-utility on Mac. When I try to sign the apk it wants to know what to use to sign it - test key or private key. I chose test key for the gmail.apk and it installed fine. Tried the same with Launcher Pro and it would not install. Am I overlooking something simple or is this a can of worms?
 
Last edited:

bartito

Inactive Recognized Developer
Dec 1, 2005
3,891
1,773
253
I can never do things the straight forward simple way. Let's say I've got a 2.3.5 transparent gmail.apk and I want to do the above, will that work? To further complicate things apkmanager always errors out on me, I've been using android-utility on Mac. When I try to sign the apk it wants to know what to use to sign it - test key or private key. I chose test key for the gmail.apk and it installed fine. Tried the same with Launcher Pro and it would not install. Am I overlooking something simple or is this a can of worms?
i have tried to resign gmail, sms unread count, gmail notifier and launcherpro with success. i don't have tried to modify the gmail, only resign. sorry, i don't known if is possible.
 

bromhexine

Senior Member
Sep 6, 2011
68
0
0
worked for me s5660

No problems here. I used root uninstaller to remove gmail. Did not see gmail.apk in system/app prior to doing this even though gmail was working. Then simply copied and renamed modified gmail file to system/app (not sure if that's needed) and ran it to install. It requested some sort of permission for gmail to read my emails. I then reinstalled the 3rd party application and everything was working. Thanks for the file!