From e44eae6f2a5d9ca2c2c356917da3d15f6bad2e8d Mon Sep 17 00:00:00 2001 From: VR-25 <28943176+VR-25@users.noreply.github.com> Date: Sat, 4 Jun 2022 13:27:02 +0100 Subject: [PATCH] **v2022.6.4 (202206040)** - `-n|--notif [[string] [user]]`: post Android notification; may not work on all systems; - `-t|--test [p|parse]`: parse potential charging switches from power supply log (as `acc -p`), test them all, and add the working ones to the list of known switches; implies `-x`; - `acc -p`: exclude all known switches and additional troublesome ctrl files; - `acc -s`: Enforce valid pause_capacity and resume_capacity difference; - `acc -t`: show more useful information; source read-ch-curr-ctrl-files-p2.sh; - `accd`: if possible, avoid idle mode when capacity > pause_capacity; - Additional charging switches; - Blacklisted usb/vbus_disable; - Fixed `accd /path/to/config --init`; - Fixed `runCmdOnPause` and `loopCmd` parsing issues; - Fixed: "after a reboot, accd doesn't control charging, until the keyguard is unlocked"; - General refactor; - Hard reset wipes config and control file blacklists (`acc -sr a` or acc --set --reset a); - Improved advanced battery status detection; - Misc fixes & optimizations; - New config variables: `batt_status_override=Idle|Discharging|'custom'`, `batt_status_workaround=true`, `reboot_resume=false`, `reset_batt_stats_on_plug=false`, `schedule='HHMM command...'` (refer to the config or readme files for details); - One-line scripts; - Parse config `ampFactor` from `batt-interface.sh` as well; - Post exit code notification if accd stops due to an error; - Removed obsolete source code files; - Run dexopt-job only once per boot session (if battery is charging, and system has been up for at least 15 minutes); - Save acc -t output to /sdcard/Download/acc-t_output.txt; - Tuning variables for not_charging() timeout (seqCount) and voltage-based idle mode (voltOff); - Updated documentation; - Updates can be downloaded with busybox's wget as well (may not work on all systems). Try upgrading with `acc -u`. --- META-INF/com/google/android/update-binary | 20 +- README.md | 277 +++++++++++------- TODO.txt | 7 + acc/batt-interface.sh | 115 -------- acc/translations/pt-PT/strings.sh | 125 -------- bin/acc_flashable_uninstaller.zip | Bin 2021 -> 2019 bytes build.sh | 34 ++- bundle.bat | 2 - bundle.sh | 19 -- changelog.md | 42 ++- customize.sh | 20 +- framework-details.txt | 70 ----- install-online.sh | 18 +- install-tarball.sh | 6 +- install.sh | 20 +- {acc => install}/acc.sh | 130 +++++--- {acc => install}/acca.sh | 24 +- {acc => install}/accd.sh | 142 ++++++--- {acc => install}/acquire-lock.sh | 0 {acc => install}/batt-info.sh | 2 +- install/batt-interface.sh | 161 ++++++++++ {acc => install}/ctrl-files.sh | 18 +- {acc => install}/default-config.txt | 156 +++++++--- {acc => install}/flash-zips.sh | 2 +- {acc => install}/logf.sh | 4 +- {acc => install}/misc-functions.sh | 187 ++++++------ {acc => install}/oem-custom.sh | 1 + {acc => install}/power-supply-logger.sh | 2 +- {acc => install}/print-config.sh | 14 +- {acc => install}/print-help.sh | 0 .../read-ch-curr-ctrl-files-p2.sh | 9 +- {acc => install}/release-lock.sh | 0 {acc => install}/select.sh | 0 {acc => install}/service.sh | 0 {acc => install}/set-ch-curr.sh | 2 +- {acc => install}/set-ch-volt.sh | 4 +- {acc => install}/set-prop.sh | 7 +- {acc => install}/setup-busybox.sh | 4 +- {acc => install}/strings.sh | 155 ++++++---- {acc => install}/translations/de-DE/README.md | 0 .../translations/de-DE/strings.sh | 78 ++--- {acc => install}/translations/id/strings.sh | 60 ++-- {acc => install}/translations/pt-PT/README.md | 0 install/translations/pt-PT/strings.sh | 125 ++++++++ .../translations/zh-rCN/README.md | 0 .../translations/zh-rCN/strings.sh | 34 +-- .../translations/zh-rTW/README.md | 0 .../translations/zh-rTW/strings.sh | 34 +-- {acc => install}/uninstall.sh | 8 +- {acc => install}/wizard.sh | 2 +- {acc => install}/write-config.sh | 71 ++++- module.json | 10 +- module.prop | 4 +- 53 files changed, 1279 insertions(+), 946 deletions(-) delete mode 100644 acc/batt-interface.sh delete mode 100644 acc/translations/pt-PT/strings.sh delete mode 100644 bundle.bat delete mode 100644 bundle.sh delete mode 100644 framework-details.txt rename {acc => install}/acc.sh (77%) rename {acc => install}/acca.sh (85%) rename {acc => install}/accd.sh (80%) rename {acc => install}/acquire-lock.sh (100%) rename {acc => install}/batt-info.sh (97%) create mode 100644 install/batt-interface.sh rename {acc => install}/ctrl-files.sh (94%) rename {acc => install}/default-config.txt (67%) rename {acc => install}/flash-zips.sh (98%) rename {acc => install}/logf.sh (94%) rename {acc => install}/misc-functions.sh (67%) rename {acc => install}/oem-custom.sh (95%) rename {acc => install}/power-supply-logger.sh (96%) rename {acc => install}/print-config.sh (76%) rename {acc => install}/print-help.sh (100%) rename {acc => install}/read-ch-curr-ctrl-files-p2.sh (85%) rename {acc => install}/release-lock.sh (100%) rename {acc => install}/select.sh (100%) rename {acc => install}/service.sh (100%) rename {acc => install}/set-ch-curr.sh (96%) rename {acc => install}/set-ch-volt.sh (88%) rename {acc => install}/set-prop.sh (94%) rename {acc => install}/setup-busybox.sh (87%) rename {acc => install}/strings.sh (68%) rename {acc => install}/translations/de-DE/README.md (100%) rename {acc => install}/translations/de-DE/strings.sh (84%) rename {acc => install}/translations/id/strings.sh (61%) rename {acc => install}/translations/pt-PT/README.md (100%) create mode 100644 install/translations/pt-PT/strings.sh rename {acc => install}/translations/zh-rCN/README.md (100%) rename {acc => install}/translations/zh-rCN/strings.sh (54%) rename {acc => install}/translations/zh-rTW/README.md (100%) rename {acc => install}/translations/zh-rTW/strings.sh (54%) rename {acc => install}/uninstall.sh (91%) rename {acc => install}/wizard.sh (98%) rename {acc => install}/write-config.sh (62%) diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary index 1b365e1..5df3fd4 100644 --- a/META-INF/com/google/android/update-binary +++ b/META-INF/com/google/android/update-binary @@ -37,7 +37,7 @@ trap exxit EXIT # set up busybox #BB# -bin_dir=/data/adb/bin +bin_dir=/data/adb/vr25/bin busybox_dir=/dev/.vr25/busybox magisk_busybox=/data/adb/magisk/busybox [ -x $busybox_dir/ls ] || { @@ -51,7 +51,7 @@ magisk_busybox=/data/adb/magisk/busybox } done [ -x $busybox_dir/ls ] || { - echo "(!) Install busybox or simply place it in $bin_dir/" + echo "Install busybox or simply place it in $bin_dir/" echo exit 3 } @@ -66,7 +66,7 @@ unset f bin_dir busybox_dir magisk_busybox # root check [ $(id -u) -ne 0 ] && { - echo "(!) $0 must run as root (su)" + echo "$0 must run as root (su)" exit 4 } @@ -97,7 +97,7 @@ set -eu srcDir="$(cd "${0%/*}" 2>/dev/null || :; echo "$PWD")" # extract flashable zip if source code is unavailable -[ -d $srcDir/$id ] || { +[ -d $srcDir/install ] || { srcDir=/dev/.$domain.${id}-install rm -rf $srcDir 2>/dev/null || : mkdir $srcDir @@ -153,7 +153,7 @@ echo "$name $version ($versionCode) Copyright 2017-2022, $author GPLv3+ -(i) Installing in $installDir/$id/..." +Installing in $installDir/$id/..." # backup @@ -162,8 +162,8 @@ mkdir -p $data_dir/backup cp -aH /data/adb/$domain/$id/* $config $data_dir/backup/ 2>/dev/null || : -/system/bin/sh $srcDir/$id/uninstall.sh install -cp -R $srcDir/$id/ $installDir/ +/system/bin/sh $srcDir/install/uninstall.sh install +cp -R $srcDir/install/ $installDir/$id installDir=$(readlink -f $installDir/$id) cp $srcDir/module.prop $installDir/ cp -f $srcDir/README.* $data_dir/ @@ -267,7 +267,7 @@ cat $srcDir/changelog.md printf "\n\n" -echo "(i) Rebooting is unnecessary +echo "Rebooting is unnecessary. - $id commands may require the "/dev/.$domain/$id/" prefix (e.g., /dev/.$domain/$id/$id -v) until system is rebooted. - Daemon started." @@ -275,13 +275,13 @@ echo "(i) Rebooting is unnecessary case $installDir in /data/adb/modules*) ;; *) echo " -(i) Non-Magisk users can enable $id auto-start by running /data/adb/$domain/$id/service.sh, a copy of, or a link to it - with init.d or an app that emulates it.";; +Non-Magisk users can enable $id auto-start by running /data/adb/$domain/$id/service.sh, a copy of, or a link to it - with init.d or an app that emulates it.";; esac #legacy f=$data_dir/logs/ps-blacklist.log [ -f $f ] || mv $data_dir/logs/psl-blacklist.txt $f 2>/dev/null -rm $data_dir/${id}-uninstaller.zip 2>/dev/null +rm $data_dir/${id}-uninstaller.zip $data_dir/logs/*.tar.gz $data_dir/curr 2>/dev/null # initialize $id /data/adb/$domain/$id/service.sh --init diff --git a/README.md b/README.md index f9960b1..035f7d9 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,6 @@ As the project gets bigger and more popular, the need for coffee goes up as well - Android or Android based OS - Any root solution (e.g., [Magisk](https://github.com/topjohnwu/Magisk)) - [Busybox\*](https://github.com/Magisk-Modules-Repo/busybox-ndk) (only if not rooted with Magisk) -- [curl](https://github.com/Zackptg5/Cross-Compiled-Binaries-Android/tree/master/curl) (for acc --upgrade, optional) - Non-Magisk users can enable acc auto-start by running /data/adb/vr25/acc/service.sh, a copy of, or a link to it - with init.d or an app that emulates it. - Terminal emulator - Text editor (optional) @@ -201,8 +200,6 @@ or `curl -L# https://github.com/VR-25/acc/archive/master.tar.gz | tar -xz` Refer to framework-details.txt for a full list of tasks carried out by it. To skip generating archives, run the build script with a random argument (e.g. bash build.sh h). -- The output files are (in `_builds/acc-$versionCode/`): `acc-$versionCode.zip`, `acc-$versionCode.tar.gz`, and `install-tarball.sh`. - - To update the local source code, run `git pull --force` or re-download it (with wget/curl) as described above. @@ -240,25 +237,48 @@ In interactive mode, it also asks the user whether they want to download and ins ``` #DC# -configVerCode=202202060 +configVerCode=202206010 + capacity=(-1 60 70 75 false false) + temperature=(40 60 90 65) + cooldownRatio=() cooldownCurrent= cooldownCustom=() -resetBattStats=(false false) + +resetBattStats=(false false false) + chargingSwitch=() + applyOnBoot=() + applyOnPlug=() + maxChargingCurrent=() + maxChargingVoltage=() -language=en -runCmdOnPause=() + +language= + +runCmdOnPause='' + ampFactor= voltFactor= -loopCmd=() + +loopCmd='' + prioritizeBattIdleMode=false currentWorkaround=false +battStatusWorkaround=true + +schedule='' + +battStatusOverride='' + +rebootResume=false + +: one-line script sample; echo nothing >/dev/null # WARNINGS @@ -282,7 +302,9 @@ currentWorkaround=false # A change to current_workaround (cw) only takes effect after an acc [re]initialization (install, upgrade or "accd --init") or system reboot. -# If those 2 variables are updated with "acc --set" (not acca --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). + +# The only nullable variables are those which are null by default (var=, var="" and var=()). # BASICS @@ -297,7 +319,7 @@ currentWorkaround=false # cooldownCurrent=cooldown_current=[milliamps] -# resetBattStats=(reset_batt_stats_on_pause reset_batt_stats_on_unplug) +# resetBattStats=(reset_batt_stats_on_pause reset_batt_stats_on_unplug reset_batt_stats_on_plug) # chargingSwitch=charging_switch=(ctrl_file1 on off ctrl_file2 on off --) @@ -319,20 +341,30 @@ currentWorkaround=false # language=lang=language_code -# runCmdOnPause=run_cmd_on_pause=(. script) +# runCmdOnPause=run_cmd_on_pause='command...' # ampFactor=amp_factor=[multiplier] # voltFactor=volt_factor=[multiplier] -# loopCmd=loop_cmd=(. script) +# loopCmd=loop_cmd='command...' # prioritizeBattIdleMode=prioritize_batt_idle_mode=boolean # currentWorkaround=current_workaround=boolean +# battStatusWorkaround=batt_status_workaround=boolean + +# schedule=sched='HHMM command... +# HHMM command... +# ...' + +# battStatusOverride=batt_status_override=Idle|Discharging|'code to PRINT value for _status' + +# rebootResume=reboot_resume=boolean + -# VARIABLE ALIASES/SHORTCUTS +# ALIASES/SHORTCUTS # cc cooldown_capacity # rc resume_capacity @@ -355,6 +387,7 @@ currentWorkaround=false # rbsp reset_batt_stats_on_pause # rbsu reset_batt_stats_on_unplug +# rbspl reset_batt_stats_on_plug # s charging_switch @@ -371,42 +404,15 @@ currentWorkaround=false # vf volt_factor # lc loop_cmd + # pbim prioritize_batt_idle_mode # cw current_workaround +# bsw batt_status_workaround +# sd sched -# COMMAND EXAMPLES - -# acc 85 80 -# acc -s pc=85 rc=80 -# acc --set pause_capacity=85 resume_capacity=80 - -# acc -s "s=battery/charging_enabled 1 0" -# acc --set "charging_switch=/proc/mtk_battery_cmd/current_cmd 0::0 0::1 /proc/mtk_battery_cmd/en_power_path 1 0" -# NOTE: "::" is used as a whitespace placeholder in "/proc/mtk_battery_cmd/current_cmd 0::0 0::1" charging switch only. - -# acc -s -v 3920 (millivolts) -# acc -s -c 500 (milliamps) - -# custom config path -# acc /data/acc-night-config.txt 45 43 -# acc /data/acc-night-config.txt -s c 500 -# accd /data/acc-night-config.txt - -# acc -s "ccu=battery/current_now 1450000 100 20" -# acc -s "cooldown_custom=battery/current_now 1450000 100 20" -# acc -s ccu="/sys/devices/virtual/thermal/thermal_zone1/temp 55 50 10" - -# acc -s amp_factor=1000 -# acc -s volt_factor=1000000 - -# acc -s mcc=500 mcv="3920 --exit" - -# acc -s loop_cmd="echo 0 \\> battery/input_suspend" - -# acc -s cooldown_current=500 - -# acc -s st=60 +# bso batt_status_override +# rr reboot_resume # FINE, BUT WHAT DOES EACH OF THESE VARIABLES ACTUALLY MEAN? @@ -467,7 +473,6 @@ currentWorkaround=false # cooldown_custom (ccu) # # When cooldown_capacity and/or cooldown_temp don't suit your needs, this comes to the rescue. # It takes precedence over the regular cooldown settings. -# Refer back the command examples. # cooldown_current (cdc) # # Instead of pausing charging periodically during the cooldown phase, limit the max charging current (e.g., to 500 mA) @@ -476,7 +481,10 @@ currentWorkaround=false # Reset battery stats after pausing charging. # reset_batt_stats_on_unplug (rbsu) # -# Reset battery stats if the charger has been unplugged for 10 seconds. +# Reset battery stats if the charger has been unplugged for a few seconds. + +# reset_batt_stats_on_plug (rbspl) # +# Reset battery stats if the charger has been plugged for a few seconds. # charging_switch (s) # # If unset, acc cycles through its database and sets the first working switch/group that disables charging. @@ -506,10 +514,10 @@ currentWorkaround=false # max_charging_voltage (mcv) # # Only the current/voltage value is to be supplied. # Control files are automatically selected. -# Refer back to the command examples. # lang (l) # -# acc language, managed with "acc --set --lang" (acc -s l). +# acc language, managed with "acc --set --lang" (acc -sl). +# When null, English (en) is assumed. # run_cmd_on_pause (rcp) # # Run commands* after pausing charging. @@ -525,7 +533,7 @@ currentWorkaround=false # loop_cmd (lc) # # This is meant for extending accd's functionality. -# It is periodically executed by is_charging() - which is called regularly, within the main accd loop. +# It is periodically executed by the is_charging function -- which is called regularly, within the main accd loop. # The boolean isCharging is available. # Refer back to COMMAND EXAMPLES. @@ -540,6 +548,57 @@ currentWorkaround=false # Try this if low current values don't work. # "accd --init" is required after changing this (automated by "acc --set"). +# batt_status_workaround (bsw) # +# With this enabled, in addition to just reading POWER_SUPPLY_STATUS, if the battery is "Charging" and current is within -11 and 95 mA (inclusive), battery status is considered "Idle". Status is considered "Discharging", if current drops significantly, after calling the disable_charging function. +# By not relying solely on the information provided by POWER_SUPPLY_STATUS, this approach boosts compatibility quite dramatically. So much so, that on certain devices (e.g., Nokia 2.2), acc only works when this is enabled. +# On the other hand, the user may observe charging control inconsistencies on devices that report wrong current values or major current fluctuations. +# Oftentimes, charging control issues are related to the power adapter. + +# sched (sd) # +# Command/script schedules, in the following format: +# +# sched="HHMM command... +# HHMM command... +# ..." +# +# e.g., 3900 mV at 22:00, and 4100 mV at 6:00, daily: +# sched="2200 acc -s mcv=3900 +# 0600 acc -s mcv=4100" +# +# 12 hour format is not supported. +# Each schedule must be on its own line. +# Each line is daemonized. +# This is not limited to acc commands. It can run anything. +# +# Commands: +# -s|--set [sd|sched]="[+-]schedule to add or pattern to delete" +# e.g., +# acc -s sd=-2050 (delete schedules that match 2050) +# acc -s sd="+2200 acc -s mcv=3900 mcc=500; acc -n "Switched to \"sleep\" profile" (append schedule) +# Note: "acc -s sd=" behaves just like similar commands (restores default value; for schedules, it's null) + +# batt_status_override (bso) # +# Overrides the battery status determined by the not_charging function. +# It can be Idle, Discharging (both case sensitive), or logic to PRINT the desired value for the _status variable. +# When set to Idle or Discharging, _status will be set to that value if the enforced* charging switch state is off. +# It only works in conjunction with an enforced charging switch (set manually, has a trailing " --"). +# +# Usage scenario: the switch "main/cool_mode 0 1" supports idle mode. However, sometimes it does not respond soon enough (e.g., due to fast charging). The user can then enforce it with acc -ss and set batt_status_override=Idle. This means, when main/cool_mode is on (0), _status will be determined by the not_charging function (as usual), but when it's off (1), _status will be Idle, bypassing the not_charging function. +# +# If the user were to write their own logic, it would've be something as follows: +# batt_status_override='[ $(cat main/cool_mode) -eq 1 ] && printf Idle' + +# reboot_resume (rr) # +# Reboot (when capacity <= resume_capacity) to re-enable charging. +# A warning notification is posted 60 seconds prior, for the user to block the action, if they so please. + +# one-line scripts # +# Every line that begins with ": " is interpreted as a one-line script. +# This feature can be useful for many things, including setting up persistent config profiles (source a file that overrides the main config). +# All script lines are executed whenever the config is loaded/sourced. +# This happens regularly while the daemon is running, and at least once per command run. +# Warning: all files used in one-line scripts must reside somewhere in /data/adb/, just like acc's own data files. + #/DC# ``` @@ -577,20 +636,24 @@ Usage e.g., acc 75 70 acc 80 (resume_capacity defaults to 80% - 5) - acc 3920 (same as acc 3920 3870, great idle mode alternative) + acc 3900 (same as acc 3900 3870, great idle mode alternative) acc [options] [args] Refer to the list of options below acca [options] [args] acc optimized for front-ends - acc[d] -x [options] [args] Sets log=/sdcard/acc[d]-${device}.log; useful for debugging unwanted reboots + acc[d] -x [options] [args] Sets log=/sdcard/Download/acc[d]-${device}.log; useful for debugging unwanted reboots A custom config path can be specified as first parameter (second if -x is used). If the file doesn't exist, the current config is cloned. e.g., acc /data/acc-night-config.txt --set pause_capacity=45 resume_capacity=43 acc /data/acc-night-config.txt --set --current 500 - accd /data/acc-night-config.txt + accd /data/acc-night-config.txt --init + + Notes regarding accd: + - The order of "--init|-i" does not matter. + - The config path string shall not contain "--init|-i". Options @@ -649,12 +712,15 @@ Options -la Same as -l -a - -l|--log -e|--export Export all logs to /data/adb/vr25/acc-data/logs/acc-logs-$deviceName.tar.gz + -l|--log -e|--export Export all logs to /logs/acc-logs-$deviceName.tgz e.g., acc -l -e -le Same as -l -e - -p|--parse [ ]|[file to parse] Helps find potential charging switches quickly, for any device + -n|--notif [["STRING" (default: ":)")] [USER ID (default: 2000 (shell))]] Post Android notification; may not work on all systems + e.g., acc -n "Hello, World!" + + -p|--parse [ ] | ] Helps find potential charging switches quickly, for any device e.g., acc -p Parse /logs/power_supply-\*.log and print potential charging switches not present in /ch-switches acc -p /sdcard/power_supply-harpia.log Parse the given file and print potential charging switches that are not already in /ch-switches @@ -676,7 +742,13 @@ Options acc -s charging_switch= acc -s pause_capacity=60 resume_capacity=55 (shortcuts: acc -s pc=60 rc=55, acc 60 55) acc -s "charging_switch=battery/charging_enabled 1 0" resume_capacity=55 pause_capacity=60 - Note: all properties have short aliases for faster typing; run "acc -c cat" to see these + Note: all properties have short aliases for faster typing; run "acc -c cat" to see them + + -s|--set [sd|sched]="[+-]schedule to add or pattern to delete" + e.g., + acc -s sd=-2050 (delete schedules that match 2050) + acc -s sd="+2200 acc -s mcv=3900 mcc=500; acc -n "Switched to \"sleep\" profile" (append schedule) + Note: "acc -s sd=" behaves just like similar commands (restores default value; for schedules, it's null) -s|--set c|--current [milliamps|-] Set/print/restore_default max charging current (range: 0-9999 Milliamps) e.g., @@ -702,12 +774,12 @@ Options -sp [egrep regex (default: ".")] Same as above - -s|--set r|--reset Restore default config + -s|--set r|--reset [a] Restore default config ("a" is for "all": config and control file blacklists, essentially a hard reset) e.g., acc -s r - rm /data/adb/vr25/acc-data/config.txt (failsafe) - -sr Same as above + -sr [a] Same as above + -s|--set s|charging_switch Enforce a specific charging switch e.g., acc -s s @@ -722,9 +794,9 @@ Options -s|--set v|--voltage [millivolts|-] [--exit] Set/print/restore_default max charging voltage (range: 3700-4300 Millivolts) e.g., acc -s v (print) - acc -s v 3920 (set) + acc -s v 3900 (set) acc -s v - (restore default) - acc -s v 3920 --exit (stop the daemon after applying settings) + acc -s v 3900 --exit (stop the daemon after applying settings) -sv [millivolts|-] [--exit] Same as above @@ -733,16 +805,19 @@ Options acc -t battery/charging_enabled 1 0 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 panic are automatically backlisted + -t|--test [file] Test charging switches from a file (default: /ch-switches) e.g., acc -t (test known switches) acc -t /sdcard/experimental_switches.txt (test custom/foreign switches) + -t|--test [p|parse] Parse potential charging switches from the power supply log (as "acc -p"), test them all, and add the working ones to the list of known switches + Implies -x, as acc -x -t p + e.g., acc -t p + -T|--logtail Monitor accd log (tail -F) e.g., acc -T - -u|--upgrade [-c|--changelog] [-f|--force] [-k|--insecure] [-n|--non-interactive] Online upgrade/downgrade (requires curl) + -u|--upgrade [-c|--changelog] [-f|--force] [-k|--insecure] [-n|--non-interactive] Online upgrade/downgrade e.g., acc -u dev (upgrade to the latest dev version) acc -u (latest version from the current branch) @@ -780,11 +855,12 @@ Exit Codes 10. All charging switches fail (--test) 11. Current (mA) out of 0-9999 range 12. Initialization failed - 13. Failed to lock /dev/.vr25/acc/acc.lock + 13. Failed to lock /acc.lock 14. ACC won't initialize, because the Magisk module disable flag is set 15. Idle mode is supported (--test) + 16. Failed to enable charging (--test) - Logs are exported automatically ("--log --export") on exit codes 1, 2, 7 and 10. + Logs are exported automatically ("--log --export") on exit codes 1, 2 and 7. Tips @@ -794,8 +870,8 @@ Tips acc -e 30m && acc -d 6h && acc -e 85 && accd Sample profile - acc -s pc=45 rc=43 mcc=500 mcv=3920 - This keeps battery capacity between 43-45%, limits charging current to 500 mA and voltage to 3920 millivolts. + acc -s pc=45 rc=43 mcc=500 mcv=3900 + This keeps battery capacity between 43-45%, limits charging current to 500 mA and voltage to 3900 millivolts. It's great for nighttime and "forever-plugged". Refer to acc -r (or --readme) for the full documentation (recommended) @@ -977,15 +1053,9 @@ This information is in the [default configuration](#default-configuration) secti ## TROUBLESHOOTING -### `acc -t` Results Seem Inconsistent +## acc -t Results Are Inconsistent -In enhanced charging status detection mode (default), if the battery is "Charging" and the absolute value of current is <= 15 mA (95 for mtk), the status is considered "Idle". -Furthermore, the battery status is considered "Discharging", if current drops by mA >= 100 after calling disable_charging(). -Although rare, this can cause charging control issues on some devices. -Hence, one may want to see if disabling it makes a difference. -However, before trying this, it's recommend to test a different power source. -Fast charging, in particular, is known for overriding/blocking custom charging control settings. -On certain devices (e.g., Nokia 2.2), acc only works when enhanced mode is enabled. +Refer to "default config > batt_status_workaround". ### Battery Capacity (% Level) Doesn't Seem Right @@ -1063,23 +1133,11 @@ Reminder: a daemon restart is required to load new/modified plugins. Volatile logs (gone on reboot) are stored in `/dev/.vr25/acc/` (.log files only). Persistent logs reside in `/data/adb/vr25/acc-data/logs/`. -`acc -le` exports all acc logs, plus Magisk's and extras to `/data/adb/acc-data/logs/acc-$device_codename.tar.gz`. +`acc -le` exports all acc logs, plus Magisk's and extras to `/data/adb/acc-data/logs/acc-$device_codename.tgz`. 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 `SETUP/USAGE > Terminal Commands > Exit Codes`). -### Finding Additional/Potential Charging Switches Quickly - -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 panic. -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 The daemon stop process implies complete reversal of changes made to the charging management system. @@ -1089,6 +1147,11 @@ That said, accd is always stopped _gracefully_ to ensure the restoration takes p One who knows what they're doing, can force-stop accd by running `pkill -9 -f accd`. +### Kernel Panic and Spontaneous Reboots + +Control files that trigger these are automatically backlisted (commented out in `/data/adb/acc-data/logs/write.log`). + + ### Restore Default Config This can potentially save a lot of time and grief. @@ -1218,13 +1281,13 @@ If it changes intermittently, the current is too low; increment it until the iss ### Generic -Emulate _battery idle mode_ with a voltage limit: `acc -s pc=101 rc=0 mcv=3920`. +Emulate _battery idle mode_ with a voltage limit: `acc -s pc=101 rc=0 mcv=3900`. The first two arguments disable the regular charging pause/resume functionality. The last sets a voltage limit that will dictate how much the battery should charge. The battery enters a _[pseudo] idle mode_ when its voltage peaks. Essentially, it works as a power buffer. -A similar effect can be achieved with settings such as `acc 60 59` (percentages) and `acc 3920` (millivolts). +A similar effect can be achieved with settings such as `acc 60 59` (percentages) and `acc 3900` (millivolts). Yet another way is limiting charging current to 0-250 mA or so (e.g., `acc -sc 0`). `acc -sc -` restores the default limit. @@ -1251,18 +1314,18 @@ Extremely slow discharge rate is expected. 2 - `charging_switch=0`: if current fluctuates, also set `current_workaround=true` (only takes affect after a reboot). If this method works, the behavior is exactly the same as `#1`. -3 - `charging_switch=3920`: only works on devices that actually support voltage control. -Unlike regular idle mode, this maintains 3920 mV (_the sweet spot_) indefinitely. +3 - `charging_switch=3900`: only works on devices that actually support voltage control. +Unlike regular idle mode, this maintains 3900 mV, indefinitely. This is not good with higher voltages. We're trying to minimize battery stress as much as possible. -Maintaining a voltage higher than 3920 for a long time is _not_ recommended. +Maintaining a voltage higher than 3900 for a long time is _not_ recommended. -4 - `acc 3920`: this is short for _acc 3920 3870_ (a 50 mV difference). -It tries to maintain 3920 mV without voltage control support. +4 - `acc 3900`: this is short for _acc 3900 3870_ (a 50 mV difference). +It tries to maintain 3900 mV without voltage control support. Yes, it's definitely not a joke. This works with regular charging switches and voltage readings. -5 - `acc 45 44`: this closely translates to 3920 mV under most circumstances. +5 - `acc 45 44`: this closely translates to 3900 mV under most circumstances. Voltage and capacity (%) do not have a linear relationship. Voltage varies with temperature, battery chemistry and age. @@ -1275,7 +1338,7 @@ Voltage varies with temperature, battery chemistry and age. Open issues on GitHub or contact the developer on Facebook, Telegram (preferred) or XDA (links below). Always provide as much information as possible. -Attach `/data/adb/vr25/acc-data/logs/acc-logs-*tar.gz` - generated by `acc -le` _right after_ the problem occurs. +Attach `/data/adb/vr25/acc-data/logs/acc-logs-*.tgz` - generated by `acc -le` _right after_ the problem occurs. Refer back to `TROUBLESHOOTING > Diagnostics/Logs` for additional details. @@ -1293,7 +1356,7 @@ 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. +ACC automatically optimizes system performance and battery utilization, by forcing `bg-dexopt-job` on daemon [re]start, once after boot, if charging and uptime >= 900 seconds. > I set voltage to 4080 mV and that corresponds to just about 75% charge. @@ -1307,16 +1370,12 @@ Otherwise, the other option is actually more beneficial - since it mitigates hig If you use both, simultaneously - you get the best of both worlds. On top of that, if you enable the cooldown cycle, it'll give you even more benefits. -Anyway, while the battery is happy in the 3700-4100 mV range, the optimal voltage for [the greatest] longevity is said\* to be ~3920 mV. - -If you're leaving your phone plugged in for extended periods of time, that's the voltage limit to aim for. - Ever wondered why lithium ion batteries aren't sold fully charged? They're usually ~40-60% charged. Why is that? Keeping a battery fully drained, almost fully drained or 70%+ charged for a long times, leads to significant (permanent) capacity loss Putting it all together in practice... -Night/heavy-duty profile: keep capacity within 40-60% and/or voltage around ~3920 mV +Night/heavy-duty profile: keep capacity within 40-60% and/or voltage around ~3900 mV Day/regular profile: max capacity: 75-80% and/or voltage no higher than 4100 mV @@ -1382,16 +1441,24 @@ A common workaround is having `resume_capacity = pause_capacity - 1`. e.g., resu ## LINKS - [Daily Job Scheduler](https://github.com/VR-25/djs) + - [Donate - Airtm, username: ivandro863auzqg](https://app.airtm.com/send-or-request/send) +- [Donate - Credit/Debit Card](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=iprj25@gmail.com&lc=US&item_name=VR25+is+creating+free+and+open+source+software.+Donate+to+suppport+their+work.&no_note=0&cn=¤cy_code=USD&bn=PP-DonationsBF:btn_donateCC_LG.gif:NonHosted) - [Donate - Liberapay](https://liberapay.com/vr25) - [Donate - Patreon](https://patreon.com/vr25) -- [Donate - PayPal or Credit/Debit Card](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=iprj25@gmail.com&lc=US&item_name=VR25+is+creating+free+and+open+source+software.+Donate+to+suppport+their+work.&no_note=0&cn=¤cy_code=USD&bn=PP-DonationsBF:btn_donateCC_LG.gif:NonHosted) +- [Donate - PayPal Me](https://paypal.me/vr25xda) + - [Facebook Page](https://fb.me/vr25xda) + - [Frontend - ACC App](https://github.com/MatteCarra/AccA/releases) - [Frontend - ACC Settings](https://github.com/CrazyBoyFeng/AccSettings) + - [Must Read - How to Prolong Lithium Ion Batteries Lifespan](https://batteryuniversity.com/article/bu-808-how-to-prolong-lithium-based-batteries) + - [Telegram Channel](https://t.me/vr25_xda) - [Telegram Group](https://t.me/acc_group) - [Telegram Profile](https://t.me/vr25xda) + - [Upstream Repository](https://github.com/VR-25/acc) + - [XDA Thread](https://forum.xda-developers.com/apps/magisk/module-magic-charging-switch-cs-v2017-9-t3668427) diff --git a/TODO.txt b/TODO.txt index e69de29..2587ad4 100644 --- a/TODO.txt +++ b/TODO.txt @@ -0,0 +1,7 @@ +notifications + resume_capacity and more +-e and -d, voltage support +profiles +reduce array usage +adaptive charging +allow any current and voltage values diff --git a/acc/batt-interface.sh b/acc/batt-interface.sh deleted file mode 100644 index 086902f..0000000 --- a/acc/batt-interface.sh +++ /dev/null @@ -1,115 +0,0 @@ -discharging() { - local af=${ampFactor:-$ampFactor_} - local curThen=$(cat $TMPDIR/.curr) - local curNow= - local maxMA=750 - local mAThreshold=100 - [ $curThen != null ] && { - [ -n "$af" ] || { - [ $curThen -lt 10000 ] && af=1000 || af=1000000 - } - af=${af#1000} - curNow=$(cat $currFile) - [ $curNow -lt $((curThen + mAThreshold$af)) ] && { - case $curThen$curNow in - [0-9]*-*) ;; - *) [ ${curNow#-} -lt $maxMA$af ];; - esac - } - } -} - - -idle() { - [ -n "$idleThreshold" ] \ - && [ $(sed s/-// $currFile) -le $idleThreshold ] -} - - -not_charging() { - - local file= - local i= - - for file in sm????_bms/status $batt/status; do - [ ! -f $file ] || break - done - - _status=$(sed 's/Not charging/Idle/' $file) - - if [ ! -f $TMPDIR/curr ] && [ ! -f $dataDir/curr ]; then - case $_status in - Charging) idle && _status=Idle || { ! discharging || _status=Discharging; };; - Discharging) ! idle || _status=Idle;; - esac - fi - - for i in Discharging DischargingDischarging Idle IdleIdle; do - [ $i != ${1-}$_status ] || return 0 - done - - return 1 -} - - -if ${init:-false}; then - - for batt in */capacity; do - if [ -f ${batt%/*}/status ]; then - batt=${batt%/*} - break - fi - done - - case $batt in - */capacity) exit 1;; - esac - - [ -f maxfg/capacity ] && battCapacity=maxfg/capacity || battCapacity=$batt/capacity - - - echo 250 > $TMPDIR/.dummy-temp - - for temp in $batt/temp $batt/batt_temp bms/temp $TMPDIR/.dummy-temp; do - [ ! -f $temp ] || break - done - - - echo 0 > $TMPDIR/.dummy-curr - - for currFile in $batt/current_now bms/current_now \ - $batt/batteryaveragecurrent $TMPDIR/.dummy-curr - do - [ ! -f $currFile ] || break - done - - curr=$(sed s/-// $currFile) - [ -d /proc/mtk_battery_cmd ] && idleThreshold=95 || idleThreshold=15 # mA - ampFactor_=1000 - - if [ $curr -le $idleThreshold ]; then - ampFactor_= - idleThreshold= - else - ! [ $curr -ge 10000 ] || { - ampFactor_=1000000 - idleThreshold=${idleThreshold}000 - } - fi - - unset curr - - echo "ampFactor_=$ampFactor_ -batt=$batt -currFile=$currFile -battCapacity=$battCapacity -idleThreshold=$idleThreshold -temp=$temp" > $TMPDIR/.batt-interface.sh - - init=false - -else - . $TMPDIR/.batt-interface.sh -fi - -[ -f $TMPDIR/.curr ] || echo null > $TMPDIR/.curr diff --git a/acc/translations/pt-PT/strings.sh b/acc/translations/pt-PT/strings.sh deleted file mode 100644 index 472e262..0000000 --- a/acc/translations/pt-PT/strings.sh +++ /dev/null @@ -1,125 +0,0 @@ -# Português, Portugal (pt-PT) - -print_already_running() { - echo "(i) accd já está em execução" -} - -print_started() { - echo "(i) accd foi iniciado" -} - -print_stopped() { - echo "(i) accd foi parado" -} - -print_not_running() { - echo "(i) accd não está em execução" -} - -print_restarted() { - echo "(i) accd foi reiniciado" -} - -print_is_running() { - echo "(i) accd $1 está em execução $2" -} - -print_config_reset() { - echo "(i) A configuração padrão foi restaurada" -} - -print_invalid_switch() { - echo "(!) Interruptor de carga inválido, [${chargingSwitch[@]-}]" -} - -print_charging_disabled_until() { - echo "(i) Recarga desativada até % <= $1" -} - -print_charging_disabled_for() { - echo "(i) Recarga desativada por $1" -} - -print_charging_disabled() { - echo "(i) Recarga desativada" -} - -print_charging_enabled_until() { - echo "(i) Recarga ativada até % >= $1" -} - -print_charging_enabled_for() { - echo "(i) Recarga ativada por $1" -} - -print_charging_enabled() { - echo "(i) Recarga ativada" -} - -print_unplugged() { - echo "(!) Conecte o carregador primeiro..." -} - -print_switch_works() { - echo "(i) [$@] funciona" -} - -print_switch_fails() { - echo "(!) [$@] não funciona" -} - -print_not_found() { - echo "(!) $1 não encontrado" -} - -#print_help() { - -print_exit() { - echo "Sair" -} - -print_choice_prompt() { - echo "(?) Introduza um número e clique [enter]: " -} - -print_auto() { - echo "Automático" -} - -print_default() { - echo "Predefinição" -} - -print_quit() { - echo "(i) Pressione $1 para sair/guardar" -} - -print_curr_restored() { - echo "(i) Máxima corrente de recarga padrão restaurada" -} - -print_volt_restored() { - echo "(i) Máxima voltagem padrão de recarga restaurada" -} - -print_read_curr() { - echo "(i) Antes the prosseguir, o acc precisa obter os padrões máximos de corrente (I) de recarga" - print_unplugged - echo -n "- À espera..." -} - -print_curr_set() { - echo "(i) Máxima corrente (I) de recarga definida para $1 miliamperes" -} - -print_volt_set() { - echo "(i) Máxima voltagem de recarga definida para $1 milivolts" -} - -print_curr_range() { - echo "(!) Apenas [$1] (miliamperes)" -} - -print_volt_range() { - echo "(!) Apenas [$1] (milivolts)" -} diff --git a/bin/acc_flashable_uninstaller.zip b/bin/acc_flashable_uninstaller.zip index a96623d6cb55f9a653d85780732e8a61db37a9e9..5e64637778e34f5ccf229ff744bd3109d9065c47 100644 GIT binary patch delta 1217 zcmaFL|CpaQz?+$civa}q{0>j#m1nc}m86+B@j7@a97B^c3mn@a3H+%oyFQ1~}UM9TY_oC^$ zpU3^YWB5yRv-e7)-AaN-COI!&vZ-&{QUeXg#w`i0r)QYC8K_(6Y~PTRa`N)EXZ8HC z`Mo+}e9ty-j-UK9$F80`-v0dgz;fl80bx219=|>Nc=vqI79%~mw@h;;mTD%rzCCsE z&>@SiMVuj5);MNP6>;KJmNYoaswg2hsm-I#Q&Kr5JY>~r_h!W-%dQc<6W^>^6BX_)u#h|nDkcc-R~!Q zMmx%5cOA!mX7;&{8g@6QFn>G{85Xsp{Vv};4u`F7oGM=hnV#l^X7X*0Pum>qyN>sX zg6OH;cYb>a$S-G^c{fUZRn9AaQ;y~02TZFN59}%GDE4`JcDC76g*zoqXV#y8_~%ad zv+!Kukl^}hj6H``I7J$d$calDcq_ly_4nT6$=RwN@=v!;W8m0!$zT`Xyx&C|^0Zg) zy5kfZq~@?|v0e|~vb)FGzP|71->u#g#rW~<`}lt@!c)Gwb-!fM(+g;L@1VfHOGcLA zu#WiJc0nl)Z^_Il>LGlLT+Avm^I1BL&YM12k>FnI5@eNFueEZ8@Xe^Cjdky`7SG%e z7V+s!U*GkVIn!sYRSYzEeY=&{O*qBE;rYVfeRI~dGelbAKP zIeP17T`g|E!$A#;vsZHcxfqZYy65OV^B=o~PVi)LCDxp7&fhfuKz_L5S)IB`HS?=@ z4`!;BCc3rvFw(z#EKDwKEZcl&txrqa#+2SUF@ZYS2-?l+qxp3FP%;C;sp4+>Tt^tAbAqqj8b z_cGoOll=X(e(gKrqFDWeW^itEADCL=2mi+&_tm>(WcUfMP?r6fHz<7q*GQ=(+(|Q<-OD-s+W9A;^3SI8}1z1G*Q(*x_EPvT5H%Jgr?-pZQ)!krh69bFvTV7y6>buHM%+7kN9EdKT`w2bUHwmzpfDnYpl)#lzy`!kWG{ z-`8X)zWt^6NA^b$E%xi-dw2IV+xh##^Q-+OwlY1sec$eXr(VYExnh?&V`3IC);HJL zyeKMR;F+m+i$l3YV4Be-jrGfAm_*n-EcWpVrN(7x1Rm_G>a3qtawsGyP<_+ZBT0X6 zTy--}T)W{(q~hE)CoS|%qn#HeT-(kwyGKu>ph3^+yPRbt=iMKHE$3E#%}_iUf8E^N z*1#kt>2Ptu>aruQsRuI)N_0PjJFg7=$anjmNQZz1Ulvzl&2i_9P4f?|4{uBrv-jNR z|CjS%q*`gB%Ue{*!iVq5=km)R6qUJkxl4FakjRu=!|=Nk z|1Y#ijF^!ZqCR<}=>G#ZbBbm#MsuZ@zJLBuy64fy|A|(TrH?PKwt2BzuH*;%%6EJD z_;zob+K@kcrGlZQjsEn5X3gtoWNj!j$@fZ(x7c{d=Fv0X%IUf@A1#w}xaD5&I#;+y z$~ib@)s}UeW7;xU!f$BQSw*Y-7L0N7-#GXB^`Bd3?vc#?!1Rx=iM2hN*YVND>4lnC zZ<*&dOs^>ly7=AH?s+!9U((k3TSWHyHHS8N&pO*wy^_28ZsCT7)*;b{}-!m+gIVVwRUidVHYk?}S}m zf9o>M9=e6^5{k@^%6jYcG05||{lg`9XBmHz5AbGWl4FLK9Fym>>N10hjq|KB;7tFH z)ewd6$Yz1UpUvg~Q52FvedS74jO3M#Vz DImHkk diff --git a/build.sh b/build.sh index e9aecdb..3211bae 100644 --- a/build.sh +++ b/build.sh @@ -55,7 +55,7 @@ EOF # set ID -for file in ./install*.sh ./$id/*.sh ./bundle.sh; do +for file in ./install*.sh ./install/*.sh ./bundle.sh; do if [ -f "$file" ] && grep -Eq '(^|\()id=' $file; then grep -Eq "(^|\()id=$id" $file || set_prop id $id $file fi @@ -63,7 +63,7 @@ done # set domain -for file in ./install*.sh ./$id/*.sh ./bundle.sh; do +for file in ./install*.sh ./install/*.sh ./bundle.sh; do if [ -f "$file" ] && grep -Eq '(^|\()domain=' $file; then grep -Eq "(^|\()domain=$domain" $file || set_prop domain $domain $file fi @@ -72,28 +72,28 @@ done # update README -if [ README.md -ot $id/default-config.txt ] \ - || [ README.md -ot $id/strings.sh ] +if [ README.md -ot install/default-config.txt ] \ + || [ README.md -ot install/strings.sh ] then # default config set -e - { sed -n '1,/#DC#/p' README.md; echo; cat $id/default-config.txt; \ + { sed -n '1,/#DC#/p' README.md; echo; cat install/default-config.txt; \ echo; sed -n '/^#\/DC#/,$p' README.md; } > README.md.tmp # terminal commands { sed -n '1,/#TC#/p' README.md.tmp; \ - echo; . ./$id/strings.sh; print_help; \ + echo; . ./install/strings.sh; print_help; \ echo; sed -n '/^#\/TC#/,$p' README.md.tmp; } > README.md rm README.md.tmp set +e fi -# update busybox config (from $id/setup-busybox.sh) in $id/uninstall.sh and install scripts +# update busybox config (from install/setup-busybox.sh) in install/uninstall.sh and install scripts set -e -for file in ./$id/uninstall.sh ./install*.sh; do - [ $file -ot $id/setup-busybox.sh ] && { +for file in ./install/uninstall.sh ./install*.sh; do + [ $file -ot install/setup-busybox.sh ] && { { sed -n '1,/#BB#/p' $file; \ - grep -Ev '^$|^#' $id/setup-busybox.sh; \ + grep -Ev '^$|^#' install/setup-busybox.sh; \ sed -n '/^#\/BB#/,$p' $file; } > ${file}.tmp mv -f ${file}.tmp $file } @@ -106,12 +106,12 @@ set +e cp -u install.sh META-INF/com/google/android/update-binary; } 2>/dev/null -if [ bin/${id}_flashable_uninstaller.zip -ot $id/uninstall.sh ] || [ ! -f bin/${id}_flashable_uninstaller.zip ]; then +if [ bin/${id}_flashable_uninstaller.zip -ot install/uninstall.sh ] || [ ! -f bin/${id}_flashable_uninstaller.zip ]; then # generate $id uninstaller flashable zip echo "=> bin/${id}_flashable_uninstaller.zip" rm -rf bin/${id}_flashable_uninstaller.zip $tmpDir 2>/dev/null mkdir -p bin $tmpDir - cp $id/uninstall.sh $tmpDir/update-binary + cp install/uninstall.sh $tmpDir/update-binary echo "#MAGISK" > $tmpDir/updater-script (cd .tmp zip -r9 ../bin/${id}_flashable_uninstaller.zip * \ @@ -130,15 +130,19 @@ fi cp bin/${id}_flashable_uninstaller.zip _builds/${basename}/ # generate $id flashable zip - echo "=> _builds/${basename}/${basename}.zip" - zip -r9 _builds/${basename}/${basename}.zip \ + case $version in + *-dev) basename_=${basename}_$(date +%H%M);; + *) basename_=$basename;; + esac + echo "=> _builds/${basename}/${basename_}.zip" + zip -r9 _builds/${basename}/${basename_}.zip \ * .gitattributes .gitignore .github \ -x _\*/\* | sed 's|.*adding: ||' | grep -iv 'zip warning:' echo # prepare files to be included in $id installable tarball cp install-tarball.sh _builds/${basename}/ - cp -R ${id}/ install.sh License.md README.* module.prop bin/ \ + cp -R install install.sh License.md README.* module.prop bin/ \ _builds/${basename}/${basename}/ 2>&1 \ | grep -iv "can't preserve" diff --git a/bundle.bat b/bundle.bat deleted file mode 100644 index 94fbfb8..0000000 --- a/bundle.bat +++ /dev/null @@ -1,2 +0,0 @@ -bash bundle.sh -PAUSE diff --git a/bundle.sh b/bundle.sh deleted file mode 100644 index 26f891c..0000000 --- a/bundle.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env sh -# $id Bundler for Front-end Apps -# Copyright 2019-2020, VR25 -# License: GPLv3+ - - -(id=acc -installerName=install -tarballName=${id}_bundle -destination=/home/*/git/AccA/app/src/main/res/raw - -cd ${0%/*} 2>/dev/null -version=$(sed -n "s/^version=//p" module.prop) -versionCode=$(sed -n "s/^versionCode=//p" module.prop) - -cp -u install-tarball.sh $destination/$installerName -cp -u _builds/${id}_${version}_\(${versionCode}\).tar.gz $destination/$tarballName) - -echo diff --git a/changelog.md b/changelog.md index 02de0e0..548df90 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,30 @@ +**v2022.6.4 (202206040)** +- `-n|--notif [[string] [user]]`: post Android notification; may not work on all systems; +- `-t|--test [p|parse]`: parse potential charging switches from power supply log (as `acc -p`), test them all, and add the working ones to the list of known switches; implies `-x`; +- `acc -p`: exclude all known switches and additional troublesome ctrl files; +- `acc -s`: Enforce valid pause_capacity and resume_capacity difference; +- `acc -t`: show more useful information; source read-ch-curr-ctrl-files-p2.sh; +- `accd`: if possible, avoid idle mode when capacity > pause_capacity; +- Additional charging switches; +- Blacklisted usb/vbus_disable; +- Fixed `accd /path/to/config --init`; +- Fixed `runCmdOnPause` and `loopCmd` parsing issues; +- Fixed: "after a reboot, accd doesn't control charging, until the keyguard is unlocked"; +- General refactor; +- Hard reset wipes config and control file blacklists (`acc -sr a` or acc --set --reset a); +- Improved advanced battery status detection; +- Misc fixes & optimizations; +- New config variables: `batt_status_override=Idle|Discharging|'custom'`, `batt_status_workaround=true`, `reboot_resume=false`, `reset_batt_stats_on_plug=false`, `schedule='HHMM command...'` (refer to the config or readme files for details); +- One-line scripts; +- Parse config `ampFactor` from `batt-interface.sh` as well; +- Post exit code notification if accd stops due to an error; +- Removed obsolete source code files; +- Run dexopt-job only once per boot session (if battery is charging, and system has been up for at least 15 minutes); +- Save acc -t output to /sdcard/Download/acc-t_output.txt; +- Tuning variables for not_charging() timeout (seqCount) and voltage-based idle mode (voltOff); +- Updated documentation; +- Updates can be downloaded with busybox's wget as well (may not work on all systems). Try upgrading with `acc -u`. + **v2022.2.22.1 (202202221)** - acc -ss and -t show more info/hints; - Fixed `acc: inaccessible or not found` following acc -t execution; @@ -17,18 +44,3 @@ - Updated naming conventions for release files; - updateJSON API for front-ends (details in the readme); - Use idleThreshold=95 (mA) for mtk devices and 15 for the rest. - -**v2022.2.3 (202202030)** -- Additional charging switches; -- Auto detect and blacklist unwritable charging control files and those that trigger unexpected reboots; -- Blacklisted troublesome charging switches; -- Fixed bg-dexopt-job wrapper causing long accd stop delay; -- Fixed typos in README.md; -- Fixed voltage "millivolts --exit" error; -- Improved charging status logic; -- Magisk updateJson support; -- Misc fixes & optimizations; -- Moved changelog from README.md to changelog.md; -- Removed README.html; -- Support for a new charging switch format: `ctrl_file1 ctrl_file2 ...`, `file` is where to get the on/off value from, e.g., `battery/charge_control_limit 0 battery/charge_control_limit_max`; -- Updated unexpected reboot troubleshooting guide. diff --git a/customize.sh b/customize.sh index 1b365e1..5df3fd4 100644 --- a/customize.sh +++ b/customize.sh @@ -37,7 +37,7 @@ trap exxit EXIT # set up busybox #BB# -bin_dir=/data/adb/bin +bin_dir=/data/adb/vr25/bin busybox_dir=/dev/.vr25/busybox magisk_busybox=/data/adb/magisk/busybox [ -x $busybox_dir/ls ] || { @@ -51,7 +51,7 @@ magisk_busybox=/data/adb/magisk/busybox } done [ -x $busybox_dir/ls ] || { - echo "(!) Install busybox or simply place it in $bin_dir/" + echo "Install busybox or simply place it in $bin_dir/" echo exit 3 } @@ -66,7 +66,7 @@ unset f bin_dir busybox_dir magisk_busybox # root check [ $(id -u) -ne 0 ] && { - echo "(!) $0 must run as root (su)" + echo "$0 must run as root (su)" exit 4 } @@ -97,7 +97,7 @@ set -eu srcDir="$(cd "${0%/*}" 2>/dev/null || :; echo "$PWD")" # extract flashable zip if source code is unavailable -[ -d $srcDir/$id ] || { +[ -d $srcDir/install ] || { srcDir=/dev/.$domain.${id}-install rm -rf $srcDir 2>/dev/null || : mkdir $srcDir @@ -153,7 +153,7 @@ echo "$name $version ($versionCode) Copyright 2017-2022, $author GPLv3+ -(i) Installing in $installDir/$id/..." +Installing in $installDir/$id/..." # backup @@ -162,8 +162,8 @@ mkdir -p $data_dir/backup cp -aH /data/adb/$domain/$id/* $config $data_dir/backup/ 2>/dev/null || : -/system/bin/sh $srcDir/$id/uninstall.sh install -cp -R $srcDir/$id/ $installDir/ +/system/bin/sh $srcDir/install/uninstall.sh install +cp -R $srcDir/install/ $installDir/$id installDir=$(readlink -f $installDir/$id) cp $srcDir/module.prop $installDir/ cp -f $srcDir/README.* $data_dir/ @@ -267,7 +267,7 @@ cat $srcDir/changelog.md printf "\n\n" -echo "(i) Rebooting is unnecessary +echo "Rebooting is unnecessary. - $id commands may require the "/dev/.$domain/$id/" prefix (e.g., /dev/.$domain/$id/$id -v) until system is rebooted. - Daemon started." @@ -275,13 +275,13 @@ echo "(i) Rebooting is unnecessary case $installDir in /data/adb/modules*) ;; *) echo " -(i) Non-Magisk users can enable $id auto-start by running /data/adb/$domain/$id/service.sh, a copy of, or a link to it - with init.d or an app that emulates it.";; +Non-Magisk users can enable $id auto-start by running /data/adb/$domain/$id/service.sh, a copy of, or a link to it - with init.d or an app that emulates it.";; esac #legacy f=$data_dir/logs/ps-blacklist.log [ -f $f ] || mv $data_dir/logs/psl-blacklist.txt $f 2>/dev/null -rm $data_dir/${id}-uninstaller.zip 2>/dev/null +rm $data_dir/${id}-uninstaller.zip $data_dir/logs/*.tar.gz $data_dir/curr 2>/dev/null # initialize $id /data/adb/$domain/$id/service.sh --init diff --git a/framework-details.txt b/framework-details.txt deleted file mode 100644 index 111285b..0000000 --- a/framework-details.txt +++ /dev/null @@ -1,70 +0,0 @@ -This file describes the framework ACC and similar projects of mine are built upon. -It's assumed that you are already a flashable zip and/or Magisk module creator. - - -Generic Project Structure - -_builds/ (local only dir) - $id-$versionCode/ - $id_$version_($versionCode).tar.gz (for front-end apps) - $id_$version_($versionCode).zip (flashable) - $id-uninstaller.zip (flashable, copy of bin/$id-uninstaller.zip) - install-tarball.sh (copied from $id/) - -_misc/ (local only dir, for drafts and random stuff) - random_dir/ - random_file - - $id/ (files to be installed) - translations/ - aquire-lock.sh (for job control, uses flock) - default-config.txt - flash-zips.sh (universal shell-based-zip flasher) - release-lock.sh - select.sh ("select" for shells that lack it) - service.sh (boot/initialization script) - setup-busybox.sh - strings.sh (core language strings) - uninstall.sh - -bin/ - $id-uninstaller.zip (generated by build.sh; update-binary is a copy of $id/uninstall.sh) - -META-INF/com/google/android/ - update-binary (copy of install.sh) - updater-script (dummy file) - -.gitattributes -.gitignore -build.bat -build.sh -bundle.bat -bundle.sh (copies tarball and install-tarball.sh to front-end-src-code/app/src/main/res/raw/) -check-syntax.bat -check-syntax.sh -customize.sh (copy of install.sh, for compatibility with Magisk) -framework-details.txt (this file) -install.sh (main installer) -install-online.sh (upgrader, online installer) -install-tarball.sh (mainly used by a front-end app) -License.md (GPLv3) -module.prop -README.md (documentation) -TODO.txt (draft for features, issues, thoughts...) - - -Tasks Carried Out By build.sh - -1. Check shell syntax in all scripts. - -2. Update version and versionCode in module.prop (values come from README.md > LATEST CHANGES). - -3. Set the correct id and domain (from module.prop) in install*.sh, $id/*.sh and bundle.sh. - -4. Patch README.md. - -5. Update busybox config (from $id/setup-busybox.sh) in $id/uninstall.sh and install scripts. - -6. Unify installers for flashable zip (customize.sh and update-binary are copies of install.sh). - -7. Generate flashable zips (main & uninstaller) - and tarball for front-ends. diff --git a/install-online.sh b/install-online.sh index 7fb2ebe..c46e412 100644 --- a/install-online.sh +++ b/install-online.sh @@ -26,7 +26,7 @@ trap 'e=$?; echo; exit $e' EXIT # set up busybox #BB# -bin_dir=/data/adb/bin +bin_dir=/data/adb/vr25/bin busybox_dir=/dev/.vr25/busybox magisk_busybox=/data/adb/magisk/busybox [ -x $busybox_dir/ls ] || { @@ -40,7 +40,7 @@ magisk_busybox=/data/adb/magisk/busybox } done [ -x $busybox_dir/ls ] || { - echo "(!) Install busybox or simply place it in $bin_dir/" + echo "Install busybox or simply place it in $bin_dir/" echo exit 3 } @@ -55,7 +55,7 @@ unset f bin_dir busybox_dir magisk_busybox # root check [ $(id -u) -ne 0 ] && { - echo "(!) $0 must run as root (su)" + echo "$0 must run as root (su)" exit 4 } @@ -70,6 +70,14 @@ get_ver() { sed -n 's/^versionCode=//p' ${1:-}; } } +which curl >/dev/null || { + curl() { + shift $(($# - 1)) + PATH=${PATH#*/busybox:} /dev/.vr25/busybox/wget -O - --no-check-certificate $1 + } +} + + case "$@" in *--insecure*|*-k*) insecure=--insecure;; *) insecure=;; @@ -102,7 +110,7 @@ then else echo print_available $id $onlineVersion 2>/dev/null \ - || echo "(i) $id $onlineVersion is available" + || echo "$id $onlineVersion is available" echo "- https://github.com/VR-25/$id/blob/${commit}/README.md#latest-changes" print_install_prompt 2>/dev/null \ || echo -n "- Should I download and install it ([enter]: yes, CTRL-C: no)? " @@ -121,7 +129,7 @@ then else echo - print_no_update 2>/dev/null || echo "(i) No update available" + print_no_update 2>/dev/null || echo "No update available" exit 6 fi diff --git a/install-tarball.sh b/install-tarball.sh index 9430d1b..cc38c17 100644 --- a/install-tarball.sh +++ b/install-tarball.sh @@ -20,7 +20,7 @@ set -x # set up busybox #BB# -bin_dir=/data/adb/bin +bin_dir=/data/adb/vr25/bin busybox_dir=/dev/.vr25/busybox magisk_busybox=/data/adb/magisk/busybox [ -x $busybox_dir/ls ] || { @@ -34,7 +34,7 @@ magisk_busybox=/data/adb/magisk/busybox } done [ -x $busybox_dir/ls ] || { - echo "(!) Install busybox or simply place it in $bin_dir/" + echo "Install busybox or simply place it in $bin_dir/" echo exit 3 } @@ -48,7 +48,7 @@ unset f bin_dir busybox_dir magisk_busybox # root check [ $(id -u) -ne 0 ] && { - echo "(!) $0 must run as root (su)" + echo "$0 must run as root (su)" exit 4 } diff --git a/install.sh b/install.sh index 1b365e1..5df3fd4 100644 --- a/install.sh +++ b/install.sh @@ -37,7 +37,7 @@ trap exxit EXIT # set up busybox #BB# -bin_dir=/data/adb/bin +bin_dir=/data/adb/vr25/bin busybox_dir=/dev/.vr25/busybox magisk_busybox=/data/adb/magisk/busybox [ -x $busybox_dir/ls ] || { @@ -51,7 +51,7 @@ magisk_busybox=/data/adb/magisk/busybox } done [ -x $busybox_dir/ls ] || { - echo "(!) Install busybox or simply place it in $bin_dir/" + echo "Install busybox or simply place it in $bin_dir/" echo exit 3 } @@ -66,7 +66,7 @@ unset f bin_dir busybox_dir magisk_busybox # root check [ $(id -u) -ne 0 ] && { - echo "(!) $0 must run as root (su)" + echo "$0 must run as root (su)" exit 4 } @@ -97,7 +97,7 @@ set -eu srcDir="$(cd "${0%/*}" 2>/dev/null || :; echo "$PWD")" # extract flashable zip if source code is unavailable -[ -d $srcDir/$id ] || { +[ -d $srcDir/install ] || { srcDir=/dev/.$domain.${id}-install rm -rf $srcDir 2>/dev/null || : mkdir $srcDir @@ -153,7 +153,7 @@ echo "$name $version ($versionCode) Copyright 2017-2022, $author GPLv3+ -(i) Installing in $installDir/$id/..." +Installing in $installDir/$id/..." # backup @@ -162,8 +162,8 @@ mkdir -p $data_dir/backup cp -aH /data/adb/$domain/$id/* $config $data_dir/backup/ 2>/dev/null || : -/system/bin/sh $srcDir/$id/uninstall.sh install -cp -R $srcDir/$id/ $installDir/ +/system/bin/sh $srcDir/install/uninstall.sh install +cp -R $srcDir/install/ $installDir/$id installDir=$(readlink -f $installDir/$id) cp $srcDir/module.prop $installDir/ cp -f $srcDir/README.* $data_dir/ @@ -267,7 +267,7 @@ cat $srcDir/changelog.md printf "\n\n" -echo "(i) Rebooting is unnecessary +echo "Rebooting is unnecessary. - $id commands may require the "/dev/.$domain/$id/" prefix (e.g., /dev/.$domain/$id/$id -v) until system is rebooted. - Daemon started." @@ -275,13 +275,13 @@ echo "(i) Rebooting is unnecessary case $installDir in /data/adb/modules*) ;; *) echo " -(i) Non-Magisk users can enable $id auto-start by running /data/adb/$domain/$id/service.sh, a copy of, or a link to it - with init.d or an app that emulates it.";; +Non-Magisk users can enable $id auto-start by running /data/adb/$domain/$id/service.sh, a copy of, or a link to it - with init.d or an app that emulates it.";; esac #legacy f=$data_dir/logs/ps-blacklist.log [ -f $f ] || mv $data_dir/logs/psl-blacklist.txt $f 2>/dev/null -rm $data_dir/${id}-uninstaller.zip 2>/dev/null +rm $data_dir/${id}-uninstaller.zip $data_dir/logs/*.tar.gz $data_dir/curr 2>/dev/null # initialize $id /data/adb/$domain/$id/service.sh --init diff --git a/acc/acc.sh b/install/acc.sh similarity index 77% rename from acc/acc.sh rename to install/acc.sh index f5d3755..cdfac45 100644 --- a/acc/acc.sh +++ b/install/acc.sh @@ -108,7 +108,7 @@ edit() { if which nano > /dev/null; then print_quit CTRL-X else - print_quit "[esc] :q [enter]" "[esc] :wq [enter]" + print_quit "[esc] :q! [enter]" "[esc] :wq [enter]" fi ;; *.log|*.md|*.help) @@ -119,8 +119,8 @@ edit() { echo } case $file in - *.txt) nano -$ $file || vim $file || vi $file;; *.log|*.md|*.help) less $file;; + *) nano -$ $file || vim $file || vi $file;; esac 2>/dev/null fi } @@ -131,31 +131,31 @@ get_prop() { sed -n "s|^$1=||p" ${2:-$config}; } test_charging_switch() { - local battIdleMode=false + local idleMode=false local failed=false chargingSwitch=($@) - flip_sw off && sleep_sd not_charging + echo + echo "${chargingSwitch[@]}" + flip_sw off $blacklisted && { - print_blacklisted "$@" + print_blacklisted return 10 } ! not_charging && failed=true || { - [ $_status = Idle ] \ - && battIdleMode=true \ - || { [ ${chargingSwitch[2]:-.} = voltage_now ] && battIdleMode=true; } + [ $_status = Idle ] && idleMode=true } flip_sw on 2>/dev/null - if ! $failed && sleep_sd "! not_charging"; then - print_switch_works "$@" - echo "- battIdleMode=$battIdleMode" - $battIdleMode && return 15 || return 0 + if ! $failed && ! not_charging; then + print_switch_works + echo " idleMode=$idleMode" + $idleMode && return 15 || return 0 else - print_switch_fails "$@" + print_switch_fails return 10 fi } @@ -193,7 +193,7 @@ parse_switches() { n=$i i="$(sed -n "$(($n - 1))p" "$f")" - n=$(sed -n ${n}p $f) + n=$(sed -n ${n}p $f | sed 's/^ //') case $n in 0) n="$n 1";; @@ -209,9 +209,10 @@ parse_switches() { *) continue;; esac + # exclude all known switches ! grep -q "$i " $1 || continue - i="$(echo "$i $n" | grep -Eiv 'brightness|curr|online|present|runtime|status|temp|volt|wakeup|[^pP]reset' \ + i="$(echo "$i $n" | grep -Eiv 'brightness|curr|online|present|runtime|status|temp|volt|wakeup|[^pP]reset|daemon|calibrat|init|resistance|capacitance|shutdown|parallel|cycle|shutdown|reboot|nvram|count' \ | sed 's|^/.*/power_supply/||')" [ -z "$i" ] || echo "$i" @@ -244,9 +245,9 @@ defaultConfig=$execDir/default-config.txt . $execDir/logf.sh . $execDir/misc-functions.sh -if [ "${1:-y}" = -x ]; then - log=/sdcard/acc-${device}.log - shift +if [ "${1:-y}" = -x ] || tt "${2-}" "p|parse"; then + log=/sdcard/Download/acc-${device}.log + [ $1 != -x ] || shift else log=$TMPDIR/acc-${device}.log fi @@ -274,7 +275,7 @@ misc_stuff "${1-}" # reset broken/obsolete config (set +x; . $config) > /dev/null 2>&1 \ - || cat -f $execDir/default-config.txt > $config + || cat $execDir/default-config.txt > $config . $config @@ -283,6 +284,7 @@ misc_stuff "${1-}" . $execDir/strings.sh # load translations +: ${language:=en} if ${verbose:-true} && [ -f $execDir/translations/$language/strings.sh ]; then . $execDir/translations/$language/strings.sh fi @@ -311,12 +313,8 @@ case "${1-}" in ;; [0-9]*) - if [ $1 -gt 3000 ]; then - capacity[2]=${2:-$((${1}-50))} - else - capacity[2]=${2:-$((${1}-5))} - fi - capacity[3]=$1 + pause_capacity=$1 + resume_capacity=${2:-5000} . $execDir/write-config.sh ;; @@ -402,6 +400,11 @@ case "${1-}" in logf "$@" ;; + -n|--notif) + shift + notif "${@-}" + ;; + -p|--parse) shift parse_switches "$@" @@ -433,7 +436,7 @@ case "${1-}" in ;; -sr) - set_prop_ --reset + set_prop_ --reset "$@" ;; -ss) @@ -459,8 +462,10 @@ case "${1-}" in -t|--test) shift + parsed= exitCode_=10 - exitCode=10 + exitCode=$exitCode_ + print_wait print_unplugged ! daemon_ctrl stop > /dev/null && daemonWasUp=false || { @@ -477,7 +482,15 @@ case "${1-}" in config=$TMPDIR/.config set +e - trap '! $daemonWasUp || start-stop-daemon -bx $TMPDIR/.accdt -S --; exit $exitCode' EXIT + exxit() { + [ -z "$parsed" ] || { + cat $TMPDIR/ch-switches $_parsed 2>/dev/null > $parsed \ + && sort -u $parsed | sed 's/ $//; /^$/d' > $TMPDIR/ch-switches + } + ! $daemonWasUp || start-stop-daemon -bx $TMPDIR/.accdt -S -- + exit $exitCode + } + trap exxit EXIT not_charging && enable_charging > /dev/null @@ -489,17 +502,41 @@ case "${1-}" in done) } - print_wait - [ "${1-}" != -- ] || shift #legacy - - case "${2-}" in - "") + [ "${1-}" != -- ] || shift #legacy, AccA + . $execDir/read-ch-curr-ctrl-files-p2.sh + : > /sdcard/Download/acc-t_output.txt + + case "${1-}" in + ""|p|parse) + ! tt "${1-}" "p|parse" || parsed=$TMPDIR/.parsed + [ -z "$parsed" ] || { + _parsed=$dataDir/logs/parsed.log + if parse_switches > $parsed; then + set -- $parsed + ! ${verbose:-true} || { + print_panic + read -n 1 a + echo + case "$a" in + ""|y) edit $parsed;; + a) exit;; + esac + } + else + echo + exit + fi + } while read _chargingSwitch; do echo "x$_chargingSwitch" | grep -Eq '^x$|^x#' && continue [ -f "$(echo "$_chargingSwitch" | cut -d ' ' -f 1)" ] && { - echo - test_charging_switch $_chargingSwitch - exitCode_=$? + { test_charging_switch $_chargingSwitch; echo $? > $TMPDIR/.exitCode; } \ + | tee -a /sdcard/Download/acc-t_output.txt + exitCode_=$(cat $TMPDIR/.exitCode) + if [ -n "$parsed" ] && [ $exitCode_ -ne 10 ]; then + grep -q "^$_chargingSwitch$" $_parsed 2>/dev/null \ + || echo "$_chargingSwitch" >> $_parsed + fi case $exitCode in 15) ;; 0) [ $exitCode_ -eq 15 ] && exitCode=15;; @@ -510,22 +547,22 @@ case "${1-}" in echo ;; *) - echo - test_charging_switch "$@" - exitCode=$? + { test_charging_switch "$@"; echo $? > $TMPDIR/.exitCode; } \ + | tee -a /sdcard/Download/acc-t_output.txt + exitCode=$(cat $TMPDIR/.exitCode) echo ;; esac - print_acct_info $(tt $exitCode "0|15" && echo y) + print_acct_info exit $exitCode ;; - -T|--logtail|-L) #legacy + -T|--logtail|-L) #legacy, AccA if ${verbose:-true} && [ $1 != -L ]; then print_quit CTRL-C - sleep 1.5 + sleep 1 fi tail -F $TMPDIR/accd-*.log ;; @@ -567,7 +604,12 @@ case "${1-}" in || chmod -R 0700 /data/adb/vr25/bin } - curl $insecure -Lo $TMPDIR/install-online.sh https://raw.githubusercontent.com/VR-25/acc/$reference/install-online.sh + if which curl >/dev/null; then + curl $insecure -Lo $TMPDIR/install-online.sh https://raw.githubusercontent.com/VR-25/acc/$reference/install-online.sh + else + PATH=${PATH#*/busybox:} /dev/.vr25/busybox/wget -O $TMPDIR/install-online.sh --no-check-certificate \ + https://raw.githubusercontent.com/VR-25/acc/$reference/install-online.sh + fi trap - EXIT set +eu installDir=$(readlink -f $execDir) @@ -590,7 +632,7 @@ case "${1-}" in : ${sleepSeconds:=3} . $execDir/batt-info.sh ! ${verbose:-true} || print_quit CTRL-C - sleep 1.5 + sleep 1 while :; do clear batt_info "${2-}" diff --git a/acc/acca.sh b/install/acca.sh similarity index 85% rename from acc/acca.sh rename to install/acca.sh index d284d08..e622797 100644 --- a/acc/acca.sh +++ b/install/acca.sh @@ -20,6 +20,20 @@ daemon_ctrl() { } +src_cfg() { + . $config || cat $execDir/default-config.txt > $config +} + + +# extended test +tt() { + eval "case \"$1\" in + $2) return 0;; + esac" + return 1 +} + + set -eu execDir=/data/adb/vr25/acc @@ -55,7 +69,7 @@ case "$@" in # print battery uevent data -i*|--info*) - . $config + src_cfg . $execDir/batt-interface.sh . $execDir/batt-info.sh batt_info "${2-}" @@ -77,7 +91,7 @@ case "$@" in shift . $defaultConfig - . $config + src_cfg export "$@" @@ -100,15 +114,15 @@ case "$@" in -s\ d*|-s\ --print-default*|--set\ d*|--set\ --print-default*|-sd*) [ $1 = -sd ] && shift || shift 2 . $defaultConfig - . $execDir/print-config.sh | grep -E "${1:-...}" || : + . $execDir/print-config.sh | grep -E "${1:-.}" | sed 's/^$//' || : exit 0 ;; # print current config -s\ p*|-s\ --print|-s\ --print\ *|--set\ p|--set\ --print|--set\ --print\ *|-sp*) [ $1 = -sp ] && shift || shift 2 - . $config - . $execDir/print-config.sh | grep -E "${1:-...}" || : + src_cfg + . $execDir/print-config.sh | grep -E "${1:-.}" | sed 's/^$//' || : exit 0 ;; diff --git a/acc/accd.sh b/install/accd.sh similarity index 80% rename from acc/accd.sh rename to install/accd.sh index 8d459d2..0108498 100644 --- a/acc/accd.sh +++ b/install/accd.sh @@ -9,20 +9,16 @@ init=false -case "$1" in - -i|--init) init=true; shift;; +case "$*" in + *-i*) init=true;; *) [ -f $TMPDIR/.config-ver ] || init=true;; esac -# wait until data is decrypted and system is ready +# wait until Android has fully booted -until [ -d /sdcard/Android ]; do - sleep 30 -done - -until [ .$(getprop sys.boot_completed) = .1 ]; do - sleep 30 +until [ .$(getprop sys.boot_completed 2>/dev/null) = .1 ]; do + sleep 15 done @@ -99,6 +95,7 @@ if ! $init; then if tt "$exitCode" "[127]"; then . $execDir/logf.sh logf --export + notif "⚠️ Daemon stopped with exit code $exitCode!" fi cd / echo versionCode=$versionCode @@ -112,21 +109,32 @@ if ! $init; then local value= local isCharging=false - . $config + src_cfg not_charging || isCharging=true # dynamically toggle capacitySync if ${capacity[4]} || ${capacity[5]}; then capacitySync=true - else + elif $capacitySync; then cmd_batt reset capacitySync=false fi - # run custom code - (set +eux - eval "${loopCmd[@]-}" - eval "${loopCmd_-}") || : + # schedules and custom loops + (set +eu + + schedTime=$(date +%H%M) + schedScript=$TMPDIR/.${schedTime}_schedScript.sh + if [ ! -f $schedScript ] && echo "${schedules-}" | grep "$schedTime " >/dev/null; then + echo "${schedules-}" | sed -n "s|^$schedTime |#!/system/bin/sh\n|p" > $schedScript + echo "sleep 60; rm $schedScript; exit" >> $schedScript + chmod +x $schedScript + start-stop-daemon -bx $schedScript -S -- + fi + + sed +x + eval '${loopCmd-}' + eval '${loopCmd_-}') || : # shutdown if battery temp >= shutdown_temp [ $(cat $temp) -lt $(( ${temperature[3]} * 10 )) ] || shutdown @@ -138,7 +146,11 @@ if ! $init; then && chgStatusCode=$(dumpsys battery 2>/dev/null | sed -n 's/^ status: //p') then setup_capacity_sync - start-stop-daemon -bx $TMPDIR/.bg-dexopt-job.sh -S -- 2>/dev/null || : + if [ ! -f $TMPDIR/.dexopt.done ] && _uptime 900; then + start-stop-daemon -bx $TMPDIR/.bg-dexopt-job.sh -S -- 2>/dev/null || : + touch $TMPDIR/.dexopt.done + fi + fi # read charging current ctrl files (part 2) once @@ -151,7 +163,18 @@ if ! $init; then fi } - $cooldown || resetBattStatsOnUnplug=true + $cooldown || { + resetBattStatsOnUnplug=true + if $resetBattStatsOnPlug && ${resetBattStats[2]}; then + sleep ${loopDelay[0]} + not_charging || { + dumpsys batterystats --reset < /dev/null > /dev/null 2>&1 || : + rm /data/system/batterystats* || : + resetBattStatsOnPlug=false + } 2>/dev/null + fi + } + ${chargingDisabled:-false} || apply_on_plug [ -z "${chargingDisabled-}" ] || enable_charging @@ -159,6 +182,17 @@ if ! $init; then else + $rebootResume \ + && ${chargingDisabled:-false} \ + && le_resume_cap \ + && [ $(cat $temp) -lt $(( ${temperature[1]} * 10 )) ] && { + notif "⚠️ System will reboot in 60 seconds to re-enable charging! Stop accd to abort." + sleep 60 + ! not_charging || { + /system/bin/reboot || reboot + } + } || : + [ -z "${chargingDisabled-}" ] || chargingDisabled=false # set dischgStatusCode and capacitySync @@ -168,9 +202,8 @@ if ! $init; then setup_capacity_sync fi - if ! $cooldown; then - - # resetBattStatsOnUnplug + $cooldown || { + resetBattStatsOnPlug=true if $resetBattStatsOnUnplug && ${resetBattStats[1]}; then sleep ${loopDelay[1]} ! not_charging Discharging || { @@ -179,7 +212,7 @@ if ! $init; then resetBattStatsOnUnplug=false } 2>/dev/null fi - fi + } fi sync_capacity @@ -199,11 +232,24 @@ if ! $init; then if is_charging; then + # disable charging after a reboot, if min < capacity < max + if [ -z "${minCapMax-}" ] && _lt_pause_cap && _gt_resume_cap; then + disable_charging + minCapMax=done + fi + # disable charging under test $(cat $temp) -ge $(( ${temperature[1]} * 10 )) \ && maxTempPause=true || maxTempPause=false if $maxTempPause || _ge_pause_cap; then - disable_charging + if [ $(cat $battCapacity) -gt ${capacity[3]} ]; then + # if possible, avoid idle mode when capacity > pause_capacity + (cat $config > $TMPDIR/.cfg + config=$TMPDIR/.cfg + cycle_switches off Discharging) + else + disable_charging + fi ! ${resetBattStats[0]} || { # reset battery stats on pause dumpsys batterystats --reset < /dev/null > /dev/null 2>&1 || : @@ -277,17 +323,17 @@ if ! $init; then fi # auto-shutdown - if ! $maxTempPause && [ $(cut -d '.' -f 1 /proc/uptime) -ge 900 ] && not_charging Discharging; then + if ! $maxTempPause && _uptime 900 && not_charging Discharging; then if [ ${capacity[0]} -ge 1 ]; then # warnings ! $shutdownWarnings || { if t ${capacity[0]} -gt 3000; then ! t $(grep -o '^..' $voltage_now) -eq $(( ${capacity[0]%??} + 1 )) \ - || ! notif "WARNING: ~100mV to auto shutdown, plug the charger!" \ + || ! notif "⚠️ WARNING: ~100mV to auto shutdown, plug the charger!" \ || sleep ${loopDelay[1]} else ! t $(cat $battCapacity) -eq $(( ${capacity[0]} + 5 )) \ - || ! notif "WARNING: 5% to auto shutdown, plug the charger!" \ + || ! notif "⚠️ WARNING: 5% to auto shutdown, plug the charger!" \ || sleep ${loopDelay[1]} fi shutdownWarnings=false @@ -322,8 +368,8 @@ if ! $init; then shutdown() { /system/bin/am start -n android/com.android.internal.app.ShutdownActivity < /dev/null > /dev/null 2>&1 \ - || reboot -p 2>/dev/null \ - || /system/bin/reboot -p || : + || /system/bin/reboot -p \ + || reboot -p || : } @@ -339,8 +385,8 @@ if ! $init; then if [ ${capacity[3]} -gt 3000 ]; then local maskedCap=$battCap else - local capFactor=$(calc 100 / ${capacity[3]} | tr , .) - local maskedCap=$(calc $battCap \* $capFactor | tr , . | xargs printf %.f) + local capFactor=$(calc 100 / ${capacity[3]}) + local maskedCap=$(calc $battCap \* $capFactor | xargs printf %.f) [ $maskedCap -le 100 ] || maskedCap=100 fi } @@ -368,6 +414,11 @@ if ! $init; then } + _uptime() { + [ $(cut -d '.' -f 1 /proc/uptime) -ge $1 ] + } + + # load generic functions . $execDir/misc-functions.sh @@ -380,12 +431,13 @@ if ! $init; then dischgStatusCode="" maxTempPause=false shutdownWarnings=true + resetBattStatsOnPlug=false resetBattStatsOnUnplug=false versionCode=$(sed -n s/versionCode=//p $execDir/module.prop 2>/dev/null || :) if [ "${1:-y}" = -x ]; then - log=/sdcard/accd-${device}.log + log=/sdcard/Download/accd-${device}.log persistLog=true shift else @@ -403,24 +455,18 @@ if ! $init; then misc_stuff "${1-}" . $execDir/oem-custom.sh - . $config + src_cfg voltage_now=$batt/voltage_now t -f $voltage_now || voltage_now=$batt/batt_vol if ! t -f $voltage_now; then - echo 3920 > $TMPDIR/.voltage_now + echo 3900 > $TMPDIR/.voltage_now voltage_now=$TMPDIR/.voltage_now fi apply_on_boot - - # disable charging after a reboot, if min < capacity < max - if _lt_pause_cap && _gt_resume_cap; then - disable_charging - fi - ctrl_charging exit $? @@ -428,6 +474,9 @@ if ! $init; then else + args="$(echo "$@" | sed -E 's/(--init|-i)//g')" + + # filter out missing and problematic charging switches (those with unrecognized values) filter_sw() { @@ -514,7 +563,7 @@ else do [ -f $f ] && . $f && break done - list_ch_switches | grep -Ev '^#|^$' | \ + ls_ch_switches | grep -Ev '^#|^$' | \ while IFS= read -r chargingSwitch; do set -f set -- $chargingSwitch @@ -526,7 +575,7 @@ else rm $TMPDIR/ch-switches__ break fi - shift 3 2>/dev/null + [ $# -lt 3 ] || shift 3 done [ -f $TMPDIR/ch-switches__ ] \ && cat $TMPDIR/ch-switches__ >> $TMPDIR/ch-switches_ \ @@ -536,12 +585,13 @@ else fi echo >> $TMPDIR/ch-switches_ done + cat $dataDir/logs/parsed.log 2>/dev/null >> $TMPDIR/ch-switches_ sed -i -e 's/ $//' -e '/^$/d' $TMPDIR/ch-switches_ # read charging voltage control files : > $TMPDIR/ch-volt-ctrl-files_ - ls -1 $(list_volt_ctrl_files | grep -Ev '^#|^$') 2>/dev/null | \ + ls -1 $(ls_volt_ctrl_files | grep -Ev '^#|^$') 2>/dev/null | \ while read file; do chmod 0644 $file 2>/dev/null && grep -Eq '^4[1-4][0-9]{2}' $file || continue grep -q '.... ....' $file && continue @@ -555,16 +605,17 @@ else rm $TMPDIR/.ch-curr-read 2>/dev/null : > $TMPDIR/ch-curr-ctrl-files_ - ls -1 $(list_curr_ctrl_files_boolean | grep -Ev '^#|^$') 2>/dev/null | \ + ls -1 $(ls_curr_ctrl_files_boolean | grep -Ev '^#|^$') 2>/dev/null | \ while read file; do chmod 0644 $file 2>/dev/null || continue grep -q '^[01]$' $file && echo ${file}::1::0 >> $TMPDIR/ch-curr-ctrl-files done - ls -1 $(list_curr_ctrl_files_static | grep -Ev '^#|^$') 2>/dev/null | \ + ls -1 $(ls_curr_ctrl_files_static | grep -Ev '^#|^$') 2>/dev/null | \ while read file; do chmod 0644 $file 2>/dev/null || continue defaultValue=$(cat $file) + [ -n "$defaultValue" ] || continue ampFactor=$(sed -n 's/^ampFactor=//p' $dataDir/config.txt 2>/dev/null) [ -n "$ampFactor" -o $defaultValue -ne 0 ] || continue if [ "${ampFactor:-1}" -eq 1000 -o ${defaultValue#-} -lt 10000 ]; then @@ -579,9 +630,10 @@ else done - # remove duplicates and parallel/ ctrl files + # exclude duplicates and parallel/ ctrl files for file in $TMPDIR/ch-*_; do sort -u $file | grep -iv parallel > ${file%_} + sed -i /::-/d ${file%_} # exclude ctrl files with negative values rm $file done @@ -600,7 +652,7 @@ else # start $id daemon rm $TMPDIR/.ghost-charging 2>/dev/null - exec $0 "$@" + exec $0 $args fi exit 0 diff --git a/acc/acquire-lock.sh b/install/acquire-lock.sh similarity index 100% rename from acc/acquire-lock.sh rename to install/acquire-lock.sh diff --git a/acc/batt-info.sh b/install/batt-info.sh similarity index 97% rename from acc/batt-info.sh rename to install/batt-info.sh index 4786dde..a183492 100644 --- a/acc/batt-info.sh +++ b/install/batt-info.sh @@ -10,7 +10,7 @@ batt_info() { # calculator calc2() { - awk "BEGIN {print $*}" | xargs printf %.2f + awk "BEGIN {print $*}" | tr , . | xargs printf %.2f } diff --git a/install/batt-interface.sh b/install/batt-interface.sh new file mode 100644 index 0000000..d4b7224 --- /dev/null +++ b/install/batt-interface.sh @@ -0,0 +1,161 @@ +discharging() { + tt "$curThen,$curNow" "-*,[0-9]*|[0-9]*,-*" && { + [ ${chargingSwitch[2]:-.} = voltage_now ] && _status=Idle || _status=Discharging + } +} + + +idle() { + grep -iq 'Not charging' $battStatus || { + [ -n "$idleThreshold_" ] && [ $curThen != null ] && { + if $positive; then + [ $curNow -ge -$idleThreshold_ ] && [ $curNow -le $idleThreshold1 ] + else + [ $curNow -le $idleThreshold_ ] && [ $curNow -ge -$idleThreshold1 ] + fi + } || return 1 + } + _status=Idle +} + + +not_charging() { + + local i= + local off=${flip-}; flip= + local curThen=$(cat $curThen) + local positive=true + local seqCount=${seqCount:-16} ### + + [ $curThen != null ] && [ $curThen -lt 0 ] && positive=false || : + tt "${chargingSwitch[$*]-}" "*\ --" || battStatusOverride= + [ $currFile != $TMPDIR/.dummy-curr ] || battStatusWorkaround=false + + if [ -z "${battStatusOverride-}" ] && [ -n "$off" ]; then + [ $off = off ] && off=true || off=false + for i in $(seq $seqCount); do + if $off; then + ! status ${1-} || return 0 + [ $i -lt 5 ] || { + if $positive; then + [ $(cat $currFile) -lt $((curThen / 100 * 90)) ] || return 1 + else + [ $(cat $currFile) -gt $((curThen / 100 * 90)) ] || return 1 + fi + } + else + status ${1-} || return 1 + fi + [ $i = $seqCount ] || sleep 1 + done + $off && return 1 || return 0 + else + status ${1-} + fi +} + + +status() { + + local i= + local curNow=$(cat $currFile) + + _status=$(sed 's/Not charging/Idle/' $battStatus) + [ -z "${exitCode_-}" ] || echo " curr=$curThen,$curNow off=${off:-false} status=$_status" + + if [ -n "${battStatusOverride-}" ]; then + if tt "$battStatusOverride" "Discharging|Idle"; then + [ $(cat ${chargingSwitch[0]}) != ${chargingSwitch[2]} ] || _status=$battStatusOverride + else + _status=$(set -eu; eval '$battStatusOverride') || : + fi + elif $battStatusWorkaround; then + idle || discharging || : + fi + + for i in Discharging DischargingDischarging Idle IdleIdle; do + [ $i != ${1-}$_status ] || return 0 + done + + return 1 +} + + +if ${init:-false}; then + + for batt in maxfg/capacity */capacity; do + if [ -f ${batt%/*}/status ]; then + batt=${batt%/*} + break + fi + done + + case $batt in + */capacity) exit 1;; + esac + + for battStatus in sm????_bms/status $batt/status; do + [ ! -f $battStatus ] || break + done + + + echo 250 > $TMPDIR/.dummy-temp + + for temp in $batt/temp $batt/batt_temp bms/temp $TMPDIR/.dummy-temp; do + [ ! -f $temp ] || break + done + + + echo 0 > $TMPDIR/.dummy-curr + + for currFile in $batt/current_now bms/current_now \ + $batt/batteryaveragecurrent $TMPDIR/.dummy-curr + do + [ ! -f $currFile ] || break + done + + curr=$(sed s/-// $currFile) + idleThreshold=11 # mA + idleThreshold1=101 # mA + idleThreshold_=$idleThreshold + ampFactor_=1000 + + if [ $curr -le $idleThreshold_ ]; then + ampFactor_= + idleThreshold_= + else + ! [ $curr -ge 10000 ] || { + ampFactor_=1000000 + idleThreshold_=${idleThreshold_}000 + } + fi + + case "$(sed -n 's/^ampFactor=//p' $dataDir/config.txt 2>/dev/null)" in + 1000) idleThreshold_=$idleThreshold;; + 1000000) idleThreshold_=${idleThreshold}000; idleThreshold1=${idleThreshold1}000;; + esac + + unset curr + curThen=$TMPDIR/.curr + rm $curThen 2>/dev/null || : + + + echo " +ampFactor_=$ampFactor_ +batt=$batt +battCapacity=$batt/capacity +battStatus=\"$battStatus\" +currFile=$currFile +curThen=$curThen +idleThreshold_=$idleThreshold_ +idleThreshold1=$idleThreshold1 +temp=$temp +" > $TMPDIR/.batt-interface.sh + + init=false + +else + . $TMPDIR/.batt-interface.sh +fi + +[ -f $curThen ] || echo null > $curThen diff --git a/acc/ctrl-files.sh b/install/ctrl-files.sh similarity index 94% rename from acc/ctrl-files.sh rename to install/ctrl-files.sh index a48889e..1893625 100644 --- a/acc/ctrl-files.sh +++ b/install/ctrl-files.sh @@ -1,4 +1,4 @@ -list_ch_switches() { +ls_ch_switches() { echo " */*charging_enabled 1 0 */*disable_charg* 0 1 @@ -10,10 +10,12 @@ list_ch_switches() { */input_suspend 0 1 battery/batt_slate_mode 0 1 battery/battery_input_suspend 0 1 +battery/bd_trickle_cnt 0 1 battery/device/*stop_charging 0 1 battery/device/Charging_Enable 1 0 battery/op_disable_charge 0 1 battery/store_mode 0 1 +battery/test_mode 2 1 idt/pin_enabled 1 0 battery/charging_enabled 0 0 battery/op_disable_charge 0 1 battery/charging_enabled 1 1 @@ -67,19 +69,19 @@ main/cool_mode 0 1 maxfg/offmode_charger 0 1 # troublesome -/sys/devices/platform/battery/ChargerEnable 1 0 -#/sys/class/qcom-battery/vbus_disable 0 1 #/sys/devices/platform/battery_meter/FG_daemon_disable 0 1 #/sys/power/pnpmgr/battery/charging_enabled 1 0 -#usb/vbus_disable 0 1 +/sys/class/qcom-battery/vbus_disable 0 1 +/sys/devices/platform/battery/ChargerEnable 1 0 battery/ChargerEnable 1 0 +#usb/vbus_disable 0 1 # deprecated battery/op_disable_charge 0 1 battery/input_suspend 0 0 " } -list_curr_ctrl_files_boolean() { +ls_curr_ctrl_files_boolean() { echo " */input_current_limited */restrict*_ch*g* @@ -87,14 +89,14 @@ list_curr_ctrl_files_boolean() { " } -list_curr_ctrl_files_dynamic() { +ls_curr_ctrl_files_dynamic() { echo " */current_max */input_current_max " } -list_curr_ctrl_files_static() { +ls_curr_ctrl_files_static() { echo " */ac_charge */ac_input @@ -121,7 +123,7 @@ list_curr_ctrl_files_static() { " } -list_volt_ctrl_files() { +ls_volt_ctrl_files() { echo " */batt_tune_float_voltage */constant_charge_voltage* diff --git a/acc/default-config.txt b/install/default-config.txt similarity index 67% rename from acc/default-config.txt rename to install/default-config.txt index da4d5a5..92a70e5 100644 --- a/acc/default-config.txt +++ b/install/default-config.txt @@ -1,22 +1,45 @@ -configVerCode=202202060 +configVerCode=202206010 + capacity=(-1 60 70 75 false false) + temperature=(40 60 90 65) + cooldownRatio=() cooldownCurrent= cooldownCustom=() -resetBattStats=(false false) + +resetBattStats=(false false false) + chargingSwitch=() + applyOnBoot=() + applyOnPlug=() + maxChargingCurrent=() + maxChargingVoltage=() -language=en -runCmdOnPause=() + +language= + +runCmdOnPause='' + ampFactor= voltFactor= -loopCmd=() + +loopCmd='' + prioritizeBattIdleMode=false currentWorkaround=false +battStatusWorkaround=true + +schedule='' + +battStatusOverride='' + +rebootResume=false + +: one-line script sample; echo nothing >/dev/null # WARNINGS @@ -40,7 +63,9 @@ currentWorkaround=false # A change to current_workaround (cw) only takes effect after an acc [re]initialization (install, upgrade or "accd --init") or system reboot. -# If those 2 variables are updated with "acc --set" (not acca --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). + +# The only nullable variables are those which are null by default (var=, var="" and var=()). # BASICS @@ -55,7 +80,7 @@ currentWorkaround=false # cooldownCurrent=cooldown_current=[milliamps] -# resetBattStats=(reset_batt_stats_on_pause reset_batt_stats_on_unplug) +# resetBattStats=(reset_batt_stats_on_pause reset_batt_stats_on_unplug reset_batt_stats_on_plug) # chargingSwitch=charging_switch=(ctrl_file1 on off ctrl_file2 on off --) @@ -77,20 +102,30 @@ currentWorkaround=false # language=lang=language_code -# runCmdOnPause=run_cmd_on_pause=(. script) +# runCmdOnPause=run_cmd_on_pause='command...' # ampFactor=amp_factor=[multiplier] # voltFactor=volt_factor=[multiplier] -# loopCmd=loop_cmd=(. script) +# loopCmd=loop_cmd='command...' # prioritizeBattIdleMode=prioritize_batt_idle_mode=boolean # currentWorkaround=current_workaround=boolean +# battStatusWorkaround=batt_status_workaround=boolean + +# schedule=sched='HHMM command... +# HHMM command... +# ...' + +# battStatusOverride=batt_status_override=Idle|Discharging|'code to PRINT value for _status' + +# rebootResume=reboot_resume=boolean + -# VARIABLE ALIASES/SHORTCUTS +# ALIASES/SHORTCUTS # cc cooldown_capacity # rc resume_capacity @@ -113,6 +148,7 @@ currentWorkaround=false # rbsp reset_batt_stats_on_pause # rbsu reset_batt_stats_on_unplug +# rbspl reset_batt_stats_on_plug # s charging_switch @@ -129,42 +165,15 @@ currentWorkaround=false # vf volt_factor # lc loop_cmd + # pbim prioritize_batt_idle_mode # cw current_workaround +# bsw batt_status_workaround +# sd sched -# COMMAND EXAMPLES - -# acc 85 80 -# acc -s pc=85 rc=80 -# acc --set pause_capacity=85 resume_capacity=80 - -# acc -s "s=battery/charging_enabled 1 0" -# acc --set "charging_switch=/proc/mtk_battery_cmd/current_cmd 0::0 0::1 /proc/mtk_battery_cmd/en_power_path 1 0" -# NOTE: "::" is used as a whitespace placeholder in "/proc/mtk_battery_cmd/current_cmd 0::0 0::1" charging switch only. - -# acc -s -v 3920 (millivolts) -# acc -s -c 500 (milliamps) - -# custom config path -# acc /data/acc-night-config.txt 45 43 -# acc /data/acc-night-config.txt -s c 500 -# accd /data/acc-night-config.txt - -# acc -s "ccu=battery/current_now 1450000 100 20" -# acc -s "cooldown_custom=battery/current_now 1450000 100 20" -# acc -s ccu="/sys/devices/virtual/thermal/thermal_zone1/temp 55 50 10" - -# acc -s amp_factor=1000 -# acc -s volt_factor=1000000 - -# acc -s mcc=500 mcv="3920 --exit" - -# acc -s loop_cmd="echo 0 \\> battery/input_suspend" - -# acc -s cooldown_current=500 - -# acc -s st=60 +# bso batt_status_override +# rr reboot_resume # FINE, BUT WHAT DOES EACH OF THESE VARIABLES ACTUALLY MEAN? @@ -225,7 +234,6 @@ currentWorkaround=false # cooldown_custom (ccu) # # When cooldown_capacity and/or cooldown_temp don't suit your needs, this comes to the rescue. # It takes precedence over the regular cooldown settings. -# Refer back the command examples. # cooldown_current (cdc) # # Instead of pausing charging periodically during the cooldown phase, limit the max charging current (e.g., to 500 mA) @@ -234,7 +242,10 @@ currentWorkaround=false # Reset battery stats after pausing charging. # reset_batt_stats_on_unplug (rbsu) # -# Reset battery stats if the charger has been unplugged for 10 seconds. +# Reset battery stats if the charger has been unplugged for a few seconds. + +# reset_batt_stats_on_plug (rbspl) # +# Reset battery stats if the charger has been plugged for a few seconds. # charging_switch (s) # # If unset, acc cycles through its database and sets the first working switch/group that disables charging. @@ -264,10 +275,10 @@ currentWorkaround=false # max_charging_voltage (mcv) # # Only the current/voltage value is to be supplied. # Control files are automatically selected. -# Refer back to the command examples. # lang (l) # -# acc language, managed with "acc --set --lang" (acc -s l). +# acc language, managed with "acc --set --lang" (acc -sl). +# When null, English (en) is assumed. # run_cmd_on_pause (rcp) # # Run commands* after pausing charging. @@ -283,7 +294,7 @@ currentWorkaround=false # loop_cmd (lc) # # This is meant for extending accd's functionality. -# It is periodically executed by is_charging() - which is called regularly, within the main accd loop. +# It is periodically executed by the is_charging function -- which is called regularly, within the main accd loop. # The boolean isCharging is available. # Refer back to COMMAND EXAMPLES. @@ -297,3 +308,54 @@ currentWorkaround=false # This is necessary only if the current limit affects both input and charging current values. # Try this if low current values don't work. # "accd --init" is required after changing this (automated by "acc --set"). + +# batt_status_workaround (bsw) # +# With this enabled, in addition to just reading POWER_SUPPLY_STATUS, if the battery is "Charging" and current is within -11 and 95 mA (inclusive), battery status is considered "Idle". Status is considered "Discharging", if current drops significantly, after calling the disable_charging function. +# By not relying solely on the information provided by POWER_SUPPLY_STATUS, this approach boosts compatibility quite dramatically. So much so, that on certain devices (e.g., Nokia 2.2), acc only works when this is enabled. +# On the other hand, the user may observe charging control inconsistencies on devices that report wrong current values or major current fluctuations. +# Oftentimes, charging control issues are related to the power adapter. + +# sched (sd) # +# Command/script schedules, in the following format: +# +# sched="HHMM command... +# HHMM command... +# ..." +# +# e.g., 3900 mV at 22:00, and 4100 mV at 6:00, daily: +# sched="2200 acc -s mcv=3900 +# 0600 acc -s mcv=4100" +# +# 12 hour format is not supported. +# Each schedule must be on its own line. +# Each line is daemonized. +# This is not limited to acc commands. It can run anything. +# +# Commands: +# -s|--set [sd|sched]="[+-]schedule to add or pattern to delete" +# e.g., +# acc -s sd=-2050 (delete schedules that match 2050) +# acc -s sd="+2200 acc -s mcv=3900 mcc=500; acc -n "Switched to \"sleep\" profile" (append schedule) +# Note: "acc -s sd=" behaves just like similar commands (restores default value; for schedules, it's null) + +# batt_status_override (bso) # +# Overrides the battery status determined by the not_charging function. +# It can be Idle, Discharging (both case sensitive), or logic to PRINT the desired value for the _status variable. +# When set to Idle or Discharging, _status will be set to that value if the enforced* charging switch state is off. +# It only works in conjunction with an enforced charging switch (set manually, has a trailing " --"). +# +# Usage scenario: the switch "main/cool_mode 0 1" supports idle mode. However, sometimes it does not respond soon enough (e.g., due to fast charging). The user can then enforce it with acc -ss and set batt_status_override=Idle. This means, when main/cool_mode is on (0), _status will be determined by the not_charging function (as usual), but when it's off (1), _status will be Idle, bypassing the not_charging function. +# +# If the user were to write their own logic, it would've be something as follows: +# batt_status_override='[ $(cat main/cool_mode) -eq 1 ] && printf Idle' + +# reboot_resume (rr) # +# Reboot (when capacity <= resume_capacity) to re-enable charging. +# A warning notification is posted 60 seconds prior, for the user to block the action, if they so please. + +# one-line scripts # +# Every line that begins with ": " is interpreted as a one-line script. +# This feature can be useful for many things, including setting up persistent config profiles (source a file that overrides the main config). +# All script lines are executed whenever the config is loaded/sourced. +# This happens regularly while the daemon is running, and at least once per command run. +# Warning: all files used in one-line scripts must reside somewhere in /data/adb/, just like acc's own data files. diff --git a/acc/flash-zips.sh b/install/flash-zips.sh similarity index 98% rename from acc/flash-zips.sh rename to install/flash-zips.sh index 35f4d75..425a48d 100644 --- a/acc/flash-zips.sh +++ b/install/flash-zips.sh @@ -110,7 +110,7 @@ for zipFile in $zipFiles; do e=$? [ $e -ne 0 ] && { printf " -(!) $zipFile: *exit $e* +$zipFile: *exit $e* > $zipFile.log Continue: [enter] diff --git a/acc/logf.sh b/install/logf.sh similarity index 94% rename from acc/logf.sh rename to install/logf.sh index c3d4eed..e92ba76 100644 --- a/acc/logf.sh +++ b/install/logf.sh @@ -29,9 +29,9 @@ logf() { batt_info > $TMPDIR/acc-i.txt) dumpsys battery > dumpsys-battery.txt - tar -c *.log *.txt | gzip -9 > $dataDir/logs/acc-logs-$device.tar.gz + tar -c *.log *.txt | gzip -9 > $dataDir/logs/acc-logs-$device.tgz rm *.txt magisk.log in*.log power*.log 2>/dev/null - echo "(i) $dataDir/logs/acc-logs-$device.tar.gz" + echo "$dataDir/logs/acc-logs-$device.tgz" else if tt "${1:-x}" "-*a*"; then diff --git a/acc/misc-functions.sh b/install/misc-functions.sh similarity index 67% rename from acc/misc-functions.sh rename to install/misc-functions.sh index b926ff1..5d6ce0b 100644 --- a/acc/misc-functions.sh +++ b/install/misc-functions.sh @@ -50,7 +50,7 @@ apply_on_plug() { calc() { - awk "BEGIN {print $*}" + awk "BEGIN {print $*}" | tr , . } @@ -73,7 +73,7 @@ cycle_switches() { if [ "$1" = on ]; then not_charging || break else - if sleep_sd not_charging ${2-}; then + if not_charging ${2-}; then # set working charging switch(es) s="${chargingSwitch[*]}" # for some reason, without this, the array is null . $execDir/write-config.sh @@ -98,48 +98,50 @@ disable_charging() { local autoMode=true - if ! switch_mA "${chargingSwitch[0]:-/}"; then + not_charging || { - ! tt "${chargingSwitch[*]-}" "*--" || autoMode=false - ! $isAccd || ! not_charging || return 0 + if tt "${chargingSwitch[0]:-/}" "*/*"; then - if tt "${chargingSwitch[0]-}" "*/*"; then - if [ -f ${chargingSwitch[0]} ]; then - if ! { flip_sw off && sleep_sd not_charging; }; then - $isAccd || print_switch_fails "${chargingSwitch[@]}" - flip_sw on 2>/dev/null || : - if $autoMode; then - unset_switch - cycle_switches_off + ! tt "${chargingSwitch[*]-}" "*--" || autoMode=false + + if tt "${chargingSwitch[0]-}" "*/*"; then + if [ -f ${chargingSwitch[0]} ]; then + if ! { flip_sw off && not_charging; }; then + $isAccd || print_switch_fails "${chargingSwitch[@]}" + flip_sw on 2>/dev/null || : + if $autoMode; then + unset_switch + cycle_switches_off + fi fi + else + invalid_switch fi else - invalid_switch + cycle_switches_off fi - else - cycle_switches_off - fi - if $autoMode && ! not_charging; then - return 7 # total failure - fi + if $autoMode && ! not_charging; then + return 7 # total failure + fi - else - set +e - if [ ${chargingSwitch[0]:-0} -lt 3700 ]; then - maxChargingCurrent0=${maxChargingCurrent[0]-} - set_ch_curr ${chargingSwitch[0]:-0} else - maxChargingVoltage0=${maxChargingVoltage[0]-} - set_ch_volt ${chargingSwitch[0]:-0} + set +e + if [ ${chargingSwitch[0]:-0} -lt 3700 ]; then + maxChargingCurrent0=${maxChargingCurrent[0]-} + set_ch_curr ${chargingSwitch[0]:-0} + else + maxChargingVoltage0=${maxChargingVoltage[0]-} + set_ch_volt ${chargingSwitch[0]:-0} + fi + set -e + chargingDisabled=true fi - set -e - chargingDisabled=true - fi - (set +eux - eval "${runCmdOnPause[@]-}" - eval "${runCmdOnPause_-}") || : + (set +eux + eval '${runCmdOnPause-}' + eval '${runCmdOnPause_-}') || : + } if [ -n "${1-}" ]; then case $1 in @@ -156,7 +158,7 @@ disable_charging() { print_charging_disabled_for $1 echo case $1 in - *h) sleep $(( ${1%h} * 3700 ));; + *h) sleep $(( ${1%h} * 3600 ));; *m) sleep $(( ${1%m} * 60 ));; *s) sleep ${1%s};; esac @@ -177,40 +179,41 @@ dumpsys() { /system/bin/dumpsys "$@" || :; } enable_charging() { - if ! switch_mA "${chargingSwitch[0]:-/}"; then + ! not_charging || { + + if tt "${chargingSwitch[0]:-/}" "*/*"; then - ! $isAccd || not_charging || return 0 + if ! $ghostCharging || { $ghostCharging && tt "$(cat */online)" "*1*"; }; then - if ! $ghostCharging || { $ghostCharging && tt "$(cat */online)" "*1*"; }; then + flip_sw on || cycle_switches on - flip_sw on || cycle_switches on + # detect and block ghost charging + if ! $ghostCharging && ! not_charging && ! tt "$(cat */online)" "*1*" \ + && sleep ${loopDelay[0]} && ! not_charging && ! tt "$(cat */online)" "*1*" + then + ghostCharging=true + disable_charging > /dev/null + touch $TMPDIR/.ghost-charging + wait_plug + return 0 + fi - # detect and block ghost charging - if ! $ghostCharging && ! not_charging && ! tt "$(cat */online)" "*1*" \ - && sleep ${loopDelay[0]} && ! not_charging && ! tt "$(cat */online)" "*1*" - then - ghostCharging=true - disable_charging > /dev/null - touch $TMPDIR/.ghost-charging + else wait_plug return 0 fi else - wait_plug - return 0 - fi - - else - set +e - if [ ${chargingSwitch[0]:-0} -lt 3700 ]; then - set_ch_curr ${maxChargingCurrent0:--} - else - set_ch_volt ${maxChargingVoltage0:--} + set +e + if [ ${chargingSwitch[0]:-0} -lt 3700 ]; then + set_ch_curr ${maxChargingCurrent0:--} + else + set_ch_volt ${maxChargingVoltage0:--} + fi + set -e + chargingDisabled=false fi - set -e - chargingDisabled=false - fi + } if [ -n "${1-}" ]; then case $1 in @@ -227,7 +230,7 @@ enable_charging() { print_charging_enabled_for $1 echo case $1 in - *h) sleep $(( ${1%h} * 3700 ));; + *h) sleep $(( ${1%h} * 3600 ));; *m) sleep $(( ${1%m} * 60 ));; *s) sleep ${1%s};; esac @@ -245,33 +248,45 @@ enable_charging() { flip_sw() { + flip=$1 + local cn= + local ct= local on= local off= local off_= - local flip=$1 set -- ${chargingSwitch[@]-} [ -f ${1:-//} ] || return 1 while [ -f ${1:-//} ]; do on="$(parse_value "$2")" - if [ $flip = off ]; then - #! tt "${chargingSwitch[*]:-.}" "battery/input_suspend?0?1?/proc/mtk_battery_cmd/en_power_path?1?1*" ] || sleep 6 # mtk idle mode workaround + [ $flip = on ] || { if [ ${chargingSwitch[2]:-.} = voltage_now ]; then off_="$off" ! off=$(cat $batt/voltage_now 2>/dev/null) \ && off="$off_" \ - || { [ $off -lt 10000 ] && off=$((off - 50)) || off=$((off - 50000)); } + || { [ $off -lt 10000 ] && off=$((off - ${voltOff:-150})) || off=$((off - ${voltOff:-150}000)); } else off="$(parse_value "$3")" fi - cat $currFile > $TMPDIR/.curr - sleep 1 - else - echo null > $TMPDIR/.curr - fi + } + + [ $flip = on ] || { + # cn=$(cat $currFile) + # ct=$(cat $curThen) + # case $ct in + # -*) [ $cn -lt $ct ] || ct=n;; + # [0-9]*) [ $cn -gt $ct ] || ct=n;; + # esac + # [ $ct = n ] || cat $currFile > $curThen + cat $currFile > $curThen + } + write \$$flip $1 || return 1 - shift 3 2>/dev/null || return 0 + + [ $# -lt 3 ] || shift 3 + [ $# -ge 3 ] || break + done } @@ -300,7 +315,7 @@ misc_stuff() { notif() { - su -lp 2000 -c "/system/bin/cmd notification post -S bigtext -t 'ACC' 'Tag' \"$*\"" < /dev/null > /dev/null 2>&1 + su -lp ${2:-2000} -c "/system/bin/cmd notification post -S bigtext -t '🔋ACC' 'Tag' \"${1:-:)}\"" < /dev/null > /dev/null 2>&1 } @@ -314,8 +329,8 @@ parse_value() { print_header() { - echo "Advanced Charging Controller $accVer ($accVerCode) -Copyright 2017-2022, VR25 + echo "Advanced Charging Controller (ACC) $accVer ($accVerCode) +(C) 2017-2022, VR25 GPLv3+" } @@ -326,20 +341,8 @@ print_wait_plug() { } -sleep_sd() { - local i= - for i in $(seq $switchSeq); do - (set +eu; eval "$@") && return 0 || sleep 2 - done - return 1 -} - - -switch_mA() { - case "$1" in - */*) return 1;; - *) return 0;; - esac +src_cfg() { + . $config || cat $execDir/default-config.txt > $config } @@ -364,7 +367,7 @@ unset_switch() { wait_plug() { $isAccd || { - echo "(i) ghostCharging=true" + echo "ghostCharging=true" print_wait_plug } (while ! tt "$(cat */online)" "*1*"; do @@ -380,18 +383,19 @@ write() { local i= local l=$dataDir/logs/write.log local s= + blacklisted=false [ -f "$2" ] && chmod 0644 "$2" || return ${3-1} s="$(grep -E "^(#$2|$2)$" $l 2>/dev/null || :)" case "$s" in \#*) blacklisted=true; return ${3-1};; "") echo "#$2" >> $l; s=x;; esac - for i in 1 2; do - eval echo "$1" > "$2" || return ${3-1} + for i in $(seq 4); do + eval echo "$1" > "$2" || { i=x; break; } sleep 0.5 done - blacklisted=false [ $s != x ] || sed -i "\|^#$2$|s|^#||" $l + [ $i != x ] || return ${3-1} } @@ -399,7 +403,6 @@ write() { id=acc domain=vr25 -switchSeq=4 isAccd=false loopDelay=(5 10) execDir=/data/adb/$domain/acc @@ -434,8 +437,6 @@ pgrep -f zygote > /dev/null || { dumpsys() { :; } } -! grep -q mtk_battery_cmd $TMPDIR/ch-switches || switchSeq=11 - # load plugins mkdir -p ${execDir}-data/plugins $TMPDIR/plugins for f in ${execDir}-data/plugins/*.sh $TMPDIR/plugins/*.sh; do diff --git a/acc/oem-custom.sh b/install/oem-custom.sh similarity index 95% rename from acc/oem-custom.sh rename to install/oem-custom.sh index c6c004a..a97de38 100644 --- a/acc/oem-custom.sh +++ b/install/oem-custom.sh @@ -12,6 +12,7 @@ if (set +x; . $config) > /dev/null 2>&1; then else $TMPDIR/acca --set dummy= fi + [ $configVer -lt 202203150 ] && sed -i '/^#/d' $dataDir/logs/write.log 2>/dev/null || : } else cat $execDir/default-config.txt > $config diff --git a/acc/power-supply-logger.sh b/install/power-supply-logger.sh similarity index 96% rename from acc/power-supply-logger.sh rename to install/power-supply-logger.sh index 2492509..16d519e 100644 --- a/acc/power-supply-logger.sh +++ b/install/power-supply-logger.sh @@ -46,7 +46,7 @@ export TMPDIR=/dev/.vr25/acc execDir=/data/adb/vr25/acc logsDir=/data/adb/vr25/acc-data/logs -print_wait 2>/dev/null || echo "(i) This may take a minute or so..." +print_wait 2>/dev/null || echo "This may take a while..." # log diff --git a/acc/print-config.sh b/install/print-config.sh similarity index 76% rename from acc/print-config.sh rename to install/print-config.sh index 19dba3d..278bfdb 100644 --- a/acc/print-config.sh +++ b/install/print-config.sh @@ -22,6 +22,7 @@ cooldown_custom=${cooldownCustom[@]} reset_batt_stats_on_pause=${resetBattStats[0]} reset_batt_stats_on_unplug=${resetBattStats[1]} +reset_batt_stats_on_plug=${resetBattStats[2]} charging_switch=${chargingSwitch[@]} @@ -35,12 +36,19 @@ max_charging_voltage=${maxChargingVoltage[0]} lang=$language -run_cmd_on_pause=${runCmdOnPause[@]} +run_cmd_on_pause='$runCmdOnPause' amp_factor=$ampFactor volt_factor=$voltFactor -loop_cmd=${loopCmd[@]} +loop_cmd='$loopCmd' prioritize_batt_idle_mode=$prioritizeBattIdleMode -current_workaround=$currentWorkaround" +current_workaround=$currentWorkaround +batt_status_workaround=$battStatusWorkaround + +sched='$schedule' + +batt_status_override='$battStatusOverride' + +reboot_resume=$rebootResume" diff --git a/acc/print-help.sh b/install/print-help.sh similarity index 100% rename from acc/print-help.sh rename to install/print-help.sh diff --git a/acc/read-ch-curr-ctrl-files-p2.sh b/install/read-ch-curr-ctrl-files-p2.sh similarity index 85% rename from acc/read-ch-curr-ctrl-files-p2.sh rename to install/read-ch-curr-ctrl-files-p2.sh index 4707c9d..452e6e6 100644 --- a/acc/read-ch-curr-ctrl-files-p2.sh +++ b/install/read-ch-curr-ctrl-files-p2.sh @@ -12,10 +12,11 @@ then plugins=/data/adb/vr25/acc-data/plugins [ -f $plugins/ctrl-files.sh ] && . $plugins/ctrl-files.sh - ls -1 $(list_curr_ctrl_files_dynamic | grep -Ev '^#|^$') 2>/dev/null | \ + ls -1 $(ls_curr_ctrl_files_dynamic | grep -Ev '^#|^$') 2>/dev/null | \ while read file; do chmod 0644 $file || continue defaultValue=$(cat $file) + [ -n "$defaultValue" ] || continue [ $defaultValue -eq 0 ] && continue if [ ${defaultValue#-} -lt 10000 ]; then # milliamps @@ -30,9 +31,13 @@ then sort -u $TMPDIR/ch-curr-ctrl-files > $TMPDIR/ch-curr-ctrl-files_ + # exclude ctrl files with negative values + sed -i /::-/d $TMPDIR/ch-curr-ctrl-files_ + # add curr and volt ctrl files to charging switches list sed -e 's/::.*::/ /g' -e 's/$/ 0/' $TMPDIR/ch-curr-ctrl-files_ > $TMPDIR/.ctrl sed -Ee 's/::.*::/ /g' -e 's/([0-9])$/\1 voltage_now/' $TMPDIR/ch-volt-ctrl-files >> $TMPDIR/.ctrl + grep / $TMPDIR/.ctrl >> $TMPDIR/ch-switches rm $TMPDIR/.ctrl @@ -45,5 +50,5 @@ then || cat $TMPDIR/ch-curr-ctrl-files_ > $TMPDIR/ch-curr-ctrl-files fi -rm $TMPDIR/ch-curr-ctrl-files_ +rm $TMPDIR/ch-curr-ctrl-files_ 2>/dev/null touch $TMPDIR/.ch-curr-read) || : diff --git a/acc/release-lock.sh b/install/release-lock.sh similarity index 100% rename from acc/release-lock.sh rename to install/release-lock.sh diff --git a/acc/select.sh b/install/select.sh similarity index 100% rename from acc/select.sh rename to install/select.sh diff --git a/acc/service.sh b/install/service.sh similarity index 100% rename from acc/service.sh rename to install/service.sh diff --git a/acc/set-ch-curr.sh b/install/set-ch-curr.sh similarity index 96% rename from acc/set-ch-curr.sh rename to install/set-ch-curr.sh index 14d7306..82fb518 100644 --- a/acc/set-ch-curr.sh +++ b/install/set-ch-curr.sh @@ -59,7 +59,7 @@ set_ch_curr() { if [ $1 -ge 0 -a $1 -le 9999 ]; then apply_current $1 || return 1 else - ! $verbose || echo "(!) [0-9999]$(print_mA; print_only)" + ! $verbose || echo "[0-9999]$(print_mA; print_only)" return 11 fi fi diff --git a/acc/set-ch-volt.sh b/install/set-ch-volt.sh similarity index 88% rename from acc/set-ch-volt.sh rename to install/set-ch-volt.sh index 1632bdd..4e2f577 100644 --- a/acc/set-ch-volt.sh +++ b/install/set-ch-volt.sh @@ -31,12 +31,12 @@ set_ch_volt() { # < 3700 millivolts elif [ $1 -lt 3700 ]; then - ! ${verbose:-true} || echo "(!) [3700-4300]$(print_mV; print_only)" + ! ${verbose:-true} || echo "[3700-4300]$(print_mV; print_only)" apply_voltage 3700 ${2-} || return 1 # > 4300 millivolts elif [ $1 -gt 4300 ]; then - ! ${verbose:-true} || echo "(!) [3700-4300]$(print_mV; print_only)" + ! ${verbose:-true} || echo "[3700-4300]$(print_mV; print_only)" apply_voltage 4300 ${2-} || return 1 fi fi diff --git a/acc/set-prop.sh b/install/set-prop.sh similarity index 94% rename from acc/set-prop.sh rename to install/set-prop.sh index f668b06..8da8b22 100644 --- a/acc/set-prop.sh +++ b/install/set-prop.sh @@ -18,7 +18,7 @@ set_prop() { # set multiple properties *=*) . $defaultConfig - . $config + src_cfg export "$@" @@ -34,6 +34,7 @@ set_prop() { r|--reset) ! daemon_ctrl stop > /dev/null || restartDaemon=true cat $defaultConfig > $config + [ .${2-} = .a ] && rm $dataDir/logs/write.log $dataDir/logs/ps-blacklist.log 2>/dev/null || : print_config_reset ! $restartDaemon || $TMPDIR/accd --init $config return 0 @@ -58,7 +59,7 @@ set_prop() { PS3="$(print_choice_prompt)" print_ss_ . $execDir/select.sh - select_ charging_switch $(print_auto; cat $TMPDIR/ch-switches; ! grep -q / $TMPDIR/ch-curr-ctrl-files 2>/dev/null || printf '0 mA\n5 mA\n10 mA\n15 mA\n50 mA\n150 mA\n250 mA\n'; ! grep -q / $TMPDIR/ch-volt-ctrl-files 2>/dev/null || printf '3700 mV\n3800 mV\n3850 mV\n3920 mV\n'; print_exit) + select_ charging_switch $(print_auto; cat $TMPDIR/ch-switches; ! grep -q / $TMPDIR/ch-curr-ctrl-files 2>/dev/null || printf '0 mA\n5 mA\n10 mA\n15 mA\n50 mA\n150 mA\n250 mA\n'; ! grep -q / $TMPDIR/ch-volt-ctrl-files 2>/dev/null || printf '3700 mV\n3800 mV\n3850 mV\n3900 mV\n'; print_exit) [ ${charging_switch:-x} != $(print_exit) ] || exit 0 [ ${charging_switch:-x} != $(print_auto) ] || charging_switch= case "${charging_switch:-x}" in @@ -77,7 +78,7 @@ set_prop() { s:|--charging*witch:) cat $TMPDIR/ch-switches ! grep -q / $TMPDIR/ch-curr-ctrl-files 2>/dev/null || printf '0 mA\n5 mA\n10 mA\n15 mA\n50 mA\n150 mA\n250 mA\n' - ! grep -q / $TMPDIR/ch-volt-ctrl-files 2>/dev/null || printf '3700 mV\n3800 mV\n3850 mV\n3920 mV\n' + ! grep -q / $TMPDIR/ch-volt-ctrl-files 2>/dev/null || printf '3700 mV\n3800 mV\n3850 mV\n3900 mV\n' return 0 ;; diff --git a/acc/setup-busybox.sh b/install/setup-busybox.sh similarity index 87% rename from acc/setup-busybox.sh rename to install/setup-busybox.sh index c1dba49..02f01db 100644 --- a/acc/setup-busybox.sh +++ b/install/setup-busybox.sh @@ -5,7 +5,7 @@ # Usage: . $0 -bin_dir=/data/adb/bin +bin_dir=/data/adb/vr25/bin busybox_dir=/dev/.vr25/busybox magisk_busybox=/data/adb/magisk/busybox @@ -20,7 +20,7 @@ magisk_busybox=/data/adb/magisk/busybox } done [ -x $busybox_dir/ls ] || { - echo "(!) Install busybox or simply place it in $bin_dir/" + echo "Install busybox or simply place it in $bin_dir/" echo exit 3 } diff --git a/acc/strings.sh b/install/strings.sh similarity index 68% rename from acc/strings.sh rename to install/strings.sh index d8fa44e..74ab223 100644 --- a/acc/strings.sh +++ b/install/strings.sh @@ -1,79 +1,79 @@ # English (en) print_already_running() { - echo "(i) accd is already running" + echo "accd is already running" } print_started() { - echo "(i) accd started" + echo "accd started" } print_stopped() { - echo "(i) accd stopped" + echo "accd stopped" } print_not_running() { - echo "(i) accd is not running" + echo "accd is not running" } print_restarted() { - echo "(i) accd restarted" + echo "accd restarted" } print_is_running() { - echo "(i) accd $1 is running $2" + echo "accd $1 is running $2" } print_config_reset() { - echo "(i) Config reset" + echo "Config reset" } print_invalid_switch() { - echo "(!) Invalid charging switch, [${chargingSwitch[@]-}]" + echo "Invalid charging switch, [${chargingSwitch[@]-}]" } print_charging_disabled_until() { - echo "(i) Charging disabled until battery capacity <= $1" + echo "Charging disabled until battery capacity <= $1" } print_charging_disabled_for() { - echo "(i) Charging disabled for $1" + echo "Charging disabled for $1" } print_charging_disabled() { - echo "(i) Charging disabled" + echo "Charging disabled" } print_charging_enabled_until() { - echo "(i) Charging enabled until battery capacity >= $1" + echo "Charging enabled until battery capacity >= $1" } print_charging_enabled_for() { - echo "(i) Charging enabled for $1" + echo "Charging enabled for $1" } print_charging_enabled() { - echo "(i) Charging enabled" + echo "Charging enabled" } print_unplugged() { - echo "(!) Charger must be plugged to continue..." + echo "Ensure the charger is plugged 🔌" } print_switch_works() { - echo "(i) [$@] works" + echo " Switch works ✅" } print_switch_fails() { - echo "(!) [$@] won't work" + echo " Switch doesn't work ❌" } print_no_ctrl_file() { - echo "(!) No control file found" + echo "No control file found" } print_not_found() { - echo "(!) $1 not found" + echo "$1 not found" } @@ -93,20 +93,24 @@ Usage e.g., acc 75 70 acc 80 (resume_capacity defaults to 80% - 5) - acc 3920 (same as acc 3920 3870, great idle mode alternative) + acc 3900 (same as acc 3900 3870, great idle mode alternative) acc [options] [args] Refer to the list of options below acca [options] [args] acc optimized for front-ends - acc[d] -x [options] [args] Sets log=/sdcard/acc[d]-\${device}.log; useful for debugging unwanted reboots + acc[d] -x [options] [args] Sets log=/sdcard/Download/acc[d]-\${device}.log; useful for debugging unwanted reboots A custom config path can be specified as first parameter (second if -x is used). If the file doesn't exist, the current config is cloned. e.g., acc /data/acc-night-config.txt --set pause_capacity=45 resume_capacity=43 acc /data/acc-night-config.txt --set --current 500 - accd /data/acc-night-config.txt + accd /data/acc-night-config.txt --init + + Notes regarding accd: + - The order of "--init|-i" does not matter. + - The config path string shall not contain "--init|-i". Options @@ -165,12 +169,15 @@ Options -la Same as -l -a - -l|--log -e|--export Export all logs to /data/adb/vr25/acc-data/logs/acc-logs-\$deviceName.tar.gz + -l|--log -e|--export Export all logs to $dataDir/logs/acc-logs-\$deviceName.tgz e.g., acc -l -e -le Same as -l -e - -p|--parse [ ]|[file to parse] Helps find potential charging switches quickly, for any device + -n|--notif [["STRING" (default: ":)")] [USER ID (default: 2000 (shell))]] Post Android notification; may not work on all systems + e.g., acc -n "Hello, World!" + + -p|--parse [ ] | ] Helps find potential charging switches quickly, for any device e.g., acc -p Parse $dataDir/logs/power_supply-\*.log and print potential charging switches not present in $TMPDIR/ch-switches acc -p /sdcard/power_supply-harpia.log Parse the given file and print potential charging switches that are not already in $TMPDIR/ch-switches @@ -192,7 +199,13 @@ Options acc -s charging_switch= acc -s pause_capacity=60 resume_capacity=55 (shortcuts: acc -s pc=60 rc=55, acc 60 55) acc -s "charging_switch=battery/charging_enabled 1 0" resume_capacity=55 pause_capacity=60 - Note: all properties have short aliases for faster typing; run "acc -c cat" to see these + Note: all properties have short aliases for faster typing; run "acc -c cat" to see them + + -s|--set [sd|sched]="[+-]schedule to add or pattern to delete" + e.g., + acc -s sd=-2050 (delete schedules that match 2050) + acc -s sd="+2200 acc -s mcv=3900 mcc=500; acc -n "Switched to \"sleep\" profile" (append schedule) + Note: "acc -s sd=" behaves just like similar commands (restores default value; for schedules, it's null) -s|--set c|--current [milliamps|-] Set/print/restore_default max charging current (range: 0-9999$(print_mA)) e.g., @@ -218,12 +231,12 @@ Options -sp [egrep regex (default: ".")] Same as above - -s|--set r|--reset Restore default config + -s|--set r|--reset [a] Restore default config ("a" is for "all": config and control file blacklists, essentially a hard reset) e.g., acc -s r - rm /data/adb/vr25/acc-data/config.txt (failsafe) - -sr Same as above + -sr [a] Same as above + -s|--set s|charging_switch Enforce a specific charging switch e.g., acc -s s @@ -238,9 +251,9 @@ Options -s|--set v|--voltage [millivolts|-] [--exit] Set/print/restore_default max charging voltage (range: 3700-4300$(print_mV)) e.g., acc -s v (print) - acc -s v 3920 (set) + acc -s v 3900 (set) acc -s v - (restore default) - acc -s v 3920 --exit (stop the daemon after applying settings) + acc -s v 3900 --exit (stop the daemon after applying settings) -sv [millivolts|-] [--exit] Same as above @@ -249,16 +262,19 @@ Options acc -t battery/charging_enabled 1 0 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 panic are automatically backlisted + -t|--test [file] Test charging switches from a file (default: $TMPDIR/ch-switches) e.g., acc -t (test known switches) acc -t /sdcard/experimental_switches.txt (test custom/foreign switches) + -t|--test [p|parse] Parse potential charging switches from the power supply log (as "acc -p"), test them all, and add the working ones to the list of known switches + Implies -x, as acc -x -t p + e.g., acc -t p + -T|--logtail Monitor accd log (tail -F) e.g., acc -T - -u|--upgrade [-c|--changelog] [-f|--force] [-k|--insecure] [-n|--non-interactive] Online upgrade/downgrade (requires curl) + -u|--upgrade [-c|--changelog] [-f|--force] [-k|--insecure] [-n|--non-interactive] Online upgrade/downgrade e.g., acc -u dev (upgrade to the latest dev version) acc -u (latest version from the current branch) @@ -296,11 +312,12 @@ Exit Codes 10. All charging switches fail (--test) 11. Current (mA) out of 0-9999 range 12. Initialization failed - 13. Failed to lock /dev/.vr25/acc/acc.lock + 13. Failed to lock $TMPDIR/acc.lock 14. ACC won't initialize, because the Magisk module disable flag is set 15. Idle mode is supported (--test) + 16. Failed to enable charging (--test) - Logs are exported automatically ("--log --export") on exit codes 1, 2, 7 and 10. + Logs are exported automatically ("--log --export") on exit codes 1, 2 and 7. Tips @@ -310,8 +327,8 @@ Tips acc -e 30m && acc -d 6h && acc -e 85 && accd Sample profile - acc -s pc=45 rc=43 mcc=500 mcv=3920 - This keeps battery capacity between 43-45%, limits charging current to 500 mA and voltage to 3920 millivolts. + acc -s pc=45 rc=43 mcc=500 mcv=3900 + This keeps battery capacity between 43-45%, limits charging current to 500 mA and voltage to 3900 millivolts. It's great for nighttime and "forever-plugged". Refer to acc -r (or --readme) for the full documentation (recommended) @@ -336,45 +353,45 @@ print_default() { } print_quit() { - echo "(i) Press $1 to abort/quit" + echo "Press $1 to quit" [ -z "${2-}" ] || echo "- Or $2 to save and quit" } print_curr_restored() { - echo "(i) Default max charging current restored" + echo "Default max charging current restored" } print_volt_restored() { - echo "(i) Default max charging voltage restored" + echo "Default max charging voltage restored" } print_read_curr() { - echo "(i) Need to read default max charging current value(s) first" + echo "Need to read default max charging current value(s) first" } print_curr_set() { - echo "(i) Max charging current set to $1$(print_mA)" + echo "Max charging current set to $1$(print_mA)" } print_volt_set() { - echo "(i) Max charging voltage set to $1$(print_mV)" + echo "Max charging voltage set to $1$(print_mV)" } print_wip() { - echo "(!) Invalid option" - echo "- Run acc -h or -r for help" + echo "Invalid option" + echo "- Run acc -h or -r for help " } print_press_key() { - printf "(i) Press any key to continue..." + printf "Press any key to continue..." } print_lang() { - echo "Language" + echo "Language 🌐" } print_doc() { - echo "Documentation" + echo "Documentation 📘" } print_cmds() { @@ -382,11 +399,11 @@ print_cmds() { } print_re_start_daemon() { - echo "Start/restart daemon" + echo "Start/restart daemon ▶️ 🔁" } print_stop_daemon() { - echo "Stop daemon" + echo "Stop daemon ⏹️" } print_export_logs() { @@ -430,7 +447,7 @@ print_test_cs() { } print_update() { - echo "Check for update" + echo "Check for update 🔃" } print_W() { @@ -442,7 +459,7 @@ print_V() { } print_available() { - echo "(i) $@ is available" + echo "$@ is available" } print_install_prompt() { @@ -450,7 +467,7 @@ print_install_prompt() { } print_no_update() { - echo "(i) No update available" + echo "No update available" } print_A() { @@ -462,11 +479,11 @@ print_only() { } print_wait() { - echo "(i) This may take a minute or so..." + echo "This may take a while... ⏳" } print_as_warning() { - echo "WARNING: I'll shutdown the system at ${1}% battery if you don't plug the charger!" + echo "⚠️ WARNING: I'll shutdown the system at ${1}% battery if you don't plug the charger!" } print_i() { @@ -478,11 +495,31 @@ print_undo() { } print_blacklisted() { - echo "(i) [$@] is blacklisted; won't be tested" + echo " Switch is blacklisted; won't be tested 🚫" } + print_acct_info() { - echo "(i) Results may vary with different power supplies and conditions, as stated in README.md -- TROUBLESHOOTING. -To set charging switches, run acc -ss (wizard) or acc -s s=\"SWITCHES GO HERE --\"." - [ -n "${1-}" ] && printf '"battIdleMode" refers to the ability of running off the charger.\n\n' || echo + echo " +💡Notes/Tips: + + - Some switches -- notably those that control current and voltage -- are prone to inconsistencies. If a switch works at least twice, assume it's functional. + + - Results may vary with different power supplies and conditions, as stated in \"readme > troubleshooting > charging switch\". + + - Want to test all potential switches? \"acc -t p\" parses them from the power supply log (as \"acc -p\"), tests all, and adds the working ones to the list of known switches. + + - To set charging switches, run acc -ss (wizard) or acc -s s=\"switches go here --\". + + - idleMode: whether the device can run directly off the charger. + + - The output of this command is saved to /sdcard/Download/acc-t_output.txt." +} + + +print_panic() { + printf "\nWARNING: experimental feature, dragons ahead! +Some problematic control files are blacklisted automatically, based on known patterns. +Do you want to see/edit the list of potential switches before testing? +a: abort operation | n: no | y: yes (default) " } diff --git a/acc/translations/de-DE/README.md b/install/translations/de-DE/README.md similarity index 100% rename from acc/translations/de-DE/README.md rename to install/translations/de-DE/README.md diff --git a/acc/translations/de-DE/strings.sh b/install/translations/de-DE/strings.sh similarity index 84% rename from acc/translations/de-DE/strings.sh rename to install/translations/de-DE/strings.sh index 2eac004..3934075 100644 --- a/acc/translations/de-DE/strings.sh +++ b/install/translations/de-DE/strings.sh @@ -1,83 +1,83 @@ # German (de_DE) print_already_running() { - echo "(i) accd läuft bereits" + echo "accd läuft bereits" } print_started() { - echo "(i) accd gestartet" + echo "accd gestartet" } print_stopped() { - echo "(i) accd gestoppt" + echo "accd gestoppt" } print_not_running() { - echo "(i) accd läuft nicht" + echo "accd läuft nicht" } print_restarted() { - echo "(i) accd neugestartet" + echo "accd neugestartet" } print_is_running() { - echo "(i) accd $1 läuft $2" + echo "accd $1 läuft $2" } print_config_reset() { - echo "(i) Konfiguration zurückgesetzt" + echo "Konfiguration zurückgesetzt" } print_switch_fails() { - echo "(!) [${chargingSwitch[@]-}] funktioniert nicht" + echo "[${chargingSwitch[@]-}] funktioniert nicht" } print_invalid_switch() { - echo "(!) Ungültiger Ladeschalter, [${chargingSwitch[@]-}]" + echo "Ungültiger Ladeschalter, [${chargingSwitch[@]-}]" } print_charging_disabled_until() { - echo "(i) Ladevorgang deaktiviert, bis die Batteriekapazität >= $1 entspricht" + echo "Ladevorgang deaktiviert, bis die Batteriekapazität >= $1 entspricht" } print_charging_disabled_for() { - echo "(i) Laden deaktiviert für $1" + echo "Laden deaktiviert für $1" } print_charging_disabled() { - echo "(i) Laden deaktiviert" + echo "Laden deaktiviert" } print_charging_enabled_until() { - echo "(i) Ladevorgang aktiviert, bis die Batteriekapazität >= $1 entspricht" + echo "Ladevorgang aktiviert, bis die Batteriekapazität >= $1 entspricht" } print_charging_enabled_for() { - echo "(i) Laden aktiviert für $1" + echo "Laden aktiviert für $1" } print_charging_enabled() { - echo "(i) Laden aktiviert" + echo "Laden aktiviert" } print_unplugged() { - echo "(!) Das Ladegerät muss eingesteckt sein, um fortzufahren..." + echo "Das Ladegerät muss eingesteckt sein, um fortzufahren..." } print_switch_works() { - echo "(i) [$@] funktioniert" + echo "[$@] funktioniert" } print_switch_fails() { - echo "(!) [$@] funktioniert nicht" + echo "[$@] funktioniert nicht" } print_no_ctrl_file() { - echo "(!) Keine Kontroll-Datei gefunden" + echo "Keine Kontroll-Datei gefunden" } print_not_found() { - echo "(!) $1 nicht gefunden" + echo "$1 nicht gefunden" } @@ -143,7 +143,7 @@ z.B., acc -l -a cat acc -l grep ': ' (zeigt nur explizite Fehler an) -la Dasselbe wie -l -a - -l|--log -e|--export Alle Protokolle nach /sdcard/Documents/vr25/acc/logs/acc-logs-\$deviceName.tar.gz exportieren + -l|--log -e|--export Alle Protokolle nach $dataDir/logs/acc-logs-\$deviceName.tgz exportieren z.B., acc -l -e -le Dasselbe wie -l -e -r|--readme [editor] [editor_opts] README.md anzeigen/bearbeiten @@ -190,9 +190,9 @@ z.B., -s|--set v|--voltage [millivolts|-] [--exit] Maximale Ladespannung setzen/drucken/wiederherstellen (Bereich: 3700-4200$(print_mV)) z.B., acc -s v (ausgeben) - acc -s v 3920 (setzen) + acc -s v 3900 (setzen) acc -s v - (Voreinstellung wiederherstellen) - acc -s v 3920 --exit (stoppt den Daemon nach Übernahme der Einstellungen) + acc -s v 3900 --exit (stoppt den Daemon nach Übernahme der Einstellungen) -sv [millivolts|-] [--exit] Wie oben -t|--test [ctrl_file1 an aus [ctrl_file2 an aus]] Benutzerdefinierte Ladeschalter testen z.B., @@ -205,8 +205,8 @@ z.B., acc -t /sdcard/experimental_switches.txt (testet eigene/fremde Schalter) -T|--logtail Überwachung des accd-Protokolls (tail -F) z.B., acc -T - -u|--upgrade [-c|--changelog] [-f|--force] [-k|--insecure] [-n|--non-interactive] Online-Upgrade/Downgrade (erfordert curl) -z.B., + -u|--upgrade [-c|--changelog] [-f|--force] [-k|--insecure] [-n|--non-interactive] Online-Upgrade/Downgrade + z.B., acc -u dev (Upgrade auf die neueste Entwicklungsversion) acc -u (letzte Version aus dem aktuellen Zweig) acc -u master^1 -f (vorherige stabile Version) @@ -244,8 +244,8 @@ Tipps: z.B. 30 Minuten laden, Ladepause für 6 Stunden, auf 85% laden und den Daemon neu starten acc -e 30m && acc -d 6h && acc -e 85 && accd Beispielprofil - acc -s pc=45 rc=43 mcc=500 mcv=3920 - Dies hält die Batteriekapazität zwischen 43-45 %, begrenzt den Ladestrom auf 500 mA und die Spannung auf 3920 Millivolt. + acc -s pc=45 rc=43 mcc=500 mcv=3900 + Dies hält die Batteriekapazität zwischen 43-45 %, begrenzt den Ladestrom auf 500 mA und die Spannung auf 3900 Millivolt. Das ist ideal für die Nacht und für "ewig-angeschlossen". Siehe acc -r (oder --readme) für die vollständige Dokumentation (empfohlen) EOF @@ -270,37 +270,37 @@ print_default() { } print_quit() { - echo "(i) Drücke $1 um abzubrechen/beenden" + echo "Drücke $1 um abzubrechen/beenden" [ -z "${2-}" ] || echo "- Oder $2 um speichern und dann schließen" } print_curr_restored() { - echo "(i) Voreingestellter maximaler Ladestrom wiederhergestellt" + echo "Voreingestellter maximaler Ladestrom wiederhergestellt" } print_volt_restored() { - echo "(i) Voreingestellte maximale Ladespannung wiederhergestellt" + echo "Voreingestellte maximale Ladespannung wiederhergestellt" } print_read_curr() { - echo "(i) Der Standardwert für den maximalen Ladestrom muss zuerst gelesen werden" + echo "Der Standardwert für den maximalen Ladestrom muss zuerst gelesen werden" } print_curr_set() { - echo "(i) Maximaler Ladestrom auf $1$(print_mA) gesetzt" + echo "Maximaler Ladestrom auf $1$(print_mA) gesetzt" } print_volt_set() { - echo "(i) Maximale Ladespannung eingestellt auf $1$(print_mV)" + echo "Maximale Ladespannung eingestellt auf $1$(print_mV)" } print_wip() { - echo "(!) Ungültige Option" + echo "Ungültige Option" echo "- Für Hilfe acc -h oder -r ausführen" } print_press_key() { - printf "(i) Drücken Sie eine beliebige Taste, um fortzufahren..." + printf "Drücken Sie eine beliebige Taste, um fortzufahren..." } print_lang() { @@ -376,7 +376,7 @@ print_V() { } print_available() { - echo "(i) $@ ist verfügbar" + echo "$@ ist verfügbar" } print_install_prompt() { @@ -384,7 +384,7 @@ print_install_prompt() { } print_no_update() { - echo "(i) Kein Update verfügbar" + echo "Kein Update verfügbar" } print_A() { @@ -396,9 +396,9 @@ print_only() { } print_m_mode() { - echo "(i) Manueller Modus" + echo "Manueller Modus" } print_wait() { - echo "(i) Gut, das kann eine Minute oder so dauern..." + echo "Gut, das kann eine Minute oder so dauern..." } diff --git a/acc/translations/id/strings.sh b/install/translations/id/strings.sh similarity index 61% rename from acc/translations/id/strings.sh rename to install/translations/id/strings.sh index 64f85a5..032ee22 100644 --- a/acc/translations/id/strings.sh +++ b/install/translations/id/strings.sh @@ -1,79 +1,79 @@ # Indonesia (id) print_already_running() { - echo "(i) accd sedang berjalan" + echo "accd sedang berjalan" } print_started() { - echo "(i) memulai accd" + echo "memulai accd" } print_stopped() { - echo "(i) accd berhenti" + echo "accd berhenti" } print_not_running() { - echo "(i) accd sedang tidak berjalan" + echo "accd sedang tidak berjalan" } print_restarted() { - echo "(i) memulai kembali accd" + echo "memulai kembali accd" } print_is_running() { - echo "(i) accd $1 sedang berjalan $2" + echo "accd $1 sedang berjalan $2" } print_config_reset() { - echo "(i) Mengatur ulang konfigurasi" + echo "Mengatur ulang konfigurasi" } print_invalid_switch() { - echo "(!) Saklar pengisi daya salah, [${chargingSwitch[@]-}]" + echo "Saklar pengisi daya salah, [${chargingSwitch[@]-}]" } print_charging_disabled_until() { - echo "(i) Pengisian daya di nonaktifkan sampai kapasitas baterai <= $1" + echo "Pengisian daya di nonaktifkan sampai kapasitas baterai <= $1" } print_charging_disabled_for() { - echo "(i) Pengisian daya di nonaktifkan untuk $1" + echo "Pengisian daya di nonaktifkan untuk $1" } print_charging_disabled() { - echo "(i) Pengisian daya di nonaktifkan" + echo "Pengisian daya di nonaktifkan" } print_charging_enabled_until() { - echo "(i) Pengisian daya aktif hingga kapasitas baterai >= $1" + echo "Pengisian daya aktif hingga kapasitas baterai >= $1" } print_charging_enabled_for() { - echo "(i) Pengisian daya aktif untuk $1" + echo "Pengisian daya aktif untuk $1" } print_charging_enabled() { - echo "(i) Pengisian daya aktif" + echo "Pengisian daya aktif" } print_unplugged() { - echo "(!) Sambungkan pengisi daya untuk melanjutkan..." + echo "Sambungkan pengisi daya untuk melanjutkan..." } print_switch_works() { - echo "(i) [$@] bekerja" + echo "[$@] bekerja" } print_switch_fails() { - echo "(!) [$@] tidak bekerja" + echo "[$@] tidak bekerja" } print_no_ctrl_file() { - echo "(!) Tidak ditemukan file untuk mengontrol" + echo "Tidak ditemukan file untuk mengontrol" } print_not_found() { - echo "(!) $1 tidak ditemukan" + echo "$1 tidak ditemukan" } print_exit() { @@ -93,37 +93,37 @@ print_default() { } print_quit() { - echo "(i) Tekan $1 untuk batal/keluar" + echo "Tekan $1 untuk batal/keluar" [ -z "${2-}" ] || echo "- Atau $2 untuk menyimpan dan keluar" } print_curr_restored() { - echo "(i) Maksimal pengisian daya bawaan dipulihkan" + echo "Maksimal pengisian daya bawaan dipulihkan" } print_volt_restored() { - echo "(i) Maksimal voltase bawaan dipulihkan" + echo "Maksimal voltase bawaan dipulihkan" } print_read_curr() { - echo "(i) Perlu membaca pengisian daya bawaan" + echo "Perlu membaca pengisian daya bawaan" } print_curr_set() { - echo "(i) Pengisian daya maksimal diatur ke $1$(print_mA)" + echo "Pengisian daya maksimal diatur ke $1$(print_mA)" } print_volt_set() { - echo "(i) Voltase maksimal diatur ke $1$(print_mV)" + echo "Voltase maksimal diatur ke $1$(print_mV)" } print_wip() { - echo "(!) Opsi salah" + echo "Opsi salah" echo "- Jalankan acc -h or -r untuk informasi lebih lanjut" } print_press_key() { - printf "(i) Tekan tombol apa saja untuk melanjutkan..." + printf "Tekan tombol apa saja untuk melanjutkan..." } print_lang() { @@ -199,7 +199,7 @@ print_V() { } print_available() { - echo "(i) $@ sudah tersedia" + echo "$@ sudah tersedia" } print_install_prompt() { @@ -207,7 +207,7 @@ print_install_prompt() { } print_no_update() { - echo "(i) Tidak ada pembaruan" + echo "Tidak ada pembaruan" } print_A() { @@ -219,5 +219,5 @@ print_only() { } print_wait() { - echo "(i) Baik, ini mungkin perlu waktu beberapa menit..." + echo "Baik, ini mungkin perlu waktu beberapa menit..." } diff --git a/acc/translations/pt-PT/README.md b/install/translations/pt-PT/README.md similarity index 100% rename from acc/translations/pt-PT/README.md rename to install/translations/pt-PT/README.md diff --git a/install/translations/pt-PT/strings.sh b/install/translations/pt-PT/strings.sh new file mode 100644 index 0000000..158d807 --- /dev/null +++ b/install/translations/pt-PT/strings.sh @@ -0,0 +1,125 @@ +# Português, Portugal (pt-PT) + +print_already_running() { + echo "accd já está em execução" +} + +print_started() { + echo "accd foi iniciado" +} + +print_stopped() { + echo "accd foi parado" +} + +print_not_running() { + echo "accd não está em execução" +} + +print_restarted() { + echo "accd foi reiniciado" +} + +print_is_running() { + echo "accd $1 está em execução $2" +} + +print_config_reset() { + echo "A configuração padrão foi restaurada" +} + +print_invalid_switch() { + echo "Interruptor de carga inválido, [${chargingSwitch[@]-}]" +} + +print_charging_disabled_until() { + echo "Recarga desativada até % <= $1" +} + +print_charging_disabled_for() { + echo "Recarga desativada por $1" +} + +print_charging_disabled() { + echo "Recarga desativada" +} + +print_charging_enabled_until() { + echo "Recarga ativada até % >= $1" +} + +print_charging_enabled_for() { + echo "Recarga ativada por $1" +} + +print_charging_enabled() { + echo "Recarga ativada" +} + +print_unplugged() { + echo "Conecte o carregador primeiro..." +} + +print_switch_works() { + echo "[$@] funciona" +} + +print_switch_fails() { + echo "[$@] não funciona" +} + +print_not_found() { + echo "$1 não encontrado" +} + +#print_help() { + +print_exit() { + echo "Sair" +} + +print_choice_prompt() { + echo "(?) Introduza um número e clique [enter]: " +} + +print_auto() { + echo "Automático" +} + +print_default() { + echo "Predefinição" +} + +print_quit() { + echo "Pressione $1 para sair/guardar" +} + +print_curr_restored() { + echo "Máxima corrente de recarga padrão restaurada" +} + +print_volt_restored() { + echo "Máxima voltagem padrão de recarga restaurada" +} + +print_read_curr() { + echo "Antes the prosseguir, o acc precisa obter os padrões máximos de corrente de recarga" + print_unplugged + echo -n "- À espera..." +} + +print_curr_set() { + echo "Máxima corrente de recarga definida para $1 miliamperes" +} + +print_volt_set() { + echo "Máxima voltagem de recarga definida para $1 milivolts" +} + +print_curr_range() { + echo "Apenas [$1] (miliamperes)" +} + +print_volt_range() { + echo "Apenas [$1] (milivolts)" +} diff --git a/acc/translations/zh-rCN/README.md b/install/translations/zh-rCN/README.md similarity index 100% rename from acc/translations/zh-rCN/README.md rename to install/translations/zh-rCN/README.md diff --git a/acc/translations/zh-rCN/strings.sh b/install/translations/zh-rCN/strings.sh similarity index 54% rename from acc/translations/zh-rCN/strings.sh rename to install/translations/zh-rCN/strings.sh index 84b8697..6898edd 100644 --- a/acc/translations/zh-rCN/strings.sh +++ b/install/translations/zh-rCN/strings.sh @@ -1,71 +1,71 @@ # 简体中文 (zh-rCN) print_already_running() { - echo "(i) accd 已处于运行状态" + echo "accd 已处于运行状态" } print_started() { - echo "(i) accd 已启动" + echo "accd 已启动" } print_stopped() { - echo "(i) accd 已停止" + echo "accd 已停止" } print_not_running() { - echo "(i) accd 当前没有运行" + echo "accd 当前没有运行" } print_restarted() { - echo "(i) accd 已重启" + echo "accd 已重启" } print_is_running() { - echo "(i) accd $1 正在运行 $2" + echo "accd $1 正在运行 $2" } print_config_reset() { - echo "(i) 配置已重置" + echo "配置已重置" } print_invalid_switch() { - echo "(!) 无效充电开关, [${chargingSwitch[@]-}]" + echo "无效充电开关, [${chargingSwitch[@]-}]" } print_charging_disabled_until() { - echo "(i) 电量高于 $1 时停止充电" + echo "电量高于 $1 时停止充电" } print_charging_disabled_for() { - echo "(i) 停止充电 $1" + echo "停止充电 $1" } print_charging_disabled() { - echo "(i) 已停止充电" + echo "已停止充电" } print_charging_enabled_until() { - echo "(i) 电量高于 $1 时继续充电" + echo "电量高于 $1 时继续充电" } print_charging_enabled_for() { - echo "(i) 开始充电 $1" + echo "开始充电 $1" } print_charging_enabled() { - echo "(i) 已开始充电" + echo "已开始充电" } print_switch_works() { - echo "(i) [$@] 可用" + echo "[$@] 可用" } print_switch_fails() { - echo "(!) [$@] 不可用" + echo "[$@] 不可用" } print_not_found() { - echo "(!) 未找到 $1 目录" + echo "未找到 $1 目录" } #print_help() { diff --git a/acc/translations/zh-rTW/README.md b/install/translations/zh-rTW/README.md similarity index 100% rename from acc/translations/zh-rTW/README.md rename to install/translations/zh-rTW/README.md diff --git a/acc/translations/zh-rTW/strings.sh b/install/translations/zh-rTW/strings.sh similarity index 54% rename from acc/translations/zh-rTW/strings.sh rename to install/translations/zh-rTW/strings.sh index 544275a..1ea2ae5 100644 --- a/acc/translations/zh-rTW/strings.sh +++ b/install/translations/zh-rTW/strings.sh @@ -1,71 +1,71 @@ # 繁體中文 (zh-rTW) print_already_running() { - echo "(i) accd 目前是執行狀態" + echo "accd 目前是執行狀態" } print_started() { - echo "(i) accd 已啟動" + echo "accd 已啟動" } print_stopped() { - echo "(i) accd 已停止" + echo "accd 已停止" } print_not_running() { - echo "(i) accd 目前沒有執行" + echo "accd 目前沒有執行" } print_restarted() { - echo "(i) accd 以重啟" + echo "accd 以重啟" } print_is_running() { - echo "(i) accd $1 正在執行 $2" + echo "accd $1 正在執行 $2" } print_config_reset() { - echo "(i) 設定已重製" + echo "設定已重製" } print_invalid_switch() { - echo "(!) 無效的充電開關, [${chargingSwitch[@]-}]" + echo "無效的充電開關, [${chargingSwitch[@]-}]" } print_charging_disabled_until() { - echo "(i) 電量高於 $1 時停止充電" + echo "電量高於 $1 時停止充電" } print_charging_disabled_for() { - echo "(i) 停止充電 $1" + echo "停止充電 $1" } print_charging_disabled() { - echo "(i) 已停止充電" + echo "已停止充電" } print_charging_enabled_until() { - echo "(i) 電量高於 $1 時繼續充電" + echo "電量高於 $1 時繼續充電" } print_charging_enabled_for() { - echo "(i) 開始充電 $1" + echo "開始充電 $1" } print_charging_enabled() { - echo "(i) 已開始充電" + echo "已開始充電" } print_switch_works() { - echo "(i) [$@] 可用" + echo "[$@] 可用" } print_switch_fails() { - echo "(!) [$@] 不可用" + echo "[$@] 不可用" } print_not_found() { - echo "(!) 未找到 $1 目錄" + echo "未找到 $1 目錄" } #print_help() { diff --git a/acc/uninstall.sh b/install/uninstall.sh similarity index 91% rename from acc/uninstall.sh rename to install/uninstall.sh index 7878515..8ff52d7 100644 --- a/acc/uninstall.sh +++ b/install/uninstall.sh @@ -1,7 +1,7 @@ #!/sbin/sh # $id uninstaller # id is set/corrected by build.sh -# Copyright 2019-2021, VR25 +# Copyright 2019-2022, VR25 # License: GPLv3+ # # devs: triple hashtags (###) mark non-generic code @@ -13,7 +13,7 @@ export TMPDIR=/dev/.$domain/$id # set up busybox #BB# -bin_dir=/data/adb/bin +bin_dir=/data/adb/vr25/bin busybox_dir=/dev/.vr25/busybox magisk_busybox=/data/adb/magisk/busybox [ -x $busybox_dir/ls ] || { @@ -27,7 +27,7 @@ magisk_busybox=/data/adb/magisk/busybox } done [ -x $busybox_dir/ls ] || { - echo "(!) Install busybox or simply place it in $bin_dir/" + echo "Install busybox or simply place it in $bin_dir/" echo exit 3 } @@ -47,7 +47,7 @@ mkdir -p $TMPDIR read pid kill $pid #timeout 20 flock 0 || kill -KILL $pid - echo "(i) If this seems to take too long, plug the charger" + echo "If this seems to be taking too long, plug the charger" flock 0 }) <>$TMPDIR/${id}.lock ### diff --git a/acc/wizard.sh b/install/wizard.sh similarity index 98% rename from acc/wizard.sh rename to install/wizard.sh index 4be4666..7fe52d8 100644 --- a/acc/wizard.sh +++ b/install/wizard.sh @@ -70,7 +70,7 @@ g) $(print_exit) 7) clear echo - echo -n "(i) " + echo -n "" print_1shot echo print_quit CTRL-C diff --git a/acc/write-config.sh b/install/write-config.sh similarity index 62% rename from acc/write-config.sh rename to install/write-config.sh index 7c3b58a..9ecaacb 100644 --- a/acc/write-config.sh +++ b/install/write-config.sh @@ -21,6 +21,7 @@ cp=${cooldown_pause-${cp-${cooldownRatio[1]}}} rbsp=${reset_batt_stats_on_pause-${rbsp-${resetBattStats[0]}}} rbsu=${reset_batt_stats_on_unplug-${rbsu-${resetBattStats[1]}}} +rbspl=${reset_batt_stats_on_plug-${rbspl-${resetBattStats[2]}}} s="${charging_switch-${s-${chargingSwitch[@]}}}" @@ -43,30 +44,84 @@ pbim=${prioritize_batt_idle_mode-${pbim-$prioritizeBattIdleMode}} cw=${current_workaround-${cw-$currentWorkaround}} +bsw=${batt_status_workaround-${bsw-$battStatusWorkaround}} + +sd=${sched-${sd-$schedule}} + +bso="${batt_status_override-${bso-$battStatusOverride}}" + +rr="${reboot_resume-${rr-$rebootResume}}" + + +# schedule -- append/delete +case "$sd" in + +*) + sd="${schedule-} +${sd#+}" + sd="$(echo "$sd" | sed '/^$/d')" + ;; + -*) + sd="$(echo "${schedule-}" | sed "\%${sd#-}%d")" + ;; +esac + + +# enforce valid pc and rc difference +[ $rc -lt $pc ] || { + [ $pc -gt 3000 ] && rc=$((pc - 50)) || rc=$((pc - 5)) +} + + +# backup scripts +! grep '^: ' $config > $TMPDIR/.scripts 2>/dev/null && echo > $TMPDIR/.scripts || { + sed -i '/: one-line script sample/d; /:/s/$/\n/' $TMPDIR/.scripts + echo >> $TMPDIR/.scripts +} + -{ echo "configVerCode=$(cat $TMPDIR/.config-ver) + capacity=(${sc:--1} ${cc:-60} ${rc:-70} ${pc:-75} ${cs:-false} ${cm:-false}) + temperature=(${ct:-40} ${mt:-60} ${mtp:-90} ${st:-65}) + cooldownRatio=($cch $cp) cooldownCurrent=$cdc cooldownCustom=($ccu) -resetBattStats=(${rbsp:-false} ${rbsu:-false}) + +resetBattStats=(${rbsp:-false} ${rbsu:-false} ${rbspl:-false}) + chargingSwitch=($(echo "$s" | sed 's/ m[AV]//')) + applyOnBoot=($ab) + applyOnPlug=($ap) + maxChargingCurrent=($mcc) + maxChargingVoltage=($mcv) -language=${lang:-en} -runCmdOnPause=($rcp) + +language=$lang + +runCmdOnPause='$rcp' + ampFactor=$af voltFactor=$vf -loopCmd=($lc) + +loopCmd='$lc' + prioritizeBattIdleMode=${pbim:-false} currentWorkaround=${cw:-false} +battStatusWorkaround=${bsw:-true} + +schedule='$sd' + +battStatusOverride='$bso' + +rebootResume=${rr:-false} -" -cat $TMPDIR/.config-help -} > $config +: one-line script sample; echo nothing >/dev/null +" > $config +cat $TMPDIR/.scripts $TMPDIR/.config-help >> $config set -u diff --git a/module.json b/module.json index a5ed635..c575191 100644 --- a/module.json +++ b/module.json @@ -2,9 +2,9 @@ "busybox": "https://github.com/Magisk-Modules-Repo/busybox-ndk", "changelog": "https://raw.githubusercontent.com/VR-25/acc/master/changelog.md", "curl": "https://github.com/Zackptg5/Cross-Compiled-Binaries-Android/tree/master/curl", - "tgz": "https://github.com/VR-25/acc/releases/download/v2022.2.22.1/acc_v2022.2.22.1_202202221.tgz", - "tgzInstaller": "https://github.com/VR-25/acc/releases/download/v2022.2.22.1/install-tarball.sh", - "version": "v2022.2.22.1", - "versionCode": 202202221, - "zipUrl": "https://github.com/VR-25/acc/releases/download/v2022.2.22.1/acc_v2022.2.22.1_202202221.zip" + "tgz": "https://github.com/VR-25/acc/releases/download/v2022.6.4/acc_v2022.6.4_202206040.tgz", + "tgzInstaller": "https://github.com/VR-25/acc/releases/download/v2022.6.4/install-tarball.sh", + "version": "v2022.6.4", + "versionCode": 202206040, + "zipUrl": "https://github.com/VR-25/acc/releases/download/v2022.6.4/acc_v2022.6.4_202206040.zip" } diff --git a/module.prop b/module.prop index 96100da..6e0845d 100644 --- a/module.prop +++ b/module.prop @@ -1,8 +1,8 @@ id=acc domain=vr25 name=Advanced Charging Controller (ACC) -version=v2022.2.22.1 -versionCode=202202221 +version=v2022.6.4 +versionCode=202206040 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. Regardless of whether the system is rooted with Magisk, the installation is always "systemless". updateJson=https://raw.githubusercontent.com/VR-25/acc/master/module.json