diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary index 112eb28..8401147 100644 --- a/META-INF/com/google/android/update-binary +++ b/META-INF/com/google/android/update-binary @@ -1,151 +1,223 @@ -#!/sbin/sh - -TMPDIR=/dev/tmp -MOUNTPATH=/dev/magisk_img - -# Default permissions -umask 022 +#!/system/bin/sh +# $id Installer/Upgrader +# Copyright (c) 2019, VR25 (xda-developers.com) +# License: GPLv3+ + +set +x +echo +id=acc +umask 077 + +# log +mkdir -p /data/adb/${id}-data/logs +exec 2>/data/adb/${id}-data/logs/install.log +set -x + +trap 'e=$?; echo; exit $e' EXIT + +# set up busybox +if [ -d /sbin/.magisk/busybox ]; then + [[ $PATH == /sbin/.magisk/busybox* ]] || PATH=/sbin/.magisk/busybox:$PATH +elif [ -d /sbin/.core/busybox ]; then + [[ $PATH == /sbin/.core/busybox* ]] || PATH=/sbin/.core/busybox:$PATH +else + [[ $PATH == /dev/.busybox* ]] || PATH=/dev/.busybox:$PATH + if ! mkdir -m 700 /dev/.busybox 2>/dev/null; then + if [ -x /data/adb/magisk/busybox ]; then + /data/adb/magisk/busybox --install -s /dev/.busybox + elif which busybox > /dev/null; then + busybox --install -s /dev/.busybox + else + echo "(!) Install busybox binary first" + exit 3 + fi + fi +fi -# Initial cleanup -rm -rf $TMPDIR 2>/dev/null -mkdir -p $TMPDIR +# root check +if [ $(id -u) -ne 0 ]; then + echo "(!) $0 must run as root (su)" + exit 4 +fi -# echo before loading util_functions -ui_print() { echo "$1"; } +print() { sed -n "s|^$1=||p" ${2:-$srcDir/module.prop}; } -require_new_magisk() { - ui_print "***********************************" - ui_print " Please install the latest Magisk! " - ui_print "***********************************" - exit 1 +set_perms() { + local owner=${2:-0} perms=0600 target=$(readlink -f $1) + if echo $target | grep -q '.*\.sh$' || [ -d $target ]; then perms=0700; fi + chmod $perms $target + chown $owner:$owner $target + restorecon $target > /dev/null 2>&1 || : } -imageless_magisk() { - [ $MAGISK_VER_CODE -gt 18100 ] - return $? +set_perms_recursive() { + local owner=${2:-0} target="" + find $1 2>/dev/null | while read target; do set_perms $target $owner; done } -########################################################################################## -# Environment -########################################################################################## +set -euo pipefail -OUTFD=$2 -ZIPFILE=$3 +# set source code directory +[ -f $PWD/${0##*/} ] && srcDir=$PWD || srcDir=${0%/*} -mount /data 2>/dev/null +# unzip flashable zip if source code is unavailable +if [ ! -f $srcDir/module.prop ]; then + srcDir=/dev/.tmp + rm -rf $srcDir 2>/dev/null || : + mkdir $srcDir + unzip -o ${ZIP:-${3:-}} -d $srcDir/ >&2 +fi -# Load utility functions -if [ -f /data/adb/magisk/util_functions.sh ]; then - . /data/adb/magisk/util_functions.sh - NVBASE=/data/adb -else - require_new_magisk +name=$(print name) +author=$(print author) +version=$(print version) +versionCode=$(print versionCode) +installDir=${installDir0:-/data/data/mattecarra.accapp/files} +config=/data/media/0/$id/${id}.conf + +# migrate/restore config +[ -f $config ] || mv ${config%/*}/config.txt $config 2>/dev/null || : +if [ -d ${config%/*} ] && [ ! -d /data/adb/${id}-data ]; then + mv $config ${config%/*}/config.txt 2>/dev/null || : + (cd /data/media/0; mv ${config%/*} ${id}-data + tar -cf - ${id}-data | tar -xf - -C /data/adb) + rm -rf ${id}-data +fi +config=/data/adb/${id}-data/config.txt +[ -f $config ] || cp /data/media/0/.${id}-config-backup.txt $config 2>/dev/null || : + +configVer=$(print versionCode $config 2>/dev/null || :) + +# check/set parent installation directory +[ -d $installDir ] || installDir=/sbin/.magisk/modules +[ -d $installDir ] || installDir=/sbin/.core/img +[ -d $installDir ] || installDir=/data/adb +[ -d $installDir ] || { echo "(!) /data/adb/ not found\n"; exit 1; } + + +cat << EOF +$name $version +Copyright (c) 2017-2019, $author +License: GPLv3+ + +(i) Installing in $installDir/$id/... +EOF + + +(pkill -9 -f "/$id (-|--)|/${id}d.sh" ) || : + +# install +rm -rf $(readlink -f /sbin/.$id/$id) $installDir/$id 2>/dev/null || : +cp -R $srcDir/$id/ $installDir/ +installDir=$installDir/$id +[ ${installDir0:-x} == x ] && installDir0=/data/data/mattecarra.accapp/files/$id || installDir0=$installDir0/$id +cp $srcDir/module.prop $installDir/ + +mkdir -p ${config%/*}/info +cp -f $srcDir/*.md ${config%/*}/info + +case $installDir in + /data/adb/$id|$installDir0) + mv $installDir/service.sh $installDir/${id}-init.sh;; + *) + ln $installDir/service.sh $installDir/post-fs-data.sh;; +esac + +# patch/upgrade config +if [ -f $config ]; then + if [ ${configVer:-0} -lt 201910130 ] \ + || [ ${configVer:-0} -gt $(print versionCode $installDir/default-config.txt) ] + then + rm $config +# else +# if [ $configVer -lt 201906290 ]; then +# echo prioritizeBattIdleMode=false >> $config +# sed -i '/^versionCode=/s/=.*/=201906290/' $config +# fi +# if [ $configVer -lt 201907080 ]; then +# sed -i '/^loopDelay=/s/=.*/=10,30/' $config +# sed -i '/^versionCode=/s/=.*/=201907080/' $config +# fi +# if [ $configVer -lt 201907090 ]; then +# sed -i '/^rebootOnUnplug=/d' $config +# sed -i '/^versionCode=/s/=.*/=201907090/' $config +# fi +# if [ $configVer -lt 201909260 ]; then +# sed -i '/^loopDelay=/s/,30/,15/' $config +# sed -i '/^versionCode=/s/=.*/=201909260/' $config +# fi + fi fi -# Preperation for flashable zips -setup_flashable +cp -f $srcDir/bin/${id}-uninstaller.zip /data/media/0/ -# Mount partitions -mount_partitions +# set perms +set_perms_recursive ${config%/*} +chmod 0666 /data/media/0/${id}-uninstaller.zip +case $installDir in + /data/*/files/$id) + pkg=${installDir%/files/$id} + pkg=${pkg##/data*/} + owner=$(grep $pkg /data/system/packages.list | awk '{print $2}') + set_perms_recursive ${installDir%/*} $owner + ;; + *) + set_perms_recursive $installDir + ;; +esac -# Detect version and architecture -api_level_arch_detect +set +euo pipefail -# Setup busybox and binaries -$BOOTMODE && boot_actions || recovery_actions -########################################################################################## -# Preparation -########################################################################################## +cat << EOF +- Done -# Extract common files -unzip -oj "$ZIPFILE" module.prop install.sh uninstall.sh 'common/*' -d $TMPDIR >&2 + LATEST CHANGES -[ ! -f $TMPDIR/install.sh ] && abort "! Unable to extract zip file!" -# Load install script -. $TMPDIR/install.sh +EOF -if imageless_magisk; then - $BOOTMODE && MODDIRNAME=modules_update || MODDIRNAME=modules - MODULEROOT=$NVBASE/$MODDIRNAME -else - $BOOTMODE && IMGNAME=magisk_merge.img || IMGNAME=magisk.img - IMG=$NVBASE/$IMGNAME - request_zip_size_check "$ZIPFILE" - mount_magisk_img - MODULEROOT=$MOUNTPATH -fi -MODID=`grep_prop id $TMPDIR/module.prop` -MODPATH=$MODULEROOT/$MODID +# print changelog +tail -n +$(grep -n \($versionCode\) ${config%/*}/info/README.md | cut -d: -f1) \ + ${config%/*}/info/README.md | sed 's/^/ /' -print_modname -ui_print "******************************" -ui_print "Powered by Magisk (@topjohnwu)" -ui_print "******************************" +cat << EOF -########################################################################################## -# Install -########################################################################################## + LINKS + - ACC app: github.com/MatteCarra/AccA/ + - Battery University: batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries/ + - Donate: paypal.me/vr25xda/ + - Daily Job Scheduler: github.com/VR-25/djs/ + - Facebook page: facebook.com/VR25-at-xda-developers-258150974794782/ + - Git repository: github.com/VR-25/$id/ + - Telegram channel: t.me/vr25_xda/ + - Telegram group: t.me/${id}_group/ + - Telegram profile: t.me/vr25xda/ + - XDA thread: forum.xda-developers.com/apps/magisk/module-magic-charging-switch-cs-v2017-9-t3668427/ -# Create mod paths -rm -rf $MODPATH 2>/dev/null -mkdir -p $MODPATH +(i) Important info: https://bit.ly/2TRqRz0 -on_install +(i) Rebooting is unnecessary. +- $id can be used right now. +- $id daemon started. +EOF -# Remove placeholder -rm -f $MODPATH/system/placeholder 2>/dev/null -# Custom uninstaller -[ -f $TMPDIR/uninstall.sh ] && cp -af $TMPDIR/uninstall.sh $MODPATH/uninstall.sh +[ $installDir == /data/adb ] && echo -e "\n(i) Use init.d or an app to run $installDir/${id}-init.sh on boot to initialize ${id}." -# Auto Mount -if imageless_magisk; then - $SKIPMOUNT && touch $MODPATH/skip_mount -else - $SKIPMOUNT || touch $MODPATH/auto_mount -fi +echo +trap - EXIT -# prop files -$PROPFILE && cp -af $TMPDIR/system.prop $MODPATH/system.prop - -# Module info -cp -af $TMPDIR/module.prop $MODPATH/module.prop -if $BOOTMODE; then - # Update info for Magisk Manager - if imageless_magisk; then - mktouch $NVBASE/modules/$MODID/update - cp -af $TMPDIR/module.prop $NVBASE/modules/$MODID/module.prop +# initialize $id +if grep -q /storage/emulated /proc/mounts; then + if [ -f $installDir/service.sh ]; then + $installDir/service.sh --override else - mktouch /sbin/.magisk/img/$MODID/update - cp -af $TMPDIR/module.prop /sbin/.magisk/img/$MODID/module.prop + $installDir/${id}-init.sh --override fi fi -# post-fs-data mode scripts -$POSTFSDATA && cp -af $TMPDIR/post-fs-data.sh $MODPATH/post-fs-data.sh - -# service mode scripts -$LATESTARTSERVICE && cp -af $TMPDIR/service.sh $MODPATH/service.sh - -# Handle replace folders -for TARGET in $REPLACE; do - mktouch $MODPATH$TARGET/.replace -done - -ui_print "- Setting permissions" -set_permissions - -########################################################################################## -# Finalizing -########################################################################################## - -cd / -imageless_magisk || unmount_magisk_img -$BOOTMODE || recovery_cleanup -rm -rf $TMPDIR $MOUNTPATH - -ui_print "- Done" +e=$? +[ $e -eq 0 ] || { echo; exit $e; } exit 0 diff --git a/README.md b/README.md index d3106f0..2a3cd22 100644 --- a/README.md +++ b/README.md @@ -52,12 +52,33 @@ ACC is primarily intended for [extending battery service life](https://batteryun --- ## PREREQUISITES -- Any root solution -- Terminal emulator +- Android or Android based OS +- Any root solution (e.g., Magisk) +- Busybox (only if not rooted with Magisk) +- Terminal emulator (e.g., Termux) - Text editor (optional) +--- +## QUICK START GUIDE + + +1. Unless Magisk is not installed, always install/upgrade from Magisk Manager or dedicated ACC front-end. Apps such as EX Kernel Manager and FK Kernel Manager are also good options. +2. [Optional] run `su -c acc STOP_LEVEL RESUME_LEVEL` (default `80 70`) or use a front-end app to change settings. +3. If you encounter any trouble, scroll down to the `TROUBLESHOOTING`, `TIPS` and `FAQ` sections. + + +### Notes + +- `2` is optional because there are default settings. For details, refer to the `DEFAULT CONFIGURATION` section below. + +- Settings can be overwhelming. Start with what you understand and leave everything else default - until you have squeezed enough knowledge from this document. + +- Uninstall: depending o the installed variant, you can run `su -c acc --uninstall` or flash `/sdcard/acc-uninstaller.zip` (both are universal), use Magisk Manager (app) or [Magisk Manager for Recovery Mode (utility)](https://github.com/VR-25/mm/), or clear the front-end app data. The flashable uninstaller works everywhere - Magisk Manager, kernel managers, TWRP, etc.. + + + --- ## BUILDING AND/OR INSTALLING FROM SOURCE @@ -68,48 +89,50 @@ ACC is primarily intended for [extending battery service life](https://batteryun - zip -### Build +### Build Tarballs and Flashable Zips 1. Download the source code: `git clone https://github.com/VR-25/acc.git` or `wget https://github.com/VR-25/acc/archive/$reference.tar.gz -O - | tar -xz` or `curl -L# https://github.com/VR-25/acc/archive/$reference.tar.gz | tar -xz` 2. `cd acc*` 3. `sh build.sh` (or double-click `build.bat` on Windows 10, if you have Windows subsystem for Linux installed) + #### Notes -- The output files are (in _builds/): `acc-$versionCode.zip`, `acc_bundle` (.tar.gz), and `install` (install-tarball.sh). +- build.sh automatically sets/corrects `id=*` in `*.sh` and `update-binary` files. -- By default, `build.sh` auto-updates the .zip [update-binary](https://raw.githubusercontent.com/topjohnwu/Magisk/master/scripts/module_installer.sh). To skip this, run `sh build.sh -o|--offline` (or `build-offline.bat` on Windows 10). +- The output files are (in `_builds/acc-$versionCode/`): `acc-$versionCode.zip`, `acc-$versionCode.tar.gz`, and `install-tarball.sh`. -- To update the local repo, run `git pull -f`. +- To update the local repo, run `git pull --force`. ### Install from Local Sources and GitHub -- `sh install-tarball.sh` installs the tarball (acc*gz) sitting next to it. The archive must be obtained from GitHub: https://github.com/VR-25/acc/archive/$reference.tar.gz +- `sh install-tarball.sh acc` installs the tarball (acc*gz) sitting next to it. The archive must be obtained from GitHub: https://github.com/VR-25/acc/archive/$reference.tar.gz ($reference examples: master, dev, 201908290). - `sh install-current.sh` installs acc from the script's location. -- `sh install-latest.sh [-c|--changelog|-f|--force|-n|--non-interactive] [%install dir%] [reference]` downloads and installs acc from GitHub. e.g., `sh install-latest.sh dev` +- `sh install-latest.sh [-c|--changelog] [-f|--force] [-n|--non-interactive] [%install dir%] [reference]` downloads and installs acc from GitHub. e.g., `sh install-latest.sh dev` + #### Notes -- `install-current.sh` and `install-tarball.sh` take an optional installation path argument (e.g., sh install-current.sh /data - this will install acc to /data/acc/). +- `install-current.sh` and `install-tarball.sh` take an optional parent installation path argument (e.g., sh install-current.sh /data - this will install acc to /data/acc/). - `install-latest.sh` is a back-end to `acc --upgrade`. - The order of arguments doesn't matter. -- The default installation paths, in order of priority, are: /data/data/mattecarra.accapp/files/, /sbin/.magisk/modules/, /sbin/.core/img/ and /data/adb/. +- The default parent installation paths, in order of priority, are: /data/data/mattecarra.accapp/files/, /sbin/.magisk/modules/, /sbin/.core/img/ and /data/adb/. -- No argument/option is mandatory. The exception is `--non-interactive` for front-ends. Additionally, unofficially supported front-ends must specify the installation path. +- No argument/option is mandatory. The exception is `--non-interactive` for front-ends. Additionally, unofficially supported front-ends must specify the parent installation path. - Recall that unlike the other two installers, `install-latest.sh` requires the installation path to be enclosed in `%` (e.g., sh install-latest.sh %/data% --non-interactive). -- The `--force` option is meant for reinstallation and downgrade. +- The `--force` option (install-latest.sh) is meant for reinstallation and downgrading. - `sh install-latest.sh --changelog --non-interactive` prints the version code (integer) and changelog URL (string) when an update is available. In interactive mode, it also asks the user whether they want to download and install the update. -- You may want to take a look at `## NOTES/TIPS FOR FRONT-END DEVELOPERS > ### Exit Codes`, too. +- You may want to take a look at `NOTES/TIPS FOR FRONT-END DEVELOPERS > Exit Codes` below, too. @@ -117,18 +140,11 @@ ACC is primarily intended for [extending battery service life](https://batteryun ## SETUP -### Magisk 18.2+ - -Install/upgrade: flash live (e.g., from Magisk Manager) or from custom recovery (e.g., TWRP). - -Uninstall: use Magisk Manager (app), [Magisk Manager for Recovery Mode (utility)](https://github.com/VR-25/mm/), or run `acc --uninstall`. - +### Any Root Solution -### Any Root Solution (Advanced) +Install/upgrade: unless Magisk is not installed, always install/upgrade from Magisk Manager or dedicated ACC front-end; apps such as EX Kernel Manager and FK Kernel Manager are also good options. -Install/upgrade: extract `acc-*.zip`, run `su`, then execute `sh /path/to/extracted/install-current.sh`. Refer to `## BUILDING AND/OR INSTALLING FROM SOURCE > ### Install from Local Sources and GitHub` for additional details. - -Uninstall: run `acc --uninstall`. +Uninstall: depending o the installed variant, you can run `su -c acc --uninstall` or flash `/sdcard/acc-uninstaller.zip` (both are universal), use Magisk Manager (app) or [Magisk Manager for Recovery Mode (utility)](https://github.com/VR-25/mm/), or clear the front-end app data. The flashable uninstaller works everywhere - Magisk Manager, kernel managers, TWRP, etc.. ### Notes @@ -148,29 +164,29 @@ For non-Magisk install, [busybox](https://duckduckgo.com/?q=busybox+android) bin versionCode=XXXXXXXXX # shutdown,coolDown,resume-pause -capacity=0,60,70-80 +capacity=0,60,75-80 -# Change this only if your system reports incorrect battery capacity ("acc -i" (BMS) vs "dumpsys battery" (system)). +# Change this only if your system reports incorrect battery capacity ("acc -i" (BMS) vs "dumpsys battery" (system)). Pixel devices are know for having this issue. 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. capacitySync=false -# - 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). -temperature=40-45_90 +# - 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., the defaults, as shown below). +temperature=70-80_90 # Charging ON/OFF ratio in seconds (e.g., coolDownRatio=50/10) - reduces battery stress induced by prolonged high temperature and high charging voltage by periodically pausing charging. If charging is too slow, turn this off (null value) or change the ratio. When set to null, and values are nullified. # Generally, you don't need this if you're limiting the maximum charging voltage. coolDownRatio= -# Reset battery stats after is reached. -resetBsOnPause=true +# Reset battery stats after is reached. If enabled, this may temporarily worsen capacity report discrepancies between Android and the BMS on Pixel devices. +resetBsOnPause=false # Reset battery stats every time charger is unplugged, as opposed to only when is reached. resetBsOnUnplug=false # Seconds (plugged,unplugged) between loop iterations - this is essentially a sensitivity "slider". Do not touch it unless you know exactly what you're doing! For Plugged seconds, a value lower than 5 may cause unexpected behavior (e.g., increased battery drain). A number above 30 may lead to significant delays in charging control; on the other hand, it will dramatically boost acc's energy efficiency. -loopDelay=10,30 +loopDelay=10,15 # Custom charging switch parameters ( ), e.g., chargingSwitch=/sys/class/power_supply/battery/charging_enabled 1 0, pro tip: can be omitted (e.g., chargingSwitch=battery/charging_enabled 1 0). chargingSwitch= @@ -183,9 +199,9 @@ applyOnBoot= # Tip: applyOnPlug=wireless/voltage_max:9000000 forces fast wireless charging on Pixel devices. applyOnPlug= -# Charging voltage limit (file:millivolts, e.g., chargingVoltageLimit=?attery/voltage_max:4200) +# Charging voltage limit (file:millivolts, e.g., maxChargingVoltage=?attery/voltage_max:4200) # Voltage range (millivolts): 3920-4349 -chargingVoltageLimit= +maxChargingVoltage= # Reboot after is reached and (e.g., rebootOnPause=60) have passed (disabled if null). If this doesn't make sense to you, you probably don't need it. rebootOnPause= @@ -193,7 +209,7 @@ rebootOnPause= # Minimum charging on/off toggling interval (seconds) chargingOnOffDelay=1 -# English (en) and Portuguese (pt) are the main languages supported. Refer to the "## LOCALIZATION" section below for all available languages and translation information. +# English (en) and Portuguese (pt) are the main languages supported. Refer to the "## LOCALIZATION" section below for all available languages and translation information. Running "acc-en" instead of "acc" overrides this setting. language=en # Wakelocks to unlock after pausing charging (e.g., wakeUnlock=chg_wake_lock qcom_step_chg) @@ -203,6 +219,9 @@ wakeUnlock= # Prioritize charging switches that support battery idle mode. prioritizeBattIdleMode=false + +# Workaround for end-of-charge issues on Android 10 (e.g., force fully charged status at 100% capacity, value 5 for Pixel devices) +forceStatusAt100= ``` @@ -214,7 +233,7 @@ ACC is designed to run out of the box, without user intervention. You can simply If you feel uncomfortable with the command line, skip this section and use the [ACC app](https://github.com/MatteCarra/AccA/releases/) to manage ACC. -Alternatively, you can use a `text editor` to modify `/data/adb/acc-*/config.txt`. Changes to this file take effect almost instantly, and without a [daemon](https://en.wikipedia.org/wiki/Daemon_(computing)) restart. +Alternatively, you can use a `text editor` to modify `/data/adb/acc-data/config.txt`. Changes to this file take effect almost instantly, and without a [daemon](https://en.wikipedia.org/wiki/Daemon_(computing)) restart. ### Terminal Commands @@ -250,6 +269,9 @@ acc <-x|--xtrace> -i|--info Show power supply info e.g., acc -i +-I|--lang Show available, as well as the default and currently set languages + e.g., acc -I + -l|--log <-a|--acc> Open accd log (default) or acc log (-a) w/ (default: nano|vim|vi) e.g., acc -l grep ': ' (show explicit errors only) @@ -259,6 +281,9 @@ acc <-x|--xtrace> -L|--logwatch Monitor accd log in realtime e.g., acc -L +-P|--performance accd performance monitor (htop) + e.g., acc -P + -r|--readme Open w/ (default: vim|vi) e.g., acc -r @@ -304,7 +329,7 @@ acc <-x|--xtrace> Exit codes: 0 (works), 1 (doesn't work) or 2 (battery must be charging) e.g., acc -t -- /sdcard/experimental_switches.txt --u|--upgrade [-c|--changelog|-f|--force|-n|--non-interactive] [reference] Upgrade/downgrade +-u|--upgrade -c|--changelog] [-f|--force] [-n|--non-interactive] [reference] Upgrade/downgrade e.g., acc -u dev (upgrade to the latest dev version) acc -u (latest stable release) @@ -357,9 +382,11 @@ Run acc --readme to see the full documentation. ## NOTES/TIPS FOR FRONT-END DEVELOPERS +Note: it's best to use `acc-en` over `acc` if your app doesn't rely on exit codes alone. This ensures acc language is always English. + It's best to use full commands over short equivalents - e.g., `acc --set chargingSwitch` instead of `acc -s s`. This makes your code more readable (less cryptic). -Use provided config descriptions for ACC settings in your app(s). Include additional information (trusted) where appropriate. +Include provided config descriptions for ACC settings in your app(s). Provide additional information (trusted) where appropriate. ### Online ACC Install @@ -369,14 +396,14 @@ Use provided config descriptions for ACC settings in your app(s). Include additi which acc > /dev/null 2) Download the installer (https://raw.githubusercontent.com/VR-25/acc/master/install-latest.sh) -- e.g., curl -#LO [URL] or wget -O install-latest.sh [URL] +- e.g., curl -#LO URL or wget -O install-latest.sh URL 3) Run "sh install-latest.sh" (installation progress is shown) ``` ### Offline ACC Install -Refer to `## SETUP > ### Any Root Solution (Advanced)` and `## SETUP > ### Notes`. +Refer to the `BUILDING AND/OR INSTALLING FROM SOURCE` section above. ### Officially Supported Front-ends @@ -390,11 +417,11 @@ Refer to `## SETUP > ### Any Root Solution (Advanced)` and `## SETUP > ### Notes 1. False or general failure 2. Incorrect command usage, or battery must be charging (acc --test) 3. Missing busybox binary -4. Not root +4. Not running as root 5. Update available 6. No update available 7. Installation path not found -8. Daemon already running or not running (acc --daemon start|stop) +8. Daemon already running (acc --daemon start) or not running (acc --daemon stop) @@ -402,6 +429,11 @@ Refer to `## SETUP > ### Any Root Solution (Advanced)` and `## SETUP > ### Notes ## TROUBLESHOOTING +### Battery Capacity (% Level) is Misreported + +The "smart" battery must be calibrated. Refer to the `FAQ` section below for details. + + ### Charging Switch By default, ACC uses whatever [charging switch](https://github.com/VR-25/acc/blob/master/acc/switches.txt) works. @@ -423,7 +455,7 @@ In such situations, you have to find and enforce a switch that works as expected ### Charging Voltage And Current Limits -Unfortunately, not all devices/kernels support these features. +Unfortunately, not all kernels support these features. Those that do are rare. Most OEMs don't care about that. @@ -439,12 +471,17 @@ The existence of potential voltage/current control file doesn't necessarily mean Check whether charging current in being limited by `applyOnPlug` or `applyOnBoot`. -Set `coolDownCapacity` to `101`, nullify coolDownRatio (`acc --set coolDownRatio`), or change its value. By default, coolDownRatio is null. +Set `coolDownCapacity` to `101`, nullify coolDownRatio (`acc --set coolDownRatio`), or change its value. By default, `coolDownRatio` is unset/null. -### Logs +### Diagnostics/Logs -Logs are stored at `/sbin/.acc/`. You can export all to `/sdcard/acc-logs-$device.tar.bz2` with `acc --log --export`. In addition to acc logs, the archive includes `charging-ctrl-files.txt`, `charging-voltage-ctrl-files.txt`, `config.txt` and `magisk.log`. +Logs are stored at `/sbin/.acc/`. You can export all to `/sdcard/acc-logs-$device.tar.bz2` with `acc --log --export`. +In addition to acc logs, the archive includes `charging-ctrl-files.txt`, `charging-voltage-ctrl-files.txt`, `config.txt`, `magisk.log`, and everything from `/data/adb/acc-data/logs/`. + +Installation and initialization logs are located at `/data/adb/acc-data/logs/`. + +The existence of `/dev/acc-modpath-not-found` indicates a fatal ACC initialization error. @@ -475,14 +512,15 @@ See current submissions [here](https://www.dropbox.com/sh/rolzxvqxtdkfvfa/AABceZ --- ## LOCALIZATION -Currently Supported Languages +Currently Supported Languages and Translation Statuses - English (en): complete -- Portuguese (pt): partial +- Portuguese, Portugal (pt-PT): partial +- Simplified Chinese (zh-rCN) by zjns @GitHub: mostly complete Translation Notes -- Translators should start with copies of [acc/strings.sh](https://github.com/VR-25/acc/blob/master/acc/strings.sh) and [README.md](https://github.com/VR-25/acc/blob/master/README.md) - and append the appropriate language suffix to the base names - e.g., `strings_it`, `README_it`. +- Translators should start with copies of [acc/strings.sh](https://github.com/VR-25/acc/blob/master/acc/strings.sh) and [README.md](https://github.com/VR-25/acc/blob/master/README.md) - and append the appropriate language code suffix to the base names - e.g., `strings_it`, `README_it`. - Anyone is free and encouraged to open translation [pull requests](https://duckduckgo.com/?q=pull+request). -- Alternatively, `strings_*.sh` and `README_*.md` files can be send to the developer. +- Alternatively, `strings_*.sh` and `README_*.md` files can be sent to the developer. @@ -496,31 +534,32 @@ Control the max USB input current: `applyOnPlug=usb/current_max:MICRO_AMPS` (e.g Force fast charge: `applyOnBoot=/sys/kernel/fast_charge/force_fast_charge:1` -Use voltage control file as charging switch file: `chagingSwitch=FILE DEFAULT_VOLTAGE STOP_VOLTAGE` +Use voltage control file as charging switch file (beta, battery idle mode support): `chagingSwitch=FILE DEFAULT_VOLTAGE STOP_VOLTAGE` (e.g., `chagingSwitch=battery/voltage_max 4380000 3500000`) ### Google Pixel Family Force fast wireless charging with third party wireless chargers that are supposed to charge the battery faster: `applyOnPlug=wireless/voltage_max:9000000`. +Workaround for end-of-charge issues on Android 10: `forceStatusAt100=5`. + ### Razer Phone Alternate charging control configuration: -``` -capacity=5,60,0,101 -applyOnBoot=razer_charge_limit_enable:1 usb/device/razer_charge_limit_max:80 usb/device/razer_charge_limit_dropdown:70 -``` + +`applyOnBoot=razer_charge_limit_enable:1 usb/device/razer_charge_limit_max:80 usb/device/razer_charge_limit_dropdown:70 --exit` + ### Samsung -The following files could be used to control charging current and voltage (with `applyOnBoot`): +The following files could be used for controlling charging current and voltage (with `applyOnBoot` or `applyOnPlug`): ``` -battery/batt_tune_fast_charge_current (default: 2100) +battery/batt_tune_fast_charge_current -battery/batt_tune_input_charge_current (default: 1800) +battery/batt_tune_input_charge_current -battery/batt_tune_float_voltage (max: 4350) +battery/batt_tune_float_voltage ``` @@ -528,37 +567,53 @@ battery/batt_tune_float_voltage (max: 4350) ## FREQUENTLY ASKED QUESTIONS (FAQ) -- How do I report issues? +> How do I report issues? -Open issues on GitHub or contact the developers on Telegram/XDA (linked below). Always provide as much information as possible, and attach `/sdcard/acc-logs-*tar.bz2`. This file is generated automatically. When this doesn't happen, run `acc --log --export` shortly after the problem occurs. +Open issues on GitHub or contact the developer on Telegram/XDA (linked below). Always provide as much information as possible, and attach `/sdcard/acc-logs-*tar.bz2`. This file is generated automatically. When this doesn't happen, run `acc --log --export` _shortly after_ the problem occurs. -- What's "battery idle" mode? +> What's "battery idle" mode? That's a device's ability to draw power directly from an external power supply when charging is disabled or the battery is pulled out. The Motorola Moto G4 Play and many other smartphones can do that. Run `acc -t --` to test yours. -- What's "cool down" capacity for? +> What's "cool down" capacity for? It's meant for reducing stress induced by prolonged high charging voltage (e.g., 4.20 Volts). It's a fair alternative to the charging voltage limit feature. -- Why won't you support my device? I've been waiting for ages! +> Why won't you support my device? I've been waiting for ages! First, never lose hope! Second, several systems don't have intuitive charging control files; I have to dig deeper and improvise; this takes extra time and effort. Lastly, some systems don't support custom charging control at all; in such cases, you have to keep trying different kernels and uploading the respective [power supply logs](https://github.com/VR-25/acc#power-supply-log). +> Why, when and how should I calibrate the battery? + +Refer to https://batteryuniversity.com/index.php/learn/article/battery_calibration + + +> How do I get rid of the annoying screen constantly lighting up issue? + +This is a device-specific issue. Use the app [SnooZZy Charger](http://snoozy.mudar.ca/) to prevent it. + + +> What if even after calibrating the battery, ACC and Android battery level reports still differ? + +It's a software (Android/kernel) issue. Use the `capacityOffset` feature. + + --- ## LINKS - [ACC app](https://github.com/MatteCarra/AccA/releases/) - [Battery University](http://batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries/) +- [Daily Job Scheduler](https://github.com/VR-25/djs/) - [Donate](https://paypal.me/vr25xda/) - [Facebook page](https://facebook.com/VR25-at-xda-developers-258150974794782/) - [Git repository](https://github.com/VR-25/acc/) - [Telegram channel](https://t.me/vr25_xda/) -- [Telegram group](https://t.me/acc/) +- [Telegram group](https://t.me/acc_group/) - [Telegram profile](https://t.me/vr25xda/) - [XDA thread](https://forum.xda-developers.com/apps/magisk/module-magic-charging-switch-cs-v2017-9-t3668427/) @@ -567,6 +622,34 @@ First, never lose hope! Second, several systems don't have intuitive charging co --- ## LATEST CHANGES +**2019.10.13-dev (201910130)** +- `acc-en` executable for front-ends (to ensure acc language is always English) +- `acc -I|--lang`: Show available, as well as the default and currently set languages +- `acc -P|--performance`: accd performance monitor (htop) +- `acc --upgrade`: always use current `installDir` +- Attribute back-end files ownership to front-end app +- Automatically copy installation log to /files/logs/ +- Back-end can be upgraded from Magisk Manager, EX/FK Kernel Manager, and similar apps (alternative to `acc --upgrade`) +- `bundle.sh` - bundler for front-end app +- Default loopDelay: 10,15 (plugged,unplugged) +- Default resume capacity: 75 +- Dynamic power saving and voltage control enhancements +- Enhanced power supply logger (psl.sh) +- Fixed busybox and `loopDelay` handling issues +- Fixed `coolDownRatio` delays +- Flashable uninstaller: `/sdcard/acc-uninstaller.zip` +- `forceStatusAt100=status#`: force android to report a specific battery status (e.g., fully charged, value 5 for Pixel devices) at 100% capacity +- Major optimizations +- Prioritize `nano -l` for text editing +- Renamed `chargingVoltageLimit` variable to `maxChargingVoltage` +- Richer installation and initialization logs (/data/adb/acc-data/logs/) +- Simplified Chinese translation (zh-rCN) by zjns @GitHub +- Updated `build.sh` and documentation +- Updated Telegram group link (`t.me/acc_group/`) +- Use `umask 077` everywhere +- Workaround for front-end autostart blockage (Magisk service.d script) +> Note: this version resets config to default to fix common issues and add new settings. + **2019.7.21-r1 (201907211)** - `acc -f`: fixed "daemon not restarted" issue - `acc -x`: fixed "file not found" error @@ -581,20 +664,3 @@ First, never lose hope! Second, several systems don't have intuitive charging co - `wakeUnlock` enhancements - Updated documentation > Note: this is NOT compatible with AccA 1.0.11-. A new version of the app will be up soon. - -**2019.7.12-dev (201907120)** -- acc --log --acc cat (or -l -a cat): print acc log -- acc -V|--version: prints acc version code -- accd: reverted `acpi -a` usage (unreliable) in `enable_charging()` -- Acceptable charging voltage limit range set to 3500-4350 millivolts -- Additional charging switches and voltage control files -- build.sh: automatically checks syntax; generates `acc_bundle` (.tar.gz) and its installer -- Enhanced debugging features -- FBE support: migrate config to /data/adb/acc-data/config.txt and auto-backup/restore it to/from internal storage as needed -- Fixed `wakeUnlock` permissions -- Initialization scripts also work without absolute paths -- `loopDelay=10,30` (plugged,unplugged) -- Major fixes and optimizations -- Removed `rebootOnUnplug` (unreliable) -- Updated documentation -> Note: this is NOT compatible with AccA 1.0.11-. diff --git a/acc/acc.sh b/acc/acc.sh index 6358165..e416f84 100644 --- a/acc/acc.sh +++ b/acc/acc.sh @@ -66,13 +66,13 @@ edit() { if [ -n "${1:-}" ]; then $@ $file else - nano $file 2>/dev/null || vim $file 2>/dev/null || vi $file + nano -l $file 2>/dev/null || vim $file 2>/dev/null || vi $file fi } set_value() { - local var=$1 PS3="- Which variable do you mean? " + local var=$1 PS3="$(print_var_prompt)" if [ $var == s ]; then var=chargingSwitch else @@ -103,7 +103,7 @@ set_values() { case ${1:-} in 8090|lite) set_value capacity 5,60,80-90;; 9095|travel) set_value capacity 5,60,90-95;; - 7080|default) set_value capacity 5,60,70-80;; + 7580|default) set_value capacity 5,60,75-80;; 5960|endurance) set_value capacity 5,60,59-60;; 4041|endurance+) set_value capacity 5,60,40-41;; r|reset) @@ -274,9 +274,9 @@ switch_loop() { break fi fi - done << SWITCHES + done << EOF $(grep -Ev '#|^$' ${modPath%/*}/switches) -SWITCHES +EOF } @@ -284,7 +284,7 @@ set_charging_voltage() { local setVoltage=false local dVolt=${modPath%/*}/default_voltage - local file=$(get_value chargingVoltageLimit) + local file=$(get_value maxChargingVoltage) local value=${file##*:} local oValue="" file=${file%:*} @@ -334,7 +334,7 @@ set_charging_voltage() { value=$(sed "s/^..../$value/" $file) [ -f $dVolt ] || echo "$file $(sed -n 1p $file)" > $dVolt if chmod +w $file && echo $value > $file 2>/dev/null && grep -q "^$oValue" $file; then - [ x$(get_value chargingVoltageLimit) == x$file:$oValue ] || set_value chargingVoltageLimit $file:$oValue + [ x$(get_value maxChargingVoltage) == x$file:$oValue ] || set_value maxChargingVoltage $file:$oValue print_cvolt_set else print_cvolt_unsupported @@ -369,7 +369,7 @@ $(print_choice_prompt)" set_charging_voltage $file:$1 && success=true || : if $success; then echo - set_value chargingVoltageLimit $file:$1 + set_value maxChargingVoltage $file:$1 print_cvolt_limit_set exit 0 else @@ -384,9 +384,9 @@ ls_charging_switches() { local file="" while IFS= read -r file; do [ ! -f $(echo $file | awk '{print $1}') ] || echo $file - done << SWITCHES + done << EOF $(grep -Ev '#|^$' ${modPath%/*}/switches) -SWITCHES +EOF } @@ -447,14 +447,16 @@ exxit() { local exitCode=$? echo # config backup - [ /data/media/0/.acc-config-backup.txt -nt $config ] \ - || cp $config /data/media/0/.acc-config-backup.txt 2>/dev/null 2>&1 || : + if [ -d /data/media/0/?ndroid ]; then + [ /data/media/0/.acc-config-backup.txt -nt $config ] \ + || install -m 0777 $config /data/media/0/.acc-config-backup.txt 2>/dev/null || : + fi exit $exitCode } echo -umask 0 +umask 077 set -euo pipefail trap exxit EXIT @@ -471,16 +473,17 @@ log=${modPath%/*}/acc-${device}.log # verbose if [[ ${1:-x} == -*x* ]]; then shift - touch $log - [ $(du $log | awk '{print $1}') -lt 50 ] || : > $log - set -x 2>>$log + exec 2>$log + set -x fi batt=$(echo /sys/class/power_supply/*attery/capacity | awk '{print $1}' | sed 's|/capacity||') +# load default strings (English) . $modPath/strings.sh -if [ -f $modPath/strings_$(get_value language).sh ]; then +# load translations +if [[ $0 != *acc-en ]] && [ -f $modPath/strings_$(get_value language).sh ]; then . $modPath/strings_$(get_value language).sh readmeSuffix=_$(get_value language) [ -f ${config%/*}/info/README$readmeSuffix.md ] || readmeSuffix="" @@ -526,6 +529,14 @@ case ${1:-} in -i|--info) sed s/POWER_SUPPLY_// $batt/uevent | sed "/^CAPACITY=/s/=.*/=$(( $(cat $batt/capacity) $(get_value capacityOffset) ))/";; + -I|--lang) + [ $(get_value language) == en ] && echo "- en (default, set)" \ + || echo "- en (default)" + ls -1 $modPath/strings_*.sh \ + | sed -e 's/^.*strings_/- /' -e 's/.sh$//' -e "/$(get_value language)/s/$/ (set)/" + print_set_lang + ;; + -l|--log) shift if [[ "${1:-x}" == -*e* ]]; then @@ -536,9 +547,10 @@ case ${1:-} in for file in /cache/magisk.log /data/cache/magisk.log; do [ -f $file ] && cp $file ./ && break done - cp $config ./ + cp $config ${config%/*}/logs/* ./ tar -c *.log *.txt magisk.log 2>/dev/null | bzip2 -9 > /data/media/0/acc-logs-$device.tar.bz2 - rm *.txt magisk.log 2>/dev/null + chmod 0777 /data/media/0/acc-logs-$device.tar.bz2 + rm *.txt magisk.log in*.log 2>/dev/null echo "(i) /sdcard/acc-logs-$device.tar.bz2" else if [[ "${1:-x}" == -*a* ]]; then @@ -554,7 +566,12 @@ case ${1:-} in -p|--preset) shift - ### + ;; + + -P|--performance) + print_quit + sleep 1.5 + htop -p $(pgrep -f accd.sh) ;; -r|--readme) shift; edit ${config%/*}/info/README$readmeSuffix.md $@;; @@ -570,7 +587,7 @@ case ${1:-} in shift daemon > /dev/null && daemonWasUp=true || daemonWasUp=false set +eo pipefail - pgrep -f '/acc (-|--)[def]|/accd.sh' | xargs kill -9 2>/dev/null + pkill -f '/acc (-|--)[def]|/accd.sh' if [ -z "${1:-}" ]; then test_charging_switch elif [ $1 == -- ]; then @@ -579,9 +596,9 @@ case ${1:-} in e=$? [ $e -eq 0 ] && exitCode=0 [ -z "${exitCode:-}" ] && exitCode=$e - done << SWITCHES + done << EOF $(grep -Ev '^#|^$' ${2:-${modPath%/*}/switches}) -SWITCHES +EOF echo else test_charging_switch $@ @@ -603,8 +620,10 @@ SWITCHES wget https://raw.githubusercontent.com/VR-25/acc/$reference/install-latest.sh \ --output-document ${modPath%/*}/install-latest.sh trap - EXIT - set +euxo pipefail - . ${modPath%/*}/install-latest.sh $@ + set +euo pipefail + installDir=$(readlink -f $modPath) + installDir=${installDir%/*} + . ${modPath%/*}/install-latest.sh $@ %$installDir% ;; -U|--uninstall) diff --git a/acc/accd.sh b/acc/accd.sh index a1f2712..1308289 100644 --- a/acc/accd.sh +++ b/acc/accd.sh @@ -23,34 +23,65 @@ get_value() { sed -n "s|^$1=||p" $config; } is_charging() { - local file="" value="" isCharging=true wakelock="" + local file="" value="" isCharging=false - grep -Eiq 'dis|not' $batt/status && isCharging=false || : + grep -Eiq 'dis|not' $batt/status || isCharging=true if $isCharging; then $coolDown || resetBsOnUnplug=true secondsUnplugged=0 + # applyOnPlug for file in $(get_value applyOnPlug); do value=${file##*:} file=${file%:*} [ -f $file ] && chmod +w $file && echo $value > $file || : done + file=$(get_value maxChargingVoltage) + if [[ "$file" == */* ]]; then + value=${file##*:} + file=${file%:*} + value=$(sed "s/^..../$value/" $file) + chmod +w $file && echo $value > $file || : + fi + + # forceStatusAt100 + if ! $forcedStatusAt100 && [[ "$(get_value forceStatusAt100)" == [0-9]* ]] && [ $(cat $batt/capacity) -gt 99 ]; then + dumpsys battery set level 100 + dumpsys battery set status $(get_value forceStatusAt100) + forcedStatusAt100=true + frozenBattSvc=true + fi + else - # resetBsOnUnplug - if $resetBsOnUnplug && eval $(get_value resetBsOnUnplug); then - sleep $(get_value loopDelay | cut -d, -f2) - if grep -iq dis $batt/status; then - dumpsys batterystats --reset > /dev/null 2>&1 || : - rm /data/system/batterystats* 2>/dev/null || : - resetBsOnUnplug=false - fi + + # revert forceStatusAt100 + if $frozenBattSvc; then + dumpsys battery reset + frozenBattSvc=false + forcedStatusAt100=false fi - # dynamic power saving + if ! $coolDown; then + + # resetBsOnUnplug + if $resetBsOnUnplug && eval $(get_value resetBsOnUnplug); then + sleep $(get_value loopDelay | cut -d, -f2) + if grep -iq dis $batt/status; then + dumpsys batterystats --reset > /dev/null 2>&1 || : + rm /data/system/batterystats* 2>/dev/null || : + resetBsOnUnplug=false + fi + fi + + # dynamic power saving + if [ $secondsUnplugged == 0 ]; then + [ $(( $(get_value capacity | cut -d, -f3 | cut -d- -f2) - $(get_value capacity | cut -d, -f3 | cut -d- -f1) )) -gt 4 ] \ + && hibernate=true || hibernate=false + fi secondsUnplugged=$(( secondsUnplugged + $(get_value loopDelay | cut -d, -f2) )) - sleep $secondsUnplugged - [ $secondsUnplugged -lt 60 ] || secondsUnplugged=0 + ! $hibernate || sleep $secondsUnplugged + [ $secondsUnplugged -lt 120 ] || secondsUnplugged=0 else secondsUnplugged=0 fi @@ -87,7 +118,7 @@ disable_charging() { fi ! is_charging || echo "(!) Failed to disable charging" fi - # cool down + # if maxTemp is reached, pause charging regardless of coolDownRatio ! is_charging && [ $(( $(cat $batt/temp 2>/dev/null || cat $batt/batt_temp) / 10 )) -ge $(get_value temperature | cut -d- -f2 | cut -d_ -f1) ] \ && sleep $(get_value temperature | cut -d- -f2 | cut -d_ -f2) || : } @@ -114,60 +145,75 @@ enable_charging() { ctrl_charging() { - local count=0 + local count=0 wakelock="" while :; do if is_charging; then - # disable charging & reset battery stats under + + # clear "rebooted on pause" flag + [ $(( $(cat $batt/capacity) $(get_value capacityOffset) )) -gt $(get_value capacity | cut -d, -f3 | cut -d- -f1) ] \ + || rm ${config%/*}/.rebootedOnPause 2>/dev/null || : + + # disable charging under if [ $(( $(cat $batt/temp 2>/dev/null || cat $batt/batt_temp) / 10 )) -ge $(get_value temperature | cut -d- -f2 | cut -d_ -f1) ] \ || [ $(( $(cat $batt/capacity) $(get_value capacityOffset) )) -ge $(get_value capacity | cut -d, -f3 | cut -d- -f2) ] then - disable_charging - if eval $(get_value resetBsOnPause); then - # reset battery stats - dumpsys batterystats --reset > /dev/null 2>&1 || : - rm /data/system/batterystats* 2>/dev/null || : + if [ ! -f ${config%/*}/.rebootedOnPause ]; then + disable_charging + if eval $(get_value resetBsOnPause); then + + # reset battery stats + dumpsys batterystats --reset > /dev/null 2>&1 || : + rm /data/system/batterystats* 2>/dev/null || : + fi fi + # rebootOnPause sleep $(get_value rebootOnPause) 2>/dev/null \ && [ $(( $(cat $batt/capacity) $(get_value capacityOffset) )) -ge $(get_value capacity | cut -d, -f3 | cut -d- -f2) ] \ && [ ! -f ${config%/*}/.rebootedOnPause ] \ && touch ${config%/*}/.rebootedOnPause \ && reboot || : - # wakeUnlock - # won't run under "battery idle" mode ("not charging" status) - if grep -iq dis $batt/status && chmod +w /sys/power/wake_unlock; then - for wakelock in $(get_value wakeUnlock); do - echo $wakelock > /sys/power/wake_unlock || : - done - fi 2>/dev/null - fi - # cool down - while [[ x$(get_value coolDownRatio) == */* ]] && is_charging \ - && [ $(( $(cat $batt/capacity) $(get_value capacityOffset) )) -lt $(get_value capacity | cut -d, -f3 | cut -d- -f2) ] \ - && [ $(( $(cat $batt/temp 2>/dev/null || cat $batt/batt_temp) / 10 )) -lt $(get_value temperature | cut -d- -f2 | cut -d_ -f1) ] - do - coolDown=true - if [ $(( $(cat $batt/temp 2>/dev/null || cat $batt/batt_temp) / 10 )) -ge $(get_value temperature | cut -d- -f1) ] \ - || [ $(( $(cat $batt/capacity) $(get_value capacityOffset) )) -ge $(get_value capacity | cut -d, -f2) ] - then - disable_charging - sleep $(get_value coolDownRatio | cut -d/ -f2) - enable_charging - count=0 - while [ $count -lt $(get_value coolDownRatio | cut -d/ -f1) ]; do - sleep $(get_value loopDelay | cut -d, -f1) - [ $(( $(cat $batt/capacity) $(get_value capacityOffset) )) -lt $(get_value capacity | cut -d, -f3 | cut -d- -f2) ] \ - && [ $(( $(cat $batt/temp 2>/dev/null || cat $batt/batt_temp) / 10 )) -lt $(get_value temperature | cut -d- -f2 | cut -d_ -f1) ] \ - && count=$(( count + $(get_value loopDelay | cut -d, -f1) )) || break - done - else - break + if [ ! -f ${config%/*}/.rebootedOnPause ]; then + # wakeUnlock + # won't run under "battery idle" mode ("not charging" status) + if grep -iq dis $batt/status && chmod +w /sys/power/wake_unlock; then + for wakelock in $(get_value wakeUnlock); do + echo $wakelock > /sys/power/wake_unlock || : + done + fi 2>/dev/null fi - done - coolDown=false + fi + + if [ ! -f ${config%/*}/.rebootedOnPause ]; then + # cool down + while [[ x$(get_value coolDownRatio) == */* ]] && is_charging \ + && [ $(( $(cat $batt/capacity) $(get_value capacityOffset) )) -lt $(get_value capacity | cut -d, -f3 | cut -d- -f2) ] \ + && [ $(( $(cat $batt/temp 2>/dev/null || cat $batt/batt_temp) / 10 )) -lt $(get_value temperature | cut -d- -f2 | cut -d_ -f1) ] + do + coolDown=true + if [ $(( $(cat $batt/temp 2>/dev/null || cat $batt/batt_temp) / 10 )) -ge $(get_value temperature | cut -d- -f1) ] \ + || [ $(( $(cat $batt/capacity) $(get_value capacityOffset) )) -ge $(get_value capacity | cut -d, -f2) ] + then + disable_charging + sleep $(get_value coolDownRatio | cut -d/ -f2) + enable_charging + count=0 + while [ $count -lt $(get_value coolDownRatio | cut -d/ -f1) ]; do + sleep $(get_value loopDelay | cut -d, -f1) + [ $(( $(cat $batt/capacity) $(get_value capacityOffset) )) -lt $(get_value capacity | cut -d, -f3 | cut -d- -f2) ] \ + && [ $(( $(cat $batt/temp 2>/dev/null || cat $batt/batt_temp) / 10 )) -lt $(get_value temperature | cut -d- -f2 | cut -d_ -f1) ] \ + && count=$(( count + $(get_value loopDelay | cut -d, -f1) )) || break + done + else + break + fi + done + coolDown=false + fi + sleep $(get_value loopDelay | cut -d, -f1) else # enable charging under @@ -175,11 +221,13 @@ ctrl_charging() { && [ $(( $(cat $batt/temp 2>/dev/null || cat $batt/batt_temp) / 10 )) -lt $(get_value temperature | cut -d- -f2 | cut -d_ -f1) ] then enable_charging - rm ${config%/*}/.rebootedOnPause 2>/dev/null || : fi # auto-shutdown if battery is not charging and capacity is less than if ! is_charging && [ $(( $(cat $batt/capacity) $(get_value capacityOffset) )) -le $(get_value capacity | cut -d, -f1) ]; then - reboot -p || : + sleep $(get_value loopDelay | cut -d, -f2) + is_charging \ + || am start -n android/com.android.internal.app.ShutdownActivity 2>/dev/null \ + || reboot -p || : fi fi @@ -215,17 +263,20 @@ switch_loop() { break fi fi - done << SWITCHES + done << EOF $(grep -Ev '#|^$' ${modPath%/*}/switches) -SWITCHES +EOF } -umask 0 +umask 077 coolDown=false +hibernate=true secondsUnplugged=0 +frozenBattSvc=false resetBsOnUnplug=false modPath=/sbin/.acc/acc +forcedStatusAt100=false config=/data/adb/acc-data/config.txt if [ ! -f $modPath/module.prop ]; then @@ -239,8 +290,10 @@ cd /sys/class/power_supply/ [ -f $config ] || cp $modPath/default-config.txt $config # config backup -[ /data/media/0/.acc-config-backup.txt -nt $config ] \ - || cp $config /data/media/0/.acc-config-backup.txt 2>/dev/null +if [ -d /data/media/0/?ndroid ]; then + [ /data/media/0/.acc-config-backup.txt -nt $config ] \ + || install -m 0777 $config /data/media/0/.acc-config-backup.txt 2>/dev/null +fi batt=$(echo /sys/class/power_supply/*attery/capacity | awk '{print $1}' | sed 's|/capacity||') log=${modPath%/*}/accd-$(getprop ro.product.device | grep .. || getprop ro.build.product).log @@ -258,9 +311,5 @@ apply_on_boot (/sbin/acc --voltage apply > /dev/null 2>&1) || : unset -f apply_on_boot -# clear "rebooted on pause" flag -[ $(( $(cat $batt/capacity) $(get_value capacityOffset) )) -gt $(get_value capacity | cut -d, -f3 | cut -d- -f1) ] \ - || rm ${config%/*}/.rebootedOnPause 2>/dev/null || : - ctrl_charging exit $? diff --git a/acc/busybox.sh b/acc/busybox.sh index 6760efe..ba261e4 100644 --- a/acc/busybox.sh +++ b/acc/busybox.sh @@ -1,16 +1,21 @@ -# Set up busybox +# Busybox Setup +# Copyright (c) 2019, VR25 (xda-developers) +# License: GPLv3+ -if [[ $PATH != *busybox:* ]]; then - if [ -d /sbin/.magisk/busybox ]; then - PATH=/sbin/.magisk/busybox:$PATH - elif [ -d /sbin/.core/busybox ]; then - PATH=/sbin/.core/busybox:$PATH - elif which busybox > /dev/null; then - mkdir -p -m 700 /dev/.busybox - busybox install -s /dev/.busybox - PATH=/dev/.busybox:$PATH - else - echo "(!) Install busybox binary first" - exit 3 +if [ -d /sbin/.magisk/busybox ]; then + [[ $PATH == /sbin/.magisk/busybox* ]] || PATH=/sbin/.magisk/busybox:$PATH +elif [ -d /sbin/.core/busybox ]; then + [[ $PATH == /sbin/.core/busybox* ]] || PATH=/sbin/.core/busybox:$PATH +else + [[ $PATH == /dev/.busybox* ]] || PATH=/dev/.busybox:$PATH + if ! mkdir -m 700 /dev/.busybox 2>/dev/null; then + if [ -x /data/adb/magisk/busybox ]; then + /data/adb/magisk/busybox --install -s /dev/.busybox + elif which busybox > /dev/null; then + busybox --install -s /dev/.busybox + else + echo "(!) Install busybox binary first" + exit 3 + fi fi fi diff --git a/acc/default-config.txt b/acc/default-config.txt index 2506e95..dd0c5da 100644 --- a/acc/default-config.txt +++ b/acc/default-config.txt @@ -1,18 +1,19 @@ -versionCode=201907090 -capacity=0,60,70-80 +versionCode=201910130 +capacity=0,60,75-80 capacityOffset=+0 capacitySync=false -temperature=40-45_90 +temperature=70-80_90 coolDownRatio= -resetBsOnPause=true +resetBsOnPause=false resetBsOnUnplug=false -loopDelay=10,30 +loopDelay=10,15 chargingSwitch= applyOnBoot= applyOnPlug= -chargingVoltageLimit= +maxChargingVoltage= rebootOnPause= chargingOnOffDelay=1 language=en wakeUnlock= prioritizeBattIdleMode=false +forceStatusAt100= diff --git a/acc/psl.sh b/acc/psl.sh index 87148ae..6792e5d 100644 --- a/acc/psl.sh +++ b/acc/psl.sh @@ -1,25 +1,24 @@ -#!/system/bin/sh # Advanced Charging Controller Power Supply Logger -# Copyright (C) 2019, VR25 @ xda-developers +# 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 if [ -f $1/$target ]; then - if echo $1/$target | grep -Ev 'logg|(/|_|-)log' | grep -Eq 'batt|ch.*rg|power_supply'; then + if echo $1/$target | grep -Ev 'logg|(/|_|-)log' | grep -Eq 'batt|charg|power_supply'; then echo $1/$target - sed 's/^/ /' $1/$target 2>/dev/null || : + sed 's/^/ /' $1/$target 2>/dev/null echo fi elif [ -d $1/$target ]; then for target2 in $(find $1/$target \( \( -type f -o -type d \) \ - -a \( -ipath '*batt*' -o -ipath '*ch*rg*' -o -ipath '*power_supply*' \) \) \ - -print 2>/dev/null || :) + -a \( -ipath '*batt*' -o -ipath '*charg*' -o -ipath '*power_supply*' \) \) \ + -print 2>/dev/null | grep -Ev 'logg|(/|_|-)log') do if [ -f $target2 ]; then echo $target2 - sed 's/^/ /' $target2 2>/dev/null || : + sed 's/^/ /' $target2 2>/dev/null echo fi done @@ -27,8 +26,8 @@ gather_ps_data() { done } +umask 077 log=/sbin/.acc/acc-power_supply-$(getprop ro.product.device | grep .. || getprop ro.build.product).log -mkdir -p /sbin/.acc { date diff --git a/acc/service.sh b/acc/service.sh index 3dd621b..689f007 100644 --- a/acc/service.sh +++ b/acc/service.sh @@ -3,29 +3,39 @@ # Copyright (c) 2017-2019, VR25 (xda-developers) # License: GPLv3+ +set +x +id=acc +umask 077 + +# log +mkdir -p /data/adb/${id}-data/logs +exec > /data/adb/${id}-data/logs/init.log 2>&1 +set -x + [ -f $PWD/${0##*/} ] && modPath=$PWD || modPath=${0%/*} . $modPath/busybox.sh -modId=$(sed -n 's/^id=//p' $modPath/module.prop) # prepare working directory -([ -d /sbin/.$modId ] && [[ ${1:-x} != -*o* ]] && exit 0 +([ -d /sbin/.$id ] && [[ ${1:-x} != -*o* ]] && exit 0 if ! mount -o remount,rw /sbin 2>/dev/null; then cp -a /sbin /dev/.sbin mount -o bind,rw /dev/.sbin /sbin + restorecon -R /sbin > /dev/null 2>&1 fi -mkdir -p /sbin/.$modId -[ -h /sbin/.$modId/$modId ] && rm /sbin/.$modId/$modId \ - || rm -rf /sbin/.$modId/$modId 2>/dev/null +mkdir -p /sbin/.$id +[ -h /sbin/.$id/$id ] && rm /sbin/.$id/$id \ + || rm -rf /sbin/.$id/$id 2>/dev/null [ ${MAGISK_VER_CODE:-18200} -gt 18100 ] \ - && ln -s $modPath /sbin/.$modId/$modId \ - || cp -a $modPath /sbin/.$modId/$modId -ln -fs /sbin/.$modId/$modId/$modId.sh /sbin/$modId -ln -fs /sbin/.$modId/$modId/${modId}d-start.sh /sbin/${modId}d -ln -fs /sbin/.$modId/$modId/${modId}d-status.sh /sbin/${modId}d, -ln -fs /sbin/.$modId/$modId/${modId}d-stop.sh /sbin/${modId}d. + && ln -s $modPath /sbin/.$id/$id \ + || cp -a $modPath /sbin/.$id/$id +ln -fs /sbin/.$id/$id/$id.sh /sbin/$id +ln -fs /sbin/.$id/$id/$id.sh /sbin/${id}-en +ln -fs /sbin/.$id/$id/${id}d-start.sh /sbin/${id}d +ln -fs /sbin/.$id/$id/${id}d-status.sh /sbin/${id}d, +ln -fs /sbin/.$id/$id/${id}d-stop.sh /sbin/${id}d. # generate power supply log -($modPath/psl.sh $(sed -n s/versionCode=//p $modPath/module.prop) &) & +(. $modPath/psl.sh $(sed -n s/versionCode=//p $modPath/module.prop) &) & # fix termux's PATH termuxSu=/data/data/com.termux/files/usr/bin/su @@ -35,9 +45,9 @@ if [ -f $termuxSu ] && grep -q 'PATH=.*/sbin/su' $termuxSu; then rm $termuxSu.tmp fi -# exclude charging switches with unknown values +# exclude charging switches with odd values (cd /sys/class/power_supply/ -: > /sbin/.$modId/switches +: > /sbin/.$id/switches while IFS= read -r file; do if [ -f $(echo $file | awk '{print $1}') ]; then on=$(echo $file | awk '{print $2}') @@ -45,18 +55,17 @@ while IFS= read -r file; do file=$(echo $file | awk '{print $1}') chmod +r $file 2>/dev/null if grep -Eq "^($on|$off)$" $file || ! cat $file; then - echo "$file $on $off" >> /sbin/.$modId/switches + echo "$file $on $off" >> /sbin/.$id/switches fi > /dev/null 2>&1 fi -done << SWITCHES +done << EOF $(grep -Ev '#|^$' $modPath/switches.txt) -SWITCHES +EOF ) -# start ${modId}d -unset file termuxSu +# start ${id}d (sleep 30 -kill -9 $(pgrep -f /psl.sh) 2>/dev/null &) & -$modPath/${modId}d.sh &) & +pkill -9 -f /psl.sh 2>/dev/null &) & +$modPath/${id}d.sh &) & exit 0 diff --git a/acc/strings.sh b/acc/strings.sh index 4eae83d..96c61aa 100644 --- a/acc/strings.sh +++ b/acc/strings.sh @@ -59,7 +59,7 @@ print_ch_disabled() { } print_ch_enabled_until() { - echo "(i) Charging enabled until battery capacity <= $1" + echo "(i) Charging enabled until battery capacity >= $1" } print_ch_enabled_for() { @@ -132,7 +132,7 @@ print_no_modpath() { } print_help() { - cat << HELP + cat << EOF Advanced Charging Controller Copyright (c) 2017-2019, VR25 (xda-developers.com) License: GPLv3+ @@ -165,6 +165,9 @@ Usage: acc <-x|--xtrace> -i|--info Show power supply info e.g., acc -i +-I|--lang Show available, as well as the default and currently set languages + e.g., acc -I + -l|--log <-a|--acc> Open accd log (default) or acc log (-a) w/ (default: nano|vim|vi) e.g., acc -l grep ': ' (show explicit errors only) @@ -174,6 +177,9 @@ Usage: acc <-x|--xtrace> -L|--logwatch Monitor accd log in realtime e.g., acc -L +-P|--performance Monitor de performance do accd (htop) + e.g., acc -P + -r|--readme Open w/ (default: vim|vi) e.g., acc -r @@ -191,11 +197,11 @@ Usage: acc <-x|--xtrace> acc -s capacity 5,60,80-85 (5: shutdown, 60: cool down, 80: resume, 85: pause) acc -s cool 55/15 --s|--set Can be 4041|endurance+, 5960|endurance, 7080|default, 8090|lite 9095|travel +-s|--set Can be 4041|endurance+, 5960|endurance, 7580|default, 8090|lite, 9095|travel e.g., acc -s endurance+ (a.k.a, "the li-ion sweet spot"; best for GPS navigation and other long operations) acc -s travel (for when you need extra juice) - acc -s 7080 (restore default capacity settings (5,60,70-80)) + acc -s 7580 (restore default capacity settings (5,60,75-80)) -s|--set Set a different charging switch from the database e.g., acc -s s @@ -219,7 +225,7 @@ Usage: acc <-x|--xtrace> Exit codes: 0 (works), 1 (doesn't work) or 2 (battery must be charging) e.g., acc -t -- /sdcard/experimental_switches.txt --u|--upgrade [-c|--changelog|-f|--force|-n|--non-interactive] [reference] Upgrade/downgrade +-u|--upgrade [-c|--changelog] [-f|--force] [-n|--non-interactive] Upgrade/downgrade e.g., acc -u dev (upgrade to the latest dev version) acc -u (latest stable release) @@ -259,13 +265,13 @@ Tips e.g., acc 85 80 That last command can be used for programming charging before bed. In this case, the daemon must be running. - e.g., acc 45 44 && acc --set applyOnPlug usb/current_max:500000 && sleep $((60*60*7)) && acc 80 70 && acc --set applyOnPlug usb/current_max:2000000 + e.g., acc 45 44 && acc --set applyOnPlug usb/current_max:500000 && sleep $((60*60*7)) && acc 80 75 && acc --set applyOnPlug usb/current_max:2000000 - "Keep battery capacity at ~45% and limit charging current to 500mA for 7 hours. Restore regular charging settings afterwards." - For convenience, this can be written to a file and ran as "sh ". - If your device supports custom charging voltage, it's better to use it instead: "acc -v 3920 && sleep $((60*60*7)) && acc -v -". Run acc --readme to see the full documentation. -HELP +EOF } print_exit() { @@ -283,3 +289,15 @@ print_auto() { print_default() { echo Default } + +print_quit() { + echo "(i) Press q to quit" +} + +print_set_lang() { + echo -e "\n(i) Run \"acc -s lang STRING\" to change (e.g., \"acc -s lang fr\")" +} + +print_var_prompt() { + echo "- Which variable do you mean? " +} diff --git a/acc/strings_pt.sh b/acc/strings_pt-PT.sh similarity index 88% rename from acc/strings_pt.sh rename to acc/strings_pt-PT.sh index eadb03e..03fd567 100644 --- a/acc/strings_pt.sh +++ b/acc/strings_pt-PT.sh @@ -59,11 +59,11 @@ print_ch_disabled() { } print_ch_enabled_until() { - echo "(i) Recarga ativada até $1" + echo "(i) Recarga ativada até % >= $1" } print_ch_enabled_for() { - echo "(i) Recarga ativad por $1" + echo "(i) Recarga ativada por $1" } print_ch_enabled() { @@ -84,7 +84,7 @@ print_invalid_input() { } print_accepted_volt() { - echo "- O intervalo permitido é 3500-4350 millivolts" + echo "- O intervalo permitido é 3500-4350 milivolts" } print_cvolt_set() { @@ -128,11 +128,11 @@ print_no_modpath() { } print_help() { - cat << DELIMITADOR + cat << EOF Advanced Charging Controller Copyright (c) 2017-2019, VR25 (xda-developers.com) Licença: GPLv3+ -Versão: $(sed -n 's/versionCode=//p' $modPath/module.prop) +Código de versão: $(sed -n 's/versionCode=//p' $modPath/module.prop) Uso: acc <-x|--xtrace> @@ -161,6 +161,9 @@ Uso: acc <-x|--xtrace> -i|--info Show power supply info Exemplo: acc -i +-I|--lang Show available, as well as the default and currently set languages + e.g., acc -I + -l|--log <-a|--acc> Open accd log (default) or acc log (-a) w/ (default: nano|vim|vi) e.g., acc -l grep ': ' (show explicit errors only) @@ -170,6 +173,9 @@ Uso: acc <-x|--xtrace> -L|--logwatch Monitor accd log in realtime Exemplo: acc -L +-P|--performance Monitor de performance do accd (htop) + e.g., acc -P + -r|--readme Open w/ (default: vim|vi) Exemplo: acc -r @@ -187,11 +193,11 @@ Uso: acc <-x|--xtrace> acc -s capacity 5,60,80-85 (5: shutdown, 60: cool down, 80: resume, 85: pause) acc -s cool 55/15 --s|--set Can be 4041|endurance+, 5960|endurance, 7080|default, 8090|lite 9095|travel +-s|--set Can be 4041|endurance+, 5960|endurance, 7580|default, 8090|lite 9095|travel Exemplos: acc -s endurance+ (a.k.a, "the li-ion sweet spot"; best for GPS navigation and other long operations) acc -s travel (for when you need extra juice) - acc -s 7080 (restore default capacity settings (5,60,70-80)) + acc -s 7580 (restore default capacity settings (5,60,75-80)) -s|--set Set a different charging switch from the database Exemplo: acc -s s @@ -215,7 +221,7 @@ Uso: acc <-x|--xtrace> Exit codes: 0 (works), 1 (doesn't work) or 2 (battery must be charging) e.g., acc -t -- /sdcard/experimental_switches.txt --u|--upgrade [-c|--changelog|-f|--force|-n|--non-interactive] [reference] Upgrade/downgrade +-u|--upgrade [-c|--changelog] [-f|--force] [-n|--non-interactive] [reference] Upgrade/downgrade e.g., acc -u dev (upgrade to the latest dev version) acc -u (latest stable release) @@ -255,13 +261,13 @@ Tips e.g., acc 85 80 That last command can be used for programming charging before bed. In this case, the daemon must be running. - e.g., acc 45 44 && acc --set applyOnPlug usb/current_max:500000 && sleep $((60*60*7)) && acc 80 70 && acc --set applyOnPlug usb/current_max:2000000 + e.g., acc 45 44 && acc --set applyOnPlug usb/current_max:500000 && sleep $((60*60*7)) && acc 80 75 && acc --set applyOnPlug usb/current_max:2000000 - "Keep battery capacity at ~45% and limit charging current to 500mA for 7 hours. Restore regular charging settings afterwards." - For convenience, this can be written to a file and ran as "sh ". - If your device supports custom charging voltage, it's better to use it instead: "acc -v 3920 && sleep $((60*60*7)) && acc -v -". Execute "acc --readme" para ler a documentação completa. -DELIMITADOR +EOF } print_exit() { @@ -279,3 +285,15 @@ print_auto() { print_default() { echo Predefinição } + +print_quit() { + echo "(i) Pressione q para sair" +} + +print_set_lang() { + echo -e "\n(i) Execute \"acc -s lang STRING\" p/ mudar o idioma (exemplo: \"acc -s lang fr\")" +} + +print_var_prompt() { + echo "- Qual das variáveis? " +} diff --git a/acc/strings_zh-rCN.sh b/acc/strings_zh-rCN.sh new file mode 100644 index 0000000..56353ff --- /dev/null +++ b/acc/strings_zh-rCN.sh @@ -0,0 +1,303 @@ +print_already_running() { + echo "(i) accd 已处于运行状态" +} + +print_started() { + echo "(i) accd 已启动" +} + +print_stopped() { + echo "(i) accd 已停止" +} + +print_not_running() { + echo "(i) accd 当前没有运行" +} + +print_restarted() { + echo "(i) accd 已重启" +} + +print_is_running() { + echo "(i) accd 正在运行" +} + +print_invalid_var() { + echo "(!) 无效变量, [$var]" +} + +print_config_reset() { + echo "(i) 配置已重置" +} + +print_cs_reset() { + echo "(i) 充电开关已设置为 \"自动\"" +} + +print_supported_cs() { + echo "(i) 充电开关可用" +} + +print_cs_fails() { + echo "(!) [$(get_value chargingSwitch)] 不可用" +} + +print_invalid_cs() { + echo "(!) 无效充电开关, [$(get_value chargingSwitch)]" +} + +print_ch_disabled_until() { + echo "(i) 电量高于 $1 时停止充电" +} + +print_ch_disabled_for() { + echo "(i) 停止充电 $1" +} + +print_ch_disabled() { + echo "(i) 已停止充电" +} + +print_ch_enabled_until() { + echo "(i) 电量高于 $1 时继续充电" +} + +print_ch_enabled_for() { + echo "(i) 开始充电 $1" +} + +print_ch_enabled() { + echo "(i) 已开始充电" +} + + +print_dvolt_restored() { + echo "(i) 已成功还原默认充电电压阈值为 ($(grep -o '^....' $file)mV)" +} + +print_dvolt_already_set() { + echo "(i) 充电电压阈值已经重置为默认值" +} + +print_invalid_input() { + echo "(!) 无效输入, [$@]" +} + +print_accepted_volt() { + echo "- 注意, 电压的有效值在3500至4350毫伏之间" +} + +print_cvolt_set() { + echo "(i) 充电电压阈值已设置为 $(grep -o '^....' $file)mV" +} + +print_cvolt_unsupported() { + echo "(!) [$(echo -n $file)] 不是有效的文件,或者您的内核不支持自定义充电电压" +} + +print_no_such_file() { + echo "(!) [$file] 不存在" +} + +print_supported_cvolt_files() { + echo "(i) 充电电压控制文件可用" +} + +print_cvolt_limit_set() { + echo "(i) chargingVoltageLimit=$file:$1 --> config.txt" +} + +print_unplugged() { + echo "(!) 需要设备处于充电状态" +} + +print_file_works() { + echo "(i) [$file $on $off] 可用" +} + +print_file_fails() { + echo "(!) [$file $on $off] 不可用" +} + +print_supported() { + echo "(i) 设备受支持" +} + +print_unsupported() { + echo "(!) 设备不受支持" +} + +print_no_modpath() { + echo "(!) 未找到 modPath 目录" +} + +print_help() { + cat << HELP +高级充电控制器 +Copyright (c) 2017-2019, VR25 (xda-developers.com) +协议: GPLv3+ +版本号: $(sed -n 's/versionCode=//p' $modPath/module.prop) + +示例: acc <-x|--xtrace> + +-c|--config 使用指定编辑器修改配置 (默认编辑器: nano|vim|vi) + 例如, acc -c + +-d|--disable <#%, #s, #m or #h (可选)> 停止充电, 可以不加条件 + 例如, + acc -d 70% (电量降至70%后再充电) + acc -d 1h (1小时后再充电) + +-D|--daemon 显示当前 acc 后台程序 (accd) 状态 + 例如, acc -D (别名: "accd,") + +-D|--daemon 管理 accd 状态 + 例如, + acc -D restart + accd -D stop (别名: "accd.") + +-e|--enable <#%, #s, #m or #h (可选)> 充电或在指定条件下充电 + 例如, acc -e 30m (充电30分钟) + +-f|--force|--full <电量值> 不间断充电至指定电量, 默认充满 + 例如, acc -f 95 + +-i|--info 显示电源信息 + 例如, acc -i + +-I|--lang Show available, as well as the default and currently set languages + 例如, acc -I + +-l|--log <-a|--acc> 使用指定编辑器查看 accd 日志(默认)或者 acc 日志(-a) (默认编辑器: nano|vim|vi) + 例如, acc -l grep ': ' (仅显示显式错误) + +-l|--log -e|--export 导出所有日志至 /sdcard/acc-logs-.tar.bz2 + 例如, acc -l -e + +-L|--logwatch 实时查看 accd 日志 + 例如, acc -L + +-P|--performance Monitor de performance do accd (htop) + 例如, acc -P + +-r|--readme 使用指定编辑器打开 README.md (默认编辑器: vim|vi) + 例如, acc -r + +-R|--resetbs 重置电池状态 + 例如, acc -R + +-s|--set 显示当前配置 + 例如, acc -s + +-s|--set 恢复默认配置 + 例如, acc -s r + +-s|--set 设置配置参数 (可选: -s|--set (可交互)) + 例如, + acc -s capacity 5,60,80-85 (5: 关机, 60: 冷却, 80: 恢复, 85: 暂停) + acc -s cool 55/15 + +-s|--set 可以为 4041|endurance+, 5960|endurance, 7580|default, 8090|lite, 9095|travel + 例如, + acc -s endurance+ (换言之, "锂电池最佳工作状态"; 最适合 GPS 导航和其他长时间操作) + acc -s travel (当你需要榨干电池时) + acc -s 7580 (恢复默认电量设置 (5,60,75-80)) + +-s|--set 从数据库中设置不同的充电开关 + 例如, acc -s s + +-s|--set 列出可用的充电开关 + 例如, acc -s s: + +-s|--set 复位充电开关 + 例如, acc -s s- + +-t|--test 测试当前设置的充电控制文件 + 退出码: 0 (可用), 1 (不可用) 或 2 (需要充电状态) + 例如, acc -t + +-t|--test 测试指定的充电控制文件 + 退出码: 0 (可用), 1 (不可用) 或 2 (需要充电状态) + 例如, acc -t battery/charging_enabled 1 0 + +-t|--test -- 从指定文件测试充电开关 + 这还将报告是否支持 "电池空闲" 模式 + 退出码: 0 (可用), 1 (不可用) 或 2 (需要充电状态) + 例如, acc -t -- /sdcard/experimental_switches.txt + +-u|--upgrade [-c|--changelog|-f|--force|-n|--non-interactive] [reference] 升级/降级 + 例如, + acc -u dev (升级至最新开发版本) + acc -u (最新稳定版本) + acc -u master^1 -f (前一个稳定版本) + acc -u -f dev^2 (低于最新开发版本的倒数第三个开发版本) + acc -u 201905110 --force (2019.5.11 版本) + +-U|--uninstall 卸载 + +-v|--voltage 显示当前充电电压 + 例如, acc -v + +-v|--voltage : 列出可用/默认充电电压控制文件 + 例如, acc -v : + +-v|--voltage - 恢复默认充电电压阈值 + 例如, acc -v - + +-v|--voltage 设置充电电压阈值 (默认/已设置控制文件) + 例如, acc -v 4100 + +-v|--voltage 设置充电电压阈值 (自定义控制文件) + 例如, acc -v battery/voltage_max:4100 + +-V|--version 显示 acc 版本号 + 例如, acc -V + +-x|--xtrace 运行为调试模式 (记录详细信息) + 例如, acc -x -t -- + +提示 + + 可以为扩展功能拼接命令. + 例如, acc -e 30m && acc -d 6h && acc -e 85 && accd (充电半小时, 中断充电6小时, 继续充电至85%并重启后台程序) + + 也可以通过 'acc ' 命令设置暂停和恢复充电时的电量. + 例如, acc 85 80 + + 最后一个命令可以用于在睡觉前编排充电。在这种情况下,后台程序必须处于运行状态. + 例如, acc 45 44 && acc --set applyOnPlug usb/current_max:500000 && sleep $((60*60*7)) && acc 80 75 && acc --set applyOnPlug usb/current_max:2000000 + - "保持电池容量在45%左右, 并将充电电流限制在500毫安, 持续7小时. 之后恢复常规充电设置." + - 为了方便起见, 可以将其写入文件并使用"sh "运行. + - 如果你的设备支持自定义充电电压阈值, 最好使用如下命令代替: "acc -v 3920 && sleep $((60*60*7)) && acc -v -". + +运行 acc --readme 查看完整的文档. +HELP +} + +print_exit() { + echo "退出" +} + +print_choice_prompt() { + echo "(?) 请选择, 回车键结束: " +} + +print_auto() { + echo "自动" +} + +print_default() { + echo "默认" +} + +print_quit() { + echo "(i) Press q to quit" +} + +print_set_lang() { + echo -e "\n(i) Run \"acc -s lang STRING\" to change (e.g., \"acc -s lang fr\")" +} + +print_var_prompt() { + echo "- Which variable do you mean? " +} diff --git a/acc/uninstall.sh b/acc/uninstall.sh index aff56d0..8e450a9 100644 --- a/acc/uninstall.sh +++ b/acc/uninstall.sh @@ -1,6 +1,13 @@ -#!/system/bin/sh +#!/system/bin/sh -u +# $id uninstaller +# id is set/corrected by build.sh +# Copyright (c) 2019, VR25 (xda-developers.com) +# License: GPLv3+ + +id=acc [ -f $PWD/${0##*/} ] && modPath=$PWD || modPath=${0%/*} . $modPath/busybox.sh -pgrep -f '/acc (-|--)[def]|/accd.sh' | xargs kill 2>/dev/null -set -e +pkill -f "/$id (-|--)|/{id}.sh" rm -rf $(readlink -f $modPath) +rm /data/media/0/${id}-uninstaller.zip 2>/dev/null +exit 0 diff --git a/bin/acc-uninstaller.zip b/bin/acc-uninstaller.zip new file mode 100644 index 0000000..141737e Binary files /dev/null and b/bin/acc-uninstaller.zip differ diff --git a/build-offline.bat b/build-offline.bat deleted file mode 100644 index 4f89400..0000000 --- a/build-offline.bat +++ /dev/null @@ -1,2 +0,0 @@ -bash build.sh --offline -pause diff --git a/build.bat b/build.bat index cdd7579..167611e 100644 --- a/build.bat +++ b/build.bat @@ -1,2 +1 @@ bash build.sh -pause diff --git a/build.sh b/build.sh index 9976488..11a4e51 100644 --- a/build.sh +++ b/build.sh @@ -5,11 +5,9 @@ (cd ${0%/*} 2>/dev/null -. check-syntax.sh || exit $? +. check-syntax.sh noprompt || exit $? -updateBinary=https://raw.githubusercontent.com/topjohnwu/Magisk/master/scripts/module_installer.sh - -set_value() { sed -i "s/^$1=.*/$1=$2/" module.prop; } +set_value() { sed -i -e "s/^($1=.*/($1=$2/" -e "s/^$1=.*/$1=$2/" ${3:-module.prop}; } id=$(sed -n "s/^id=//p" module.prop) @@ -22,30 +20,40 @@ versionCode=$(grep '\*\*.*\(.*\)\*\*' README.md \ set_value version $version set_value versionCode $versionCode -rm -rf _builds/${id}-*/ 2>/dev/null -mkdir -p _builds/${id}-$versionCode -cp install-tarball.sh _builds/install -cp -R acc/ install-c* *.md module.prop _builds/${id}-$versionCode/ - -if [ -z "${1:-}" ]; then - echo "(i) Downloading latest update-binary..." - if wget $updateBinary --output-document _builds/update-binary \ - || curl -#L $updateBinary > _builds/update-binary - then - mv -f _builds/update-binary META-INF/com/google/android/ +# prepare files to be included in tarball +rm -rf _builds/${id}-${versionCode}/ 2>/dev/null +mkdir -p bin _builds/${id}-$versionCode/${id}-${versionCode} +cp install-tarball.sh _builds/${id}-${versionCode}/ +cp -R ${id}/ install-c* *.md module.prop bin/ _builds/${id}-$versionCode/${id}-${versionCode} 2>&1 | grep -iv "can't preserve" + +# set ID +for file in ./install-*.sh ./$id/*.sh ./bundle.sh \ + ./uninstaller-src/META-INF/com/google/android/update-binary +do + if [ -f "$file" ] && grep -Eq '(^|\()id=' $file; then + grep -Eq "(^|\()id=$id" $file || set_value id $id $file fi - echo -fi +done + +# unify installers +cp -u install-current.sh install.sh 2>/dev/null +cp -u install-current.sh META-INF/com/google/android/update-binary 2>/dev/null -echo "=> ${id}-${versionCode}.zip" -rm _builds/${id}-${versionCode}.zip 2>/dev/null -zip -r9 _builds/${id}-${versionCode}.zip \ +# generate flashable zips +echo "=> _builds/${id}-${versionCode}/${id}-${versionCode}.zip" +rm bin/${id}-uninstaller.zip 2>/dev/null +(cd uninstaller-src; zip -r9q ../bin/${id}-uninstaller.zip META-INF) +zip -r9 _builds/${id}-${versionCode}/${id}-${versionCode}.zip \ * .gitattributes .gitignore \ - -x _\*/\* | sed 's/^.*adding: //' | grep -iv 'zip warning:' | grep .. && echo + -x _\*/\* | sed 's|^.*adding: ||' | grep -iv 'zip warning:' +echo -cd _builds -echo "=> acc_bundle" -tar -cvf - ${id}-${versionCode} | gzip -9 > acc_bundle -rm -rf ${id}-*/ +# generate tarball +cd _builds/${id}-${versionCode} +echo "=> _builds/${id}-${versionCode}/${id}-${versionCode}.tar.gz" +tar -cvf - ${id}-${versionCode} | gzip -9 > ${id}-${versionCode}.tar.gz +rm -rf ${id}-${versionCode}/ +echo +read -p "(i) Press ENTER to continue..." echo exit 0) diff --git a/bundle.bat b/bundle.bat new file mode 100644 index 0000000..21958ad --- /dev/null +++ b/bundle.bat @@ -0,0 +1 @@ +bash bundle.sh diff --git a/bundle.sh b/bundle.sh new file mode 100644 index 0000000..c988f49 --- /dev/null +++ b/bundle.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env sh +# ${1:-id} Bundler for Front-end App +# Copyright (c) 2019, VR25 (xda-developers.com) +# License: GPLv3+ + + +(id=acc +installerName=install +tarballName=${id}_bundle +destination=/mnt/d/Desktop/AccA/app/src/main/res/raw + +cd ${0%/*} 2>/dev/null +versionCode=$(sed -n "s/^versionCode=//p" module.prop) + +cp -u install-tarball.sh $destination/$installerName +cp -u _builds/${id}-${versionCode}/${id}-${versionCode}.tar.gz $destination/$tarballName) + +read -p "(i) Press ENTER to continue..." +echo diff --git a/check-syntax.bat b/check-syntax.bat index 812e945..46dbb69 100644 --- a/check-syntax.bat +++ b/check-syntax.bat @@ -1,2 +1 @@ bash check-syntax.sh -pause diff --git a/check-syntax.sh b/check-syntax.sh index d3f6aba..105ef41 100644 --- a/check-syntax.sh +++ b/check-syntax.sh @@ -5,7 +5,6 @@ (echo cd ${0%/*} 2>/dev/null -modId=${PWD##/} exitCode=0 for f in $(find . \( -path ./_builds -o -path ./_resources -o -path ./META-INF \) -prune -o -type f -name '*.sh'); do if [ -f "$f" ]; then @@ -13,4 +12,8 @@ for f in $(find . \( -path ./_builds -o -path ./_resources -o -path ./META-INF \ fi done [ $exitCode -eq 0 ] || echo +if [ -z "$1" ]; then + read -p "(i) Press ENTER to continue..." + echo +fi exit $exitCode) diff --git a/install-current.sh b/install-current.sh index 81e596c..8401147 100644 --- a/install-current.sh +++ b/install-current.sh @@ -1,27 +1,40 @@ #!/system/bin/sh -# From-source Installer/Upgrader +# $id Installer/Upgrader # Copyright (c) 2019, VR25 (xda-developers.com) # License: GPLv3+ - +set +x echo +id=acc +umask 077 + +# log +mkdir -p /data/adb/${id}-data/logs +exec 2>/data/adb/${id}-data/logs/install.log +set -x + trap 'e=$?; echo; exit $e' EXIT -if [[ $PATH != *busybox:* ]]; then - if [ -d /sbin/.magisk/busybox ]; then - PATH=/sbin/.magisk/busybox:$PATH - elif [ -d /sbin/.core/busybox ]; then - PATH=/sbin/.core/busybox:$PATH - elif which busybox > /dev/null; then - mkdir -p -m 700 /dev/.busybox - busybox install -s /dev/.busybox - PATH=/dev/.busybox:$PATH - else - echo "(!) Install busybox binary first" - exit 3 +# set up busybox +if [ -d /sbin/.magisk/busybox ]; then + [[ $PATH == /sbin/.magisk/busybox* ]] || PATH=/sbin/.magisk/busybox:$PATH +elif [ -d /sbin/.core/busybox ]; then + [[ $PATH == /sbin/.core/busybox* ]] || PATH=/sbin/.core/busybox:$PATH +else + [[ $PATH == /dev/.busybox* ]] || PATH=/dev/.busybox:$PATH + if ! mkdir -m 700 /dev/.busybox 2>/dev/null; then + if [ -x /data/adb/magisk/busybox ]; then + /data/adb/magisk/busybox --install -s /dev/.busybox + elif which busybox > /dev/null; then + busybox --install -s /dev/.busybox + else + echo "(!) Install busybox binary first" + exit 3 + fi fi fi +# root check if [ $(id -u) -ne 0 ]; then echo "(!) $0 must run as root (su)" exit 4 @@ -29,141 +42,180 @@ fi print() { sed -n "s|^$1=||p" ${2:-$srcDir/module.prop}; } -umask 022 +set_perms() { + local owner=${2:-0} perms=0600 target=$(readlink -f $1) + if echo $target | grep -q '.*\.sh$' || [ -d $target ]; then perms=0700; fi + chmod $perms $target + chown $owner:$owner $target + restorecon $target > /dev/null 2>&1 || : +} + +set_perms_recursive() { + local owner=${2:-0} target="" + find $1 2>/dev/null | while read target; do set_perms $target $owner; done +} + set -euo pipefail +# set source code directory [ -f $PWD/${0##*/} ] && srcDir=$PWD || srcDir=${0%/*} -modId=$(print id) + +# unzip flashable zip if source code is unavailable +if [ ! -f $srcDir/module.prop ]; then + srcDir=/dev/.tmp + rm -rf $srcDir 2>/dev/null || : + mkdir $srcDir + unzip -o ${ZIP:-${3:-}} -d $srcDir/ >&2 +fi + name=$(print name) author=$(print author) version=$(print version) versionCode=$(print versionCode) installDir=${installDir0:-/data/data/mattecarra.accapp/files} -config=/data/media/0/$modId/${modId}.conf -[ -f $config ] || mv ${config%/*}/config.txt $config 2>/dev/null || : +config=/data/media/0/$id/${id}.conf # migrate/restore config -if [ -d ${config%/*} ] && [ ! -d /data/adb/${modId}-data ]; then +[ -f $config ] || mv ${config%/*}/config.txt $config 2>/dev/null || : +if [ -d ${config%/*} ] && [ ! -d /data/adb/${id}-data ]; then mv $config ${config%/*}/config.txt 2>/dev/null || : - (cd /data/media/0; mv ${config%/*} ${modId}-data - tar -cf - ${modId}-data | tar -xf - -C /data/adb) - rm -rf ${modId}-data + (cd /data/media/0; mv ${config%/*} ${id}-data + tar -cf - ${id}-data | tar -xf - -C /data/adb) + rm -rf ${id}-data fi -config=/data/adb/${modId}-data/config.txt -[ -f $config ] || cp /data/media/0/.${modId}-config-backup.txt $config 2>/dev/null || : +config=/data/adb/${id}-data/config.txt +[ -f $config ] || cp /data/media/0/.${id}-config-backup.txt $config 2>/dev/null || : configVer=$(print versionCode $config 2>/dev/null || :) +# check/set parent installation directory [ -d $installDir ] || installDir=/sbin/.magisk/modules [ -d $installDir ] || installDir=/sbin/.core/img [ -d $installDir ] || installDir=/data/adb [ -d $installDir ] || { echo "(!) /data/adb/ not found\n"; exit 1; } -cat << CAT +cat << EOF $name $version Copyright (c) 2017-2019, $author License: GPLv3+ -(i) Installing to $installDir/$modId/... -CAT +(i) Installing in $installDir/$id/... +EOF + -(pgrep -f "/$modId (-|--)[def]|/${modId}d.sh" | xargs kill -9 2>/dev/null) || : +(pkill -9 -f "/$id (-|--)|/${id}d.sh" ) || : -rm -rf $(readlink -f /sbin/.$modId/$modId) 2>/dev/null || : -cp -R $srcDir/$modId/ $installDir/ -installDir=$installDir/$modId -[ ${installDir0:-x} == x ] && installDir0=/data/data/mattecarra.accapp/files/$modId || installDir0=$installDir0/$modId +# install +rm -rf $(readlink -f /sbin/.$id/$id) $installDir/$id 2>/dev/null || : +cp -R $srcDir/$id/ $installDir/ +installDir=$installDir/$id +[ ${installDir0:-x} == x ] && installDir0=/data/data/mattecarra.accapp/files/$id || installDir0=$installDir0/$id cp $srcDir/module.prop $installDir/ mkdir -p ${config%/*}/info cp -f $srcDir/*.md ${config%/*}/info case $installDir in - /data/adb/$modId|$installDir0) - mv $installDir/service.sh $installDir/${modId}-init.sh;; + /data/adb/$id|$installDir0) + mv $installDir/service.sh $installDir/${id}-init.sh;; *) ln $installDir/service.sh $installDir/post-fs-data.sh;; esac -chmod -R 0600 $installDir -chmod 0700 $installDir/*.sh - # patch/upgrade config if [ -f $config ]; then - if [ ${configVer:-0} -lt 201906230 ] \ + if [ ${configVer:-0} -lt 201910130 ] \ || [ ${configVer:-0} -gt $(print versionCode $installDir/default-config.txt) ] - then - rm $config - else - if [ $configVer -lt 201906290 ]; then - echo prioritizeBattIdleMode=false >> $config - sed -i '/^versionCode=/s/=.*/=201906290/' $config - fi - if [ $configVer -lt 201907080 ]; then - sed -i '/^loopDelay=/s/=.*/=10,30/' $config - sed -i '/^versionCode=/s/=.*/=201907080/' $config - fi - if [ $configVer -lt 201907090 ]; then - sed -i '/^rebootOnUnplug=/d' $config - sed -i '/^versionCode=/s/=.*/=201907090/' $config - fi + then + rm $config +# else +# if [ $configVer -lt 201906290 ]; then +# echo prioritizeBattIdleMode=false >> $config +# sed -i '/^versionCode=/s/=.*/=201906290/' $config +# fi +# if [ $configVer -lt 201907080 ]; then +# sed -i '/^loopDelay=/s/=.*/=10,30/' $config +# sed -i '/^versionCode=/s/=.*/=201907080/' $config +# fi +# if [ $configVer -lt 201907090 ]; then +# sed -i '/^rebootOnUnplug=/d' $config +# sed -i '/^versionCode=/s/=.*/=201907090/' $config +# fi +# if [ $configVer -lt 201909260 ]; then +# sed -i '/^loopDelay=/s/,30/,15/' $config +# sed -i '/^versionCode=/s/=.*/=201909260/' $config +# fi fi fi -chmod -R 0777 ${config%/*} +cp -f $srcDir/bin/${id}-uninstaller.zip /data/media/0/ + +# set perms +set_perms_recursive ${config%/*} +chmod 0666 /data/media/0/${id}-uninstaller.zip +case $installDir in + /data/*/files/$id) + pkg=${installDir%/files/$id} + pkg=${pkg##/data*/} + owner=$(grep $pkg /data/system/packages.list | awk '{print $2}') + set_perms_recursive ${installDir%/*} $owner + ;; + *) + set_perms_recursive $installDir + ;; +esac + set +euo pipefail -cat << CAT +cat << EOF - Done LATEST CHANGES -CAT +EOF -println=false -cat ${config%/*}/info/README.md | while IFS= read -r line; do - if $println; then - echo " $line" - else - echo "$line" | grep -q \($versionCode\) && println=true \ - && echo " $line" - fi -done +# print changelog +tail -n +$(grep -n \($versionCode\) ${config%/*}/info/README.md | cut -d: -f1) \ + ${config%/*}/info/README.md | sed 's/^/ /' -cat << CAT +cat << EOF LINKS - ACC app: github.com/MatteCarra/AccA/ - Battery University: batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries/ - Donate: paypal.me/vr25xda/ + - Daily Job Scheduler: github.com/VR-25/djs/ - Facebook page: facebook.com/VR25-at-xda-developers-258150974794782/ - - Git repository: github.com/VR-25/$modId/ + - Git repository: github.com/VR-25/$id/ - Telegram channel: t.me/vr25_xda/ - - Telegram group: t.me/${modId}/ + - Telegram group: t.me/${id}_group/ - Telegram profile: t.me/vr25xda/ - XDA thread: forum.xda-developers.com/apps/magisk/module-magic-charging-switch-cs-v2017-9-t3668427/ (i) Important info: https://bit.ly/2TRqRz0 (i) Rebooting is unnecessary. -- $modId can be used right now. -- $modId daemon started. -CAT +- $id can be used right now. +- $id daemon started. +EOF -[ $installDir == /data/adb ] && echo -e "\n(i) Use init.d or an app to run $installDir/${modId}-init.sh on boot to initialize ${modId}." +[ $installDir == /data/adb ] && echo -e "\n(i) Use init.d or an app to run $installDir/${id}-init.sh on boot to initialize ${id}." echo trap - EXIT -if [ -f $installDir/service.sh ]; then - $installDir/service.sh --override -else - $installDir/${modId}-init.sh --override +# initialize $id +if grep -q /storage/emulated /proc/mounts; then + if [ -f $installDir/service.sh ]; then + $installDir/service.sh --override + else + $installDir/${id}-init.sh --override + fi fi e=$? diff --git a/install-latest.sh b/install-latest.sh index ab29941..de851d5 100644 --- a/install-latest.sh +++ b/install-latest.sh @@ -1,35 +1,48 @@ #!/system/bin/sh # -# $modId Installer/Upgrader/Downgrader -# https://raw.githubusercontent.com/VR-25/$modId/$branch/install-latest.sh +# $id Installer/Upgrader/Downgrader +# https://raw.githubusercontent.com/VR-25/$id/$branch/install-latest.sh # # Copyright (c) 2019, VR25 (xda-developers.com) # License: GPLv3+ # -# Usage: sh install-latest.sh [-c|--changelog|-f|--force|-n|--non-interactive] [%install dir%] [reference] +# Usage: sh install-latest.sh [-c|--changelog] [-f|--force] [-n|--non-interactive] [%install dir%] [reference] # # Refer to README.md > NOTES/TIPS FOR FRONT-END DEVELOPERS for exit codes +set +x echo -modId=acc +id=acc +umask 077 + +# log +mkdir -p /data/adb/${id}-data/logs +exec 2>/data/adb/${id}-data/logs/install-latest.sh.log +set -x + trap 'e=$?; echo; exit $e' EXIT -if [[ $PATH != *busybox:* ]]; then - if [ -d /sbin/.magisk/busybox ]; then - PATH=/sbin/.magisk/busybox:$PATH - elif [ -d /sbin/.core/busybox ]; then - PATH=/sbin/.core/busybox:$PATH - elif which busybox > /dev/null; then - mkdir -p -m 700 /dev/.busybox - busybox install -s /dev/.busybox - PATH=/dev/.busybox:$PATH - else - echo "(!) Install busybox binary first" - exit 3 +# set up busybox +if [ -d /sbin/.magisk/busybox ]; then + [[ $PATH == /sbin/.magisk/busybox* ]] || PATH=/sbin/.magisk/busybox:$PATH +elif [ -d /sbin/.core/busybox ]; then + [[ $PATH == /sbin/.core/busybox* ]] || PATH=/sbin/.core/busybox:$PATH +else + [[ $PATH == /dev/.busybox* ]] || PATH=/dev/.busybox:$PATH + if ! mkdir -m 700 /dev/.busybox 2>/dev/null; then + if [ -x /data/adb/magisk/busybox ]; then + /data/adb/magisk/busybox --install -s /dev/.busybox + elif which busybox > /dev/null; then + busybox --install -s /dev/.busybox + else + echo "(!) Install busybox binary first" + exit 3 + fi fi fi +# root check if [ $(id -u) -ne 0 ]; then echo "(!) $0 must run as root (su)" exit 4 @@ -39,12 +52,12 @@ set -euo pipefail get_ver() { sed -n 's/^versionCode=//p' ${1:-}; } reference="$(echo "$*" | sed -E 's/-c|--changelog|-f|--force|-n|--non-interactive|%.*%| //g')" -tarball=https://github.com/VR-25/$modId/archive/${reference:-master}.tar.gz -instVer=$(get_ver /sbin/.$modId/$modId/module.prop 2>/dev/null || :) -currVer=$(wget https://raw.githubusercontent.com/VR-25/$modId/${reference:-master}/module.prop --output-document - | get_ver) +tarball=https://github.com/VR-25/$id/archive/${reference:-master}.tar.gz +instVer=$(get_ver /sbin/.$id/$id/module.prop 2>/dev/null || :) +currVer=$(wget https://raw.githubusercontent.com/VR-25/$id/${reference:-master}/module.prop --output-document - | get_ver) [ -f $PWD/${0##*/} ] || cd ${0%/*} -rm -rf "./${modId}-${reference:-master}/" 2>/dev/null || : +rm -rf "./${id}-${reference:-master}/" 2>/dev/null || : if [ ${instVer:-0} -lt ${currVer:-0} ] || [[ "$*" == *-f* ]] || [[ "$*" == *--force* ]]; then case $* in @@ -52,13 +65,13 @@ if [ ${instVer:-0} -lt ${currVer:-0} ] || [[ "$*" == *-f* ]] || [[ "$*" == *--fo case $* in *--non-interactive*|*-n*) echo $currVer - echo "https://github.com/VR-25/$modId/blob/${reference:-master}/README.md#latest-changes" + echo "https://github.com/VR-25/$id/blob/${reference:-master}/README.md#latest-changes" exit 5 ;; *) echo - echo "(i) $modId $currVer is available" - echo "- Changelog: https://github.com/VR-25/$modId/blob/${reference:-master}/README.md#latest-changes" + echo "(i) $id $currVer is available" + echo "- Changelog: https://github.com/VR-25/$id/blob/${reference:-master}/README.md#latest-changes" echo "- Would you like to download and install it now (Y/n)?" read ans [[ ${ans:-y} == [nN]* ]] && exit 0 @@ -71,7 +84,7 @@ if [ ${instVer:-0} -lt ${currVer:-0} ] || [[ "$*" == *-f* ]] || [[ "$*" == *--fo trap - EXIT echo wget $tarball --output-document - | tar -xz \ - && sh ${modId}-${reference:-master}/install-current.sh + && sh ${id}-${reference:-master}/install-current.sh else echo echo "(i) No update available" @@ -79,5 +92,5 @@ else fi set -eu -rm -rf $0 "./${modId}-${reference:-master}/" +rm -rf $0 "./${id}-${reference:-master}/" exit 0 diff --git a/install-tarball.sh b/install-tarball.sh index 2de4dee..fcad0a6 100644 --- a/install-tarball.sh +++ b/install-tarball.sh @@ -1,32 +1,88 @@ #!/system/bin/sh +# ${1:-$id}*gz Installer +# Copyright (c) 2019, VR25 (xda-developers.com) +# License: GPLv3+ -if [[ $PATH != *busybox:* ]]; then - if [ -d /sbin/.magisk/busybox ]; then - PATH=/sbin/.magisk/busybox:$PATH - elif [ -d /sbin/.core/busybox ]; then - PATH=/sbin/.core/busybox:$PATH - elif which busybox > /dev/null; then - mkdir -p -m 700 /dev/.busybox - busybox install -s /dev/.busybox - PATH=/dev/.busybox:$PATH - else - echo "(!) Install busybox binary first" - exit 3 +id=acc +umask 077 + +# log +mkdir -p /data/adb/${1:-$id}-data/logs +exec 2>/data/adb/${1:-$id}-data/logs/install-tarball.sh.log +set -x + +# set up busybox +if [ -d /sbin/.magisk/busybox ]; then + [[ $PATH == /sbin/.magisk/busybox* ]] || PATH=/sbin/.magisk/busybox:$PATH +elif [ -d /sbin/.core/busybox ]; then + [[ $PATH == /sbin/.core/busybox* ]] || PATH=/sbin/.core/busybox:$PATH +else + [[ $PATH == /dev/.busybox* ]] || PATH=/dev/.busybox:$PATH + if ! mkdir -m 700 /dev/.busybox 2>/dev/null; then + if [ -x /data/adb/magisk/busybox ]; then + /data/adb/magisk/busybox --install -s /dev/.busybox + elif which busybox > /dev/null; then + busybox --install -s /dev/.busybox + else + echo "(!) Install busybox binary first" + exit 3 + fi fi fi +# root check if [ $(id -u) -ne 0 ]; then echo "(!) $0 must run as root (su)" exit 4 fi -id=acc +umask 0 set -e + +# get into the target directory [ -f $PWD/${0##*/} ] || cd ${0%/*} -[ -d $id/${id}-init.sh ] && exit 0 -rm -rf ${id}-*/ -tar -xf ${id}*gz -export installDir0="$1" -sh ${id}-*/install-current.sh -rm -rf ${id}-*/ +cd $(readlink -f $PWD) + +# this runs on exit if the installer is launched by a front-end app +copy_log() { + if [[ $PWD == /data/data/* ]]; then + umask 077 + mkdir -p logs + + cp -af /data/adb/${1:-$id}-data/logs/install.log logs/${1:-$id}-install.log + + pkg=$(cd ..; pwd) + pkg=${pkg##/data*/} + + owner=$(grep $pkg /data/system/packages.list | awk '{print $2}') + chown -R $owner:$owner logs + fi +} +trap copy_log EXIT + +# extract tarball +rm -rf ${1:-$id}-*/ 2>/dev/null +tar -xf ${1:-$id}*gz + +# install ${1:-$id} +export installDir0="$2" +sh ${1:-$id}-*/install-current.sh +rm -rf ${1:-$id}-*/ + +# set up alternate initializer (Magisk service.d) +if [[ $PWD == /data/data/* ]] && [ -d /data/adb/service.d ]; then + cat << EOF > /data/adb/service.d/${1:-$id}-init.sh +#!/system/bin/sh +(until grep -q /storage/emulated /proc/mounts; do sleep 15; done +if [ -f $PWD/${1:-$id}/${1:-$id}-init.sh ]; then + $PWD/${1:-$id}/${1:-$id}-init.sh +else + rm \$0 +fi +exit 0 &) & +exit 0 +EOF + chmod 0700 /data/adb/service.d/${1:-$id}-init.sh +fi + exit 0 diff --git a/install.sh b/install.sh index 695ab43..8401147 100644 --- a/install.sh +++ b/install.sh @@ -1,289 +1,223 @@ -######################################################################################################## -# -# Magisk Module Installer Script -# -########################################################################################## -########################################################################################## -# -# Instructions: -# -# 1. Place your files into system folder (delete the placeholder file) -# 2. Fill in your module's info into module.prop -# 3. Configure and implement callbacks in this file -# 4. If you need boot scripts, add them into common/post-fs-data.sh or common/service.sh -# 5. Add your additional or modified system properties into common/system.prop -# -########################################################################################## - -########################################################################################## -# Config Flags -########################################################################################## - -# 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=true - -# Set to true if you need to load system.prop -PROPFILE=false - -# Set to true if you need post-fs-data script -POSTFSDATA=false - -# Set to true if you need late_start service script -LATESTARTSERVICE=false - -########################################################################################## -# Replace list -########################################################################################## - -# List all directories you want to directly replace in the system -# Check the documentations for more info why you would need this - -# Construct your list in the following format -# This is an example -REPLACE_EXAMPLE=" -/system/app/Youtube -/system/priv-app/SystemUI -/system/priv-app/Settings -/system/framework -" - -# Construct your own list here -REPLACE=" -" - -########################################################################################## -# -# Function Callbacks -# -# The following functions will be called by the installation framework. -# You do not have the ability to modify update-binary, the only way you can customize -# installation is through implementing these functions. -# -# When running your callbacks, the installation framework will make sure the Magisk -# internal busybox path is *PREPENDED* to PATH, so all common commands shall exist. -# Also, it will make sure /data, /system, and /vendor is properly mounted. -# -########################################################################################## -########################################################################################## -# -# The installation framework will export some variables and functions. -# You should use these variables and functions for installation. -# -# ! DO NOT use any Magisk internal paths as those are NOT public API. -# ! DO NOT use other functions in util_functions.sh as they are NOT public API. -# ! Non public APIs are not guranteed to maintain compatibility between releases. -# -# Available variables: -# -# MAGISK_VER (string): the version string of current installed Magisk -# MAGISK_VER_CODE (int): the version code of current installed Magisk -# BOOTMODE (bool): true if the module is currently installing in Magisk Manager -# MODPATH (path): the path where your module files should be installed -# TMPDIR (path): a place where you can temporarily store files -# ZIPFILE (path): your module's installation zip -# ARCH (string): the architecture of the device. Value is either arm, arm64, x86, or x64 -# IS64BIT (bool): true if $ARCH is either arm64 or x64 -# API (int): the API level (Android version) of the device -# -# Availible functions: -# -# ui_print -# print to console -# Avoid using 'echo' as it will not display in custom recovery's console -# -# abort -# print error message to console and terminate installation -# Avoid using 'exit' as it will skip the termination cleanup steps -# -# set_perm [context] -# if [context] is empty, it will default to "u:object_r:system_file:s0" -# this function is a shorthand for the following commands -# chown owner.group target -# chmod permission target -# chcon context target -# -# set_perm_recursive [context] -# if [context] is empty, it will default to "u:object_r:system_file:s0" -# for all files in , it will call: -# set_perm file owner group filepermission context -# for all directories in (including itself), it will call: -# set_perm dir owner group dirpermission context -# -########################################################################################## -########################################################################################## -# If you need boot scripts, DO NOT use general boot scripts (post-fs-data.d/service.d) -# ONLY use module scripts as it respects the module status (remove/disable) and is -# guaranteed to maintain the same behavior in future Magisk releases. -# Enable boot scripts by setting the flags in the config section above. -########################################################################################## - -# Set what you want to display when installing your module - -print_modname() { - ui_print " " - ui_print "$name $version" - ui_print "Copyright (c) 2017-2019, $author" - ui_print "License: GPLv3+" - ui_print " " +#!/system/bin/sh +# $id Installer/Upgrader +# Copyright (c) 2019, VR25 (xda-developers.com) +# License: GPLv3+ + +set +x +echo +id=acc +umask 077 + +# log +mkdir -p /data/adb/${id}-data/logs +exec 2>/data/adb/${id}-data/logs/install.log +set -x + +trap 'e=$?; echo; exit $e' EXIT + +# set up busybox +if [ -d /sbin/.magisk/busybox ]; then + [[ $PATH == /sbin/.magisk/busybox* ]] || PATH=/sbin/.magisk/busybox:$PATH +elif [ -d /sbin/.core/busybox ]; then + [[ $PATH == /sbin/.core/busybox* ]] || PATH=/sbin/.core/busybox:$PATH +else + [[ $PATH == /dev/.busybox* ]] || PATH=/dev/.busybox:$PATH + if ! mkdir -m 700 /dev/.busybox 2>/dev/null; then + if [ -x /data/adb/magisk/busybox ]; then + /data/adb/magisk/busybox --install -s /dev/.busybox + elif which busybox > /dev/null; then + busybox --install -s /dev/.busybox + else + echo "(!) Install busybox binary first" + exit 3 + fi + fi +fi + +# root check +if [ $(id -u) -ne 0 ]; then + echo "(!) $0 must run as root (su)" + exit 4 +fi + +print() { sed -n "s|^$1=||p" ${2:-$srcDir/module.prop}; } + +set_perms() { + local owner=${2:-0} perms=0600 target=$(readlink -f $1) + if echo $target | grep -q '.*\.sh$' || [ -d $target ]; then perms=0700; fi + chmod $perms $target + chown $owner:$owner $target + restorecon $target > /dev/null 2>&1 || : } -# Copy/extract your module files into $MODPATH in on_install. - -on_install() { - # The following is the default implementation: extract $ZIPFILE/system to $MODPATH - # Extend/change the logic to whatever you want - #ui_print "- Extracting module files" - #unzip -o "$ZIPFILE" 'system/*' -d $MODPATH >&2 +set_perms_recursive() { + local owner=${2:-0} target="" + find $1 2>/dev/null | while read target; do set_perms $target $owner; done +} - [ -d /data/data/mattecarra.accapp/files/acc ] && cancel "(!) Upgrade within ACC App or run acc --upgrade" +set -euo pipefail - $BOOTMODE && pgrep -f "/$MODID (-|--)[def]|/${MODID}d.sh" | xargs kill -9 2>/dev/null - set -euxo pipefail - trap 'exxit $?' EXIT +# set source code directory +[ -f $PWD/${0##*/} ] && srcDir=$PWD || srcDir=${0%/*} - config=/data/media/0/$MODID/${MODID}.conf - [ -f $config ] || mv ${config%/*}/config.txt $config 2>/dev/null || : +# unzip flashable zip if source code is unavailable +if [ ! -f $srcDir/module.prop ]; then + srcDir=/dev/.tmp + rm -rf $srcDir 2>/dev/null || : + mkdir $srcDir + unzip -o ${ZIP:-${3:-}} -d $srcDir/ >&2 +fi - # migrate/restore config - if [ -d ${config%/*} ] && [ ! -d /data/adb/${config%/*} ]; then - mv $config ${config%/*}/config.txt 2>/dev/null || : - (cd /data/media/0; mv ${config%/*} ${MODID}-data - tar -cf - ${MODID}-data | tar -xf - -C /data/adb) - rm -rf ${MODID}-data - fi - config=/data/adb/${MODID}-data/config.txt - [ -f $config ] || cp /data/media/0/.${MODID}-config-backup.txt $config 2>/dev/null || : - - local configVer=$(print versionCode $config) - - # extract module files - ui_print " " - ui_print "(i) Extracting module files..." - unzip -o "$ZIPFILE" "$MODID/*" -d ${MODPATH%/*}/ >&2 - ln $MODPATH/service.sh $MODPATH/post-fs-data.sh - mkdir -p ${config%/*}/info - unzip -o "$ZIPFILE" '*.md' -d ${config%/*}/info/ >&2 - - # patch/upgrade config - if [ -f $config ]; then - if [ ${configVer:-0} -lt 201906230 ] \ - || [ ${configVer:-0} -gt $(print versionCode $MODPATH/default-config.txt) ] - then - rm $config - else - if [ $configVer -lt 201906290 ]; then - echo prioritizeBattIdleMode=false >> $config - sed -i '/^versionCode=/s/=.*/=201906290/' $config - fi - if [ $configVer -lt 201907080 ]; then - sed -i '/^loopDelay=/s/=.*/=10,30/' $config - sed -i '/^versionCode=/s/=.*/=201907080/' $config - fi - if [ $configVer -lt 201907090 ]; then - sed -i '/^rebootOnUnplug=/d' $config - sed -i '/^versionCode=/s/=.*/=201907090/' $config - fi - fi +name=$(print name) +author=$(print author) +version=$(print version) +versionCode=$(print versionCode) +installDir=${installDir0:-/data/data/mattecarra.accapp/files} +config=/data/media/0/$id/${id}.conf + +# migrate/restore config +[ -f $config ] || mv ${config%/*}/config.txt $config 2>/dev/null || : +if [ -d ${config%/*} ] && [ ! -d /data/adb/${id}-data ]; then + mv $config ${config%/*}/config.txt 2>/dev/null || : + (cd /data/media/0; mv ${config%/*} ${id}-data + tar -cf - ${id}-data | tar -xf - -C /data/adb) + rm -rf ${id}-data +fi +config=/data/adb/${id}-data/config.txt +[ -f $config ] || cp /data/media/0/.${id}-config-backup.txt $config 2>/dev/null || : + +configVer=$(print versionCode $config 2>/dev/null || :) + +# check/set parent installation directory +[ -d $installDir ] || installDir=/sbin/.magisk/modules +[ -d $installDir ] || installDir=/sbin/.core/img +[ -d $installDir ] || installDir=/data/adb +[ -d $installDir ] || { echo "(!) /data/adb/ not found\n"; exit 1; } + + +cat << EOF +$name $version +Copyright (c) 2017-2019, $author +License: GPLv3+ + +(i) Installing in $installDir/$id/... +EOF + + +(pkill -9 -f "/$id (-|--)|/${id}d.sh" ) || : + +# install +rm -rf $(readlink -f /sbin/.$id/$id) $installDir/$id 2>/dev/null || : +cp -R $srcDir/$id/ $installDir/ +installDir=$installDir/$id +[ ${installDir0:-x} == x ] && installDir0=/data/data/mattecarra.accapp/files/$id || installDir0=$installDir0/$id +cp $srcDir/module.prop $installDir/ + +mkdir -p ${config%/*}/info +cp -f $srcDir/*.md ${config%/*}/info + +case $installDir in + /data/adb/$id|$installDir0) + mv $installDir/service.sh $installDir/${id}-init.sh;; + *) + ln $installDir/service.sh $installDir/post-fs-data.sh;; +esac + +# patch/upgrade config +if [ -f $config ]; then + if [ ${configVer:-0} -lt 201910130 ] \ + || [ ${configVer:-0} -gt $(print versionCode $installDir/default-config.txt) ] + then + rm $config +# else +# if [ $configVer -lt 201906290 ]; then +# echo prioritizeBattIdleMode=false >> $config +# sed -i '/^versionCode=/s/=.*/=201906290/' $config +# fi +# if [ $configVer -lt 201907080 ]; then +# sed -i '/^loopDelay=/s/=.*/=10,30/' $config +# sed -i '/^versionCode=/s/=.*/=201907080/' $config +# fi +# if [ $configVer -lt 201907090 ]; then +# sed -i '/^rebootOnUnplug=/d' $config +# sed -i '/^versionCode=/s/=.*/=201907090/' $config +# fi +# if [ $configVer -lt 201909260 ]; then +# sed -i '/^loopDelay=/s/,30/,15/' $config +# sed -i '/^versionCode=/s/=.*/=201909260/' $config +# fi fi +fi - set +euxo pipefail - version_info -} +cp -f $srcDir/bin/${id}-uninstaller.zip /data/media/0/ -# Only some special files require specific permissions -# This function will be called after on_install is done -# The default permissions should be good enough for most cases - -set_permissions() { - local file="" - # The following is the default rule, DO NOT remove - set_perm_recursive $MODPATH 0 0 0700 0600 - - # Here are some examples: - # set_perm_recursive $MODPATH/system/lib 0 0 0755 0644 - # set_perm $MODPATH/system/bin/app_process32 0 2000 0755 u:object_r:zygote_exec:s0 - # set_perm $MODPATH/system/bin/dex2oat 0 2000 0755 u:object_r:dex2oat_exec:s0 - # set_perm $MODPATH/system/lib/libart.so 0 0 0644 - - # permissions for executables - for file in $MODPATH/*.sh; do - [ -f $file ] && set_perm $file 0 0 0700 - done - - # finishing touches - chmod -R 0777 ${config%/*} - $BOOTMODE && $MODPATH/service.sh --override -} +# set perms +set_perms_recursive ${config%/*} +chmod 0666 /data/media/0/${id}-uninstaller.zip +case $installDir in + /data/*/files/$id) + pkg=${installDir%/files/$id} + pkg=${pkg##/data*/} + owner=$(grep $pkg /data/system/packages.list | awk '{print $2}') + set_perms_recursive ${installDir%/*} $owner + ;; + *) + set_perms_recursive $installDir + ;; +esac -# You can add more functions to assist your custom script code +set +euo pipefail -cancel() { - imageless_magisk || unmount_magisk_image - abort "$1" -} +cat << EOF +- Done -exxit() { - set +euxo pipefail - [ $1 -ne 0 ] && cancel "$2" - exit $1 -} + LATEST CHANGES +EOF -version_info() { - local line="" - local println=false +# print changelog +tail -n +$(grep -n \($versionCode\) ${config%/*}/info/README.md | cut -d: -f1) \ + ${config%/*}/info/README.md | sed 's/^/ /' - ui_print "- Done" - # a note on untested Magisk versions - if [ $MAGISK_VER_CODE -gt 19300 ]; then - ui_print " " - ui_print " (i) Note: this Magisk version hasn't been tested by $author!" - ui_print " - If you come across any issue, please report." - fi +cat << EOF - ui_print " " - ui_print " LATEST CHANGES" - ui_print " " - cat ${config%/*}/info/README.md | while IFS= read -r line; do - if $println; then - line="$(echo " $line")" && ui_print "$line" - else - echo "$line" | grep -q \($versionCode\) && println=true \ - && line="$(echo " $line")" && ui_print "$line" - fi - done - ui_print " " - - ui_print " LINKS" - ui_print " - ACC app: github.com/MatteCarra/AccA/" - ui_print " - Battery University: batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries/" - ui_print " - Donate: paypal.me/vr25xda/" - ui_print " - Facebook page: facebook.com/VR25-at-xda-developers-258150974794782/" - ui_print " - Git repository: github.com/VR-25/$MODID/" - ui_print " - Telegram channel: t.me/vr25_xda/" - ui_print " - Telegram group: t.me/${MODID}/" - ui_print " - Telegram profile: t.me/vr25xda/" - ui_print " - XDA thread: forum.xda-developers.com/apps/magisk/module-magic-charging-switch-cs-v2017-9-t3668427/" - ui_print " " - - ui_print "(i) Important info: https://bit.ly/2TRqRz0" - ui_print " " - if $BOOTMODE; then - ui_print "(i) Ignore the reboot button." - ui_print "- $MODID can be used right now." - ui_print "- $MODID daemon started." - ui_print " " - fi -} + LINKS + - ACC app: github.com/MatteCarra/AccA/ + - Battery University: batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries/ + - Donate: paypal.me/vr25xda/ + - Daily Job Scheduler: github.com/VR-25/djs/ + - Facebook page: facebook.com/VR25-at-xda-developers-258150974794782/ + - Git repository: github.com/VR-25/$id/ + - Telegram channel: t.me/vr25_xda/ + - Telegram group: t.me/${id}_group/ + - Telegram profile: t.me/vr25xda/ + - XDA thread: forum.xda-developers.com/apps/magisk/module-magic-charging-switch-cs-v2017-9-t3668427/ -print() { sed -n "s|^$1=||p" ${2:-$TMPDIR/module.prop} 2>/dev/null || :; } +(i) Important info: https://bit.ly/2TRqRz0 -author=$(print author) -name=$(print name) -version=$(print version) -versionCode=$(print versionCode) +(i) Rebooting is unnecessary. +- $id can be used right now. +- $id daemon started. +EOF + + +[ $installDir == /data/adb ] && echo -e "\n(i) Use init.d or an app to run $installDir/${id}-init.sh on boot to initialize ${id}." + +echo +trap - EXIT + +# initialize $id +if grep -q /storage/emulated /proc/mounts; then + if [ -f $installDir/service.sh ]; then + $installDir/service.sh --override + else + $installDir/${id}-init.sh --override + fi +fi + +e=$? +[ $e -eq 0 ] || { echo; exit $e; } +exit 0 diff --git a/module.prop b/module.prop index 2316358..6ba587b 100644 --- a/module.prop +++ b/module.prop @@ -1,6 +1,6 @@ id=acc name=Advanced Charging Controller (acc) -version=2019.7.21-r1 -versionCode=201907211 +version=2019.10.13-dev +versionCode=201910130 author=VR25 (xda-developers.com) description=This is primarily intended for extending battery service life. On the flip side, the name says it all. Any root solution is supported. A recent stable Magisk version is recommended. Refer to README.md for details. If you are in Magisk Manager > Downloads, click here to open the documentation. diff --git a/uninstaller-src/META-INF/com/google/android/update-binary b/uninstaller-src/META-INF/com/google/android/update-binary new file mode 100644 index 0000000..6858461 --- /dev/null +++ b/uninstaller-src/META-INF/com/google/android/update-binary @@ -0,0 +1,38 @@ +#!/system/bin/sh +# $id uninstaller +# id is set/corrected by build.sh + +set -u +id=acc + +# set up busybox +PATH=/sbin/.magisk/busybox +if [ -d /sbin/.core/busybox ]; then + PATH=/sbin/.core/busybox +else + PATH=/dev/.busybox + if ! mkdir -m 700 /dev/.busybox 2>/dev/null; then + if [ -x /data/adb/magisk/busybox ]; then + /data/adb/magisk/busybox --install -s /dev/.busybox + elif which busybox > /dev/null; then + busybox --install -s /dev/.busybox + else + echo "(!) Install busybox binary first" + exit 3 + fi + fi +fi + +exec 2>/dev/null + +pkill -f "/$id (-|--)|/${id}d.sh" + +rm -rf $(readlink -f /sbin/.$id/$id/) + +rm -rf /data/adb/$id/ \ + /data/adb/modules*/$id/ \ + /data/data/mattecarra.accapp/files/$id/ + +rm $3 + +exit 0 diff --git a/uninstaller-src/META-INF/com/google/android/updater-script b/uninstaller-src/META-INF/com/google/android/updater-script new file mode 100644 index 0000000..11d5c96 --- /dev/null +++ b/uninstaller-src/META-INF/com/google/android/updater-script @@ -0,0 +1 @@ +#MAGISK