[Captivate Q&A, Help & Troubleshooting] jahfry:
I'm a Samsung Captivate user with the stock AT&T Froyo 2.2 ROM, rooted. After some playing around I think I have atomic reproducible steps for trimming out the Exchange security policies. Removed my post in the other thread on this and posting in the Captivate forum.

NOTE: I included the steps for BUILDING this APK (primarily for other phones that are similar but not identical), but many people won't want that. If you are only interested in using my pre-built .APK file, skip down to "II. INSTALLING the modified Email.apk". Download link provided there. You must still have rooted your phone and have a working busybox install (I usually just use Titanium Backup to fix my busybox install the first time after rooting).

As always, this is at YOUR own risk. YOU take responsibility for the fact you may be violating your corporate email policies.

CREDITS:

Initial thread giving me hints

This post for giving extra info on how to handle odexed APKs

This thread giving me the final clue on disabling the check

Smali/Baksmali project for deodexing and re-odexing files

NOTE: I don't actually know if the second code change (as shown below) was necessary or not. I did this change first and after it I still had to accept the security policy, delete the policy after email configuration, and I still got notifications about needing to accept the security policy every time I read mail (even though I didn't actually accept the policy again). To really make the APK work I had to add the first change below. However the APK is working for me so I'm going to keep it in there.

I. BUILDING the modified Email.apk on a Samsung Captivate Froyo 2.2 stock ROM using Windows 7

I tried to make the instructions detailed enough that you can do this on other builds, too. If you are using a custom ROM, chances are good you won't have an Email.odex file, which will significantly slim down the steps needed.

The first 2 items are left as exercises for the reader since they are well documented elsewhere.

root your phone and get busybox installed/working

get adb running in an otherwise empty subdirectory (I used "deodex")

grab a copy of baksmali and smali from http://code.google.com/p/smali/downloads/list

... make sure java is in your %PATH% as documented on the Smali site

NOTE: the following commands are run from your "cmd" window:

`adb pull /system/framework`

`adb pull /system/app/Email.apk`

`java -jar baksmali.jar -c:twframework.odex -x Email.apk`

... Samsung default ROM uses touchwiz, so we needed to include it for baksmali (note: leave out the "-c:twframework.odex" for AOSP-based ROMs like CM7)

... output of the odex should be in a new subdirectory

Edit "out\com\android\email\SecurityPolicy$Policy.smali (note, on CM7 and probably AOSP this is SecurityPolicy.smali)

... Find the line with "const/4 v5, 0x0" in it (for the Captivate APK it was line 641) in the ".method public isActive" section

... Replace "0x0" in that line with "0x1".

Edit "out\com\android\email\SecurityPolicy$PolicyAdmin.smali

... replace the contents of the "onDisabled" section with the contents of the "onEnabled" section

Original code:

.method public onDisabled(Landroid/content/Context;Landroid/content/Intent;)V
.registers 5
.parameter "context"
.parameter "intent"

.prologue
.line 647
invoke-static {p1}, Lcom/android/email/SecurityPolicy;->getInstance(Landroid/content/Context;)Lcom/android/email/SecurityPolicy;

move-result-object v0

const/4 v1, 0x0

invoke-virtual {v0, v1}, Lcom/android/email/SecurityPolicy;->onAdminEnabled(Z)V

.line 648
return-void
.end method

New Code

.method public onDisabled(Landroid/content/Context;Landroid/content/Intent;)V
.registers 5
.parameter "context"
.parameter "intent"

.prologue
.line 639
invoke-static {p1}, Lcom/android/email/SecurityPolicy;->getInstance(Landroid/content/Context;)Lcom/android/email/SecurityPolicy;

move-result-object v0

const/4 v1, 0x1

invoke-virtual {v0, v1}, Lcom/android/email/SecurityPolicy;->onAdminEnabled(Z)V

.line 640
return-void
.end method

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

Using something like 7zip, open the "Email.apk" file and add your new "classes.dex" to the apk

II. INSTALLING the modified Email.apk

NOTE: If you chose to download my modified Email.apk, grab it here. You must still have rooted your phone and have a working busybox install (I usually just use Titanium Backup to fix my busybox install the first time after rooting).

NOTE: Next steps can be altered to fit your preferred method for removing and uploading the Email.apk. The important part is to make sure you delete "/system/app/Email.apk" and "/system/app/Email.odex", then push your new Email.apk to /system/app ... my steps follow.

NOTE: THE FOLLOWING IS GOING TO GET SPECIFIC TO THE SAMSUNG CAPTIVATE RUNNING STOCK FROYO 2.2, modify the shell commands to fit YOUR device.

from Windows command shell again: `adb push Email.apk /mnt/sdcard`

Force Email to stop (Settings -> Applications -> Manage Applications -> All -> Email -> Force Stop) ... while you're in there you may want to "Clear Data". Not sure if this was important or not.

Load your adb shell via "adb shell". The following commands are to be run directly in your adb shell:

`su` # become superuser

`mount` # see which partition YOUR /system is and use it in the next command if different!

`mount -o rw,remount -t yaffs2 /dev/block/stl9 /system` # /dev/block/stl9 may differ for you! NOT st19, stl9. Remounts writeable

`cp /system/app/Email.odex /mnt/sdcard/Email.odex-ORIGINAL` # back up your files just in case

`cp /system/app/Email.apk /mnt/sdcard/Email.apk-ORIGINAL`

`rm /system/app/Email.odex`

`rm /system/app/Email.apk`

`cp /mnt/sdcard/Email.apk /system/app` # copy the file from the sdcard, had failures when trying to push directly to /system/app

`chmod 644 /system/app/Email.apk` # give it normal APK permissions

`rm /mnt/sdcard/Email.apk` # remove from the temp location

`mount -o ro,remount -t yaffs2 /dev/block/stl9 /system` # remount to read-only

`exit` # get out of su

`exit` # get out of the shell

Add your Exchange account as normal.

NOTE: You will get a message saying you have to accept the server security policy, however I did not actually have to do so.

OPTIONAL: Add the "Email" icon back to the touchwiz launcher (unless you'd rather use something else):

Applications -> {Context menu} -> View Type -> "Customizable Grid"

{Context menu} -> Edit

Drag the Email icon down to the launcher bar where it used to be (or customize it with something else ... only the middle 2 launcher icons are configurable, Phone and Applications/Home will be locked)

{Context menu} -> Save

OPTIONAL: Switch back to Alphabetical List or Alphabetical Grid via the "View Type" setting.

To be sure you have things working, it is a good idea to reboot. See note below.

NOTE: Originally I had a few random shutdowns after finishing the above, might be unrelated (I'm a little worried I got -another- phone with that problem after warranty replacement). They went away after I did a battery removal and charged to 100% before powering on. If you get a random shutdown, do this. However I'm not adding this as a required step since I was later able to upgrade without even needing a reboot. It may have been something that corrupted when removing the initial .odex file, which was not needed as I kept testing new versions.