The PowerManager class provides a way to obtain a WakeLock, preventing the phone from sleeping. Ideally, I want something which functions exactly like a WakeLock, except that while it is acquire()d it will only lengthen the sleep timer, not disable it entirely. Overriding the typical 30 second timeout with, for example, a 5 minute one.
The current WakeLock paradigm is ideal for situations where the user doesn't interact at all during an event with a pre-determined length, such as watching a movie. However, there is another class of situations, typified by the eReader, in which the user interaction is still key, it is just less frequent than the typical phone timeout. Consider an eReader. My phone typically times out and tries to go to sleep when I am about 70% done with each page. So if I do not change my timeout, I have to use WakeLock, and then if I fall asleep, the phone will be drained when I wake up. I have another application I am developing with similar usage profile -- the user will interact with the screen approximately every 90-180 seconds. But if the user walks off and forgets to close the app, I don't want their phone to be completely drained when they come back to it. In other words, rather than disabling the sleep, I want to temporarily set it for 5 minutes. That way during typical interaction with these sorts of apps, the phone will not sleep but if the user goes AWOL, the phone will not drain all the way. BTW, FBReader approaches this by setting a minimum battery percent. I see why they wound up at that compromise but really it is the wrong answer because you don't want it to be drained to 25% battery any more than you want it to be drained to 0% battery. After 5 minutes of waiting for user input, it should be obvious that they have lost interest. So really this is a feature request. I'm pretty sure this functionality would be absolutely trivial to add to PowerManager/ WakeLock in a relatively bulletproof way. In fact, I might even be able to provide a patch. But I'm not able to wait for Android 2.3. :) In the mean time, does anyone have a good idea for a hack that would be fairly bulletproof? It seems like a bad idea to me for an app to edit the system preferences. So the only options I see are to obtain a WakeLock and set up a thread that will automatically release it in 5 minutes, or to have a thread that calls PowerManager.userActivity() periodically. The real question for either of those hacks is how do we reset the hack thread's internal timer? Is there a way to track existing calls to PowerManager.userActivity(), or does anyone know a convenient way to intercept every click event that happens within an activity? I'd really like to avoid instrumenting all of my onClickListeners etc... I'm interested in any and all thoughts on the matter! Thanks, - Greg -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

