Skip to content

Commit

Permalink
v1.8.7
Browse files Browse the repository at this point in the history
Changelog:
- Android 13 support
- Added GMS to battery optimization and disabled another components
- Fixed broken API checking and Multi-User support
- Moved to inbuilt (Magisk) BusyBox
- Improved pre-boot conflict fixer and proper boot script execution
- Improved superuser checking method and used cmd flag arguments
- Improved XML patching logic
- Minimized root path checking depth
- Revived overall code quality and syntax
- Rewrite GMS state checker bin

Signed-off-by: Gloeyisk <[email protected]>
  • Loading branch information
gloeyisk committed Sep 7, 2022
1 parent 643bf63 commit e85961f
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 111 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ There's a line written `Whitelist (except idle) system apps:` and if `com.google
## Credits
- [@topjohnwu](https://github.com/topjohnwu) / Magisk - Magisk Module Template
- [@JumbomanXDA](https://github.com/JumbomanXDA) / Custom installation script
- [@MrCarb0n](https://github.com/MrCarb0n) / Code rebase, overall code quality & syntax

---
## Extras
Expand Down
50 changes: 31 additions & 19 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
---
## Change Log:
- 1.8.7
- Android 13 support
- Added GMS to battery optimization and disabled another components
- Fixed broken API checking and Multi-User support
- Moved to inbuilt (Magisk) BusyBox
- Improved pre-boot conflict fixer and proper boot script execution
- Improved superuser checking method and used cmd flag arguments
- Improved XML patching logic
- Minimized root path checking depth
- Revived overall code quality and syntax
- Rewrite GMS state checker bin

- 1.8.6
- Added /system_ext detection support
- Added /system_ext detection support
- Improved patching detections (Allow to revoke location permissions)

- 1.8.5
- Added updateJson support
- Added updateJson support
- Improved patching detections (XML files)

- 1.8.4
- Removed redundant script (GMS: Stay with disabling Find My Device only)
- Removed redundant script (GMS: Stay with disabling Find My Device only)

- 1.8.3
- Android 12 support
- Additional boot complete check
- Multi-User support
- Set ignore for GMS and IMS WRITE_SETTINGS
- Android 12 support
- Additional boot complete check
- Multi-User support
- Set ignore for GMS and IMS WRITE_SETTINGS
- Minor improvements

- 1.8.2
- Android 11 support
- Improved installation (Magisk Live and Custom Recovery)
- Improved patching detections (XML files and conflicting modules)
- Integrated add-on (run 'gmsc' with superuser rights for check optimization status)
- Set ignore for GMS and IMS BOOT_COMPLETED
- Set ignore for GMS and IMS AUTO_START (custom permissions for Oxygen OS)
- Updated template
- Android 11 support
- Improved installation (Magisk Live and Custom Recovery)
- Improved patching detections (XML files and conflicting modules)
- Integrated add-on (run 'gmsc' with superuser rights for check optimization status)
- Set ignore for GMS and IMS BOOT_COMPLETED
- Set ignore for GMS and IMS AUTO_START (custom permissions for Oxygen OS)
- Updated template

- 1.8.1
- Integrated custom recovery installation
- Added boot logic for search and patch any conflicting modules (if present)
- Whitelisted IMS and Turbo (this should fixed location crash issue in MIUI)
- Integrated custom recovery installation
- Added boot logic for search and patch any conflicting modules (if present)
- Whitelisted IMS and Turbo (this should fixed location crash issue in MIUI)

- 1.8.0
- Initial re-release
- 100 seconds Magisk Boot Service
- Initial re-release
- 100 seconds Magisk Boot Service
155 changes: 101 additions & 54 deletions customize.sh
Original file line number Diff line number Diff line change
@@ -1,69 +1,116 @@
#!/sbin/sh
#!/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
# Patches Google Play services app and its background
# processes to be able using battery optimization
#

# Checking for installation environment
if [ $BOOTMODE = true ]; then
ROOT=$(find `magisk --path` -type d -name "mirror" | head -n 1)
ui_print "- Root path: $ROOT"
ui_print "- Finding root path"
ROOT="$(find "$(magisk --path)" -maxdepth 2 -type d -name "mirror" -print)"
ui_print " Path: $ROOT"
else
ROOT=""
unset ROOT
fi

# Check device SDK
sdk="$(getprop ro.build.version.sdk)"
if [[ !"$sdk" -ge "23" ]]; then
ui_print "- Unsupported SDK version: $sdk"
exit 1
fi
# Check Android API
[ $API -ge 23 ] ||
abort "- Unsupported API version: $API"

# Patch the XML and place the modified one to the original directory
# Patch the xml and place the modified one to the original directory
ui_print "- Patching XML files"
location=$(xml=$(find /system/ /system_ext/ /product/ /vendor/ -iname "*.xml");for i in $xml; do if grep -q 'allow-unthrottled-location package="com.google.android.gms"' $ROOT$i 2>/dev/null; then echo "$i";fi; done)
ignore=$(xml=$(find /system/ /system_ext/ /product/ /vendor/ -iname "*.xml");for i in $xml; do if grep -q 'allow-ignore-location-settings package="com.google.android.gms"' $ROOT$i 2>/dev/null; then echo "$i";fi; done)
for i in $location $ignore
do
mkdir -p `dirname $MODPATH$i`
cp -af $ROOT$i $MODPATH$i
sed -i '/allow-unthrottled-location package="com.google.android.gms"/d;/allow-ignore-location-settings package="com.google.android.gms"/d' $MODPATH$i
done
for i in product vendor
do
if [ -d $MODPATH/$i ]; then
if [ ! -d $MODPATH/system/$i ]; then
sleep 1
ui_print "- Moving files to /system partition"
mkdir -p $MODPATH/system/$i
mv -f $MODPATH/$i $MODPATH/system/
else
rm -rf $MODPATH/$i
fi
fi
done

{
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/$P
fi
done
}

# Search and patch any conflicting modules (if present)
# Search conflicting XML files
conflict1=$(xml=$(find /data/adb -iname "*.xml");for i in $xml; do if grep -q 'allow-unthrottled-location package="com.google.android.gms"' $i 2>/dev/null; then echo "$i";fi; done)
conflict2=$(xml=$(find /data/adb -iname "*.xml");for i in $xml; do if grep -q 'allow-ignore-location-settings package="com.google.android.gms"' $i 2>/dev/null; then echo "$i";fi; done)
for i in $conflict1 $conflict2
do
search=$(echo "$i" | sed -e 's/\// /g' | awk '{print $4}')
ui_print "- Conflicting modules detected"
ui_print " $search"
sed -i '/allow-unthrottled-location package="com.google.android.gms"/d;/allow-ignore-location-settings package="com.google.android.gms"/d' $i
done
# Additional add-on for check GMS status
ui_print "- Inflating add-on file"
mkdir -p $MODPATH/system/bin
mv -f $MODPATH/gmsc $MODPATH/system/bin/gmsc
chmod +x $MODPATH/system/bin/gmsc
# Clean up
rm -rf $MODPATH/LICENSE
# 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
44 changes: 29 additions & 15 deletions gmsc
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
#!/system/bin/sh

# Root check
id=`id`; id=`echo ${id#*=}`; id=`echo ${id%%\(*}`; id=`echo ${id%% *}`
if [ "$id" != "0" ] && [ "$id" != "root" ]; then
echo "Superuser (su) rights is needed!"
exit 1
else
# Command-line for check whether Google Play services is optimized or not
# Run 'gmsc' with superuser rights
gms=`dumpsys deviceidle whitelist | grep -o com.google.android.gms | head -n 1`
if [ "$gms" = "com.google.android.gms" ]; then
echo "\033[0;31m Google Play services is Not Optimized \033[0m"
else
echo "\033[0;32m Google Play services is Optimized \033[0m"
fi
fi
#
# 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
#

ID="$(id -u)"
NULL="/dev/null"
GMS="com.google.android.gms"

{ R="\e[1;31m" G="\e[1;32m" Y="\e[1;33m" N="\e[0m"; } 2> $NULL

CHK_OPT() {
local OPT="$(dumpsys deviceidle whitelist |
awk -F',' "/$GMS/{print $2;exit}")"
[ -z $OPT ] && echo -e "$G $1 Optimized. $N" ||
echo -e "$R $1 Not Optimized. $N"
}

case $ID in
0)
CHK_OPT "Google Play services is"
;;
*)
echo -e "$Y Superuser (su) rights is needed! $N"
exit 1
;;
esac
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "1.8.6",
"versionCode": 186,
"zipUrl": "https://github.com/gloeyisk/universal-gms-doze/releases/download/v1.8.6/gms_v1.8.6.zip",
"version": "1.8.7",
"versionCode": 187,
"zipUrl": "https://github.com/gloeyisk/universal-gms-doze/releases/download/v1.8.7/gms_v1.8.7.zip",
"changelog": "https://raw.githubusercontent.com/gloeyisk/universal-gms-doze/master/changelog.md"
}
4 changes: 2 additions & 2 deletions module.prop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id=universal-gms-doze
name=Universal GMS Doze
version=1.8.6
versionCode=186
version=1.8.7
versionCode=187
author=gloeyisk
description=Patches Google Play services app and its background processes to be able to use battery optimizations.
updateJson=https://raw.githubusercontent.com/gloeyisk/universal-gms-doze/master/module.json
36 changes: 29 additions & 7 deletions post-fs-data.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
#!/sbin/sh
#!/data/adb/magisk/busybox sh
set -o standalone

#
# 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
#

# Search and patch any conflicting modules (if present)
# Patch conflicting XML files
conflict=$(xml=$(find /data/adb -iname "*.xml");for i in $xml; do if grep -q 'allow-in-power-save package="com.google.android.gms"' $i 2>/dev/null; then echo "$i";fi; done)
for i in $conflict
do
sed -i '/allow-in-power-save package="com.google.android.gms"/d;/allow-in-data-usage-save package="com.google.android.gms"/d' $i
done

{
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"
}

{
find /data/adb/* -type f -iname "*.xml" -print |
while IFS= read -r XML; do
for X in $XML; do
if grep -qE "$STR1|$STR2|$STR3|$STR4" $X 2> $NULL; then
sed -i "/$STR1/d;/$STR2/d;/$STR3/d;/$STR4/d" $X
fi
done
done
}
Loading

0 comments on commit e85961f

Please sign in to comment.