Is it possible to have an android application such that if the user starts it the phone will not switch off by pressing the side button? It means the only means to switch off it will be remove the battery, and taking all sort of permission from user is not an issue here.
2 Answers
No, it's not possible. The functionality to turn off the device if the power button is held down is at a very low level of the system, so that even if Android gets into some broken state, the user can still switch the device off to prevent it overheating. This is especially important on devices without a removable battery!
Only replacing the kernel with a custom-built one can disable the power button completely. This may or may not be possible depending on what device you're targeting and whether all the drivers and kernel source for that device are available.
It is possible to disable or even change what hardware keys do even without an app.
In my case I just commented out (added a # at beginning of) the lines starting with POWER in the /system/usr/keylayout/Generic.kl
file
(with root and rw access to /system . To access /system as rw just use this command: mount -o remount,rw /system
)
and rebooted the device. After this my physical power button doesn't work anymore. I tested this more by making my physical home button type the letter a in the same way.
(You can get an idea what changes can be made by reading that file. MEDIA_PLAY , CAMERA , CALL , CONTACTS , BRIGTHESS and more are all there. I suppose that in the same way it is possible to change what virtual keys (like virtual keyboard keys) do).