sriharshaarangi / batterychargelimit Goto Github PK
View Code? Open in Web Editor NEWLicense: GNU General Public License v3.0
License: GNU General Public License v3.0
Nexus 6 (shamu)
Magisk systemless root using Magisk Manager
Charge limit worked perfectly until the max cutoff. After falling below the minimum, it is continuing to drain. Phone will not charge even after disabling Battery Charge Limit or even uninstalling the application.
Currently /sys/class/power_supply/battery/charging_enabled is set to 1 and still won't charge.
(disabling and re-booting restores charging functionality)
It occurred to me that it might be a good idea to split the code into two parts - the existing code could run without root privileges, so long as something (could be a separate helper app - which does need to run as root - but only once per boot, or a shell script, or even a script or other type of permissions tweak which ships with the OS for custom ROMs) changes the necessary permissions on the /sys files to give the app write permissions to the necessary files (permissions only need changing on boot-up, thereafter the main part of the app can run without root privileges).
I've tested this using adb (confirmed that I could stop charging on a jfltexx as a non-root user - having changed the permissions on the necessary files under /sys).
Sometimes the app will allow a full charge. I've started opening the app before plugging in to prevent this from happening. I wish I had more info to give. I'm on a pixel xl running Android 7.1.1 with root.
I found a right file which works for Mi6 on stock Android 7.1.1 (MiUi 9)
by editing this file
"file": "//sys/class/power_supply/battery/input_suspend",
"label": "input_suspend",
"details": "Xiaomi Mi6",
"chargeOn": "0",
"chargeOff": "1",
"0" allow charging and "1" disables charging
I tested it and works without any problem, please add support for Mi6 ASAP. Thanks
I'm trying to support my device but failed to find the correct file. Can you please look at my attempts and give some advice?
1|shell@flo:/sys $ su
root@flo:/sys # find . -iname *charg*
./fs/cgroup/memory/sw/memory.move_charge_at_immigrate
./fs/cgroup/memory/memory.move_charge_at_immigrate
./bus/platform/devices/pm8921-charger
./devices/i2c-0/0-0055/power_supply/battery/charge_full_design
./devices/i2c-0/0-0055/power_supply/battery/charge_avg
./devices/i2c-0/0-0055/power_supply/battery/charge_now
./devices/i2c-0/0-0055/power_supply/battery/charge_full
./devices/i2c-0/0-0055/power_supply/battery/charge_counter
./devices/platform/msm_ssbi.0/pm8921-core/pm8921-charger
./kernel/fast_charge
./kernel/fast_charge/force_fast_charge
./module/msm_otg/parameters/usbhost_charge_mode
root@flo:/sys/bus/platform/devices/pm8921-charger # ls -l
-r--r--r-- root root 4096 2017-10-15 17:02 modalias
drwxr-xr-x root root 2017-10-15 16:59 power
lrwxrwxrwx root root 2017-10-15 17:02 subsystem -> ../../../../../bus/platform
-rw-r--r-- root root 4096 2017-10-15 16:59 uevent
root@flo:/sys/bus/platform/devices/pm8921-charger # cd /sys/devices/i2c-0/0-0055/power_supply/battery
root@flo:/sys/devices/i2c-0/0-0055/power_supply/battery # ls -l
-r--r--r-- root root 4096 2017-10-15 16:59 capacity
-r--r--r-- root root 4096 2017-10-15 17:02 charge_avg
-r--r--r-- root root 4096 2017-10-15 16:59 charge_counter
-r--r--r-- root root 4096 2017-10-15 17:02 charge_full
-r--r--r-- root root 4096 2017-10-15 17:02 charge_full_design
-r--r--r-- root root 4096 2017-10-15 17:02 charge_now
-r--r--r-- root root 4096 2017-10-15 16:59 current_now
-r--r--r-- root root 4096 2017-10-15 17:02 cycle_count
lrwxrwxrwx root root 2017-10-15 17:02 device -> ../../../0-0055
-r--r--r-- root root 4096 2017-10-15 17:02 energy_now
-r--r--r-- root root 4096 2017-10-15 16:59 health
drwxr-xr-x root root 2017-10-15 16:59 power
-r--r--r-- root root 4096 2017-10-15 17:02 power_now
-r--r--r-- root root 4096 2017-10-15 16:59 present
-r--r--r-- root root 4096 2017-10-15 16:59 status
lrwxrwxrwx root root 2017-10-15 17:02 subsystem -> ../../../../../class/power_supply
-r--r--r-- root root 4096 2017-10-15 16:59 technology
-r--r--r-- root root 4096 2017-10-15 16:59 temp
-r--r--r-- root root 4096 2017-10-15 16:59 type
-rw-r--r-- root root 4096 2017-10-15 17:02 uevent
-r--r--r-- root root 4096 2017-10-15 16:59 voltage_now
root@flo:/sys/devices/i2c-0/0-0055/power_supply/battery # cat status
Charging
root@flo:/sys/devices/i2c-0/0-0055/power_supply/battery # cat charge_full
3626000
root@flo:/sys/devices/i2c-0/0-0055/power_supply/battery # cat charge_full_design
3828000
root@flo:/ # cd /sys/devices/platform/msm_ssbi.0/pm8921-core/pm8921-charger
root@flo:/sys/devices/platform/msm_ssbi.0/pm8921-core/pm8921-charger # ls -l
-r--r--r-- root root 4096 2017-10-15 17:02 modalias
drwxr-xr-x root root 2017-10-15 16:59 power
lrwxrwxrwx root root 2017-10-15 17:02 subsystem -> ../../../../../bus/platform
-rw-r--r-- root root 4096 2017-10-15 16:59 uevent
Please provide support for Samsung Galaxy Note 10.1 (GT-N8013).
Is there possibility to limit charge by real voltage, not by percents? It seems that percent indicator readings have no straightforward dependence with real battery voltage.
I would like to keep voltage about 3.8V, but it's difficult to say what percentage to choose.
Hi,
Im an LG G5 owner. I please ask you to supporto G5 because in my case this app would have saved my phone from bending the screen.. Yes read right.
(Little story spoiler)
LG G5 is unibody metal with sleeve battery (no back cover)..so a "keep growing battery" find his "locus minoris resistentiae"(alias avere could grow with minor pressure) in upper parte exactly below IPS frame.
As in my case you won't notice any bulging from back part but when happen, you recognize surfing on web page in white background some circular strain In various colour where the pressure hit the screen, like discolorations.
Further investigations made me conscious that leaving the phone face down on table gave the phone a " ship form".. yes my gorilla glass 4 was bendedand my battery stucked inside without possibility to remove it.
It also 1 and half months in LG assistant service (they took pieces from Singapore and take a while to ship in Italy)
(/finish spoiler)
So cross fingers for all LG G5 owners and a warning to them.. Sleeve the battery from inside at least once a week to recognize the first signs of bulging, or hug this app ;)
I received a random crash at 17:29 today after unplugging power cable. Attached is an unfiltered logcat. If this is another weird crash like that crash i had at first run after installing the app this morning, don't worry about it, just close the issue. I'm going to uninstall this app and wait to test again until I get my system straightened out from that bad Titanium Backup restore I did a while back. I'm not really helping the situation here by continuing to test with a known system issue on my end. Thanks for your work on this app and adding experimental Shield Tablet support though! I appreciate it.
hi every body I need voltage limit because my p9lite dont stop charging 4.5volt andgo upper to 4.6 volt ineed ur help percentage is always false hardware problem but give real battery volt
Support for Amazon Fire tablets. The file is /sys/class/power_supply/battery/device/Charging_Enable (1 = charging enabled, 0 = disabled) or /sys/devices/platform/battery/Charging_Enable (direct file), either works.
I'd like to use this app differently to most.
I have DJI Drone and the remote when connected to an android phone will automatically start charging the phone and therefore drawing power from the tiny battery on the controller.
I would like to be able to enable and disable charging with a simple click. Rather than having to use the charging limits.
Support for Samsung Nexus 10.
The file is /sys/class/power_supply/manta-battery/charge_enabled (1 = charging enabled, 0 = disabled).
Thanks :)
When I started using Magisk v13 (beta) on my N6P running lastest PureNexus, I notice Battery Charge Limit behaved differently and sometimes it didn't work properly after reconnecting.
When rooted with Magisk v12 (stable), I was used to see the "Battery Charge Limit enabled" toast as soon as I plugged the power cord in and the "Battery Charge Limid disabled" toast right after I unplugged the power cord. Also it was possible to replug the cord immediately and the enabled toast will show again.
With Magisk v13, the first toast is usually showed but the second one never shows and very often if I plug the power cord again Battery Charge Limit will not work as intended.
The logcats I capture just before I plug the power cord and right after I unplug it with each Magisk version installed are attached.
Magisk_v12.txt
Magisk_v13.txt
related to #45
When testing BCL with Nexus 5 (running LineageOS 14.1-20170829-NIGHTLY-hammerhead), BCL failed to write to the control file (/sys/class/power_supply/ac/charging_enabled). BCL had therefore no effect on limiting the battery charge.
Reason: The control file was readable only.
After changing the file to read/write (chmod u+w), BCL was able to limit the battery charge level as intended.
Therefore it is suggested to include code to BCL, that checks and if necessary updates the control file's access permissions to read/write.
Hey following setting:
-S7 edge (exynos)
-Nougat (batman rom)
-magisk 13.5 rooted
The samsung smartmanager reports 12 force close of bcl in the last 5 days. Beside that its working 100%. I mean the app does what it should do. But im scared it could drain battery or something like that if its fc's and needs to restart.
If i need to provide a log please give short advice how to do that. If you give me the codes im able to extract necessary information via adb or something else :)
Regards
Some android devices support changing the charge rate via files in /sys, slow charging prolongs battery life (and the user probably won't be inconvenienced at all for overnight charging).
Would be good to offer option to limit charge current where supported (perhaps offering option to reduce current when very empty or near target fill).
Charge rate could be automatically limited based on Android "quiet hours" setting and also device temperature (or battery temperature if available).
Charging fast towards when near full and completely empty impacts battery life (more so with some cell chemistries than others I believe).
The same goes for charging batteries which are at high temperatures or very low temperatures. Some built-in chargers will be sufficiently intelligent to compensate for these factors on their own, but most aren't.
http://batteryuniversity.com/learn/article/charging_lithium_ion_batteries
^^^ also see "Fast charging trade-off" section in the digikey article...
http://teslapedia.org/model-s/tesla-driver/understanding-charging-rates/
^^^ section on charging speed vs. temperature
Cheers,
Tim.
Add voltage, current, other useful info to application
I found the following on my nexus 9:
flounder:/ # cat /sys/devices/platform/tegra12-i2c.0/i2c-0/0-006b/charging_state
enabled
Can you add support for the Nexus 9? It would be much appreciated!
Hello,
i think i've found the configurations named online.
It is in /sys/class/power_supply/ac/
/sys/class/power_supply/usb/
/sys/class/power_supply/wireless/
The online file change its number for non charging 0 and charging 1
I don't know if it's important, that the online file is also available in /usb /wireless
I also found the direct path /sys/devices/platform/battery/power_supply also with /ac / usb /wireless and the online file
For now I wasn't able to change the numbers with a text editor, i think its the issue, that Magisk is rooting as read only.
Any chance to support Android 4.3 (Specifically Samsung Galaxy S3)?
not working on my samsung gt-s5830 (cyanogen mod 11, android 4.4.4)
Using superman ROM on a Samsung galaxy s7 sm-g930f. Tried both control files available to me (store_mode and batt_slate_mode) and didn't seem to make a difference.
Logs with suggested filter don't include anything at the moment it hits 70. But I can attach complete logs (is there any sensitive information I should edit out?)
I would suggest adding this app to F-Droid. For this, the author has to be notified and has to support the inclusion. There is a ticket for this at https://gitlab.com/fdroid/rfp/issues/254.
Control file for mipad 2: /sys/class/power_supply/bq2589x_charger/enable_charging
Steps to reproduce:
Even the in-app status says "DISCHARGING".
App version: 1.0.4
Device: Motorola Moto X (2013)
Control file: pm8921
Thank you for your work on the Battery Charge Limit apk! I know there is some support for the N10 already...
Issue: It does not function as intended on my N10 running DU Android 6.0.1! It charged up to the set limit the first time & the next time I put my N10 on charge (once the charge level was below the set low limit) my N10 it got fully charged the second time around, despite the limit been set to 75%.
Let me know if I can help you in any way. Thank you!
Note: Link to a script control feature => https://forum.xda-developers.com/nexus-10/general/script-to-control-nexus-10-charge-35-65-t3035588
Kernel mod anyone => https://forum.xda-developers.com/showthread.php?t=2469261
Cheers
Model: Xiaomi Redmi Note4/Note4x
Android version: 7
Miui version: 7.8.24
There are two control files for changing charging state.
For both files, 0 is not charging, 1 is charging
Changing the value of either of the files turns off the charging. Even if any one of the files have value '0', charging is cut-off.
I'll be happy to provide any other info
BatteryChargeLimit.zip
Bengali Translated String File is added below! :)
Currently, you can only choose a lower limit of 1-10 below your upper limit. Could you make the lower limit a textbox instead of a slider so we can enter anything we want?
Samsung S3 Android 4.3
Sometimes during overnight charge BatteryChargeLimit process exits and thus device is charged to 100%.
Feel free to ask me any needed info, using ADB, collecting logs, etc.
Hello
My note 3 (n9005 eur)phronesis v6 phantom kernel v1.2p stops recharging normally after the app has cut the load until restart
It is as if the app remains in "no charge or discharge" mode permanently
thank you in advance
Being able to change the limit via intent is pretty nice, but how about being able to completely disable or enable the limit?
My N6P powered by latest PureNexus (7.1.2.r17) and rooted with Magisk v12 or Magisk v13 beta doesn't allow to reset battery stats with "dumpsys batterystats --reset" command, same as mentioned before by another Battery Charge Limit user at the XDA thread.
Using an elevated terminal, the command "dumpsys batterystats --reset" will return "Error dumping service info: (Unknown error -2147483646) batterystats".
And this is the corresponding logcat output:
[ 06-12 19:54:21.837 19200:19200 W/dumpsys ] type=1400 audit(0.0:67): avc: denied { write } for path="pipe:[107864]" dev="pipefs" ino=107864 scontext=u:r:system_server:s0 tcontext=u:r:su:s0 tclass=fifo_file permissive=0
Newest PureNexus just added an option to reset battery stats and it seems that's done with this commit.
Can this method be added to Battery Charge Limit as an alternative to the dumpsys command?
Nexus 4,
the program works fine if charging through micro USB.
On Wireless Charger, the charging starts regardless of battery level.
I could assist to debug it, if necessary.
Thanks
I believe the I'm having the rapid cycling issue (issue #15 ) on my Shield Tablet. I plugged it in several hours ago at 60%, came back to it just now and it was at 97% (all app setting at default, including 80% limit). Attached is a filtered logcat.
alogcat.2017-08-16-15-47-48-0600.txt
https://mega.nz/#!no4EAZzY!jvp64bG9NlRJrTwVX36cS7ECLGQEcSvxHEEM0joK42c
Here is a link with filtres.
My phone not charge after stopped by the app.
Until next reboot.
Thanks
I would like to see a feature to have battery charge limiter be able to auto enable and disable a specific times. E.g. turn on in the am and of in the pm so the phone will charge fully overnight only.
Nexus 5 running LineageOS 14.1-20170829-NIGHTLY-hammerhead
Control File (default = read-only ... -r--r--r--):
/sys/class/power_supply/ac/charging_enabled
1 = charging enabled
0 = charging disabled
I had to change the file to read/write:
/sys/class/power_supply/ac # chmod u+w charging_enabled
Testing
/sys/class/power_supply/ac # echo 0 > charging_enabled
/sys/class/power_supply/ac # cat status
Not charging
Waited for 10 minutes ... battery charge level didn't go up.
After setting the file back to 1, the phone got charged again and battery charge level increased.
/sys/class/power_supply/ac # echo 1 > charging_enabled
/sys/class/power_supply/ac # cat status
Charging
Please add an option to not display the permanent status of the app in the notification aera.
In my opinion, the status is just useful for someone that is worried about this status ;-) If everything works fine, it's like another parameters of the phone and a permanent notification is not required anymore.
Hi Sir,
Can you add support for two of my devices?
The Battery Charge Limit says my devices are not supported yet.
On Samsung Nexus 10, rooted, using root explorer, i mounted the partition as r/w, i tried to change from '0' to '1' the value of
/sys/class/power_supply/manta-battery/charge_enabled
Saved the file and exit.
Tried to run the Battery Charge Limit, but it still says the device isnt supported.
I then tried to reboot but the changes i made to the system didn't survive the reboot.
On Jiayu S3 Advance (please see xda), i cannot find an entry to edit using the guide you posted here. Can you point me in the right direction please?
Also, both devices are in Nougat 7.1.2 if that matters.
Jiayu is on MadOS 7.1.2
Nexus 10 is on LineageOS 7.1.2
Any suggestions?
I posted in the forum, but I'm adding here also.
I found the correct file to make this work on the Nvidia Shield Tablet (Android version 7.0 stock rooted OS).
File location: /sys/devices/platform/7000c400.i2c/i2c-1/1-006b/charging_state
File has one line of text and only one word: "enabled" or "disabled"
Setting text to "enabled", which is the default text, allows charging, and setting it to "disabled" stops charging.
Took me almost two hours to find the correct file and test it.
It's not handy to set seek bar to exact percent. May be replace it with some other control, like picker, that can be good for setting charge limit as well
My GN (maguro) running DU 11.7 has /sys/class/power_supply/battery/charge_enabled with values=0|1
Can you please add it?
OK I just noticed an issue. When the tablet is plugged in it stops charging at 80% like it should, but if I turn on the display and use the tablet a little while its plugged in (just a few seconds, maybe 15 or 20) it re-enables charging for a little bit and then disables it again, repeatedly. In doing so, the charge keeps increase above the 80% limit.
2017-08-16-10-14-36.txt
Congrats for a good job. Your APP is working perfectly in my mobile phone.Is it possible to support the teclast x98 air ? Which Informations you need oft the Intel cherry trail tablet?
Some files are located /sys/class/power_supply/dollar_cove_charger/enable_charging
Thanks in advance!
I’ve found the following file /sys/class/power_supply/battery/charge_enabled on my rooted Nexus 6 (Shamu) & toggling 1 to 0 does stop charging the device. The same file is selected by default in your apk.
Can you please add support for the Nexus 6?
Issue: The latest version of your apk does not function as intended on my N6 running RR Unofficial Android 7.1.1. (I gave it SU rights).
The Battery Charge Limit apk seems to stop the charge at the set limit once, however the N6 will not charge again once below the lower limit set in the apk unless rebooted. Than it will charge to the set limit again once only! I also don’t see the value of 1 change to 0 in the above mentioned control file.
I also don't like the idea of the phone being kept awake always if it is on hte charger...
Couldn't the ROM be modified to se 75% as full?
Let me know if I can help you in any way. Thank you!
Cheers
The 2014 Note 10.1 is supported.
The GT-N8013 is the 2012 version, and it shows it is not supported.
Actually that's the issue.
See also discussion https://forum.xda-developers.com/android/apps-games/root-battery-charge-limit-t3557002/post73513352#post73513352
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.