#!/usr/bin/env bash set -euo pipefail PROJECT_ROOT="/home/anthony/Documents/Projects/GameTime" ARTIFACT_BASE="${ARTIFACT_BASE:-$PROJECT_ROOT/.ideai/artifacts/qa-device}" PHONE_SERIAL="${PHONE_SERIAL:-}" PACKAGE_NAME="${PACKAGE_NAME:-com.idea.gametime}" usage() { cat <<'EOF' Usage: ./tool/qa_device_import_export_real.sh start ./tool/qa_device_import_export_real.sh stop Environment: PHONE_SERIAL Optional adb serial for the phone under test ARTIFACT_BASE Optional artifact root PACKAGE_NAME Optional Android package name (default: com.idea.gametime) EOF } adb_cmd() { if [[ -n "$PHONE_SERIAL" ]]; then adb -s "$PHONE_SERIAL" "$@" else adb "$@" fi } require_adb() { command -v adb >/dev/null 2>&1 || { echo "adb not found in PATH." >&2 exit 1 } adb start-server >/dev/null adb_cmd get-state >/dev/null 2>&1 || { echo "No adb device available. Connect the phone or set PHONE_SERIAL." >&2 exit 1 } } timestamp() { date -u +"%Y%m%dT%H%M%SZ" } start_capture() { require_adb local dir="$ARTIFACT_BASE/import-export-real-$(timestamp)" mkdir -p "$dir" adb devices -l >"$dir/adb-devices.txt" adb_cmd shell getprop ro.build.fingerprint >"$dir/phone-build-fingerprint.txt" adb_cmd shell dumpsys package "$PACKAGE_NAME" >"$dir/package-dumpsys-before.txt" || true adb_cmd logcat -c adb_cmd logcat -v threadtime >"$dir/logcat.txt" 2>&1 & echo "$!" >"$dir/logcat.pid" cat >"$dir/steps.md" <&2 exit 2 } require_adb [[ -d "$dir" ]] || { echo "Artifact directory not found: $dir" >&2 exit 1 } [[ -f "$dir/logcat.pid" ]] && kill "$(cat "$dir/logcat.pid")" >/dev/null 2>&1 || true adb_cmd shell dumpsys package "$PACKAGE_NAME" >"$dir/package-dumpsys-after.txt" || true cat <