[MOD][KERNEL] Touch Wake

Search This thread

Ezekeel

Retired Recognized Developer
Jun 21, 2011
715
1,680
Last week I have released the Screen Dimmer kernel modification. While the feedback was very positive, it became clear that this mod had the limitation that the FLAG_KEEP_SCREEN_ON (set in apps, which prevents the screen lock from activating) was not preventing Screen Dimmer from blanking the screen. So if you wanted to watch a movie and did not want the screen to be dimmed all the time, you had to manually deactivate the Screen Dimmer for this period and re-enable it afterwards. Also the battery drain while the screen was dimmed was much higher compared to a proper screen lock, since only the display and the access to the framebuffer was disabled - the other hardware was still enabled and most importantly the Android OS and the apps were still running.

I thought that I could do better than that and tried to find a way to achieve the same what Screen Dimmer was doing without running into its limitations. Since the Android OS power manager handles the FLAG_KEEP_SCREEN_ON and also suspends the OS and running apps on a screen lock, I thought why not letting the power manager do its jobs and just prevent the touch controls (screen and keys) from suspending. Then one could wake the device from screen lock by emulating a power button press on touch. After a user defined delay after screen off the touch controls also get suspended. The only complication was to monitor the power button, so one can differentiate between screen timeouts, for which the touch controls should be kept enabled for a certain time, and a screen lock manually triggered by the user by pressing the power button, for which the touch controls should be disabled right away.

So with Touch Wake, one can wake the device from suspend (for a certain user-defined time after screen off) by touching the touchscreen or the touchkeys. Combined with a OS level tweak which disables the lock screen on timeout for a certain time or altogether (for example in CM 7.03, but also available as standalone apps from the Market), one can achieve the same functionality as Screen Dimmer. Compared to Screen Dimmer, Touch Wake has the advantage that the screen will not be blanked as long as the FLAG_KEEP_SCREEN_ON is set and also the battery drain while the screen is off will be significantly less because only the touch controls are kept enabled and the Android OS and running apps are properly put to sleep. For the record, with Touch Wake, while the touch controls are still enabled, the kernel is kept in a wake lock, so the battery drain will still be a little higher than for the normal stock screen lock, however it is a significant improvement over Screen Dimmer.

To enable (disable) wake on touch pass 1 (0) to 'enabled' in /sys/class/misc/touchwake. Pass the delay (until the touch controls will be disabled after screen off) in ms (this is milliseconds; 1000ms = 1s) to 'delay'; a value of 0 for the delay means the touch controls will be kept enabled indefinitely. The default state is disabled and a delay of 45000 = 45s.


Changes to the source (based on kernel with BLD 3 and Screen Dimmer 1):
http://www.pastie.org/2445282


BUGFIX:

Fixed BLN not working properly anymore.

Bug fix: http://www.pastie.org/2446398


BUGFIX #2:

Fixed the problem with the proximity sensor not reactivating the screen when making calls. Also, since I was in the neighborhood I also fixed the problem with BLD on the i9023.

Bug Fix: http://www.pastie.org/2457092


BUGFIX #3:

I cleaned up the code a bit for all three mods BLD, Screen Dimmer and Touch Wake.

Bug fix: www.pastie.org/2488785


BUGFIX #4:

Fixed the BLD problem for the i9023 of the touchkey backlights not being re-enabled on touchkey press.

Bug fix: http://www.pastie.org/2499956


BUGFIX #5:

Fixed the problem of the touch controls misbehaving after the proximity sensor has blanked the screen during a call.

Bug fix: http://www.pastie.org/2528577


BUGFIX #6:

Fixed the problem with BLD on the i9023 of the touchkey backlights getting activated when the bottom of the touchscreen was touched.

Bug fix: http://www.pastie.org/2544546


BUGFIX #7:
For Touch Wake, call the suspend function a bit earlier to prevent a rare hiccup happening when the touch controls are pressed in exactly the same moment the screen is disabled.

Bugfix: http://www.pastie.org/2641540


BUGFIX #8:
For BLD, Screen Dimmer and Touchwake, use mutex_trylock instead of mutex_is_locked/mutex_lock combo to avoid race conditions.

