-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jaymin Suthar <[email protected]>
- Loading branch information
Jaymin Suthar
committed
May 21, 2019
0 parents
commit ccc3fad
Showing
13 changed files
with
722 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
#!/sbin/sh | ||
|
||
# Copyright (c) 2019 Jaymin Suthar. All rights reserved. | ||
# | ||
# This file is part of "Advanced Charging Control (ACControl)". | ||
# | ||
# ACControl is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, only version 3 of the License. | ||
# | ||
# ACControl is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with ACControl. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
INSTALLER=/dev/ACControl | ||
|
||
MODULE_ROOT_DEF=/data/adb/modules | ||
|
||
OUTFD=$2 | ||
ZIPFILE=$3 | ||
|
||
INITDIR=/system/etc/init.d | ||
DE_DATA=/data/adb | ||
BOOTMODE=false | ||
MAGISK_VER=00000 | ||
SYSTEMLESS=true | ||
|
||
exec 2>/dev/ACControl_install.log | ||
|
||
ui_print() { | ||
$BOOTMODE && echo "$1" || echo -e "ui_print $1\nui_print" >>/proc/self/fd/$OUTFD | ||
} | ||
|
||
abort() { | ||
ui_print "ERROR: $1" | ||
cleanup | ||
exit 1 | ||
} | ||
|
||
print() { | ||
ui_print "- $1" | ||
} | ||
|
||
cleanup() { | ||
rm -rf $INSTALLER | ||
if ! $BOOTMODE; then | ||
umount -l /system_root | ||
umount -l /system | ||
umount -l /data | ||
umount -l /dev/random | ||
fi | ||
} | ||
|
||
is_mounted() { | ||
cat /proc/mounts | grep " $1 " >/dev/null | ||
} | ||
|
||
getprop() { | ||
cat $2 | sed -n "s/^$1=//p" | ||
} | ||
|
||
patchstr() { | ||
ZEROCOUNT=$((${#1} - ${#2})) | ||
ZEROES=$(yes "\x0" | head -n $ZEROCOUNT | tr -d "\n") | ||
sed -i "s|${1}|${2}${ZEROES}|g" $3 | ||
} | ||
|
||
set_perm() { | ||
chown $2:$3 $1 | ||
chmod $4 $1 | ||
if [ -z "$5" ]; then | ||
chcon u:object_r:system_file:s0 $1 | ||
else | ||
chcon $5 $1 | ||
fi | ||
} | ||
|
||
set_perm_recursive() { | ||
find $1/ | while read FILE; do | ||
if [ -f $FILE ]; then | ||
set_perm $FILE $2 $3 $5 $6 | ||
else | ||
set_perm $FILE $2 $3 $4 $6 | ||
fi | ||
done | ||
} | ||
|
||
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true | ||
|
||
print "Constructing environment" | ||
|
||
is_mounted /data || mount /data || abort "Could not mount /data" | ||
|
||
MAGISK_VER=$(getprop MAGISK_VER_CODE $DE_DATA/magisk/util_functions.sh) | ||
[ -n "$MAGISK_VER" ] && [ $MAGISK_VER -ge 18105 ] || SYSTEMLESS=false | ||
|
||
$SYSTEMLESS && RW=ro || RW=rw | ||
mount -o $RW /system || mount -o $RW,remount /system || abort "Could not mount /system" | ||
if [ -f /system/init ]; then | ||
mkdir /system_root | ||
mount -o move /system /system_root | ||
mount -o bind /system_root/system /system | ||
fi | ||
|
||
API=$(getprop ro.build.version.sdk /system/build.prop) | ||
[ $API -ge 21 ] || abort "Unsupported platform ($API) detected" | ||
|
||
ARCH=$(getprop ro.product.cpu.abi /system/build.prop) | ||
case $ARCH in | ||
arm*) ARCH=arm ;; | ||
x86*) ARCH=x86 ;; | ||
*) abort "Unsupported architecture ($ARCH) detected" ;; | ||
esac | ||
|
||
$SYSTEMLESS || [ -d $INITDIR ] || abort "Init.d support is not present" | ||
|
||
UEVENT_DEF=/sys/class/power_supply/battery/uevent | ||
|
||
UEVENT_PATH=$UEVENT_DEF | ||
[ -f $UEVENT_PATH ] || UEVENT_PATH=/sys/class/power_supply/Battery/uevent | ||
[ -f $UEVENT_PATH ] || abort "Non-standard device setup detected" | ||
|
||
if ! $BOOTMODE; then | ||
mount -o bind /dev/urandom /dev/random | ||
unset LD_LIBRARY_PATH | ||
unset LD_PRELOAD | ||
unset LD_CONFIG_FILE | ||
fi | ||
|
||
ui_print " " | ||
ui_print "**************************************" | ||
ui_print " Advanced Charging Control Installer " | ||
ui_print "**************************************" | ||
|
||
ui_print " " | ||
print "Systemless mode: $SYSTEMLESS" | ||
print "Device architecture: $ARCH" | ||
|
||
rm -rf $INSTALLER | ||
mkdir -p $INSTALLER | ||
|
||
ui_print " " | ||
print "Unzipping $ZIPFILE" | ||
unzip -o "$ZIPFILE" -d $INSTALLER >/dev/null | ||
[ -f $INSTALLER/module.prop ] || abort "Could not extract archive" | ||
|
||
ui_print " " | ||
ui_print "Installing..." | ||
|
||
if $SYSTEMLESS; then | ||
MODULE_ROOT=$DE_DATA/modules_update | ||
ACCDIR=$MODULE_ROOT/ACControl | ||
|
||
ACCINFO=$INSTALLER/module.prop | ||
DEBUGGER=$INSTALLER/debug.sh | ||
BOOTRUN=$INSTALLER/service.sh | ||
ACCEXEC=$INSTALLER/bin/acc_$ARCH | ||
CFGFILE=$INSTALLER/acc.conf | ||
|
||
[ -d /system/xbin ] && BINDIR=$ACCDIR/system/xbin || BINDIR=$ACCDIR/system/bin | ||
ACCBIN=$BINDIR/acc | ||
|
||
rm -rf $ACCDIR | ||
mkdir -p $BINDIR | ||
|
||
ui_print " " | ||
print "Copying files" | ||
cp -f $ACCEXEC $ACCBIN | ||
cp -f $ACCINFO $DEBUGGER $BOOTRUN $CFGFILE $ACCDIR/ | ||
|
||
print "Patching acc binary" | ||
patchstr $UEVENT_DEF $UEVENT_PATH $ACCBIN | ||
|
||
touch $ACCDIR/auto_mount | ||
|
||
if $BOOTMODE; then | ||
mkdir $MODULE_ROOT_DEF/ACControl | ||
cp -f $ACCINFO $MODULE_ROOT_DEF/ACControl/ | ||
touch $MODULE_ROOT_DEF/ACControl/update | ||
fi | ||
|
||
print "Setting permissions" | ||
set_perm_recursive $ACCDIR 0 0 0755 0644 | ||
set_perm_recursive $BINDIR 0 2000 0755 0755 | ||
|
||
else | ||
ACCDIR=$DE_DATA/ACControl | ||
|
||
ACCINFO=$INSTALLER/module.prop | ||
DEBUGGER=$INSTALLER/debug.sh | ||
BOOTRUN=$INSTALLER/service.sh | ||
ACCEXEC=$INSTALLER/bin/acc_$ARCH | ||
CFGFILE=$INSTALLER/acc.conf | ||
|
||
ACCBIN=/system/bin/acc | ||
MODINFO=$ACCDIR/acc.prop | ||
INITRUN=$INITDIR/02accd_launcher | ||
|
||
rm -rf $ACCDIR | ||
mkdir -p $ACCDIR | ||
|
||
ui_print " " | ||
print "Copying files" | ||
cp -f $ACCINFO $MODINFO | ||
cp -f $BOOTRUN $INITRUN | ||
cp -f $ACCEXEC $ACCBIN | ||
cp -f $DEBUGGER $CFGFILE $ACCDIR/ | ||
|
||
print "Patching acc binary" | ||
patchstr $MODULE_ROOT_DEF $DE_DATA $ACCBIN | ||
patchstr $UEVENT_DEF $UEVENT_PATH $ACCBIN | ||
|
||
print "Setting permissions" | ||
set_perm_recursive $ACCDIR 0 0 0700 0600 u:object_r:adb_data_file:s0 | ||
set_perm $ACCBIN 0 2000 0750 | ||
set_perm $INITRUN 0 0 0700 | ||
fi | ||
|
||
ui_print " " | ||
ui_print "Installation completed successfully!" | ||
cleanup | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#MAGISK # Check out update-binary which is a shell script. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
None! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Advanced Charging Control (ACControl) | ||
|
||
Copyright (c) 2019 Jaymin Suthar. All rights reserved. | ||
|
||
This repository is a subtree and part of ACControl project. | ||
|
||
Please see the full version of this NOTICE at this link: | ||
https://github.com/sjaymin1001/ACControl/blob/master/NOTICE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# Advanced Charging Control | ||
|
||
### Basically enables you to switch charging. | ||
|
||
## Description | ||
|
||
ACControl automatically switches charging off when battery level reaches a certain | ||
disable threshold and back on as soon as it drowns to enable threshold. Thus, it | ||
is kept bouncing between those boundaries. This feature is called `Automation`. | ||
|
||
There's one more feature, namingly `method`s, that basically helps in switching | ||
based on conditions including level and time, but it is recommended only if you | ||
really need it or have decent knowledge of how phone batteries work. | ||
|
||
Please see `Commandline` section on manipulating these feature and other available | ||
options. | ||
|
||
## Requirements | ||
|
||
1. Android Lollipop or up | ||
2. ARM or x86 based chipset | ||
3. Magisk v18.2 (18105) or up | ||
4. Any root solution and Init.d support | ||
|
||
Having either of 3 or 4 would suffice, 3 is favored if both are detected. | ||
|
||
## Downloads | ||
|
||
Please obtain release zips [from GitHub releases](https://github.com/Magisk-Modules-Repo/ACControl/releases), | ||
downloading from Magisk Manager enforces Magisk framework which forbids some | ||
installation functions. | ||
|
||
## Installation | ||
|
||
Assured your device meets requirements, flash ACControl like any other flashable. | ||
Magisk Manager or TWRP are advised as installation mediums. | ||
|
||
## Setup | ||
|
||
If you aren't a power-user and don't wanna mess with understanding commandline | ||
(although it's explained well below), here is what minimal setup should be like, | ||
|
||
su # Obtain root shell | ||
acc --update 70 60 # Update thresholds, substitute 70 and 60 | ||
acc --daemon launch # Launch the daemon | ||
|
||
## Commandline | ||
|
||
Usage: `acc [<option> [<args>...]...]` | ||
|
||
Options: | ||
|
||
[--update] <thr_disable> <thr_enable> | ||
|
||
Updates disable and enable threshold for Automation. | ||
resets them to defaults if no values were specified. | ||
<thr_disable> and <thr_enable> must be integers. | ||
|
||
-> `acc --update 90 80` sets disable threshold to 90 | ||
and enable threshold to 80 | ||
-> `acc --update` resets thresholds to 70 60 | ||
|
||
[--toggle] <status> | ||
|
||
Toggles Automation on or off. | ||
<status> can be 'ON' or 'OFF'. | ||
|
||
-> `acc --toggle ON` toggles Automation on | ||
-> `acc --toggle OFF` toggles Automation off | ||
|
||
[--method] <format_str> | ||
|
||
Run a method based on format string <format_str>. | ||
Here, format string must follow the pattern: | ||
(e|d)(%|s|m|h)(threshold: int) | ||
|
||
where... | ||
... (e|d) defines if enable/disabling charging, | ||
... (%|s|m|h) defines if seeking level or timespan, | ||
... and this is the value of threshold. | ||
|
||
-> `acc --method es60` enables charging for 60 secs | ||
-> `acc --method d%40` disables charging until 40% | ||
-> `acc --method em30` enables charging for 30 mins | ||
|
||
[--daemon] <action> | ||
|
||
Launches or kills the daemon. | ||
<action> can be 'launch' or 'kill'. | ||
|
||
-> `acc --daemon launch` launches the daemon | ||
-> `acc --daemon kill` kills the daemon | ||
|
||
[--info] | ||
|
||
Print battery details and ACControl settings. | ||
|
||
-> `acc --info` prints out battery level, charging | ||
status, Automation status, disable | ||
threshold and enable threshold | ||
|
||
## Support | ||
|
||
Please share your unease in [this Telegram group](https://t.me/ACControl_Support) | ||
and I will serve you ASAP with required solutions. | ||
|
||
## Legal | ||
|
||
Copyright (c) 2019 Jaymin Suthar. All rights reserved. | ||
|
||
See file NOTICE in project root for licensing information. | ||
|
||
## Changelog | ||
|
||
#### 1.3.1 | ||
|
||
Intermediary versions from v1.1.1 to v1.3.1 are lost as I had to reset and setup | ||
my local development environment and personal testing device all over again. | ||
|
||
- Fix modules flashed after ACControl unable to mount magisk.img when ACControl | ||
had aborted for some reason, applicable to Magisk v18.0 or lesser | ||
- Reduce sane sleep delays to 10 seconds, thus improving accuracy to great extent | ||
- Update documentations and make [--help] output fit Termux' default window size | ||
- Fix the daemon not being killed by `acc --daemon kill` and `acc --daemon launch` | ||
spawning multiple daemons if subsequent calls were made to it | ||
- Fix the daemon recognizing a method as running after unreachable level was given | ||
to [--method], thus no methods could be ran until a reboot | ||
|
||
#### 1.1.1 | ||
|
||
- Update documentations | ||
|
||
#### 1.1.0 | ||
|
||
- Remove all untested legacy-derived switches | ||
- Don't check each switch on initialization | ||
- Update debug script | ||
- Remove need of initializing on each install | ||
- Fix heavy resource usage for some devices | ||
|
||
#### 1.0.2 | ||
|
||
- Fix 'Permission denied' errors when initializing | ||
|
||
#### 1.0.1 | ||
|
||
- Add support for some new devices | ||
- Fix syntax error in debug script | ||
|
||
#### 1.0.0 | ||
|
||
- Renamed from `Advanced Charging Switch` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Fix acc.conf missing in some cases. Reason: Unknown! |
Oops, something went wrong.