yashsingh1/xdaforums huggingface dataset:
[Android Apps and Games] ACiDxCHRiST:
Thanks for that info, but unfortunately, it didn't work. Let me know from these screenshots if you see anything wrong.
[Android Apps and Games] tassos_chry:
The file needs to be a script so rename it to something like "battery_stats_reset_perms_fix.sh" in your example
[Android Apps and Games] ACiDxCHRiST:
I don't think it is necessary to add the file extension. I have never done it in the past for Magisk service.d scripts. I did try it though and I also tried with and without a newline at the end of the file. Same results. Automatic or manual battery stats reset does not work.

-Edit

I should also add that I am currently using Snoke Kernel R15
[Android Apps and Games] guest4711:
I would add the shebang at the beginning of the script:

#!/system/bin/sh
sepolicy-inject --live "allow system_server su fd use"
sepolicy-inject --live "allow system_server su fifo_file write"

But I just checked: On my phone there is no command called "sepolicy-inject". So the script will do nothing...

To get it working we need some tools, e. g. https://xdaforums.com/android/software-hacking/mod-universal-init-d-injector-wip-t3692105
[Android Apps and Games] ACiDxCHRiST:
Thanks, but I am not *that* concerned with it. I use AccuBattery for my main source of battery usage related information anyways. I also have EX Kernel Manager and can use the Battery Monitor in that as well. Both of those options are superior to the built-in Android implementation so getting the reset battery stats to work is not critical for me.
[Android Apps and Games] :
V1.1.1 unofficial release with new experimental Pixel 2 support, for those of you who are having troubles.

Check out my GitHub here for all old and new changes: https://github.com/xdnax/BatteryChargeLimit/tree/local
[Android Apps and Games] marbertshere:
Hey thanks again mike. I just want to let you know I did get 1.1 working with taimen but i'll try out 1.1.1 anyway. After unplugging I get a notification saying that if the phone is unplugged i must stop the service. What happens if I do not? Is there anyway to have it detect an unplug and stop the service?

It's not a big deal, but I'm just curious cause I didn't receive that message on my 6P with version 1.0.4. Thanks for your hard work!
[Android Apps and Games] post-mortem:
You could run BetterBatteryStats to see if the phone goes into deep sleep mode over night, or if it is indeed running overtime.
[Android Apps and Games] ACiDxCHRiST:
Working great on Pixel 2 XL. Much better than input_suspend. Reset Battery Stats is not working (You already know that, just writing that so other Pixel 2 XL users are aware)

If you use the input_suspend control file (which is the only one available on v1.1 for the Pixel 2 XL) then you will see that persistent notification until your battery drops below your recharge limit and then it will automatically go away. Or use v1.1.1 instead which has proper support for taimen and uses the charge_disable control file and the notification will go away as soon as you unplug the charger.

Thanks for the info.
[Android Apps and Games] :
That notification I changed to be more informative... This is why.

On all devices I tested thus far, when the phone is below the charging limit and you unplug the charger, the phones know the charger was unplugged as it always has and will dismiss the notification and service... However, once your phone hits the limit and it starts to maintain the battery between two values, afaik from looking at source and the config files used, the phone doesn't see whether a charger is still plugged in or not, it ONLY sees whether it is charging... Therefore, once the phone hit the battery limit and charging is disabled, the phone does not know whether the charger is still in... Therefore, if the charger is still in and it hits the lower maintaining value, it will start recharging again like usual. But if the charger was removed, once phone hits the lower value and sees that no current is being given when it WANTS to charge, it will shut off the service and dismiss notification... Therefore, if you set a larger maintaining range like me (10%ish), if I unplug the phone from the charger in the maintaining state, the notification will stay there for a long time. The notification I added quickly dismisses and resets the service properly. Whether you let the device go below the bottom maintaining value and see its not charging or if you dismiss it yourself when you're done, it will reset properly. The notification is only to dismiss the notification faster if you set a wider maintaining range.

