Power button functionality (sleep/resume/wakeup)

2,178 views
Skip to first unread message

Ashwin Bihari

unread,
Feb 24, 2010, 10:16:28 AM2/24/10
to android-porting
I've got a custom board designed around the OMAP3530 and we have a
power button the device that we want to use to cause Android to go to
sleep or wakeup based on it's current state.

I've done a few searches and have figured out the the function
goToSleep within the PowerManager handles this functionality. For the
power button handler, I'm sending the KEY_POWER eventcode into
Android..this is mapped appropriately into Andriod as
KeyEvent.KEYCODE_POWER. However, pressing the button doesn't cause
anything to happen with Android..what am I missing in making my
connections?

Regards
-- Ashwin

Srikant

unread,
Feb 25, 2010, 10:34:06 PM2/25/10
to android-porting
Are you sure that this functionality is supported by your Kernel and
Target hardware?

Regards,
Sreekanth

girish

unread,
Feb 26, 2010, 12:05:52 AM2/26/10
to abi...@gmail.com, android-porting
I guess you intend to power off the device when you hit the power button right?

First, the keycode as you mentioned should map Android power key. Secondly, you should
have proper hook in baseport level for pm_power_off() for DEVICE OFF.


-Girish


Ashwin Bihari

unread,
Feb 26, 2010, 8:41:20 AM2/26/10
to android-porting
To list

-- Ashwin


---------- Forwarded message ----------
From: Ashwin Bihari <abi...@gmail.com>
Date: Fri, Feb 26, 2010 at 8:38 AM
Subject: Re: [android-porting] Re: Power button functionality
(sleep/resume/wakeup)
To: w.sre...@gmail.com


Sreekanth,

Yes, the hardware supports it and the Kernel does as well. My question
is more towards the Android side of things since I know Linux and the
HW are fine.

Regards
-- Ashwin

Ashwin Bihari

unread,
Feb 26, 2010, 8:41:36 AM2/26/10
to android-porting
To list

-- Ashwin


---------- Forwarded message ----------
From: Ashwin Bihari <abi...@gmail.com>

Date: Fri, Feb 26, 2010 at 8:41 AM
Subject: Re: [android-porting] Power button functionality (sleep/resume/wakeup)
To: girish <neo.d...@gmail.com>


Girish,

No, I don't want the power button to turn the device off, I've already
implemented that at the Kernel level through a different scheme. I
want to invoke the Linux Power Manage suspend and resume functionality
with the power button through Android. If you take any Android phone
right now, there's usually a single button (the top button on the
Motorola Droid for example) that when pressed will put the device to
sleep if it was awake or wake it up if it was asleep. In the sleep
mode the LCD is turned off and the touchscreen doesn't respond to
anything.

It's basically what happens when you let the screen timeout and the
device goes to sleep. The power button allows you to put the device to
sleep faster, and that's the functionality I'm trying to implement.

I have the power button mapped to KeyEvent.KEYCODE_POWER in my Android
build, but that doesn't do anything..

Regards
-- Ashwin

girish

unread,
Feb 27, 2010, 2:53:48 AM2/27/10
to abi...@gmail.com, android-porting
Ok, I get your point. Mapping the power key is the first thing to do. Rest android should take care...

Can you attach your defconfig file, need to check if all the proper power flags are enabled..which is
important for android power frmwork to work.

Also, when you press the power key do you see any early_suspend dumps on the terminal? if it
does and doesn't go any further to suspend to RAM that means someone is holding a wake_lock.

-Girish

Ashwin Bihari

unread,
Mar 8, 2010, 10:20:37 AM3/8/10
to girish, android-porting
Girish,

I do have the power management code within the Kernel enabled since my
screen timeout causes the system to go into the suspend state. I can
then hit the Power button to wake up the system nicely.

When I do press the Power button while the system is active, I don't
see any messages related to early_suspend, any ideas on what exactly I
should be looking for??

