102 lines
2.9 KiB
Bash
Executable File
102 lines
2.9 KiB
Bash
Executable File
#!/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
|