Hopefully that makes sense. In the end, its not a big deal, I added it for myself for efficiency since I didn't want the service notification hanging around a long time. Each device is slightly different though and some may act differently. Again, this was made only for the devices I was using this app with (as these builds reflect personal interests).
[Android Apps and Games] marbertshere:
It's certainly not a big deal. Just curious. I have never had my phone drop below the lower charging limit so I guess I would not have known what happens when it is below that. Would you have any interest in adding an option to play a notification when the upper charging limit is reached? I'm sure I can do that with Tasker, so no worries if you don't feel the need.

Edit: now i remember why i didn't see that notification before! I blocked all notifications from the app on my last phone because I found the ongoing notification so annoying. So , big thanks for that haha. Totally forgot I did that.
[Android Apps and Games] iluvatrix:
Hi

Does anyone have a solution for my Nexus 6?

I can have the phone stop charging at 80 but it doesn't charge again until I restart the phone.

I am only able to use charging_enabled control file.

Thanks
[Android Apps and Games] magik666:
I use A5 2017 Dual Sim - Rooted with AXES Rom v1.

When Phone switch ON/Active - sometimes charging stopped at 78% ( i put setting to 98%)

When Phone Switched OFF - normal can reach 100%
[Android Apps and Games] hgmichna:
Read and understand

Unable to read, comprehend, and follow simple instructions.
[Android Apps and Games] :
I'll think about adding a sound... If you set your limits close to each other though for a long time, it'll be a lot of beeping!
[Android Apps and Games] iamstrong:
Usefull apk ?

I have question:

I limit battery charging to 99%. When fully charged automatically app will stop charging right?

So in this case, what status my phone now when battery full and I didn't remove the charger?

Using battery mode or power mode? Because, I'm using my phone for couple minutes battery still 99% while charger connected.

Thank in advance
[Android Apps and Games] jonahmt21:
this is the app behavior on my OP5T, i set it to 80 upper and 40 lower and reset battery stats on. when it reaches 80%, the notification stays on and the battery stats didnt reset. still true after unplugging.

still a great app being able to limit charging to a certain %. thums up!
[Android Apps and Games] jonahmt21:
tried 1.1.1 on OP5t and notification still wont auto disappear.
[Android Apps and Games] tassos_chry:
[MENTION=6280728]xdnax[/MENTION] explained it thoroughly above. The notification will disappear and the battery stats will reset once the lower limit is reached. If you dont want to wait until then you can use the disable service button in the notification
[Android Apps and Games] jonahmt21:
Yes he did. Thanks
[Android Apps and Games] HamburgerxDDD:
What control file should i use in op5?
[Android Apps and Games] Infy_AsiX:
I just picked up a ZTE Axon 7 and have found some very useful interesting things regarding it's charging. Testing on stock 7.1.1 it functions similarly to Nexus/Pixel having battery_charging_enabled available as well as the generic charging_enabled. It functions similarly to the Pixel someone previously mentioned here with the /battery/current_now being positive for discharging and negative for charging. Monitoring current_now it does keep near 0 when limited by the battery_charging_enabled file.

What's more important is /battery/voltage_max can be edited to a lower limit. The charging voltage will respect this limit as the new constant-voltage phase, thereby slowing the current with the saturation charge until at that voltage level's "full" capacity limit. The file charge_type reads as Taper instead of Fast during this phase. This method is ideal for usage while charging, as the power source is just used to run the device once at the "full" limit. Although note it's likely not suitable to hold a particularly higher voltage for extended periods with this method.

Using the percentage level charge limit alone has the voltage when charging reach higher than the stopped charging voltage, particularly even more so if using a fast charger. It can't really be avoided as slower current saturation charge normally starts after 80%.

Combining both types of method could be better for a device with low usage. But due to overheating issues prevalent in modern smartphones, it seems ideal to keep the device powered by mains to avoid needing to charge the battery under heat while also adding further charging heat back into the mix.

Definitely worth checking if more devices support the /battery/voltage_max control. It's a simple setting that stops charging with a new normal charging curve profile and when stopped both the charging_enabled files are unchanged. Which brings up a separate thought, in the interest of safety does the app not re-enable charging respecting when the system temperature safety off limits are engaged?

Checking a Sony Z3C and Samsung S3 does not have the file in battery. They have it in USB as does the ZTE Axon 7 too but that file's default is 0 and doesn't seem to have an effect. Note I've only just noticed all this, further testing for confirming is required.
[Android Apps and Games] no_name_no:
Hi,

