Skip to content

Commit ccc3fad

Browse files
author
Jaymin Suthar
committed
Initialize module tree
Signed-off-by: Jaymin Suthar <sjaymin.us@gmail.com>
0 parents  commit ccc3fad

13 files changed

Lines changed: 722 additions & 0 deletions

File tree

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
#!/sbin/sh
2+
3+
# Copyright (c) 2019 Jaymin Suthar. All rights reserved.
4+
#
5+
# This file is part of "Advanced Charging Control (ACControl)".
6+
#
7+
# ACControl is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, only version 3 of the License.
10+
#
11+
# ACControl is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with ACControl. If not, see <https://www.gnu.org/licenses/>.
18+
19+
INSTALLER=/dev/ACControl
20+
21+
MODULE_ROOT_DEF=/data/adb/modules
22+
23+
OUTFD=$2
24+
ZIPFILE=$3
25+
26+
INITDIR=/system/etc/init.d
27+
DE_DATA=/data/adb
28+
BOOTMODE=false
29+
MAGISK_VER=00000
30+
SYSTEMLESS=true
31+
32+
exec 2>/dev/ACControl_install.log
33+
34+
ui_print() {
35+
$BOOTMODE && echo "$1" || echo -e "ui_print $1\nui_print" >>/proc/self/fd/$OUTFD
36+
}
37+
38+
abort() {
39+
ui_print "ERROR: $1"
40+
cleanup
41+
exit 1
42+
}
43+
44+
print() {
45+
ui_print "- $1"
46+
}
47+
48+
cleanup() {
49+
rm -rf $INSTALLER
50+
if ! $BOOTMODE; then
51+
umount -l /system_root
52+
umount -l /system
53+
umount -l /data
54+
umount -l /dev/random
55+
fi
56+
}
57+
58+
is_mounted() {
59+
cat /proc/mounts | grep " $1 " >/dev/null
60+
}
61+
62+
getprop() {
63+
cat $2 | sed -n "s/^$1=//p"
64+
}
65+
66+
patchstr() {
67+
ZEROCOUNT=$((${#1} - ${#2}))
68+
ZEROES=$(yes "\x0" | head -n $ZEROCOUNT | tr -d "\n")
69+
sed -i "s|${1}|${2}${ZEROES}|g" $3
70+
}
71+
72+
set_perm() {
73+
chown $2:$3 $1
74+
chmod $4 $1
75+
if [ -z "$5" ]; then
76+
chcon u:object_r:system_file:s0 $1
77+
else
78+
chcon $5 $1
79+
fi
80+
}
81+
82+
set_perm_recursive() {
83+
find $1/ | while read FILE; do
84+
if [ -f $FILE ]; then
85+
set_perm $FILE $2 $3 $5 $6
86+
else
87+
set_perm $FILE $2 $3 $4 $6
88+
fi
89+
done
90+
}
91+
92+
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true
93+
94+
print "Constructing environment"
95+
96+
is_mounted /data || mount /data || abort "Could not mount /data"
97+
98+
MAGISK_VER=$(getprop MAGISK_VER_CODE $DE_DATA/magisk/util_functions.sh)
99+
[ -n "$MAGISK_VER" ] && [ $MAGISK_VER -ge 18105 ] || SYSTEMLESS=false
100+
101+
$SYSTEMLESS && RW=ro || RW=rw
102+
mount -o $RW /system || mount -o $RW,remount /system || abort "Could not mount /system"
103+
if [ -f /system/init ]; then
104+
mkdir /system_root
105+
mount -o move /system /system_root
106+
mount -o bind /system_root/system /system
107+
fi
108+
109+
API=$(getprop ro.build.version.sdk /system/build.prop)
110+
[ $API -ge 21 ] || abort "Unsupported platform ($API) detected"
111+
112+
ARCH=$(getprop ro.product.cpu.abi /system/build.prop)
113+
case $ARCH in
114+
arm*) ARCH=arm ;;
115+
x86*) ARCH=x86 ;;
116+
*) abort "Unsupported architecture ($ARCH) detected" ;;
117+
esac
118+
119+
$SYSTEMLESS || [ -d $INITDIR ] || abort "Init.d support is not present"
120+
121+
UEVENT_DEF=/sys/class/power_supply/battery/uevent
122+
123+
UEVENT_PATH=$UEVENT_DEF
124+
[ -f $UEVENT_PATH ] || UEVENT_PATH=/sys/class/power_supply/Battery/uevent
125+
[ -f $UEVENT_PATH ] || abort "Non-standard device setup detected"
126+
127+
if ! $BOOTMODE; then
128+
mount -o bind /dev/urandom /dev/random
129+
unset LD_LIBRARY_PATH
130+
unset LD_PRELOAD
131+
unset LD_CONFIG_FILE
132+
fi
133+
134+
ui_print " "
135+
ui_print "**************************************"
136+
ui_print " Advanced Charging Control Installer "
137+
ui_print "**************************************"
138+
139+
ui_print " "
140+
print "Systemless mode: $SYSTEMLESS"
141+
print "Device architecture: $ARCH"
142+
143+
rm -rf $INSTALLER
144+
mkdir -p $INSTALLER
145+
146+
ui_print " "
147+
print "Unzipping $ZIPFILE"
148+
unzip -o "$ZIPFILE" -d $INSTALLER >/dev/null
149+
[ -f $INSTALLER/module.prop ] || abort "Could not extract archive"
150+
151+
ui_print " "
152+
ui_print "Installing..."
153+
154+
if $SYSTEMLESS; then
155+
MODULE_ROOT=$DE_DATA/modules_update
156+
ACCDIR=$MODULE_ROOT/ACControl
157+
158+
ACCINFO=$INSTALLER/module.prop
159+
DEBUGGER=$INSTALLER/debug.sh
160+
BOOTRUN=$INSTALLER/service.sh
161+
ACCEXEC=$INSTALLER/bin/acc_$ARCH
162+
CFGFILE=$INSTALLER/acc.conf
163+
164+
[ -d /system/xbin ] && BINDIR=$ACCDIR/system/xbin || BINDIR=$ACCDIR/system/bin
165+
ACCBIN=$BINDIR/acc
166+
167+
rm -rf $ACCDIR
168+
mkdir -p $BINDIR
169+
170+
ui_print " "
171+
print "Copying files"
172+
cp -f $ACCEXEC $ACCBIN
173+
cp -f $ACCINFO $DEBUGGER $BOOTRUN $CFGFILE $ACCDIR/
174+
175+
print "Patching acc binary"
176+
patchstr $UEVENT_DEF $UEVENT_PATH $ACCBIN
177+
178+
touch $ACCDIR/auto_mount
179+
180+
if $BOOTMODE; then
181+
mkdir $MODULE_ROOT_DEF/ACControl
182+
cp -f $ACCINFO $MODULE_ROOT_DEF/ACControl/
183+
touch $MODULE_ROOT_DEF/ACControl/update
184+
fi
185+
186+
print "Setting permissions"
187+
set_perm_recursive $ACCDIR 0 0 0755 0644
188+
set_perm_recursive $BINDIR 0 2000 0755 0755
189+
190+
else
191+
ACCDIR=$DE_DATA/ACControl
192+
193+
ACCINFO=$INSTALLER/module.prop
194+
DEBUGGER=$INSTALLER/debug.sh
195+
BOOTRUN=$INSTALLER/service.sh
196+
ACCEXEC=$INSTALLER/bin/acc_$ARCH
197+
CFGFILE=$INSTALLER/acc.conf
198+
199+
ACCBIN=/system/bin/acc
200+
MODINFO=$ACCDIR/acc.prop
201+
INITRUN=$INITDIR/02accd_launcher
202+
203+
rm -rf $ACCDIR
204+
mkdir -p $ACCDIR
205+
206+
ui_print " "
207+
print "Copying files"
208+
cp -f $ACCINFO $MODINFO
209+
cp -f $BOOTRUN $INITRUN
210+
cp -f $ACCEXEC $ACCBIN
211+
cp -f $DEBUGGER $CFGFILE $ACCDIR/
212+
213+
print "Patching acc binary"
214+
patchstr $MODULE_ROOT_DEF $DE_DATA $ACCBIN
215+
patchstr $UEVENT_DEF $UEVENT_PATH $ACCBIN
216+
217+
print "Setting permissions"
218+
set_perm_recursive $ACCDIR 0 0 0700 0600 u:object_r:adb_data_file:s0
219+
set_perm $ACCBIN 0 2000 0750
220+
set_perm $INITRUN 0 0 0700
221+
fi
222+
223+
ui_print " "
224+
ui_print "Installation completed successfully!"
225+
cleanup
226+
exit 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#MAGISK # Check out update-binary which is a shell script.

NOTES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
None!

NOTICE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Advanced Charging Control (ACControl)
2+
3+
Copyright (c) 2019 Jaymin Suthar. All rights reserved.
4+
5+
This repository is a subtree and part of ACControl project.
6+
7+
Please see the full version of this NOTICE at this link:
8+
https://github.com/sjaymin1001/ACControl/blob/master/NOTICE.

README.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Advanced Charging Control
2+
3+
### Basically enables you to switch charging.
4+
5+
## Description
6+
7+
ACControl automatically switches charging off when battery level reaches a certain
8+
disable threshold and back on as soon as it drowns to enable threshold. Thus, it
9+
is kept bouncing between those boundaries. This feature is called `Automation`.
10+
11+
There's one more feature, namingly `method`s, that basically helps in switching
12+
based on conditions including level and time, but it is recommended only if you
13+
really need it or have decent knowledge of how phone batteries work.
14+
15+
Please see `Commandline` section on manipulating these feature and other available
16+
options.
17+
18+
## Requirements
19+
20+
1. Android Lollipop or up
21+
2. ARM or x86 based chipset
22+
3. Magisk v18.2 (18105) or up
23+
4. Any root solution and Init.d support
24+
25+
Having either of 3 or 4 would suffice, 3 is favored if both are detected.
26+
27+
## Downloads
28+
29+
Please obtain release zips [from GitHub releases](https://github.com/Magisk-Modules-Repo/ACControl/releases),
30+
downloading from Magisk Manager enforces Magisk framework which forbids some
31+
installation functions.
32+
33+
## Installation
34+
35+
Assured your device meets requirements, flash ACControl like any other flashable.
36+
Magisk Manager or TWRP are advised as installation mediums.
37+
38+
## Setup
39+
40+
If you aren't a power-user and don't wanna mess with understanding commandline
41+
(although it's explained well below), here is what minimal setup should be like,
42+
43+
su # Obtain root shell
44+
acc --update 70 60 # Update thresholds, substitute 70 and 60
45+
acc --daemon launch # Launch the daemon
46+
47+
## Commandline
48+
49+
Usage: `acc [<option> [<args>...]...]`
50+
51+
Options:
52+
53+
[--update] <thr_disable> <thr_enable>
54+
55+
Updates disable and enable threshold for Automation.
56+
resets them to defaults if no values were specified.
57+
<thr_disable> and <thr_enable> must be integers.
58+
59+
-> `acc --update 90 80` sets disable threshold to 90
60+
and enable threshold to 80
61+
-> `acc --update` resets thresholds to 70 60
62+
63+
[--toggle] <status>
64+
65+
Toggles Automation on or off.
66+
<status> can be 'ON' or 'OFF'.
67+
68+
-> `acc --toggle ON` toggles Automation on
69+
-> `acc --toggle OFF` toggles Automation off
70+
71+
[--method] <format_str>
72+
73+
Run a method based on format string <format_str>.
74+
Here, format string must follow the pattern:
75+
(e|d)(%|s|m|h)(threshold: int)
76+
77+
where...
78+
... (e|d) defines if enable/disabling charging,
79+
... (%|s|m|h) defines if seeking level or timespan,
80+
... and this is the value of threshold.
81+
82+
-> `acc --method es60` enables charging for 60 secs
83+
-> `acc --method d%40` disables charging until 40%
84+
-> `acc --method em30` enables charging for 30 mins
85+
86+
[--daemon] <action>
87+
88+
Launches or kills the daemon.
89+
<action> can be 'launch' or 'kill'.
90+
91+
-> `acc --daemon launch` launches the daemon
92+
-> `acc --daemon kill` kills the daemon
93+
94+
[--info]
95+
96+
Print battery details and ACControl settings.
97+
98+
-> `acc --info` prints out battery level, charging
99+
status, Automation status, disable
100+
threshold and enable threshold
101+
102+
## Support
103+
104+
Please share your unease in [this Telegram group](https://t.me/ACControl_Support)
105+
and I will serve you ASAP with required solutions.
106+
107+
## Legal
108+
109+
Copyright (c) 2019 Jaymin Suthar. All rights reserved.
110+
111+
See file NOTICE in project root for licensing information.
112+
113+
## Changelog
114+
115+
#### 1.3.1
116+
117+
Intermediary versions from v1.1.1 to v1.3.1 are lost as I had to reset and setup
118+
my local development environment and personal testing device all over again.
119+
120+
- Fix modules flashed after ACControl unable to mount magisk.img when ACControl
121+
had aborted for some reason, applicable to Magisk v18.0 or lesser
122+
- Reduce sane sleep delays to 10 seconds, thus improving accuracy to great extent
123+
- Update documentations and make [--help] output fit Termux' default window size
124+
- Fix the daemon not being killed by `acc --daemon kill` and `acc --daemon launch`
125+
spawning multiple daemons if subsequent calls were made to it
126+
- Fix the daemon recognizing a method as running after unreachable level was given
127+
to [--method], thus no methods could be ran until a reboot
128+
129+
#### 1.1.1
130+
131+
- Update documentations
132+
133+
#### 1.1.0
134+
135+
- Remove all untested legacy-derived switches
136+
- Don't check each switch on initialization
137+
- Update debug script
138+
- Remove need of initializing on each install
139+
- Fix heavy resource usage for some devices
140+
141+
#### 1.0.2
142+
143+
- Fix 'Permission denied' errors when initializing
144+
145+
#### 1.0.1
146+
147+
- Add support for some new devices
148+
- Fix syntax error in debug script
149+
150+
#### 1.0.0
151+
152+
- Renamed from `Advanced Charging Switch`

TODO

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix acc.conf missing in some cases. Reason: Unknown!

0 commit comments

Comments
 (0)