Android - Automatically limit (stop) battery charging at a given percentage
Okay.. Got it :)
The first thing to note is on Honor 6, my previous device , there was a single file I could play around with to stop charging automatically
On Moto X play, there are two distinct files - one for disconnecting the charger and other for removing charging symbol ( In other words, you could stop charging and still have the charger connected symbol showing). Till I realised this, I was running around in circles, since I took charging symbol to show that charging was happening ( and assuming I was dealing with the wrong file ). While experimenting, when I noticed charge drop despite charging symbol showing, I verified with Ampere app and wisdom dawned !
What are the files?
(Edit:30 Mar 20 Jackpot! Found this awesome repository of files for various devices by the developer of Advanced Charging Controller Magisk Module. You are better off using that versatile module but in case you want to DIY, it's a great start) .
There may be other files, but the files I homed on too are :
For Charging Icon :
/sys/devices/soc.0/78d9000.usb/power_supply/usb/online( For disabling icon change value of file from
0 to 1)
For charging :
/sys/devices/soc.0/78b5000.i2c/i2c-1/1-001c/power_supply/battery/charging_enabled( For disabling charging change value of file from
1 to 0)
For automating this, approach was similar to my answer here using Terminal Emulator and Macrodroid as explained here - How to automate command line when specific application is launched?
How did I find the files?
Inelegantly, and I am hoping that somebody posts a good way. Here is a way that may work for you in identifying the file and path
Long hours on the net and some coding on GitHub ( which I don't understand at all ) pointed me to look at
usbrelated files with names like
enable_charger. This seems to be true for Honor 6, Moto X and some Nexus devices. I have no clue whether it is chipset or device dependent
The true path of this file is in
/sys. Again, may vary
Do a search for
enable_chargeror a wild card search with similar words in
rwpermissions to enable changing the content from
0or vice versa
Connect your charger and see the value in file, disconnect and repeat. If the value changes, it looks like the right file. While the charger is connected, change the value in file and if charging stops, you have hit it (More so, if the path is in
i2cdirectory). Verify with Ampere app to confirm charging status
While you are at it, may as well copy original and modified files to a separate directory in your storage. Needed for automation
If your device is like mine where charging can be stopped but charging icon, shows, more grind to identify that file by keywords like
If you are lucky, above should work for you
Just as additional information for posterity the Terminal Emulator shortcuts are :
- For disabling charging and removing the charging icon
su –c "cp /storage/emulated/0/moto_charging/disable_charging/charging_enabled /sys/devices/soc.0/78b5000.i2c/i2c-1/1-001c/power_supply/battery/"
su -c "cp /storage/emulated/0/moto_charging/no_symbol_charging/online /sys/devices/soc.0/78d9000.usb/power_supply/usb/"
- For enabling charger and charging icon
su -c "cp /storage/emulated/0/moto_charging/show_charging/online /sys/devices/soc.0/78d9000.usb/power_supply/usb/"
su –c "cp /storage/emulated/0/moto_charging/enable_charging/charging_enabled /sys/devices/soc.0/78b5000.i2c/i2c-1/1-001c/power_supply/battery/"
moto_charging is a folder created in Internal SD that has original and modified copies ( to enable and disable charging), and these files are copied into the system. Of course, requires root
Now there's Chargie - a USB stick+Android app combo that limits charging externally. Just install the stick between the charger and phone and use the app to select the charge level. Simple as that. Look for "chargie stick" on Google.
Disclosure: I am the CEO of Lighty Electronics. We developed Chargie and would love people who have had this issue to enjoy our product as much as we do. No spam, just the solution to the problem.