yashsingh1/xdaforums huggingface dataset:
[Android Apps and Games] nubla:
Battery Charge Limit is never stopping charging, though it notifies when the charge limit is reached.

Control file /sys/class/power_supply/battery/status exists, but its value is always "Charging", even when the device is at 100% and showing fully charged.

I tried using adb as root to write "Discharging" but when I check the value it is still "Charging".

I first had to change permissions from 444 to 664, and then tried: echo "Discharging" > status

On a Samsung Gio GT-S5660M running Cyanogenmod 11.

Any ideas what's going on and what else I could try?
[Android Apps and Games] amn1987:
Was it working in A10?
[Android Apps and Games] nubla:
Android 10? This old phone was on 2.3.4, and CyanogenMod 11 (Android 4.4.4) is the most recent ROM I could find for it. I did not try Battery Charge Limit with anything else for the Samsung Gio.

In contrast, BCL works great on an LG G4 running /e/-OS based on Android 9, with control file data /sys/class/power_supply/battery/battery_charging_enabled, 1, 0. Permissions for the file are 644.

I'm wondering if different control file data is needed for the Gio, or if there could be another issue?
[Android Apps and Games] Flyview:
Has anyone noticed that the service does not start if plugging in while the screen is off? Once the screen is turned on, the service starts and limits charging.
[Android Apps and Games] amn1987:
Haven't encountered this issue in any of my devices so far. Check if Battery Optimization is actually disabled or not.
[Android Apps and Games] Flyview:
I just checked and it's not optimized, even though I never put it on the do not optimize list...strange.
[Android Apps and Games] amn1987:
Oops! I misread it as Android 11. Anyways was BCL working OK previously?
[Android Apps and Games] amn1987:
The app automatically disables BO IIRC. Since it's setup correctly maybe someone else can point out what's the issue.
[Android Apps and Games] nubla:
BCL was not used with the stock Samsung Gio previously, only with CM11 which is also the only ROM tried.

Is there anything I can do to check the functionality?
[Android Apps and Games] amn1987:
OK. Check out all the other charge control files if any. Maybe a different kernel is needed or even a different ROM. Are you using Magisk?
[Android Apps and Games] nubla:
No Magisk. I believe CyanogenMod is rooted by default. When BCL is started there is a popup that shows it is granted superuser rights.

BCL shows only one control file, /sys/class/power_supply/battery/status with states Charging and Discharging, nominally for a Motorola Defy+ MB526 (experimental). That file exists, but its value is always Charging even when the battery is at 100% and the lock screen shows "Charged".

Here are the contents of /sys/class/power_supply/battery:

