Skip to content

Commit

Permalink
**v2022.1.8 (202201080)**
Browse files Browse the repository at this point in the history
- `acc -p` finds even more potential switches;
- Enhanced charging status detection;
- General fixes & optimizations;
- Improved idle mode support;
- New charging switches;
- Optimize system performance and battery utilization, by forcing `bg-dexopt-job` on daemon [re]start, if charging;
- Support for Qualcomm SnapDragon 8 Gen 1 devices, Nokia 2.2 and more;
- Updated documentation.
  • Loading branch information
VR-25 committed Jan 8, 2022
1 parent c609dfb commit 18e033d
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 100 deletions.
8 changes: 6 additions & 2 deletions META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/system/bin/sh
# $id Installer/Upgrader
# Copyright 2019-2021, VR25
# Copyright 2019-2022, VR25
# License: GPLv3+
#
# devs: triple hashtags (###) mark non-generic code
Expand Down Expand Up @@ -146,7 +146,7 @@ fi

###
echo "$name $version ($versionCode)
Copyright 2017-2021, $author
Copyright 2017-2022, $author
GPLv3+
(i) Installing in $installDir/$id/..."
Expand Down Expand Up @@ -280,4 +280,8 @@ esac
# initialize $id
/data/adb/$domain/$id/service.sh --init

[ $(date +%m%d) -gt 110 ] || su -lp 2000 -c "/system/bin/cmd notification post -S bigtext -t 'ACC' 'Tag' \"Happy New Year!\"" < /dev/null > /dev/null 2>&1

rm $data_dir/curr $data_dir/warn 2>/dev/null ###

exit 0
38 changes: 28 additions & 10 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h2 id="description">DESCRIPTION</h2>
The installation is always &quot;systemless&quot;, whether or not the system is rooted with Magisk.</p>
<hr>
<h2 id="license">LICENSE</h2>
<p>Copyright 2017-2021, VR25</p>
<p>Copyright 2017-2022, VR25</p>
<p>This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand Down Expand Up @@ -284,7 +284,7 @@ <h4 id="notes-2">Notes</h4>
<h2 id="default-configuration">DEFAULT CONFIGURATION</h2>
<pre><code><code><div>#DC#

configVerCode=202111030
configVerCode=202201010
capacity=(-1 60 70 75 false false)
temperature=(40 60 90 65)
cooldownRatio=()
Expand Down Expand Up @@ -461,7 +461,6 @@ <h2 id="default-configuration">DEFAULT CONFIGURATION</h2>
# shutdown_capacity (sc) #
# When the battery is discharging and its capacity/voltage_now_millivolts &lt;= sc and phone has been running for 15 minutes or more, acc daemon turns the phone off to reduce the discharge rate and protect the battery from potential damage induced by voltage below the operating range.
# sc=-1 disables it.
# [Beta] if the file /data/adb/vr25/acc-data/warn exists, accd posts Android shutdown warning notifications at sc + 5% or sc + 100 mV.

# cooldown_capacity (cc) #
# Capacity/voltage_now_millivolts at which the cooldown cycle starts.
Expand Down Expand Up @@ -770,6 +769,7 @@ <h3 id="terminal-commands">Terminal Commands</h3>
acc -t /proc/mtk_battery_cmd/current_cmd 0::0 0::1 /proc/mtk_battery_cmd/en_power_path 1 0 (&quot;::&quot; is a placeholder for &quot; &quot; - MTK only)

