[HACK] Removing keyguard and other security policy restrictions from Email apk

Search This thread

rustyx3

Senior Member
Apr 25, 2009
199
411
This patch was originally created for Samsung Galaxy S II and Galaxy S III, but it might work for other devices* running Android 2.3 or 4.x because it patches the Email application that you have on your phone. This is not a pre-patched Email.apk.

* Motorola Blur (Droid), LG G2 and HTC Sense - based ROMs are not supported!

What does it do?

It will make the Email app ignore Exchange-pushed policy on your device, including things like mandatory pin lock (a.k.a. keyguard), minimum password length, encryption, etc.

How to apply this patch?

  1. Root your phone. Your phone must be rooted. It is impossible to apply this patch without root access. You need root to proceed.
  2. Get Java (Java SE JRE v7 or later)
  3. Get USB ADB drivers (for Samsung, install Samsung USB Drivers). Most likely you already have this because of step 1.
    Note - ADB via Wi-Fi is also supported. In that case no USB drivers are needed.
  4. Enable USB debugging on the phone (Settings->Applications->Development->USB debugging)
    * For CM9 users, also go to Settings > Developer Options > Root access, and select ADB.
  5. Download and unzip attached patch
  6. Run apply-patch.cmd or apply-patch.sh

Note 1: Although the Email app will prompt you for device admin access, it won't actually enforce any policy on your device. Let the app install the device admin!

Note 2: any shortcuts to the Email app as well as any Exchange accounts will disappear and will need to be re-created.

Note 3: The patch will reboot your phone, this is needed for the changes to take effect.

Note 4: If you already installed another Email application and it doesn't work, first restore your original Email application before applying this patch.

A Special Note to those experiencing performance issues! This is not an issue of my patch. This is an issue in the Email app itself. Sometimes calendar sync can't finish properly, causing battery drain. It often happens after you just added a new exchange account. A reboot usually solves this issue. Again, this is not my issue!

Change Log

4.6 - Added basic lollipop support (generic AOSP and CM, no Samsung, alpha, untested)
4.5 - More fixes for Android 4.3 and 4.4
4.4 - Minor release with fixes for KitKat 4.4
4.3 - Bugfix release (adb path errors)
4.2 - ...
4.2 - Bugfix release (IOException)
4.1 - Bugfix release (connection timeout bug fix)
4.0 - Improved ADB support for Mac and Linux (beta)
3.4 - JB 4.3 support (improved boot class path detection)
3.3 - JB 4.2 support (updated adb)
3.2 - Improved Jelly Bean support
3.1 - Added Jelly Bean support (alpha, do not use), minor optimization and cleanup
3.0 - Added Galaxy S III support
2.4 - Bugfix release
2.3 - Will now patch both Email.apk and Exchange.apk, added patch for ProvisionP****r.hasSupportablePolicy(), courtesy of boost252525
2.2 - added ICS isSupported() patch
2.1 - added support for EmailGoogle.apk
2.0 - New patch method based on patching SecurityPolicy's isActive() and isActiveAdmin()
1.1 - Fixed a bug with /system remounting
1.0 - Initial revision based on patching SecurityPolicy.PolicySet <init>


Did the patch work for you? Donations are welcome! :D
 

Attachments

  • email-policy-patch-4.4.zip
    1.4 MB · Views: 404
  • email-policy-patch-4.5.zip
    1.4 MB · Views: 135
  • email-policy-patch-4.6.zip
    1.4 MB · Views: 716
Last edited:
Dec 29, 2008
14
3
Already patch Email.apk

Your "How to install this patch "is a little to difficult for me.

Is it possible for you to supply an already patched Email.apk ?

In advance thanks
 
  • Like
Reactions: kheltek

has128

Member
Jul 19, 2003
27
9
Samsung Galaxy Z Flip 4
Thank You

Thanks so much for your effort. just want to get one thing clear, since you provided the patched Email.apk can i just install it directly, or do i need to be in recovery mode for example. because in your note you mentioned not to install!

Thanks again :)
 
  • Like
Reactions: deepak taneja

BackfireNL

Senior Member
Nov 11, 2009
603
59
Haarlem
Root explorer will also work! no ADB required!