root@gio:/sys/class/power_supply/battery # ls -la
-rw-rw---- root root 4096 2021-05-17 11:38 amp_down
-rw-rw---- root root 4096 2021-05-17 11:38 batt_low_noty
-r--r--r-- root root 4096 2021-05-17 00:37 batt_temp
-r--r--r-- root root 4096 2021-05-17 11:38 batt_temp_adc
-r--r--r-- root root 4096 2021-05-17 11:38 batt_temp_adc_aver
-r--r--r-- root root 4096 2021-05-17 11:38 batt_temp_aver
-r--r--r-- root root 4096 2021-05-17 11:38 batt_vf_adc
-r--r--r-- root root 4096 2021-05-17 11:38 batt_vol
-r--r--r-- root root 4096 2021-05-17 11:38 batt_vol_adc
-r--r--r-- root root 4096 2021-05-17 11:38 batt_vol_adc_aver
-r--r--r-- root root 4096 2021-05-17 11:38 batt_vol_aver
-rw-rw---- root root 4096 2021-05-17 11:38 bt_down
-rw-rw---- root root 4096 2021-05-17 11:38 camcoder_down
-rw-rw---- root root 4096 2021-05-17 11:38 camera_down
-rw-rw---- root root 4096 2021-05-17 11:38 camera_flash_down
-r--r--r-- root root 4096 2021-05-17 00:37 capacity
-rw-rw---- root root 4096 2021-05-17 11:38 control_tmp
lrwxrwxrwx root root 2021-05-17 11:38 device -> ../../../msm-battery
-r--r--r-- root root 4096 2021-05-17 00:37 health
-rw-rw---- root root 4096 2021-05-17 11:38 keypad_backlight
-rw-rw---- root root 4096 2021-05-17 11:38 lcd_backlight
-rw-rw---- root root 4096 2021-05-17 11:38 lcd_dimming
drwxr-xr-x root root 2021-05-17 11:38 power
-r--r--r-- root root 4096 2021-05-17 00:37 present
-r--r--r-- root root 4096 2021-05-17 00:37 status
lrwxrwxrwx root root 2021-05-17 11:38 subsystem -> ../../../../../class/power_supply
-rw-rw---- root root 4096 2021-05-17 11:38 talk_gsm
-rw-rw---- root root 4096 2021-05-17 11:38 talk_wcdma
-r--r--r-- root root 4096 2021-05-17 00:37 technology
-r--r--r-- root root 4096 2021-05-17 11:38 type
-rw-r--r-- root root 4096 2021-05-17 11:38 uevent
-rw-rw---- root root 4096 2021-05-17 11:38 vibrator
-rw-rw---- root root 4096 2021-05-17 11:38 video_down
-r--r--r-- root root 4096 2021-05-17 11:38 voltage_max_design
-r--r--r-- root root 4096 2021-05-17 11:38 voltage_min_design
-r--r--r-- root root 4096 2021-05-17 00:37 voltage_now

There is also /sys/class/power_supply/ac:

root@gio:/sys/class/power_supply/ac # ls -la
lrwxrwxrwx root root 2021-05-17 11:53 device -> ../../../msm-battery
-r--r--r-- root root 4096 2021-05-17 00:37 online
drwxr-xr-x root root 2021-05-17 11:53 power
lrwxrwxrwx root root 2021-05-17 11:53 subsystem -> ../../../../../class/power_supply
-r--r--r-- root root 4096 2021-05-17 11:53 type
-rw-r--r-- root root 4096 2021-05-17 11:53 uevent

Is there a way to tell if the current kernel is suitable? There aren't many options for a different newish ROM on this ancient phone.
[Android Apps and Games] Flyview:
I think the problem might be a trickle charge. Accubattery reports 2%/h charge even though BCL is saying it's just maintaining charge. That or something resets the file periodically, and BCL doesn't maintain it. Would you please post screenshots of exactly how you have it set up? There's a lot of options, maybe I haven't checked the right stuff for the Pixel 4 XL.

I might have to write my own app for this! :p This one hasn't been updated in 3 years?
[Android Apps and Games] amn1987:
Having used BCL in my devices over the years from the last couple of months I have switched to using Tasker as it also allows battery temp. based controls. BCL had no issues with trickle charging at least in my case. I had manually limited charging current to 40mA. In my Poco F1 bypass charging used to kick in only when fully charged. But this wasn't an acceptable solution as charging to 100% and worse staying at that level for prolonged periods is undesirable. Instead just limiting the max. charging voltage to say 4.1V fools the system into thinking charging is complete and so bypass charging can be triggered at any arbitrary level.

If BCL isn't working out as expected maybe try Tasker or Macrodroid. Just a matter of using the right terminal commands.
[Android Apps and Games] amn1987:
None of those files look particularly promising. You might manually check them after excluding the ones that obviously aren't related to charging.

Just limiting the max. charging voltage is sufficient to limit the battery charge levels. But there's no voltage_max. Maybe try creating it on your own. In some devices the value there is in milli volts but in others it's micro volts.
[Android Apps and Games] Flyview:
I finally figured it out by trial and error:

