forked from gloeyisk/universal-gms-doze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomize.sh
116 lines (99 loc) · 2.96 KB
/
customize.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/data/adb/magisk/busybox sh
set -o standalone
set -x
#
# Universal GMS Doze by the
# open source loving GL-DP and all contributors;
# Patches Google Play services app and its background
# processes to be able using battery optimization
#
# Checking for installation environment
if [ $BOOTMODE = true ]; then
ui_print "- Finding root path"
ROOT="$(find "$(magisk --path)" -maxdepth 2 -type d -name "mirror" -print)"
ui_print " Path: $ROOT"
else
unset ROOT
fi
# Check Android API
[ $API -ge 23 ] ||
abort "- Unsupported API version: $API"
# Patch the xml and place the modified one to the original directory
ui_print "- Patching XML files"
{
GMS0="\"com.google.android.gms"\"
STR1="allow-unthrottled-location package=$GMS0"
STR2="allow-ignore-location-settings package=$GMS0"
STR3="allow-in-power-save package=$GMS0"
STR4="allow-in-data-usage-save package=$GMS0"
NULL="/dev/null"
}
ui_print "- Finding system XML"
SYS_XML="$(
SXML="$(find /system_ext/* /system/* /product/* \
/vendor/* -type f -iname '*.xml' -print)"
for S in $SXML; do
if grep -qE "$STR1|$STR2|$STR3|$STR4" $ROOT$S 2> $NULL; then
echo "$S"
fi
done
)"
PATCH_SX() {
for SX in $SYS_XML; do
mkdir -p "$(dirname $MODPATH$SX)"
cp -af $ROOT$SX $MODPATH$SX
ui_print " Patching: $SX"
sed -i "/$STR1/d;/$STR2/d;/$STR3/d;/$STR4/d" $MODPATH/$SX
done
# Merge patched files under /system dir
for P in product vendor; do
if [ -d $MODPATH/$P ]; then
ui_print "- Moving files to module dir"
mkdir -p $MODPATH/system/$P
mv -f $MODPATH/$P $MODPATH/system/
fi
done
}
# Search and patch any conflicting modules (if present)
# Search conflicting xml files
MOD_XML="$(
MXML="$(find /data/adb/* -type f -iname "*.xml" -print)"
for M in $MXML; do
if grep -qE "$STR1|$STR2|$STR3|$STR4" $M; then
echo "$M"
fi
done
)"
PATCH_MX() {
ui_print "- Finding conflicting XML"
for MX in $MOD_XML; do
MOD="$(echo "$MX" | awk -F'/' '{print $5}')"
ui_print " $MOD: $MX"
sed -i "/$STR1/d;/$STR2/d;/$STR3/d;/$STR4/d" $MX
done
}
# Find and patch XMLs
PATCH_SX && PATCH_MX
# Additional add-on for check gms status
ADDON() {
ui_print "- Inflating add-on file"
mkdir -p $MODPATH/system/bin
mv -f $MODPATH/gmsc $MODPATH/system/bin/gmsc
}
FINALIZE() {
ui_print "- Finalizing installation"
# Clean up
ui_print " Cleaning obsolete files"
find $MODPATH/* -maxdepth 0 \
! -name 'module.prop' \
! -name 'post-fs-data.sh' \
! -name 'service.sh' \
! -name 'system' \
-exec rm -rf {} \;
# Settings dir and file permission
ui_print " Settings permissions"
set_perm_recursive $MODPATH 0 0 0755 0755
set_perm $MODPATH/system/bin/gmsc 0 2000 0755
}
# Final adjustment
ADDON && FINALIZE