From 2f92195a85c379653ad62acb15f9f6925c2dd84f Mon Sep 17 00:00:00 2001 From: VR-25 Date: Sun, 12 May 2019 01:33:11 +0100 Subject: [PATCH] **2019.5.12 (201905120)** - Autofix Termux SU PATH - Do not use Magic Mount; link everything to /sbin - Enforce Magisk's busybox to prevent issues caused by outdated binaries - Enhanced live upgrade; no more command prefix - Fixed bugs and typos - Removed nano from fallback editors list. - Updated build tools and info --- README.md | 43 +++++++++++++++------------------ build.sh | 2 +- common/MODPATH/acc | 35 +++++++++++++-------------- common/MODPATH/accd | 19 +++++++-------- common/MODPATH/accd-init | 2 ++ common/MODPATH/config.txt | 4 +-- common/MODPATH/psl | 5 ++-- common/MODPATH/system/xbin/acc | 2 -- common/MODPATH/system/xbin/accd | 2 -- common/post-fs-data.sh | 11 --------- common/service.sh | 24 ++++++++++++++++-- install.sh | 30 ++++++++++++++++++----- module.prop | 4 +-- 13 files changed, 100 insertions(+), 83 deletions(-) create mode 100644 common/MODPATH/accd-init delete mode 100644 common/MODPATH/system/xbin/acc delete mode 100644 common/MODPATH/system/xbin/accd delete mode 100644 common/post-fs-data.sh diff --git a/README.md b/README.md index 0a0f8fd..ca661bb 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ ACC is primarily intended for extending battery service life. On the flip side, Dependencies +- curl (optional) - git - zip @@ -92,7 +93,7 @@ Install - Flash live (e.g., from Magisk Manager) or from custom recovery (e.g., TWRP). -- ACC suports live upgrades. This means you don't need to reboot after installing/upgrading to be able to use it. However, after installing it for the first time, you have to prefix `acc` with `/dev/acc/modPath/` (e.g., /dev/acc/*/acc -D) to run it before a reboot. +- ACC suports live upgrades. This means you don't need to reboot after installing/upgrading to be able to use it. - The daemon is stopped before installation and restarted afterwards. It is started automatically even after the first install. Again, rebooting is unnecessary to get things running. @@ -115,7 +116,7 @@ capacity=0,60,70-80 # Change this only if your system reports incorrect battery capacity ("acc -i" (BMS) vs "dumpsys battery" (system)). capacityOffset=+0 -# This is an alternative to CapacityOffset. It tells acc whether the battery capacity reported by Android should be updated every few seconds to reflect the actual value from the battery management system. +# This is an alternative to capacityOffset. It tells acc whether the battery capacity reported by Android should be updated every few seconds to reflect the actual value from the battery management system. capacitySync=true # - allow battery temperature to drop below . Temperature values are interpreted in Celsius degrees. To disable temperature control entirely, set absurdly high temperature values (e.g., temperature=90-95_90). @@ -165,7 +166,6 @@ If you're not comfortable with the command line, skip this section and use the ` Alternatively, you can use a `text editor` to modify `/sdcard/acc/config.txt`. Changes to this file take effect almost instantly, and without a daemon restart. Notes/Tips for Front-end Developers -- Apps should always run `/dev/acc/modPath/acc` (e.g., /dev/acc/modPath/acc --daemon restart) instead of the regular `acc`and `accd` commands. This ensures full compatibility with ACC's live upgrade feature. - It's best to use full commands over short equivalents - e.g., `--set chargingSwitch` instead of `-s s`. - Follow auto-install/upgrade instructions in `moduleZip/install-latest.sh`. - Use provided config descriptions for ACC settings in the app. Include additional information (trusted) where appropriate. @@ -176,8 +176,8 @@ Terminal Commands ``` acc --c|--config Edit config w/ (default: nano|vim|vi) - e.g., acc -c vim +-c|--config Edit config w/ (default: vim|vi) + e.g., acc -c -d|--disable <#%, #s, #m or #h (optional)> Disable charging or disable charging with e.g., acc -d 70% (do not recharge until capacity drops to 70%), acc -d 1h (do not recharge until 1 hour has passed) @@ -200,13 +200,13 @@ acc -l|--log -e|--export Export all logs to /sdcard/acc-logs-.tar.bz2 e.g., acc -l -e --l|--log Open w/ (default: nano|vim|vi) +-l|--log Open w/ (default: vim|vi) e.g., acc -l grep ': ' (show explicit errors only) -L|--logwatch Monitor log e.g., acc -L --r|--readme Open w/ (default: nano|vim|vi) +-r|--readme Open w/ (default: vim|vi) e.g., acc -r -R|--resetbs Reset battery stats @@ -296,7 +296,7 @@ Use `acc --voltage :millivolts` (e.g., acc -v :4050) for evaluating charging vol - Slow charging Nullify coolDownRatio (`acc --set coolDownRatio`) or change its value. By default, coolDownRatio is null. -- Logs are stored at `/dev/acc/`. You can export all to `/sdcard/acc-logs-$device.tar.bz2` with `acc --log --export`. +- Logs are stored at `/sbin/_acc/`. You can export all to `/sdcard/acc-logs-$device.tar.bz2` with `acc --log --export`. @@ -304,7 +304,7 @@ Nullify coolDownRatio (`acc --set coolDownRatio`) or change its value. By defaul ## Power Supply Log -Please upload `/dev/acc/acc-power_supply-*.log` to [this dropbox](https://www.dropbox.com/request/WYVDyCc0GkKQ8U5mLNlH/). +Please upload `/sbin/_acc/acc-power_supply-*.log` to [this dropbox](https://www.dropbox.com/request/WYVDyCc0GkKQ8U5mLNlH/). This file contains invaluable power supply information, such as battery details and available charging control files. I'm creating a public database for mutual benefit. Your cooperation is greatly appreciated. @@ -342,6 +342,15 @@ See current submissions [here](https://www.dropbox.com/sh/rolzxvqxtdkfvfa/AABceZ --- ## LATEST CHANGES +**2019.5.12 (201905120)** +- Autofix Termux SU PATH +- Do not use Magic Mount; link everything to /sbin +- Enforce Magisk's busybox to prevent issues caused by outdated binaries +- Enhanced live upgrade; no more command prefix +- Fixed bugs and typos +- Removed nano from fallback editors list. +- Updated build tools and info + **2019.5.11 (201905110)** - build.sh auto-updates update-binary (module_installer.sh) - capacityOffset and capacitySync features for better control over battery capacity reported by the system @@ -349,7 +358,7 @@ See current submissions [here](https://www.dropbox.com/sh/rolzxvqxtdkfvfa/AABceZ - coolDownRatio is null by default - Enhanced daemon efficiency and flexibility - Export logs to /sdcard/acc-logs-.tar.bz2 with --log --export -- Fallback editors for --config and --log options:nano > vim > vi +- Fallback editors for --config and --log options: vim|vi - Improved overall performance - Live upgrade support - users don't need to reboot after installing/upgrading to use the module - Major fixes and optimizations @@ -368,17 +377,3 @@ See current submissions [here](https://www.dropbox.com/sh/rolzxvqxtdkfvfa/AABceZ **2019.3.7-r1 (201903071)** - Hotfix: new users can't install. - -**2019.3.7 (201903070)** -- `acc --log` commands determine the target log file based on verbose state. -- Enhanced self-upgrade. -- Fixed installation error faced by some users. -- Generate `/dev/acc/installed` after successful install/upgrade. -- Include version code in log files. -- New (experimental) charging switches (in `switches.txt`) -- Reduced installer verbose. -- `resetUnplugged` doesn't apply within `coolDownRatioRatio` loop. -- Updated documentation (mainly the troubleshooting section). -- Updated installation instructions in `install.sh` (for app developers). -- Use regular `reboot` commands instead of the unreliable `am bla bla` for system reboot and power off. -- `vNow=mV_pauseSeconds` - monitor `voltage_now` as part of `coolDownRatioRatio` (experimental, default: null (off)). diff --git a/build.sh b/build.sh index 84c4184..4b05f8e 100644 --- a/build.sh +++ b/build.sh @@ -22,7 +22,7 @@ mkdir -p _builds if [[ ${1:-x} != f ]]; then echo "Downloading latest update-binary..." - curl -L https://raw.githubusercontent.com/topjohnwu/Magisk/master/scripts/module_installer.sh 2>/dev/null > _builds/update-binary \ + curl -#L https://raw.githubusercontent.com/topjohnwu/Magisk/master/scripts/module_installer.sh > _builds/update-binary \ && mv -f _builds/update-binary META-INF/com/google/android/ fi diff --git a/common/MODPATH/acc b/common/MODPATH/acc index 1db4082..75af2ff 100644 --- a/common/MODPATH/acc +++ b/common/MODPATH/acc @@ -19,7 +19,7 @@ daemon() { else echo "(i) accd started" set +x - $accd + accd fi ;; stop) @@ -39,7 +39,7 @@ daemon() { echo "(i) accd started" fi set +x - $accd + accd ;; *) if $isRunning; then @@ -60,7 +60,7 @@ edit() { if [ -n "${1:-}" ]; then $@ $file else - nano -$ $file 2>/dev/null || vim $file 2>/dev/null || vi $file + vim $file 2>/dev/null || vi $file fi } @@ -74,8 +74,8 @@ Version code: $(sed -n 's/versionCode=//p' $modPath/module.prop) Usage: acc --c|--config Edit config w/ (default: nano|vim|vi) - e.g., acc -c vim +-c|--config Edit config w/ (default: vim|vi) + e.g., acc -c -d|--disable <#%, #s, #m or #h (optional)> Disable charging or disable charging with e.g., acc -d 70% (do not recharge until capacity drops to 70%), acc -d 1h (do not recharge until 1 hour has passed) @@ -98,13 +98,13 @@ Usage: acc -l|--log -e|--export Export all logs to /sdcard/acc-logs-.tar.bz2 e.g., acc -l -e --l|--log Open w/ (default: nano|vim|vi) +-l|--log Open w/ (default: vim|vi) e.g., acc -l grep ': ' (show explicit errors only) -L|--logwatch Monitor log e.g., acc -L --r|--readme Open w/ (default: nano|vim|vi) +-r|--readme Open w/ (default: vim|vi) e.g., acc -r -R|--resetbs Reset battery stats @@ -177,9 +177,9 @@ set_value() { [ $var = s ] && var=chargingSwitch || : shift if grep -q "^$var=" $config; then - sed -i "s|^$var=.*|$var=$@|" $config + sed -i "s|^$var=.*|$var=$*|" $config elif grep -q "^#$var=" $config; then - sed -i "s|^#$var=.*|$var=$@|" $config + sed -i "s|^#$var=.*|$var=$*|" $config else echo "(!) Invalid variable, [$var]" exit 1 @@ -198,7 +198,7 @@ set_values() { cp -f $modPath/config.txt $config chmod 0777 $config echo "(i) Config reset" - daemon > /dev/null && daemon restart || : + accd return 0 ;; *) @@ -494,7 +494,7 @@ test_charging_switch() { if not_charging; then echo "(!) Battery must be charging" - $accd + accd return 2 fi @@ -504,19 +504,19 @@ test_charging_switch() { if not_charging; then echo "(i) [$file $on $off] works" echo $default > $file - $accd + accd return 0 else echo "(!) [$file $on $off] doesn't work" echo $default > $file - $accd + accd return 1 fi else disable_charging > /dev/null if not_charging; then echo "(i) Supported device" - $accd + accd return 0 else echo "(!) Unsupported device" @@ -540,10 +540,9 @@ umask 0 trap exxit EXIT set -euo pipefail -modPath=/dev/acc/modPath -accd=$modPath/system/*bin/accd +modPath=/sbin/_acc/acc config=/data/media/0/acc/config.txt -which busybox > /dev/null || PATH=/sbin/.magisk/busybox:$PATH +[[ $PATH == "*magisk/busybox*" ]] || PATH=/sbin/.magisk/busybox:$PATH device=$(getprop ro.product.device | grep .. || getprop ro.build.product) batt=$(echo /sys/class/power_supply/*attery/capacity | awk '{print $1}' | sed 's|/capacity||') @@ -579,7 +578,7 @@ case ${1:-} in enable_charging ${2:-100}% set_charging_voltage $chargingVoltageLimit unset chargingVoltageLimit - $accd + accd ;; -i|--info) sed s/POWER_SUPPLY_// $batt/uevent | sed "/^CAPACITY=/s/=.*/=$(( $(cat $batt/capacity) $(get_value capacityOffset) ))/";; diff --git a/common/MODPATH/accd b/common/MODPATH/accd index 1604214..5ce5b41 100644 --- a/common/MODPATH/accd +++ b/common/MODPATH/accd @@ -64,12 +64,12 @@ disable_charging() { value=$(get_value chargingSwitch | awk '{print $3}') if [ -f $file ]; then chmod +w $file && echo $value > $file 2>/dev/null \ - || $acc --set chargingSwitch- > /dev/null + || acc --set chargingSwitch- > /dev/null else - $acc --set chargingSwitch- > /dev/null + acc --set chargingSwitch- > /dev/null fi #sleep 1 - #! is_charging || $acc --set chargingSwitch- > /dev/null + #! is_charging || acc --set chargingSwitch- > /dev/null else switch_loop off ! is_charging || exxit 1 "(!) Unsupported device" @@ -89,9 +89,9 @@ enable_charging() { value=$(get_value chargingSwitch | awk '{print $2}') if [ -f $file ]; then chmod +w $file && echo $value > $file 2>/dev/null \ - || $acc --set chargingSwitch- > /dev/null + || acc --set chargingSwitch- > /dev/null else - $acc --set chargingSwitch- > /dev/null + acc --set chargingSwitch- > /dev/null fi else switch_loop on @@ -223,11 +223,10 @@ set -euo pipefail modId=acc coolDown=false resetBsOnUnplug=false -modPath=/dev/$modId/modPath -acc=$modPath/acc +modPath=/sbin/_$modId/$modId config=/data/media/0/$modId/config.txt -which busybox > /dev/null || PATH=/sbin/.magisk/busybox:$PATH +[[ $PATH == "*magisk/busybox*" ]] || PATH=/sbin/.magisk/busybox:$PATH log=${modPath%/*}/acc-daemon-$(getprop ro.product.device | grep .. || getprop ro.build.product).log @@ -244,7 +243,7 @@ set -e mkdir -p ${modPath%/*} ${config%/*} [ -f $config ] || install -m 0777 $modPath/config.txt $config -cd /sys/class/power_supply +cd /sys/class/power_supply/ # diagnostics and cleanup echo "###$(date)###" >> $log @@ -256,7 +255,7 @@ trap exxit EXIT [ -f $modPath/module.prop ] || exxit 1 "(!) modPath not found" unset modId apply_on_boot -$acc --voltage apply > /dev/null 2>&1 || : +acc --voltage apply > /dev/null 2>&1 || : check_compatibility ctrl_charging exit $? diff --git a/common/MODPATH/accd-init b/common/MODPATH/accd-init new file mode 100644 index 0000000..88afb5e --- /dev/null +++ b/common/MODPATH/accd-init @@ -0,0 +1,2 @@ +#!/system/bin/sh +(/sbin/_acc/acc/accd &) & diff --git a/common/MODPATH/config.txt b/common/MODPATH/config.txt index f9b1591..8bb8a3e 100644 --- a/common/MODPATH/config.txt +++ b/common/MODPATH/config.txt @@ -3,7 +3,7 @@ # This is used to determine whether config should be patched. Do NOT modify! -versionCode=201905110 +versionCode=201905111 # shutdown,coolDown,resume-pause capacity=0,60,70-80 @@ -11,7 +11,7 @@ capacity=0,60,70-80 # Change this only if your system reports incorrect battery capacity ("acc -i" (BMS) vs "dumpsys battery" (system)). capacityOffset=+0 -# This is an alternative to CapacityOffset. It tells acc whether the battery capacity reported by Android should be updated every few seconds to reflect the actual value from the battery management system. +# This is an alternative to capacityOffset. It tells acc whether the battery capacity reported by Android should be updated every few seconds to reflect the actual value from the battery management system. capacitySync=true # - allow battery temperature to drop below . Temperature values are interpreted in Celsius degrees. To disable temperature control entirely, set absurdly high temperature values (e.g., temperature=90-95_90). diff --git a/common/MODPATH/psl b/common/MODPATH/psl index 8f04a6e..b046ebb 100644 --- a/common/MODPATH/psl +++ b/common/MODPATH/psl @@ -3,7 +3,6 @@ # Copyright (C) 2019, VR25 @ xda-developers # License: GPLv3+ - gather_ps_data() { local target="" target2="" for target in $(ls -1 $1 | grep -Ev '^[0-9]|^block$|^dev$|^fs$|^ram$'); do @@ -28,8 +27,8 @@ gather_ps_data() { done } -log=/dev/acc/acc-power_supply-$(getprop ro.product.device | grep .. || getprop ro.build.product).log -mkdir -p /dev/acc +log=/sbin/_acc/acc-power_supply-$(getprop ro.product.device | grep .. || getprop ro.build.product).log +mkdir -p /sbin/_acc { date diff --git a/common/MODPATH/system/xbin/acc b/common/MODPATH/system/xbin/acc deleted file mode 100644 index 7cf0a96..0000000 --- a/common/MODPATH/system/xbin/acc +++ /dev/null @@ -1,2 +0,0 @@ -#!/system/bin/sh -/dev/acc/modPath/acc $@ diff --git a/common/MODPATH/system/xbin/accd b/common/MODPATH/system/xbin/accd deleted file mode 100644 index f025f7a..0000000 --- a/common/MODPATH/system/xbin/accd +++ /dev/null @@ -1,2 +0,0 @@ -#!/system/bin/sh -(/dev/acc/modPath/accd &) & diff --git a/common/post-fs-data.sh b/common/post-fs-data.sh deleted file mode 100644 index 63d4ff9..0000000 --- a/common/post-fs-data.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/system/bin/sh -# For better compatibility and live upgrade support - -# generate power supply log -(${0%/*}/psl $(sed -n s/versionCode=//p ${0%/*}/module.prop) &) & - -# prepare working directory -mkdir -p /dev/acc -ln -fs ${0%/*} /dev/acc/modPath - -exit 0 diff --git a/common/service.sh b/common/service.sh index 0739466..d8c97b3 100644 --- a/common/service.sh +++ b/common/service.sh @@ -1,4 +1,24 @@ #!/system/bin/sh -# Advanced Charging Controller Daemon (accd) Starter +# acc/accd initializer -(/dev/acc/modPath/accd &) & +# prepare working directory +mkdir /sbin/_acc +ln -fs ${0%/*} /sbin/_acc/acc +ln -fs /sbin/_acc/acc/acc /sbin/acc +ln -fs /sbin/_acc/acc/accd-init /sbin/accd + +# generate power supply log +${0%/*}/psl $(sed -n s/versionCode=//p ${0%/*}/module.prop) + +# fix termux su PATH +termuxSu=/data/data/com.termux/files/usr/bin/su +if [ -f $termuxSu ] && grep -q '/su:' $termuxSu; then + sed -i 's|/su:|:|' $termuxSu + magisk --clone-attr ${termuxSu%su}apt $termuxSu +fi +unset termuxSu + +# start accd +accd + +exit 0 diff --git a/install.sh b/install.sh index 3d49a25..3f15e8d 100644 --- a/install.sh +++ b/install.sh @@ -22,13 +22,13 @@ # Set to true if you do *NOT* want Magisk to mount # any files for you. Most modules would NOT want # to set this flag to true -SKIPMOUNT=false +SKIPMOUNT=true # Set to true if you need to load system.prop PROPFILE=false # Set to true if you need post-fs-data script -POSTFSDATA=true +POSTFSDATA=false # Set to true if you need late_start service script LATESTARTSERVICE=true @@ -151,6 +151,8 @@ on_install() { trap 'exxit $?' EXIT config=/data/media/0/$MODID/config.txt + configVer=$(sed -n s|^versionCode=||p $config 2>/dev/null || :) + termuxSu=/data/data/com.termux/files/usr/bin/su # extract module files ui_print "- Extracting module files" @@ -162,8 +164,12 @@ on_install() { unzip -o "$ZIPFILE" License.md README.md -d ${config%/*}/info/ >&2 # upgrade config - if [ -f $config ] && [ 0$(sed -n s|^verionCode=||p $config) -lt 0201905110 ]; then - rm -rf $config ${config%/*}/logs 2>/dev/null || : + if [ -f $config ]; then + if [ ${configVer:-0} -lt 201905110 ]; then + rm -rf $config ${config%/*}/logs 2>/dev/null || : + elif [ ${configVer:-0} -lt 201905111 ]; then + sed -i -e /CapacityOffset/s/C/c/ -e /versionCode/s/=.*/201905111/ $config + fi fi set +euxo pipefail @@ -194,14 +200,26 @@ set_permissions() { # finishing touches if $BOOTMODE; then - mkdir -p /dev/acc + mkdir -p /sbin/_acc + [ -h /sbin/_acc/acc ] && rm /sbin/_acc/acc \ + || rm -rf /sbin/_acc/acc 2>/dev/null + cp -a $MODPATH /sbin/_acc/acc + ln -fs /sbin/_acc/acc/acc /sbin/acc + ln -fs /sbin/_acc/acc/accd-init /sbin/accd + ### [ -h /dev/acc/modPath ] && rm /dev/acc/modPath \ || rm -rf /dev/acc/modPath 2>/dev/null cp -a $MODPATH /dev/acc/modPath + ### wait - /dev/acc/modPath/system/*bin/accd + /sbin/accd fi chmod -R 0777 ${config%/*} + # fix termux su PATH + if [ -f $termuxSu ] && grep -q '/su:' $termuxSu; then + sed -i 's|/su:|:|' $termuxSu + magisk --clone-attr ${termuxSu%su}apt $termuxSu + fi } # You can add more functions to assist your custom script code diff --git a/module.prop b/module.prop index 522dfdd..5bcb1fd 100644 --- a/module.prop +++ b/module.prop @@ -1,7 +1,7 @@ id=acc name=Advanced Charging Controller (acc) -version=2019.5.11 -versionCode=201905110 +version=2019.5.12 +versionCode=201905120 author=VR25 @ xda-developers description=This is primarily intended for extending battery service life. On the flip side, the name says it all. It supports Magisk 17-19. minMagisk=17000