From b338a1ff1a98663992850201eb6bb23b6024609c Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 23 Mar 2026 14:26:18 +0800 Subject: [PATCH] chore: lock android debugging to honor device --- README.md | 10 ++++ scripts/android_honor_debug.sh | 101 +++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100755 scripts/android_honor_debug.sh diff --git a/README.md b/README.md index c682ade..9826f88 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,16 @@ cd android-app android-app/app/build/outputs/apk/debug/app-debug.apk ``` +如果你后面要只用那台荣耀无线调试手机来联调,仓库里已经有固定目标脚本: + +```bash +./scripts/android_honor_debug.sh build-install +./scripts/android_honor_debug.sh launch +./scripts/android_honor_debug.sh screenshot +``` + +这个脚本默认只会操作当前锁定的荣耀设备,不会去碰别的安卓手机。需要切换目标时,再通过 `BOSS_ANDROID_SERIAL` 显式覆盖。 + 安卓端当前包含: - 会话创建、切换、持续对话 diff --git a/scripts/android_honor_debug.sh b/scripts/android_honor_debug.sh new file mode 100755 index 0000000..4f58965 --- /dev/null +++ b/scripts/android_honor_debug.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +DEFAULT_SERIAL="adb-A9TU024628000647-B0UNif._adb-tls-connect._tcp" +PACKAGE_NAME="site.hyzq.bossandroid" +APK_PATH="$ROOT_DIR/android-app/app/build/outputs/apk/debug/app-debug.apk" +TARGET_SERIAL="${BOSS_ANDROID_SERIAL:-$DEFAULT_SERIAL}" + +usage() { + cat < + +Commands: + serial Print the locked Honor device serial + status Show adb status for the Honor device + install Install the current debug APK on the Honor device + launch Launch the Boss app on the Honor device + build-install Build the debug APK and install it on the Honor device + screenshot Save a screenshot to /tmp/boss-honor-screen.png + logcat Tail logcat for the Boss app only + +Environment: + BOSS_ANDROID_SERIAL Override the locked device serial if needed + ANDROID_HOME Android SDK path for build-install + ANDROID_SDK_ROOT Android SDK path for build-install +EOF +} + +ensure_connected() { + local state + state="$(adb -s "$TARGET_SERIAL" get-state 2>/dev/null || true)" + if [[ "$state" != "device" ]]; then + echo "Honor debug device is not connected: $TARGET_SERIAL" >&2 + exit 1 + fi +} + +ensure_apk() { + if [[ ! -f "$APK_PATH" ]]; then + echo "APK not found: $APK_PATH" >&2 + echo "Run './scripts/android_honor_debug.sh build-install' or build the app first." >&2 + exit 1 + fi +} + +build_debug_apk() { + ( + cd "$ROOT_DIR/android-app" + ./gradlew assembleDebug + ) +} + +command="${1:-}" + +case "$command" in + serial) + echo "$TARGET_SERIAL" + ;; + status) + ensure_connected + echo "Serial: $TARGET_SERIAL" + echo "State: $(adb -s "$TARGET_SERIAL" get-state)" + adb -s "$TARGET_SERIAL" shell getprop ro.product.brand + adb -s "$TARGET_SERIAL" shell getprop ro.product.model + ;; + install) + ensure_connected + ensure_apk + adb -s "$TARGET_SERIAL" install -r "$APK_PATH" + ;; + launch) + ensure_connected + adb -s "$TARGET_SERIAL" shell monkey -p "$PACKAGE_NAME" -c android.intent.category.LAUNCHER 1 + ;; + build-install) + ensure_connected + build_debug_apk + adb -s "$TARGET_SERIAL" install -r "$APK_PATH" + adb -s "$TARGET_SERIAL" shell monkey -p "$PACKAGE_NAME" -c android.intent.category.LAUNCHER 1 + ;; + screenshot) + ensure_connected + adb -s "$TARGET_SERIAL" shell screencap -p /sdcard/boss-honor-screen.png >/dev/null + adb -s "$TARGET_SERIAL" pull /sdcard/boss-honor-screen.png /tmp/boss-honor-screen.png >/dev/null + adb -s "$TARGET_SERIAL" shell rm -f /sdcard/boss-honor-screen.png >/dev/null + echo "/tmp/boss-honor-screen.png" + ;; + logcat) + ensure_connected + adb -s "$TARGET_SERIAL" logcat --pid="$(adb -s "$TARGET_SERIAL" shell pidof "$PACKAGE_NAME")" + ;; + ""|-h|--help|help) + usage + ;; + *) + echo "Unknown command: $command" >&2 + usage >&2 + exit 1 + ;; +esac