1) Put Email.apk on your sdcard
2) Go to /system/app and press mount rw
3) remove Email.apk and Email.odex
4) move Email.apk from /sdcard/ to /system/app/

Then you need to setup your email again!
I had to clear the data also in applications -> email

Edit1:
your Email.apk is weird. When i reboot i get the notification that i need to set extra security. But when i press it nothing happends.

And after the email.apk the phone doesn't feel as smooth.. weird

Edit: removed Email.apk (modified) and wen't back to stock! phone is smooth again and works fine
 
Last edited:
  • Like
Reactions: syn3h

Fr4gg0r

Inactive Recognized Developer
Aug 4, 2010
698
679
May I ask why u use const/16 ?
const/4 goes from -8 to 8 (2^4) and should be preferred for small constants I think ;)
 

rustyx3

Senior Member
Apr 25, 2009
199
411
May I ask why u use const/16 ?
const/4 goes from -8 to 8 (2^4) and should be preferred for small constants I think ;)
const/4 has also a limited range of destination register numbers, and with the p-format in smali the mapping of p-registers to actual v-registers depends on the number of v-registers. It may happen that in the future more v-register are added, and an existing p-register does not fit in const/4 anymore. Using const/16 is thus more or less future proof. :D
 

salamt

Senior Member
Nov 8, 2008
132
8
This is awesome, it woks great :D

I am on KF1 and it works flawless push with no lag or so

I wonder what happened when we deleted the Email.odex and didn't replace it? we only replace the Email.apk
 

fscherz

Senior Member
May 12, 2011
118
14
At first to all, I used tool "FroyoMailUnlocker" to generate my new mail.apk and it worked fine for SGSII on 2.2.3 and also on GT7100 on Honeycomb 3.0.1.

Only problem is that after flashing new OS it need to be installed again.

Does anybody what settings should/can be saved to have an easier restore of the mailbox setup (for my exchange and hotmail accounts)?

Frank
 
  • Like
Reactions: Kisi78

CrackaBoi

Senior Member
Aug 7, 2008
51
1
This looks very interesting, but please help me figure out if it will solve my problem:

I have complete security enforced by my work Exchange account.
I need to sync email and calendar with that account.
I want to be able to set a timeout delay to the PIN lock engagement (now it is on immediately as the screen goes black), and it would be nice to use swipe unlock instead of PIN/password.

Will this hack do the trick for me? If so, even with calendar sync?

Thanks!

/Edit: I use the standard email app and calendar om my SGS2
 
Last edited:

steefen

Member
Oct 7, 2009
24
2
too bad

Hi,

in general I was searching for a long while for this!!!!
Now I have all done as decribed and once I try to create the exchange account it comes back with: "the server requires security settings which your phone dosn't support"

too bad...any ideas?

update:
now it's working...I'd to be patient..:)

THANK YOU VERY MUCH!!!!
 
Last edited:

CrackaBoi

Senior Member
Aug 7, 2008
51
1
Just to clarify the instructions here (I am noob):

After installing Android SDK, do I unzip the attachement on my PC or phone?
The shell commands, I type them in the adb shell with the phone in recovery mode, or what?

Thanks!
 

catastrat

Member
Nov 24, 2009
42
1
Bucharest
I've been using this hacked app in the past week or so, and it does great what it is supposed to do.
BUT: lately I wanted to see what is draining the battery so fast, and imagine the surprise when I saw that the biggest drainer by far is email.apk, far above the display itself, which is supposed to be the main consumer!!! :confused:

Is anyone else seeing this? Do you know about any resolution to this? For now, I just froze the application, but that's not acceptable, since one of the main uses of the phone is to sync up mail, calendar, etc with the corporate one.
 

CrackaBoi

Senior Member
Aug 7, 2008
51
1
I've been using this hacked app in the past week or so, and it does great what it is supposed to do.
BUT: lately I wanted to see what is draining the battery so fast, and imagine the surprise when I saw that the biggest drainer by far is email.apk, far above the display itself, which is supposed to be the main consumer!!! :confused:

