// vivo 的跨应用打开确认只处理由应用宝发起的请求,按用户偏好选择“始终打开”。 var yibaoAppJumpBusy = false; function readYibaoAppJumpPage(root) { if (!root || String(root.getPackageName() || "") !== "com.vivo.appfilter") return null; var items = [], title = "", count = 0; function visit(node, depth) { if (!node || depth > 24 || ++count > 500) throw new Error("打开确认弹窗节点树不完整"); if (!node.isVisibleToUser()) return; var text = String(node.getText() || ""), desc = String(node.getContentDescription() || ""); var resourceId = String(node.getViewIdResourceName() || ""); if (resourceId === "com.vivo.appfilter:id/alertTitle") title = text; if (text || desc) { var rect = new android.graphics.Rect(); node.getBoundsInScreen(rect); items.push({text:text,desc:desc,enabled:Boolean(node.isEnabled()), bounds:{left:rect.left,top:rect.top,right:rect.right,bottom:rect.bottom}}); } for (var i = 0; i < node.getChildCount(); i += 1) visit(node.getChild(i), depth + 1); } visit(root, 0); return {packageName:"com.vivo.appfilter",title:title,items:items}; } function planYibaoAppJumpAction(page) { if (!page || page.packageName !== "com.vivo.appfilter" || !/^[“"「『]?应用宝[”"」』]?想要打开.+$/.test(normalizeText(page.title))) return null; var matches = (page.items || []).filter(function (item) { var b = item.bounds; return item.enabled !== false && (normalizeText(item.text) === "始终打开" || normalizeText(item.desc) === "始终打开") && b && b.left >= 0 && b.top >= 0 && b.right <= device.width && b.bottom <= device.height && b.right > b.left && b.bottom > b.top; }); // 同一个按钮的父控件描述与子控件文字可能重复,按中心位置合并。 var unique = []; matches.forEach(function (item) { var b = item.bounds; if (!unique.some(function (other) { var a = other.bounds; return Math.abs(a.left + a.right - b.left - b.right) < 8 && Math.abs(a.top + a.bottom - b.top - b.bottom) < 8; })) unique.push(item); }); return unique.length === 1 ? unique[0] : null; } function handleYibaoAppJumpPrompt(root) { if (yibaoAppJumpBusy || !root || String(root.getPackageName() || "") !== "com.vivo.appfilter") return false; yibaoAppJumpBusy = true; try { var page = readYibaoAppJumpPage(root), action = planYibaoAppJumpAction(page); if (!action) return false; // 点击前重读,避免沿用上一个目标应用弹窗的位置。 var fresh = readYibaoAppJumpPage(auto.rootInActiveWindow); action = planYibaoAppJumpAction(fresh); if (!action || fresh.title !== page.title) return false; var b = action.bounds; log("应用宝跨应用打开确认:选择始终打开,title=" + fresh.title + " bounds=" + JSON.stringify(b)); if (press(Math.round((b.left + b.right) / 2), Math.round((b.top + b.bottom) / 2), 100) === false) return false; var deadline = Date.now() + 3000; while (Date.now() < deadline) { sleep(200); var current = auto.rootInActiveWindow; if (current && String(current.getPackageName() || "") !== "com.vivo.appfilter") { log("始终打开确认已消失,继续验证目标应用跳转"); return true; } } log("始终打开点击后弹窗尚未消失,交给后续跳转检查复核"); return false; } catch (error) { if (error && error.taskInterrupted) throw error; log("应用宝打开确认读取失败,本帧不操作:" + errorText(error)); return false; } finally { yibaoAppJumpBusy = false; } } function getForegroundAppByAutoJs() { try { if (typeof auto !== "undefined" && auto && auto.service) handleYibaoAppJumpPrompt(auto.rootInActiveWindow); } catch (error) { if (error && error.taskInterrupted) throw error; } return businessGetForegroundAppByAutoJs(); }