├── Changelog.md ├── META-INF └── com │ └── google │ └── android │ ├── update-binary │ └── updater-script ├── NOTES ├── NOTICE ├── README.md ├── TODO ├── bin ├── ipc_arm └── ipc_x86 ├── debug.sh ├── install.sh ├── ipc.conf ├── module.prop └── service.sh /Changelog.md: -------------------------------------------------------------------------------- 1 | ## Changelog 2 | 3 | #### 3.0.1 4 | 5 | - libsocket library is rebuilt with Android NDK r20 6 | 7 | #### 3.0.0 8 | 9 | - Replace short commandline options with longer ones due to internal integrity 10 | - List of Supported Devices in README is updated as reported in Telegram group 11 | - Update documentations 12 | 13 | Guys, 14 | 15 | Please note that those who have wakelocks and other kernel-level disturbances, I 16 | have tried to debug those and I figured there is no universal solution to it due 17 | to lack of 'parallel' charging device (/sys/class/power_supply/parallel/ folder). 18 | 19 | Big thanks to XaNdR0 @ Telegram for their testing! 20 | 21 | #### 2.1.0 22 | 23 | - Supported Devices are listed in README as reported in IPControl Support group 24 | - README is slightly updated to fit in default Magisk Manager markdown window 25 | 26 | #### 2.0.2 27 | 28 | - Position of banner is moved from top to beneath "Input Power Control" heading 29 | - Some more delays are removed from debug script as I see unreliability in them 30 | - Link to Changelog is working now and banner also has been stretched to fit 31 | 32 | #### 2.0.0 33 | 34 | "Advanced Charging Control (ACControl)" is renamed to "Input Power Control (IPControl)" 35 | due to name clashes with "Advanced Charging Controller (acc)" by @VR-25. You are 36 | requested to uninstall any version of ACControl yourselves. 37 | 38 | - Unlikely to [--help], [-i] exits with success (0) instead of failure (1) 39 | - Sane sleep delay is reduced to 1 second, resulting in almost instant operations 40 | - Threads are now synchronized by sane sleep delay, so crashhes because of multi- 41 | threaded model should vanish 42 | - Output of debug script now fits Termux' default window size and many others too 43 | - README files are garnished with banner designed and contributed by the awesome 44 | Gaming_Inc @ Telegram 45 | - Control files preference order is updated to potentially fix 'level stuck at 46 | disable threshold' reports 47 | - Errors not caused by IPControl are now displayed as 'Error occured while...' 48 | - Shorter delays are removed from debug script as they introduced unreliability 49 | - Effective UID is presumed root and is never seteuid(UID_ROOT) due to SELinux 50 | - Commandline now implements short options (with no GNU extensions) instead of 51 | long ones 52 | - Unused symbols are stripped from binaries, thus greatly reducing binary sizes 53 | 54 | #### 1.3.1 55 | 56 | Intermediary versions from v1.1.1 to v1.3.1 are lost as I had to reset and setup 57 | my local development environment and personal testing device all over again. 58 | 59 | - Fix modules flashed after ACControl unable to mount magisk.img when ACControl 60 | had aborted for some reason, applicable to Magisk v18.0 or lesser 61 | - Reduce sane sleep delays to 10 seconds, thus improving accuracy to great extent 62 | - Update documentations and make [--help] output fit Termux' default window size 63 | - Fix the daemon not being killed by `acc --daemon kill` and `acc --daemon launch` 64 | spawning multiple daemons if subsequent calls were made to it 65 | - Fix the daemon recognizing a method as running after unreachable level was given 66 | to [--method], thus no methods could be ran until a reboot 67 | 68 | #### 1.1.1 69 | 70 | - Update documentations 71 | 72 | #### 1.1.0 73 | 74 | - Remove all untested legacy-derived switches 75 | - Don't check each switch on initialization 76 | - Update debug script 77 | - Remove need of initializing on each install 78 | - Fix heavy resource usage for some devices 79 | 80 | #### 1.0.2 81 | 82 | - Fix 'Permission denied' errors when initializing 83 | 84 | #### 1.0.1 85 | 86 | - Add support for some new devices 87 | - Fix syntax error in debug script 88 | 89 | #### 1.0.0 90 | 91 | - Renamed from `Advanced Charging Switch` 92 | -------------------------------------------------------------------------------- /META-INF/com/google/android/update-binary: -------------------------------------------------------------------------------- 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 . 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 227 | -------------------------------------------------------------------------------- /META-INF/com/google/android/updater-script: -------------------------------------------------------------------------------- 1 | #MAGISK # Check out update-binary which is a shell script. 2 | -------------------------------------------------------------------------------- /NOTES: -------------------------------------------------------------------------------- 1 | None! 2 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 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/JayminSuthar1910/IPControl/blob/master/NOTICE. 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Input Power Control 2 | 3 | ![IPControl banner](https://i.imgur.com/6gyQUTZ.png) 4 | 5 | ### Completely native input power control tool written purely in C++ for performance and stability 6 | 7 | ## Description 8 | 9 | IPControl automatically switches charging off when battery level reaches a certain 10 | disable threshold and back on as soon as it drowns to enable threshold. Thus, it 11 | is kept bouncing between those boundaries. This feature is called `Automation`. 12 | 13 | There's one more feature, namingly `method`s, that basically helps in switching 14 | based on conditions including level and time, but it is recommended only if you 15 | really need it or have decent knowledge of how phone batteries work. 16 | 17 | Please see `Commandline` section on manipulating these feature and other available 18 | options. 19 | 20 | ## Requirements 21 | 22 | 1. Android Lollipop or up 23 | 2. ARM or x86 based chipset 24 | 3. Magisk v18.2 (18105) or up 25 | 4. Any root solution and Init.d support 26 | 27 | Having either of 3 or 4 would suffice, 3 is favored if both are detected. 28 | 29 | ## Supported Devices 30 | 31 | - Asus Zenfone Max Pro M1 32 | - Google Pixel 3 33 | - LG Google Nexus 5 34 | - LeEco Le Max 2 35 | - Lenovo Zuk Z2 Plus 36 | - Motorola Moto X4 37 | - OnePlus 3T 38 | - OnePlus 3 39 | - OnePlus 5T 40 | - OnePlus 6 41 | - OnePlus 7 Pro 42 | - Samsung Galaxy Note 3 43 | - Samsung Galaxy S6 Edge 44 | - Samsung Galaxy S8 45 | - Xiaomi Mi A1 46 | - Xiaomi Mi Max 2 47 | - Xiaomi Mi Max 3 48 | - Xiaomi Pocophone F1 49 | - Xiaomi Redmi K20 Pro 50 | - Xiaomi Redmi Note 3 Pro 51 | - Xiaomi Redmi Note 4 52 | - Xiaomi Redmi Note 5 53 | - Xiaomi Redmi Note 6 Pro 54 | - Xiaomi Redmi Note 7 55 | - ZTE Axon 7 56 | 57 | If your device isn't listed above, don't worry! You should try IPControl and test 58 | it out yourself. 59 | 60 | ## Downloads 61 | 62 | Please obtain release zips [from GitHub releases](https://github.com/Magisk-Modules-Repo/IPControl/releases), 63 | downloading from Magisk Manager enforces Magisk framework which forbids some 64 | installation functions. 65 | 66 | ## Installation 67 | 68 | Assured your device meets requirements, flash IPControl like any other flashable. 69 | Magisk Manager or TWRP are advised as installation mediums. 70 | 71 | ## Setup 72 | 73 | If you aren't a power-user and don't wanna mess with understanding commandline 74 | (although it's explained well below), here is what minimal setup should be like, 75 | 76 | su # Obtain root shell 77 | ipc --update 70 60 # Update thresholds 78 | ipc --daemon launch # Launch the daemon 79 | 80 | ## Commandline 81 | 82 | Usage: `ipc [