-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick-start-android.sh
More file actions
86 lines (71 loc) · 2.88 KB
/
quick-start-android.sh
File metadata and controls
86 lines (71 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ---- Configuration ----
AVD_NAME="proxy-emulator"
API_LEVEL=36
ABI="arm64-v8a" # For Apple Silicon (M1/M2/M3/M4)
# ABI="x86_64" # For Intel-based machines or CI/CD (e.g. Bitrise Linux)
SYSTEM_IMAGE="system-images;android-${API_LEVEL};google_apis;${ABI}"
DEVICE_PROFILE="pixel_7_pro"
# ------------------------
echo "[!] WARNING: This script has not been fully tested and may require minor modifications to work on your machine."
echo ""
echo "[*] Quick Start: Android Proxy Setup"
echo "============================================"
# Check if the emulator is already running
EMULATOR=$(adb devices 2>/dev/null | awk '/^emulator-.*device$/{print $1; exit}')
if [ -z "$EMULATOR" ]; then
echo "[*] No running emulator detected. Setting up '$AVD_NAME'..."
# Install the system image if not present
if ! sdkmanager --list_installed 2>/dev/null | grep -q "$SYSTEM_IMAGE"; then
echo "[*] Installing system image: $SYSTEM_IMAGE"
sdkmanager "$SYSTEM_IMAGE"
fi
# Create the AVD if it doesn't exist
if ! avdmanager list avd -c 2>/dev/null | grep -q "^${AVD_NAME}$"; then
echo "[*] Creating AVD: $AVD_NAME (API $API_LEVEL, $ABI, $DEVICE_PROFILE)"
echo "no" | avdmanager create avd \
--name "$AVD_NAME" \
--package "$SYSTEM_IMAGE" \
--device "$DEVICE_PROFILE" \
--force
fi
# Launch the emulator
echo "[*] Launching emulator '$AVD_NAME'..."
emulator -avd "$AVD_NAME" -writable-system -no-snapshot-save -no-audio -gpu auto &
EMULATOR_PID=$!
echo "[*] Waiting for emulator to boot..."
adb wait-for-device
# Wait until the boot animation has finished
while [ "$(adb shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" != "1" ]; do
sleep 2
done
echo "[✓] Emulator booted"
EMULATOR=$(adb devices 2>/dev/null | awk '/^emulator-.*device$/{print $1; exit}')
else
echo "[✓] Emulator already running: $EMULATOR"
fi
# Start mitmproxy in the background
echo "[*] Starting mitmproxy..."
mitmdump -p 8080 -s "$SCRIPT_DIR/session-recording-controller.py" --ssl-insecure &
MITM_PID=$!
sleep 2
# Verify mitmproxy started
if ! kill -0 "$MITM_PID" 2>/dev/null; then
echo "[x] mitmproxy failed to start. Is port 8080 already in use?"
exit 1
fi
echo "[✓] mitmproxy running (PID: $MITM_PID)"
# Install certs and configure proxy on emulator
echo "[*] Installing certificates and configuring proxy on emulator..."
bash "$SCRIPT_DIR/android-cert-install.sh"
echo ""
echo "============================================"
echo "[✓] Android proxy setup complete!"
echo " Emulator: $EMULATOR"
echo " mitmproxy PID: $MITM_PID"
echo " Control server: http://localhost:9999"
echo ""
echo " To stop: kill $MITM_PID"
echo "============================================"