[APP][ROOT][4.0+]Battery Charge Limit v1.1.1

Search This thread

mmoiron

Member
Oct 5, 2008
19
1
Feature request / application idea:
I no longer root my smartphones but this is something I'd like to have. I've tried to do something similar with Tasker but didn't manage to get it working properly. It would be nice if your application was able to send GET requests to switch ON or OFF a smartplug (sonoff basic with Tasmota but should work with others) thus controlling the charging process. Another nice functionality would be to keep battery level between two thresholds, say 75-80, until time to next alarm is less than a certain time (1 hour). This would allow us to charge our smartphones every night, without having it fully charged for too long, yet maintaining the full charge available when the wakeup alarm is triggered.
Just an idea.
Cheers
MFM
 

larsdennert

Senior Member
Dec 5, 2007
1,010
322
Feature request / application idea:
I no longer root my smartphones but this is something I'd like to have. I've tried to do something similar with Tasker but didn't manage to get it working properly. It would be nice if your application was able to send GET requests to switch ON or OFF a smartplug (sonoff basic with Tasmota but should work with others) thus controlling the charging process. Another nice functionality would be to keep battery level between two thresholds, say 75-80, until time to next alarm is less than a certain time (1 hour). This would allow us to charge our smartphones every night, without having it fully charged for too long, yet maintaining the full charge available when the wakeup alarm is triggered.
Just an idea.
Cheers
MFM
Buy a new oneplus phone or iPhone. They have this feature built in.
 

sfaeium

Member
Dec 8, 2020
10
0
My old Nexus 5 has a ROM which sets the control file to be read only, so without "user intervention" Battery Charge Limit (BCL) won't be able to change the content of this file and it won't work as expected. As a workaround, I created a script using ElementalX Kernel Manager, which runs after every boot, to allow the control file to be writable. After that BCL works perfectly.

My other rooted Android devices don't need this workaround.
Could you share this script?
 

aamadorj

Senior Member
My old Nexus 5 has a ROM which sets the control file to be read only, so without "user intervention" Battery Charge Limit (BCL) won't be able to change the content of this file and it won't work as expected. As a workaround, I created a script using ElementalX Kernel Manager, which runs after every boot, to allow the control file to be writable. After that BCL works perfectly.

My other rooted Android devices don't need this workaround.
Could you share this script?
Sure, it's attached as a text file.
 

Attachments

  • 99BCL_Attributes.txt
    154 bytes · Views: 66

d3smond

Senior Member
Aug 8, 2020
67
19
I have a Xiaomi Mi 10T Pro running Lineage OS with Magisk.
I granted root permission for the app but the app does not work, I set it to 80% but it charged past 80%.
What do I have to change to make it work?

Thx
 

yaconsult

Senior Member
Nov 13, 2013
326
54
Google Pixel 4a 5G
I would LOVE to get this working on my new Pixel 4a 5G. Here are the nodes under the power_supply directory. Can someone tell me how to enable and disable charging on this magisk rooted phone? I am willing to experiment and report back results.

I have uploaded a copy of all the file nodes under /sys/class/power_supply at the following pastebin:
https://pastebin.com/T0VJqiW4

I know something has changed on the 4a 5G because advanced charge controller worked fine on the 3a but on the 4a 5G the phone always thinks it is charging even when ACC has stopped the charging.

Thanks!
 

Gibsonflyingv

Senior Member
Jul 28, 2011
378
62
I would LOVE to get this working on my new Pixel 4a 5G. Here are the nodes under the power_supply directory. Can someone tell me how to enable and disable charging on this magisk rooted phone? I am willing to experiment and report back results.

I have uploaded a copy of all the file nodes under /sys/class/power_supply at the following pastebin:
https://pastebin.com/T0VJqiW4

I know something has changed on the 4a 5G because advanced charge controller worked fine on the 3a but on the 4a 5G the phone always thinks it is charging even when ACC has stopped the charging.

Thanks!
I'm also trying to get this to work on my P5. I noticed, when I was looking, only some of those are files are writable. I don't know much about this stuff but I wonder if setting "current max" to 0 once we hit our limit would do it?
 

evronetwork

Senior Member
Jan 19, 2012
1,568
411
North
Wish this app would still be in development, my gf phone(my prev phone) oneplus one works great, as for mine Xiaomi Mi Mix 2S, I need to reset battery stats each time ...but it does honor the limit
 

pleomaxell

Senior Member
Oct 20, 2012
333
76
I am trying to make it work on Nexus 7 3G. The default /sys/class/power_supply/battery/status file isn't working. It keeps on charging past my set limit. Is there any other way to make it work?
 

