There are many custom ROMs/kernels out there that allow you to:
- Double tap the screen to wake it up but it cost 2% of battery/hour
- Use Volume Rocker to wake the screen
I don’t want to install custom ROMs because some of them are not open sources.
The cleanest way to remap button would be:
- clone AOSP
- modify /system/usr/keylayout/xxx.kl to remap the button
- build my own ROM, and flash it
Remap Volume button with temporary recovery ROM
I found a way to avoid permanently root my phone, or flash a custom ROM. But you still need to unlock your bootloader which will WIPE ALL DATA ON YOUR PHONE!
I temporary boot into a custom recovery ROM via fastboot, modify the keymap file, and eureka!
- Get adb and fastboot from Android SDK
- Download openrecovery-twrp-126.96.36.199-hammerhead.img (a custom recovery for Nexus 5)
- Unlock the bootloader with following command:
WARNING: THIS WILL WIPE ALL DATA ON YOUR PHONE!!!
adb reboot bootloader # reboot to bootloader fastboot oem unlock # unlock the bootloader
- Temporary boot into a custom recovery ROM (without flashing it)
adb reboot bootloader fastboot boot openrecovery-twrp-188.8.131.52-hammerhead.img
- Press Mount and select System to mount /system
- On your PC, run:
adb shell vi /system/usr/keylayout/gpio-keys.kl
- Modify the content of file from:
key 115 VOLUME_UP key 114 VOLUME_DOWN
key 115 POWER key 114 VOLUME_DOWN
- Save [ESC] then :wq[ENTER], then unmount the /system by select System again on your phone
- Press back (bottom right of the screen) and Reboot -> System
- Choose NOT to install Super SU (DON’T swipe!)
When the phone reboots, you may use Volume Up button to wake the screen now. Unfortunately, the button will not turn up the volume anymore.
I tried modifying the keymap to allow the volume button to acts as both VOLUME UP and button to wake the screen:
key 115 VOLUME_UP WAKE # THIS WONT WORK key 114 VOLUME_DOWN
This does not work because the behaviour of Wake Key was controlled by
PhoneWindowManager.interceptKeyBeforeQueueing which you can read more from the doc and PhoneWindowManager source code. Seem like we can turn up the volume while listening to music without waking up the phone (That might be the feature that prevent this to work).