chore: lock android debugging to honor device

This commit is contained in:
Codex
2026-03-23 14:26:18 +08:00
parent 0453c1b8ce
commit b338a1ff1a
2 changed files with 111 additions and 0 deletions

View File

@@ -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` 显式覆盖。
安卓端当前包含:
- 会话创建、切换、持续对话

101
scripts/android_honor_debug.sh Executable file
View File

@@ -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 <<EOF
Usage: ./scripts/android_honor_debug.sh <command>
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