From 75860cc9e941f2dcefd7f9272a4849ea6b81b1a7 Mon Sep 17 00:00:00 2001 From: Jaymin Suthar Date: Tue, 21 May 2019 10:16:39 +0530 Subject: [PATCH] Initialize module tree Signed-off-by: Jaymin Suthar --- Changelog.md | 68 +++++++ META-INF/com/google/android/update-binary | 226 +++++++++++++++++++++ META-INF/com/google/android/updater-script | 1 + NOTES | 1 + NOTICE | 6 + README.md | 115 +++++++++++ TODO | 1 + bin/ipc_arm | Bin 0 -> 470332 bytes bin/ipc_x86 | Bin 0 -> 846192 bytes debug.sh | 99 +++++++++ install.sh | 197 ++++++++++++++++++ ipc.conf | 13 ++ module.prop | 6 + service.sh | 19 ++ 14 files changed, 752 insertions(+) create mode 100644 Changelog.md create mode 100644 META-INF/com/google/android/update-binary create mode 100644 META-INF/com/google/android/updater-script create mode 100644 NOTES create mode 100644 NOTICE create mode 100644 README.md create mode 100644 TODO create mode 100755 bin/ipc_arm create mode 100755 bin/ipc_x86 create mode 100644 debug.sh create mode 100644 install.sh create mode 100644 ipc.conf create mode 100644 module.prop create mode 100644 service.sh diff --git a/Changelog.md b/Changelog.md new file mode 100644 index 0000000..24f4bf6 --- /dev/null +++ b/Changelog.md @@ -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` diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary new file mode 100644 index 0000000..a2d6952 --- /dev/null +++ b/META-INF/com/google/android/update-binary @@ -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 . + +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 diff --git a/META-INF/com/google/android/updater-script b/META-INF/com/google/android/updater-script new file mode 100644 index 0000000..d27ddb8 --- /dev/null +++ b/META-INF/com/google/android/updater-script @@ -0,0 +1 @@ +#MAGISK # Check out update-binary which is a shell script. diff --git a/NOTES b/NOTES new file mode 100644 index 0000000..cfac940 --- /dev/null +++ b/NOTES @@ -0,0 +1 @@ +None! diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..6f52b21 --- /dev/null +++ b/NOTICE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..9bc6e92 --- /dev/null +++ b/README.md @@ -0,0 +1,115 @@ +# Input Power Control + +![IPControl banner](https://i.imgur.com/6gyQUTZ.png) + +### Completely native input power control tool written purely in C++ for performance and stability + +## Description + +IPControl 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/IPControl/releases), +downloading from Magisk Manager enforces Magisk framework which forbids some +installation functions. + +## Installation + +Assured your device meets requirements, flash IPControl 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 + ipc -u 70 60 # Update thresholds, substitute 70 and 60 + ipc -d launch # Launch the daemon + +## Commandline + + Usage: `ipc [