From 3eaf5d470c6160a5a0f1291b5b569c3dadd08ea0 Mon Sep 17 00:00:00 2001 From: VR-25 <28943176+VR-25@users.noreply.github.com> Date: Mon, 20 Sep 2021 10:52:30 +0100 Subject: [PATCH] **v2021.9.20 (202109200)** - General enhancements - Manual capacitySync toggle (`[capacity_sync|cs] = [true|false]`) - it overrides the automatic. Both include the `freeze at 2%` feature. This is the actual `capacity_freeze2` replacement now. `capacity_mask` implies `capacity_sync`. - Unlike in previous versions, changes to `capacity_mask` and `capacity_sync` take effect (within a few seconds) without a daemon restart. - Updated documentation --- README.html | 59 ++++++++++++++++++--------- README.md | 75 +++++++++++++++++++++++++--------- acc/accd.sh | 93 +++++++++++++++++++++++++++++++++--------- acc/default-config.txt | 26 ++++++++---- acc/misc-functions.sh | 27 ------------ acc/print-config.sh | 3 +- acc/set-prop.sh | 5 ++- acc/write-config.sh | 5 ++- module.prop | 4 +- 9 files changed, 195 insertions(+), 102 deletions(-) diff --git a/README.html b/README.html index 8403b80..3426ac3 100644 --- a/README.html +++ b/README.html @@ -79,6 +79,7 @@

Advanced Charging Controller (ACC)