Bugfix: http://www.pastie.org/2710096


No further patches will be published here. I have set up a git repo for all my tweaks. Each mod has its own branch to keep the tweaks cleanly separated and one can simply pull the latest patches from the corresponding branch.

https://github.com/Ezekeel/GLaDOS-nexus-s/tree/touchwake



Get Jonathon Grigg's 'Spark Mod Manager' GUI for controlling Touch Wake: http://xdaforums.com/showthread.php?p=17291034


I do not accept donations and since I reached my 50GB limit of free space on SpiderOak, thanks to all of you kind people who got an account using my referral link, I could not ask for more.
Instead if you really want to donate your hard earned money to someone who deserves and needs it, consider donating to the Free Software Foundation at fsf.org: These guys are at the frontline when it comes to keeping Linux free and fighting these greedy bastards who think they are entitled to collect royalties and other fees from Linux users due to some silly patents - and if Linux falls, Android will be next.
 
Last edited:

reddv1

Senior Member
Sep 16, 2009
733
452
Torrance, CA
Does this depend on screen dimmer code? Cause I'd like to maybe remove screen dimmer and just have this mod.

Also, thanks for putting all this time on these mods. Love your work.

Sent from my Nexus S using xda premium
 

Ezekeel

Retired Recognized Developer
Jun 21, 2011
715
1,680
The patch file I have provided is for a kernel already including BLD 3 and Screen Dimmer 1 (+ all bugfixes), but the code of Touch Wake does not depend on either Screen Dimmer or BLD - so you can enable BLD, Screen Dimmer and Touch Wake independently from each other in the kernel config and also could remove one tweak entirely from the kernel source if you want.
 
  • Like
Reactions: morfic

Enhanced

Senior Member
Sep 18, 2010
1,141
279
This sounds amazing.

Probably the biggest "mod" to our phones since BLN.

If the battery drain isn't terrible with this mod, I think you have a winner on your hands.

Goodjob. :)

EDIT: Think you should make an app that allows users to easily change the values. I could see this catching on as much as BLN has.
 
Last edited:

rejanmanis

Senior Member
Feb 17, 2011
453
63
Jakarta
Can you stop copy pasting this "couldn't reach morfic"
That would be awesome.
Sent from my Nexus S using Tapatalk

I think those are deleted already. lol.

cool stuff.

so... I presume, when the screen dimmed. the crt animation will appear as well ? :cool:

and to mr simms and mr reddv1 , can i have ur test kernel included this TouchWake MOD for any ROM since i used MIUI ROM
 
Last edited:

nbeebe24

Senior Member
Jun 16, 2009
2,464
923
Sounds like an awesome mod

Sent from my Nexus S using XDA App
 
Last edited:

Ezekeel

Retired Recognized Developer
Jun 21, 2011
715
1,680
Yeah, they both needed modifying of include/linux/input.h and instead of having two patch files in two different threads which would need to be applied in a certain order I decided to simply make one patch for both problems and put it in this thread. It does not make a difference for you guys and if later people want to include this in their kernel they probably simply pull the up-to-date files from my git instead of applying these gazzilion patches one after each other.

Hope this really fixes the problem with the i9023. I had to guess what the problem was and if this does not solve it, I am all out of ideas. Unfortunately, I do not know anyone with a i9023 I could borrow. The next best thing would be to get someone on gtalk or similar with a i9023 who is willing to go through a painful process of flashing a test kernel with debug statement and passing the logs on to me, then wait until I have compiled the next test kernel... rinse and repeat - lets say about ten times. Not really looking forward to this.
 

kecinzer

Senior Member
Jul 1, 2007
1,857
1,621
Decin
kecinzer.cz
If it will be nessecary I can help on Google Talk. But I'm not capable to compile kernel. If we go for this, you have to send me flashable zip :)
 

Enhanced

Senior Member
Sep 18, 2010
1,141
279
Using Touch Wake right now with the Lucid kernel and it works perfectly.

Not sure if this is possible, but here's my idea:

Is it possible to somehow wake the phone through touching the touch keys when BLN is active (as in touch keys are on)?

