2
0
mirror of https://gitlab.com/Nanolx/NanoDroid synced 2024-10-31 09:20:23 +00:00
NanoDroid/systest/SysTest
2020-04-18 10:28:32 +02:00

422 lines
11 KiB
Bash

#!/sbin/sh
##########################################################################################
#
# NanoDroid System Testing Script
# by Nanolx
#
##########################################################################################
VERSION=22.6.90.99999999
TMPDIR=/dev/tmp
LOGFILE="/data/media/0/nanodroid_logs/NanoDroid-SysTest-$(date +%Y%m%d-%H.%M.%S).log"
##########################################################################################
# Generic Functions
##########################################################################################
show_banner () {
ui_print " "
ui_print "*******************"
ui_print " NanoDroid SysTest "
ui_print " ${VERSION} "
ui_print "*******************"
ui_print " "
}
ui_print() {
${BOOTMODE} && echo "${1}" || \
echo -e "ui_print ${1}\nui_print" >> /proc/self/fd/${OUTFD}
}
is_mounted () {
if [ ! -z "$2" ]; then
cat /proc/mounts | grep $1 | grep $2, >/dev/null
else
cat /proc/mounts | grep $1 >/dev/null
fi
return $?
}
mount_apex () {
APEX_FILE=""
APEX_DIR=""
APEX_LOOP=""
for apex in com.android.runtime com.android.runtime.release com.android.runtime.debug; do
if [ -f /system/apex/${apex}.apex ]; then
APEX_FILE=/system/apex/${apex}.apex
break
elif [ -d /system/apex/${apex} ]; then
APEX_DIR=/system/apex/${apex}
break
fi
done
if ! ${BOOTMODE}; then
if [ -n "${APEX_FILE}" ]; then
mkdir -p "${TMPDIR}/apex"
unzip -oq "${APEX_FILE}" -d "${TMPDIR}/apex"
mkdir -p /apex/com.android.runtime
mount -oloop,ro "${TMPDIR}/apex/apex_payload.img" /apex/com.android.runtime
APEX_LOOP=$(mount | awk '/com.android.runtime/{print $1}')
elif [ -n "${APEX_DIR}" ]; then
mkdir -p /apex
ln -sf "${APEX_DIR}" /apex/com.android.runtime
fi
fi
}
# taken from Magisk, with minor modifications for NanoDroid
mount_partitions () {
DEVICE_AB=FALSE
VENDOR_COMPAT=FALSE
SYSTEM_AS_ROOT=FALSE
SLOT=$(grep_cmdline androidboot.slot_suffix)
echo " INFO: #1 [SLOT] ${SLOT}"
if [ -z ${SLOT} ]; then
SLOT=$(grep_cmdline androidboot.slot)
echo " INFO: #2 [SLOT] ${SLOT}"
if [ ! -z ${SLOT} ]; then
SLOT=_${SLOT}
echo " INFO: #3 [SLOT] ${SLOT}"
DEVICE_AB=TRUE
fi
fi
system_tmp=$(find /dev/block -type l -name system${SLOT} | head -n 1)
echo " INFO: #4 [system_tmp] ${system_tmp}"
SYSTEM_BLOCK=$(readlink -f ${system_tmp})
echo " INFO: #5 [SYSTEM_BLOCK] ${SYSTEM_BLOCK}"
is_mounted /data || mount /data || error "failed to mount /data!"
mount -o bind /dev/urandom /dev/random
! is_mounted /system && mount -o rw /system
! is_mounted /system && mount -o rw ${SYSTEM_BLOCK} /system
! is_mounted /system && error "failed to mount /system!"
if [ -f /system/init.rc ]; then
SYSTEM_AS_ROOT=true
[ -L /system_root ] && rm -f /system_root
mkdir /system_root 2>/dev/null
mount --move /system /system_root
mount -o bind /system_root/system /system
fi
vendor_tmp=$(find /dev/block -type l -name vendor${SLOT} | head -n 1)
echo " INFO: #6 [vendor_tmp] ${vendor_tmp}"
VENDOR_BLOCK=$(readlink -f ${vendor_tmp})
echo " INFO: #7 [VENDOR_BLOCK] ${VENDOR_BLOCK}"
! is_mounted /vendor && mount -o ro /vendor || mount -o ro ${VENDOR_BLOCK} /vendor
if [ -d /system/vendor ]; then
### XXX work-around required for some ROMs
VENDOR_COMPAT=TRUE
ln -sf /system/vendor /vendor >/dev/null
fi
echo " "
mount | awk '{print $1 " on " $3 " params: " $6}'
echo " "
echo " INFO: #8 [prop]"
ls -l /system/*.prop
export build_props=$(find /system /system_root /vendor -type f -name build.prop)
echo " INFO: #9 [build_props] ${build_props}"
[ -z "${build_props}" ] && error "failed to mount /system (unsupported A/B device?)"
mount_apex
}
error () {
ui_print " "
ui_print " !! ${@}"
ui_print " "
exit 1
}
##########################################################################################
# check if ROM has native fake signature spoofing support
# by @ale5000
##########################################################################################
check_fake_package_signature () {
PERMISSION=android.permission.FAKE_PACKAGE_SIGNATURE
PERMISSION_OD=$(echo -n "${PERMISSION}" | od -A n -t x1 | tr -d '\n' | sed -e 's/^ //g;s/ /00/g')
HAS_FAKESIGN=false
FW_RES_DIR="${TMPDIR}/framework-res"
FW_RES_FILE="${FW_RES_DIR}/AndroidManifest.xml"
if [ ! -f ${FW_RES_FILE} ]; then
mkdir -p "${FW_RES_DIR}"
unzip -oq /system/framework/framework-res.apk -d "${FW_RES_DIR}"
fi
grep -qF "${PERMISSION}" "${FW_RES_FILE}" && HAS_FAKESIGN=true
od -A n -t x1 "${FW_RES_FILE}" | tr -d ' \n' | grep -qF "${PERMISSION_OD}" && HAS_FAKESIGN=true
${HAS_FAKESIGN} && return 0 || return 1
}
##########################################################################################
# check if Bromite System WebView is supported
##########################################################################################
check_bromite_webview_support () {
WEBVIEW_PKG="com.android.webview"
HAS_WEBVIEW=false
${AAPT} dump xmltree /system/framework/framework-res.apk res/xml/config_webview_packages.xml | \
tr -d '\n' | sed -e 's/webviewprovider/\n/g' | grep com.android.webview | \
grep -q 'E: signature' || HAS_WEBVIEW=true
${HAS_WEBVIEW} && return 0 || return 1
}
##########################################################################################
# Device Functions
##########################################################################################
detect_outfd () {
if [ -z $OUTFD ] || readlink /proc/$$/fd/$OUTFD | grep -q /tmp; then
# We will have to manually find out OUTFD
for FD in `ls /proc/$$/fd`; do
if readlink /proc/$$/fd/$FD | grep -q pipe; then
if ps | grep -v grep | grep -q " 3 $FD "; then
OUTFD=$FD
break
fi
fi
done
fi
}
detect_bootmode () {
[ -z ${BOOTMODE} ] && BOOTMODE=false
${BOOTMODE} || ps | grep zygote | grep -qv grep && BOOTMODE=true
${BOOTMODE} || ps -A | grep zygote | grep -qv grep && BOOTMODE=true
}
grep_prop() {
[ -f /vendor/build.prop ] && \
FILES="/system/build.prop /vendor/build.prop" || \
FILES="/system/build.prop"
sed -n "s/^${1}=//p" ${FILES} | head -n 1
}
grep_cmdline() {
local REGEX="s/^${1}=//p"
sed -E 's/ +/\n/g' /proc/cmdline | \
sed -n "${REGEX}" 2>/dev/null
}
system_test () {
ABI=$(grep_prop ro.product.cpu.abi | cut -c-3)
ABI2=$(grep_prop ro.product.cpu.abi2 | cut -c-3)
ABILONG=$(grep_prop ro.product.cpu.abi)
ARCH=arm
[ "$ABI" = "x86" ] && ARCH=x86
[ "$ABI2" = "x86" ] && ARCH=x86
[ "$ABILONG" = "arm64-v8a" ] && ARCH=arm64
[ "$ABILONG" = "x86_64" ] && ARCH=x86_64
case ${ARCH} in
arm | arm64 )
BB=${TMPDIR}/busybox.arm
FILE=${TMPDIR}/file.arm
AAPT=${TMPDIR}/aapt.arm
;;
x86 | x86_64 )
BB=${TMPDIR}/busybox.x86
FILE=${TMPDIR}/file.x86
AAPT=${TMPDIR}/aapt.x86
;;
esac
OLD_PATH=${PATH}
mkdir -p ${TMPDIR}/busybox
ln -s ${BB} ${TMPDIR}/busybox/busybox
chmod 0755 ${BB}
${BB} --install -s ${TMPDIR}/busybox/
export PATH="${TMPDIR}/busybox:${PATH}"
chmod 0755 "${FILE}" "${AAPT}"
DALVIKVM_BIN=$(ls -l /system/bin/dalvikvm | awk '{print $NF}')
DALVIKVM_ARCH=$("${FILE}" -m "${TMPDIR}/magic.mgc" -L /system/bin/dalvikvm)
case ${DALVIKVM_BIN} in
dalvikvm32 )
LD="/system/lib:/vendor/lib:/system/vendor/lib"
;;
dalvikvm64 )
LD="/system/lib64:/vendor/lib64:/system/vendor/lib64"
;;
dalvikvm )
case ${DALVIKVM_ARCH} in
*32-bit* )
LD="/system/lib:/vendor/lib:/system/vendor/lib"
;;
*64-bit* )
LD="/system/lib64:/vendor/lib64:/system/vendor/lib64"
;;
esac
;;
esac
SERVICES_JAR_DEX=$(unzip -lq /system/framework/services.jar | grep classes.dex)
if [ -n "$(find '/system/framework/' -name 'services.vdex')" ]; then
ROM_DEX_STATUS=VDEX
elif [ -n "$(find '/system/framework/' -name 'services.odex')" ]; then
ROM_DEX_STATUS=ODEX
else ROM_DEX_STATUS=UNKOWN
fi
[ "${SERVICES_JAR_DEX}" ] && ROM_DEX_STATUS=DEODEX
}
add_log () {
echo "${@}" >> ${LOGFILE}
}
store_results () {
mkdir -p "$(dirname "${LOGFILE}")"
add_log "NanoDroid System Test Results"
add_log "============================="
add_log ""
add_log "CPU and ABI details"
add_log "==================="
add_log ""
add_log "ARCH=${ARCH}"
add_log "ABI=${ABI}"
add_log "ABI2=${ABI2}"
add_log "ABILONG=${ABILONG}"
add_log ""
add_log "Mounted Partitions"
add_log "=================="
add_log ""
add_log "DEVICE_AB=${DEVICE_AB}"
add_log "VENDOR_COMPAT=${VENDOR_COMPAT}"
add_log "SYSTEM_AS_ROOT=${SYSTEM_AS_ROOT}"
add_log "SYSTEMBLOCK=${SYSTEMBLOCK}"
add_log "VENDORBLOCK=${VENDORBLOCK}"
add_log ""
mount | sed '/magisk/d' | awk '{print $1 " on " $3 " params: " $6}' >> ${LOGFILE}
if [ ! ${BOOTMODE} ]; then
add_log ""
add_log "TWRP usuable space for Installer"
add_log "================================"
add_log ""
add_log $(df /dev 2>/dev/null | awk '/tmpfs/{print $4}')
fi
add_log ""
add_log "DalvikVM, LD_LIBRARY_PATH and DEX status"
add_log "========================================"
add_log ""
add_log "DALVIKVM_BIN=${DALVIKVM_BIN}"
add_log "DALVIKVM_ARCH=${DALVIKVM_ARCH}"
add_log "LD_LIBRARY_PATH=${LD}"
add_log "ROM_DEX_STATUS=${ROM_DEX_STATUS}"
if [ -n "${APEX_FILE}" ]; then
add_log "APEX_FILE=${APEX_FILE}"
elif [ -n "${APEX_DIR}" ]; then
add_log "APEX_DIR=${APEX_DIR}"
fi
add_log ""
add_log "Generic System Properties"
add_log "========================="
add_log ""
for prop in ro.build.description ro.build.display.id ro.build.flavor ro.build.product \
ro.build.tags ro.build.type ro.build.version.sdk ro.build.version.security_patch \
ro.product.cpu.abi ro.product.cpu.abilist ro.product.cpu.abilist32 \
ro.product.cpu.abilist64 ro.product.model ro.product.vendor.device; do
add_log "${prop}=$(grep_prop ${prop})"
done
add_log ""
add_log "Native Signature Spoofing support"
add_log "================================="
add_log ""
check_fake_package_signature && add_log "NATIVE_SIGSPOOF=TRUE" || add_log "NATIVE_SIGSPOOF=FALSE"
add_log ""
add_log "Bromite System WebView support"
add_log "=============================="
add_log ""
check_bromite_webview_support && add_log "WEBVIEW_SUPPORT=TRUE" || add_log "WEBVIEW_SUPPORT=FALSE"
add_log ""
add_log "Magisk installation status"
add_log "=========================="
add_log ""
if [ -f /data/adb/magisk/util_functions.sh ]; then
add_log "MAGISK=TRUE"
. /data/adb/magisk/util_functions.sh
add_log "MAGISK_VERSION=${MAGISK_VER_CODE}"
if [ ${MAGISK_VER_CODE} -gt 18100 ]; then
add_log "MAGISK_IMAGELESS=TRUE"
else add_log "MAGISK_IMAGELESS=FALSE"
fi
else
add_log "MAGISK=FALSE"
add_Log "MAGISK_VERSION=NONE"
add_log "MAGISK_IMAGELESS=FALSE"
fi
add_log ""
add_log "Installed Google packages"
add_log "=== packages.list ======="
add_log ""
grep google /data/system/packages.list | sort >> ${LOGFILE}
add_log ""
add_log "=== packages.xml ========"
add_log ""
grep 'package .*google' /data/system/packages.xml | sort >> ${LOGFILE}
add_log ""
add_log "Content of /system/app"
add_log "======================"
add_log ""
find /system/app -type f -name '*.apk' | sort >> ${LOGFILE}
add_log ""
add_log "Content of /system/priv-app"
add_log "==========================="
add_log ""
find /system/priv-app -type f -name '*.apk' | sort >> ${LOGFILE}
chown root:sdcard_rw ${LOGFILE}
chmod 0644 ${LOGFILE}
export PATH=${OLD_PATH}
}