the_cr0w

Senior Member
I am trying to make it work on Nexus 7 3G. The default /sys/class/power_supply/battery/status file isn't working. It keeps on charging past my set limit. Is there any other way to make it work?
same to me in my asus zenpad 10 :(
it shows only motorola defy+ in the control files, don't know if that is the problem

UPDATE: found out that the app should automatically edit /sys/class/power_supply/battery/charging_enabled but on my device the control file points to /sys/class/power_supply/battery/status , which is a file that does not have a binary value, thus cannot be automatically switched, i guess? however a custom file can be pointed enabling configurable ctrl file data option, but i don't know what file should be. any ideas?
 
Last edited:

the_cr0w

Senior Member
But is there a charging_enabled file on /sys/class/power_supply/battery/?
no! maybe that's the problem ? or maybe there is another file with the same function?

UPDATE: found out that there is a file in sys/class/power_supply/ac/device that is called charge_status, and as expected the content of the file is 0 while not plugged and 1 while plugged. i tried to set that as ctrl file but nothing changed, then i noticed that it has only read permissions, tried to set rwxrwxrwx so that the app could edit the file but changing the permissions bugged my system ui and forced me to reboot. after booting the permissions of the file are reset into r--r--r--. Is this the problem?
 
Last edited:

pleomaxell

Senior Member
Oct 20, 2012
333
76
There is another file called sys/class/power_supply/ac/online which becomes 1 when the charger is connected. I face similar issue with that file too. The phone restarts as soon as I change the permission and set an upper and lower limit.
 

the_cr0w

Senior Member
There is another file called sys/class/power_supply/ac/online which becomes 1 when the charger is connected. I face similar issue with that file too. The phone restarts as soon as I change the permission and set an upper and lower limit.
eww let me know if you find out anything new... i guess the app is discontinued by the developer as of now, and it's sad because it's still used even in modern devices
 
  • Like
Reactions: pleomaxell

Saqib Mushtaq 74

Senior Member
Aug 27, 2013
137
35
28
sargodha
S:
Used battery charge limit app to charge only to 99% but now turned off but still it does not charge to 100% now any solution to get 100 chrgd

Like editng some value in root folder
I am using redmi note 7
 

amn1987

Senior Member
I would LOVE to get this working on my new Pixel 4a 5G. Here are the nodes under the power_supply directory. Can someone tell me how to enable and disable charging on this magisk rooted phone? I am willing to experiment and report back results.

I have uploaded a copy of all the file nodes under /sys/class/power_supply at the following pastebin:
https://pastebin.com/T0VJqiW4

I know something has changed on the 4a 5G because advanced charge controller worked fine on the 3a but on the 4a 5G the phone always thinks it is charging even when ACC has stopped the charging.

Thanks!
If its possible to set the proper permissions then try lowering charge voltage and/or current in constant_charge_current, constant_charge_voltage or voltage_max_design etc. BCL works out-of-the-box in my Poco F1 but in addition I have limited charging voltage and current as well. At 4.15V battery charge hits 80% thereafter the battery light starts blinking. If I then increase voltage to 4.2V battery light stops blinking. But in my case the files are differently named constant_charge_current_max and voltage_max. Dunno if it work for you. Experiment with various files.
 
  • Like
Reactions: SGH-i200

Heinz_P

Senior Member
I install it today on a Samsung Galaxy Tab SM-T585.
It works fine, but I can not clear the statistik in the Tab.
I delete
/data/system/batterystats.bin to clear stats
But it is still there.

Edit:
Now it works, statistik is ok.
I delete the file, power down the Tab and start again and after 80% the stat is correkt.

Edit 2:
After a new charge the statistik is wrong again and nothing helps to clear it.
Like
 
Last edited:
  • Like
Reactions: SGH-i200

@kitokit

Senior Member
Mar 15, 2017
364
70
I've been using this app for a while now, I'm using a Mi9 with RR Rom a10, before I set my limit to 85 and 2O percent.. and then I decided to increase it to 90. What I've noticed is, whenever I charge my phone, when my battery reaches 85 it notifies me that it has reached the limit and after a second it will start charging again obviously because I set it to 90, and when that level is reached it will stop charging.. but it will start charging again at 80 percent, even though I set the minimum to 20.. any ideas why is this is happening..
I've already tried to uninstall and rebooted the phone and then reinstall the app, but same problem I face.. any help?
 
  • Like
Reactions: ivkom

Top Liked Posts

  • There are no posts matching your filters.
  • 400
    Please read the following before installing the app:
    • This app requires a rooted mobile (Android 4.0 or later)
    • Before uninstalling the app, disable limit in the app (if forgotten, reboot after uninstalling)

    Usage instructions and app details:
    • Enable limit in the app
    • Change the limit up to which it should charge (default: 80)
    • Check which control file suits best for your device, see Q/A section below for hints. In most cases, the pre-selected choice should be the best that's available for your device.
    • The app only gets kicked in while you connect a charger (or USB), and automatically closes shortly after unplugging charger (or USB) i.e it only runs in the background as long as it is plugged in, and won't affect your battery life.
    • If your device is not charging even after disabling the limit (which shouldn't happen, just in case), uninstall the app and reboot the device (The changes made by the app don't survive a reboot). Your device should charge normally then.

    If the app says "your device is not yet supported"
    There are various control files in different devices (due to OEMs), and toggling the values in them (0 and 1) makes it possible to enable and disable charging via software (might not be possible for every device), though the charging cable is still physically connected.
    Since we cannot own every device, it is impossible for us to find every file. We can support a lot more devices with information provided by testing possible files on different devices by you, the people in the community.
    Hence, for support to be provided to other devices, you need to do some detective work to find the files on the respective devices. Please refer to this file for control files of currently supported devices, so you can know where they are generally present: https://github.com/sriharshaarangi/BatteryChargeLimit/blob/master/app/src/main/res/raw/control_files.json
    You can send us a pull request or open an issue on GitHub. If necessary, you can also post the name of the device and the file here.

    FAQ
    Q) Can you please add support for... (insert arbitrary device name here)?
    A) Maybe, but we need your help. Bottom line, this app does nothing but modifying the content of a certain "control file", some more details are given above. If you find such a control file for your device, please let us know (ideally, open a GitHub issue here: https://github.com/sriharshaarangi/BatteryChargeLimit/issues) and we will add support for your device.

    Q) I think I observed a bug. Can you fix it?
    A) We'll do our best, but we need your help: Please open an issue on GitHub (https://github.com/sriharshaarangi/BatteryChargeLimit/issues) and provide as much information as possible about the problem.
    In most cases, we need the "logcat" logs of your device to find out about the exact issue. In order to provide those, you could use aLogcat (https://play.google.com/store/apps/details?id=rs.pedjaapps.alogcatroot.app).
    FOR CHARGING-RELATED ISSUES: Select the "Time" format in the preferences of aLogcat, so we can see precise timings, and filter for "(Charging|Power) State" with "Apply as regular expression" ticked.
    FOR CRASHES: Please also select the "Time" format and provide unfiltered logcat data that includes the stack trace of the crash.

    Q) Why do you want to limit charge to a lower capacity?
    A) In short, to prolong battery life in long term usage. For more information, refer this : http://batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries

    Q) How does this app work? Does it modify something in the ROM/Kernel to stop charging?
    A) It writes "0" or "1" to a control file that represents some state of the power supply hardware, as simple as that. The file is normally read-only, so you need root to overwrite it.
    The change might be automatically reversed by the OS if the power supply situation changes. Anyway, it should never survive a reboot of the device.

    Q) I can select multiple more than one control file in the radio group. Which one should I use?
    A) For most devices, battery_charging_enabled or store_mode are preferable. Try those first and see if it works. If you observe any bugs, try another file.

    Q) I have a OnePlus device, and the app doesn't work correctly for me. What to do?
    A) Check that the control file you selected is NOT battery_charging_enabled! Although it should be preferred in general, there are known issues for this file with OnePlus devices.

    Q) I use the store_mode on a Samsung device. My device always stops charging at 70 % (or other specific percentage), no matter what limit I have set.
    A) The store_mode implementation differs among the supported (Samsung) devices.
    Normally, it freezes the level at the current percentage when store_mode is triggered until the cable is unplugged for some seconds. This is a normal condition due to Samsung's kernel implementation, it's not a bug of this app.
    If this is a problem for you, try to switch to another control file (e.g. batt_slate_mode), if supported.

    Q) How does the "automatic stats reset" work?
    A) The automatic reset should perform a stats reset when your power supply is removed while the battery level is within the desired range. Everything else is wrong behavior.

    Q) No matter if I the "automatic stats reset" is enabled or not, my phone is always resetting my battery statistics. Why?
    A) Are you using a threshold above 90%? If yes, your ROM will most likely clear the stats when the power is removed. There is nothing we can do about that.

    Downloads:
    The app is available on Google Play Store

    Alternate APK download links:
    v1.1.1: https://www.androidfilehost.com/?fid=674106145207486851
    v1.1.0: https://www.androidfilehost.com/?fid=817906626617956614
    v1.0.4: https://www.androidfilehost.com/?fid=889764386195927297
    v1.0.3: https://www.androidfilehost.com/?fid=745425885120755941
    v1.0.2: https://www.androidfilehost.com/?fid=889764386195923345
    v1.0.1: https://www.androidfilehost.com/?fid=889764386195919111
    v1.0.0: https://www.androidfilehost.com/?fid=817550096634789023
    v0.11.0: https://www.androidfilehost.com/?fid=961840155545580765
    v0.10.0: https://www.androidfilehost.com/?fid=961840155545576298
    v0.9.2: https://www.androidfilehost.com/?fid=457095661767160082
    v0.8.2: https://www.androidfilehost.com/?fid=673368273298951679

    Please uninstall versions < 0.8 before installing this!

    Changelog:

    1.1.1:
    • Fix charging status layout issues and misc UI fixes @xdnax
    • Added switch to disable toasts on service changes @xdnax
    • Added switch to show temperature in notification @xdnax
    • Ensuring write permissions on the charging control file @real_milux
    • Fixed notification sound on limit reach @sriharshaarangi
    • Fixed a bug causing crash
    • Added Russian translation
    • Updated Bengali, German and Brazilian Portuguese translations
    • Added control file for Amazon Tate (LineageOS 14.1)

    1.1.0:
    • UI & icon redesign @xdnax
    • Custom control file data support @xdnax
    • Improved control file lists @real_milux
    • ICS (Android 4.0, API 14) compatibility @real_milux
    • Pixel/Pixel 2 support fixes @xdnax
    • Added control files for Pixel/Pixel 2, Xiaomi Redmi Note 2, Sony XPERIA Mini, Le 1s, Huawei P10 lite, HTC One, Motorola Defy+, Xiaomi Mi A1
    • Bengali translation @AdroitAdorKhan
    • Spanish translation @Joseahfer
    • Lots of bugfixes and minor improvements

    1.0.4:
    • New "always write" setting for devices that modify their control files in a problematic way
    • Experimental support for Xiaomi MiPad 2, Nexus 5, Nexus 9, Galaxy Nexus (maguro) and Xiaomi Mi6

    1.0.3:
    • Fixed service starting after boot when disabled

    1.0.2:
    • Fixed ignoring "ACTION_POWER_CONNECTED" when service was disabled
    • Experimental support for Nexus 10, Nvidia Shield and Xiaomi Mi6

    1.0.1:
    • Added preference to disable limit enforcement aka "state fixing"
    • Added expert preference to enable immediate reaction to power state events (be careful!)

    1.0.0:
    • Tested Magisk 13.x support
    • Improved UI
    • Even higher service priority (against being killed by Android)
    • Online limit change support (limit changeable while service is active)
    • Settings with control file selection and temperature scale
    • Fahrenheit temperature info support
    • Greatly improved "state fixing" with exponentially increasing delay (hopefully fixing GitHub issue #15 aka "rapid cycling")
    • Greatly improved SU shell speed/performance
    • German translation

    0.11.0:
    • Improved UI (Using NumberPickers, GitHub issue #13)
    • Show voltage and temperature in app and notification (GitHub issue #14)

    0.10.0:
    • The recharge threshold can now be customized between 0 and the chosen charging limit
    • Sending a charging limit of 100 via (broadcast) intent will disable the service.
    • Sending values between 40 and 99 will enable and start the service if it was previously disabled.

    0.9.2:
    • Fixed crash on some devices that are unrooted or unsupported

    0.9.1:
    • Fixed widget not showing in some devices

    0.9:
    • Added Widget to toggle service
    • Added scrollable view

    0.8.2:
    • experimental Amazon Fire support

    0.8.1:
    • Bugfixes

    0.8:
    • State check after boot (starting monitoring service as necessary)
    • Bugfixes

    0.7:
    • Experimental support for Huawei and Nexus 4 devices
    • Support for external control over charging limit
    • Bug fixes

    0.5
    • Ability to select recharge limit (Range: 10%)
    • Automatic file selection
    • Added store_mode for Samsung devices
    • Added option to auto reset stats
    • (Huge code refactoring)

    0.3
    • Updated to support 7.1.1
    • Auto-select the battery charging file for Samsung, Pixel and Nexus devices
    • Added clear battery stats button
    • Auto-whitelisting from Doze mode

    XDA:DevDB Information
    Battery Charge Limit, App for all devices (see above for details)

    Contributors
    harsha1397, real_milux
    Source Code: https://github.com/sriharshaarangi/BatteryChargeLimit


    Version Information
    Status: Stable
    Current Stable Version: 1.1.1
    Stable Release Date: 2018-10-17
    Current Beta Version: 1.0.4
    Beta Release Date: 2017-09-04

    Created 2017-02-15
    Last Updated 2020-08-05
    59
    Todo:
    - Check for charging on device boot
    - Widget for quick toggle
    - Widget to reset batterystats
    - Limit reached alert
    - Low battery alert - Needs a service running in the background
    - UI overhaul
    - on/off switch to enable/disable charging
    38
    Announcement: Official Version 1.1.0, welcome @xdnax!

    Hello everybody,

    it has been quite a while since I wrote my last post here. The reason for this is rather simple:
    Apart from being very busy in the last months, I realized some time ago that I was investing more time in reading and answering posts in this thread than doing actual implementation work for BCL, which is definitely not my intended workflow.
    Therefore, I shifted my attention completely to GitHub, where the workflow was/is much more efficient.
    Some people here suggested to officially fork this project and continue it elsewhere. I want to say the following to those people:
    While it is in general a good thing that dead projects are forked and continued, good behavior demands to first open a GitHub issue asking whether the project is to be continued before suggesting an official fork, which did afaik not happen.
    Furthermore, a simple look at GitHub would have clearly revealed at all times that I was reacting to issues there on a regular basis, so our project was hardly inactive, and surely not dead!
    Luckily, @xdnax was considerate and smart enough to keep mentioning that he wants to respect our work and keep his fork unofficial for the moment, which deserves a huge THANK YOU from my side!

    Talking about @xdnax:
    He did a great job in contributing to the development of this app during the last months.
    Unfortunately, I didn't have his contributions on my radar for quite a while.
    Since we love to work with other motivated and decent developers like him, we are happy to announce that he is now the third "official developmer" of BCL.
    Welcome to the team, @xdnax!

    Some people noticed the appearance of a semi-official version 1.0.5.
    Although I never had time to publish an official build, I indeed created this version and uploaded it with a "v1.0.5" tag to our GitHub repo.
    This is where the F-Droid build system picked it up and created an APK from it, which I myself wasn't aware of for some while. Sorry for the confusion guys...

    During the last days, we organized our internal communication and unified our contributions to bring out a new official version.
    Well, here we go: I'm happy to announce that we finally release version 1.1.0!
    Link: https://www.androidfilehost.com/?fid=817906626617956614
    Please don't get confused about the numbering: This release includes all improvements of @xdnax and more, and is not a major version step because it doesn't introduce any breaking behavior changes.
    Happy charging, opening post will be updated soon!

    Changelog:
    • UI & icon redesign @xdnax
    • Custom control file data support @xdnax
    • Improved control file lists @real_milux
    • ICS (Android 4.0, API 14) compatibility @real_milux
    • Pixel/Pixel 2 support fixes @xdnax
    • Added control files for Pixel/Pixel 2, Xiaomi Redmi Note 2, Sony XPERIA Mini, Le 1s, Huawei P10 lite, HTC One, Motorola Defy+, Xiaomi Mi A1
    • Bengali translation @AdroitAdorKhan
    • Lots of bugfixes and minor improvements
    22
    Source code: https://github.com/sriharshaarangi/BatteryChargeLimit
    App v0.3: https://www.androidfilehost.com/?fid=745425885120716170
    Changelog:
    - Updated to support 7.1.1
    - Auto-select the battery charging file for Samsung, Pixel and Newus devices
    - Added clear battery stats button
    - Auto-whitelisting from doze
    19
    Update to version 1.1.1

    This is mainly a bug fixing update, with loads of improvements. Should reduce crashes as well.
    Download link: https://www.androidfilehost.com/?fid=674106145207486851
    The update will be available on Play Store soon[UPDATE: Now available]
    Changelog:
    • Fix charging status layout issues and misc UI fixes @xdnax
    • Added (i) Switch to disable toasts on service changes (ii)Add switch to show temp. in notification @xdnax
    • Ensuring write permissions on the charging control file @real_milux
    • Fixed notification sound on limit reach @sriharshaarangi
    • Fixed a bug causing crash
    • Added Russian translation
    • Updated Bengali, German and Brazilian Portuguese translations
    • Added control file for Amazon Tate
    • Other minor fixes