I thought of this as you said that the touch keys (and screen) are not suspended when Touch Wake is active. So now I'm going further to assume that maybe the touch keys are also not suspended when BLN is active so that maybe it can be coded to allow touching the keys to wake the phone?

I know nothing about programming so I may be talking out of my ass here but just an idea.

Thanks!
 

reddv1

Senior Member
Sep 16, 2009
733
452
Torrance, CA
I think I found a bug with Touch Wake. I'm on 9020, with latest touch wake bugfixes.

After the screen goes off and the touch wake timer has passed, if I touch the soft keys they light up and stay lit while the phone sleeps. I tried to grab a logcat with the phone plugged in to my PC, but the bug can't be replicated while the phone is plugged in.

Sent from my Nexus S
 

Maximilian Mary

Senior Member
Jan 16, 2011
885
283
Wisconsin
I think I found a bug with Touch Wake. I'm on 9020, with latest touch wake bugfixes.

After the screen goes off and the touch wake timer has passed, if I touch the soft keys they light up and stay lit while the phone sleeps. I tried to grab a logcat with the phone plugged in to my PC, but the bug can't be replicated while the phone is plugged in.

Sent from my Nexus S

It seems having bln installed (and disabled for me) solves this
 

Ezekeel

Retired Recognized Developer
Jun 21, 2011
715
1,680
Using Touch Wake right now with the Lucid kernel and it works perfectly.

Not sure if this is possible, but here's my idea:

Is it possible to somehow wake the phone through touching the touch keys when BLN is active (as in touch keys are on)?

I thought of this as you said that the touch keys (and screen) are not suspended when Touch Wake is active. So now I'm going further to assume that maybe the touch keys are also not suspended when BLN is active so that maybe it can be coded to allow touching the keys to wake the phone?

I know nothing about programming so I may be talking out of my ass here but just an idea.

Thanks!

I would be possible, however this could lead to the possible problem of accidentally unlocking the device when you carry it around in a pocket and get a notification. I do not think it is worth the trade-off


I think I found a bug with Touch Wake. I'm on 9020, with latest touch wake bugfixes.

After the screen goes off and the touch wake timer has passed, if I touch the soft keys they light up and stay lit while the phone sleeps. I tried to grab a logcat with the phone plugged in to my PC, but the bug can't be replicated while the phone is plugged in.

Sent from my Nexus S

I cannot reproduce the problem with my reference kernel. Does it happen every time you try it?
 

