[Galaxy S II General] claimui:
WARNING: This is an extremely crude hack and I do not really know what it does. It could very well destroy your Exchange folders or worse. Please make backups and do not use this hack with any important email accounts, Exchange or otherwise!

---

Tl;dr summary: I removed EASSyncService.smali from the stock Samsung Email.apk and replaced it with the EASSyncService.smali from jakubklos' AOSP email wakelock fix. I did not edit the smali code or have access to Samsung sources, so this is a very crude hack and there are some bugs. I'm hoping people can expand on this work and come up with a better solution. All credits to jakubklos for the fix; any bugs are the result of this hack and not jakubklos' work.

---

In this thread, jakubklos identified and fixed a battery drain bug in the AOSP Email app. This bug causes the Email app to not release a partial wakelock in some cases when syncing with a Microsoft Exchange account. The result is a battery drain until you restart the phone or regain the connection. See the linked thread for more details.

The bug fix is just a very simple change to EASSyncService.java, but it required editing the source code and recompiling the Email app. This change has already been merged into CyanogenMod and Google should be putting it in future versions of Android.

The Galaxy S II comes with a different version of Email.apk. It is similar to AOSP, but generally the Samsung Email.apk is a "better" version of the AOSP Email.apk. The Samsung Email.apk has some extra features like peak/off-peak sync scheduling, and an option to force emails to display in white text with black backgrounds (my favorite feature -- easier on my eyes and saves some power on the AMOLED screen).

Although the source code for the AOSP Email.apk is available, the code for Samsung's Email.apk is not. (At least as far as I know; please let me know if I am wrong.) So we can't directly use jakubklos' method of editing the source and recompiling the app.

However when I opened up Samsung's Email.apk, I noticed it had basically the same .smali files as the AOSP Email.apk. Yes, there are differences, but I figured that the EASSyncService.smali in the Samsung app probably does basically the same thing as EASSyncService.smali in the AOSP app. Understanding and editing smali is way beyond my abilities. So my hack was simply to replace the EASSyncService.smali from the stock Email.apk with the EASSyncService.smali from the fixed AOSP Email.apk.

Result: It's not a perfect fit. I get occasional force closes and other random errors. But for the most part, it seems to work, and my Email wakelocks are lower. Note that this bug affects me a *lot* because my Exchange server at work is really ghetto and constantly unreachable. If you have an Exchange server running at real corporate standards without much downtime, then this bug probably does not affect you and you will not notice any improvements.

Despite the occasional crashes, this is "good enough" that I am using it for my daily use. I am sharing the app below so others can test it out. But be warned, this is for experimenting only. I really have no idea what EASSyncService does and what the differences are between the Samsung EASSyncService and the AOSP EASSyncService, so I cannot guarantee that it will not trash your Exchange folders or worse. Do not use this with any email accounts that are of any value whatsoever!

Eventually I hope somebody can come up with a better solution, either by editing the .smali code, or getting Samsung sources and recompiling the app, or something else.

---

Installation instructions (requires root):

- Backup your stock Email.apk.

- Delete your email accounts and clear all email data.

- Uninstall your stock Email.apk.

- Download the "Email.apk" attached below. Copy to your /system/app folder.

- Reboot your phone.