[G4 Android Development] shbang:
So I was wondering why my battery kept draining overnight when the phone was supposed to be asleep. I opened up BetterBatteryStats and found this goddamn WifiOffDelayIfNotUsed wakelock keeping my phone awake all the time. I didn't have 1 min of deep sleep time unless I turned wifi off. I looked up some information on this and finally found a post by [MENTION=4088197]metalboy94[/MENTION] detailing a simple framework modification to get rid of this. I went through all the steps here and the other page with a few modifications. I installed the new wifi-service.jar framework, and my phone has had hours of deep sleep now. My battery level stays the same for hours now when the screen is off.

I'm not sure if other people are suffering from this battery draining wakelock, but if your battery is draining with the screen off, I'd go ahead and check BetterBatteryStats or GSam Battery Monitor to see if you have this wakelock. In android's battery monitor, it gets blended in with Android System or Android OS, pushing one of them up to 20-30% in battery consumption.

This new wifi-service framework is made from a Verizon VS986 11a phone, but the process I went through should work on all G4s and other phones as well, and I'm willing to make a modded framework for other G4s if necessary and desired. I only need two files: /system/framework/arm/boot.oat and /system/framework/arm/wifi-service.odex.

I didn't bundle this in a nice installer since the VS986 doesn't have TWRP yet, but the installation is just one file along with the backup and removal of a few files (I'll make a twrp installer for H815 folks who are interested and supply the two files I need). I attached a zip containing the framework. I'll go through all the steps you need to do after downloading it. This should really be installed using adb. Use terminal emulator if you must and definitely not a slow and dangerous file manager. (If something goes wrong and you get into a bootloop, you'll want to be in adb since the terminal doesn't close. While in a hypothetical bootloop, you can use adb to undo the installation. I've done this a lot testing out stuff; it's pretty reliable. You can also reflash the rooted system.img in download mode assuming it's on your phone. That's a worst case scenario.) If you don't have busybox, skip the unzip step, and use a file manager to extract the framework to /sdcard/Download. So after you download the attached zip file, follow these steps in adb. You can copy the whole thing and paste it in with terminal emulator or via adb on Linux. Window's excuse for a terminal might throw a fit. Just don't enter the last command unless all others were successful.

su
cd /sdcard/Download
unzip wifi-service.zip
mount -o remount,rw /system
cp wifi-service.jar /system
cd /system
chown 0:0 wifi-service.jar
chmod 0644 wifi-service.jar
cp framework/wifi-service.jar framework/wifi-service.jar.bak
cp framework/arm/wifi-service.odex framework/arm/wifi-service.odex.bak
cp framework/arm64/wifi-service.odex framework/arm64/wifi-service.odex.bak
mount -o remount,rw /system
cp -f wifi-service.jar framework; rm framework/arm/wifi-service.odex; rm framework/arm64/wifi-service.odex

At this point, your phone may hot reboot or not. Reboot it if it doesn't(or execute "svc power reboot" in adb if you're lazy). The phone needs to reboot to odex the new framework. That's it. You can check to see if the WifiOffDelayIfNotUsed wakelock is still plaguing your phone. It isn't, so enjoy some better battery life.

:EDIT:

I uploaded a TWRP flash installer and uninstaller for the H815. Thanks for posting those files [MENTION=591743]stuliv12[/MENTION]. Let me know if this works. I tested the installation and uninstallation on my Nexus 4 just to make sure they worked in TWRP. (The files are named, so I didn't include a "ro.product.model" check in the update-binary.)

That's great [MENTION=3730004]mawells787[/MENTION] found a solution that I suggest trying first before flashing this. For me though, I was getting the wakelock when my wifi connection was great (full wifi bars, 4 meters from router), and it just wouldn't go away even when I turned on "Avoid bad Wi-Fi connections."