Top Liked Posts

  • There are no posts matching your filters.
  • 45
    Last week I have released the Screen Dimmer kernel modification. While the feedback was very positive, it became clear that this mod had the limitation that the FLAG_KEEP_SCREEN_ON (set in apps, which prevents the screen lock from activating) was not preventing Screen Dimmer from blanking the screen. So if you wanted to watch a movie and did not want the screen to be dimmed all the time, you had to manually deactivate the Screen Dimmer for this period and re-enable it afterwards. Also the battery drain while the screen was dimmed was much higher compared to a proper screen lock, since only the display and the access to the framebuffer was disabled - the other hardware was still enabled and most importantly the Android OS and the apps were still running.

    I thought that I could do better than that and tried to find a way to achieve the same what Screen Dimmer was doing without running into its limitations. Since the Android OS power manager handles the FLAG_KEEP_SCREEN_ON and also suspends the OS and running apps on a screen lock, I thought why not letting the power manager do its jobs and just prevent the touch controls (screen and keys) from suspending. Then one could wake the device from screen lock by emulating a power button press on touch. After a user defined delay after screen off the touch controls also get suspended. The only complication was to monitor the power button, so one can differentiate between screen timeouts, for which the touch controls should be kept enabled for a certain time, and a screen lock manually triggered by the user by pressing the power button, for which the touch controls should be disabled right away.

    So with Touch Wake, one can wake the device from suspend (for a certain user-defined time after screen off) by touching the touchscreen or the touchkeys. Combined with a OS level tweak which disables the lock screen on timeout for a certain time or altogether (for example in CM 7.03, but also available as standalone apps from the Market), one can achieve the same functionality as Screen Dimmer. Compared to Screen Dimmer, Touch Wake has the advantage that the screen will not be blanked as long as the FLAG_KEEP_SCREEN_ON is set and also the battery drain while the screen is off will be significantly less because only the touch controls are kept enabled and the Android OS and running apps are properly put to sleep. For the record, with Touch Wake, while the touch controls are still enabled, the kernel is kept in a wake lock, so the battery drain will still be a little higher than for the normal stock screen lock, however it is a significant improvement over Screen Dimmer.

    To enable (disable) wake on touch pass 1 (0) to 'enabled' in /sys/class/misc/touchwake. Pass the delay (until the touch controls will be disabled after screen off) in ms (this is milliseconds; 1000ms = 1s) to 'delay'; a value of 0 for the delay means the touch controls will be kept enabled indefinitely. The default state is disabled and a delay of 45000 = 45s.


    Changes to the source (based on kernel with BLD 3 and Screen Dimmer 1):
    http://www.pastie.org/2445282


    BUGFIX:

    Fixed BLN not working properly anymore.

    Bug fix: http://www.pastie.org/2446398


    BUGFIX #2:

    Fixed the problem with the proximity sensor not reactivating the screen when making calls. Also, since I was in the neighborhood I also fixed the problem with BLD on the i9023.

    Bug Fix: http://www.pastie.org/2457092


    BUGFIX #3:

    I cleaned up the code a bit for all three mods BLD, Screen Dimmer and Touch Wake.

    Bug fix: www.pastie.org/2488785


    BUGFIX #4:

    Fixed the BLD problem for the i9023 of the touchkey backlights not being re-enabled on touchkey press.

    Bug fix: http://www.pastie.org/2499956


    BUGFIX #5:

    Fixed the problem of the touch controls misbehaving after the proximity sensor has blanked the screen during a call.

    Bug fix: http://www.pastie.org/2528577


    BUGFIX #6:

    Fixed the problem with BLD on the i9023 of the touchkey backlights getting activated when the bottom of the touchscreen was touched.

    Bug fix: http://www.pastie.org/2544546


    BUGFIX #7:
    For Touch Wake, call the suspend function a bit earlier to prevent a rare hiccup happening when the touch controls are pressed in exactly the same moment the screen is disabled.

    Bugfix: http://www.pastie.org/2641540


    BUGFIX #8:
    For BLD, Screen Dimmer and Touchwake, use mutex_trylock instead of mutex_is_locked/mutex_lock combo to avoid race conditions.

    Bugfix: http://www.pastie.org/2710096


    No further patches will be published here. I have set up a git repo for all my tweaks. Each mod has its own branch to keep the tweaks cleanly separated and one can simply pull the latest patches from the corresponding branch.

    https://github.com/Ezekeel/GLaDOS-nexus-s/tree/touchwake



    Get Jonathon Grigg's 'Spark Mod Manager' GUI for controlling Touch Wake: http://xdaforums.com/showthread.php?p=17291034


    I do not accept donations and since I reached my 50GB limit of free space on SpiderOak, thanks to all of you kind people who got an account using my referral link, I could not ask for more.
    Instead if you really want to donate your hard earned money to someone who deserves and needs it, consider donating to the Free Software Foundation at fsf.org: These guys are at the frontline when it comes to keeping Linux free and fighting these greedy bastards who think they are entitled to collect royalties and other fees from Linux users due to some silly patents - and if Linux falls, Android will be next.
    4
    I have put together a quick app for enabling/disabling Ezekeel's various mods included in many kernels, for those who dislike playing around with scripts. You can find it at RootzWiki (with support) - http://rootzwiki.com/showthread.php?4526 or here at XDA (without support) - http://xdaforums.com/showthread.php?p=17282651
    2
    Can you stop copy pasting this "couldn't reach morfic"
    That would be awesome.
    Sent from my Nexus S using Tapatalk
    2
    Fixed BLN not working properly anymore.

    Bug fix: http://www.pastie.org/2446398
    2
    Fixed the problem with the proximity sensor not reactivating the screen when making calls. Also, since I was in the neighborhood I also fixed the problem with BLD on the i9023.

    Bug Fix: http://www.pastie.org/2457092