mirror of
git://f0xx.org/android_cast
synced 2026-07-29 04:18:09 +03:00
test adb reconnect persistence
This commit is contained in:
96
rebuild.sh
96
rebuild.sh
@@ -1,63 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
# Rebuild debug APK, run unit tests, reconnect known wireless adb targets, install, relaunch.
|
||||
# Rebuild debug APK, run unit tests, reconnect wireless adb targets, install, relaunch.
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
RECONNECT_KNOWN_DEVICES=${RECONNECT_KNOWN_DEVICES:-no}
|
||||
RECONNECT_KNOWN_DEVICES=${RECONNECT_KNOWN_DEVICES:-yes}
|
||||
|
||||
# Hints for wireless debugging. Edit as needed.
|
||||
## CONNECTIONS_LIST_HINTS[IP_WITH_UNDERLINES]="hint string"
|
||||
declare -A CONNECTIONS_LIST_HINTS
|
||||
## android tv projector / android 13
|
||||
CONNECTIONS_LIST_HINTS["192_168_33_153"]="[A13] Android Projector"
|
||||
## tab g6 max / android 16
|
||||
CONNECTIONS_LIST_HINTS["192_168_33_39"]="[A16] Doogee Tab G6 Max / P8_EEA"
|
||||
## bl6000pro main / android 11
|
||||
CONNECTIONS_LIST_HINTS["192_168_33_106"]="[A11] BlackView BL6000Pro / BL6000Pro_EEA"
|
||||
## bl6000pro aux / android 11
|
||||
CONNECTIONS_LIST_HINTS["192_168_33_173"]="[A11] BlackView BL6000Pro / BL6000Pro"
|
||||
|
||||
get_ip_for_hint_key() {
|
||||
local ip=${1}
|
||||
ip="$(echo "${ip}" | sed -e s'@_@\.@g' -e s'@:.*@@' | tr -d '\n' )"
|
||||
printf "%s" "${ip}"
|
||||
}
|
||||
|
||||
get_hint_key_for_ip() {
|
||||
local ip=${1}
|
||||
ip="$(echo "${ip}" | sed -e s'@\.@_@g' -e s'@:.*@@' | tr -d '\n' )"
|
||||
printf "%s" "${ip}"
|
||||
}
|
||||
|
||||
get_hint() {
|
||||
local ip_mask="${1}"
|
||||
local -n hint
|
||||
ip_mask="$(get_hint_key_for_ip "${ip_mask}")"
|
||||
hint=CONNECTIONS_LIST_HINTS[${ip_mask}]
|
||||
printf "%s" "${hint}"
|
||||
}
|
||||
# shellcheck source=scripts/adb-reconnect.sh
|
||||
source "$ROOT/scripts/adb-reconnect.sh"
|
||||
adb_reconnect_init_hints
|
||||
|
||||
APK="$ROOT/app/build/outputs/apk/debug/app-debug.apk"
|
||||
PACKAGE="com.foxx.androidcast"
|
||||
LAUNCHER="$PACKAGE/.MainActivity"
|
||||
|
||||
RUN_UNIT_TESTS="${RUN_UNIT_TESTS:-1}"
|
||||
ADB_CONNECT_RETRIES="${ADB_CONNECT_RETRIES:-4}"
|
||||
ADB_CONNECT_DELAY_SEC="${ADB_CONNECT_DELAY_SEC:-2}"
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--skip-tests) RUN_UNIT_TESTS=0 ;;
|
||||
--no-tests) RUN_UNIT_TESTS=0 ;;
|
||||
--no-reconnect) RECONNECT_KNOWN_DEVICES=no ;;
|
||||
--java-home=*)
|
||||
ANDROID_CAST_JAVA_HOME="${arg#--java-home=}"
|
||||
;;
|
||||
-h|--help)
|
||||
echo "Usage: $0 [--skip-tests] [--java-home=PATH]"
|
||||
echo " Builds debug APK, runs unit tests (unless skipped), reconnects devices in CONNECTIONS_LIST_HINTS,"
|
||||
echo " installs on all adb devices in 'device' state, and launches the app."
|
||||
echo "Usage: $0 [--skip-tests] [--no-reconnect] [--java-home=PATH]"
|
||||
echo " Builds debug APK, runs unit tests (unless skipped), reconnects adb (mdns + HTTP"
|
||||
echo " :5039/adb.json + known IPs), installs on all adb devices, and launches the app."
|
||||
echo " Env: RECONNECT_KNOWN_DEVICES=yes|no (default yes), DEV_ADB_HTTP_PORT=5039"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
@@ -98,42 +70,6 @@ if ! picked="$(pick_java_home)"; then
|
||||
fi
|
||||
export JAVA_HOME="$picked"
|
||||
|
||||
reconnect_endpoint() {
|
||||
local endpoint="$1"
|
||||
[[ -z "$endpoint" ]] && return 1
|
||||
local attempt out
|
||||
local hint=""
|
||||
hint="$(get_hint "${endpoint}")"
|
||||
[[ -n "${hint}" ]] && hint="(having hint: ${hint})"
|
||||
echo " trying to connect to $endpoint ${hint}"
|
||||
adb disconnect "$endpoint" >/dev/null 2>&1 || true
|
||||
for (( attempt = 1; attempt <= ADB_CONNECT_RETRIES; attempt++ )); do
|
||||
out="$(adb connect "$endpoint" 2>&1)" || true
|
||||
if grep -qiE 'connected|already' <<<"$out"; then
|
||||
if adb -s "$endpoint" get-state 2>/dev/null | grep -q '^device$'; then
|
||||
echo " $endpoint — ready"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
if [[ "$attempt" -lt "$ADB_CONNECT_RETRIES" ]]; then
|
||||
sleep "$ADB_CONNECT_DELAY_SEC"
|
||||
fi
|
||||
done
|
||||
echo " $endpoint — not reachable ($out)" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
reconnect_known_devices() {
|
||||
echo "==> Reconnecting known wireless adb endpoints"
|
||||
adb start-server >/dev/null 2>&1 || true
|
||||
adb reconnect offline >/dev/null 2>&1 || true
|
||||
local endpoint
|
||||
for endpoint in "${!CONNECTIONS_LIST_HINTS[@]}"; do
|
||||
reconnect_endpoint "$(get_ip_for_hint_key "$endpoint")" || true
|
||||
done
|
||||
adb devices -l
|
||||
}
|
||||
|
||||
# shellcheck source=scripts/android-ndk.sh
|
||||
source "$ROOT/scripts/android-ndk.sh"
|
||||
# shellcheck source=scripts/native-build-cache.sh
|
||||
@@ -187,15 +123,16 @@ if [[ ! -f "$APK" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "${RECONNECT_KNOWN_DEVICES}" =~ "[yY]*" ]]; then
|
||||
reconnect_known_devices
|
||||
if [[ "${RECONNECT_KNOWN_DEVICES}" =~ [yY] ]]; then
|
||||
adb_reconnect_all || true
|
||||
fi
|
||||
|
||||
mapfile -t DEVICES < <(adb devices | awk 'NR > 1 && $2 == "device" { print $1 }')
|
||||
|
||||
if [[ ${#DEVICES[@]} -eq 0 ]]; then
|
||||
echo "ERROR: No adb devices in 'device' state after reconnect." >&2
|
||||
echo " Wake devices, re-enable wireless debugging, or: adb connect HOST:5555" >&2
|
||||
echo " Enable dev setting “ADB over Wi‑Fi keeper”, grant WRITE_SECURE_SETTINGS once via USB," >&2
|
||||
echo " pair wireless debugging once, then retry. Or: curl http://DEVICE:5039/adb.json" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -205,6 +142,9 @@ for serial in "${DEVICES[@]}"; do
|
||||
echo "--- $serial"
|
||||
if adb -s "$serial" install -r "$APK"; then
|
||||
echo " Installed"
|
||||
adb -s "$serial" shell am broadcast \
|
||||
-a com.foxx.androidcast.dev.REFRESH_ADB_WIFI \
|
||||
-n com.foxx.androidcast/.dev.DevAdbWifiReceiver >/dev/null 2>&1 || true
|
||||
if adb -s "$serial" shell am start -n "$LAUNCHER" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER; then
|
||||
echo " Launched $LAUNCHER"
|
||||
else
|
||||
@@ -216,6 +156,8 @@ for serial in "${DEVICES[@]}"; do
|
||||
fi
|
||||
done
|
||||
|
||||
adb_update_connect_cache
|
||||
|
||||
if [[ $FAILED -gt 0 ]]; then
|
||||
echo "Done with $FAILED failure(s)." >&2
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user