diff options
| -rwxr-xr-x | deck-it | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -64,11 +64,14 @@ alive() { wifi_connect() { local addr - # An existing TCP connection first: mDNS is not always advertising. - for addr in $(adb devices | awk 'NR > 1 && $2 == "device" && $1 ~ /:/ {print $1}'); do + # An explicit address, or the last one used. Never "any TCP device": a TV + # or another device with ADB on the network would be picked instead. + for addr in ${WIFI_ADDR:-} $(cat "$RUN/serial" 2>/dev/null); do + [ -n "$addr" ] || continue + timeout 5 adb connect "$addr" 2>/dev/null | grep -q '^connected\|already connected' || true alive "$addr" && { echo "$addr"; return 0; } done - for addr in $(adb mdns services | awk '/_adb-tls-connect/ {print $NF}' | sort -u); do + for addr in $(adb mdns services 2>/dev/null | awk '/_adb-tls-connect/ {print $NF}' | sort -u); do timeout 5 adb connect "$addr" 2>/dev/null | grep -q '^connected\|already connected' && alive "$addr" && { echo "$addr"; return 0; } done @@ -90,6 +93,13 @@ teardown) exit 0 ;; pair) + if ! adb mdns services >/dev/null 2>&1; then + echo "This adb has no mDNS discovery. Pair from the tablet instead:" + echo " Developer options > Wireless debugging > Pair device with pairing code" + echo " adb pair <ip>:<pair-port> <code>" + echo " adb connect <ip>:<connect-port>" + exit 1 + fi command -v qrencode >/dev/null || { echo "Install qrencode first"; exit 1; } name="deck-it-$(tr -dc a-z0-9 </dev/urandom | head -c 8)" pass=$(tr -dc 0-9 </dev/urandom | head -c 8) @@ -151,6 +161,7 @@ watch-usb) done ;; wifi) + if [[ "${2:-}" == *:* ]]; then WIFI_ADDR="$2"; fi echo "Looking for the tablet on Wi-Fi..." while :; do [[ "${2:-}" == --wait ]] && usb_present && { echo "Tablet is on USB, leaving it to the USB start"; exit 0; } |
