Skip to content

Commit

Permalink
Misc charging control fixes and optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
VR-25 committed Jul 19, 2022
1 parent d74a647 commit 423fadb
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 41 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ In interactive mode, it also asks the user whether they want to download and ins
```
#DC#
configVerCode=202207180
configVerCode=202207191
capacity=(-1 60 70 75 false false)
Expand Down Expand Up @@ -1174,7 +1174,7 @@ Refer back to the [warnings](#warnings) section above.
### Unexpected Reboots

Wrong/troublesome charging control files may trigger unwanted reboots.
ACC blacklist these automatically (registered in `/data/adb/vr25/acc-data/logs/write.log`, with a leading hashtag).
ACC blacklist some of these automatically (registered in `/data/adb/vr25/acc-data/logs/write.log`, with a leading hashtag).
Sometimes, there may be false positives in there - i.e., due to unexpected reboots caused by something else. Thus, if a control file that used to work, suddenly does not, see if it was blacklisted (`acc -t` also reveals blacklisted switches).
Send `write.log` to the developer once the reboots have stopped.

Expand Down
6 changes: 3 additions & 3 deletions install/acc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,14 @@ case "${1-}" in
echo "#!/system/bin/sh
sleep 2
exec $TMPDIR/accd $config_" > $TMPDIR/.accdt
chmod +x $TMPDIR/.accdt
chmod u+x $TMPDIR/.accdt
}

. $execDir/acquire-lock.sh

grep -Ev '^$|^#' $config > $TMPDIR/.config
config=$TMPDIR/.config

set +e
exxit() {
[ -z "$parsed" ] || {
cat $TMPDIR/ch-switches $_parsed 2>/dev/null > $parsed \
Expand All @@ -512,8 +511,9 @@ case "${1-}" in
! $daemonWasUp || start-stop-daemon -bx $TMPDIR/.accdt -S --
exit $exitCode
}
trap exxit EXIT

set +e
trap exxit EXIT
not_charging && enable_charging > /dev/null

not_charging && {
Expand Down
2 changes: 1 addition & 1 deletion install/accd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ else

# prepare bg-dexopt-job wrapper
printf "#!/system/bin/sh\n/system/bin/cmd package bg-dexopt-job < /dev/null > /dev/null 2>&1" > $TMPDIR/.bg-dexopt-job.sh
chmod +x $TMPDIR/.bg-dexopt-job.sh
chmod u+x $TMPDIR/.bg-dexopt-job.sh

# start $id daemon
rm $TMPDIR/.ghost-charging 2>/dev/null
Expand Down
11 changes: 6 additions & 5 deletions install/batt-interface.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
idle_discharging() {
[ $curThen != null ] && [ ${curNow#-} -le $idleThreshold ] && _status=Idle || {
[ $_status != Discharging ] || return 0
case "${dischargePolarity-}" in
+) [ $curNow -ge 0 ] && _status=Discharging || _status=Charging;;
-) [ $curNow -lt 0 ] && _status=Discharging || _status=Charging;;
Expand All @@ -14,9 +15,9 @@ idle_discharging() {
not_charging() {

local i=
local nci=${nci:-5}
local switch=${flip-}; flip=
local curThen=$(cat $curThen)
local nci=${nci:-7}
local battStatusOverride="${battStatusOverride-}"
local battStatusWorkaround=${battStatusWorkaround-}

Expand Down Expand Up @@ -48,8 +49,8 @@ online() {
read_status() {
local status="$(cat $battStatus)"
case "$status" in
Charging|Discharging) printf %s $status;;
Not?charging) printf Idle;;
*Charging*) printf Charging;;
*Not*) printf Idle;;
*) printf Discharging;;
esac
}
Expand All @@ -76,7 +77,7 @@ status() {

_status=$(read_status)

[ -z "${exitCode_-}" ] || echo " switch:${switch:-on} status:$_status curr:$curThen,$curNow"
[ -z "${exitCode_-}" ] || echo " switch_state:${switch:-on} batt_status:$_status current_on_off:$curThen,$curNow"

if [ -n "${battStatusOverride-}" ]; then
if tt "$battStatusOverride" "Discharging|Idle"; then
Expand Down Expand Up @@ -143,7 +144,7 @@ if ${init:-false}; then
}


idleThreshold=95 # mA
idleThreshold=25 # mA
ampFactor=$(sed -n 's/^ampFactor=//p' $dataDir/config.txt 2>/dev/null || :)
ampFactor_=${ampFactor:-1000}

Expand Down
2 changes: 1 addition & 1 deletion install/default-config.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configVerCode=202207180
configVerCode=202207191

capacity=(-1 60 70 75 false false)

Expand Down
33 changes: 8 additions & 25 deletions install/misc-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,7 @@ notif() {


parse_value() {
local i=
case $1 in
*/*) i="$(sed 's/ /::/g' $1 2>/dev/null || :)"; [ -z "$i" ] || echo $i;;
*) echo $1;;
esac
[ -f "$1" ] && cat $1 || echo "$1" | sed 's/::/ /g'
}


Expand Down Expand Up @@ -406,31 +402,19 @@ wait_plug() {


write() {
local i=
local i=y
local l=$dataDir/logs/write.log
local s=
local f=$TMPDIR/.unblacklist.$(date +%s)
blacklisted=false
[ -f "$2" ] && chmod u+w "$2" || return ${3-1}
s="$(grep -E "^(#$2|$2)$" $l 2>/dev/null || :)"
case "$s" in
case "$(grep -E "^(#$2|$2)$" $l 2>/dev/null || :)" in
\#*) blacklisted=true; return ${3-1};;
"") echo "#$2" >> $l; s=x;;
*/*) eval echo "$1" > "$2" || return ${3-1};;
*) echo \#$2 >> $l
eval echo "$1" > "$2" || i=x
sed -i "s|^#$2$|$2|" $l
[ $i = y ] || return ${3-1};;
esac
for i in 1 2; do
eval echo "$1" > "$2" || { i=x; break; }
sleep 0.5
done
[ $s != x ] || {
echo "#!/system/bin/sh
sleep 15
sed -i \"\|^#$2$|s|^#||\" $l
rm $f
exit" > $f
chmod u+x $f
start-stop-daemon -bx $f -S --
}
[ $i != x ] || return ${3-1}
}


Expand Down Expand Up @@ -459,7 +443,6 @@ trap exxit EXIT
device=$(getprop ro.product.device | grep .. || getprop ro.build.product)

cd /sys/class/power_supply/

. $execDir/batt-interface.sh

# cmd and dumpsys wrappers for Termux and recovery
Expand Down
2 changes: 1 addition & 1 deletion install/oem-custom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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 202207170 ]; then
if [ $configVer -lt 202207191 ]; then
rm $dataDir/logs/write.log 2>/dev/null || :
sed -i '/^: one-line script sample/d' $config
$TMPDIR/acca --set force_off=false
Expand Down
4 changes: 2 additions & 2 deletions install/strings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ print_acct_info() {

print_panic() {
printf "\nWARNING: experimental feature, dragons ahead!
Some problematic control files are excluded, based on known patterns.
Control files that trigger a reboot are automatically blacklisted.
Potentially problematic control files are excluded based on known patterns.
Some 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) "
}
Expand Down
2 changes: 1 addition & 1 deletion install/translations/fr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ Refer back to the [warnings](#warnings) section above.
### Unexpected Reboots

Wrong/troublesome charging control files may trigger unwanted reboots.
ACC blacklist these automatically (registered in `/data/adb/vr25/acc-data/logs/write.log`, with a leading hashtag).
ACC blacklist some of these automatically (registered in `/data/adb/vr25/acc-data/logs/write.log`, with a leading hashtag).
Sometimes, there may be false positives in there - i.e., due to unexpected reboots caused by something else. Thus, if a control file that used to work, suddenly does not, see if it was blacklisted (`acc -t` also reveals blacklisted switches).
Send `write.log` to the developer once the reboots have stopped.

Expand Down

0 comments on commit 423fadb

Please sign in to comment.