[Droid Eris Android Development] MongooseHelix:
This is a modification to set the time the screen will stay awake when waking to the lockscreen from sleep, NOT the screen timeout, screen timeout delay, or screen turned off delay which can be changed through setttings. I started looking into this after someone asked in the Q&A forum if CM7 had an option to change this which it does not. The default timeout is 5 seconds, but if you would like the lockscreen to be shown for longer(or shorter) before the screen turns off again, follow this guide. If you'd like to change this but don't know if you can or want to, send me a PM and I'll try and make the mod for you to install or maybe I'll even learn how to put it into a flashable zip. This mod requires root!

After searching around for where this value is set, I came across a thread on another forum which led me to android.policy.jar but I still needed to know which smali/java file to edit. The Android source helped locate the setting and usage of this value in KeyguardViewMediator.java. Near the beginning the defaults are defined(10s if KB open & 5s otherwise):

/**
* The default amount of time we stay awake (used for all key input)
*/
protected static final int [COLOR="Green"][B]AWAKE_INTERVAL_DEFAULT_MS = 5000[/B][/COLOR];

/**
* The default amount of time we stay awake (used for all key input) when the keyboard is open
*/
protected static final int AWAKE_INTERVAL_DEFAULT_KEYBOARD_OPEN_MS = 10000;

However, in the decoded smali version of this file, changing the values in these definitions don't affect anything. That's why when we edit the smali file later, we change the value where the DEFAULT_MS variable is actually used in the pokeWakelock method:

public void pokeWakelock() {
pokeWakelock(mKeyboardOpen ?
AWAKE_INTERVAL_DEFAULT_KEYBOARD_OPEN_MS : [COLOR="Green"][B]AWAKE_INTERVAL_DEFAULT_MS[/B][/COLOR]);
}

----------------------------------------

I've only tested this on my Eris running GSB v3.1 - Gingerbread 2.3.4 - CM 7.1.0 RC0. Be sure to make a NAND backup and a backup of android.policy.jar as I can't guarantee this will work for you. If you have problems or just want to switch back to the original 5s timeout, replace the modified android.policy.jar with the backup, wipe cache & dalvik, and reboot or restore from the NAND backup you created.

So how does one go about modifying this wakeup timeout...

For Windows users, download APK Manager, extract it to your preferred location and then follow my step-by-step instructions in this post.

For Mac OSX and Linux users, download apktool from here. You will need both apktool*.tar.bz2 and your OS(linux/macos) specific dependencies(apktool-install-OS-*.tar.bz2). Unpack both and place those files(apktool.jar/apktool/aapt) in /usr/local/bin or wherever as long as it is in your PATH.

Now we need to get android.policy.jar off the phone and onto the computer. ADB is probably the easiest way:

adb pull /system/framework/android.policy.jar

Next, we want to decode android.policy.jar using apktool:

apktool d android.policy.jar out

If working correctly, apktool should say "I: Baksmaling..." & "I: Copying assets and libs...". It should also have created the directory "out" that contains "apktool.yml" and a "smali" directory.

Using your favorite text editor, open "out/smali/com/android/internal/policy/impl/KeyguardViewMediator.smali" as it contains the timeout value to modify. Look for ".method public pokeWakelock()V" and but be careful not to be looking at ".method public pokeWakelock(I)V" instead. The method should be near the end and starts at line 2864/3288 in mine. Inside the method there will be two lines starting with "const/16". The first represents AWAKE_INTERVAL_DEFAULT_KEYBOARD_OPEN_MS so we don't need to worry about it for the Eris. The hex value(0x####) in the second is the value for AWAKE_INTERVAL_DEFAULT_MS. The default interval is 5s = 5000ms = 0x1388. Since this value is a 16-bit signed integer value, the max value that can be set is 32767 which makes it a couple seconds over 30. If you change it to a value greater than the max, it will be interpreted as a negative value and your screen will not wake up...trust me, I tried. You can use this decimal to hex converter to determine the hex value you need to replace 1388. For example, 10s would be 0x2710 or 0x7530 for 30s. Make the change and save the file.

To build android.policy.jar with the modification:

apktool b out

If the build worked correctly, apktool will say "I: Checking whether sources has changed..." & "I: Smaling..." & "W: Could not find resources" & "I: Building apk file...". It should also create the directories "build" and "dist" inside of "out". The "dist" directory holds the modified android.policy.jar file.

The next step is signing the modified android.policy.jar with the testkey. Signing tools: Mac <> Phone <> Linux users can chime in on the easiest way(s) they've found.

All that's left is to replace the original with the mod:

adb remount #mounts system as r/w
adb push out/dist/android.policy-signed.jar /system/framework/android.policy.jar
adb shell chmod 644 android.policy.jar #permissions = rw-r--r--
adb reboot recovery
#wipe both cache & dalvik-cache
#reboot

Finished! Enjoy your new wake timeout :)