#!/bin/bash
# Start the emulator headless (no window) — run this first, then use deploy.sh
export ANDROID_HOME=~/android-sdk
export PATH="$ANDROID_HOME/emulator:$ANDROID_HOME/platform-tools:$PATH"

echo "Starting emulator (headless)..."
emulator -avd claude_test -no-window -no-audio -no-snapshot -gpu swiftshader_indirect &
EMU_PID=$!
echo "Emulator PID: $EMU_PID"

echo "Waiting for device to be ready..."
adb wait-for-device
adb shell getprop sys.boot_completed | grep -q 1 || \
  timeout 120 bash -c 'until adb shell getprop sys.boot_completed 2>/dev/null | grep -q 1; do sleep 3; done'
echo "Emulator ready!"