Is anyone else seeing this? Do you know about any resolution to this? For now, I just froze the application, but that's not acceptable, since one of the main uses of the phone is to sync up mail, calendar, etc with the corporate one.

Do you have push enabled on the account? Try disabling it (setting it to a pull every 15 mins for example).

I had the same issue (without this hack though!) on one of my Exchange accounts, and not using push fixed the issue. It must be an Exchange provider issue, because my work account uses push with no issues.
 

catastrat

Member
Nov 24, 2009
42
1
Bucharest
I don't use push - I have it set for every 1h check during the workday and every 12h for off hours.
I even have disabled all notifications from it...
 

CrackaBoi

Senior Member
Aug 7, 2008
51
1
I don't use push - I have it set for every 1h check during the workday and every 12h for off hours.
I even have disabled all notifications from it...

Hmm I see. Well, if this hack introduces another possible battery draining culprit, I'm not so sure I want to try it. I've spent too much time identifying battery draining apps/processes on my new phone already.

Has anyone else experienced email.apk battery drain after applying this hack?
 

rustyx3

Senior Member
Apr 25, 2009
199
411
There are many factors that may cause a slowdown, which I have no way to reproduce. I can only say that my company's Exchange server is 2003 and that it is the only non-google mail account that I have configured on my phone. I have push enabled. The hack works great with this setup, i.e. no slowdown of the phone, no extra battery drain.

If someone who is experiencing issues can post more details about the version of exchange, sync mode, and any other pop/imap mail accounts configured, I may be able to investigate the issue further.
 
  • Like
Reactions: zyxeu

ecefrm

Member
Apr 8, 2011
7
1
If someone who is experiencing issues can post more details about the version of exchange, sync mode, and any other pop/imap mail accounts configured, I may be able to investigate the issue further.

I am running your modded Email.apk in a Galaxy Tab with Gingerbread (Overcome Hermes) and I have no problems with slowdowns or battery drain either. However I am always getting a FC from the mail application when rebooting the Tab. Afterwards it works correctly. I guess it's natural since it is not the native mail application.

I have tried to mod myself the native Gingerbread Email.apk from the Galaxy Tab using your posted code, but it does not work (FC continuously). Although very similar to the Galaxy S II mail application, there must be some differences that make it impossible to just blindingly use your modifications.

Would you be so kind as to have a look at the original Email.apk from the Tab Gingerbread Overcome firmware and suggest a possible mod? Thanks in advance.
 

Attachments

  • Email_Tab.apk
    6.5 MB · Views: 175

