From c0c48a07807ef87a247516a324c1e5670791a34a Mon Sep 17 00:00:00 2001 From: Christopher Roy Bratusek Date: Wed, 23 Sep 2020 13:25:37 +0200 Subject: [PATCH] CommonInstaller: auto-detect whether we use official or Nanolx GmsCore/DroidGuard and migrate if required --- CommonInstaller | 61 +++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/CommonInstaller b/CommonInstaller index b51f592..3222033 100644 --- a/CommonInstaller +++ b/CommonInstaller @@ -451,40 +451,44 @@ detect_migrate_microg () { GMSCORE_PATH=$(find /data/app -type d -name 'com.google.android.gms-*' 2>/dev/null) if [ ! -z ${GMSCORE_PATH} ]; then - if [ -n "${1}" ]; then - if ! ${UNZIP} -l "${GMSCORE_PATH}/base.apk" | grep META-INF/NANOLX.RSA 2>/dev/null; then - decho " + Removing Official microG GmsCore in favor of NanoDroid microG GmsCore" - rm -rf "${GMSCORE_PATH}" + if ${UNZIP} -l "${MODPATH}/system/priv-app/GmsCore/GmsCore.apk" | grep META-INF/NANOLX.RSA 2>/dev/null; then + GMSCORE_BUILD=Nanolx + else GMSCORE_BUILD=Official + fi - decho " + Resetting GCM/FCM connection of all apps to allow re-registration" - find /data/data/*/shared_prefs -name com.google.android.gms.*.xml -delete - fi - else - if ${UNZIP} -l "${GMSCORE_PATH}/base.apk" | grep META-INF/NANOLX.RSA 2>/dev/null; then - decho " + Removing NanoDroid microG GmsCore in favor of Official microG GmsCore" - rm -rf "${GMSCORE_PATH}" + if ${UNZIP} -l "${GMSCORE_PATH}/base.apk" | grep META-INF/NANOLX.RSA 2>/dev/null; then + GMSCORE_LOCAL=Nanolx + else GMSCORE_LOCAL=Official + fi - decho " + Resetting GCM/FCM connection of all apps to allow re-registration" - find /data/data/*/shared_prefs -name com.google.android.gms.*.xml -delete - fi + if [ "${GMSCORE_LOCAL}" != "${GMSCORE_BUILD}" ]; then + decho " + Removing ${GMSCORE_LOCAL} microG GmsCore in favor of ${GMSCORE_BUILD} microG GmsCore" + rm -rf "${GMSCORE_PATH}" + + decho " + Resetting GCM/FCM connection of all apps to allow re-registration" + find /data/data/*/shared_prefs -name com.google.android.gms.*.xml -delete fi fi } detect_migrate_droidguard () { DROIDGUARD_PATH=$(find /data/app -type d -name 'org.microg.gms.droidguard-*' 2>/dev/null) + DROIDGUARD_TYPE="Nanolx" if [ ! -z ${DROIDGUARD_PATH} ]; then - if [ -n "${1}" ]; then - if ! ${UNZIP} -l "${DROIDGUARD_PATH}/base.apk" | grep META-INF/NANOLX.RSA 2>/dev/null; then - decho " + Removing Official DroidGuard in favor of NanoDroid DroidGuard" - rm -rf "${DROIDGUARD_PATH}" - fi - else - if ${UNZIP} -l "${DROIDGUARD_PATH}/base.apk" | grep META-INF/NANOLX.RSA 2>/dev/null; then - decho " + Removing NanoDroid DroidGuard in favor of Official DroidGuard" - rm -rf "${DROIDGUARD_PATH}" - fi + if ${UNZIP} -l "${MODPATH}/system/papp/DroidGuard/DroidGuard.apk" | grep META-INF/NANOLX.RSA 2>/dev/null; then + DROIDGUARD_BUILD=Nanolx + else DROIDGUARD_BUILD=Official + fi + + if ${UNZIP} -l "${DROIDGUARD_PATH}/base.apk" | grep META-INF/NANOLX.RSA 2>/dev/null; then + DROIDGUARD_LOCAL=Nanolx + else DROIDGUARD_LOCAL=Official + fi + + if [ "${DROIDGUARD_LOCAL}" != "${DROIDGUARD_TYPE}" ]; then + decho " + Removing ${DROIDGUARD_LOCAL} DroidGuard in favor of ${DROIDGUARD_BUILD} DroidGuard" + rm -rf "${DROIDGUARD_PATH}" fi fi } @@ -1096,20 +1100,17 @@ install_microg () { print_info " ++ Radiocell location backend" fi - # migrate from Nanolx microG GmsCore to Official microG GmsCore - detect_migrate_microg - - # migrate from Official DroidGuard to Nanolx DroidGuard - detect_migrate_droidguard reverse - print_info " ++ microG GmsCore" nanodroid_install_apk GmsCore + detect_migrate_microg if [ "${nanodroid_microg}" -ne 2 ]; then for app in GsfProxy DroidGuard; do nanodroid_install_apk ${app} done + detect_migrate_droidguard + ${NANODROID_BINDIR}/nanodroid-overlay --add GmsDroidGuard fi