This is something that can give you an idea of ββthe OS you are working on, and not about developing an application that will work on any device, since you did not make an OS for them.
Just pull the android branch, configure it according to your desire and in mainfest
remove the filters , permissions that do not allow you to do this , or add your own. Now you have to play with the battery if I'm talking about more depth.
But if you just want to trigger a click when you turn off the power, then its easier.
source share