Initializing ACC
  • Managing ACC
  • The Output of --info
  • +
  • Profiles
  • More
  • @@ -281,8 +282,8 @@

    Notes

    DEFAULT CONFIGURATION

    #DC# -configVerCode=202109190 -capacity=(-1 60 70 75 false) +configVerCode=202109200 +capacity=(-1 60 70 75 false false) temperature=(40 60 90 65) cooldownRatio=() cooldownCurrent= @@ -319,16 +320,16 @@

    DEFAULT CONFIGURATION

    # NOTES -# The daemon does not have to be restarted after making changes to this file - unless one of the changes is capacity_mask or charging_switch. +# The daemon does not have to be restarted after making changes to this file - unless one of the changes is charging_switch. -# Changes to current_workaround (cw) only take effect after an acc [re]initialization (install, upgrade or accd --init) or system reboot. +# A change to current_workaround (cw) only takes effect after an acc [re]initialization (install, upgrade or "accd --init") or system reboot. -# If those 3 variables are updated with "acc --set", accd is restarted automatically (--init is implied as needed). +# If those 2 variables are updated with "acc --set" (not acca --set), accd is restarted automatically (--init is implied as needed). # BASICS -# capacity=(shutdown_capacity cooldown_capacity resume_capacity pause_capacity capacity_mask) +# capacity=(shutdown_capacity cooldown_capacity resume_capacity pause_capacity capacity_sync capacity_mask) # temperature=(cooldown_temp max_temp max_temp_pause shutdown_temp) @@ -374,6 +375,7 @@

    DEFAULT CONFIGURATION

    # cc cooldown_capacity # rc resume_capacity # pc pause_capacity +# cs capacity_sync # cm capacity_mask # sc shutdown_capacity @@ -466,10 +468,16 @@

    DEFAULT CONFIGURATION

    # pause_capacity (pc) # # Capacity or voltage_now_millivolts at which charging should pause. +# capacity_sync (cs) # +# Some devices, notably from the Pixel lineup, have a capacity discrepancy issue between Android and the kernel. +# This forces Android to report the actual battery capacity supplied by the kernel. +# The discrepancy is usually detected and corrected automatically by accd. +# This setting overrides the automatic behavior. +# Besides, it also prevents Android from getting capacity readings below 2%, since some systems shutdown before battery level actually drops to 0%. + # capacity_mask (cm) # -# This forces Android to report "capacity = capacity * (100 / pause_capacity)", effectively masking capacity limits. -# It also prevents Android from getting capacity readings below 2% (because some systems shutdown before battery level actually drops to 0%). -# A daemon restart is required after changing this (automated by "acc --set"). +# This forces Android to report "capacity = capacity * (100 / pause_capacity)", effectively masking capacity limits (more like capacity_sync on steroids). +# It also prevents Android from getting capacity readings below 2%, since some systems shutdown before battery level actually drops to 0%. # cooldown_temp (ct) # # Temperature (°C) at which the cooldown cycle starts. @@ -894,13 +902,26 @@

    The Output of --info

    POWER_NOW=0 # (CURRENT_NOW * VOLTAGE_NOW) (Watts)

    Note that the power information refers to what is actually supplied to the battery, not what's coming from the adapter. External power is always converted before it reaches the battery.

    +

    Profiles

    +

    Those are simply different config files. +A config path can be supplied as first argument to acca and second to accd executables.

    +

    Examples:

    +

    Copy the config:

    +

    Current config: /dev/.vr25/acc/acca --config cat > /path/to/new/file

    +

    Default config: /dev/.vr25/acc/acca /path/to/new/file --version (--version can be replaced with any option + arguments, as seen below.)

    +

    Edit the copy:

    +

    /dev/.vr25/acc/acca /path/to/new/file --set pause_capacity=75 resume_capacity=70 (if the file does not exist, it is created as a copy of the default config.)

    +

    Use the copy:

    +

    /dev/.vr25/acc/accd --init /path/to/new/file (the daemon is restarted with the new config.)

    +

    Back to the main config:

    +

    /dev/.vr25/acc/accd --init

    More

    ACC daemon does not have to be restarted after making changes to the config. It picks up new changes within seconds.

    There are a few exceptions:

      -
    • capacity_mask (cm) and charging_switch (s) requires a daemon restart.
    • -
    • current_workaround (cw) requires accd --init.
    • +
    • charging_switch (s) requires a daemon restart (/dev/.vr25/acc/accd).
    • +
    • current_workaround (cw) requires a full re-initialization (/dev/.vr25/acc/accd --init).

    This information is in the default configuration section as well.


    @@ -908,7 +929,7 @@

    TROUBLESHOOTING

    Battery Capacity (% Level) Doesn't Seem Right

    When Android's battery level differs from that of the kernel, ACC daemon automatically syncs it by stopping the battery service and feeding it the real value every few seconds.

    Pixel devices are known for having battery level discrepancies for the longest time.

    -

    If your device shuts down before the battery is actually empty, capacity_mask may help. +

    If your device shuts down before the battery is actually empty, capacity_sync or capacity_mask may help. Refer to the default configuration section above for details.

    Bootloop

    While uncommon, it may happen.

    @@ -1202,13 +1223,6 @@

    LATEST CHANGES

    -

    v2021.8.31 (202108310)

    -
      -
    • Additional charging switches
    • -
    • Fixed "current_now is always 0 mA."
    • -
    • Logs are exported as a tarball archive.
    • -
    • Updated readme > notes/tips for front-end developers > initializing acc
    • -

    v2021.9.5 (202109050)

    • Additional charging switches (including a group of 3 for OnePlus that allegedly enable idle mode)
    • @@ -1230,6 +1244,13 @@

      LATEST CHANGES

    • Support for "volatile" plugins (gone on reboot, useful for debugging): /dev/.vr25/acc/plugins/
    • Updated documentation (mainly tips > idle mode and alternatives)
    • Upgrade rollback feature (-b|--rollback or wizard option f)
    • +
    +

    v2021.9.20 (202109200)

    +
      +
    • General enhancements
    • +
    • Manual capacitySync toggle ([capacity_sync|cs] = [true|false]) - it overrides the automatic. Both include the freeze at 2% feature. This is the actual capacity_freeze2 replacement now. capacity_mask implies capacity_sync.
    • +
    • Unlike in previous versions, changes to capacity_mask and capacity_sync take effect (within a few seconds) without a daemon restart.
    • +
    • Updated documentation
    diff --git a/README.md b/README.md index dfee3d2..491db98 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ - [Initializing ACC](#initializing-acc) - [Managing ACC](#managing-acc) - [The Output of --info](#the-output-of---info) + - [Profiles](#profiles) - [More](#more) - [TROUBLESHOOTING](#troubleshooting) - [Battery Capacity (% Level) Doesn't Seem Right](#battery-capacity--level-doesnt-seem-right) @@ -239,8 +240,8 @@ In interactive mode, it also asks the user whether they want to download and ins ``` #DC# -configVerCode=202109190 -capacity=(-1 60 70 75 false) +configVerCode=202109200 +capacity=(-1 60 70 75 false false) temperature=(40 60 90 65) cooldownRatio=() cooldownCurrent= @@ -277,16 +278,16 @@ currentWorkaround=false # NOTES -# The daemon does not have to be restarted after making changes to this file - unless one of the changes is capacity_mask or charging_switch. +# The daemon does not have to be restarted after making changes to this file - unless one of the changes is charging_switch. -# Changes to current_workaround (cw) only take effect after an acc [re]initialization (install, upgrade or accd --init) or system reboot. +# A change to current_workaround (cw) only takes effect after an acc [re]initialization (install, upgrade or "accd --init") or system reboot. -# If those 3 variables are updated with "acc --set", accd is restarted automatically (--init is implied as needed). +# If those 2 variables are updated with "acc --set" (not acca --set), accd is restarted automatically (--init is implied as needed). # BASICS -# capacity=(shutdown_capacity cooldown_capacity resume_capacity pause_capacity capacity_mask) +# capacity=(shutdown_capacity cooldown_capacity resume_capacity pause_capacity capacity_sync capacity_mask) # temperature=(cooldown_temp max_temp max_temp_pause shutdown_temp) @@ -332,6 +333,7 @@ currentWorkaround=false # cc cooldown_capacity # rc resume_capacity # pc pause_capacity +# cs capacity_sync # cm capacity_mask # sc shutdown_capacity @@ -424,10 +426,17 @@ currentWorkaround=false # pause_capacity (pc) # # Capacity or voltage_now_millivolts at which charging should pause. +# capacity_sync (cs) # +# Some devices, notably from the Pixel lineup, have a capacity discrepancy issue between Android and the kernel. +# capacity_sync forces Android to report the actual battery capacity supplied by the kernel. +# The discrepancy is usually detected and corrected automatically by accd. +# This setting overrides the automatic behavior. +# Besides, it also prevents Android from getting capacity readings below 2%, since some systems shutdown before battery level actually drops to 0%. + # capacity_mask (cm) # -# This forces Android to report "capacity = capacity * (100 / pause_capacity)", effectively masking capacity limits. -# It also prevents Android from getting capacity readings below 2% (because some systems shutdown before battery level actually drops to 0%). -# A daemon restart is required after changing this (automated by "acc --set"). +# Implies capacity_sync. +# This forces Android to report "capacity = capacity * (100 / pause_capacity)", effectively masking capacity limits (more like capacity_sync on steroids). +# It also prevents Android from getting capacity readings below 2%, since some systems shutdown before battery level actually drops to 0%. # cooldown_temp (ct) # # Temperature (°C) at which the cooldown cycle starts. @@ -903,6 +912,32 @@ Note that the power information refers to what is actually supplied to the batte External power is always converted before it reaches the battery. +### Profiles + +Those are simply different config files. +A config path can be supplied as first argument to `acca` and second to `accd` executables. + +Examples: + +_Copy the config:_ + +Current config: `/dev/.vr25/acc/acca --config cat > /path/to/new/file` + +Default config: `/dev/.vr25/acc/acca /path/to/new/file --version` (`--version` can be replaced with any option + arguments, as seen below.) + +_Edit the copy:_ + +`/dev/.vr25/acc/acca /path/to/new/file --set pause_capacity=75 resume_capacity=70` (if the file does not exist, it is created as a copy of the default config.) + +_Use the copy:_ + +`/dev/.vr25/acc/accd --init /path/to/new/file` (the daemon is restarted with the new config.) + +_Back to the main config:_ + +`/dev/.vr25/acc/accd --init` + + ### More ACC daemon does not have to be restarted after making changes to the config. @@ -910,8 +945,8 @@ It picks up new changes within seconds. There are a few exceptions: -- `capacity_mask` (`cm`) and `charging_switch` (`s`) requires a daemon restart. -- `current_workaround` (`cw`) requires `accd --init`. +- `charging_switch` (`s`) requires a daemon restart (`/dev/.vr25/acc/accd`). +- `current_workaround` (`cw`) requires a full re-initialization (`/dev/.vr25/acc/accd --init`). This information is in the [default configuration](#default-configuration) section as well. @@ -926,7 +961,7 @@ When Android's battery level differs from that of the kernel, ACC daemon automat Pixel devices are known for having battery level discrepancies for the longest time. -If your device shuts down before the battery is actually empty, capacity_mask may help. +If your device shuts down before the battery is actually empty, capacity_sync or capacity_mask may help. Refer to the [default configuration](#default-configuration) section above for details. @@ -1327,14 +1362,6 @@ A common workaround is having `resume_capacity = pause_capacity - 1`. e.g., resu ## LATEST CHANGES -**v2021.8.31 (202108310)** - -- Additional charging switches -- Fixed "current_now is always 0 mA." -- Logs are exported as a tarball archive. -- Updated readme > notes/tips for front-end developers > initializing acc - - **v2021.9.5 (202109050)** - Additional charging switches (including a group of 3 for OnePlus that allegedly enable idle mode) @@ -1357,3 +1384,11 @@ A common workaround is having `resume_capacity = pause_capacity - 1`. e.g., resu - Support for "volatile" plugins (gone on reboot, useful for debugging): `/dev/.vr25/acc/plugins/` - Updated documentation (mainly tips > idle mode and alternatives) - Upgrade rollback feature (`-b|--rollback` or wizard option `f`) + + +**v2021.9.20 (202109200)** + +- General enhancements +- Manual capacitySync toggle (`[capacity_sync|cs] = [true|false]`) - it overrides the automatic. Both include the `freeze at 2%` feature. This is the actual `capacity_freeze2` replacement now. `capacity_mask` implies `capacity_sync`. +- Unlike in previous versions, changes to `capacity_mask` and `capacity_sync` take effect (within a few seconds) without a daemon restart. +- Updated documentation diff --git a/acc/accd.sh b/acc/accd.sh index d205e60..ff8f230 100644 --- a/acc/accd.sh +++ b/acc/accd.sh @@ -116,6 +116,14 @@ if ! $init; then . $config not_charging || isCharging=true + # dynamically toggle capacitySync + if ${capacity[4]} || ${capacity[5]}; then + capacitySync=true + else + cmd_batt reset + capacitySync=false + fi + # run custom code eval "${loopCmd[@]-}" @@ -128,12 +136,12 @@ if ! $init; then if $isCharging; then - # read chgStatusCode once - [ -n "$chgStatusCode" ] || { - cmd_batt reset - chgStatusCode=$(dumpsys battery 2>/dev/null | sed -n 's/^ status: //p') || : - ! ${capacity[4]} || capacitySync=true - } + # set chgStatusCode and capacitySync + if [ -z "$chgStatusCode" ] && cmd_batt reset \ + && chgStatusCode=$(dumpsys battery 2>/dev/null | sed -n 's/^ status: //p') + then + setup_capacity_sync + fi # read charging current ctrl files (part 2) once $chCurrRead || { @@ -153,20 +161,12 @@ if ! $init; then [ -z "${chargingDisabled-}" ] || chargingDisabled=false - # read dischgStatusCode once - # and dynamically enable/disable capacitySync - [ -n "$dischgStatusCode" ] || { - ! cmd_batt reset || { - ! dischgStatusCode=$(dumpsys battery 2>/dev/null | sed -n 's/^ status: //p') || { - if ${capacity[4]} || { [ $(dumpsys battery 2>/dev/null | sed -n 's/^ level: //p') -ne $(cat $batt/capacity) ] \ - && sleep 2 \ - && [ $(dumpsys battery 2>/dev/null | sed -n 's/^ level: //p') -ne $(cat $batt/capacity) ]; } - then - capacitySync=true - fi - } - } - } + # set dischgStatusCode and capacitySync + if [ -z "$dischgStatusCode" ] && cmd_batt reset \ + && dischgStatusCode=$(dumpsys battery 2>/dev/null | sed -n 's/^ status: //p') + then + setup_capacity_sync + fi if ! $cooldown; then @@ -313,6 +313,59 @@ if ! $init; then } + setup_capacity_sync(){ + if ! $capacitySync; then + if ${capacity[4]} || ${capacity[5]} || \ + { [ $(dumpsys battery 2>/dev/null | sed -n 's/^ level: //p') -ne $(cat $batt/capacity) ] \ + && sleep 2 \ + && [ $(dumpsys battery 2>/dev/null | sed -n 's/^ level: //p') -ne $(cat $batt/capacity) ]; } + then + capacitySync=true + fi + fi + } + + + sync_capacity() { + + ! $capacitySync || { + + isCharging=${isCharging:-false} + local isCharging_=$isCharging + local battCap=$(cat $batt/capacity) + + ! ${capacity[5]} || { + if [ ${capacity[3]} -gt 3000 ]; then + local maskedCap=$battCap + else + local capFactor=$(calc 100 / ${capacity[3]}) + local maskedCap=$(printf "%.*f" 0 $(calc $battCap \* $capFactor)) + fi + } + + ! $cooldown || isCharging=true + + if $isCharging; then + cmd_batt set ac 1 + cmd_batt set status $chgStatusCode + else + cmd_batt unplug + cmd_batt set status $dischgStatusCode + fi + + isCharging=$isCharging_ + + [ $battCap -lt 2 ] || { + if ${capacity[5]}; then + cmd_batt set level $maskedCap + else + cmd_batt set level $battCap + fi + } + } + } + + # load generic functions . $execDir/misc-functions.sh diff --git a/acc/default-config.txt b/acc/default-config.txt index 46ff6d8..0ce91f4 100644 --- a/acc/default-config.txt +++ b/acc/default-config.txt @@ -1,5 +1,5 @@ -configVerCode=202109190 -capacity=(-1 60 70 75 false) +configVerCode=202109200 +capacity=(-1 60 70 75 false false) temperature=(40 60 90 65) cooldownRatio=() cooldownCurrent= @@ -36,16 +36,16 @@ currentWorkaround=false # NOTES -# The daemon does not have to be restarted after making changes to this file - unless one of the changes is capacity_mask or charging_switch. +# The daemon does not have to be restarted after making changes to this file - unless one of the changes is charging_switch. -# Changes to current_workaround (cw) only take effect after an acc [re]initialization (install, upgrade or accd --init) or system reboot. +# A change to current_workaround (cw) only takes effect after an acc [re]initialization (install, upgrade or "accd --init") or system reboot. -# If those 3 variables are updated with "acc --set", accd is restarted automatically (--init is implied as needed). +# If those 2 variables are updated with "acc --set" (not acca --set), accd is restarted automatically (--init is implied as needed). # BASICS -# capacity=(shutdown_capacity cooldown_capacity resume_capacity pause_capacity capacity_mask) +# capacity=(shutdown_capacity cooldown_capacity resume_capacity pause_capacity capacity_sync capacity_mask) # temperature=(cooldown_temp max_temp max_temp_pause shutdown_temp) @@ -91,6 +91,7 @@ currentWorkaround=false # cc cooldown_capacity # rc resume_capacity # pc pause_capacity +# cs capacity_sync # cm capacity_mask # sc shutdown_capacity @@ -183,10 +184,17 @@ currentWorkaround=false # pause_capacity (pc) # # Capacity or voltage_now_millivolts at which charging should pause. +# capacity_sync (cs) # +# Some devices, notably from the Pixel lineup, have a capacity discrepancy issue between Android and the kernel. +# capacity_sync forces Android to report the actual battery capacity supplied by the kernel. +# The discrepancy is usually detected and corrected automatically by accd. +# This setting overrides the automatic behavior. +# Besides, it also prevents Android from getting capacity readings below 2%, since some systems shutdown before battery level actually drops to 0%. + # capacity_mask (cm) # -# This forces Android to report "capacity = capacity * (100 / pause_capacity)", effectively masking capacity limits. -# It also prevents Android from getting capacity readings below 2% (because some systems shutdown before battery level actually drops to 0%). -# A daemon restart is required after changing this (automated by "acc --set"). +# Implies capacity_sync. +# This forces Android to report "capacity = capacity * (100 / pause_capacity)", effectively masking capacity limits (more like capacity_sync on steroids). +# It also prevents Android from getting capacity readings below 2%, since some systems shutdown before battery level actually drops to 0%. # cooldown_temp (ct) # # Temperature (°C) at which the cooldown cycle starts. diff --git a/acc/misc-functions.sh b/acc/misc-functions.sh index 70319b5..f3730f8 100644 --- a/acc/misc-functions.sh +++ b/acc/misc-functions.sh @@ -298,33 +298,6 @@ print_wait_plug() { } -sync_capacity() { - - isCharging=${isCharging:-false} - local isCharging_=$isCharging - local battCap=$(cat $batt/capacity) - local capFactor=$(calc 100 / ${capacity[3]}) - local maskedCap=$(printf "%.*f" 0 $(calc $battCap \* $capFactor)) - - ! $capacitySync || { - ! $cooldown || isCharging=true - if $isCharging; then - cmd_batt set ac 1 - cmd_batt set status $chgStatusCode - else - cmd_batt unplug - cmd_batt set status $dischgStatusCode - fi - isCharging=$isCharging_ - if ${capacity[4]}; then - [ $battCap -lt 2 ] || cmd_batt set level $maskedCap - else - cmd_batt set level $battCap - fi - } -} - - sleep_sd() { local i= for i in 1 2 3 4; do diff --git a/acc/print-config.sh b/acc/print-config.sh index fa7e94c..19dba3d 100644 --- a/acc/print-config.sh +++ b/acc/print-config.sh @@ -3,7 +3,8 @@ set +u echo "shutdown_capacity=${capacity[0]} resume_capacity=${capacity[2]} pause_capacity=${capacity[3]} -capacity_mask=${capacity[4]} +capacity_sync=${capacity[4]} +capacity_mask=${capacity[5]} cooldown_capacity=${capacity[1]} cooldown_temp=${temperature[0]} diff --git a/acc/set-prop.sh b/acc/set-prop.sh index 2f67f9e..2833dfd 100644 --- a/acc/set-prop.sh +++ b/acc/set-prop.sh @@ -102,8 +102,9 @@ set_prop() { esac # check whether a daemon restart is required (to restore defaults) - if { [ ".${chargingSwitch[0]-x}" != .x ] && [ ".${s-${charging_switch-x}}" != .x ]; } \ - || [ ".${cm-${capacity_mask-x}}" != .x ] || [ ".${cw-${current_workaround-x}}" != .x ] + if { [ ".${chargingSwitch[0]-x}" != .x ] \ + && [ ".${s-${charging_switch-x}}" != .x ]; } \ + || [ ".${cw-${current_workaround-x}}" != .x ] then ! daemon_ctrl stop || restartDaemon=true fi > /dev/null diff --git a/acc/write-config.sh b/acc/write-config.sh index d49cf87..150dcc6 100644 --- a/acc/write-config.sh +++ b/acc/write-config.sh @@ -4,7 +4,8 @@ sc=${shutdown_capacity-${sc-${capacity[0]}}} cc=${cooldown_capacity-${cc-${capacity[1]}}} rc=${resume_capacity-${rc-${capacity[2]}}} pc=${pause_capacity-${pc-${capacity[3]}}} -cm=${capacity_mask-${cm-${capacity[4]}}} +cs=${capacity_sync-${cs-${capacity[4]}}} +cm=${capacity_mask-${cm-${capacity[5]}}} ct=${cooldown_temp-${ct-${temperature[0]}}} mt=${max_temp-${mt-${temperature[1]}}} @@ -45,7 +46,7 @@ cw=${current_workaround-${cw-$currentWorkaround}} { echo "configVerCode=$(cat $TMPDIR/.config-ver) -capacity=(${sc:-0} ${cc:-60} ${rc:-70} ${pc:-75} ${cm:-false}) +capacity=(${sc:-0} ${cc:-60} ${rc:-70} ${pc:-75} ${cs:-false} ${cm:-false}) temperature=(${ct:-40} ${mt:-60} ${mtp:-90} ${st:-65}) cooldownRatio=($cch $cp) cooldownCurrent=$cdc diff --git a/module.prop b/module.prop index b7bf11c..8297b2a 100644 --- a/module.prop +++ b/module.prop @@ -1,7 +1,7 @@ id=acc domain=vr25 name=Advanced Charging Controller (ACC) -version=v2021.9.19 -versionCode=202109190 +version=v2021.9.20 +versionCode=202109200 author=VR25 description=Mainly intended for extending battery service life on Android devices. In a nutshell, this is achieved through limiting charging current, temperature and voltage. Any root solution is supported. The installation is always "system-less", whether or not the system is rooted with Magisk.