Power button in Android

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Power button in Android

3,847 Views
hajimohammed
Contributor III

Hi,

      We are currently working on IMX6 custom board & our OS is android lollipop with 3.10.53 linux kernel. When we press the power button, we have to get Reboot / Shutdown  power status popup but we are not able to configure our gpio to perform this power button functionality.

       Please provide a solution to fix it

Regards,

Haji

0 Kudos
11 Replies

2,073 Views
aravinthkumarja
Senior Contributor II

Hi Haji,

In dts under gpio-keys section add the below line.

power {
label = "Power Button";
gpios = <&gpio3 29 1>;   //Here you need to give your gpio number
gpio-key,wakeup;
linux,code = <KEY_POWER>;
};

Hope above information is helpful for you!

Regards,

Aravinth

0 Kudos

2,073 Views
hajimohammed
Contributor III

Hi,

  When we using below code,we are able to get only power off popup (working). If i want to reboot/restart popup what are the changes i need to do

#define POWER_OFF        IMX_GPIO_NR(2, 4)

static struct gpio_keys_button buttons[] = {
        {
                .gpio           = POWER_OFF,
                .code           = KEY_POWER,
                .desc           = "Power Off Button",
                .type           = EV_KEY,
                .active_low     = 0,
                .wakeup         = 1,
        }
};

static struct gpio_keys_platform_data button_data = {
        .buttons        = buttons,
        .nbuttons       = ARRAY_SIZE(buttons),
};

static struct platform_device button_device = {
        .name           = "gpio-keys",
        .id             = -1,
        .num_resources  = 0,
        .dev            = {
                .platform_data  = &button_data,
        }
};

0 Kudos

2,073 Views
vinodmaverickr0
Contributor IV

Hi Haji,

For restart you can try by modifying the below code. 

.code           = KEY_POWER,  

.code        =  KEY_RESTART,  //try this

Thanks,

Vinod

0 Kudos

2,073 Views
aravinthkumarja
Senior Contributor II

Hi Haji,

Do the below changes,

.code = KEY_SCREENLOCK,

Regards,

Aravinth

0 Kudos

2,073 Views
hajimohammed
Contributor III

Hi aravinthkumar,

         With below code changes also we are getting only poweroff popup. but we need reboot/restart popup

.code = KEY_SCREENLOCK,

2,073 Views
aravinthkumarja
Senior Contributor II

Hi Haji,

That is application layer dependency. Ask them to check, If you get long press event from "KEY_SCREENLOCK" , popup the expected function(Reboot, poweroff, Screenshot, etc).

Hope above information is helpful for you!

Regards,

Aravinth

2,073 Views
deepanrajanbara
Contributor IV

hi aravinthkumar jayaprakasam

Is there any way to configure the same power button click event to show reboot option also ?

Thank you,

Deepanraj.A

0 Kudos

2,073 Views
aravinthkumarja
Senior Contributor II

Hi Deepanraj,

Yes. we can do it. It's just android pop-up. 

Regards,

Aravinth

0 Kudos

2,073 Views
deepanrajanbara
Contributor IV

How to configure that pop up do you know ?

Thank you,

Deepanraj.A

0 Kudos

2,073 Views
aravinthkumarja
Senior Contributor II

Hi Deepanraj,

Sorry for the delay. Android App developer know about it.

Regards,

Aravinth

0 Kudos

2,073 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hi haji,

You need to do a key mapping to the AOSP power key 

PowerManager | Android Developers 

Key layout files are searched for in the following order:

  • /system/usr/keylayout/Vendor_XXXX_Product_XXXX_Version_XXXX.kl
  • /system/usr/keylayout/Vendor_XXXX_Product_XXXX.kl
  • /system/usr/keylayout/DEVICE_NAME.kl
  • /data/system/devices/keylayout/Vendor_XXXX_Product_XXXX_Version_XXXX.kl
  • /data/system/devices/keylayout/Vendor_XXXX_Product_XXXX.kl
  • /data/system/devices/keylayout/DEVICE_NAME.kl
  • /system/usr/keylayout/Generic.kl/

Regards

0 Kudos