parent
645fbc276a
commit
2849b32d1e
|
|
@ -11,3 +11,18 @@ warn_red() { printf "${RED}${BOLD}[iiab] WARNING:${RST} %s\n" "$*" >&2; }
|
||||||
have() { command -v "$1" >/dev/null 2>&1; }
|
have() { command -v "$1" >/dev/null 2>&1; }
|
||||||
need() { have "$1" || return 1; }
|
need() { have "$1" || return 1; }
|
||||||
die() { echo "[!] $*" >&2; exit 1; }
|
die() { echo "[!] $*" >&2; exit 1; }
|
||||||
|
|
||||||
|
# -------------------------
|
||||||
|
# Global defaults (may be overridden via environment)
|
||||||
|
# -------------------------
|
||||||
|
STATE_DIR="${STATE_DIR:-${HOME}/.iiab-android}"
|
||||||
|
ADB_STATE_DIR="${ADB_STATE_DIR:-${STATE_DIR}/adbw_pair}"
|
||||||
|
LOG_DIR="${LOG_DIR:-${STATE_DIR}/logs}"
|
||||||
|
|
||||||
|
HOST="${HOST:-127.0.0.1}"
|
||||||
|
CONNECT_PORT="${CONNECT_PORT:-}"
|
||||||
|
TIMEOUT_SECS="${TIMEOUT_SECS:-180}"
|
||||||
|
|
||||||
|
# Defaults used by ADB flows / logging / misc
|
||||||
|
CLEANUP_OFFLINE="${CLEANUP_OFFLINE:-1}"
|
||||||
|
DEBUG="${DEBUG:-0}"
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,8 @@ LAST_NOTIF_ID=""
|
||||||
# Termux:API sanity check (notifications)
|
# Termux:API sanity check (notifications)
|
||||||
termux_api_ready() {
|
termux_api_ready() {
|
||||||
have termux-notification || return 1
|
have termux-notification || return 1
|
||||||
have termux-dialog || return 1
|
|
||||||
|
|
||||||
# Quick probe: some Samsung setups fail until Termux:API app is installed/allowed.
|
# Quick probe: some setups fail until Termux:API app is installed/allowed.
|
||||||
# We try a harmless notification and remove it.
|
|
||||||
local msg="iiab test notification"
|
local msg="iiab test notification"
|
||||||
if ! termux-notification --id "$NOTIF_BASE_ID" --title "iiab" --content "$msg" --priority max --sound >/dev/null 2>&1; then
|
if ! termux-notification --id "$NOTIF_BASE_ID" --title "iiab" --content "$msg" --priority max --sound >/dev/null 2>&1; then
|
||||||
return 1
|
return 1
|
||||||
|
|
@ -47,9 +45,8 @@ cleanup_notif() {
|
||||||
notify_ask_one() {
|
notify_ask_one() {
|
||||||
# args: key title content
|
# args: key title content
|
||||||
local key="$1" title="$2" content="$3"
|
local key="$1" title="$2" content="$3"
|
||||||
local out="$ADB_STATE_DIR/$key.txt"
|
local out="$ADB_STATE_DIR/$key.reply"
|
||||||
rm -f "$out"
|
rm -f "$out"
|
||||||
local action
|
|
||||||
|
|
||||||
# Fresh notification each time + sound (use a new ID so Android plays sound each time)
|
# Fresh notification each time + sound (use a new ID so Android plays sound each time)
|
||||||
local nid
|
local nid
|
||||||
|
|
@ -61,13 +58,10 @@ notify_ask_one() {
|
||||||
termux-notification-remove "$nid" >/dev/null 2>&1 || true
|
termux-notification-remove "$nid" >/dev/null 2>&1 || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# termux-notification does not provide a reply input; use termux-dialog to capture text.
|
# Direct reply: Termux:API injects the user input into $REPLY for the action.
|
||||||
if ! have termux-dialog; then
|
# Write it to a known file, then the main loop reads it.
|
||||||
warn "termux-dialog not available. Install: pkg install termux-api + Termux:API app."
|
local action
|
||||||
return 1
|
action="sh -lc 'umask 077; printf \"%s\" \"\$REPLY\" > \"${out}\"'"
|
||||||
fi
|
|
||||||
|
|
||||||
action="sh -lc 'termux-dialog -i -t \"${title}\" -h \"${content}\" | tr -d \"\\n\" | sed -n \"s/.*\\\"text\\\"[[:space:]]*:[[:space:]]*\\\"\\([^\\\"]*\\)\\\".*/\\1/p\" > \"${out}\"'"
|
|
||||||
|
|
||||||
termux-notification \
|
termux-notification \
|
||||||
--id "$nid" \
|
--id "$nid" \
|
||||||
|
|
@ -80,16 +74,20 @@ notify_ask_one() {
|
||||||
--button1-action "$action" \
|
--button1-action "$action" \
|
||||||
|| return 1
|
|| return 1
|
||||||
|
|
||||||
local start now
|
local start now reply
|
||||||
start="$(date +%s)"
|
start="$(date +%s)"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
if [[ -f "$out" ]]; then
|
if [[ -f "$out" ]]; then
|
||||||
|
reply="$(tr -d '\r\n' < "$out" 2>/dev/null || true)"
|
||||||
|
rm -f "$out" >/dev/null 2>&1 || true
|
||||||
if have termux-notification-remove; then
|
if have termux-notification-remove; then
|
||||||
termux-notification-remove "$nid" >/dev/null 2>&1 || true
|
termux-notification-remove "$nid" >/dev/null 2>&1 || true
|
||||||
fi
|
fi
|
||||||
tr -d '\r\n' < "$out"
|
printf '%s' "$reply"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
now="$(date +%s)"
|
now="$(date +%s)"
|
||||||
if (( now - start >= TIMEOUT_SECS )); then
|
if (( now - start >= TIMEOUT_SECS )); then
|
||||||
if have termux-notification-remove; then
|
if have termux-notification-remove; then
|
||||||
|
|
|
||||||
|
|
@ -138,3 +138,52 @@ check_readiness() {
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self_check_android_flags() {
|
||||||
|
have adb || return 0
|
||||||
|
adb start-server >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
local serial sdk rel mon mon_fflag ds ppk_eff
|
||||||
|
serial="$(adb_pick_loopback_serial 2>/dev/null)" || {
|
||||||
|
warn "ADB: no loopback device connected. Tip: run --adb-only (pair+connect) or --check for more info."
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
sdk="$(adb -s "$serial" shell getprop ro.build.version.sdk 2>/dev/null | tr -d '\r' || true)"
|
||||||
|
rel="$(adb -s "$serial" shell getprop ro.build.version.release 2>/dev/null | tr -d '\r' || true)"
|
||||||
|
log " Android flags (quick): release=${rel:-?} sdk=${sdk:-?} serial=$serial"
|
||||||
|
|
||||||
|
if [[ "$sdk" =~ ^[0-9]+$ ]] && (( sdk >= 34 )); then
|
||||||
|
mon_fflag="$(adb_get_child_restrictions_flag "$serial")"
|
||||||
|
if [[ "$mon_fflag" == "true" || "$mon_fflag" == "false" ]]; then
|
||||||
|
mon="$mon_fflag"
|
||||||
|
else
|
||||||
|
mon="$(adb -s "$serial" shell settings get global settings_enable_monitor_phantom_procs 2>/dev/null | tr -d '\r' || true)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$mon" == "false" ]]; then
|
||||||
|
ok " Child restrictions: OK (monitor=false)"
|
||||||
|
elif [[ "$mon" == "true" ]]; then
|
||||||
|
warn " Child restrictions: NOT OK (monitor=true) -> check Developer Options"
|
||||||
|
else
|
||||||
|
warn " Child restrictions: unknown/unreadable (monitor='${mon:-}')"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$sdk" =~ ^[0-9]+$ ]] && (( sdk >= 31 && sdk <= 33 )); then
|
||||||
|
ds="$(adb -s "$serial" shell dumpsys activity settings 2>/dev/null | tr -d '\r' || true)"
|
||||||
|
ppk_eff="$(printf '%s\n' "$ds" | awk -F= '/max_phantom_processes=/{print $2; exit}' | tr -d '[:space:]' || true)"
|
||||||
|
|
||||||
|
if [[ "$ppk_eff" =~ ^[0-9]+$ ]]; then
|
||||||
|
if (( ppk_eff >= 256 )); then
|
||||||
|
ok " PPK: OK (max_phantom_processes=$ppk_eff)"
|
||||||
|
else
|
||||||
|
warn " PPK: low (max_phantom_processes=$ppk_eff) -> suggest: --ppk-only"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
warn " PPK: unreadable (max_phantom_processes='${ppk_eff:-}')"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
log " Tip: run --check for full details."
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,10 @@
|
||||||
# -------------------------
|
# -------------------------
|
||||||
# Defaults
|
# Defaults
|
||||||
# -------------------------
|
# -------------------------
|
||||||
STATE_DIR="${HOME}/.iiab-android"
|
# NOTE: Core defaults live in 00_lib_common.sh to guarantee availability for all modules.
|
||||||
ADB_STATE_DIR="${STATE_DIR}/adbw_pair"
|
|
||||||
LOG_DIR="${STATE_DIR}/logs"
|
|
||||||
mkdir -p "$STATE_DIR" "$ADB_STATE_DIR"
|
|
||||||
|
|
||||||
HOST="127.0.0.1"
|
# Ensure state directories exist (safe even if user overrides via environment).
|
||||||
CONNECT_PORT=""
|
mkdir -p "$STATE_DIR" "$ADB_STATE_DIR" "$LOG_DIR" 2>/dev/null || true
|
||||||
TIMEOUT_SECS=180
|
|
||||||
CLEANUP_OFFLINE=1
|
|
||||||
DEBUG=0
|
|
||||||
|
|
||||||
RESET_DEBIAN=0
|
RESET_DEBIAN=0
|
||||||
ONLY_CONNECT=0
|
ONLY_CONNECT=0
|
||||||
|
|
@ -105,6 +99,8 @@ self_check() {
|
||||||
else
|
else
|
||||||
warn " adb: not present"
|
warn " adb: not present"
|
||||||
fi
|
fi
|
||||||
|
# Quick Android flags check (best-effort; no prompts)
|
||||||
|
self_check_android_flags || true
|
||||||
|
|
||||||
if have termux-wake-lock; then ok " Termux:API wakelock: available"; else warn " Termux:API wakelock: not available"; fi
|
if have termux-wake-lock; then ok " Termux:API wakelock: available"; else warn " Termux:API wakelock: not available"; fi
|
||||||
if have termux-notification; then ok " Termux:API notifications: command present"; else warn " Termux:API notifications: missing"; fi
|
if have termux-notification; then ok " Termux:API notifications: command present"; else warn " Termux:API notifications: missing"; fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue