Skip to content

Commit 75860cc

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

14 files changed

Lines changed: 752 additions & 0 deletions

File tree

Changelog.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
## Changelog
2+
3+
#### 2.0.2
4+
5+
- Position of banner is moved from top to beneath "Input Power Control" heading
6+
- Some more delays are removed from debug script as I see unreliability in them
7+
- Link to Changelog is working now and banner also has been stretched to fit
8+
9+
#### 2.0.0
10+
11+
"Advanced Charging Control (ACControl)" is renamed to "Input Power Control (IPControl)"
12+
due to name clashes with "Advanced Charging Controller (acc)" by @VR-25. You are
13+
requested to uninstall any version of ACControl yourselves.
14+
15+
- Unlikely to [--help], [-i] exits with success (0) instead of failure (1)
16+
- Sane sleep delay is reduced to 1 second, resulting in almost instant operations
17+
- Threads are now synchronized by sane sleep delay, so crashhes because of multi-
18+
threaded model should vanish
19+
- Output of debug script now fits Termux' default window size and many others too
20+
- README files are garnished with banner designed and contributed by the awesome
21+
Gaming_Inc @ Telegram
22+
- Control files preference order is updated to potentially fix 'level stuck at
23+
disable threshold' reports
24+
- Errors not caused by IPControl are now displayed as 'Error occured while...'
25+
- Shorter delays are removed from debug script as they introduced unreliability
26+
- Effective UID is presumed root and is never seteuid(UID_ROOT) due to SELinux
27+
- Commandline now implements short options (with no GNU extensions) instead of
28+
long ones
29+
- Unused symbols are stripped from binaries, thus greatly reducing binary sizes
30+
31+
#### 1.3.1
32+
33+
Intermediary versions from v1.1.1 to v1.3.1 are lost as I had to reset and setup
34+
my local development environment and personal testing device all over again.
35+
36+
- Fix modules flashed after ACControl unable to mount magisk.img when ACControl
37+
had aborted for some reason, applicable to Magisk v18.0 or lesser
38+
- Reduce sane sleep delays to 10 seconds, thus improving accuracy to great extent
39+
- Update documentations and make [--help] output fit Termux' default window size
40+
- Fix the daemon not being killed by `acc --daemon kill` and `acc --daemon launch`
41+
spawning multiple daemons if subsequent calls were made to it
42+
- Fix the daemon recognizing a method as running after unreachable level was given
43+
to [--method], thus no methods could be ran until a reboot
44+
45+
#### 1.1.1
46+
47+
- Update documentations
48+
49+
#### 1.1.0
50+
51+
- Remove all untested legacy-derived switches
52+
- Don't check each switch on initialization
53+
- Update debug script
54+
- Remove need of initializing on each install
55+
- Fix heavy resource usage for some devices
56+
57+
#### 1.0.2
58+
59+
- Fix 'Permission denied' errors when initializing
60+
61+
#### 1.0.1
62+
63+
- Add support for some new devices
64+
- Fix syntax error in debug script
65+
66+
#### 1.0.0
67+
68+
- Renamed from `Advanced Charging Switch`
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 "Input Power Control (IPControl)".
6+
#
7+
# IPControl 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+
# IPControl 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 IPControl. If not, see <https://www.gnu.org/licenses/>.
18+
19+
INSTALLER=/dev/IPControl
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/IPControl_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 "Error occured while mounting /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 "Error occured while mounting /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 " Input Power 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 "Error occured while extracting archive"
150+
151+
ui_print " "
152+
ui_print "Installing..."
153+
154+
if $SYSTEMLESS; then
155+
MODULE_ROOT=$DE_DATA/modules_update
156+
IPCDIR=$MODULE_ROOT/IPControl
157+
158+
IPCINFO=$INSTALLER/module.prop
159+
DEBUGGER=$INSTALLER/debug.sh
160+
BOOTRUN=$INSTALLER/service.sh
161+
IPCEXEC=$INSTALLER/bin/ipc_$ARCH
162+
CFGFILE=$INSTALLER/ipc.conf
163+
164+
[ -d /system/xbin ] && BINDIR=$IPCDIR/system/xbin || BINDIR=$IPCDIR/system/bin
165+
IPCBIN=$BINDIR/ipc
166+
167+
rm -rf $IPCDIR
168+
mkdir -p $BINDIR
169+
170+
ui_print " "
171+
print "Copying files"
172+
cp -f $IPCEXEC $IPCBIN
173+
cp -f $IPCINFO $DEBUGGER $BOOTRUN $CFGFILE $IPCDIR/
174+
175+
print "Patching ipc binary"
176+
patchstr $UEVENT_DEF $UEVENT_PATH $IPCBIN
177+
178+
touch $IPCDIR/auto_mount
179+
180+
if $BOOTMODE; then
181+
mkdir $MODULE_ROOT_DEF/IPControl
182+
cp -f $IPCINFO $MODULE_ROOT_DEF/IPControl/
183+
touch $MODULE_ROOT_DEF/IPControl/update
184+
fi
185+
186+
print "Setting permissions"
187+
set_perm_recursive $IPCDIR 0 0 0755 0644
188+
set_perm_recursive $BINDIR 0 2000 0755 0755
189+
190+
else
191+
IPCDIR=$DE_DATA/IPControl
192+
193+
IPCINFO=$INSTALLER/module.prop
194+
DEBUGGER=$INSTALLER/debug.sh
195+
BOOTRUN=$INSTALLER/service.sh
196+
IPCEXEC=$INSTALLER/bin/ipc_$ARCH
197+
CFGFILE=$INSTALLER/ipc.conf
198+
199+
IPCBIN=/system/bin/ipc
200+
MODINFO=$IPCDIR/ipc.prop
201+
INITRUN=$INITDIR/02ipcd_launcher
202+
203+
rm -rf $IPCDIR
204+
mkdir -p $IPCDIR
205+
206+
ui_print " "
207+
print "Copying files"
208+
cp -f $IPCINFO $MODINFO
209+
cp -f $BOOTRUN $INITRUN
210+
cp -f $IPCEXEC $IPCBIN
211+
cp -f $DEBUGGER $CFGFILE $IPCDIR/
212+
213+
print "Patching ipc binary"
214+
patchstr $MODULE_ROOT_DEF $DE_DATA $IPCBIN
215+
patchstr $UEVENT_DEF $UEVENT_PATH $IPCBIN
216+
217+
print "Setting permissions"
218+
set_perm_recursive $IPCDIR 0 0 0700 0600 u:object_r:adb_data_file:s0
219+
set_perm $IPCBIN 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Copyright (c) 2019 Jaymin Suthar. All rights reserved.
2+
3+
This repository is a subtree and part of IPControl project.
4+
5+
Please see the full version of this NOTICE at this link:
6+
https://github.com/JayminSuthar1001/IPControl/blob/master/NOTICE.

0 commit comments

Comments
 (0)