diff --git a/README.md b/README.md index 4bd56b8..6e453d9 100644 --- a/README.md +++ b/README.md @@ -237,7 +237,7 @@ In interactive mode, it also asks the user whether they want to download and ins ``` #DC# -configVerCode=202207160 +configVerCode=202207170 capacity=(-1 60 70 75 false false) @@ -270,8 +270,6 @@ prioritizeBattIdleMode=false currentWorkaround=false battStatusWorkaround=true -schedule='' - battStatusOverride='' rebootResume=false @@ -284,8 +282,6 @@ forceOff= tempLevel=0 -: one-line script sample; echo nothing >/dev/null - # WARNINGS @@ -351,10 +347,6 @@ tempLevel=0 # battStatusWorkaround=batt_status_workaround=BOOLEAN -# schedule=sched='HHMM COMMAND... -# HHMM COMMAND... -# ...' NULLABLE - # battStatusOverride=batt_status_override=Idle|Discharging|'code to PRINT value for _status' NULLABLE # rebootResume=reboot_resume=BOOLEAN @@ -411,8 +403,6 @@ tempLevel=0 # cw current_workaround # bsw batt_status_workaround -# sd sched - # bso batt_status_override # rr reboot_resume # dp discharge_polarity @@ -554,29 +544,6 @@ tempLevel=0 # 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. @@ -602,6 +569,8 @@ tempLevel=0 # 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. +# One can schedule tasks with the following construct: +# : sleep profile; at 22:00 "acc -s pc=50 mcc=500 mcv=3900; acc -n 'Switched to night profile'" # off_mid (om) # # Whether to turn off charging after rebooting or restarting accd, if capacity is within resume_capacity and pause_capacity (default: true). @@ -682,6 +651,11 @@ Options acc -c less acc -c cat + -c|--config a|d string|regex Append (a) or delete (d) string/pattern to/from config + e.g., + acc -c a ": sleep profile; at 22:00 acc -s pc=50 mcc=500 mcv=3900" (append a schedule) + acc -c d sleep (remove all lines matching "sleep") + -d|--disable [#%, #s, #m, #h or #mv (optional)] Disable charging e.g., acc -d 70% (do not recharge until capacity <= 70%) @@ -762,12 +736,6 @@ Options 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 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., acc -s c (print current limit) @@ -886,9 +854,10 @@ Tips Commands can be chained for extended functionality. e.g., charge for 30 minutes, pause charging for 6 hours, charge to 85% and restart the daemon acc -e 30m && acc -d 6h && acc -e 85 && accd + One can take advantage of one-line scripts and the built-in "at" function to schedule profiles (refer back to -c|--config). Sample profile - acc -s pc=60 rc=55 mcc=500 mcv=3900 + acc -s pc=60 mcc=500 mcv=3900 This keeps battery capacity between 55-60%, limits charging current to 500 mA and voltage to 3900 millivolts. It's great for nighttime and "forever-plugged". diff --git a/install/acc.sh b/install/acc.sh index 697858f..da12411 100644 --- a/install/acc.sh +++ b/install/acc.sh @@ -100,7 +100,15 @@ edit() { local file="$1" shift if [ -n "${1-}" ]; then - IFS="$(printf ' \t\n')" eval "$* $file" + if [ "$1" = a ]; then + shift + echo >> $file + echo "$@" >> $file + elif [ "$1" = d ]; then + sed -Ei "\#$2#d" $file + else + IFS="$(printf ' \t\n')" eval "$* $file" + fi else ! ${verbose:-true} || { case $file in diff --git a/install/acca.sh b/install/acca.sh index 510b261..e57a214 100644 --- a/install/acca.sh +++ b/install/acca.sh @@ -1,9 +1,12 @@ #!/system/bin/sh # acca: acc for front-ends (faster and more efficient than acc) -# Copyright 2020, VR25 +# Copyright 2020-2022, VR25 # License: GPLv3+ +at() { :; } + + daemon_ctrl() { case "${1-}" in start|restart) diff --git a/install/accd.sh b/install/accd.sh index 815ad48..1f3068f 100644 --- a/install/accd.sh +++ b/install/accd.sh @@ -121,20 +121,7 @@ if ! $init; then capacitySync=false fi - # 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 - - set +x - eval '${loopCmd-}') || : + (set +eu; eval '${loopCmd-}') || : # shutdown if battery temp >= shutdown_temp [ $(cat $temp) -lt $(( ${temperature[3]} * 10 )) ] || shutdown diff --git a/install/default-config.txt b/install/default-config.txt index a14da3c..f018654 100644 --- a/install/default-config.txt +++ b/install/default-config.txt @@ -1,4 +1,4 @@ -configVerCode=202207160 +configVerCode=202207170 capacity=(-1 60 70 75 false false) @@ -31,8 +31,6 @@ prioritizeBattIdleMode=false currentWorkaround=false battStatusWorkaround=true -schedule='' - battStatusOverride='' rebootResume=false @@ -45,8 +43,6 @@ forceOff= tempLevel=0 -: one-line script sample; echo nothing >/dev/null - # WARNINGS @@ -112,10 +108,6 @@ tempLevel=0 # battStatusWorkaround=batt_status_workaround=BOOLEAN -# schedule=sched='HHMM COMMAND... -# HHMM COMMAND... -# ...' NULLABLE - # battStatusOverride=batt_status_override=Idle|Discharging|'code to PRINT value for _status' NULLABLE # rebootResume=reboot_resume=BOOLEAN @@ -172,8 +164,6 @@ tempLevel=0 # cw current_workaround # bsw batt_status_workaround -# sd sched - # bso batt_status_override # rr reboot_resume # dp discharge_polarity @@ -315,29 +305,6 @@ tempLevel=0 # 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. @@ -363,6 +330,8 @@ tempLevel=0 # 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. +# One can schedule tasks with the following construct: +# : sleep profile; at 22:00 "acc -s pc=50 mcc=500 mcv=3900; acc -n 'Switched to night profile'" # off_mid (om) # # Whether to turn off charging after rebooting or restarting accd, if capacity is within resume_capacity and pause_capacity (default: true). diff --git a/install/misc-functions.sh b/install/misc-functions.sh index 2f54ed5..f074dc1 100644 --- a/install/misc-functions.sh +++ b/install/misc-functions.sh @@ -49,6 +49,24 @@ apply_on_plug() { } +at() { + local one=$1 + local time=$(date +%H:%M) + local file=$TMPDIR/schedules/$one + shift + if [ ! -f $file ] && [ ${one#0} = ${time#0} ]; then + mkdir -p ${file%/*} + echo "#!/system/bin/sh + sleep 60 + rm $file + exit" > $file + chmod u+x $file + start-stop-daemon -bx $file -S -- + eval "$@" + fi +} + + calc() { awk "BEGIN {print $*}" | tr , . } diff --git a/install/oem-custom.sh b/install/oem-custom.sh index 0e9ef5e..fe88664 100644 --- a/install/oem-custom.sh +++ b/install/oem-custom.sh @@ -7,8 +7,9 @@ if (set +x; . $config) > /dev/null 2>&1; then configVer=0$(_get_prop configVerCode) defaultConfVer=0$(cat $TMPDIR/.config-ver) [ $configVer -eq $defaultConfVer ] || { - if [ $configVer -lt 202207160 ]; then + if [ $configVer -lt 202207170 ]; then rm $dataDir/logs/write.log 2>/dev/null || : + sed -i '/^: one-line script sample/d' $config $TMPDIR/acca --set force_off=false else $TMPDIR/acca --set dummy= diff --git a/install/print-config.sh b/install/print-config.sh index 5994e43..871f00d 100644 --- a/install/print-config.sh +++ b/install/print-config.sh @@ -45,8 +45,6 @@ prioritize_batt_idle_mode=$prioritizeBattIdleMode current_workaround=$currentWorkaround batt_status_workaround=$battStatusWorkaround -sched='$schedule' - batt_status_override='$battStatusOverride' reboot_resume=$rebootResume @@ -57,7 +55,6 @@ off_mid=$offMid force_off=$forceOff -temp_level=$tempLevel -" +temp_level=$tempLevel" -sed -n '/^: /p' $config +sed -n 's/^: /\n: /p' $config diff --git a/install/strings.sh b/install/strings.sh index 3a4cd02..7b21b93 100644 --- a/install/strings.sh +++ b/install/strings.sh @@ -123,6 +123,11 @@ Options acc -c less acc -c cat + -c|--config a|d string|regex Append (a) or delete (d) string/pattern to/from config + e.g., + acc -c a ": sleep profile; at 22:00 acc -s pc=50 mcc=500 mcv=3900" (append a schedule) + acc -c d sleep (remove all lines matching "sleep") + -d|--disable [#%, #s, #m, #h or #mv (optional)] Disable charging e.g., acc -d 70% (do not recharge until capacity <= 70%) @@ -203,12 +208,6 @@ Options 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 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., acc -s c (print current limit) @@ -327,9 +326,10 @@ Tips Commands can be chained for extended functionality. e.g., charge for 30 minutes, pause charging for 6 hours, charge to 85% and restart the daemon acc -e 30m && acc -d 6h && acc -e 85 && accd + One can take advantage of one-line scripts and the built-in "at" function to schedule profiles (refer back to -c|--config). Sample profile - acc -s pc=60 rc=55 mcc=500 mcv=3900 + acc -s pc=60 mcc=500 mcv=3900 This keeps battery capacity between 55-60%, limits charging current to 500 mA and voltage to 3900 millivolts. It's great for nighttime and "forever-plugged". @@ -523,7 +523,8 @@ print_acct_info() { print_panic() { printf "\nWARNING: experimental feature, dragons ahead! -Some problematic control files are blacklisted automatically, based on known patterns. +Some problematic control files are excluded, based on known patterns. +Control files that trigger a reboot are automatically blacklisted. Do you want to see/edit the list of potential switches before testing? a: abort operation | n: no | y: yes (default) " } @@ -534,6 +535,6 @@ print_resume() { Waiting for charging to resume... If it doesn't happen after a few seconds, try re-plugging the charger. If it's taking too long, unplug the charger, stop the test with CTRL-C, run accd -i, wait a few seconds, and retest. - In extreme cases, one shall comment out (blacklist) this switch in $dataDir/logs/write.log, reboot, and re-run the test. + In extreme cases, one shall comment out (blacklist) this switch in $dataDir/logs/write.log, reboot (to enable charging), and re-run the test. ##########" } diff --git a/install/write-config.sh b/install/write-config.sh index 808182e..4f33987 100644 --- a/install/write-config.sh +++ b/install/write-config.sh @@ -44,8 +44,6 @@ 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}}" @@ -59,17 +57,11 @@ fo="${force_off-${fo-$forceOff}}" tl="${temp_level-${tl-$tempLevel}}" -# schedule -- append/delete -case "$sd" in - +*) - sd="${schedule-} -${sd#+}" - sd="$(echo "$sd" | sed '/^$/d')" - ;; - -*) - sd="$(echo "${schedule-}" | sed "\%${sd#-}%d")" - ;; -esac +# backup scripts +touch $TMPDIR/.scripts +grep '^: ' $config > $TMPDIR/.scripts 2>/dev/null || : +sed -i 's/^: /\n: /' $TMPDIR/.scripts +printf "\n\n" >> $TMPDIR/.scripts # enforce valid pc and rc difference @@ -78,13 +70,6 @@ esac } -# 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}) @@ -118,8 +103,6 @@ prioritizeBattIdleMode=${pbim:-false} currentWorkaround=${cw:-false} battStatusWorkaround=${bsw:-true} -schedule='$sd' - battStatusOverride='$bso' rebootResume=${rr:-false} @@ -130,10 +113,8 @@ offMid=${om:-true} forceOff=${fo:-false} -tempLevel=${tl:-0} - -: one-line script sample; echo nothing >/dev/null -" > $config +tempLevel=${tl:-0}" > $config cat $TMPDIR/.scripts $TMPDIR/.config-help >> $config +rm $TMPDIR/.scripts set -u