I have a smartphone connected to a solar charger.
By day, it is powered correctly. But during the night, sometimes it turns itself off due to the lack of energy.
My question is : It is possible to turn it back on (programmatically), when the battery charge exceeds a certain percentage?
I’m looking for a clean and legal way. I’m not interested in flaws or exploits.
I found nothing in the official documentation. Thank you.
The mechanism for doing this relies on replacing the battery animation script, which is run while the device is turned off but plugged in, typically displaying an icon of the charging battery. The name of the script varies from device to device, but it is generally located in the
/system/bin directory. Samsung devices generally call the script
playlpm, and other names for the script that I’ve seen include
battery_charging. This will not necessarily work on every device, because this is well outside of the standard Android framework — some devices might not have an equivalent script, or they might implement it in a different way.
This could be characterized as an “exploit” in that it requires root and works at the Linux level rather than the Android framework level, but there is currently no alternative for implementing this behavior.
The general mechanism for making this change is described here: https://android.stackexchange.com/questions/20021/automatically-power-on-android-when-the-charger-is-connected. Of course it’s a good idea to back up the previous battery animation script before you do any of this.
The following script has worked for me on multiple devices (several Samsung devices and the Verizon Ellipsis 7). Basically, it checks to see if the phone is plugged into AC power and has enough charge. If so, it boots up. If not, it waits for N seconds and tries again. As a side effect, the original battery animation script won’t run, and you won’t ever see the pretty charging animation.
#!/system/bin/sh # battery threshold before boot-up (in percent) bthresh=10 # time to sleep between checks (in seconds) sleeptime=600 # file that contains current battery level as integer between 0 and 100 cfi=/sys/class/power_supply/battery/capacity # file that contains 1 if we're plugged in to AC, 0 if not acfi=/sys/class/power_supply/battery/subsystem/ac/online # if either file doesn't exist, just do normal sleep+boot [ ! -f $cfi ] && sleep $sleeptime && /system/bin/reboot [ ! -f $acfi ] && sleep $sleeptime && /system/bin/reboot # populate capacity and AC variables c=`cat $cfi` ac=`cat $acfi` # stop loop if we're not plugged into AC until [ "$ac" -eq 0 ] do # if capacity above threshold, boot up if [ "$c" -gt "$bthresh" ]; then /system/bin/reboot fi # wait some time before next check sleep $sleeptime # update capacity and AC variables c=`cat $cfi` ac=`cat $acfi` done
I don’t have a solution that is not hardware dependent and does not involve rooting the device.
This answer is just meant to clarify some misunderstandings.
“the device is powered off, there’s no way to run software of any type on it”
This is both true and false. Firstly, no modern device is ever really “off”. Sometimes, the off button is merely for show (e.g. your TV). Sometimes the processor is really powered down but addition circuitry on the motherboard is still powered at a trickle current. Secondly, this additional circuitry can power the processor and other circuitry back up under certain circumstances, such as wake on some external event (e.g. plugging in the charging cord), or when an off-processor timer reaches zero.
The only way to really power off a modern device, such as a smart phone, is to remove the battery and power cord. And even that sometimes doesn’t work as a small battery or low leakage capacitor might be on the mother board to preserve some operational state.
Not possible without rooting the device
If the device is powered off, there’s no way to run software of any type on it.
starting a device is a hardware task and there must be a physical power to run device(here with pressing power button). then you can not do this with code. there should be a physical power.
Last time I checked rooting is “legal” and is required to do this.
For example, this file
/system/bin/battery_charging may be located on your device. Edit it to contain
And set some permissions
chmod 0755/system/bin/battery_charging chown root.shell /system/bin/battery_charging