Regards
-- Ashwin

girish

unread,
Mar 8, 2010, 12:09:48 PM3/8/10
to Ashwin Bihari, android-porting
did you check if hitting the power button locks the screen? You might need to look
into that first...

-Girish

Ashwin Bihari

unread,
Mar 9, 2010, 11:37:59 AM3/9/10
to girish, android-porting
Girish,

The device on which we are using Android shouldn't have the keygaurd
enabled, so I've disabled all of that functionality. The device gets
to the home screen on bootup, and the idea is to let the screen
timeout for it to lock itself or use the power button to force the
lock and the only the power button will unlock/wake up the device back
to the home screen or wherever it was..

Do you know where specifically the power button is handled within
Android to show the lock screen or go to sleep? I've been searching
for a bit but haven't followed all the source through..

Regards
-- Ashwin

Ashwin Bihari

unread,
Apr 9, 2010, 8:10:20 AM4/9/10
to Jebediah Huang, girish, android-porting, android-...@googlegroups.com
Jebediah,

Yeah I got the power button functionality working. I'm working with
the Donut 1.6 release from Rowboat and I looked at the newer Eclair
code as it deals with the POWER button and the handling is changed. So
I backported just the changes from one file and the power button now
functions as it should. Plus, when I hold the power button down for
some longer duration, I get the Power Off dialog..

So check out http://android.git.kernel.org/?p=platform/frameworks/policies/base.git;a=blob;f=phone/com/android/internal/policy/impl/PhoneWindowManager.java
and compare it to what you have..

Regards
-- Ashwin

On Fri, Apr 9, 2010 at 2:38 AM, Jebediah Huang <jebedia...@gmail.com> wrote:
> Ashwin,
>
> Did you get solution to this problem? I've see in testing:
> - screen timeout can suspend , no problem
> - wake from power button , no problem
> - cannot suspend from power button
>
> pressing power button when system active:
>
> # getevent
> add device 1: /dev/input/event0
>  name:     "keys"
> /dev/input/event0: 0001 0074 00000001
> /dev/input/event0: 0000 0000 00000000
> /dev/input/event0: 0001 0074 00000000
> /dev/input/event0: 0000 0000 00000000
>
> $74 = 116 = KeyEvent.KEYCODE_POWER
>
> Can help me some advice?
>
> Regards
> --Jebediah

Jebediah Huang

unread,
Apr 9, 2010, 2:38:01 AM4/9/10
to abi...@gmail.com, girish, android-porting, android-...@googlegroups.com
Ashwin,

Did you get solution to this problem? I've see in testing:
- screen timeout can suspend , no problem
- wake from power button , no problem
- cannot suspend from power button

pressing power button when system active:

# getevent
add device 1: /dev/input/event0
name: "keys"
/dev/input/event0: 0001 0074 00000001
/dev/input/event0: 0000 0000 00000000
/dev/input/event0: 0001 0074 00000000
/dev/input/event0: 0000 0000 00000000

$74 = 116 = KeyEvent.KEYCODE_POWER

Can help me some advice?

Regards
--Jebediah

Ashwin Bihari

unread,
Apr 10, 2010, 8:29:38 AM4/10/10
to Jebediah Huang, android-porting
Jebediah,

My diff is attached..

-- Ashwin

On Sat, Apr 10, 2010 at 4:49 AM, Jebediah Huang
<jebedia...@gmail.com> wrote:
> Thanks you Ashwin.
>
> Is it possible you share the diff you appli?

PhoneWindowManager.diff

Jebediah Huang

unread,
Apr 10, 2010, 4:49:50 AM4/10/10
to Ashwin Bihari, girish, android-porting, android-...@googlegroups.com
Thanks you Ashwin.

Is it possible you share the diff you appli?

On Fri, Apr 9, 2010 at 8:10 PM, Ashwin Bihari <abi...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages