Skip to content

Commit b9fe9f4

Browse files
committed
# v2017.9.5.1
- Fixed cs history not fully read (missing percentage value). # v2017.9.5 - Major optimizations - Initial release # v2017.9.1 - Initial version
0 parents  commit b9fe9f4

File tree

9 files changed

+1180
-0
lines changed

9 files changed

+1180
-0
lines changed

.gitattributes

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Declare files that will always have LF line endings on checkout.
2+
** text eol=lf
3+
4+
# Denote all files that are truly binary and should not be modified.
5+
#system/** binary

License.md

+674
Large diffs are not rendered by default.
+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
#!/sbin/sh
2+
##########################################################################################
3+
#
4+
# Magisk Module Template Install Script
5+
# by topjohnwu
6+
#
7+
##########################################################################################
8+
9+
# Detect whether in boot mode
10+
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true || BOOTMODE=false
11+
$BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMODE=true
12+
13+
# This path should work in any cases
14+
TMPDIR=/dev/tmp
15+
MOUNTPATH=/magisk
16+
IMG=/data/magisk.img
17+
if $BOOTMODE; then
18+
MOUNTPATH=/dev/magisk_merge
19+
IMG=/data/magisk_merge.img
20+
fi
21+
INSTALLER=$TMPDIR/install
22+
MAGISKBIN=/data/magisk
23+
24+
# Default permissions
25+
umask 022
26+
27+
##########################################################################################
28+
# Flashable update-binary preparation
29+
##########################################################################################
30+
31+
OUTFD=$2
32+
ZIP=$3
33+
34+
ui_print() {
35+
if $BOOTMODE; then
36+
echo "$1"
37+
else
38+
echo -n -e "ui_print $1\n" >> /proc/self/fd/$OUTFD
39+
echo -n -e "ui_print\n" >> /proc/self/fd/$OUTFD
40+
fi
41+
}
42+
43+
require_new_magisk() {
44+
ui_print "***********************************"
45+
ui_print "! $MAGISKBIN isn't setup properly!"
46+
ui_print "! Please install Magisk v13.1+!"
47+
ui_print "***********************************"
48+
exit 1
49+
}
50+
51+
# Mount /data to access MAGISKBIN
52+
mount /data 2>/dev/null
53+
54+
# MAGISKBIN must exist, binaries and utility functions are placed there
55+
[ -d $MAGISKBIN -a -f $MAGISKBIN/magisk -a -f $MAGISKBIN/util_functions.sh ] || require_new_magisk
56+
57+
# Load utility fuctions
58+
. $MAGISKBIN/util_functions.sh
59+
[ ! -z $SCRIPT_VERSION -a $SCRIPT_VERSION -ge 1310 ] || require_new_magisk
60+
get_outfd
61+
62+
rm -rf $TMPDIR 2>/dev/null
63+
mkdir -p $INSTALLER
64+
unzip -o "$ZIP" config.sh -d $INSTALLER 2>/dev/null
65+
66+
##########################################################################################
67+
# Prepare
68+
##########################################################################################
69+
70+
[ ! -f $INSTALLER/config.sh ] && abort "! Unable to extract zip file!"
71+
72+
. $INSTALLER/config.sh
73+
74+
MODPATH=$MOUNTPATH/$MODID
75+
76+
# Print mod name
77+
print_modname
78+
79+
# Please leave this message in your flashable zip for credits :)
80+
ui_print "******************************"
81+
ui_print "Powered by Magisk (@topjohnwu)"
82+
ui_print "******************************"
83+
84+
ui_print "- Mounting /system, /vendor, /data, /cache"
85+
mount -o ro /system 2>/dev/null
86+
mount -o ro /vendor 2>/dev/null
87+
mount /data 2>/dev/null
88+
mount /cache 2>/dev/null
89+
90+
[ ! -f /data/magisk.img ] && abort "! Magisk is not installed"
91+
$BOOTMODE && ! is_mounted /magisk && abort "! Magisk is not activated!"
92+
[ ! -f /system/build.prop ] && abort "! /system could not be mounted!"
93+
94+
# Detect version and architecture
95+
api_level_arch_detect
96+
97+
# You can get the Android API version from $API, the CPU architecture from $ARCH
98+
# Useful if you are creating Android version / platform dependent mods
99+
100+
##########################################################################################
101+
# Install
102+
##########################################################################################
103+
104+
ui_print "- Extracting module files"
105+
unzip -o "$ZIP" -d $INSTALLER 2>/dev/null
106+
request_size_check $INSTALLER
107+
108+
# We're going to use magisk binary now, require some recovery fixes
109+
$BOOTMODE || recovery_actions
110+
111+
if [ -f "$IMG" ]; then
112+
ui_print "- $IMG detected!"
113+
image_size_check $IMG
114+
if [ "$reqSizeM" -gt "$curFreeM" ]; then
115+
newSizeM=$(((reqSizeM + curUsedM) / 32 * 32 + 64))
116+
ui_print "- Resizing $IMG to ${newSizeM}M"
117+
$MAGISKBIN/magisk --resizeimg $IMG $newSizeM
118+
fi
119+
else
120+
newSizeM=$((reqSizeM / 32 * 32 + 64));
121+
ui_print "- Creating $IMG with size ${newSizeM}M"
122+
$MAGISKBIN/magisk --createimg $IMG $newSizeM
123+
fi
124+
125+
ui_print "- Mounting $IMG to $MOUNTPATH"
126+
MAGISKLOOP=`$MAGISKBIN/magisk --mountimg $IMG $MOUNTPATH`
127+
is_mounted $MOUNTPATH || abort"! $IMG mount failed..."
128+
129+
# Create mod paths
130+
rm -rf $MODPATH 2>/dev/null
131+
mkdir -p $MODPATH
132+
133+
# Copy files
134+
ui_print "- Copying files"
135+
mv $INSTALLER/system $MODPATH/system
136+
137+
# Handle replace folders
138+
for TARGET in $REPLACE; do
139+
mktouch $MODPATH$TARGET/.replace
140+
done
141+
142+
# Auto Mount
143+
$AUTOMOUNT && touch $MODPATH/auto_mount
144+
145+
# prop files
146+
$PROPFILE && cp -af $INSTALLER/common/system.prop $MODPATH/system.prop
147+
148+
# Module info
149+
cp -af $INSTALLER/module.prop $MODPATH/module.prop
150+
if $BOOTMODE; then
151+
# Update info for Magisk Manager
152+
mktouch /magisk/$MODID/update
153+
cp -af $INSTALLER/module.prop /magisk/$MODID/module.prop
154+
fi
155+
156+
# post-fs-data mode scripts
157+
$POSTFSDATA && cp -af $INSTALLER/common/post-fs-data.sh $MODPATH/post-fs-data.sh
158+
159+
# service mode scripts
160+
$LATESTARTSERVICE && cp -af $INSTALLER/common/service.sh $MODPATH/service.sh
161+
162+
ui_print "- Setting permissions"
163+
set_permissions
164+
165+
##########################################################################################
166+
# Finalizing
167+
##########################################################################################
168+
169+
$MAGISKBIN/magisk --umountimg $MOUNTPATH $MAGISKLOOP
170+
rmdir $MOUNTPATH
171+
172+
# Shrink the image if possible
173+
image_size_check $IMG
174+
newSizeM=$((curUsedM / 32 * 32 + 64))
175+
if [ $curSizeM -gt $newSizeM ]; then
176+
ui_print "- Shrinking $IMG to ${newSizeM}M"
177+
$MAGISKBIN/magisk --resizeimg $IMG $newSizeM
178+
fi
179+
180+
$BOOTMODE || recovery_cleanup
181+
182+
ui_print "- Done"
183+
exit 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#MAGISK

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Magic Charging Switch (cs)
2+
# VR25 @ XDA Developers
3+
4+
5+
**Description**
6+
7+
Automagically stops charging at a given % level to extend battery lifespan.
8+
9+
10+
**Disclaimer**
11+
12+
Don't quote me on the above. Do your own research on lithium-ion batteries! This module tweaks low level Android settings -- I shall not be held responsible for any nuclear disaster potentially triggered by the use/misuse of it.
13+
14+
15+
**Usage**
16+
17+
cs -i --> Show battery info.
18+
19+
cs -d --> Disable charging mechanism.
20+
21+
cs -e --> Enable charging mechanism.
22+
23+
cs % --> Stop charging at given % (i.e., 80).
24+
25+
just "cs" --> Stop charging at last given % (includes last UpdateFreq).
26+
27+
cs --help --> Self explanatory
28+
29+
30+
**Tips**
31+
32+
"cs 80 30" updates charging info every 30 seconds & switches charging OFF at 80% battery level. You can also use minutes or hours instead of seconds (#m or #h). If "UpdateFreq" value is not specified, then the default (60 seconds) is used.
33+
34+
"-d" & "-e" options can also take a "timeout" argument to automatically enable & disable charging, respectively (i.e., "cs -d 30m" --> disables charging for 30 minutes, "cs -e 1h" --> enables charging for 1 hour).
35+
36+
37+
**Online Support**
38+
39+
[XDA Thread](https://forum.xda-developers.com/apps/magisk/module-magic-charging-switch-cs-v2017-9-t3668427)
40+
41+
[GitHub Repo](https://github.com/VR-25/Magic-Charging-Switch)

changelog.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# v2017.9.5.1
2+
- Fixed cs history not fully read (missing percentage value).
3+
4+
# v2017.9.5
5+
- Major optimizations
6+
- Initial release
7+
8+
# v2017.9.1
9+
- Initial version

config.sh

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
##########################################################################################
2+
#
3+
# Magisk Module Template Config Script
4+
# by topjohnwu
5+
#
6+
##########################################################################################
7+
##########################################################################################
8+
#
9+
# Instructions:
10+
#
11+
# 1. Place your files into system folder (delete the placeholder file)
12+
# 2. Fill in your module's info into module.prop
13+
# 3. Configure the settings in this file (common/config.sh)
14+
# 4. For advanced features, add shell commands into the script files under common:
15+
# post-fs-data.sh, service.sh
16+
# 5. For changing props, add your additional/modified props into common/system.prop
17+
#
18+
##########################################################################################
19+
20+
##########################################################################################
21+
# Defines
22+
##########################################################################################
23+
24+
# NOTE: This part has to be adjusted to fit your own needs
25+
26+
# This will be the folder name under /magisk
27+
# This should also be the same as the id in your module.prop to prevent confusion
28+
MODID=cs
29+
30+
# Set to true if you need to enable Magic Mount
31+
# Most mods would like it to be enabled
32+
AUTOMOUNT=true
33+
34+
# Set to true if you need to load system.prop
35+
PROPFILE=false
36+
37+
# Set to true if you need post-fs-data script
38+
POSTFSDATA=false
39+
40+
# Set to true if you need late_start service script
41+
LATESTARTSERVICE=false
42+
43+
##########################################################################################
44+
# Installation Message
45+
##########################################################################################
46+
47+
# Set what you want to show when installing your mod
48+
49+
print_modname() {
50+
ui_print "****************************"
51+
ui_print "Magic Charging Switch (cs)"
52+
ui_print " VR25 @ XDA Developers "
53+
ui_print "****************************"
54+
}
55+
56+
##########################################################################################
57+
# Replace list
58+
##########################################################################################
59+
60+
# List all directories you want to directly replace in the system
61+
# By default Magisk will merge your files with the original system
62+
# Directories listed here however, will be directly mounted to the correspond directory in the system
63+
64+
# You don't need to remove the example below, these values will be overwritten by your own list
65+
# This is an example
66+
REPLACE="
67+
/system/app/Youtube
68+
/system/priv-app/SystemUI
69+
/system/priv-app/Settings
70+
/system/framework
71+
"
72+
73+
# Construct your own list here, it will overwrite the example
74+
# !DO NOT! remove this if you don't need to replace anything, leave it empty as it is now
75+
REPLACE="
76+
"
77+
78+
##########################################################################################
79+
# Permissions
80+
##########################################################################################
81+
82+
# NOTE: This part has to be adjusted to fit your own needs
83+
84+
set_permissions() {
85+
# Default permissions, don't remove them
86+
set_perm_recursive $MODPATH 0 0 0755 0644
87+
set_perm $MODPATH/system/xbin/cs 0 0 0777
88+
89+
# Only some special files require specific permissions
90+
# The default permissions should be good enough for most cases
91+
92+
# Some templates if you have no idea what to do:
93+
94+
# set_perm_recursive <dirname> <owner> <group> <dirpermission> <filepermission> <contexts> (default: u:object_r:system_file:s0)
95+
# set_perm_recursive $MODPATH/system/lib 0 0 0755 0644
96+
97+
# set_perm <filename> <owner> <group> <permission> <contexts> (default: u:object_r:system_file:s0)
98+
# set_perm $MODPATH/system/bin/app_process32 0 2000 0755 u:object_r:zygote_exec:s0
99+
# set_perm $MODPATH/system/bin/dex2oat 0 2000 0755 u:object_r:dex2oat_exec:s0
100+
# set_perm $MODPATH/system/lib/libart.so 0 0 0644
101+
}

module.prop

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
id=cs
2+
name=Magic Charging Switch (cs)
3+
version=v2017.9.5.1
4+
versionCode=2017951
5+
author=VR25 @ XDA Developers
6+
description=Automagically stops charging at a given % level to extend battery lifespan.
7+
template=4

0 commit comments

Comments
 (0)