I have had mentioned previously in this thread that on my Galaxy S7 there is a file so-called fg_full_voltage (sys/class/power_supply/battery), which contais the end of charge voltage of my device (4.35V). I am very new to android/programming roms in general, do you maybe know how I could change this value? I tried this with a text editor, but i got no permissions for changing this value. It would really interest me what happens then!
[Android Apps and Games] Infy_AsiX:
Hey, that's ok. I've no experience except I like to read, explore and tinker. The files can be edited with a root explorer app and text editor. However the intended file needs to have write access permission enabled by default. Trying to change the permission manually to allow write won't stick and is controlled by the kernel. Note that you can open the uevent file in each power_supply sub-folder for a quick overview of data contents. There may be other alternatives, restricted_charging is an available file on the Ax7 for example. Someone posted their Pixel2 XL /battery contents, if I recall correctly that had a qnovo_voltage_max as well as the voltage_max file.
[Android Apps and Games] no_name_no:
Thanks for your help! File uevent on my S7 does not contain a voltage limit and fg_full_voltage has rw-rw-r permissions. Only POWER_SUPPLY_CHARGE_CONTROL_LIMIT i think could maybe be useful, but i can't imagine what this variable indicates. So, is there any way to edit fg_full_voltage? Because like i said, i tried a root explorer app and text editor, but nothing happend then. I think maybe this could changed by a script before booting or something?
[Android Apps and Games] Infy_AsiX:
Your text editor uses root too right? Oops, uevent only lists everything on my Ax7, the other two don't. You have a lot of writable files there, totally different to my S3 on LOS14.1 too. I'd assume that fg stands for Fuel Gauge and unfortunately that's just the percentage State of Charge controller.
[Android Apps and Games] no_name_no:
Well I am using Explorer by Speed Software and tried it in this App and also with the App called Quick Edit. But only Quick Edit asks for root access. Quick Edit shows me "java.io.FileNotFoundException /sys/class/power_supply/battery/fg_full_voltage (Permission denied)" :(

Hmm.. I found another file batt_tune_float_voltage, with value 43500 - otherwise I think there is no file which colud limit the batttery voltage.
[Android Apps and Games] Infy_AsiX:
I use the old Root Browser 2.3.9.0 with it's text editor, before it was sold off, get it safely from Apkmirror.

That file actually fits the description. Just needs testing. You'll want a way to monitor voltage and current to show any change. I use Cool Tool but it requires some setup. Remember be sensible with your choices and have the required background knowledge.
[Android Apps and Games] no_name_no:
Unfortunately Root browser fails to edit that file, too. I think morning I am going to try to find out how i can change these values, thank you so far!
[Android Apps and Games] lalala9q:
I have an S7 edge exynos and tried to edit the file as well. It's not possible to write:

ro2lte:/ # cat /sys/devices/battery/power_supply/battery/fg_full_voltage
42875
hero2lte:/ # echo 42975 > /sys/devices/battery/power_supply/battery/fg_full_voltage
1|hero2lte:/ # cat /sys/devices/battery/power_supply/battery/fg_full_voltage
42875
hero2lte:/ #

It seems it is meant to be just read, now written to. I guess this applies to all fg_* files. See the "1" in the terminal output after the echo command.

Actually it's a good idea to your hands off writing the maximum voltage. A too high voltage would, if high enough, make your battery explode....
[Android Apps and Games] ACiDxCHRiST:
So I have reinstalled Battery Charge Limit v1.1.1 and plugged the phone in for a little while. It charged up to 80% and then stopped like it should, and no issues so far. I haven't seen anymore screen on or battery drain issues yet. I will post again if anything changes.
[Android Apps and Games] :
Thank you for the updates. Please also try the official app when debugging to make sure my personal branch isn't causing problems. Again, I haven't changed any functional code, but you never know. But it seems something was happening. Let it hit the minimum threshold or let it sit and see if something wonky happens again.
[Android Apps and Games] ACiDxCHRiST:
Yeah, taimen. My first step is to reproduce the problem. If I can replicate it and solve it by removing Battery Charge Limit again, then I will move on to trying the other versions.

I think this *might* be an 8.1 issue though. I noticed similar but not the same behavior on my Nexus 6P that I updated to 8.1 and I also saw a post somewhere that said they were having issues with the screen taking a long time to come on after they pressed the power button on 8.1. So it might have nothing to do with Battery Charge Limit at all. Kinda weird that everything miraculously fixed itself after I uninstalled Battery Charge Limit despite having tried numerous things before I did that. Also, the battery draining to 0 on my Pixel 2 XL while plugged in overnight is super weird.
[Android Apps and Games] Infy_AsiX:
The idea is to lower not raise the voltage. If the system for some reason allows a higher than rated voltage, a battery's functioning PCB (protection circuit) prevents over-voltage. I hope no one tries to, it's not something advisable to test without proper knowledge and equipment.

Some on topic facts, the stock Axon 7 has voltage_max at 4400, the same as voltage_max_design and it's printed official rating. Though I haven't fully charged it yet, I'm not interested in capacity at the cost of longevity. I haven't seen a report of a phone battery being charged to 4.4V yet. It seems manufacturer's use the higher rating to simply be able to quote a higher Ah (ampere hours), it's misleading as it's not usable and therefore untrue. Here a table of tests from Qnovo that shows in the S7 series charging is limited to 4.35V rather than the rated 4.4V rating.

It's helpful when tests are made and there's some sources or proof to claims being made. I'm now interested whether the voltage_max and voltage_max_design (latter is read-only) in the S7's is 4350 or 4400. If anyone can check that for me I'd be grateful. If it's 4350, I wouldn't trust my Axon 7's stock 4400 safely charging to full.

Two Qnovo sources on the S7 issue:

https://qnovo.com/88-charging-samsung-galaxy-s7-edge/

https://qnovo.com/90-charging-galaxy-s7/

edit: I just remembered my Z3C has the voltage_max function set to 4250 of the 4350 when using the stock firmware updated feature to limit charging. They change something else too to remap the fuel gauge percentage SoC to the new lower "100%".
[Android Apps and Games] F_R_I_T_Z:
I'm running the nexus 6p + lineage 15. so far, the version 1.0.4 is working 100% perfect.
[Android Apps and Games] ACiDxCHRiST:
The issue with the screen not turning on has come back. So I uninstalled Battery Charge Limit again and the problems went away. I tried Magic Charging Switch magisk module which has similar functionality to this app but is command line and has to be configured in terminal emulator. The funny thing is, once I installed and configured that, the problem is back.

I am curious if both of these programs are suffering from some kind of memory leak or something.
[Android Apps and Games] guest4711:
So it's possible a problem of selecting the wrong control file for your device. (There may be some other actions been triggered when writing/changing the contents of the used control file, e.g. power saving or disabling GPU.)

You"ll find a description how to specify another control file and some hints in the thread for the Magisk module (cs). There is also a description how we could test to help the devs (and ourselves) for this wip in the first postings of this thread.
[Android Apps and Games] guanto96:
Unfortunately stop charging doesn't work on my Nexus 5 (Android 8.0 and Magisk)

Anyway thank you for your work :)
[Android Apps and Games] greyfreeman:
Does anyone know what the trigger file is for a Nexus 7 2013? I was looking for it all night. I know it's not supported, but maybe I can rig something with Tasker.
[Android Apps and Games] no_name_no:
That's really frustrating. I have tried a lot of things now, but nothing works. A terminal app can change the permissions of batt_tune_float_voltage or fg_full_voltage (chmod). Editing these files with root explorer throws then no errors, but like in your example it's still not possible.

