main
John Lauer Publish 0.1.3 28b92ce
#!/bin/bash
# Install Adom Bridge Android on a USB-connected phone and switch on what it needs.
# Usage: install-on-phone.sh <adb command...>      e.g.  APK=adom-bridge-android-0.1.3.apk install-on-phone.sh adb
set -e
P=inc.adom.bridge.android

: "${APK:?Set APK to the path of the downloaded adom-bridge-android-<version>.apk}"
# adb here may be the Windows one, which cannot read WSL paths
[[ "$1" == *.exe || "$1" == *wadb* ]] && [[ "$APK" == /* ]] && APK="$(wslpath -w "$APK")"
[ "$("$@" get-state 2>/dev/null | tr -d '\r')" = device ] || { echo "ERROR: no authorised phone"; echo "Hint: turn on USB debugging and tap Allow on the phone"; exit 1; }
"$@" install -r -g "$APK"
s() { "$@" 2>&1 | tr -d '\r'; }
# Without this, Android refuses screen access to an app that did not come from a store.
s "$@" shell appops set $P ACCESS_RESTRICTED_SETTINGS allow
# Without this, Android 15+ hides one-time codes from the notification list.
s "$@" shell appops set $P RECEIVE_SENSITIVE_NOTIFICATIONS allow || true
CUR="$(s "$@" shell settings get secure enabled_accessibility_services)"
ME=$P/inc.adom.bridge.PhoneControl
case "$CUR" in null|"") NEW=$ME;; *$ME*) NEW="$CUR";; *) NEW="$CUR:$ME";; esac   # keep the owner's other services
s "$@" shell settings put secure enabled_accessibility_services "$NEW"
s "$@" shell settings put secure accessibility_enabled 1
s "$@" shell cmd notification allow_listener $P/inc.adom.bridge.Notifs
s "$@" shell dumpsys deviceidle whitelist +$P
s "$@" shell am start -n $P/inc.adom.bridge.MainActivity
echo "OK: installed. Sign in on the phone, then trust your machines."