For my Pixel 4XL I also needed these set to the opposite of their defaults:

Enforce charge limit: disabled

Always Write CFTRL File: enabled

Works like a charm now. I updated my initial post in this thread to include that for the Pixel 4 XL.

I would love to make a non-root app to accomplish this. I have an idea that might work. Are you able to do it without root with Tasker?
[Android Apps and Games] amn1987:
No. Root is compulsory. Unless if it comes implemented out of the box in the ROM I think. Are you on the stock ROM? Smart Charging is included in most custom ROMs.
[Android Apps and Games] Flyview:
Yes, stock ROM for me!
[Android Apps and Games] nubla:
Yeah, "status" seems like the most sensible file, but for some reason its value is not changing from "Charging".

I'm not able to create any new file (eg. voltage_max). Is there something simple I'm missing? I used adb, switch to root user, and neither "touch voltage_max" nor "vi voltage_max" create a file in the /sys/class/power_supply/battery directory. vi complains of "no such file or directory" when trying to save.
[Android Apps and Games] amn1987:
Could be a kernel or ROM limitation. At this point you could use a 1A charger and use Accubattery to sound an alarm when battery reaches say 75/80%. Voltage can't be modified but this should stop it from going much above 4.2V.
[Android Apps and Games] the bolt of thunder:
Does anybody have this working on a OnePlus 9 Pro?
[Android Apps and Games] Dosclic98:
Hi, I am facing an issue where i connect my phone, the battery charges up to the set limit, it discharges down to the discharge limit but then it does not start the charge again. I am on Lineage OS 18.1 and Redmi note 7.
[Android Apps and Games] nubla:
Is there a way to verify this?
[Android Apps and Games] amn1987:
Sorry I have no idea. In some of my devices while charging control worked fine in older Android versions limiting max. charging voltage and current only started working in P/Q. Prior to that the files in control of charging voltage and current were read only.
[Android Apps and Games] mystery007:
Works for me at 8T but not at 9Pro.
[Android Apps and Games] the bolt of thunder:
Works on my 6t also. Can't get it working on 9 Pro
[Android Apps and Games] nubla:
Can't that be at least temporarily addressed with adb and chmod? I noticed that my /sys/class/power_supply/battery/status file has 444 permissions, i.e. read only. With adb and chmod I changed it to 644, but I'm really confused why I cannot manually write to it with echo or vi, or create a new file in that directory.
[Android Apps and Games] Nik2424:
Thanks works perfectly on ZTE Axon 7 android 7.1.1.

I agree with above poster, a feature to not maintain charge would be really nice or if we could customize between what percents to maintain. For example I would like to set between 40-85.

excellent work sir, keep it up!
[Android Apps and Games] savvymatthew:
Ouuuu I didn't even think of that custom percents for maintaining would be great to!!!!
[Android Apps and Games] xenyz:
Thanks for making it open-source.

On my Nexus 4 the charging is controlled by setting 1/0 (don't charge/charge) in /sys/module/pm8921_charger/parameters/disabled

Mind adding it in? If not, I can hack the source at least :D
[Android Apps and Games] HikingMoose:
Wait...what? So you want your phone to let the battery run down to 40% overnight before it starts to charge it to 85? As in, it's finished charging at 85 and you want it to not apply a charge until it's at 40? Your phone shouldn't drop to 40% overnight. I lose maybe 1% overnight.

Maybe I'm misunderstanding what you're​ asking for. (That happens a lot) lol
[Android Apps and Games] tiennhu89:
Install on my Galaxy A9 Pro (A910F) and it dont work. My phone still charge to 94% when i remove my charge. I choose defauls setting.
[Android Apps and Games] Nik2424:
Yup exactly what I want. I know it won't drop that much but having that control can be nice.

I was thinking of people using a tablet which is always on ac(like my mother), that would keep the battery between the optimum 40-80% range.

basically, with custom settings, anyone can use the app like they want to :)
[Android Apps and Games] sriharshaarangi:
What was the default selected file? Is it battery_slat_mode for Samsung or charging_enabled?
[Android Apps and Games] tiennhu89:
battery_slat_mode for Samsung. i didnt change anything, just install it and enable, get root, done.
[Android Apps and Games] billubakra:
Also not working in S7 non-rooted.
[Android Apps and Games] Skull97:
Of course it won't work. Why do you think you will be able to make it work on non-rooted phones?
[Android Apps and Games] DMagister:
I just do this with two flows in the Automagic app
[Android Apps and Games] HikingMoose:
Nice!