My next thought was that i could try to write an init.d/ su.d script:

battery.sh (0700 permissions)

#!/su/bin/sush

echo 1 > /sdcard/Download/testfile
echo 42000 > /sys/class/power/power_supply/batt_tune_float_voltage

Unfortunatly su.d does not work in general on my device and I dunno why. Maybe you could try this?

Otherwise: The App discussed here even changes batt_slate_mode in the same folder, does somebody know how this works?

---------- Post added at 09:38 PM ---------- Previous post was at 09:11 PM ----------

End-of-charge voltage on my S7 is definitely 4.35V, battery apps when charged up to 100% showing me this and also the files I am having here mentioned say that. Indeed I could not find a file like voltage_max_design, but a file called batt_capacity_max, it contains the value 990, dubious to me.
[Android Apps and Games] ACiDxCHRiST:
So I have found a workaround. If I enable always on ambient display, I don't have any problems with Battery Charge Limit.
[Android Apps and Games] :
Did you factory reset your device or wipe data at all in this process?
[Android Apps and Games] ACiDxCHRiST:
I wiped Battery Charge Limit data each time before I uninstall it; bot other than that, no.
[Android Apps and Games] :
Alright. I read on Reddit that people in general we're having issues with AOD being disabled and slow response times with the power button... If you want, wipe your device or factory reset and it should fix the lag all together. That's what the advice from a lot of people were. Don't have taimen yet so can't check
[Android Apps and Games] ACiDxCHRiST:
I clean flashed 8.1 from factory image. The problems started shortly after that.
[Android Apps and Games] :
Hm weird... Not sure then.
[Android Apps and Games] NetSoerfer:
On my OnePlus 5 with the latest LineageOS, BCL 1.05 seems to completely ignore the lower battery limit, regardless of any combination of options I've selected. Anything I can do to (help?) resolve this?
[Android Apps and Games] 5t0rmr1d3r:
It works very well on my fairphone2 with LOS14. 1
[Android Apps and Games] ACiDxCHRiST:
So I have since disabled Always On Display, and instead enabled Double-tap to Check Phone, and I have not had the problem return. So it appears (for me at least) any setting that prevents Ambient Display from being completely off, prevents the issue of the screen not turning on.
[Android Apps and Games] maik005:
I also only charge wireless. May you please send me your Tasker Profile?
[Android Apps and Games] KunalAPatel:
Doesn't work on Galaxy S5 Plus

