From 8a8fdf06dc59eaef03af9098bf09ba77ff01cd85 Mon Sep 17 00:00:00 2001 From: uurcan7 <79050542+uurcan7@users.noreply.github.com> Date: Fri, 6 Nov 2026 22:23:01 +0000 Subject: [PATCH 1/2] fix: improve boot property handling and CI Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/workflows/build.yml | 28 ++++++- CHANGELOG.md | 5 ++ README.md | 1 + common/prop-handler.sh | 50 ++++++++++++ package.sh | 2 + prop.sh | 55 +++++++------ service.sh | 24 ++++-- tests/package-contents.sh | 30 +++++++ tests/prop-handler.sh | 148 ++++++++++++++++++++++++++++++++++ tests/service-prop-handler.sh | 124 ++++++++++++++++++++++++++++ 10 files changed, 435 insertions(+), 32 deletions(-) create mode 100644 common/prop-handler.sh create mode 100644 tests/package-contents.sh create mode 100644 tests/prop-handler.sh create mode 100644 tests/service-prop-handler.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9f59d34..53a4280 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,6 +7,7 @@ on: - 'rust/**' - 'webui/**' - 'common/**' + - 'tests/**' - '*.sh' - 'module.prop' - '.github/workflows/build.yml' @@ -14,9 +15,27 @@ on: branches: [main] paths: - 'rust/**' + - 'webui/**' + - 'common/**' + - 'tests/**' + - '*.sh' + - 'module.prop' + - '.github/workflows/build.yml' workflow_dispatch: jobs: + shell-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Test property handler + run: | + sh -n prop.sh service.sh common/prop-handler.sh + sh -n tests/prop-handler.sh tests/service-prop-handler.sh tests/package-contents.sh + bash -n package.sh + sh tests/prop-handler.sh + sh tests/service-prop-handler.sh + build: runs-on: ubuntu-latest strategy: @@ -116,7 +135,7 @@ jobs: retention-days: 7 package: - needs: build + needs: [build, shell-tests] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -171,6 +190,9 @@ jobs: -x ".gitignore" \ -x ".gitmodules" \ -x ".github/*" \ + -x ".omc/*" \ + -x ".context/*" \ + -x "handoff/*" \ -x "external/*" \ -x "artifacts/*" \ -x "CLAUDE.md" \ @@ -182,6 +204,7 @@ jobs: -x "release/*" \ -x "package.sh" \ -x "rust/*" \ + -x "tests/*" \ -x "node_modules/*" \ -x "webui/src/*" \ -x "webui/node_modules/*" \ @@ -208,6 +231,9 @@ jobs: -x "webui/material-symbols-outlined.woff2" \ -x "*.md" + - name: Verify module ZIPs + run: sh tests/package-contents.sh release/*.zip + - name: Separate ZIPs run: | mkdir -p release/rel release/dbg diff --git a/CHANGELOG.md b/CHANGELOG.md index 75a3b14..dff9485 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +- Prefer the active root manager's native resetprop for the boot property handler, with the bundled ABI-specific binary as a fallback. Verify property writes and log failures. This adapts the vivo fork's resetprop fix without waiting until boot completion and avoids losing the handler if Magisk removes the original module copy. +- Run property-handler tests and Android builds for shell, WebUI and other module changes in pull requests; exclude test and session files from packaged ZIPs. + ## v5.53.1 (2026-05-01) ### Bug Fixes diff --git a/README.md b/README.md index 7f38e18..77605f4 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ One binary. One process. One config file. No shell scripts in the hot path. - [x] **15 properties spoofed** — `vbmeta.digest`, `device_state`, `verifiedbootstate`, and 12 more - [x] **Captured at install time** — reads `ro.boot.vbmeta.digest` before any modules are active - [x] **Fallback chain** — persisted file → bootloader property → APK extraction (last resort) +- [x] **Root-manager resetprop** — the boot property handler prefers the active manager's native resetprop, falls back to the bundled binary, and logs failed or ineffective writes to `ta-enhanced/logs/main.log` **Custom ROM Identity Hiding** - [x] **LineageOS prop scrub on boot:** strips the `lineage_` prefix from `ro.product.vendor.name`, replaces `org.lineageos.aperture` in `vendor.camera.aux.packagelist` and `persist.vendor.camera.privapp.list`, stops `vendor.lineage_health` and deletes its `init.svc.*` status prop diff --git a/common/prop-handler.sh b/common/prop-handler.sh new file mode 100644 index 0000000..e9dde3e --- /dev/null +++ b/common/prop-handler.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +select_prop_resetprop() { + local manager="$1" bundled="$2" adb_dir="${3:-/data/adb}" native="" + + case "$manager" in + KSU) native="$adb_dir/ksu/bin/resetprop" ;; + APATCH) native="$adb_dir/ap/bin/resetprop" ;; + MAGISK) native="$adb_dir/magisk/resetprop" ;; + esac + + if [ -n "$native" ] && [ -x "$native" ]; then + printf '%s\n' "$native" + elif [ -x "$bundled" ]; then + printf '%s\n' "$bundled" + else + printf 'No executable resetprop found for %s (bundled: %s)\n' "$manager" "$bundled" >&2 + return 1 + fi +} + +set_reset_prop() { + local name="$1" expected="$2" value + + if ! "$RP" -n "$name" "$expected"; then + printf 'Failed to set property %s\n' "$name" >&2 + return 1 + fi + if ! value=$("$RP" "$name"); then + printf 'Failed to verify property %s\n' "$name" >&2 + return 1 + fi + if [ "$value" != "$expected" ]; then + printf 'Property %s did not retain the requested value\n' "$name" >&2 + return 1 + fi +} + +check_reset_prop() { + local name="$1" expected="$2" value + + if ! value=$("$RP" "$name"); then + printf 'Failed to read property %s\n' "$name" >&2 + return 1 + fi + if [ -z "$value" ] || [ "$value" = "$expected" ]; then + return 0 + fi + set_reset_prop "$name" "$expected" +} diff --git a/package.sh b/package.sh index 9876d6a..ea0387b 100755 --- a/package.sh +++ b/package.sh @@ -152,6 +152,7 @@ REQUIRED_FILES=( prop.sh uninstall.sh install_func.sh + common/prop-handler.sh hotinstall.sh module.prop update.json @@ -246,6 +247,7 @@ zip -r9 "$ZIP_PATH" . \ -x "release/*" \ -x "package.sh" \ -x "rust/*" \ + -x "tests/*" \ -x "node_modules/*" \ -x "webui/src/*" \ -x "webui/node_modules/*" \ diff --git a/prop.sh b/prop.sh index d1d2c96..c123baa 100644 --- a/prop.sh +++ b/prop.sh @@ -1,37 +1,46 @@ #!/bin/sh RP="${RP_BIN:-resetprop}" - -check_reset_prop() { - local NAME=$1 - local EXPECTED=$2 - local VALUE=$($RP $NAME) - [ -z $VALUE ] || [ $VALUE = $EXPECTED ] || $RP -n $NAME $EXPECTED -} +SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) +. "$SCRIPT_DIR/common/prop-handler.sh" contains_reset_prop() { local NAME=$1 local CONTAINS=$2 local NEWVAL=$3 - [[ "$($RP $NAME)" = *"$CONTAINS"* ]] && $RP -n $NAME $NEWVAL + local VALUE + if ! VALUE=$("$RP" "$NAME"); then + printf 'Failed to read property %s\n' "$NAME" >&2 + return 1 + fi + case "$VALUE" in + *"$CONTAINS"*) set_reset_prop "$NAME" "$NEWVAL" ;; + esac } empty_reset_prop() { local NAME=$1 local NEWVAL=$2 - local VALUE=$(getprop "$NAME") - [ -z "$VALUE" ] && $RP -n $NAME $NEWVAL + local VALUE + if ! VALUE=$(getprop "$NAME"); then + printf 'Failed to read property %s\n' "$NAME" >&2 + return 1 + fi + [ -n "$VALUE" ] && return 0 + set_reset_prop "$NAME" "$NEWVAL" } -$RP -w sys.boot_completed 0 - if [ -f "/data/adb/disable_prop_handler" ]; then exit 0 fi if [ ! -f "/data/adb/disable_vbmeta_digest_spoof" ] && [ -f "/data/adb/boot_hash" ]; then hash_value=$(grep -v '^#' "/data/adb/boot_hash" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]') - [ -z "$hash_value" ] && rm -f /data/adb/boot_hash || $RP -n ro.boot.vbmeta.digest "$hash_value" + if [ -z "$hash_value" ]; then + rm -f /data/adb/boot_hash || printf '%s\n' 'Failed to remove empty boot hash' >&2 + else + set_reset_prop ro.boot.vbmeta.digest "$hash_value" + fi fi check_reset_prop "ro.boot.vbmeta.device_state" "locked" @@ -65,24 +74,24 @@ contains_reset_prop "ro.boot.bootmode" "recovery" "unknown" contains_reset_prop "vendor.boot.bootmode" "recovery" "unknown" # Custom ROM (LineageOS) identity scrub: only fires when LOS-only signatures are present -v=$($RP ro.product.vendor.name) +v=$("$RP" ro.product.vendor.name) case "$v" in - lineage_*) $RP -n ro.product.vendor.name "${v#lineage_}" ;; + lineage_*) set_reset_prop ro.product.vendor.name "${v#lineage_}" ;; esac -v=$($RP vendor.camera.aux.packagelist) +v=$("$RP" vendor.camera.aux.packagelist) case "$v" in - *org.lineageos*) $RP -n vendor.camera.aux.packagelist "com.android.camera" ;; + *org.lineageos*) set_reset_prop vendor.camera.aux.packagelist "com.android.camera" ;; esac -v=$($RP persist.vendor.camera.privapp.list) +v=$("$RP" persist.vendor.camera.privapp.list) case "$v" in - *org.lineageos*) $RP -n persist.vendor.camera.privapp.list "com.android.camera" ;; + *org.lineageos*) set_reset_prop persist.vendor.camera.privapp.list "com.android.camera" ;; esac -[ -n "$($RP init.svc.vendor.lineage_health)" ] && { - setprop ctl.stop vendor.lineage_health - $RP -d init.svc.vendor.lineage_health +[ -n "$("$RP" init.svc.vendor.lineage_health)" ] && { + setprop ctl.stop vendor.lineage_health || printf '%s\n' 'Failed to stop vendor.lineage_health' >&2 + "$RP" -d init.svc.vendor.lineage_health || printf '%s\n' 'Failed to delete init.svc.vendor.lineage_health' >&2 } # Reset vbmeta related prop @@ -92,4 +101,4 @@ empty_reset_prop "ro.boot.vbmeta.avb_version" "1.0" empty_reset_prop "ro.boot.vbmeta.hash_alg" "sha256" empty_reset_prop "ro.boot.vbmeta.size" "4096" -$RP -c || true +exit 0 diff --git a/service.sh b/service.sh index a0b2557..03ec18a 100644 --- a/service.sh +++ b/service.sh @@ -5,6 +5,7 @@ HIDE_DIR="/data/adb/modules/.TA_enhanced" TSPA="/data/adb/modules/tsupport-advance" . "$MODPATH/common/common.sh" +. "$MODPATH/common/prop-handler.sh" detect_manager _log "INFO" "Service started (manager=$MANAGER)" @@ -40,12 +41,6 @@ add_denylist_to_target() { # Security patch is handled by the daemon's SecurityPatchTask (with retries + bulletin fetch). # Running `set` here would overwrite bulletin-fetched dates with stale device props. -# prop.sh runs with RP_BIN pointed at the bundled resetprop-rs to keep the -# upstream calling pattern intact while sourcing the property setter from -# the module bundle. -RP_BIN="$MODPATH/bin/$ABI/resetprop-rs" sh "$MODPATH/prop.sh" & - - # TSupport-A Interop if [ -d "$TSPA" ]; then touch "/storage/emulated/0/stop-tspa-auto-target" 2>/dev/null || true @@ -77,6 +72,18 @@ else [ -d "$HIDE_DIR" ] && rm -rf "$HIDE_DIR" fi +if PROP_RP_BIN=$(select_prop_resetprop "$MANAGER" "$MODPATH/bin/$ABI/resetprop-rs"); then + _log "INFO" "Property handler using $PROP_RP_BIN" + ( + RP_BIN="$PROP_RP_BIN" sh "$MODPATH/prop.sh" || + printf '%s\n' "Property handler exited with an error" + ) 2>&1 | while IFS= read -r line; do + _log "WARN" "$line" + done & +else + _log "ERROR" "Property handler could not find a usable resetprop" +fi + # Ensure system_app file exists for WebUI system app display if [ ! -f "$TS_DIR/system_app" ]; then : > "$TS_DIR/system_app" @@ -150,8 +157,9 @@ mkdir -p "$MODPATH/common/tmp" # Xposed Detection (background) "$BIN" status xposed-scan >> "$LOG_BASE_DIR/main.log" 2>&1 & -# Magisk: clean up unhidden module dir -[ -f "$MODPATH/action.sh" ] && rm -rf "/data/adb/modules/TA_enhanced" +# Magisk: clean up the unhidden copy only after switching to the hidden copy. +[ "$MANAGER" = "MAGISK" ] && [ "$MODPATH" = "$HIDE_DIR" ] && [ -f "$MODPATH/action.sh" ] && + rm -rf "/data/adb/modules/TA_enhanced" # Launch Daemon _log "INFO" "Starting ta-enhanced daemon" diff --git a/tests/package-contents.sh b/tests/package-contents.sh new file mode 100644 index 0000000..69501d7 --- /dev/null +++ b/tests/package-contents.sh @@ -0,0 +1,30 @@ +#!/bin/sh +set -eu + +if [ "$#" -eq 0 ]; then + echo "Usage: sh tests/package-contents.sh [...]" >&2 + exit 2 +fi + +for archive in "$@"; do + unzip -tq "$archive" >/dev/null + contents=$(unzip -Z1 "$archive" | sed 's|^\./||') + + for required in \ + META-INF/com/google/android/update-binary \ + module.prop service.sh prop.sh common/prop-handler.sh webui/index.html \ + bin/arm64-v8a/ta-enhanced bin/arm64-v8a/resetprop-rs \ + bin/armeabi-v7a/ta-enhanced bin/armeabi-v7a/resetprop-rs \ + bin/x86/ta-enhanced bin/x86/resetprop-rs \ + bin/x86_64/ta-enhanced bin/x86_64/resetprop-rs; do + if ! printf '%s\n' "$contents" | grep -Fxq "$required"; then + printf 'Missing %s in %s\n' "$required" "$archive" >&2 + exit 1 + fi + done + if printf '%s\n' "$contents" | grep -Eq '^(\.git|\.github|\.omc|\.context|handoff|artifacts|release|rust|tests)/'; then + printf 'Development or session files found in %s\n' "$archive" >&2 + exit 1 + fi + printf 'Validated %s\n' "$archive" +done diff --git a/tests/prop-handler.sh b/tests/prop-handler.sh new file mode 100644 index 0000000..c4d173a --- /dev/null +++ b/tests/prop-handler.sh @@ -0,0 +1,148 @@ +#!/bin/sh +set -eu + +repo_dir=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) +. "$repo_dir/common/prop-handler.sh" + +tmpdir=$(mktemp -d) +trap 'rm -rf "$tmpdir"' EXIT HUP INT TERM +adb_dir="$tmpdir/adb" +bundled="$tmpdir/bundled resetprop" +mkdir -p "$adb_dir/ksu/bin" "$adb_dir/ap/bin" "$adb_dir/magisk" "$tmpdir/state" + +assert_equal() { + if [ "$1" != "$2" ]; then + printf 'FAIL: %s: expected "%s", got "%s"\n' "$3" "$2" "$1" >&2 + exit 1 + fi +} + +for native in "$adb_dir/ksu/bin/resetprop" "$adb_dir/ap/bin/resetprop" "$adb_dir/magisk/resetprop"; do + : > "$native" + chmod +x "$native" +done + +cat > "$bundled" <<'EOF' +#!/bin/sh +set -eu +printf '%s\n' "$*" >> "$MOCK_STATE_DIR/calls" +if [ "$1" = "-n" ]; then + [ "${MOCK_FAIL_SET:-0}" = 0 ] || exit 1 + if [ "${MOCK_IGNORE_SET:-0}" = 0 ]; then + printf '%s' "$3" > "$MOCK_STATE_DIR/$2" + fi +elif [ "$1" = "-d" ]; then + rm -f "$MOCK_STATE_DIR/$2" +else + [ "${MOCK_FAIL_GET:-0}" = 0 ] || exit 1 + if [ -f "$MOCK_STATE_DIR/$1" ]; then + cat "$MOCK_STATE_DIR/$1" + fi +fi +EOF +chmod +x "$bundled" + +assert_equal "$(select_prop_resetprop KSU "$bundled" "$adb_dir")" "$adb_dir/ksu/bin/resetprop" "KernelSU native" +assert_equal "$(select_prop_resetprop APATCH "$bundled" "$adb_dir")" "$adb_dir/ap/bin/resetprop" "APatch native" +assert_equal "$(select_prop_resetprop MAGISK "$bundled" "$adb_dir")" "$adb_dir/magisk/resetprop" "Magisk native" +chmod -x "$adb_dir/ksu/bin/resetprop" +assert_equal "$(select_prop_resetprop KSU "$bundled" "$adb_dir")" "$bundled" "fallback ignores other managers" +assert_equal "$(select_prop_resetprop UNKNOWN "$bundled" "$adb_dir")" "$bundled" "unknown manager fallback" +if select_prop_resetprop KSU "$tmpdir/missing" "$adb_dir" 2>"$tmpdir/error"; then + echo "FAIL: missing binaries were accepted" >&2 + exit 1 +fi +grep -q 'No executable resetprop found' "$tmpdir/error" + +RP="$bundled" +MOCK_STATE_DIR="$tmpdir/state" +export MOCK_STATE_DIR + +printf '%s' unlocked > "$MOCK_STATE_DIR/ro.boot.vbmeta.device_state" +check_reset_prop ro.boot.vbmeta.device_state locked +assert_equal "$(cat "$MOCK_STATE_DIR/ro.boot.vbmeta.device_state")" locked "property updated" +assert_equal "$(wc -l < "$MOCK_STATE_DIR/calls" | tr -d ' ')" 3 "write verified" + +: > "$MOCK_STATE_DIR/calls" +check_reset_prop ro.boot.vbmeta.device_state locked +check_reset_prop ro.boot.missing locked +assert_equal "$(wc -l < "$MOCK_STATE_DIR/calls" | tr -d ' ')" 2 "unchanged and missing properties are not written" +[ ! -e "$MOCK_STATE_DIR/ro.boot.missing" ] + +printf '%s' unlocked > "$MOCK_STATE_DIR/ro.boot.vbmeta.device_state" +export MOCK_FAIL_SET=1 +if check_reset_prop ro.boot.vbmeta.device_state locked 2>"$tmpdir/error"; then + echo "FAIL: failed write was accepted" >&2 + exit 1 +fi +grep -q 'Failed to set property ro.boot.vbmeta.device_state' "$tmpdir/error" +unset MOCK_FAIL_SET + +export MOCK_IGNORE_SET=1 +if check_reset_prop ro.boot.vbmeta.device_state locked 2>"$tmpdir/error"; then + echo "FAIL: ineffective write was accepted" >&2 + exit 1 +fi +grep -q 'did not retain the requested value' "$tmpdir/error" +unset MOCK_IGNORE_SET + +export MOCK_FAIL_GET=1 +if check_reset_prop ro.boot.vbmeta.device_state locked 2>"$tmpdir/error"; then + echo "FAIL: failed read was accepted" >&2 + exit 1 +fi +grep -q 'Failed to read property ro.boot.vbmeta.device_state' "$tmpdir/error" +unset MOCK_FAIL_GET + +mkdir -p "$tmpdir/common" "$tmpdir/mockbin" +cp "$repo_dir/common/prop-handler.sh" "$tmpdir/common/prop-handler.sh" +sed "s|/data/adb|$adb_dir|g" "$repo_dir/prop.sh" > "$tmpdir/prop.sh" +cat > "$tmpdir/mockbin/getprop" <<'EOF' +#!/bin/sh +if [ -f "$MOCK_STATE_DIR/$1" ]; then + cat "$MOCK_STATE_DIR/$1" +fi +EOF +cat > "$tmpdir/mockbin/setprop" <<'EOF' +#!/bin/sh +printf '%s\n' "$*" >> "$MOCK_STATE_DIR/setprop-calls" +EOF +chmod +x "$tmpdir/mockbin/getprop" "$tmpdir/mockbin/setprop" + +printf '%s' unlocked > "$MOCK_STATE_DIR/ro.boot.vbmeta.device_state" +printf '%s' orange > "$MOCK_STATE_DIR/ro.boot.verifiedbootstate" +printf '%s' 0 > "$MOCK_STATE_DIR/ro.boot.flash.locked" +printf '%s' lineage_device > "$MOCK_STATE_DIR/ro.product.vendor.name" +printf '%s' org.lineageos.aperture > "$MOCK_STATE_DIR/vendor.camera.aux.packagelist" +printf '%s' running > "$MOCK_STATE_DIR/init.svc.vendor.lineage_health" +printf '%s\n' ABC123 > "$adb_dir/boot_hash" +: > "$MOCK_STATE_DIR/calls" +(cd "$tmpdir" && PATH="$tmpdir/mockbin:$PATH" RP_BIN="$bundled" sh prop.sh) 2>"$tmpdir/error" +[ ! -s "$tmpdir/error" ] +assert_equal "$(cat "$MOCK_STATE_DIR/ro.boot.vbmeta.device_state")" locked "boot device state" +assert_equal "$(cat "$MOCK_STATE_DIR/ro.boot.verifiedbootstate")" green "verified boot state" +assert_equal "$(cat "$MOCK_STATE_DIR/ro.boot.flash.locked")" 1 "flash lock state" +assert_equal "$(cat "$MOCK_STATE_DIR/ro.boot.vbmeta.digest")" abc123 "boot hash" +assert_equal "$(cat "$MOCK_STATE_DIR/ro.product.vendor.name")" device "LineageOS property" +assert_equal "$(cat "$MOCK_STATE_DIR/vendor.camera.aux.packagelist")" com.android.camera "LineageOS camera property" +assert_equal "$(cat "$MOCK_STATE_DIR/ro.boot.vbmeta.avb_version")" 1.0 "missing vbmeta property" +assert_equal "$(cat "$MOCK_STATE_DIR/setprop-calls")" "ctl.stop vendor.lineage_health" "LineageOS service" +[ ! -e "$MOCK_STATE_DIR/init.svc.vendor.lineage_health" ] +if grep -Eq '^(-w|-c)( |$)' "$MOCK_STATE_DIR/calls"; then + echo "FAIL: property handler used incompatible resetprop options" >&2 + exit 1 +fi + +: > "$adb_dir/disable_vbmeta_digest_spoof" +printf '%s\n' DEF456 > "$adb_dir/boot_hash" +PATH="$tmpdir/mockbin:$PATH" RP_BIN="$bundled" sh "$tmpdir/prop.sh" 2>"$tmpdir/error" +assert_equal "$(cat "$MOCK_STATE_DIR/ro.boot.vbmeta.digest")" abc123 "boot hash spoof disabled" +[ ! -s "$tmpdir/error" ] + +: > "$adb_dir/disable_prop_handler" +: > "$MOCK_STATE_DIR/calls" +PATH="$tmpdir/mockbin:$PATH" RP_BIN="$bundled" sh "$tmpdir/prop.sh" 2>"$tmpdir/error" +[ ! -s "$MOCK_STATE_DIR/calls" ] +[ ! -s "$tmpdir/error" ] + +echo "Property handler tests passed" diff --git a/tests/service-prop-handler.sh b/tests/service-prop-handler.sh new file mode 100644 index 0000000..c7d687d --- /dev/null +++ b/tests/service-prop-handler.sh @@ -0,0 +1,124 @@ +#!/bin/sh +set -eu + +repo_dir=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) +tmpdir=$(mktemp -d) +trap 'rm -rf "$tmpdir"' EXIT HUP INT TERM +mockbin="$tmpdir/mockbin" +mkdir -p "$mockbin" + +cat > "$mockbin/resetprop" <<'EOF' +#!/bin/sh +set -eu +printf '%s\n' "$*" >> "$MOCK_STATE_DIR/calls" +case "$1" in + -n) + if [ "${MOCK_IGNORE_PROP:-}" != "$2" ]; then + printf '%s' "$3" > "$MOCK_STATE_DIR/$2" + fi + ;; + -d) rm -f "$MOCK_STATE_DIR/$2" ;; + *) [ ! -f "$MOCK_STATE_DIR/$1" ] || cat "$MOCK_STATE_DIR/$1" ;; +esac +EOF +cat > "$mockbin/getprop" <<'EOF' +#!/bin/sh +if [ "$1" = sys.boot_completed ]; then + printf '0\n' +elif [ -f "$MOCK_STATE_DIR/$1" ]; then + cat "$MOCK_STATE_DIR/$1" +fi +EOF +cat > "$mockbin/cp" <<'EOF' +#!/bin/sh +if [ "${MOCK_FAIL_HIDE:-0}" = 1 ] && [ "$1" = -af ]; then + exit 1 +fi +exec /bin/cp "$@" +EOF +for command in busybox log pm setprop timeout; do + printf '#!/bin/sh\nexit 0\n' > "$mockbin/$command" +done +chmod +x "$mockbin/"* + +run_case() { + local case_name="$1" ksu="$2" fail_hide="$3" ignored_prop="${4:-}" + local case_dir="$tmpdir/$case_name" adb module state expected_prop_bin + adb="$case_dir/adb" + module="$adb/modules/TA_enhanced" + state="$case_dir/state" + mkdir -p "$module/common" "$module/bin/x86_64" "$adb/tricky_store" \ + "$adb/modules/tricky_store" "$adb/ksu/bin" "$state" + for file in service.sh prop.sh common/common.sh common/prop-handler.sh; do + sed "s|/data/adb|$adb|g; s|/storage/emulated/0|$case_dir/storage|g" \ + "$repo_dir/$file" > "$module/$file" + done + cp "$mockbin/resetprop" "$module/bin/x86_64/resetprop-rs" + printf '#!/bin/sh\nexit 0\n' > "$module/bin/x86_64/ta-enhanced" + chmod +x "$module/bin/x86_64/ta-enhanced" + printf 'id=TA_enhanced\n' > "$module/module.prop" + : > "$adb/tricky_store/keybox.xml" + : > "$state/calls" + printf '%s' orange > "$state/ro.boot.verifiedbootstate" + + if [ "$ksu" = true ]; then + cp "$mockbin/resetprop" "$adb/ksu/bin/resetprop" + expected_prop_bin="$adb/ksu/bin/resetprop" + else + : > "$module/action.sh" + if [ "$fail_hide" = 1 ]; then + expected_prop_bin="$module/bin/x86_64/resetprop-rs" + else + expected_prop_bin="$adb/modules/.TA_enhanced/bin/x86_64/resetprop-rs" + fi + fi + + PATH="$mockbin:$PATH" MOCK_STATE_DIR="$state" MOCK_FAIL_HIDE="$fail_hide" MOCK_IGNORE_PROP="$ignored_prop" \ + ARCH=x64 KSU="$ksu" APATCH="" sh "$module/service.sh" > "$case_dir/service-output" 2>&1 + + local attempt=0 + while [ "$attempt" -lt 100 ]; do + if grep -qx 'ro.boot.vbmeta.size' "$state/calls"; then + break + fi + attempt=$((attempt + 1)) + sleep 0.1 + done + if ! grep -qx 'ro.boot.vbmeta.size' "$state/calls"; then + printf 'FAIL: property handler did not finish in %s\n' "$case_name" >&2 + cat "$case_dir/service-output" >&2 + cat "$adb/tricky_store/ta-enhanced/logs/main.log" >&2 + exit 1 + fi + if [ -n "$ignored_prop" ]; then + [ "$(cat "$state/ro.boot.verifiedbootstate")" = orange ] + attempt=0 + while [ "$attempt" -lt 100 ]; do + if grep -Fq "Property $ignored_prop did not retain the requested value" "$adb/tricky_store/ta-enhanced/logs/main.log"; then + break + fi + attempt=$((attempt + 1)) + sleep 0.1 + done + grep -Fq "Property $ignored_prop did not retain the requested value" "$adb/tricky_store/ta-enhanced/logs/main.log" + else + [ "$(cat "$state/ro.boot.verifiedbootstate")" = green ] + fi + grep -Fq "Property handler using $expected_prop_bin" "$adb/tricky_store/ta-enhanced/logs/main.log" + + if [ "$ksu" != true ] && [ "$fail_hide" = 0 ]; then + [ ! -d "$module" ] + [ -f "$adb/modules/.TA_enhanced/common/prop-handler.sh" ] + else + [ -d "$module" ] + fi + if [ "$fail_hide" = 1 ]; then + grep -Fq 'Module hiding copy failed, using original path' "$adb/tricky_store/ta-enhanced/logs/main.log" + fi +} + +run_case magisk-fallback false 0 +run_case magisk-copy-failure false 1 +run_case kernelsu-native true 0 +run_case kernelsu-write-failure true 0 ro.boot.verifiedbootstate +echo "Service property handler tests passed" From 679adf9f9d84d95dd9dc83ef8aaaf8ac0d81fba3 Mon Sep 17 00:00:00 2001 From: ugurcan Date: Sat, 7 Nov 2026 01:30:17 +0300 Subject: [PATCH 2/2] Refactor script checks into a loop Refactored script checks into a loop for better maintainability. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .github/workflows/build.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 53a4280..947c04f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,8 +30,10 @@ jobs: - uses: actions/checkout@v4 - name: Test property handler run: | - sh -n prop.sh service.sh common/prop-handler.sh - sh -n tests/prop-handler.sh tests/service-prop-handler.sh tests/package-contents.sh + for script in prop.sh service.sh common/prop-handler.sh \ + tests/prop-handler.sh tests/service-prop-handler.sh tests/package-contents.sh; do + sh -n "$script" || exit 1 + done bash -n package.sh sh tests/prop-handler.sh sh tests/service-prop-handler.sh