---------- Post added at 09:16 AM ---------- Previous post was at 08:52 AM ----------

After I posed I thought of a great use for what you were asking lol. I want to leave an old, deactivated phone for my music, and maybe to connect to my OBDII adapter so I can run Torque while driving and watch the live data and gas mileage. So I think I'm going to try the Automate flows shown above and just leave my old device plugged in at all times. Great idea.
[Android Apps and Games] mesvam:
Thank you so much for making this, great work. I've been looking for this for a while.

A couple ideas for the future:

Make the range configurable. Right now it's range is 3%, so if you set it to 80, it cycles between 77-80. It would be nice to be able to cycle between a smaller or larger range like 79-80 or 75-80. If you could configure both the lower and upper limits that would be great.

Don't limit the max level to 40 to 99. Just let it be the full range 0-99. Sure, it's a little dangerous to let people empty their phone, but as a power user, I find these arbitrary limitations kind of annoying. For the most part, we all know what we're doing here. If you still want to keep a safety margin, at least lower it to 10%.

Since this is a battery saver app, perhaps add a current limiting feature, since slower charging also prolongs battery life. Those of us who leave it on the charger overnight or all day long, don't need fast charging. You could specify it in mA or better as a C-rate, which is relative to battery capacity and more commonly used in specifications. I have a /sys/class/power_supply/battery/input_current_max file that can be set lower. There's also some other settings in /sys/class/power_supply/usb/ and some other folders that have an effect.

Voltage limit, in addition to (or instead of) state of charge limit. Battery University (BU-808b) says staying above 4.10V is harmful and the optimal level is 3.92V.
[Android Apps and Games] chancex:
Can set less than 40%(or custom rate) at the beginning of charging?
[Android Apps and Games] kimpot04:
Thanks man.. This is now working on my Galaxy Grand Prime
[Android Apps and Games] AdroitAdorKhan:
This feature would be great! and lowering the voltage probably charges bit fast (i think so)!

On my XZ3, Sony already implemented CHARGING OPTIMIZATION which charges to 90% and charges on lower volt.

I checked "/sys/class/power_supply/battery/input_current_max" file and it was 100000....so it would be really awesome if BATTERYCHARGELIMIT can have those features too! then we all can proloooooong our batteries! :P
[Android Apps and Games] blueberry.sky:
Cycling over a larger range provides no benefit for li-ions, can cause more wear. As it's currently set appears to be ideal.

Low voltage causes more stress (wear) on li-ions just like high voltage does. 40 is about the lowest you should normally set it to. And you'd really only use that if you almost always kept the device plugged in. For true 24/7/365 ac powered, like a project were a tablet will be wall mounted, you could maybe do 30. Questionable benefit tho. It would be best if it's not easy to set that low.

Limiting percentage = limiting voltage.

The OP knew what he was doing when he picked the original max limit range & cycling range.
[Android Apps and Games] mesvam:
I know. I actually want to make the range more narrow, so that it cycles between 79-80. But if you're going to change that, then why not make it configurable too! :) I've had problems with battery gauges that drop very quickly after a charge. If you'd set the range to 2% it would cycle very rapidly (< 10s), so I can imagine someone would want to make it 5% or 7% to prevent that.

