| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/usr/bin/env bash
- set -euo pipefail
- SDK="${ANDROID_HOME:-/opt/android-sdk}"
- ADB="$SDK/platform-tools/adb"
- EMULATOR="$SDK/emulator/emulator"
- API="${1:-35}"
- GPU_MODE="${CARDASH_GPU:-host}"
- if [[ "$API" == "stop" ]]; then
- if "$ADB" devices | grep -q "emulator-"; then
- "$ADB" emu kill >/dev/null 2>&1 || true
- echo "Emulator stopped."
- else
- echo "No emulator is running."
- fi
- exit 0
- fi
- if [[ "$API" != "35" && "$API" != "29" ]]; then
- echo "Usage: $0 [35|29|stop] [window]" >&2
- exit 2
- fi
- AVD="cardash_tablet_api$API"
- if ! "$ADB" devices | grep -q "emulator-"; then
- args=(
- -avd "$AVD"
- -no-audio
- -no-boot-anim
- -gpu "$GPU_MODE"
- -no-snapshot
- -no-metrics
- -camera-back none
- -camera-front none
- )
- if [[ "${2:-}" != "window" ]]; then
- args+=(-no-window)
- fi
- echo "Booting $AVD (1280x800, landscape)…"
- nohup "$EMULATOR" "${args[@]}" > "/tmp/cardash-emulator-api$API.log" 2>&1 &
- else
- echo "An emulator is already running; reusing it."
- fi
- "$ADB" wait-for-device
- for _ in $(seq 1 90); do
- if [[ "$("$ADB" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" == "1" ]]; then
- echo "Boot completed: $("$ADB" shell wm size | tr -d '\r') @ $("$ADB" shell wm density | tr -d '\r')"
- exit 0
- fi
- sleep 2
- done
- echo "Emulator did not report boot_completed. See /tmp/cardash-emulator-api$API.log" >&2
- exit 1
|