Top Liked Posts

  • There are no posts matching your filters.
  • 298
    This patch was originally created for Samsung Galaxy S II and Galaxy S III, but it might work for other devices* running Android 2.3 or 4.x because it patches the Email application that you have on your phone. This is not a pre-patched Email.apk.

    * Motorola Blur (Droid), LG G2 and HTC Sense - based ROMs are not supported!

    What does it do?

    It will make the Email app ignore Exchange-pushed policy on your device, including things like mandatory pin lock (a.k.a. keyguard), minimum password length, encryption, etc.

    How to apply this patch?

    1. Root your phone. Your phone must be rooted. It is impossible to apply this patch without root access. You need root to proceed.
    2. Get Java (Java SE JRE v7 or later)
    3. Get USB ADB drivers (for Samsung, install Samsung USB Drivers). Most likely you already have this because of step 1.
      Note - ADB via Wi-Fi is also supported. In that case no USB drivers are needed.
    4. Enable USB debugging on the phone (Settings->Applications->Development->USB debugging)
      * For CM9 users, also go to Settings > Developer Options > Root access, and select ADB.
    5. Download and unzip attached patch
    6. Run apply-patch.cmd or apply-patch.sh

    Note 1: Although the Email app will prompt you for device admin access, it won't actually enforce any policy on your device. Let the app install the device admin!

    Note 2: any shortcuts to the Email app as well as any Exchange accounts will disappear and will need to be re-created.

    Note 3: The patch will reboot your phone, this is needed for the changes to take effect.

    Note 4: If you already installed another Email application and it doesn't work, first restore your original Email application before applying this patch.

    A Special Note to those experiencing performance issues! This is not an issue of my patch. This is an issue in the Email app itself. Sometimes calendar sync can't finish properly, causing battery drain. It often happens after you just added a new exchange account. A reboot usually solves this issue. Again, this is not my issue!

    Change Log

    4.6 - Added basic lollipop support (generic AOSP and CM, no Samsung, alpha, untested)
    4.5 - More fixes for Android 4.3 and 4.4
    4.4 - Minor release with fixes for KitKat 4.4
    4.3 - Bugfix release (adb path errors)
    4.2 - ...
    4.2 - Bugfix release (IOException)
    4.1 - Bugfix release (connection timeout bug fix)
    4.0 - Improved ADB support for Mac and Linux (beta)
    3.4 - JB 4.3 support (improved boot class path detection)
    3.3 - JB 4.2 support (updated adb)
    3.2 - Improved Jelly Bean support
    3.1 - Added Jelly Bean support (alpha, do not use), minor optimization and cleanup
    3.0 - Added Galaxy S III support
    2.4 - Bugfix release
    2.3 - Will now patch both Email.apk and Exchange.apk, added patch for ProvisionP****r.hasSupportablePolicy(), courtesy of boost252525
    2.2 - added ICS isSupported() patch
    2.1 - added support for EmailGoogle.apk
    2.0 - New patch method based on patching SecurityPolicy's isActive() and isActiveAdmin()
    1.1 - Fixed a bug with /system remounting
    1.0 - Initial revision based on patching SecurityPolicy.PolicySet <init>


    Did the patch work for you? Donations are welcome! :D
    14
    For those who are interested in the source code of this patch, here it is.
    https://github.com/rustyx/email-policy-patch
    9
    Working with new Lollipop Gmail 5.0 and AOSP Exchange 5.0 (on Xperia Z)

    I got it working today with the new Lollipop Gmail 5.0 and AOSP Exchange 5.0.

    I have the very first Lollipop non-Nexus ROM on my Xperia Z and after getting root the first thing I tried was this hack which I can't live without - I wanna decide on my own how complex my device should be locked.

    However, the the patch in version 4.3 works flawlessly if one knows where to find the APKs.

    Note: I've tested this just on my Xperia Z. I assume it will work on other Lollipop systems as well, but no promises...

    So here is the content from my console window when patching the files. Please also note that I just did the "remote patch", could not get it working with the files copied locally and the patch applied manually.

    AOSP Email 5.0
    The trick is to submit the (relative) sub-directory paths where the single system APKs are located, e.g. /system/app/Email/Email.apk.
    Code:
    C:\Users\mcfisch\Android\email-policy-patch-4.3> apply-patch.cmd
    Cleaning up ...
    Found adb on PATH.
    Waiting for USB connection...
    Checking device...
    Model: Full Android on C6603, build full_c6603-userdebug 5.0 LRX21M eng.thomas.20141109.175337 test-keys, android 5.0 (API Level 15)
    /system mounted on /dev/block/platform/msm_sdcc.1/by-name/system, mode ro
    checking root access. root uid: 0, secure: no, busybox: yes
    Can't detect boot class path. Using defaults...
    Pulling app(s) ...
    Can't find Email app. Enter the name of your Email apk or press <Enter> to exit: Email/Email.apk
    Can't find Exchange app. Enter the name of your Exchange apk or press <Enter> to continue: Exchange2/Exchange2.apk
    Pulling libs ...
    Decompiling Email/Email.apk ...
    Applying patch ...
    Patching com/android/emailcommon/provider/Policy.normalize()V
    Recompiling ...
    Building Email/Email.patched.apk ...
    Decompiling Exchange2/Exchange2.apk ...
    Applying patch ...
    Patching com/android/emailcommon/provider/Policy.normalize()V
    Patching com/android/exchange/adapter/ProvisionParser.hasSupportablePolicySet()Z
    Recompiling ...
    Building Exchange2/Exchange2.patched.apk ...
    Updating device ...
    Rebooting device ...
    Done.
    
    NOTES! PLEASE READ!
    
    * All shortcuts to the Email app will disappear and will need to be re-created.
      The Email app icon will move towards the end of the application list.
    
    
    Drücken Sie eine beliebige Taste . . .

    Gmail 5.0 + GmailExchange 5.0

    With Gmail 5.0 Google introduced the ability to handle Microsoft Exchange accounts within the Gmail app. Therefore they deliver an additional Exchange connector for Gmail, which is separated from the AOSP Exchange2 service. Here we additionally now need to know the name of these new APKs, find them e.g. by typing ls -l /system/app in an ADB shell.

    • PrebuiltGmail/PrebuiltGmail.apk
    • PrebuiltExchange3Google/PrebuiltExchange3Google.apk

    Code:
    C:\Users\mcfisch\Android\email-policy-patch-4.3> apply-patch.cmd
    Cleaning up ...
    Found adb on PATH.
    Waiting for USB connection...
    Checking device...
    Model: Full Android on C6603, build full_c6603-userdebug 5.0 LRX21M eng.thomas.20141109.175337 test-keys, android 5.0 (API Level 15)
    /system mounted on /dev/block/platform/msm_sdcc.1/by-name/system, mode ro
    checking root access. root uid: 0, secure: no, busybox: yes
    Can't detect boot class path. Using defaults...
    Pulling app(s) ...
    Can't find Email app. Enter the name of your Email apk or press <Enter> to exit: PrebuiltGmail/PrebuiltGmail.apk
    Can't find Exchange app. Enter the name of your Exchange apk or press <Enter> to continue: PrebuiltExchange3Google/PrebuiltExchange3Google.apk
    Pulling libs ...
    Decompiling PrebuiltGmail/PrebuiltGmail.apk ...
    Applying patch ...
    Unable to apply patch. Code to patch not found.
    Decompiling PrebuiltExchange3Google/PrebuiltExchange3Google.apk ...
    Applying patch ...
    Patching com/android/emailcommon/provider/Policy.normalize()V
    Patching com/android/exchange/adapter/ProvisionParser.hasSupportablePolicySet()Z
    Recompiling ...
    Building PrebuiltExchange3Google/PrebuiltExchange3Google.patched.apk ...
    Updating device ...
    Rebooting device ...
    Done.
    
    NOTES! PLEASE READ!
    
    * All shortcuts to the Email app will disappear and will need to be re-created.
      The Email app icon will move towards the end of the application list.
    
    
    Drücken Sie eine beliebige Taste . . .

    Ignore the warning about not being able to patch Gmail itself - it isn't necessary. Just the patch needs it when remotely applied.

    I've set up both patched applications with my company related Exchange account for testing and both are working flawlessly. :D
    I'll stick with the Gmail app for now just to see how it goes, but may recreate the account in the AOSP Email app later if not satisfying.

    Many thanks to the OP for making this possible! :)
    5
    ******Warning! Follow these instructions at your own risk. I am not responsible for any damage done to your phone*********

    Just got this working on my GS4 and .........

    I got this working great on my i9505 S4 with the most recent 4.3 UK release / BTU XXUEMJ7 (which I rooted) from 15th October, thanks to mmulq.

    I've put my patched apks at http://d-h.st/U60

    Remember to
    - Remove any exchange accounts you have already configured
    - Clear all app data for email and exchange
    - use Root Explorer or similar in /system/app to rename the existing SecExchange.apk / .odex and SecEmail_J.apk / .odex files (e.g. add an extra ".backup" to the end of the name)
    - copy in the new patched apk files to the same location
    - reboot

    If these patched apks don't work for you, please don't come asking me why - I just followed the instructions and it came good.


    Again thanks to mmulq for the easy to follow instructions - the only thing I'd add is all the files in /system/framework need to be copied into workdir, not into workdir/framework. I think it was me not quite following the instructions verbatim :)
    5
    May I ask why u use const/16 ?
    const/4 goes from -8 to 8 (2^4) and should be preferred for small constants I think ;)
    const/4 has also a limited range of destination register numbers, and with the p-format in smali the mapping of p-registers to actual v-registers depends on the number of v-registers. It may happen that in the future more v-register are added, and an existing p-register does not fit in const/4 anymore. Using const/16 is thus more or less future proof. :D