-t|--test [file] Test charging switches from a file (default: /dev/.vr25/acc/ch-switches)
Control files that trigger reboots or kernel panics are automatically backlisted
e.g.,
acc -t (test known switches)
acc -t /sdcard/experimental_switches.txt (test custom/foreign switches)
Expand Down Expand Up @@ -1016,7 +1016,19 @@ <h3 id="diagnosticslogs">Diagnostics/Logs</h3>
The logs do not contain any personal information and are never automatically sent to the developer.
Automatic exporting (local) happens under specific conditions (refer back to <code>SETUP/USAGE &gt; Terminal Commands &gt; Exit Codes</code>).</p>
<h3 id="finding-additionalpotential-charging-switches-quickly">Finding Additional/Potential Charging Switches Quickly</h3>
<p>Refer to (search for) the <code>--parse</code> option in the <a href="#terminal-commands">terminal commands</a> section.</p>
<ol>
<li>
<p>Generate a list of potential charging switches: <code>acc -p &gt; /sdcard/acc-p.txt</code>.</p>
</li>
<li>
<p>Remove from the list, all lines that you're SURE don't resemble a charging switch.</p>
</li>
<li>
<p>Test all: <code>acc -t /sdcard/acc-p.txt</code>.</p>
</li>
</ol>
<p>Note that some control files may trigger reboots or kernel panics.
ACC automatically blacklists these, so that the user can continue testing (step 2) after each reboot.</p>
<h3 id="install-upgrade-stop-and-restart-processes-seem-to-take-too-long">Install, Upgrade, Stop and Restart Processes Seem to Take Too Long</h3>
<p>The daemon stop process implies complete reversal of changes made to the charging management system.
Sometimes, <strong>this requires the charger to be plugged</strong>.
Expand Down Expand Up @@ -1161,6 +1173,7 @@ <h2 id="frequently-asked-questions-faq">FREQUENTLY ASKED QUESTIONS (FAQ)</h2>
</blockquote>
<p>With modern battery management systems, that's generally unnecessary.</p>
<p>However, if your battery is underperforming, you may want to try the procedure described at <a href="https://batteryuniversity.com/article/bu-603-how-to-calibrate-a-smart-battery">https://batteryuniversity.com/article/bu-603-how-to-calibrate-a-smart-battery</a> .</p>
<p>ACC automatically optimizes system performance and battery utilization, by forcing <code>bg-dexopt-job</code> on daemon [re]start, if charging.</p>
<blockquote>
<p>I set voltage to 4080 mV and that corresponds to just about 75% charge.
But is it typically safer to let charging keep running, or to have the circuits turn on and shut off between defined percentage levels repeatedly?</p>
Expand Down Expand Up @@ -1243,12 +1256,6 @@ <h2 id="links">LINKS</h2>
</ul>
<hr>
<h2 id="latest-changes">LATEST CHANGES</h2>
<p><strong>v2021.11.3 (202111030)</strong></p>
<ul>
<li>Fixed installation issues</li>
<li>Improved support for the current Magisk canary.</li>
<li>Shutdown warning notifications (mV) are now posted at shutdown_capacity + 100mV (formerly 200).</li>
</ul>
<p><strong>v2021.12.14 (202112140)</strong></p>
<ul>
<li>Additional charging switches;</li>
Expand All @@ -1269,6 +1276,17 @@ <h2 id="latest-changes">LATEST CHANGES</h2>
<li>[ctrl-files]: added <code>battery/op_disable_charge 0 1</code> switch;</li>
<li>[README]: updated troubleshooting section;</li>
<li>General optimizations.</li>
</ul>
<p><strong>v2022.1.8 (202201080)</strong></p>
<ul>
<li><code>acc -p</code> finds even more potential switches;</li>
<li>Enhanced charging status detection;</li>
<li>General fixes &amp; optimizations;</li>
<li>Improved idle mode support;</li>
<li>New charging switches;</li>
<li>Optimize system performance and battery utilization, by forcing <code>bg-dexopt-job</code> on daemon [re]start, if charging;</li>
<li>Support for Qualcomm SnapDragon 8 Gen 1 devices, Nokia 2.2 and more;</li>
<li>Updated documentation.</li>
</ul>

</body>
Expand Down
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The installation is always "systemless", whether or not the system is rooted wit
---
## LICENSE

Copyright 2017-2021, VR25
Copyright 2017-2022, VR25

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -241,7 +241,7 @@ In interactive mode, it also asks the user whether they want to download and ins
```
#DC#
configVerCode=202111030
configVerCode=202201010
capacity=(-1 60 70 75 false false)
temperature=(40 60 90 65)
cooldownRatio=()
Expand Down Expand Up @@ -418,7 +418,6 @@ currentWorkaround=false
# shutdown_capacity (sc) #
# When the battery is discharging and its capacity/voltage_now_millivolts <= sc and phone has been running for 15 minutes or more, acc daemon turns the phone off to reduce the discharge rate and protect the battery from potential damage induced by voltage below the operating range.
# sc=-1 disables it.
# [Beta] if the file /data/adb/vr25/acc-data/warn exists, accd posts Android shutdown warning notifications at sc + 5% or sc + 100 mV.
# cooldown_capacity (cc) #
# Capacity/voltage_now_millivolts at which the cooldown cycle starts.
Expand Down Expand Up @@ -736,6 +735,7 @@ Options
acc -t /proc/mtk_battery_cmd/current_cmd 0::0 0::1 /proc/mtk_battery_cmd/en_power_path 1 0 ("::" is a placeholder for " " - MTK only)
-t|--test [file] Test charging switches from a file (default: /dev/.vr25/acc/ch-switches)
Control files that trigger reboots or kernel panics are automatically backlisted
e.g.,
acc -t (test known switches)
acc -t /sdcard/experimental_switches.txt (test custom/foreign switches)
Expand Down Expand Up @@ -1071,7 +1071,14 @@ Automatic exporting (local) happens under specific conditions (refer back to `SE

