#!/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_health_connect.sh start ./tool/qa_device_health_connect.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/health-connect-$(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 & local pid=$! echo "$pid" >"$dir/logcat.pid" cat >"$dir/steps.md" < Intégrations > Health Connect. 3. Validate the visible initial status. 4. Tap "Autoriser l'accès" or "Gérer les autorisations". 5. Validate the expected path: - permission sheet opens, or - settings fallback opens cleanly. 6. Grant or deny permissions according to the scenario under test. 7. Return to GameTime and validate the refreshed status. 8. Start and finish a workout if export-after-workout must be checked. 9. Confirm the final Health Connect export outcome shown by the app. ## Evidence to collect - Screenshot(s) of the visible status before and after permission handling. - Screenshot(s) of Health Connect permission/settings UI if opened. - Notes on whether the path used the permission contract or settings fallback. - Result of export-after-workout if exercised. EOF echo "$dir" } stop_capture() { local dir="${1:-}" [[ -n "$dir" ]] || { usage >&2 exit 2 } require_adb [[ -d "$dir" ]] || { echo "Artifact directory not found: $dir" >&2 exit 1 } if [[ -f "$dir/logcat.pid" ]]; then kill "$(cat "$dir/logcat.pid")" >/dev/null 2>&1 || true fi adb_cmd shell dumpsys package "$PACKAGE_NAME" >"$dir/package-dumpsys-after.txt" || true adb_cmd shell settings list secure >"$dir/settings-secure.txt" || true cat <