From 49a4548984d6c704795e70d37220b51c32d85bb1 Mon Sep 17 00:00:00 2001 From: Alessandro Astone Date: Mon, 7 Feb 2022 23:41:59 +0100 Subject: [PATCH] Add version and arch checks --- build/gapps.sh | 7 ++++ build/main.mk | 4 +-- build/meta/com/google/android/update-binary | 36 +++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/build/gapps.sh b/build/gapps.sh index 52e5ec5..15dea65 100755 --- a/build/gapps.sh +++ b/build/gapps.sh @@ -9,7 +9,10 @@ DATE=$(date -u +%Y%m%d_%H%M%S) TOP=$(realpath .) ANDROIDV=12.0.0 +SDKV=31 GARCH=$1 +CPUARCH=$GARCH +[ ! -z "$2" ] && CPUARCH=$2 OUT=$TOP/out BUILD=$TOP/build METAINF=$BUILD/meta @@ -54,6 +57,10 @@ function create() { test -d $OUT/$GARCH/system/addon.d || mkdir -p $OUT/$GARCH/system/addon.d cp -f addond_head $OUT/$GARCH/system/addon.d cp -f addond_tail $OUT/$GARCH/system/addon.d + echo "Writing build props..." + echo "arch=$CPUARCH" > $OUT/$GARCH/build.prop + echo "version=$SDKV" >> $OUT/$GARCH/build.prop + echo "version_nice=$ANDROIDV" >> $OUT/$GARCH/build.prop } function zipit() { diff --git a/build/main.mk b/build/main.mk index 441f290..bd2f756 100644 --- a/build/main.mk +++ b/build/main.mk @@ -11,11 +11,11 @@ distclean: gapps_arm: @echo "Compiling GApps for arm..." - @bash $(BUILD_GAPPS) arm 2>&1 + @bash $(BUILD_GAPPS) arm armv7l 2>&1 gapps_arm64: @echo "Compiling GApps for arm64..." - @bash $(BUILD_GAPPS) arm64 2>&1 + @bash $(BUILD_GAPPS) arm64 aarch64 2>&1 gapps_x86: @echo "Compiling GApps for x86..." diff --git a/build/meta/com/google/android/update-binary b/build/meta/com/google/android/update-binary index 86ade04..09abde5 100644 --- a/build/meta/com/google/android/update-binary +++ b/build/meta/com/google/android/update-binary @@ -21,6 +21,24 @@ ui_print() { echo "ui_print" > "$OUTFD"; } +getprop2() { + grep -m 1 "^$2=" $1 | cut -d= -f2 +} + +nice_arch() { + case $1 in + aarch64*|armv8*) + echo "arm64" + ;; + arm*) + echo "arm" + ;; + *) + echo $1 + ;; + esac +} + cleanup() { ui_print "Cleaning up files" rm -rf $TMP/system @@ -120,6 +138,15 @@ cd "$TMP" unzip -o "$ZIP" rm -rf META-INF +# Check for arch. We need to do this before extracting our toybox, since that might be +# compiled for a different architecture. Just hope that all environments have at least +# a proper `grep` and `uname`. +GAPPS_ARCH=$(getprop2 $TMP/build.prop arch) +CPU_ARCH=$(uname -m) +if [ $GAPPS_ARCH != $CPU_ARCH ]; then + error "This package is built for $(nice_arch $GAPPS_ARCH) but your device is $(nice_arch $CPU_ARCH)! Aborting" +fi + ui_print "Setting up environment" TOYBOX="${TMP}/toybox" chmod +x "$TOYBOX" @@ -181,6 +208,15 @@ error_mounting "$SYSTEM_MNT" fi SYSTEM_OUT="${SYSTEM_MNT}/system" +# Compare sdk version +GAPPS_VERSION=$(getprop2 $TMP/build.prop version) +ANDROID_VERSION=$(getprop2 $SYSTEM_OUT/build.prop ro.build.version.sdk) +if [ "$GAPPS_VERSION" != "$ANDROID_VERSION" ]; then + gapps_version_nice=$(getprop2 $TMP/build.prop version_nice) + android_version_nice=$(getprop2 $SYSTEM_OUT/build.prop ro.build.version.release) + error "This package is for Android $gapps_version_nice (SDK $GAPPS_VERSION) but your system is Android $android_version_nice (SDK $ANDROID_VERSION)! Aborting" +fi + # Ignore {product,system_ext} block devices in case they are symlinks # This is common on devices where maintainers have chosen not to use # real partitions because of their size being too small to be useful