Skip to content

Commit

Permalink
Initialize module tree
Browse files Browse the repository at this point in the history
Signed-off-by: Jaymin Suthar <sjaymin.us@gmail.com>
  • Loading branch information
Jaymin Suthar committed Jun 20, 2019
0 parents commit 75860cc
Show file tree
Hide file tree
Showing 14 changed files with 752 additions and 0 deletions.
68 changes: 68 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
## Changelog

#### 2.0.2

- Position of banner is moved from top to beneath "Input Power Control" heading
- Some more delays are removed from debug script as I see unreliability in them
- Link to Changelog is working now and banner also has been stretched to fit

#### 2.0.0

"Advanced Charging Control (ACControl)" is renamed to "Input Power Control (IPControl)"
due to name clashes with "Advanced Charging Controller (acc)" by @VR-25. You are
requested to uninstall any version of ACControl yourselves.

- Unlikely to [--help], [-i] exits with success (0) instead of failure (1)
- Sane sleep delay is reduced to 1 second, resulting in almost instant operations
- Threads are now synchronized by sane sleep delay, so crashhes because of multi-
threaded model should vanish
- Output of debug script now fits Termux' default window size and many others too
- README files are garnished with banner designed and contributed by the awesome
Gaming_Inc @ Telegram
- Control files preference order is updated to potentially fix 'level stuck at
disable threshold' reports
- Errors not caused by IPControl are now displayed as 'Error occured while...'
- Shorter delays are removed from debug script as they introduced unreliability
- Effective UID is presumed root and is never seteuid(UID_ROOT) due to SELinux
- Commandline now implements short options (with no GNU extensions) instead of
long ones
- Unused symbols are stripped from binaries, thus greatly reducing binary sizes

#### 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`
226 changes: 226 additions & 0 deletions META-INF/com/google/android/update-binary
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 "Input Power Control (IPControl)".
#
# IPControl 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.
#
# IPControl 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 IPControl. If not, see <https://www.gnu.org/licenses/>.

INSTALLER=/dev/IPControl

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/IPControl_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 "Error occured while mounting /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 "Error occured while mounting /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 " Input Power 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 "Error occured while extracting archive"

ui_print " "
ui_print "Installing..."

if $SYSTEMLESS; then
MODULE_ROOT=$DE_DATA/modules_update
IPCDIR=$MODULE_ROOT/IPControl

IPCINFO=$INSTALLER/module.prop
DEBUGGER=$INSTALLER/debug.sh
BOOTRUN=$INSTALLER/service.sh
IPCEXEC=$INSTALLER/bin/ipc_$ARCH
CFGFILE=$INSTALLER/ipc.conf

[ -d /system/xbin ] && BINDIR=$IPCDIR/system/xbin || BINDIR=$IPCDIR/system/bin
IPCBIN=$BINDIR/ipc

rm -rf $IPCDIR
mkdir -p $BINDIR

ui_print " "
print "Copying files"
cp -f $IPCEXEC $IPCBIN
cp -f $IPCINFO $DEBUGGER $BOOTRUN $CFGFILE $IPCDIR/

print "Patching ipc binary"
patchstr $UEVENT_DEF $UEVENT_PATH $IPCBIN

touch $IPCDIR/auto_mount

if $BOOTMODE; then
mkdir $MODULE_ROOT_DEF/IPControl
cp -f $IPCINFO $MODULE_ROOT_DEF/IPControl/
touch $MODULE_ROOT_DEF/IPControl/update
fi

print "Setting permissions"
set_perm_recursive $IPCDIR 0 0 0755 0644
set_perm_recursive $BINDIR 0 2000 0755 0755

else
IPCDIR=$DE_DATA/IPControl

IPCINFO=$INSTALLER/module.prop
DEBUGGER=$INSTALLER/debug.sh
BOOTRUN=$INSTALLER/service.sh
IPCEXEC=$INSTALLER/bin/ipc_$ARCH
CFGFILE=$INSTALLER/ipc.conf

IPCBIN=/system/bin/ipc
MODINFO=$IPCDIR/ipc.prop
INITRUN=$INITDIR/02ipcd_launcher

rm -rf $IPCDIR
mkdir -p $IPCDIR

ui_print " "
print "Copying files"
cp -f $IPCINFO $MODINFO
cp -f $BOOTRUN $INITRUN
cp -f $IPCEXEC $IPCBIN
cp -f $DEBUGGER $CFGFILE $IPCDIR/

print "Patching ipc binary"
patchstr $MODULE_ROOT_DEF $DE_DATA $IPCBIN
patchstr $UEVENT_DEF $UEVENT_PATH $IPCBIN

print "Setting permissions"
set_perm_recursive $IPCDIR 0 0 0700 0600 u:object_r:adb_data_file:s0
set_perm $IPCBIN 0 2000 0750
set_perm $INITRUN 0 0 0700
fi

ui_print " "
ui_print "Installation completed successfully!"
cleanup
exit 0
1 change: 1 addition & 0 deletions META-INF/com/google/android/updater-script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#MAGISK # Check out update-binary which is a shell script.
1 change: 1 addition & 0 deletions NOTES
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
None!
6 changes: 6 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Copyright (c) 2019 Jaymin Suthar. All rights reserved.

This repository is a subtree and part of IPControl project.

Please see the full version of this NOTICE at this link:
https://github.com/JayminSuthar1001/IPControl/blob/master/NOTICE.
Loading

0 comments on commit 75860cc

Please sign in to comment.