I'm aware of this and I do not plan on setting it much lower. However, the whole philosophy of protecting the user from themselves is repulsive to me. Just because you shouldn't set it below 40 doesn't mean the app should actively prevent you from doing so. And it's always possible that there is a legitimate use case you haven't thought of. No body says you can only use a hammer on nails.

Please provide general purpose tools and let the user choose how to use them. If you have to display a warning that's fine, but there's something wrong with making it impossible because of an arbitrary limit the author had in mind. We're mostly power users here and we love to tinker, so these limitations can be pretty frustrating especially if they could easily be removed. We didn't root our phones for nothing.

So tell me... what percentage should I set if I want voltage to stay at 3.7V? Not so easy is it? ;) In some cases you can approximate percentage using voltage and vice versa, but it's not so intuitive.

Also, usually percentage can't be directly translated into voltage since voltage rises during charging because batteries experience hysteresis. This is why the charge and discharge I-V curves are not the same, and also why chargers don't use voltage to determine state of charge. So if you want to charge to 4.1V, ideally you'd want to set it as max voltage so that trickle charging initiates around 4.0V and slowly goes to 4.1V. But this might not be configurable in the hardware, so cutting the current would still work.
[Android Apps and Games] danecr7:
Hi guys and many thanks to the dev for this piece of genius.

I noticed that one my phone when I unplug the charger, the app closing triggers the battery saver, is it the normal behaviour or maybe it is related to my phone, ROM or Kernel.

Phone: OnePlus 3

ROM: Freedom OS 2.6.1 by Nevax

Kernel: Franco Kernel
[Android Apps and Games] ShanxRoux:
Pixel 4xl here, manage to stop the charge at 80 by following your guide. But the battery is not discharging and maintain at 80 while plugged in, not follow my charging setup (72-80). Appreciate your help.
[Android Apps and Games] amn1987:
Back then it never occurred to me to try changing the permissions via ADB. It's gonna reset after every reboot, isn't it? As to why that's the case I have no idea.
[Android Apps and Games] amn1987:
If It doesn't discharge while plugged in that's good. It means bypass charging is probably working. This well help prolong the useful life of the battery.
[Android Apps and Games] nubla:
Yes, but even as a temporary measure at least it could help confirm which files work to control charging.

Right now I'm stumped. If writing is not possible, then it could explain why BCL is not working. The default control file "status" exists but never changes value from Charging.
[Android Apps and Games] amn1987:
The "status" file just reports the current state of charging whether plugged, unplugged or full. It doesn't have any control over charging.
[Android Apps and Games] nubla:
It's listed as an experimental control file: https://github.com/sriharshaarangi/...f/app/src/main/res/raw/control_files.json#L75

