diff --git a/shells/tv.sh b/shells/tv.sh index 9871e29..37ccd3c 100644 --- a/shells/tv.sh +++ b/shells/tv.sh @@ -77,46 +77,93 @@ is_valid_ip() { connect_adb() { adb disconnect >/dev/null 2>&1 history_file="/tvhelper/shells/history" + + # 读取历史IP if [[ -f "$history_file" ]]; then last_ip=$(tail -n 1 "$history_file") last_name=$(head -n 1 "$history_file") - # 检查历史中的IP地址是否合法 if is_valid_ip "$last_ip"; then - echo -e "上次连接的设备是 ${GREEN}${last_name}${NC}IP地址为 ${GREEN}${last_ip}${NC}\n您是否要再次连接到此设备?确认请直接回车,否定输入n再回车[Y/n]" + echo -e "上次连接的设备是 ${GREEN}${last_name}${NC} IP=${GREEN}${last_ip}${NC}\n是否使用该设备? 回车确认, 输入n更换 [Y/n]" read answer if [[ "$answer" == "N" || "$answer" == "n" ]]; then - echo -e "${YELLOW}请手动输入电视盒子的完整IP地址:${NC}" + echo -e "${YELLOW}请输入设备的IP地址:${NC}" read ip else ip=$last_ip fi else - echo -e "${RED}历史记录中的IP地址不合法,请手动输入电视盒子的完整IP地址:${NC}" + echo -e "${RED}历史记录中的IP不合法,请重新输入:${NC}" read ip fi else - echo -e "${YELLOW}请手动输入电视盒子的完整IP地址:${NC}" + echo -e "${YELLOW}请输入设备的IP地址:${NC}" read ip fi - echo -e "${BLUE}首次使用,盒子上可能会提示授权弹框,给您半分钟时间来操作...【允许】${NC}" - adb connect ${ip} + # 输入安卓版本 + echo -e "${YELLOW}您的设备是否是2020款Googel TV (2+8G) ?(输入 y 表示是,其它直接回车表示否) [y/N]:${NC}" + read answer + if [[ "$answer" == "y" || "$answer" == "Y" ]]; then + android_ver=14 + else + android_ver=13 + fi - for ((i = 1; i <= 30; i++)); do - echo -e "${YELLOW}第${i}次尝试连接ADB,请在设备上点击【允许】按钮...${NC}" - device_status=$(adb devices | grep "${ip}:5555" | awk '{print $2}') - if [[ "$device_status" == "device" ]]; then - echo -e "${GREEN}ADB 已经连接成功啦,你可以放心操作了${NC}" - # 连接成功后,写入名称和IP地址到历史文件 - echo "$(get_history_name)" >"$history_file" - echo "${ip}" >>"$history_file" - return 0 + if [[ "$android_ver" -ge 14 ]]; then + # ---------- 安卓14配对流程 ---------- + echo -e "${YELLOW}请点击【使用配对码配对设备】出现与设备配对的页面${NC}" + echo -e "${YELLOW}请输入该页面显示的配对端口号 通常是冒号后的5位 (例如 35295):${NC}" + read pair_port + + echo -e "${BLUE}正在配对设备,请按要求输入WLAN配对码 通常是6位${NC}" + adb pair "${ip}:${pair_port}" + + if [[ $? -ne 0 ]]; then + echo -e "${RED}配对失败,请检查配对端口/配对码是否正确${NC}" + return 1 fi - sleep 1 - done - echo -e "${RED}连接超时,或者您点击了【取消】,请确认电视盒子的IP地址是否正确。如果问题持续存在,请检查设备的USB调试设置是否正确并重新连接adb${NC}" + echo -e "${GREEN}配对并且连接成功!请返回上一页查看用于debug的端口号${NC}" + echo -e "${YELLOW}请输入设备显示的debug【调试端口号】:(通常位于无线调试这一页)${NC}" + read debug_port + adb connect "${ip}:${debug_port}" + for ((i = 1; i <= 30; i++)); do + device_status=$(adb devices | grep "${debug_port}" | awk '{print $2}') + if [[ "$device_status" == "device" ]]; then + echo -e "${GREEN}ADB 已成功连接到设备 ${debug_port}${NC}" + echo "$(get_history_name)" >"$history_file" + echo "${ip}" >>"$history_file" # 只保存IP,不保存端口 + return 0 + fi + echo -e "${YELLOW}第${i}次尝试连接,请在设备上点击【允许】...${NC}" + sleep 1 + done + else + # ---------- 安卓13及以下 ---------- + echo -e "${YELLOW}请输入端口号 [回车默认5555]:${NC}" + read port + port=${port:-5555} + ip_port="${ip}:${port}" + adb connect "${ip_port}" + + # ---------- 检查连接状态 ---------- + for ((i = 1; i <= 30; i++)); do + device_status=$(adb devices | grep "${ip_port}" | awk '{print $2}') + if [[ "$device_status" == "device" ]]; then + echo -e "${GREEN}ADB 已成功连接到设备 ${ip_port}${NC}" + echo "$(get_history_name)" >"$history_file" + echo "${ip}" >>"$history_file" # 只保存IP,不保存端口 + return 0 + fi + echo -e "${YELLOW}第${i}次尝试连接,请在设备上点击【允许】...${NC}" + sleep 1 + done + + echo -e "${RED}连接超时或失败,请确认IP/端口/配对码是否正确${NC}" + fi } + + # 一键修改NTP服务器地址 modify_ntp() { echo -e "${BLUE}它的作用在于:解决安卓原生TV时间不正确和网络受限问题${NC}"