I was quite happy to have found just the app that did monitor the charging limit. Installed it and when I open it it just gets stuck. Tried 'Force Stop' it from App Info still no luck. Please help.:confused:
[Android Apps and Games] TechExhibeo:
Good Work Brother!

I was missing this feature on Android and wanted something like that.

Thank you for your hard work.
[Android Apps and Games] gohamstergo:
[MENTION=6898873]harsha1397[/MENTION] it seems like the app works to stop charging during the first charge cycle, but my device won't charge a second cycle. I always have to reboot to fix it. I checked the file and it is properly at "1" but still doesnt charge. Nexus 6 stock rom.
[Android Apps and Games] frequentc:
[MENTION=6898873]harsha1397[/MENTION]

In addition to store_mode, I also found another option for Samsung phones:

/sys/class/power_supply/battery/batt_slate_mode

By default batt_slate_mode is 0, but if you set this to 1, it stops the battery from charging. And it is reversible, so if you set batt_slate_mode back to 0, it starts charging again.

The main difference between batt_slate_mode and store_mode is batt_slate_mode acts like the charging cable is unplugged, so it allows the phone's battery to drain (store_mode kept the battery at the same percentage).

I figured this out by looking at Samsung's battery driver in the kernel source code (/drivers/battery/sec_battery.c).
[Android Apps and Games] murali3127:
There is no file named charging_enabled in that path!
[Android Apps and Games] amn1987:
I tried with adb but it did not work.Permissions denied.Tried with Root Explorer but I could not change the value to "0". However the app seems to work and stopped charging at the set limit! Redmi 3s running stock MIUI 8.1.1.0 and ofc with root access. Thanks.

Edit: Now the value is "0".
[Android Apps and Games] veez21:
Now trying
[Android Apps and Games] BlueTaurus:
Your App link takes me to aliexpress for some reason, wtf.

EDIT: Damn, that was really weird. Yellow text that said app that takes you to Aliexpress, it's gone now though.
[Android Apps and Games] sriharshaarangi:
Try to change the file /sys/class/power/battery/battery_charging_enabled manually to 0, and then to 1 while charging, and see whether it is working as expected
[Android Apps and Games] sriharshaarangi:
Thanks a lot for your work! Taken into consideration. I will resume the work soon.
[Android Apps and Games] lerkin:
Please add current version number to op title. Thank you for your work!