None of the other control files exist on this Cyanogenmod 11 ROM for the Samsung Gio: https://xdaforums.com/t/rom-cyanogenmod-11-final-05-08-2015.3066771/
[Android Apps and Games] amn1987:
I stand corrected. In none of my devices though including some ranging back to early 2016 does it have any effect.
[Android Apps and Games] creatorb:
Hi, is it support for infinix x510 (https://xdaforums.com/f/infinix-hot-2.4513/) ? because i don't see on https://github.com/sriharshaarangi/...aster/app/src/main/res/raw/control_files.json
[Android Apps and Games] B1tWeaver:
After messing around with it last night, I was able to get it working on my 9 Pro.

Have the control file data of

/sys/class/oplus_chg/usb/chg_enable, 1, 0

I don't have either of the advanced settings toggled on for it to work. Only tested it on USB and not sure if it'll work with the wireless charging as well.
[Android Apps and Games] the bolt of thunder:
Going to try when I get home. Thanks for this.

Edit. Can confirm this works on the wall charger. Thanks so much dude!
[Android Apps and Games] B1tWeaver:
Glad it worked. I couldn't believe I found it last night but I'm glad I did as I wanted it to work as well!

I checked with my wireless charger earlier and no dice with that file. I'm sure there is a way of getting wireless working as there is a wireless folder next to the usb folder. I just haven't had a chance to mess with it since I normally charge with USB. I guess its a sort of pick your preferred way of charging unless you wanna change it out each time you switch.
[Android Apps and Games] the bolt of thunder:
I usually charge with USB as well. If I had any idea on how the files work, I would mess with it, but honestly I'm no help. >.<
[Android Apps and Games] B1tWeaver:
Honestly all I did was watch what files changed when I plugged it in and unplugged it. I just happened upon the oplus_chg and looked inside and saw usb and wireless. Just from there I narrowed down what files changed and how. I'll probably mess around with it this weekend and see if I can get the wireless charging part working incase someone prefers that way.
[Android Apps and Games] dlareghoe:
Can confirm, on OnePlus9 Pro it's working for wired and wireless charging with

wired:
/sys/class/oplus_chg/usb/chg_enable, 1, 0
wireless:
/sys/class/oplus_chg/wireless/chg_enable, 1, 0

I am changing always both files using Tasker. Working very well.
[Android Apps and Games] B1tWeaver:
I was able to get the wireless to turn off with /sys/class/oplus_chg/wireless/chg_enable, 1, 0 in BCL but it never turned back on. I would have to manually turn the service off then on again to have it reset and be able to charge. Did you find the same thing with Tasker?

Also /sys/class/oplus_chg/wireless/batt_chg_enable, 1, 0 would basically hold the charge at level with the wireless charger. It seemed to really mess with my wifi as well while I used this file. Not sure if coincidence or actually affects it.
[Android Apps and Games] dlareghoe:
I had only one regular charging-session over night (Europe). This one was charging as expected.

I tried one more by hand and it worked also well right now.

All with Tasker
[Android Apps and Games] B1tWeaver:
Nice, I guess its just something up with BCL that doesn't want to re-enable it. I'll have to install Tasker again and see if I can get it working.
[Android Apps and Games] dlareghoe:
Now I got one strange behavior.

As I put in the phone into wireless charger, it charged until 80% as expected. But after discharging, it startet NOT again charging. After taking out of charger and putting back, it startet.

Have not found out, the reason for this.
[Android Apps and Games] the bolt of thunder:
So we need to choose if we want to use usb charging or wireless charging if we want to use battery limit?
[Android Apps and Games] mystery007:
Is there any step-by-step introduction to let it run at 1+ 9Pro, please?
[Android Apps and Games] diorlee90:
Sorry for my bad english

Yeah after read this

I've checked and found out control file on my phone Mi11ultra's control file for battery charge limit worked. Battery Charge Limit on Android 11 not work like before we known

First, your device require root permission to run Battery Charge Limit, then go to setting

Turn on "Configurable CTRL File Data" and touch "Configure Control Data" then touch "Understand" and type like below:

/sys/class/qcom-battery/input_suspend

0

1

then touch "UPDATE CONTROL FILE DATA" and done, battery charge limit worked

You guys can watch video below for sure: From original control file not work then after re-config control file and work perfectly.

P/s: From 84% to 85% i made app for auto charge limit itself and you guys can go to end of video for result.

Good health for battery charge overnight
[Android Apps and Games] AlainL:
Hi

Nice app, thanks!

I have a little problem :

When charge limit is reached (80%), charge stop but then I have constant toast notifications "Battery Limit Service Disabled!" than "Battery Limit Service Enabled!" until battery drop to 79%. Screen is always on when toasts popup.

Anyone knows how to solve this problem ?

Samsung Note 9, stock ROM with 12.2020 update (Android 10), Magisk 23.

Battery Charge Limit settings :

- Min : 75%

- Max : 80%

- Control file : batt_slate_mode

- Hide toast on service change : unchecked

- Enforce Charge limit : checked

- Always handle power evente : unchecked

- Always write CTRL file : checked