### Finding Additional/Potential Charging Switches Quickly

Refer to (search for) the `--parse` option in the [terminal commands](#terminal-commands) section.
1. Generate a list of potential charging switches: `acc -p > /sdcard/acc-p.txt`.

2. Remove from the list, all lines that you're SURE don't resemble a charging switch.

3. Test all: `acc -t /sdcard/acc-p.txt`.

Note that some control files may trigger reboots or kernel panics.
ACC automatically blacklists these, so that the user can continue testing (step 2) after each reboot.


### Install, Upgrade, Stop and Restart Processes Seem to Take Too Long
Expand Down Expand Up @@ -1279,6 +1286,8 @@ With modern battery management systems, that's generally unnecessary.

However, if your battery is underperforming, you may want to try the procedure described at https://batteryuniversity.com/article/bu-603-how-to-calibrate-a-smart-battery .

ACC automatically optimizes system performance and battery utilization, by forcing `bg-dexopt-job` on daemon [re]start, if charging.


> I set voltage to 4080 mV and that corresponds to just about 75% charge.
But is it typically safer to let charging keep running, or to have the circuits turn on and shut off between defined percentage levels repeatedly?
Expand Down Expand Up @@ -1384,11 +1393,6 @@ A common workaround is having `resume_capacity = pause_capacity - 1`. e.g., resu
---
## LATEST CHANGES

**v2021.11.3 (202111030)**
- Fixed installation issues
- Improved support for the current Magisk canary.
- Shutdown warning notifications (mV) are now posted at shutdown_capacity + 100mV (formerly 200).

**v2021.12.14 (202112140)**
- Additional charging switches;
- Auto-add current and voltage ctrl files to charging switches list for extended idle mode support;
Expand All @@ -1407,3 +1411,13 @@ A common workaround is having `resume_capacity = pause_capacity - 1`. e.g., resu
- [ctrl-files]: added `battery/op_disable_charge 0 1` switch;
- [README]: updated troubleshooting section;
- General optimizations.

**v2022.1.8 (202201080)**
- `acc -p` finds even more potential switches;
- Enhanced charging status detection;
- General fixes & optimizations;
- Improved idle mode support;
- New charging switches;
- Optimize system performance and battery utilization, by forcing `bg-dexopt-job` on daemon [re]start, if charging;
- Support for Qualcomm SnapDragon 8 Gen 1 devices, Nokia 2.2 and more;
- Updated documentation.
10 changes: 4 additions & 6 deletions acc/acc.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/system/bin/sh
# Advanced Charging Controller
# Copyright 2017-2021, VR25
# Copyright 2017-2022, VR25
# License: GPLv3+


Expand Down Expand Up @@ -135,9 +135,9 @@ test_charging_switch() {
flip_sw off && sleep_sd not_charging || :

! not_charging && failed=true || {
not_charging not \
[ $_status = Idle ] \
&& battIdleMode=true \
|| battIdleMode=false
|| { [ ${chargingSwitch[2]:-.} = voltage_now ] && battIdleMode=true || battIdleMode=false; }
}

flip_sw on 2>/dev/null
Expand Down Expand Up @@ -181,7 +181,7 @@ parse_switches() {

cat -v "$2" > $f

for i in $(grep -En '^ (1|0)$' $f | cut -d: -f1); do
for i in $(grep -Ein '^ ((1|0)$|.*able.*)' $f | cut -d: -f1); do

n=$i
i="$(sed -n "$(($n - 1))p" "$f")"
Expand Down Expand Up @@ -311,7 +311,6 @@ case "${1-}" in
-d|--disable)
shift
${verbose:-true} || exec > /dev/null
print_m_mode
! daemon_ctrl stop > /dev/null || print_stopped
. $execDir/acquire-lock.sh
disable_charging "$@"
Expand All @@ -324,7 +323,6 @@ case "${1-}" in
-e|--enable)
shift
${verbose:-true} || exec > /dev/null
print_m_mode
! daemon_ctrl stop > /dev/null || print_stopped
. $execDir/acquire-lock.sh
enable_charging "$@"
Expand Down
13 changes: 8 additions & 5 deletions acc/accd.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/system/bin/sh
# Advanced Charging Controller Daemon (accd)
# Copyright 2017-2021, VR25
# Copyright 2017-2022, VR25
# License: GPLv3+


Expand Down Expand Up @@ -137,6 +137,9 @@ if ! $init; then
&& chgStatusCode=$(dumpsys battery 2>/dev/null | sed -n 's/^ status: //p')
then
setup_capacity_sync
set +e
cmd package bg-dexopt-job < /dev/null > /dev/null 2>&1 &
set -e
fi

# read charging current ctrl files (part 2) once
Expand Down Expand Up @@ -278,18 +281,18 @@ if ! $init; then
if ! $maxTempPause && [ $(cut -d '.' -f 1 /proc/uptime) -ge 900 ] && not_charging dis; then
if [ ${capacity[0]} -ge 1 ]; then
# warnings
if $shutdownWarnings && [ -f $data_dir/warn ]; then
! $shutdownWarnings || {
if t ${capacity[0]} -gt 3000; then
! t $(grep -o '^..' $voltage_now) -eq $(( ${capacity[0]%??} + 1 )) \
|| ! su -lp 2000 -c "cmd notification post -S bigtext -t 'ACC' 'Tag' \"WARNING: ~100mV to auto shutdown, plug the charger!\"" \
|| ! notif "WARNING: ~100mV to auto shutdown, plug the charger!" \
|| sleep ${loopDelay[1]}
else
! t $(cat $batt/capacity) -eq $(( ${capacity[0]} + 5 )) \
|| ! su -lp 2000 -c "cmd notification post -S bigtext -t 'ACC' 'Tag' \"WARNING: 5% to auto shutdown, plug the charger!\"" \
|| ! notif "WARNING: 5% to auto shutdown, plug the charger!" \
|| sleep ${loopDelay[1]}
fi
shutdownWarnings=false
fi
}
# action
if _le_shutdown_cap; then
sleep ${loopDelay[1]}
Expand Down
25 changes: 9 additions & 16 deletions acc/batt-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ batt_info() {


# raw battery info from the kernel's battery interface

info="$(
cat $batt/uevent *bms*/uevent 2>/dev/null \
| sort -u \
Expand All @@ -39,15 +38,8 @@ batt_info() {


# determine the correct charging status
case "$info" in
*STATUS=[Cc]harging*)
if not_charging dis; then
info="${info/STATUS=?harging/STATUS=Discharging}"
elif not_charging not; then
info="${info/STATUS=?harging/STATUS=Not charging}"
fi
;;
esac
not_charging || :
info="$(echo "$info" | sed "/^STATUS=/s/=.*/=$_status/")"


# because MediaTek is weird
Expand All @@ -65,18 +57,19 @@ batt_info() {

# add/remove negative sign
case $currNow in
*.*)
if not_charging dis; then
0.00)
:
;;
*)
if [ $_status = Discharging ]; then
currNow=-${currNow#-}
elif ! not_charging; then
elif [ $_status = Charging ]; then
currNow=${currNow#-}
fi
;;
*)
currNow=0
;;
esac


# parse VOLTAGE_NOW & convert to Volts
voltNow=$(echo "$info" | sed -n "s/^VOLTAGE_NOW=//p")
dtr_conv_factor $voltNow ${voltFactor-}
Expand Down
22 changes: 15 additions & 7 deletions acc/batt-interface.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ not_charging() {
[ ! -f $file ] || break
done

[ ${1:-.} = not ] && _status=Idle || _status=Discharging

grep -Eiq "${1-dis|not}" $file || {
if [ -n "$currThreshold" ] && [ ! -f ${config_%/*}/curr ] \
&& [ ! -f $TMPDIR/curr ] && [ $(sed s/-// $currFile) -le $currThreshold ]
then
return 0
else
if { [ -z "${1-}" ] || [ $1 = dis ]; } \
&& [ $(sed s/-// $currFile) -lt $curr ]
then
return 0
fi
_status=Charging
return 1
fi
}
Expand Down Expand Up @@ -48,7 +56,7 @@ if ${init:-false}; then
done

curr=$(sed s/-// $currFile)
currThreshold=50 # mA
currThreshold=95 # mA
ampFactor_=1000

if [ $curr -le $currThreshold ]; then
Expand All @@ -61,16 +69,16 @@ if ${init:-false}; then
}
fi

unset curr

echo "ampFactor_=$ampFactor_
batt=$batt
currFile=$currFile
currThreshold=$currThreshold
temp=$temp" > $TMPDIR/.batt-interface.sh
batt=$batt
currFile=$currFile
currThreshold=$currThreshold
temp=$temp" > $TMPDIR/.batt-interface.sh

init=false

else
. $TMPDIR/.batt-interface.sh
fi

curr=-1
Loading

0 comments on commit 18e033d

Please sign in to comment.