diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary index 34add8d..010221c 100644 --- a/META-INF/com/google/android/update-binary +++ b/META-INF/com/google/android/update-binary @@ -1,6 +1,6 @@ #!/system/bin/sh -# ACC Installer/Upgrader -# Copyright 2019-2020, VR25 +# $id Installer/Upgrader +# Copyright 2019-2021, VR25 # License: GPLv3+ # # devs: triple hashtags (###) mark non-generic code @@ -14,7 +14,7 @@ echo id=acc domain=vr25 umask 0077 -data_dir=/sdcard/Documents/$domain/$id +data_dir=/data/adb/$domain/${id}-data # log @@ -38,25 +38,25 @@ trap exxit EXIT # set up busybox #BB# -[ -x /dev/.busybox/ls ] || { - mkdir -p /dev/.busybox - chmod 0700 /dev/.busybox - if [ -f /data/adb/bin/busybox ]; then - [ -x /data/adb/bin/busybox ] || chmod -R 0700 /data/adb/bin - /data/adb/bin/busybox --install -s /dev/.busybox +[ -x /dev/.vr25/busybox/ls ] || { + mkdir -p /dev/.vr25/busybox + chmod 0700 /dev/.vr25/busybox + if [ -f /data/adb/vr25/bin/busybox ]; then + [ -x /data/adb/vr25/bin/busybox ] || chmod -R 0700 /data/adb/vr25/bin + /data/adb/vr25/bin/busybox --install -s /dev/.vr25/busybox elif [ -f /data/adb/magisk/busybox ]; then [ -x /data/adb/magisk/busybox ] || chmod 0700 /data/adb/magisk/busybox - /data/adb/magisk/busybox --install -s /dev/.busybox + /data/adb/magisk/busybox --install -s /dev/.vr25/busybox elif which busybox > /dev/null; then - eval "$(which busybox) --install -s /dev/.busybox" + eval "$(which busybox) --install -s /dev/.vr25/busybox" else - echo "(!) Install busybox or simply place it in /data/adb/bin/" + echo "(!) Install busybox or simply place it in /data/adb/vr25/bin/" exit 3 fi } case $PATH in - /data/adb/bin:*) :;; - *) export PATH=/data/adb/bin:/dev/.busybox:$PATH;; + /data/adb/vr25/bin:*) :;; + *) export PATH=/data/adb/vr25/bin:/dev/.vr25/busybox:$PATH;; esac #/BB# @@ -105,19 +105,20 @@ author=$(get_prop author) version=$(get_prop version) magiskModDir=/data/adb/modules versionCode=$(get_prop versionCode) -: ${installDir:=/data/data/mattecarra.${id}app/files} ### +accaFiles=/data/data/mattecarra.accapp/files ### +: ${installDir:=$accaFiles} ### config=$data_dir/config.txt [ -d $magiskModDir ] && magisk=true || magisk=false -ls -d /data/app/mattecarra.${id}app* > /dev/null 2>&1 && acca=true || acca=false ### +ls -d ${accaFiles%/*}* > /dev/null 2>&1 && acca=true || acca=false ### -# ensure AccA's files/ exists - to prevent unwanted ACC downgrades ### -if $acca && [ ! -d /data/data/mattecarra.${id}app/files ]; then - mkdir -p /data/data/mattecarra.${id}app/files - chmod 0777 /data/data/mattecarra.${id}app \ - /data/data/mattecarra.${id}app/files +# ensure AccA's files/ exists - to prevent unwanted downgrades ### +if $acca && [ ! -d $accaFiles ]; then + mkdir -p $accaFiles + chmod 0777 ${accaFiles%/*} \ + $accaFiles fi @@ -132,30 +133,12 @@ fi ### echo "$name $version ($versionCode) -Copyright 2017-present, $author +Copyright 2017-2021, $author GPLv3+ (i) Installing in $installDir/$id/..." -# migrate #legacy data - -if [ -d /data/adb/${id}-data ]; then - mv -f /data/adb/${id}-data/* /data/adb/${id}-data/.* \ - $data_dir/ 2>/dev/null || : -elif [ -d /sdcard/Download/$id ]; then - mv -f /sdcard/Download/$id/* /sdcard/Download/$id/.* \ - $data_dir/ 2>/dev/null || : -else - mv -f /sdcard/$domain/$id/* /sdcard/$domain/$id/.* \ - $data_dir/ 2>/dev/null || : -fi -rm -rf $data_dir/info 2>/dev/null || : - -mkdir -p /dev/.$domain -mv /dev/.$id /dev/.$domain/$id 2>/dev/null || : - - /system/bin/sh $srcDir/$id/uninstall.sh install cp -R $srcDir/$id/ $installDir/ installDir=$(readlink -f $installDir/$id) @@ -180,7 +163,7 @@ if $acca; then ! $magisk || { - ln -fs $installDir /data/data/mattecarra.${id}app/files/ + ln -fs $installDir $accaFiles/ # AccA post-uninstall cleanup script mkdir -p /data/adb/service.d || { @@ -190,7 +173,7 @@ if $acca; then echo "#!/system/bin/sh # AccA post-uninstall cleanup script - until test -d /sdcard/Download \\ + until test -d /sdcard/Android \\ && test .\$(getprop sys.boot_completed) = .1 do sleep 60 @@ -198,7 +181,7 @@ if $acca; then sleep 60 - [ -e /data/data/mattecarra.${id}app/files/$id ] || rm -rf \$0 /data/adb/$domain/$id /data/adb/modules/$id 2>/dev/null + [ -e $accaFiles/$id ] || rm -rf \$0 /data/adb/$domain/$id /data/adb/modules/$id 2>/dev/null exit 0" | sed 's/^ //' > /data/adb/service.d/${id}-cleanup.sh chmod 0700 /data/adb/service.d/${id}-cleanup.sh @@ -257,7 +240,7 @@ echo "- Done " # print links and changelog -sed -En "\|## LINKS|,\$p" $srcDir/README.md \ +sed -En "\|^## LINKS|,\$p" $srcDir/README.md \ | grep -v '^---' | sed 's/^## //' @@ -270,9 +253,11 @@ echo " - Daemon started." -[ $installDir = /data/adb ] && echo " +case $installDir in + /data/adb/*) echo " (i) Non-Magisk users can enable $id auto-start by running /data/adb/$domain/$id/service.sh, a copy of, or a link to it - with init.d or an app that emulates it." - + ;; +esac # initialize $id /data/adb/$domain/$id/service.sh --init diff --git a/README.md b/README.md index 40956f7..5d1c1cb 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ --- ## DESCRIPTION -ACC is an Android software mainly intended for [extending battery service life](https://batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries). +ACC is an Android software mainly intended for [extending battery service life](https://batteryuniversity.com/article/bu-808-how-to-prolong-lithium-based-batteries). In a nutshell, this is achieved through limiting charging current, temperature and voltage. Any root solution is supported. The installation is always "systemless", whether or not the system is rooted with Magisk. @@ -13,7 +13,7 @@ The installation is always "systemless", whether or not the system is rooted wit --- ## LICENSE -Copyright 2017-present, VR25 +Copyright 2017-2021, VR25 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,17 +40,33 @@ To prevent fraud, do NOT mirror any link associated with this project; do NOT sh --- -## WARNING +## WARNINGS ACC manipulates Android low level ([kernel](https://duckduckgo.com/lite/?q=kernel+android)) parameters which control the charging circuitry. The author assumes no responsibility under anything that might break due to the use/misuse of this software. By choosing to use/misuse it, you agree to do so at your own risk! +Some devices, notably Xiaomi phones, have a buggy PMIC (Power Management Integrated Circuit) that can be triggered by acc. +The issue blocks charging. +Ensure your battery does not discharge too low. +Using acc's auto shutdown feature is highly recommended. + +Refer to [this XDA post](https://forum.xda-developers.com/t/rom-official-arrowos-11-0-android-11-0-vayu-bhima.4267263/post-85119331) for additional details. + +[lybxlpsv](https://github.com/lybxlpsv) suggested booting into bootloader and then back into system to reset the PMIC. + + +--- +## DONATIONS + +Please, support the project with donations (`## LINKS` at the bottom). +As the project gets bigger and more popular, the need for coffee goes up as well. + --- ## PREREQUISITES -- [Must read - how to prolong lithium ion batteries lifespan](https://batteryuniversity.com/index.php/learn/article/how_to_prolong_lithium_based_batteries/) +- [Must read - how to prolong lithium ion batteries lifespan](https://batteryuniversity.com/article/bu-808-how-to-prolong-lithium-based-batteries/) - Android or Android based OS - Any root solution (e.g., [Magisk](https://github.com/topjohnwu/Magisk/)) - [Busybox\*](https://github.com/search?o=desc&q=busybox+android&s=updated&type=Repositories/) (only if not rooted with Magisk) @@ -59,11 +75,11 @@ By choosing to use/misuse it, you agree to do so at your own risk! - Terminal emulator - Text editor (optional) -\* A busybox binary can simply be placed in /data/adb/bin/. +\* A busybox binary can simply be placed in /data/adb/vr25/bin/. Permissions (0700) are set automatically, as needed. -Precedence: /data/adb/bin/busybox > Magisk's busybox > system's busybox +Precedence: /data/adb/vr25/bin/busybox > Magisk's busybox > system's busybox -Other executables or static binaries can also be placed in /data/adb/bin/ (with proper permissions) instead of being installed system-wide. +Other executables or static binaries can also be placed in /data/adb/vr25/bin/ (with proper permissions) instead of being installed system-wide. --- @@ -95,7 +111,7 @@ Settings can be overwhelming. Start with what you understand. The default configuration has you covered. Don't ever feel like you have to configure everything. You probably shouldn't anyway - unless you really know what you're doing. -Uninstall: run `acc --uninstall` or flash\* `/sdcard/Documents/vr25/acc/acc-uninstaller.zip`. +Uninstall: run `acc --uninstall` or flash\* `/data/adb/vr25/acc-data/acc-uninstaller.zip`. ACC runs in some recovery environments as well. Unless the zip is flashed again, manual initialization is required. @@ -307,7 +323,8 @@ currentWorkaround=false # acc --set pause_capacity=85 resume_capacity=80 # acc -s "s=battery/charging_enabled 1 0" -# acc --set "charging_switch=/proc/mtk_battery_cmd/current_cmd 0::0 0::1 /proc/mtk_battery_cmd/en_power_path 1 0" ("::" = " ") +# acc --set "charging_switch=/proc/mtk_battery_cmd/current_cmd 0::0 0::1 /proc/mtk_battery_cmd/en_power_path 1 0" +# NOTE: "::" is used as a whitespace placeholder in "/proc/mtk_battery_cmd/current_cmd 0::0 0::1" charging switch only. # acc -s -v 3920 (millivolts) # acc -s -c 500 (milliamps) @@ -339,18 +356,20 @@ currentWorkaround=false # This is checked during updates to determine whether config should be patched. Do NOT modify. # shutdown_capacity (sc) # -# When the battery is discharging and its capacity <= sc and phone has been running for 15 minutes or more, acc daemon turns the phone off to reduce the discharge rate and protect the battery from potential damage induced by voltage below the operating range. +# When the battery is discharging and its capacity/voltage_now_millivolts <= sc and phone has been running for 15 minutes or more, acc daemon turns the phone off to reduce the discharge rate and protect the battery from potential damage induced by voltage below the operating range. +# sc=0 disables it. +# The daemon posts Android shutdown warning notifications at sc+10%, sc+5%, sc+300mV and sc+100mV. # cooldown_capacity (cc) # -# Capacity at which the cooldown cycle starts. +# Capacity/voltage_now_millivolts at which the cooldown cycle starts. # Cooldown reduces battery stress induced by prolonged exposure to high temperature and high charging voltage. # It does so through periodically pausing charging for a few seconds (more details below). # resume_capacity (rc) # -# Capacity at which charging should resume. +# Capacity or voltage_now_millivolts at which charging should resume. # pause_capacity (pc) # -# Capacity at which charging should pause. +# Capacity or voltage_now_millivolts at which charging should pause. # capacity_freeze2 (cft) # # This prevents Android from getting capacity readings below 2%. @@ -397,7 +416,7 @@ currentWorkaround=false # If unset, acc cycles through its database and sets the first working switch/group that disables charging. # If the set switch/group doesn't work, acc unsets chargingSwitch and repeats the above. # If all switches fail to disable charging, chargingSwitch is unset and acc/d exit with error code 7. -# This automated process can be disabled by appending "--" to "charging_switch=...". +# This automated process can be disabled by appending " --" to "charging_switch=...". # e.g., acc -s s="battery/charge_enabled 1 0 --" # charging_switch=milliamps (e.g., 0, 250 or 500) enables current-based charging control. # For details, refer to the readme's tips section. @@ -464,7 +483,7 @@ It's a wizard you'll either love or hate. 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 `/sdcard/Documents/vr25/acc/config.txt`. +Alternatively, you can use a `text editor` to modify `/data/adb/vr25/acc-data/config.txt`. The config file itself has configuration instructions. These instructions are the same found in the `DEFAULT CONFIG` section, above. @@ -537,7 +556,7 @@ Options e.g., acc -F (lauches a zip flashing wizard) acc -F "file1" "file2" "fileN" ... (install multiple zips) - acc -F "/sdcard/Documents/vr25/Magisk-v20.0(20000).zip" + acc -F "/data/media/0/Download/Magisk-v20.0(20000).zip" -i|--info [case insentive egrep regex (default: ".")] Show battery info e.g., @@ -554,11 +573,17 @@ Options -la Same as -l -a - -l|--log -e|--export Export all logs to /sdcard/Documents/vr25/acc/logs/acc-logs-$deviceName.tar.bz2 + -l|--log -e|--export Export all logs to /data/adb/vr25/acc-data/logs/acc-logs-$deviceName.tar.bz2 e.g., acc -l -e -le Same as -l -e + -p|--parse [[base file] [file to parse]] Helps find potential charging switches quickly, for any device + e.g., + acc -p Parse /logs/power_supply-\*.log and print potential charging switches not present in /charging-switches.txt + acc -p /data/media/0/power_supply-harpia.log Parse the given file and print potential charging switches not present in /charging-switches.txt + acc -p /data/media/0/charging-switches.txt /data/media/0/power_supply-harpia.log Parse /data/media/0/power_supply-harpia.log and print potential charging switches not present in /data/media/0/charging-switches.txt + -r|--readme [editor] [editor_opts] Print/edit README.md e.g., acc -r (same as acc -r less) @@ -604,7 +629,7 @@ Options -s|--set r|--reset Restore default config e.g., acc -s r - rm /sdcard/Documents/vr25/acc/config.txt (failsafe) + rm /data/adb/vr25/acc-data/config.txt (failsafe) -sr Same as above @@ -618,7 +643,7 @@ Options -ss: Same as above - -s|--set v|--voltage [millivolts|-] [--exit] Set/print/restore_default max charging voltage (range: 3700-4200 Millivolts) + -s|--set v|--voltage [millivolts|-] [--exit] Set/print/restore_default max charging voltage (range: 3700-4300 Millivolts) e.g., acc -s v (print) acc -s v 3920 (set) @@ -636,7 +661,7 @@ Options This will also report whether "battery idle" mode is supported e.g., acc -t (test known switches) - acc -t /sdcard/experimental_switches.txt (test custom/foreign switches) + acc -t /data/media/0/experimental_switches.txt (test custom/foreign switches) -T|--logtail Monitor accd log (tail -F) e.g., acc -T @@ -680,6 +705,7 @@ Exit Codes 11. Current (mA) out of range 12. Initialization failed 13. Failed to lock /dev/.vr25/acc/acc.lock + 14. ACC wont initialize because the Magisk module disable flag is set Logs are exported automatically ("--log --export") on exit codes 1, 2, 7 and 10. @@ -709,7 +735,7 @@ These are optimized for front-ends - guaranteed to be readily available after in It may be best to use long options over short equivalents - e.g., `/dev/.vr25/acc/acca --set charging_switch=` instead of `/dev/.vr25/acc/acca -s s=`. This makes code more readable (less cryptic). -Include provided descriptions for ACC features/settings in your app(s). +Include provided descriptions of ACC features/settings in your app(s). Provide additional information (trusted) where appropriate. Explain settings/concepts as clearly and with as few words as possible. @@ -745,14 +771,6 @@ Refer back to the `BUILDING AND/OR INSTALLING FROM SOURCE` section. ## TROUBLESHOOTING -### [Samsung] Charging _Always_ Stops at 70% Capacity - -This is a device-specific issue (by design?). -It's caused by the store_mode charging control file. -Switch to batt_slate_mode to prevent it. -Refer to `### Charging Switch` below for details on that. - - ### Battery Capacity (% Level) Doesn't Seem Right When Android's battery level differs from that of the kernel, ACC daemon automatically syncs it by stopping the battery service and feeding it the real value every few seconds. @@ -781,7 +799,7 @@ Most of the time, though, it's just a matter of plugging the phone before turnin Battery level must be below pause_capacity. Once booted, one can run `acc --uninstall` (or `acc -U`) to remove ACC. -From recovery, one can flash `/sdcard/Documents/vr25/acc/acc-uninstaller.zip` or run `mount /system; /data/adb/vr25/acc/uninstall.sh`. +From recovery, one can flash `/data/adb/vr25/acc-data/acc-uninstaller.zip` or run `mount /system; /data/adb/vr25/acc/uninstall.sh`. ### Charging Switch @@ -843,18 +861,31 @@ These are simply ignored. ### Diagnostics/Logs -Volatile logs (gone on reboot) are stored in `/dev/.vr25/acc/`, persistent logs - `/sdcard/Documents/vr25/acc/logs/`. +Volatile logs (gone on reboot) are stored in `/dev/.vr25/acc/`, persistent logs - `/data/adb/vr25/acc-data/logs/`. -`acc -le` exports all acc logs, plus Magisk's and extras to `/sdcard/acc-$device_codename.tar.bz2`. +`acc -le` exports all acc logs, plus Magisk's and extras to `/data/media/0/acc-$device_codename.tar.bz2`. The logs do not contain any personal information and are never automatically sent to the developer. Automatic exporting (local) happens under specific conditions (refer back to `SETUP/USAGE > Terminal Commands > Exit Codes`). +### Finding Additional/Potential Charging Switches Quickly + +Refer to (search for) the `--parse` option. + + ### Restore Default Config This can save you a lot of time and grief. -`acc --set --reset`, `acc -sr` or `rm /sdcard/Documents/vr25/acc/config.txt` (failsafe) +`acc --set --reset`, `acc -sr` or `rm /data/adb/vr25/acc-data/config.txt` (failsafe) + + +### Samsung, Charging _Always_ Stops at 70% Capacity + +This is a device-specific issue (by design?). +It's caused by the _store_mode_ charging control file. +Switch to _batt_slate_mode_ to prevent it. +Refer back to `### Charging Switch` above for details on that. ### Slow Charging @@ -867,17 +898,36 @@ At least one of the following may be the cause: - Weak adapter and/or power cord +### Unable to Charge + +Refer back to the `## WARNINGS` section above. + + +### WARP, VOOC and Other Fast Charging Tech + +ACC may not work reliably with the original power adapter. +If you face issues, either try a different charging switch or a regular power brick (a.k.a., slow charger). +This has nothing to do with acc. +It's bad design by the OEMs themselves. + + +### Why Did accd Stop? + +Run `acc -l tail` to find out. +This will print the last 10 lines of the daemon log file. + + --- -## POWER SUPPLY LOG (HELP NEEDED) +## POWER SUPPLY LOGS (HELP NEEDED) -Please run `acc -le` and upload `/sdcard/Documents/vr25/acc/logs/power_supply-*.log` to [my dropbox](https://www.dropbox.com/request/WYVDyCc0GkKQ8U5mLNlH/) (no account/sign-up required). +Please run `acc -le` and upload `/data/adb/vr25/acc-data/logs/power_supply-*.log` to [my dropbox](https://www.dropbox.com/request/WYVDyCc0GkKQ8U5mLNlH/) (no account/sign-up required). This file contains invaluable power supply information, such as battery details and available charging control files. A public database is being built for mutual benefit. Your cooperation is greatly appreciated. Privacy Notes -- Name: phone brand and/or model (e.g., 1+7pro, Moto Z Play) +- Name: random/fake - Email: random/fake See current submissions [here](https://www.dropbox.com/sh/rolzxvqxtdkfvfa/AABceZM3BBUHUykBqOW-0DYIa?dl=0). @@ -930,8 +980,11 @@ The last sets a voltage limit that will dictate how much the battery should char The battery enters a _[pseudo] idle mode_ when its voltage peaks. Essentially, it works as a power buffer. -Limiting the charging current to 0-250 mA or so (e.g., `acc -sc 0`) may produce the same effect. +A similar effect can be achieved with settings such as `acc 60 59` (percentages) and `acc 3920 3800` (millivolts). + +Yet another way is limiting charging current to 0-250 mA or so (e.g., `acc -sc 0`). `acc -sc -` restores the default limit. +Alternatively, one can experiment with `acc -s s=0`, which uses current control files as charging switches. Force fast charge: `appy_on_boot="/sys/kernel/fast_charge/force_fast_charge::1::0 usb/boost_current::1::0 charger/boost_current::1::0"` @@ -963,7 +1016,7 @@ If your device does not support custom current limits, use a dedicated ("slow") Open issues on GitHub or contact the developer on Facebook, Telegram (preferred) or XDA (links below). Always provide as much information as possible. -Attach `/sdcard/Documents/vr25/acc/logs/acc-logs-*tar.bz2` - generated by `acc -le` _right after_ the problem occurs. +Attach `/data/adb/vr25/acc-data/logs/acc-logs-*tar.bz2` - generated by `acc -le` _right after_ the problem occurs. Refer back to `TROUBLESHOOTING > Diagnostics/Logs` for additional details. @@ -979,7 +1032,7 @@ Refer back to `POWER SUPPLY LOGS (HELP NEEDED)`. With modern battery management systems, that's generally unnecessary. -However, if your battery is underperforming, you may want to try the procedure described at https://batteryuniversity.com/index.php/learn/article/battery_calibration . +However, if your battery is underperforming, you may want to try the procedure described at https://batteryuniversity.com/article/bu-603-how-to-calibrate-a-smart-battery . > I set voltage to 4080 mV and that corresponds to just about 75% charge. @@ -1008,7 +1061,7 @@ Day/regular profile: max capacity: 75-80% and/or voltage no higher than 4100 mV Travel profile: capacity up to 95% and/or voltage no higher than 4200 mV -\* https://batteryuniversity.com/index.php/learn/article/how_to_prolong_lithium_based_batteries/ +\* https://batteryuniversity.com/article/bu-808-how-to-prolong-lithium-based-batteries/ > I don't really understand what the "-f|--force|--full [capacity]" is meant for. @@ -1067,7 +1120,7 @@ A common workaround is having `resume_capacity = pause_capacity - 1`. e.g., resu --- ## LINKS -- [Must read - how to prolong lithium ion batteries lifespan](http://batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries/) +- [Must read - how to prolong lithium ion batteries lifespan](https://batteryuniversity.com/article/bu-808-how-to-prolong-lithium-based-batteries/) - [ACC app](https://github.com/MatteCarra/AccA/releases/) - [Daily Job Scheduler](https://github.com/VR-25/djs/) - [Facebook page](https://fb.me/vr25xda/) @@ -1085,17 +1138,6 @@ A common workaround is having `resume_capacity = pause_capacity - 1`. e.g., resu ## LATEST CHANGES -**v2020.10.28 (202010280)** - -- 500 mA preset for charging_switch. -- `acc [pause_capacity [resume_capacity, default: pause_capacity - 5]]`, e.g., acc 80 (resume_capacity defaults to 80 - 5) -- Enhanced current-based charging control (still experimental, but should be more stable now). -- General fixes and optimizations -- Updated documentation. - -Release note: those using current-based charging control should reboot after the upgrade. - - **v2020.11.20 (202011200)** - Additional charging switches @@ -1127,3 +1169,40 @@ For details, refer to `config.txt > current_workaround` or `readme > default con - General optimizations Release note: those who have current-related settings must reboot after upgrading, then reapply those settings manually (e.g., `acc -sc 1800`). + + +**v2021.7.28 (202107280)** + +- acc -p|--parse: helps find potential charging switches quickly, for any device; refer to --help for details. + +- Additional charging switches +- Disable charging after a reboot, if min < capacity < max. +- Extended test (`[[...]]`) alternative function for better shell compatibility + +- Fixed issue `#89`: "--"" not respected in charging switch options. +- Fixed issue `#90`: acc is disabled in Magisk, but it keeps starting. +- Fixed issue `#97`: accd dies after plugging USB cable (thanks, @530f6caa). + +- General fixes & optimizations +- Max allowed custom charging voltage limit set to 4300 millivolts. + +- Cooldown, pause, shutdown and resume capacities can be in millivolts instead of percentages (beta feature). + +- Post Android shutdown warning notifications at sc+10%, sc+5%, sc+300mV and sc+100mV (beta feature). + +- Save data to /data/adb/vr25/acc-data/, for security reasons. +- Strip negative sign from current if battery is charging. +- Updated documentation. + +- Use /data/media/0 over /sdcard as base path for user data. FUSE/SDcardFS seem to have issues in deep sleep - making emulated storage unavailable. + +Release Notes + +- `acc pause_millivolts resume_millivolts`, e.g., `acc 3920 3800`, is yet another "cheap" alternative to direct charging voltage control. + +- If you've been facing the "accd stops randomly" issue, share the output of `acc -l tail` as soon as you notice the problem. + +- If you need more charging switches, try `acc -p` while charging; it'll print potential candidates. +The results can be batch tested with `acc -t /path/to/list` or `acc -t file on off`. + +- Upgrading to this version will reset config.txt. diff --git a/TODO.txt b/TODO.txt index dd168e8..31d6ed6 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,5 +1,14 @@ -remove #legacy +As whole idea is to enhance battery life and one of the most important is to prevent complete discharges, reasonable is to have some feedback when device is idle. +In more specific it would have user set up value of battery left capacity making play sound (also chosen by user) when battery capacity drop below the value. Ideally would have few such thresholds (and sounds). + printf '\7' + echo 200 > /sys/class/timed_output/vibrator/enable + su -lp 2000 -c "cmd notification post -S bigtext -t 'Title' 'Tag' 'Multiline text'" -alerts/notifications + preliminary work done -pixel 4a switch issue + +add acc --info to the wizard + +add more charging switches + +accd.sh, 330: isCharging:=false failing - parameter not set? diff --git a/acc/acc.sh b/acc/acc.sh index a5e1f4c..e25027d 100644 --- a/acc/acc.sh +++ b/acc/acc.sh @@ -1,6 +1,6 @@ #!/system/bin/sh # Advanced Charging Controller -# Copyright 2017-present, VR25 +# Copyright 2017-2021, VR25 # License: GPLv3+ @@ -121,8 +121,8 @@ exxit() { local exitCode=$? set +eux ! ${noEcho:-false} && ${verbose:-true} && echo - [[ $exitCode = [05689] ]] || { - [[ $exitCode = [127] || $exitCode = 10 ]] && logf --export + tt "$exitCode" "[05689]" || { + tt "$exitCode" "[127]|10" && logf --export echo } cd / @@ -130,6 +130,42 @@ exxit() { } +parse_switches() { + + local f=/dev/.parse_switches.tmp + local i + local n + + [ -n "${2-}" ] || set -- $execDir/charging-switches.txt "${1-}" + + if [ -z "${2-}" ]; then + set -- $1 ${config_%/*}/logs/power_supply-*.log + $execDir/power-supply-logger.sh + echo + fi + + cat -v "$2" > $f + + for i in $(grep -En '^ (1|0)$' $f | cut -d: -f1); do + + n=$i + i="$(sed -n "$(($n - 1))p" "$f")" + n=$(sed -n ${n}p $f) + n="$([ $n -eq 1 ] && echo "1 0" || echo "0 1")" + + i="$(echo "$i $n" | grep -Eiv 'brightness|curr|online|present|runtime|status|temp|volt|wakeup' \ + | sed 's|^/.*/power_supply/||')" + + if ! grep -q "^$i" $1; then + echo "$i" + fi + + done + + rm $f +} + + set_prop_() { . $execDir/set-prop.sh set_prop "$@" @@ -149,7 +185,7 @@ log=$TMPDIR/acc-${device}.log # verbose -if ${verbose:-true} && [[ "${1-}" != *-w* ]]; then +if ${verbose:-true} && ! tt "${1-}" "*-w*"; then [ -z "${LINENO-}" ] || export PS4='$LINENO: ' touch $log [ $(du -m $log | cut -f 1) -ge 2 ] && : > $log @@ -166,7 +202,7 @@ unset -f get_prop misc_stuff "${1-}" -[[ "${1-}" != */* ]] || shift +! tt "${1-}" "*/*" || shift # reset broken/obsolete config @@ -191,7 +227,7 @@ grep -q .. $execDir/translations/$language/README.md 2>/dev/null \ # aliases/shortcuts # daemon_ctrl status (acc -D|--daemon): "accd," # daemon_ctrl stop (acc -D|--daemon stop): "accd." -[[ $0 != *accd* ]] || { +! tt "$0" "*accd*" || { case $0 in *accd.) daemon_ctrl stop;; *) daemon_ctrl;; @@ -282,7 +318,7 @@ case "${1-}" in { { - if [[ "$dsys" = *reset* ]] > /dev/null; then + if tt "${dsys:-x}" "*reset*"; then status=$(echo "$dsys" | sed -n 's/^ status: //p') level=$(echo "$dsys" | sed -n 's/^ level: //p') @@ -328,6 +364,11 @@ case "${1-}" in logf "$@" ;; + -p|--parse) + shift + parse_switches "$@" + ;; + -r|--readme) shift; edit $readMe "$@" ;; @@ -470,9 +511,9 @@ case "${1-}" in || reference=master } - ! test -f /data/adb/bin/curl || { - test -x /data/adb/bin/curl \ - || chmod -R 0700 /data/adb/bin + ! test -f /data/adb/vr25/bin/curl || { + test -x /data/adb/vr25/bin/curl \ + || chmod -R 0700 /data/adb/vr25/bin } curl $insecure -Lo $TMPDIR/install-online.sh https://raw.githubusercontent.com/VR-25/acc/$reference/install-online.sh diff --git a/acc/acca.sh b/acc/acca.sh index ca3862c..95ba315 100644 --- a/acc/acca.sh +++ b/acc/acca.sh @@ -31,7 +31,7 @@ switch_mA() { set -eu execDir=/data/adb/vr25/acc -config=/sdcard/Documents/vr25/acc/config.txt +config=/data/adb/vr25/acc-data/config.txt defaultConfig=$execDir/default-config.txt TMPDIR=/dev/.vr25/acc verbose=false diff --git a/acc/accd.sh b/acc/accd.sh index 8f0afd6..88ab6b4 100644 --- a/acc/accd.sh +++ b/acc/accd.sh @@ -1,6 +1,6 @@ #!/system/bin/sh # Advanced Charging Controller Daemon (accd) -# Copyright 2017-present, VR25 +# Copyright 2017-2021, VR25 # License: GPLv3+ # # devs: triple hashtags (###) mark non-generic code @@ -31,6 +31,61 @@ pgrep zygote > /dev/null && { if ! $init; then + + _ge_cooldown_cap() { + if t ${capacity[1]} -gt 3000; then + t $(grep -o '^....' $voltage_now) -ge ${capacity[1]} + else + t $(cat $batt/capacity) -ge ${capacity[1]} + fi + } + + + _ge_pause_cap() { + if t ${capacity[3]} -gt 3000; then + t $(grep -o '^....' $voltage_now) -ge ${capacity[3]} + else + t $(cat $batt/capacity) -ge ${capacity[3]} + fi + } + + + _lt_pause_cap() { + if t ${capacity[3]} -gt 3000; then + t $(grep -o '^....' $voltage_now) -lt ${capacity[3]} + else + t $(cat $batt/capacity) -lt ${capacity[3]} + fi + } + + + _gt_resume_cap() { + if t ${capacity[2]} -gt 3000; then + t $(grep -o '^....' $voltage_now) -gt ${capacity[2]} + else + t $(cat $batt/capacity) -gt ${capacity[2]} + fi + } + + + _le_resume_cap() { + if t ${capacity[2]} -gt 3000; then + t $(grep -o '^....' $voltage_now) -le ${capacity[2]} + else + t $(cat $batt/capacity) -le ${capacity[2]} + fi + } + + + _le_shutdown_cap() { + if t ${capacity[0]} -gt 3000; then + t $(grep -o '^....' $voltage_now) -le ${capacity[0]} + else + t $(cat $batt/capacity) -le ${capacity[0]} + fi + } + + exxit() { exitCode=$? set +eux @@ -49,7 +104,7 @@ if ! $init; then } > /dev/null 2>&1 [ -n "$1" ] && exitCode=$1 [ -n "$2" ] && print "$2" - [[ $exitCode = [127] ]] && { + tt "$exitCode" "[127]" && { . $execDir/logf.sh logf --export > /dev/null 2>&1 & pids+=($!) @@ -150,9 +205,11 @@ if ! $init; then $isCharging && return 0 || return 1 } + ctrl_charging() { local count=0 + local i while :; do @@ -161,7 +218,7 @@ if ! $init; then # disable charging under test $(cat $temp) -ge $(( ${temperature[1]} * 10 )) \ && maxTempPause=true || maxTempPause=false - if $maxTempPause || test $(cat $batt/capacity) -ge ${capacity[3]}; then + if $maxTempPause || _ge_pause_cap; then disable_charging ! ${resetBattStats[0]} || { # reset battery stats on pause @@ -173,11 +230,11 @@ if ! $init; then # cooldown cycle while [ -n "${cooldownRatio[0]-}${cooldownCustom[0]-}" ] \ - && [ $(cat $batt/capacity) -lt ${capacity[3]} ] \ + && _lt_pause_cap \ && is_charging do if [ $(cat $temp) -ge $(( ${temperature[0]} * 10 )) ] \ - || [ $(cat $batt/capacity) -ge ${capacity[1]} ] \ + || _ge_cooldown_cap \ || [ $(sed s/-// ${cooldownCustom[0]:-cooldownCustom} 2>/dev/null || echo 0) -ge ${cooldownCustom[1]:-1} ] then cooldown=true @@ -196,7 +253,7 @@ if ! $init; then while [ $count -lt ${cooldownRatio[0]:-1} ] do sleep ${loopDelay[0]} - [ $(cat $batt/capacity) -lt ${capacity[3]} ] \ + _lt_pause_cap \ && count=$(( count + ${loopDelay[0]} )) \ || break done @@ -214,7 +271,7 @@ if ! $init; then count=0 while ! not_charging && [ $count -lt ${cooldownRatio[0]:-1} ]; do sleep ${loopDelay[0]} - [ $(cat $batt/capacity) -lt ${capacity[3]} ] \ + _lt_pause_cap \ && count=$(( count + ${loopDelay[0]} )) \ || break done @@ -230,21 +287,36 @@ if ! $init; then else # enable charging under - [ ! $(cat $batt/capacity) -le ${capacity[2]} ] || { + if _le_resume_cap; then [ ! $(cat $temp) -lt $(( ${temperature[1]} * 10 )) ] \ || enable_charging - } + fi # auto-shutdown - if not_charging && ! $maxTempPause \ - && [ $(cat $batt/capacity) -le ${capacity[0]} ] \ - && [ $(cut -d '.' -f 1 /proc/uptime) -ge 900 ] - then - sleep ${loopDelay[1]} - ! not_charging \ - || am start -n android/com.android.internal.app.ShutdownActivity < /dev/null > /dev/null 2>&1 \ - || reboot -p 2>/dev/null \ - || /system/bin/reboot -p || : + if ! $maxTempPause && [ $(cut -d '.' -f 1 /proc/uptime) -ge 900 ] && not_charging dis; then + if [ ${capacity[0]} -ge 1 ]; then + # warnings + if t ${capacity[0]} -gt 3000; then + i=2 + ! t $(grep -o '^..' $voltage_now) -eq $(( ${capacity[0]%??} + i )) \ + || su -lp 2000 -c "cmd notification post -S bigtext -t 'ACC' 'Tag' \"WARNING: $(grep -o '^....' $voltage_now | sed 's/^.//' | sed "s/^./$i/")mV to auto shutdown, plug the charger!\"" \ + && sleep ${loopDelay[1]} || : + else + for i in 5 10; do + ! t $(cat $batt/capacity) -eq $(( ${capacity[0]} + i )) \ + || su -lp 2000 -c "cmd notification post -S bigtext -t 'ACC' 'Tag' \"WARNING: ${i}% to auto shutdown, plug the charger!\"" \ + && sleep ${loopDelay[1]} || : + done + fi + # action + if _le_shutdown_cap; then + sleep ${loopDelay[1]} + ! not_charging dis \ + || am start -n android/com.android.internal.app.ShutdownActivity < /dev/null > /dev/null 2>&1 \ + || reboot -p 2>/dev/null \ + || /system/bin/reboot -p || : + fi + fi fi sleep ${loopDelay[1]} @@ -255,6 +327,7 @@ if ! $init; then sync_capacity() { + : isCharging:=false local isCharging_=$isCharging ! $capacitySync || { ! $cooldown || isCharging=true @@ -303,7 +376,21 @@ if ! $init; then . $config + voltage_now=$batt/voltage_now + t -f $voltage_now || voltage_now=$batt/batt_vol + if ! t -f $voltage_now; then + echo 3920 > $TMPDIR/.voltage_now + voltage_now=$TMPDIR/.voltage_now + fi + + apply_on_boot + + # disable charging after a reboot, if min < capacity < max + if _lt_pause_cap && _gt_resume_cap; then + disable_charging + fi + ctrl_charging exit $? @@ -311,9 +398,11 @@ if ! $init; then else - # log - data_dir=/sdcard/Documents/vr25/$id + data_dir=/data/adb/vr25/${id}-data mkdir -p $TMPDIR $data_dir/logs + + + # log exec > $data_dir/logs/init.log 2>&1 set -x @@ -335,17 +424,18 @@ else ln -fs $execDir/${id}a.sh /dev/.$domain/$id/${id}a ln -fs $execDir/service.sh /dev/.$domain/$id/${id}d - test -d /sbin && { - ! grep -q "^tmpfs / " /proc/mounts \ - || /system/bin/mount -o remount,rw / 2>/dev/null \ - || mount -o remount,rw / - for h in /dev/.$domain/$id/$id \ + if [ -d /sbin ]; then + if grep -q '^tmpfs / ' /proc/mounts; then + /system/bin/mount -o remount,rw / \ + || mount -o remount,rw / + fi + for h in /dev/.$domain/$id/$id \ /dev/.$domain/$id/${id}d, /dev/.$domain/$id/${id}d. \ /dev/.$domain/$id/${id}a /dev/.$domain/$id/${id}d do ln -fs $h /sbin/ 2>/dev/null || break done - } + fi # fix Termux's PATH (missing /sbin/) diff --git a/acc/batt-info.sh b/acc/batt-info.sh index f79c55e..d6342ea 100644 --- a/acc/batt-info.sh +++ b/acc/batt-info.sh @@ -42,6 +42,11 @@ batt_info() { dtr_conv_factor ${currNow#-} ${ampFactor-} currNow=$(calc ${currNow:-0} / $factor) + # strip negative sign if charging + case $currNow in + -*) grep -Eiq 'dis|not' $batt/status || currNow=${currNow#-} + ;; + esac # parse VOLTAGE_NOW & convert to Volts voltNow=$(echo "$info" | sed -n "s/^VOLTAGE_NOW=//p") diff --git a/acc/charging-switches.txt b/acc/charging-switches.txt index 0ff2cee..78933bf 100644 --- a/acc/charging-switches.txt +++ b/acc/charging-switches.txt @@ -1,16 +1,14 @@ # ACC Charging Switches Database -# Copyright 2017-present, VR25 +# Copyright 2017-2021, VR25 # License: GPLv3+ # # "::" = " " # PWD=/sys/class/power_supply -# Last updated: Mon, Dec 7, 2020 +# Last updated: Thu, Jul 22, 2021 smb?/input_suspend battery/charger_control 1 0 */charge_disable 0 1 -sm*_bms/charge_disable 0 1 -smb?/charge_disable 0 1 idt/pin_enabled 1 0 manta-battery/charge_enabled 1 0 battery/charge_enabled 1 0 @@ -60,7 +58,7 @@ battery/device/smartchg_stop_charging 0 1 /proc/mtk_battery_cmd/current_cmd 0::0 0::1 /proc/mtk_battery_cmd/en_power_path 1 0 /proc/driver/charger_limit_enable 0 1 /proc/driver/charger_limit 100 1 /sys/module/lge_battery/parameters/charge_stop_level 100 1 battery/input_suspend 0 0 -/sys/devices/platform/*.i2c/i2c-?/?-*/*-battery/power_supply/battery/charging_enabled 1 0 +#/sys/devices/platform/*.i2c/i2c-?/?-*/*-battery/power_supply/battery/charging_enabled 1 0 battery/input_suspend 0 1 @@ -113,3 +111,13 @@ battery/mmi_charging_enable 1 0 #/proc/mtk_battery_cmd/current_cmd 0::0 0::1 battery/ChargerEnable 1 0 /sys/devices/platform/battery/ChargerEnable 1 0 + +# untested +battery/batt_ce_full 0 1 +#usb/pd_active 1 0 +battery/pd_disable 0 1 +#/sys/devices/platform/soc/soc:google,charger/charge_start_level 0 1 +#/sys/devices/platform/tegra-i2c.*/i2c-*/*/battery_smbus 1 0 +pack_bat/charge_full 0 1 +/sys/class/qcom-battery/input_suspend 0 1 +bq*standalone/charging_enabled 1 0 diff --git a/acc/default-config.txt b/acc/default-config.txt index 56c7864..7a7e29c 100644 --- a/acc/default-config.txt +++ b/acc/default-config.txt @@ -131,7 +131,8 @@ currentWorkaround=false # acc --set pause_capacity=85 resume_capacity=80 # acc -s "s=battery/charging_enabled 1 0" -# acc --set "charging_switch=/proc/mtk_battery_cmd/current_cmd 0::0 0::1 /proc/mtk_battery_cmd/en_power_path 1 0" ("::" = " ") +# acc --set "charging_switch=/proc/mtk_battery_cmd/current_cmd 0::0 0::1 /proc/mtk_battery_cmd/en_power_path 1 0" +# NOTE: "::" is used as a whitespace placeholder in "/proc/mtk_battery_cmd/current_cmd 0::0 0::1" charging switch only. # acc -s -v 3920 (millivolts) # acc -s -c 500 (milliamps) @@ -163,18 +164,20 @@ currentWorkaround=false # This is checked during updates to determine whether config should be patched. Do NOT modify. # shutdown_capacity (sc) # -# When the battery is discharging and its capacity <= sc and phone has been running for 15 minutes or more, acc daemon turns the phone off to reduce the discharge rate and protect the battery from potential damage induced by voltage below the operating range. +# When the battery is discharging and its capacity/voltage_now_millivolts <= sc and phone has been running for 15 minutes or more, acc daemon turns the phone off to reduce the discharge rate and protect the battery from potential damage induced by voltage below the operating range. +# sc=0 disables it. +# The daemon posts Android shutdown warning notifications at sc+10%, sc+5%, sc+300mV and sc+100mV. # cooldown_capacity (cc) # -# Capacity at which the cooldown cycle starts. +# Capacity/voltage_now_millivolts at which the cooldown cycle starts. # Cooldown reduces battery stress induced by prolonged exposure to high temperature and high charging voltage. # It does so through periodically pausing charging for a few seconds (more details below). # resume_capacity (rc) # -# Capacity at which charging should resume. +# Capacity or voltage_now_millivolts at which charging should resume. # pause_capacity (pc) # -# Capacity at which charging should pause. +# Capacity or voltage_now_millivolts at which charging should pause. # capacity_freeze2 (cft) # # This prevents Android from getting capacity readings below 2%. @@ -221,7 +224,7 @@ currentWorkaround=false # If unset, acc cycles through its database and sets the first working switch/group that disables charging. # If the set switch/group doesn't work, acc unsets chargingSwitch and repeats the above. # If all switches fail to disable charging, chargingSwitch is unset and acc/d exit with error code 7. -# This automated process can be disabled by appending "--" to "charging_switch=...". +# This automated process can be disabled by appending " --" to "charging_switch=...". # e.g., acc -s s="battery/charge_enabled 1 0 --" # charging_switch=milliamps (e.g., 0, 250 or 500) enables current-based charging control. # For details, refer to the readme's tips section. diff --git a/acc/flash-zips.sh b/acc/flash-zips.sh index b608a34..35f4d75 100644 --- a/acc/flash-zips.sh +++ b/acc/flash-zips.sh @@ -24,7 +24,7 @@ s_() { pick_zips() { clear echo - cd "${1-/sdcard/Download/}" + cd "${1-/data/media/0/Download/}" echo ": $PWD/" IFS=$'\n' select_ target $(ls -1Ap | grep -Ei '.*.zip$|/$') "" "" "" diff --git a/acc/logf.sh b/acc/logf.sh index 7c74ebe..759a23e 100644 --- a/acc/logf.sh +++ b/acc/logf.sh @@ -1,8 +1,8 @@ logf() { - if [[ "${1:-x}" = -*e* ]]; then + if tt "${1:-x}" "-*e*"; then - data_dir=/sdcard/Documents/vr25/acc + data_dir=/data/adb/vr25/acc-data mkdir -p $data_dir/logs exec 2>> ${log:-/dev/null} @@ -41,7 +41,7 @@ logf() { echo "(i) $data_dir/logs/acc-logs-$device.tar.bz2" else - if [[ "${1:-x}" = -*a* ]]; then + if tt "${1:-x}" "-*a*"; then shift edit $log "$@" else diff --git a/acc/misc-functions.sh b/acc/misc-functions.sh index ad74d66..c1eab2a 100644 --- a/acc/misc-functions.sh +++ b/acc/misc-functions.sh @@ -4,7 +4,7 @@ apply_on_boot() { [ ${2:-x} != force ] || force=true - [[ "${applyOnBoot[@]-}${maxChargingVoltage[@]-}" != *--exit* ]] || exitCmd=true + ! tt "${applyOnBoot[@]-}${maxChargingVoltage[@]-}" "*--exit*" || exitCmd=true for entry in "${applyOnBoot[@]-}" "${maxChargingVoltage[@]-}"; do [ "$entry" != --exit ] || continue @@ -67,6 +67,7 @@ cycle_switches() { else if sleep_sd not_charging ${2-}; then # set working charging switch(es) + s="${chargingSwitch[*]}" # for some reason, without this, the array is null . $execDir/write-config.sh break else @@ -92,41 +93,40 @@ disable_charging() { then local autoMode=true - [[ "${chargingSwitch[*]-}" = *-- ]] || autoMode=false + ! tt "${chargingSwitch[*]-}" "*--" || autoMode=false ! $isAccd || ! not_charging || return 0 - if [[ "${chargingSwitch[0]-}" = */* ]]; then + if tt "${chargingSwitch[0]-}" "*/*"; then if [ -f ${chargingSwitch[0]} ]; then # toggle primary switch - if chmod 0644 ${chargingSwitch[0]} && run_xtimes "echo ${chargingSwitch[2]//::/ } > ${chargingSwitch[0]}"; then - [ ! -f "${chargingSwitch[3]-}" ] || { - # toggle secondary switch - chmod 0644 ${chargingSwitch[3]} && run_xtimes "echo ${chargingSwitch[5]//::/ } > ${chargingSwitch[3]}" || { - $isAccd || print_switch_fails - unset_switch - cycle_switches_off - } - } - if $autoMode && ! sleep_sd not_charging; then - unset_switch - cycle_switches_off + if chmod 0644 ${chargingSwitch[0]} \ + && run_xtimes "echo ${chargingSwitch[2]//::/ } > ${chargingSwitch[0]}" + then + if tt "${chargingSwitch[3]-}" "*/*"; then + if t -f "${chargingSwitch[3]-}"; then + # toggle secondary switch + chmod 0644 ${chargingSwitch[3]} \ + && run_xtimes "echo ${chargingSwitch[5]//::/ } > ${chargingSwitch[3]}" \ + || switch_fails + else + invalid_switch + fi fi else - $isAccd || print_switch_fails - unset_switch - cycle_switches_off + switch_fails fi + sleep_sd not_charging || switch_fails else - $isAccd || print_invalid_switch - unset_switch - cycle_switches_off + invalid_switch fi else cycle_switches_off fi - not_charging || ! $autoMode || return 7 # total failure + if $autoMode && ! not_charging; then + return 7 # total failure + fi else maxChargingCurrent0=${maxChargingCurrent[0]-} @@ -179,7 +179,7 @@ enable_charging() { ! $isAccd || not_charging || return 0 - if ! $ghostCharging || { $ghostCharging && [[ $(cat */online) = *1* ]]; }; then + if ! $ghostCharging || { $ghostCharging && tt "$(cat */online)" "*1*"; }; then chmod 0644 ${chargingSwitch[0]-} ${chargingSwitch[3]-} 2>/dev/null \ && run_xtimes "echo ${chargingSwitch[1]//::/ } > ${chargingSwitch[0]-} @@ -187,8 +187,8 @@ enable_charging() { || cycle_switches on # detect and block ghost charging - if ! $ghostCharging && ! not_charging && [[ $(cat */online) != *1* ]] \ - && sleep ${loopDelay[0]} && ! not_charging && [[ $(cat */online) != *1* ]] + if ! $ghostCharging && ! not_charging && ! tt "$(cat */online)" "*1*" \ + && sleep ${loopDelay[0]} && ! not_charging && ! tt "$(cat */online)" "*1*" then ghostCharging=true disable_charging > /dev/null @@ -240,6 +240,13 @@ enable_charging() { } +invalid_switch() { + $isAccd || print_invalid_switch + unset_switch + cycle_switches_off +} + + misc_stuff() { set -eu mkdir -p ${config%/*} 2>/dev/null || : @@ -263,7 +270,7 @@ not_charging() { print_header() { echo "Advanced Charging Controller $accVer ($accVerCode) -Copyright 2017-present, VR25 +Copyright 2017-2021, VR25 GPLv3+" } @@ -292,6 +299,15 @@ sleep_sd() { } +switch_fails() { + $isAccd || print_switch_fails "${chargingSwitch[@]}" + if $autoMode; then + unset_switch + cycle_switches_off + fi +} + + switch_mA() { case "$1" in */*) return 1;; @@ -300,6 +316,19 @@ switch_mA() { } +# test +t() { test "$@"; } + + +# extended test +tt() { + eval "case \"$1\" in + $2) return 0;; + esac" + return 1 +} + + unset_switch() { charging_switch= . $execDir/write-config.sh @@ -311,7 +340,7 @@ wait_plug() { echo "(i) ghostCharging=true" print_wait_plug } - (while [[ $(cat */online) != *1* ]]; do + (while ! tt "$(cat */online)" "*1*"; do sleep ${loopDelay[1]} ! $isAccd || sync_capacity set +x @@ -330,7 +359,7 @@ loopDelay=(10 10) execDir=/data/adb/$domain/acc ctrlFileWrites=(3 0.3) export TMPDIR=/dev/.vr25/acc -config=/sdcard/Documents/$domain/$id/config.txt +config=/data/adb/$domain/${id}-data/config.txt config_=$config [ -f $TMPDIR/.ghost-charging ] \ @@ -369,7 +398,7 @@ temp=$batt/temp } # cmd and dumpsys wrappers for Termux and recovery -[[ $(readlink -f $execDir) != *com.termux* ]] || { +! tt "$(readlink -f $execDir)" "*com.termux*" || { cmd_batt() { su -c /system/bin/cmd battery "$@" < /dev/null > /dev/null 2>&1 || :; } dumpsys() { su -c /system/bin/dumpsys "$@" || :; } } diff --git a/acc/power-supply-logger.sh b/acc/power-supply-logger.sh index 1e0b958..cad18a5 100644 --- a/acc/power-supply-logger.sh +++ b/acc/power-supply-logger.sh @@ -1,6 +1,6 @@ #!/system/bin/sh # Advanced Charging Controller Power Supply Logger -# Copyright 2019-2020, VR25 +# Copyright 2019-2021, VR25 # License: GPLv3+ @@ -43,7 +43,7 @@ gather_ps_data() { export TMPDIR=/dev/.vr25/acc execDir=/data/adb/vr25/acc -logsDir=/sdcard/Documents/vr25/acc/logs +logsDir=/data/adb/vr25/acc-data/logs print_wait 2>/dev/null || echo "(i) Alright, this may take a minute or so..." diff --git a/acc/service.sh b/acc/service.sh index 5d0fd32..f47b98f 100644 --- a/acc/service.sh +++ b/acc/service.sh @@ -1,6 +1,6 @@ #!/system/bin/sh # $id initializer -# Copyright 2017-present, VR25 +# Copyright 2017-2021, VR25 # License: GPLv3+ id=acc @@ -8,6 +8,7 @@ domain=vr25 TMPDIR=/dev/.$domain/$id execDir=/data/adb/$domain/$id +[ -f $execDir/disable ] && exit 14 umask 0077 mkdir -p $TMPDIR export domain execDir id TMPDIR diff --git a/acc/set-ch-volt.sh b/acc/set-ch-volt.sh index f349c98..044e8e4 100644 --- a/acc/set-ch-volt.sh +++ b/acc/set-ch-volt.sh @@ -23,19 +23,19 @@ set_ch_volt() { } || return 1 } - # = [3700-4200] millivolts - if [ $1 -ge 3700 -a $1 -le 4200 ]; then + # = [3700-4300] millivolts + if [ $1 -ge 3700 -a $1 -le 4300 ]; then apply_voltage $1 ${2-} || return 1 # < 3700 millivolts elif [ $1 -lt 3700 ]; then - ! ${verbose:-true} || echo "(!) [3700-4200]$(print_mV; print_only)" + ! ${verbose:-true} || echo "(!) [3700-4300]$(print_mV; print_only)" apply_voltage 3700 ${2-} || return 1 - # > 4200 millivolts - elif [ $1 -gt 4200 ]; then - ! ${verbose:-true} || echo "(!) [3700-4200]$(print_mV; print_only)" - apply_voltage 4200 ${2-} || return 1 + # > 4300 millivolts + elif [ $1 -gt 4300 ]; then + ! ${verbose:-true} || echo "(!) [3700-4300]$(print_mV; print_only)" + apply_voltage 4300 ${2-} || return 1 fi fi diff --git a/acc/set-prop.sh b/acc/set-prop.sh index ea47d46..7f18d74 100644 --- a/acc/set-prop.sh +++ b/acc/set-prop.sh @@ -24,7 +24,7 @@ set_prop() { # reset config r|--reset) ! daemon_ctrl stop > /dev/null || restartDaemon=true - cp -f $defaultConfig $config + cat $defaultConfig > $config print_config_reset ! $restartDaemon || /dev/.vr25/acc/accd $config return 0 diff --git a/acc/setup-busybox.sh b/acc/setup-busybox.sh index a1fe80c..f350195 100644 --- a/acc/setup-busybox.sh +++ b/acc/setup-busybox.sh @@ -5,24 +5,24 @@ # Usage: . $0 -[ -x /dev/.busybox/ls ] || { - mkdir -p /dev/.busybox - chmod 0700 /dev/.busybox - if [ -f /data/adb/bin/busybox ]; then - [ -x /data/adb/bin/busybox ] || chmod -R 0700 /data/adb/bin - /data/adb/bin/busybox --install -s /dev/.busybox +[ -x /dev/.vr25/busybox/ls ] || { + mkdir -p /dev/.vr25/busybox + chmod 0700 /dev/.vr25/busybox + if [ -f /data/adb/vr25/bin/busybox ]; then + [ -x /data/adb/vr25/bin/busybox ] || chmod -R 0700 /data/adb/vr25/bin + /data/adb/vr25/bin/busybox --install -s /dev/.vr25/busybox elif [ -f /data/adb/magisk/busybox ]; then [ -x /data/adb/magisk/busybox ] || chmod 0700 /data/adb/magisk/busybox - /data/adb/magisk/busybox --install -s /dev/.busybox + /data/adb/magisk/busybox --install -s /dev/.vr25/busybox elif which busybox > /dev/null; then - eval "$(which busybox) --install -s /dev/.busybox" + eval "$(which busybox) --install -s /dev/.vr25/busybox" else - echo "(!) Install busybox or simply place it in /data/adb/bin/" + echo "(!) Install busybox or simply place it in /data/adb/vr25/bin/" exit 3 fi } case $PATH in - /data/adb/bin:*) :;; - *) export PATH=/data/adb/bin:/dev/.busybox:$PATH;; + /data/adb/vr25/bin:*) :;; + *) export PATH=/data/adb/vr25/bin:/dev/.vr25/busybox:$PATH;; esac diff --git a/acc/strings.sh b/acc/strings.sh index d3bd66b..40a29fb 100644 --- a/acc/strings.sh +++ b/acc/strings.sh @@ -32,10 +32,6 @@ print_known_switches() { echo "(i) Known charging switches" } -print_switch_fails() { - echo "(!) [${chargingSwitch[@]}] won't work" -} - print_invalid_switch() { echo "(!) Invalid charging switch, [${chargingSwitch[@]}]" } @@ -151,7 +147,7 @@ Options e.g., acc -F (lauches a zip flashing wizard) acc -F "file1" "file2" "fileN" ... (install multiple zips) - acc -F "/sdcard/Documents/vr25/Magisk-v20.0(20000).zip" + acc -F "/data/media/0/Download/Magisk-v20.0(20000).zip" -i|--info [case insentive egrep regex (default: ".")] Show battery info e.g., @@ -168,11 +164,17 @@ Options -la Same as -l -a - -l|--log -e|--export Export all logs to /sdcard/Documents/vr25/acc/logs/acc-logs-\$deviceName.tar.bz2 + -l|--log -e|--export Export all logs to /data/adb/vr25/acc-data/logs/acc-logs-\$deviceName.tar.bz2 e.g., acc -l -e -le Same as -l -e + -p|--parse [[base file] [file to parse]] Helps find potential charging switches quickly, for any device + e.g., + acc -p Parse ${config_%/*}/logs/power_supply-\*.log and print potential charging switches not present in $execDir/charging-switches.txt + acc -p /data/media/0/power_supply-harpia.log Parse the given file and print potential charging switches not present in $execDir/charging-switches.txt + acc -p /data/media/0/charging-switches.txt /data/media/0/power_supply-harpia.log Parse /data/media/0/power_supply-harpia.log and print potential charging switches not present in /data/media/0/charging-switches.txt + -r|--readme [editor] [editor_opts] Print/edit README.md e.g., acc -r (same as acc -r less) @@ -218,7 +220,7 @@ Options -s|--set r|--reset Restore default config e.g., acc -s r - rm /sdcard/Documents/vr25/acc/config.txt (failsafe) + rm /data/adb/vr25/acc-data/config.txt (failsafe) -sr Same as above @@ -232,7 +234,7 @@ Options -ss: Same as above - -s|--set v|--voltage [millivolts|-] [--exit] Set/print/restore_default max charging voltage (range: 3700-4200$(print_mV)) + -s|--set v|--voltage [millivolts|-] [--exit] Set/print/restore_default max charging voltage (range: 3700-4300$(print_mV)) e.g., acc -s v (print) acc -s v 3920 (set) @@ -250,7 +252,7 @@ Options This will also report whether "battery idle" mode is supported e.g., acc -t (test known switches) - acc -t /sdcard/experimental_switches.txt (test custom/foreign switches) + acc -t /data/media/0/experimental_switches.txt (test custom/foreign switches) -T|--logtail Monitor accd log (tail -F) e.g., acc -T @@ -294,6 +296,7 @@ Exit Codes 11. Current (mA) out of range 12. Initialization failed 13. Failed to lock /dev/.vr25/acc/acc.lock + 14. ACC wont initialize because the Magisk module disable flag is set Logs are exported automatically ("--log --export") on exit codes 1, 2, 7 and 10. @@ -463,3 +466,7 @@ print_m_mode() { print_wait() { echo "(i) Alright, this may take a minute or so..." } + +print_as_warning() { + echo "WARNING: I'll shutdown the system at ${1}% battery if you don't plug the charger!" +} diff --git a/acc/translations/id/strings.sh b/acc/translations/id/strings.sh index cfe1d89..593bc7d 100644 --- a/acc/translations/id/strings.sh +++ b/acc/translations/id/strings.sh @@ -32,10 +32,6 @@ print_known_switches() { echo "(i) Saklar pengisi daya yang diketahui" } -print_switch_fails() { - echo "(!) [${chargingSwitch[@]}] tidak akan bekerja" -} - print_invalid_switch() { echo "(!) Saklar pengisi daya salah, [${chargingSwitch[@]}]" } diff --git a/acc/translations/pt-PT/strings.sh b/acc/translations/pt-PT/strings.sh index a7733f1..ab3d9c3 100644 --- a/acc/translations/pt-PT/strings.sh +++ b/acc/translations/pt-PT/strings.sh @@ -32,10 +32,6 @@ print_known_switches() { echo "(i) Interruptores de carga suportados" } -print_switch_fails() { - echo "(!) [${chargingSwitch[@]}] não funciona" -} - print_invalid_switch() { echo "(!) Interruptor de carga inválido, [${chargingSwitch[@]}]" } diff --git a/acc/translations/zh-rCN/strings.sh b/acc/translations/zh-rCN/strings.sh index dc02d9f..d10c7e3 100644 --- a/acc/translations/zh-rCN/strings.sh +++ b/acc/translations/zh-rCN/strings.sh @@ -32,10 +32,6 @@ print_known_switches() { echo "(i) 充电开关可用" } -print_switch_fails() { - echo "(!) [${chargingSwitch[@]}] 不可用" -} - print_invalid_switch() { echo "(!) 无效充电开关, [${chargingSwitch[@]}]" } diff --git a/acc/translations/zh-rTW/strings.sh b/acc/translations/zh-rTW/strings.sh index f1a5a6f..7fc318a 100644 --- a/acc/translations/zh-rTW/strings.sh +++ b/acc/translations/zh-rTW/strings.sh @@ -32,10 +32,6 @@ print_known_switches() { echo "(i) 充電開關可用" } -print_switch_fails() { - echo "(!) [${chargingSwitch[@]}] 不可用" -} - print_invalid_switch() { echo "(!) 無效的充電開關, [${chargingSwitch[@]}]" } diff --git a/acc/uninstall.sh b/acc/uninstall.sh index 58e0f51..1e1cd3c 100644 --- a/acc/uninstall.sh +++ b/acc/uninstall.sh @@ -1,7 +1,7 @@ #!/sbin/sh # $id uninstaller # id is set/corrected by build.sh -# Copyright 2019-2020, VR25 +# Copyright 2019-2021, VR25 # License: GPLv3+ # # devs: triple hashtags (###) mark non-generic code @@ -13,25 +13,25 @@ export TMPDIR=/dev/.$domain/$id # set up busybox #BB# -[ -x /dev/.busybox/ls ] || { - mkdir -p /dev/.busybox - chmod 0700 /dev/.busybox - if [ -f /data/adb/bin/busybox ]; then - [ -x /data/adb/bin/busybox ] || chmod -R 0700 /data/adb/bin - /data/adb/bin/busybox --install -s /dev/.busybox +[ -x /dev/.vr25/busybox/ls ] || { + mkdir -p /dev/.vr25/busybox + chmod 0700 /dev/.vr25/busybox + if [ -f /data/adb/vr25/bin/busybox ]; then + [ -x /data/adb/vr25/bin/busybox ] || chmod -R 0700 /data/adb/vr25/bin + /data/adb/vr25/bin/busybox --install -s /dev/.vr25/busybox elif [ -f /data/adb/magisk/busybox ]; then [ -x /data/adb/magisk/busybox ] || chmod 0700 /data/adb/magisk/busybox - /data/adb/magisk/busybox --install -s /dev/.busybox + /data/adb/magisk/busybox --install -s /dev/.vr25/busybox elif which busybox > /dev/null; then - eval "$(which busybox) --install -s /dev/.busybox" + eval "$(which busybox) --install -s /dev/.vr25/busybox" else - echo "(!) Install busybox or simply place it in /data/adb/bin/" + echo "(!) Install busybox or simply place it in /data/adb/vr25/bin/" exit 3 fi } case $PATH in - /data/adb/bin:*) :;; - *) export PATH=/data/adb/bin:/dev/.busybox:$PATH;; + /data/adb/vr25/bin:*) :;; + *) export PATH=/data/adb/vr25/bin:/dev/.vr25/busybox:$PATH;; esac #/BB# @@ -58,20 +58,22 @@ pgrep -f "/($id|${id}a) (-|--)[det]|/${id}d" > /dev/null && { #legacy rm -rf /data/adb/$domain/$id \ /data/adb/modules/$id \ /data/adb/service.d/${id}-*.sh \ - /data/data/mattecarra.accapp/files/$id \ - $(test "${1:-}" = install || echo "/sdcard/Documents/$domain/$id") + /data/data/mattecarra.accapp/files/$id + +[ "${1:-}" = install ] || rm -rf /data/adb/$domain/${id}-data +rmdir /data/adb/$domain #legacy rm -rf $(readlink -f /data/adb/$id) \ /data/adb/$id \ /data/adb/${id}-data \ $(readlink -f /sbin/.$id/$id) \ - /sdcard/${id}-logs-*.tar.* \ - /sdcard/${id}-uninstaller.zip \ - /sdcard/.${id}-config-backup.txt \ - /sdcard/Download/$id \ - /sdcard/$domain \ - /sdcard/Documents/$domain/$id/.acc-config-backup.txt \ - /data/data/com.termux/files/home/.termux/boot/${id}-init.sh 2>/dev/null + /data/media/0/${id}-logs-*.tar.* \ + /data/media/0/${id}-uninstaller.zip \ + /data/media/0/.${id}-config-backup.txt \ + /data/media/0/Download/$id \ + /data/media/0/$domain \ + /data/media/0/Documents/$domain/$id \ + /data/data/com.termux/files/home/.termux/boot/${id}-init.sh exit 0 diff --git a/bin/acc-uninstaller.zip b/bin/acc-uninstaller.zip index 2065d9e..139a27b 100644 Binary files a/bin/acc-uninstaller.zip and b/bin/acc-uninstaller.zip differ diff --git a/bundle.sh b/bundle.sh index e998ac5..26f891c 100644 --- a/bundle.sh +++ b/bundle.sh @@ -7,7 +7,7 @@ (id=acc installerName=install tarballName=${id}_bundle -destination=/home/*/Desktop/git/AccA/app/src/main/res/raw +destination=/home/*/git/AccA/app/src/main/res/raw cd ${0%/*} 2>/dev/null version=$(sed -n "s/^version=//p" module.prop) diff --git a/customize.sh b/customize.sh index 34add8d..010221c 100644 --- a/customize.sh +++ b/customize.sh @@ -1,6 +1,6 @@ #!/system/bin/sh -# ACC Installer/Upgrader -# Copyright 2019-2020, VR25 +# $id Installer/Upgrader +# Copyright 2019-2021, VR25 # License: GPLv3+ # # devs: triple hashtags (###) mark non-generic code @@ -14,7 +14,7 @@ echo id=acc domain=vr25 umask 0077 -data_dir=/sdcard/Documents/$domain/$id +data_dir=/data/adb/$domain/${id}-data # log @@ -38,25 +38,25 @@ trap exxit EXIT # set up busybox #BB# -[ -x /dev/.busybox/ls ] || { - mkdir -p /dev/.busybox - chmod 0700 /dev/.busybox - if [ -f /data/adb/bin/busybox ]; then - [ -x /data/adb/bin/busybox ] || chmod -R 0700 /data/adb/bin - /data/adb/bin/busybox --install -s /dev/.busybox +[ -x /dev/.vr25/busybox/ls ] || { + mkdir -p /dev/.vr25/busybox + chmod 0700 /dev/.vr25/busybox + if [ -f /data/adb/vr25/bin/busybox ]; then + [ -x /data/adb/vr25/bin/busybox ] || chmod -R 0700 /data/adb/vr25/bin + /data/adb/vr25/bin/busybox --install -s /dev/.vr25/busybox elif [ -f /data/adb/magisk/busybox ]; then [ -x /data/adb/magisk/busybox ] || chmod 0700 /data/adb/magisk/busybox - /data/adb/magisk/busybox --install -s /dev/.busybox + /data/adb/magisk/busybox --install -s /dev/.vr25/busybox elif which busybox > /dev/null; then - eval "$(which busybox) --install -s /dev/.busybox" + eval "$(which busybox) --install -s /dev/.vr25/busybox" else - echo "(!) Install busybox or simply place it in /data/adb/bin/" + echo "(!) Install busybox or simply place it in /data/adb/vr25/bin/" exit 3 fi } case $PATH in - /data/adb/bin:*) :;; - *) export PATH=/data/adb/bin:/dev/.busybox:$PATH;; + /data/adb/vr25/bin:*) :;; + *) export PATH=/data/adb/vr25/bin:/dev/.vr25/busybox:$PATH;; esac #/BB# @@ -105,19 +105,20 @@ author=$(get_prop author) version=$(get_prop version) magiskModDir=/data/adb/modules versionCode=$(get_prop versionCode) -: ${installDir:=/data/data/mattecarra.${id}app/files} ### +accaFiles=/data/data/mattecarra.accapp/files ### +: ${installDir:=$accaFiles} ### config=$data_dir/config.txt [ -d $magiskModDir ] && magisk=true || magisk=false -ls -d /data/app/mattecarra.${id}app* > /dev/null 2>&1 && acca=true || acca=false ### +ls -d ${accaFiles%/*}* > /dev/null 2>&1 && acca=true || acca=false ### -# ensure AccA's files/ exists - to prevent unwanted ACC downgrades ### -if $acca && [ ! -d /data/data/mattecarra.${id}app/files ]; then - mkdir -p /data/data/mattecarra.${id}app/files - chmod 0777 /data/data/mattecarra.${id}app \ - /data/data/mattecarra.${id}app/files +# ensure AccA's files/ exists - to prevent unwanted downgrades ### +if $acca && [ ! -d $accaFiles ]; then + mkdir -p $accaFiles + chmod 0777 ${accaFiles%/*} \ + $accaFiles fi @@ -132,30 +133,12 @@ fi ### echo "$name $version ($versionCode) -Copyright 2017-present, $author +Copyright 2017-2021, $author GPLv3+ (i) Installing in $installDir/$id/..." -# migrate #legacy data - -if [ -d /data/adb/${id}-data ]; then - mv -f /data/adb/${id}-data/* /data/adb/${id}-data/.* \ - $data_dir/ 2>/dev/null || : -elif [ -d /sdcard/Download/$id ]; then - mv -f /sdcard/Download/$id/* /sdcard/Download/$id/.* \ - $data_dir/ 2>/dev/null || : -else - mv -f /sdcard/$domain/$id/* /sdcard/$domain/$id/.* \ - $data_dir/ 2>/dev/null || : -fi -rm -rf $data_dir/info 2>/dev/null || : - -mkdir -p /dev/.$domain -mv /dev/.$id /dev/.$domain/$id 2>/dev/null || : - - /system/bin/sh $srcDir/$id/uninstall.sh install cp -R $srcDir/$id/ $installDir/ installDir=$(readlink -f $installDir/$id) @@ -180,7 +163,7 @@ if $acca; then ! $magisk || { - ln -fs $installDir /data/data/mattecarra.${id}app/files/ + ln -fs $installDir $accaFiles/ # AccA post-uninstall cleanup script mkdir -p /data/adb/service.d || { @@ -190,7 +173,7 @@ if $acca; then echo "#!/system/bin/sh # AccA post-uninstall cleanup script - until test -d /sdcard/Download \\ + until test -d /sdcard/Android \\ && test .\$(getprop sys.boot_completed) = .1 do sleep 60 @@ -198,7 +181,7 @@ if $acca; then sleep 60 - [ -e /data/data/mattecarra.${id}app/files/$id ] || rm -rf \$0 /data/adb/$domain/$id /data/adb/modules/$id 2>/dev/null + [ -e $accaFiles/$id ] || rm -rf \$0 /data/adb/$domain/$id /data/adb/modules/$id 2>/dev/null exit 0" | sed 's/^ //' > /data/adb/service.d/${id}-cleanup.sh chmod 0700 /data/adb/service.d/${id}-cleanup.sh @@ -257,7 +240,7 @@ echo "- Done " # print links and changelog -sed -En "\|## LINKS|,\$p" $srcDir/README.md \ +sed -En "\|^## LINKS|,\$p" $srcDir/README.md \ | grep -v '^---' | sed 's/^## //' @@ -270,9 +253,11 @@ echo " - Daemon started." -[ $installDir = /data/adb ] && echo " +case $installDir in + /data/adb/*) echo " (i) Non-Magisk users can enable $id auto-start by running /data/adb/$domain/$id/service.sh, a copy of, or a link to it - with init.d or an app that emulates it." - + ;; +esac # initialize $id /data/adb/$domain/$id/service.sh --init diff --git a/framework-details.txt b/framework-details.txt index bc3158a..111285b 100644 --- a/framework-details.txt +++ b/framework-details.txt @@ -1,4 +1,4 @@ -This file describes the framework ACC and other projects of mine are built upon. +This file describes the framework ACC and similar projects of mine are built upon. It's assumed that you are already a flashable zip and/or Magisk module creator. @@ -6,22 +6,23 @@ Generic Project Structure _builds/ (local only dir) $id-$versionCode/ - $id-$versionCode/tar.gz (for front-end apps) - $id-$versionCode.zip (flashable) - install-tarball.sh (copy) + $id_$version_($versionCode).tar.gz (for front-end apps) + $id_$version_($versionCode).zip (flashable) + $id-uninstaller.zip (flashable, copy of bin/$id-uninstaller.zip) + install-tarball.sh (copied from $id/) -_misc/ (local only dir) +_misc/ (local only dir, for drafts and random stuff) random_dir/ random_file - $id/ + $id/ (files to be installed) translations/ aquire-lock.sh (for job control, uses flock) default-config.txt flash-zips.sh (universal shell-based-zip flasher) release-lock.sh select.sh ("select" for shells that lack it) - service.sh (initialization script) + service.sh (boot/initialization script) setup-busybox.sh strings.sh (core language strings) uninstall.sh @@ -41,15 +42,15 @@ bundle.bat bundle.sh (copies tarball and install-tarball.sh to front-end-src-code/app/src/main/res/raw/) check-syntax.bat check-syntax.sh -customize.sh (copy of install.sh, for Magisk) +customize.sh (copy of install.sh, for compatibility with Magisk) framework-details.txt (this file) install.sh (main installer) install-online.sh (upgrader, online installer) -install-tarball.sh -License.md +install-tarball.sh (mainly used by a front-end app) +License.md (GPLv3) module.prop -README.md -TODO.txt +README.md (documentation) +TODO.txt (draft for features, issues, thoughts...) Tasks Carried Out By build.sh @@ -66,4 +67,4 @@ Tasks Carried Out By build.sh 6. Unify installers for flashable zip (customize.sh and update-binary are copies of install.sh). -7. Generate flashable zips (main & uninstaller) and tarball. +7. Generate flashable zips (main & uninstaller) - and tarball for front-ends. diff --git a/install-online.sh b/install-online.sh index 3f2b46d..7fa8692 100644 --- a/install-online.sh +++ b/install-online.sh @@ -16,7 +16,7 @@ echo id=acc domain=vr25 umask 0077 -data_dir=/sdcard/Documents/$domain/$id +data_dir=/data/adb/$domain/${id}-data # log [ -z "${LINENO-}" ] || export PS4='$LINENO: ' @@ -29,25 +29,25 @@ trap 'e=$?; echo; exit $e' EXIT # set up busybox #BB# -[ -x /dev/.busybox/ls ] || { - mkdir -p /dev/.busybox - chmod 0700 /dev/.busybox - if [ -f /data/adb/bin/busybox ]; then - [ -x /data/adb/bin/busybox ] || chmod -R 0700 /data/adb/bin - /data/adb/bin/busybox --install -s /dev/.busybox +[ -x /dev/.vr25/busybox/ls ] || { + mkdir -p /dev/.vr25/busybox + chmod 0700 /dev/.vr25/busybox + if [ -f /data/adb/vr25/bin/busybox ]; then + [ -x /data/adb/vr25/bin/busybox ] || chmod -R 0700 /data/adb/vr25/bin + /data/adb/vr25/bin/busybox --install -s /dev/.vr25/busybox elif [ -f /data/adb/magisk/busybox ]; then [ -x /data/adb/magisk/busybox ] || chmod 0700 /data/adb/magisk/busybox - /data/adb/magisk/busybox --install -s /dev/.busybox + /data/adb/magisk/busybox --install -s /dev/.vr25/busybox elif which busybox > /dev/null; then - eval "$(which busybox) --install -s /dev/.busybox" + eval "$(which busybox) --install -s /dev/.vr25/busybox" else - echo "(!) Install busybox or simply place it in /data/adb/bin/" + echo "(!) Install busybox or simply place it in /data/adb/vr25/bin/" exit 3 fi } case $PATH in - /data/adb/bin:*) :;; - *) export PATH=/data/adb/bin:/dev/.busybox:$PATH;; + /data/adb/vr25/bin:*) :;; + *) export PATH=/data/adb/vr25/bin:/dev/.vr25/busybox:$PATH;; esac #/BB# @@ -63,9 +63,9 @@ set -eu get_ver() { sed -n 's/^versionCode=//p' ${1:-}; } -! test -f /data/adb/bin/curl || { - test -x /data/adb/bin/curl \ - || chmod -R 0700 /data/adb/bin +! test -f /data/adb/vr25/bin/curl || { + test -x /data/adb/vr25/bin/curl \ + || chmod -R 0700 /data/adb/vr25/bin } diff --git a/install-tarball.sh b/install-tarball.sh index f690925..d02dec8 100644 --- a/install-tarball.sh +++ b/install-tarball.sh @@ -6,7 +6,7 @@ id=acc domain=vr25 umask 0077 -data_dir=/sdcard/Documents/$domain/${1:-$id} +data_dir=/data/adb/$domain/${1:-$id}-data # log [ -z "${LINENO-}" ] || export PS4='$LINENO: ' @@ -16,25 +16,25 @@ set -x # set up busybox #BB# -[ -x /dev/.busybox/ls ] || { - mkdir -p /dev/.busybox - chmod 0700 /dev/.busybox - if [ -f /data/adb/bin/busybox ]; then - [ -x /data/adb/bin/busybox ] || chmod -R 0700 /data/adb/bin - /data/adb/bin/busybox --install -s /dev/.busybox +[ -x /dev/.vr25/busybox/ls ] || { + mkdir -p /dev/.vr25/busybox + chmod 0700 /dev/.vr25/busybox + if [ -f /data/adb/vr25/bin/busybox ]; then + [ -x /data/adb/vr25/bin/busybox ] || chmod -R 0700 /data/adb/vr25/bin + /data/adb/vr25/bin/busybox --install -s /dev/.vr25/busybox elif [ -f /data/adb/magisk/busybox ]; then [ -x /data/adb/magisk/busybox ] || chmod 0700 /data/adb/magisk/busybox - /data/adb/magisk/busybox --install -s /dev/.busybox + /data/adb/magisk/busybox --install -s /dev/.vr25/busybox elif which busybox > /dev/null; then - eval "$(which busybox) --install -s /dev/.busybox" + eval "$(which busybox) --install -s /dev/.vr25/busybox" else - echo "(!) Install busybox or simply place it in /data/adb/bin/" + echo "(!) Install busybox or simply place it in /data/adb/vr25/bin/" exit 3 fi } case $PATH in - /data/adb/bin:*) :;; - *) export PATH=/data/adb/bin:/dev/.busybox:$PATH;; + /data/adb/vr25/bin:*) :;; + *) export PATH=/data/adb/vr25/bin:/dev/.vr25/busybox:$PATH;; esac #/BB# diff --git a/install.sh b/install.sh index 34add8d..010221c 100644 --- a/install.sh +++ b/install.sh @@ -1,6 +1,6 @@ #!/system/bin/sh -# ACC Installer/Upgrader -# Copyright 2019-2020, VR25 +# $id Installer/Upgrader +# Copyright 2019-2021, VR25 # License: GPLv3+ # # devs: triple hashtags (###) mark non-generic code @@ -14,7 +14,7 @@ echo id=acc domain=vr25 umask 0077 -data_dir=/sdcard/Documents/$domain/$id +data_dir=/data/adb/$domain/${id}-data # log @@ -38,25 +38,25 @@ trap exxit EXIT # set up busybox #BB# -[ -x /dev/.busybox/ls ] || { - mkdir -p /dev/.busybox - chmod 0700 /dev/.busybox - if [ -f /data/adb/bin/busybox ]; then - [ -x /data/adb/bin/busybox ] || chmod -R 0700 /data/adb/bin - /data/adb/bin/busybox --install -s /dev/.busybox +[ -x /dev/.vr25/busybox/ls ] || { + mkdir -p /dev/.vr25/busybox + chmod 0700 /dev/.vr25/busybox + if [ -f /data/adb/vr25/bin/busybox ]; then + [ -x /data/adb/vr25/bin/busybox ] || chmod -R 0700 /data/adb/vr25/bin + /data/adb/vr25/bin/busybox --install -s /dev/.vr25/busybox elif [ -f /data/adb/magisk/busybox ]; then [ -x /data/adb/magisk/busybox ] || chmod 0700 /data/adb/magisk/busybox - /data/adb/magisk/busybox --install -s /dev/.busybox + /data/adb/magisk/busybox --install -s /dev/.vr25/busybox elif which busybox > /dev/null; then - eval "$(which busybox) --install -s /dev/.busybox" + eval "$(which busybox) --install -s /dev/.vr25/busybox" else - echo "(!) Install busybox or simply place it in /data/adb/bin/" + echo "(!) Install busybox or simply place it in /data/adb/vr25/bin/" exit 3 fi } case $PATH in - /data/adb/bin:*) :;; - *) export PATH=/data/adb/bin:/dev/.busybox:$PATH;; + /data/adb/vr25/bin:*) :;; + *) export PATH=/data/adb/vr25/bin:/dev/.vr25/busybox:$PATH;; esac #/BB# @@ -105,19 +105,20 @@ author=$(get_prop author) version=$(get_prop version) magiskModDir=/data/adb/modules versionCode=$(get_prop versionCode) -: ${installDir:=/data/data/mattecarra.${id}app/files} ### +accaFiles=/data/data/mattecarra.accapp/files ### +: ${installDir:=$accaFiles} ### config=$data_dir/config.txt [ -d $magiskModDir ] && magisk=true || magisk=false -ls -d /data/app/mattecarra.${id}app* > /dev/null 2>&1 && acca=true || acca=false ### +ls -d ${accaFiles%/*}* > /dev/null 2>&1 && acca=true || acca=false ### -# ensure AccA's files/ exists - to prevent unwanted ACC downgrades ### -if $acca && [ ! -d /data/data/mattecarra.${id}app/files ]; then - mkdir -p /data/data/mattecarra.${id}app/files - chmod 0777 /data/data/mattecarra.${id}app \ - /data/data/mattecarra.${id}app/files +# ensure AccA's files/ exists - to prevent unwanted downgrades ### +if $acca && [ ! -d $accaFiles ]; then + mkdir -p $accaFiles + chmod 0777 ${accaFiles%/*} \ + $accaFiles fi @@ -132,30 +133,12 @@ fi ### echo "$name $version ($versionCode) -Copyright 2017-present, $author +Copyright 2017-2021, $author GPLv3+ (i) Installing in $installDir/$id/..." -# migrate #legacy data - -if [ -d /data/adb/${id}-data ]; then - mv -f /data/adb/${id}-data/* /data/adb/${id}-data/.* \ - $data_dir/ 2>/dev/null || : -elif [ -d /sdcard/Download/$id ]; then - mv -f /sdcard/Download/$id/* /sdcard/Download/$id/.* \ - $data_dir/ 2>/dev/null || : -else - mv -f /sdcard/$domain/$id/* /sdcard/$domain/$id/.* \ - $data_dir/ 2>/dev/null || : -fi -rm -rf $data_dir/info 2>/dev/null || : - -mkdir -p /dev/.$domain -mv /dev/.$id /dev/.$domain/$id 2>/dev/null || : - - /system/bin/sh $srcDir/$id/uninstall.sh install cp -R $srcDir/$id/ $installDir/ installDir=$(readlink -f $installDir/$id) @@ -180,7 +163,7 @@ if $acca; then ! $magisk || { - ln -fs $installDir /data/data/mattecarra.${id}app/files/ + ln -fs $installDir $accaFiles/ # AccA post-uninstall cleanup script mkdir -p /data/adb/service.d || { @@ -190,7 +173,7 @@ if $acca; then echo "#!/system/bin/sh # AccA post-uninstall cleanup script - until test -d /sdcard/Download \\ + until test -d /sdcard/Android \\ && test .\$(getprop sys.boot_completed) = .1 do sleep 60 @@ -198,7 +181,7 @@ if $acca; then sleep 60 - [ -e /data/data/mattecarra.${id}app/files/$id ] || rm -rf \$0 /data/adb/$domain/$id /data/adb/modules/$id 2>/dev/null + [ -e $accaFiles/$id ] || rm -rf \$0 /data/adb/$domain/$id /data/adb/modules/$id 2>/dev/null exit 0" | sed 's/^ //' > /data/adb/service.d/${id}-cleanup.sh chmod 0700 /data/adb/service.d/${id}-cleanup.sh @@ -257,7 +240,7 @@ echo "- Done " # print links and changelog -sed -En "\|## LINKS|,\$p" $srcDir/README.md \ +sed -En "\|^## LINKS|,\$p" $srcDir/README.md \ | grep -v '^---' | sed 's/^## //' @@ -270,9 +253,11 @@ echo " - Daemon started." -[ $installDir = /data/adb ] && echo " +case $installDir in + /data/adb/*) echo " (i) Non-Magisk users can enable $id auto-start by running /data/adb/$domain/$id/service.sh, a copy of, or a link to it - with init.d or an app that emulates it." - + ;; +esac # initialize $id /data/adb/$domain/$id/service.sh --init diff --git a/module.prop b/module.prop index cf09d7c..8faedca 100644 --- a/module.prop +++ b/module.prop @@ -1,7 +1,7 @@ id=acc domain=vr25 name=Advanced Charging Controller (ACC) -version=v2021.2.25 -versionCode=202102250 +version=v2021.7.28 +versionCode=202107280 author=VR25 -description=ACC is an Android software mainly intended for extending battery service life. In a nutshell, this is achieved through limiting charging current, temperature and voltage. Any root solution is supported. The installation is always "systemless", whether or not the system is rooted with Magisk. If you're reading this from Magisk Manager > Downloads, tap here to open the documentation. Once there, if you feel lazy, scroll down to the quick start section. +description=Mainly intended for extending battery service life on Android devices. In a nutshell, this is achieved through limiting charging current, temperature and voltage. Any root solution is supported. The installation is always "system-less", whether or not the system is rooted with Magisk.