Skip to content

Commit

Permalink
Implement forceOff: for keeping stubborn switches off
Browse files Browse the repository at this point in the history
  • Loading branch information
VR-25 committed Jul 3, 2022
1 parent e2edbf7 commit 21f68d1
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ In interactive mode, it also asks the user whether they want to download and ins
```
#DC#
configVerCode=202206200
configVerCode=202207030
capacity=(-1 60 70 75 false false)
Expand Down Expand Up @@ -281,6 +281,8 @@ dischargePolarity=
offMid=true
forceOff=
: one-line script sample; echo nothing >/dev/null
Expand Down Expand Up @@ -370,6 +372,8 @@ offMid=true
# offMid=off_mid=boolean
# forceOff=force_off=int
# ALIASES/SHORTCUTS
Expand Down Expand Up @@ -422,6 +426,7 @@ offMid=true
# rr reboot_resume
# dp discharge_polarity
# om off_mid
# fo force_off
# FINE, BUT WHAT DOES EACH OF THESE VARIABLES ACTUALLY MEAN?
Expand Down Expand Up @@ -615,6 +620,11 @@ offMid=true
# off_mid (om) #
# Whether to turn off charging after rebooting or restarting accd, if capacity is within resume_capacity and pause_capacity (default: true).
# force_off (fo) #
# Repeatedly call "flip_sw off" after disabling charging, until enable_charging is called.
# This is needed when the set charging switch is stubbornly reset by the system.
# The value (integer == enabled, null == disabled) dictates the number of seconds to wait between "flip_sw off" calls. While decimals are supported, anything less than 1 is overkill. Probably the optimal value is somewhere between 2 and 5.
#/DC#
```

Expand Down
9 changes: 9 additions & 0 deletions install/accd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ if ! $init; then
echo "chargingSwitch=(${chargingSwitch[@]-})" > $TMPDIR/.sw)
else
disable_charging
[ -z "${forceOff-}" ] || {
touch $TMPDIR/.forceoff
set +x
while [ -f $TMPDIR/.forceoff ]; do
flip_sw off
sleep $forceOff
done &
set -x
}
fi
! ${resetBattStats[0]} || {
# reset battery stats on pause
Expand Down
12 changes: 11 additions & 1 deletion install/default-config.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configVerCode=202206200
configVerCode=202207030

capacity=(-1 60 70 75 false false)

Expand Down Expand Up @@ -43,6 +43,8 @@ dischargePolarity=

offMid=true

forceOff=

: one-line script sample; echo nothing >/dev/null


Expand Down Expand Up @@ -132,6 +134,8 @@ offMid=true

# offMid=off_mid=boolean

# forceOff=force_off=int


# ALIASES/SHORTCUTS

Expand Down Expand Up @@ -184,6 +188,7 @@ offMid=true
# rr reboot_resume
# dp discharge_polarity
# om off_mid
# fo force_off


# FINE, BUT WHAT DOES EACH OF THESE VARIABLES ACTUALLY MEAN?
Expand Down Expand Up @@ -376,3 +381,8 @@ offMid=true

# off_mid (om) #
# Whether to turn off charging after rebooting or restarting accd, if capacity is within resume_capacity and pause_capacity (default: true).

# force_off (fo) #
# Repeatedly call "flip_sw off" after disabling charging, until enable_charging is called.
# This is needed when the set charging switch is stubbornly reset by the system.
# The value (integer == enabled, null == disabled) dictates the number of seconds to wait between "flip_sw off" calls. While decimals are supported, anything less than 1 is overkill. Probably the optimal value is somewhere between 2 and 5.
2 changes: 2 additions & 0 deletions install/misc-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ dumpsys() { /system/bin/dumpsys "$@" || :; }

enable_charging() {

rm $TMPDIR/.forceoff 2>/dev/null || :

! not_charging || {

[ ! -f $TMPDIR/.sw ] || (. $TMPDIR/.sw; rm $TMPDIR/.sw; flip_sw on) 2>/dev/null || :
Expand Down
2 changes: 2 additions & 0 deletions install/print-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ reboot_resume=$rebootResume
discharge_polarity=$dischargePolarity
off_mid=$offMid
force_off=$forceOff
"

sed -n '/^: /p' $config
4 changes: 4 additions & 0 deletions install/write-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ dp="${discharge_polarity-${dp-$dischargePolarity}}"

om="${off_mid-${om-$offMid}}"

fo="${force_off-${fo-$forceOff}}"


# schedule -- append/delete
case "$sd" in
Expand Down Expand Up @@ -128,6 +130,8 @@ dischargePolarity=$dp
offMid=${om:-true}
forceOff=$fo
: one-line script sample; echo nothing >/dev/null
" > $config

Expand Down

0 comments on commit 21f68d1

Please sign in to comment.