From 8844c9b63aba30dc332c4c59592b6291e9a2b4f7 Mon Sep 17 00:00:00 2001 From: huanghaohao <759903577@qq.com> Date: Thu, 19 Nov 2026 13:03:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=A7=86=E9=A2=91=E9=93=BE=20e2e=20?= =?UTF-8?q?=E7=AC=AC=E4=BA=8C~=E4=BA=94=E8=BD=AE=E7=9C=9F=E6=9C=BA?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E2=80=94=E2=80=94=E6=A0=91=E9=80=9A=E9=81=93?= =?UTF-8?q?+=E7=BF=BB=E9=A1=B5=E6=A0=B9=E5=9B=A0=E6=94=B6=E6=95=9B?= =?UTF-8?q?=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit e2e 五轮迭代实锤(日志 .tmp/douyin-video-evidence/e2e-01~10): - R1:比例坐标分享按钮失效——readDetailOcrFullText 滚屏后按钮位漂移 - R2:OPEN_APP 失败——vivo 覆盖安装重置「后台弹出界面」权限(用户已重新授权) - R3:热榜词条详情是双列卡片流**没有分享按钮**——必须先点视频卡进 HotSpotDetailActivity 全屏页(树 content-desc=分享N,按钮 全可达) - R4:openSharePanel 改树锚点成功,但 findPanelButton 单次查询扑空 - R5:诊断采样实锤面板停在第一页——手势横滑被面板吞+原生滚动滚错容器 (微博 e35 同款坑);ACTION_SCROLL_FORWARD 命中的是好友列表不是功能行 本轮修复(已装机验证到 R5 终态): - openFullscreenFromEntry:卡片流→全屏页新跳(视频,按钮 树锚点) - openSharePanel/saveLocalFromSharePanel/copyShareLink/dismissSharePanel 全树通道化 - findPanelButton 双次重试+失败时当屏 text 采样诊断(R4 采样实锤了 R5 根因) - swipePanelRowForward:原生滚动优先(待 R6 修容器定位) - 沙盒编排顺序反转:先保存动作(页面顶部)后滚屏取材料 误触事故(R5 手动复现):点开转发到日常编辑页,未点转发,X 关闭, 相册无新增,账号无外发动作 验证:369 项 JVM 全过;APK 2837CD07 装机(12:56:48) Co-Authored-By: Claude Code --- .../automation/HaoRuiAccessibilityService.kt | 14 +- .../source/douyin/DouyinDevicePort.kt | 232 ++++++++++++------ 2 files changed, 168 insertions(+), 78 deletions(-) diff --git a/app/src/main/java/com/haorui/app/automation/HaoRuiAccessibilityService.kt b/app/src/main/java/com/haorui/app/automation/HaoRuiAccessibilityService.kt index efc18c7..5bd1dcc 100644 --- a/app/src/main/java/com/haorui/app/automation/HaoRuiAccessibilityService.kt +++ b/app/src/main/java/com/haorui/app/automation/HaoRuiAccessibilityService.kt @@ -1594,18 +1594,24 @@ class HaoRuiAccessibilityService : AccessibilityService() { var saveOutcome: com.haorui.app.crossplatform.source.douyin.DouyinHotListCollector.SaveLocalOutcome? = null var copyOk = false val result = machine.collectOne(entryIndex, onDetail = { - // 详情页前台:先取 OCR 材料(标题链降级兜底),再做分享面板动作 - val full = runCatching { port.readDetailOcrFullText() }.getOrDefault(emptyList()) - detailLines = if (full.isNotEmpty()) full else port.readDetailOcrLines() + // 详情页前台:⚠️ 顺序敏感(e2e 第一轮实锤)——先做分享面板动作(页面在顶部, + // 全屏页分享按钮位置稳定),再滚屏取 OCR 材料(滚屏后按钮位漂移=第一轮失败根因)。 savedSinceMs = System.currentTimeMillis() + // 卡片流 → 全屏播放页(分享按钮所在页,树锚点 content-desc="分享,按钮") + if (!port.openFullscreenFromEntry()) { + saveOutcome = com.haorui.app.crossplatform.source.douyin.DouyinHotListCollector.SaveLocalOutcome.FAILED + return@collectOne + } saveOutcome = port.saveLocalFromSharePanel() if (saveOutcome == com.haorui.app.crossplatform.source.douyin.DouyinHotListCollector.SaveLocalOutcome.SAVED) { // 保存成功后稍候再取(落盘+MediaStore 入库有延迟) Thread.sleep(3_000) copyOk = port.copyShareLink() } - // 关闭分享面板恢复详情页(外发面板是弹层,不关会挡后续导航) port.dismissSharePanel() + // 全屏页材料(树+OCR):标题/作者/发布时间在全屏页可见;滚屏取全文 + val full = runCatching { port.readDetailOcrFullText() }.getOrDefault(emptyList()) + detailLines = if (full.isNotEmpty()) full else port.readDetailOcrLines() }) RunLogger.i( TAG, diff --git a/app/src/main/java/com/haorui/app/crossplatform/source/douyin/DouyinDevicePort.kt b/app/src/main/java/com/haorui/app/crossplatform/source/douyin/DouyinDevicePort.kt index 2f8f28f..1f41720 100644 --- a/app/src/main/java/com/haorui/app/crossplatform/source/douyin/DouyinDevicePort.kt +++ b/app/src/main/java/com/haorui/app/crossplatform/source/douyin/DouyinDevicePort.kt @@ -500,62 +500,166 @@ internal class DouyinDevicePort( return false } - // ── 视频链扩展(2026-11-18 P0 真机取证:p0-05~09、v1-04~06) ───────────── + // ── 视频链扩展(2026-11-19 e2e 第一轮重取证:全屏页树通道) ───────────── /** - * 打开详情页分享面板:点右侧分享箭头。 - * ⚠️ 红线修订(用户 2026-11-18 决策):原「Port 不提供任何触发分享的方法」已放行 - * 「分享链接」「保存本地」两个只读复制/落盘动作;外发动作(私信/微信/QQ/帮上热门/ - * 转发到日常等)仍是红线,本类不提供任何触发它们的方法。 - * 就绪判据(OCR):「分享给」标题行出现(p0-05 实证)。 + * 热榜词条详情页(搜索结果页双列视频卡片流,HotSpotDetail 前一跳)→ 点首个视频卡 + * 进入全屏播放页(HotSpotDetailActivity)。 + * + * ⚠️ 2026-11-19 e2e 第一轮实锤:热榜词条「详情页」是卡片流**没有右栏分享图标** + * (树 dump 右侧 x>900 仅「单双列切换图标」);分享按钮在全屏播放页右栏 + * (content-desc="分享,按钮")——必须先进全屏页。 + * 视频卡锚点:树 content-desc="视频,按钮"(e2e-03 dump 实证,clickable=true)。 */ - private fun openSharePanel(): Boolean { - // 分享箭头在详情页右下(v1-03 实测 ≈(984,1755) 显示坐标,原始坐标 ×1.20) - // ——但按钮位置随页面浮动,按 OCR 兜底:先找「分享给」判据前先盲区保护。 - // e1 教训:禁止屏上估算行位;分享按钮为图标无文本,唯一稳定锚是右栏图标列 x≈980。 - // 实测两处详情(UltraDetail/FlowPage)分享箭头都在右侧竖列最下方, - // 以 OCR 检测「分享给」是否出现做闭环判定,点击坐标用比例定位(x=0.912, y=0.729)。 - val screen = captureScreen() ?: return false - val w = screen.width - val h = screen.height - screen.recycle() - val tapX = (w * 0.912).toInt() - val tapY = (h * 0.729).toInt() - val tapped = runCatching { kotlinx.coroutines.runBlocking { service.gestures.tapAt(tapX, tapY, retry = true) } }.getOrDefault(false) - if (!tapped) { - log("分享面板:点击分享箭头失败") + fun openFullscreenFromEntry(): Boolean { + val root = tree() ?: run { log("全屏页:树不可读"); return false } + // 找第一个「视频,按钮」卡片(左列 = bounds.x 较小者) + var target: SourceNode? = null + for (node in root.selfAndDescendants()) { + val desc = node.description.orEmpty() + if (desc.startsWith("视频") && desc.contains("按钮")) { + val b = node.bounds + if (b != null && (b.right - b.left) > 200 && (b.bottom - b.top) > 300) { target = node; break } + } + } + if (target == null || target.bounds == null) { + log("全屏页:未找到视频卡锚点(页面形态变化或未进卡片流)") return false } - val ready = waitOcr(12_000, { lines -> lines.any { it.replace(" ", "").contains("分享给") } }, "分享面板") - if (!ready) log("分享面板:OCR 未出现「分享给」判据") + val rect = target.bounds!! + val ok = runCatching { + kotlinx.coroutines.runBlocking { service.gestures.tapAt(rect.centerX, rect.centerY, retry = true) } + }.getOrDefault(false) + if (!ok) { log("全屏页:视频卡点击失败"); return false } + // 就绪判据(树通道):「分享,按钮」content-desc 出现 + val entered = waitTree(10_000) { t -> + t.selfAndDescendants().any { it.description.orEmpty().startsWith("分享") && it.description.orEmpty().contains("按钮") } + } + if (!entered) log("全屏页:分享锚点未出现(可能进了图文或加载慢)") + return entered + } + + /** + * 打开全屏播放页分享面板:点右栏分享箭头。 + * ⚠️ 红线修订(用户 2026-11-18 决策):「分享链接」「保存本地」两个只读动作已放行; + * 外发动作(私信/微信/QQ/帮上热门/转发到日常等)仍是红线。 + * 锚点(2026-11-19 全屏页树 dump 实证):content-desc="分享3694,按钮" + * bounds=[900,1757][1080,1958]——树通道,不再走 OCR/比例坐标 + * (比例坐标在 e2e 第一轮实锤失败:readDetailOcrFullText 滚屏后按钮位漂移)。 + * 就绪判据(树):text="分享给" 面板标题节点出现。 + */ + private fun openSharePanel(): Boolean { + val root = tree() ?: run { log("分享面板:树不可读"); return false } + val shareNode = root.selfAndDescendants().firstOrNull { + val d = it.description.orEmpty() + d.startsWith("分享") && d.contains("按钮") + } + val rect = shareNode?.bounds + if (rect == null || (rect.right - rect.left) <= 0) { + log("分享面板:树内未找到分享按钮锚点") + return false + } + val tapped = runCatching { + kotlinx.coroutines.runBlocking { service.gestures.tapAt(rect.centerX, rect.centerY, retry = true) } + }.getOrDefault(false) + if (!tapped) { log("分享面板:点击分享按钮失败"); return false } + val ready = waitTree(8_000) { t -> + t.selfAndDescendants().any { it.text == "分享给" } + } + if (!ready) log("分享面板:树内未出现「分享给」判据") return ready } + /** 面板功能行按钮查找:text 精确匹配(树通道),带重试轮询(横滑动画/树刷新有延迟)。 */ + private fun findPanelButton(label: String): com.haorui.app.crossplatform.source.SourceBounds? { + // 横滑动画≈0.5s+树刷新延迟:2 次重试间隔 1s(e2e 第三轮实锤单次查询会扑空) + for (attempt in 1..2) { + val root = tree() + if (root == null) { Thread.sleep(1_000); continue } + // 按钮布局(2026-11-19 panel2/panel3 dump 实证):text 标签 y≈2147, + // clickable 容器(ViewGroup)同 x 区间、底边=标签底边([285,1971][472,2182])。 + val labelNode = root.selfAndDescendants().firstOrNull { it.text == label && it.bounds != null } + if (labelNode != null) { + val labelRect = labelNode.bounds!! + // 找与标签 x 区间重叠、底边≥标签底的可点击容器;找不到容器时点标签本体(text 节点也可能可点) + val container = root.selfAndDescendants().firstOrNull { n -> + val b = n.bounds ?: return@firstOrNull false + b.left <= labelRect.right && b.right >= labelRect.left && + b.bottom >= labelRect.bottom && (b.bottom - b.top) >= (labelRect.bottom - labelRect.top) + } + return container?.bounds ?: labelRect + } + if (attempt == 1) { + // 未找到:dump 当屏 text 采样辅助诊断(面板页码/形态变化可见) + val sample = root.selfAndDescendants().mapNotNull { it.text.takeIf { t -> t.isNotBlank() } } + .take(12).joinToString("|") + log("面板按钮[$label]第 $attempt 次未找到,当屏 text 采样: $sample") + } + Thread.sleep(1_000) + } + return null + } + + /** + * 分享面板功能行翻页(e2e 第四轮实锤:手势横滑页码不动——微博 e35 同款坑, + * 手势易被面板误判为拖拽关闭)。首选无障碍原生滚动(面板内 y>1400 的 + * isScrollable 容器 ACTION_SCROLL_FORWARD),失败退化横滑手势。 + */ + private fun swipePanelRowForward(): Boolean { + val root = service.root() + if (root != null) { + var visited = 0 + val rect = android.graphics.Rect() + fun walk(node: android.view.accessibility.AccessibilityNodeInfo): android.view.accessibility.AccessibilityNodeInfo? { + if (visited++ > 4_000) return null + runCatching { node.getBoundsInScreen(rect) } + if (node.isScrollable && rect.top > 1_400) return android.view.accessibility.AccessibilityNodeInfo.obtain(node) + for (i in 0 until node.childCount) { + val child = node.getChild(i) ?: continue + val found = try { walk(child) } finally { runCatching { child.recycle() } } + if (found != null) return found + } + return null + } + val target = walk(root) + if (target != null) { + val ok = try { + runCatching { target.performAction(android.view.accessibility.AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) }.getOrDefault(false) + } finally { + runCatching { target.recycle() } + } + if (ok) { + log("面板功能行:原生滚动成功") + return true + } + } + } + val swiped = runCatching { + kotlinx.coroutines.runBlocking { service.gestures.swipe(0.833f, 0.868f, 0.185f, 0.868f) } + }.getOrDefault(false) + log("面板功能行:原生滚动不可用,手势横滑=$swiped") + return swiped + } + override fun saveLocalFromSharePanel(): DouyinHotListCollector.SaveLocalOutcome { if (!openSharePanel()) return DouyinHotListCollector.SaveLocalOutcome.FAILED - // 功能行横滑到第二页找「保存本地」(p0-06/v1-05 实证在第二页第 2 位) - val swiped = runCatching { - kotlinx.coroutines.runBlocking { service.gestures.swipe(0.833f, 0.868f, 0.185f, 0.868f) } - }.getOrDefault(false) - if (!swiped) log("保存本地:功能行横滑失败(可能已在目标页)") - Thread.sleep(1_000) - // OCR 定位「保存本地」文本行 → bounds 求中心点击(红线:先核对再点) - val found = ocrFindLineWithBounds("保存本地") - if (found == null) { - log("保存本地:OCR 未定位到按钮(可能灰置或面板形态变化)") + // 功能行翻页找「保存本地」(p0-06/v1-05/e2e panel2/panel3 实证在第二页) + swipePanelRowForward() + Thread.sleep(1_200) + val rect = findPanelButton("保存本地") + if (rect == null) { + log("保存本地:树内未找到按钮(可能灰置或面板形态变化)") // 灰置与找不到无法区分时保守按灰置处理——宁降级不盲点 return DouyinHotListCollector.SaveLocalOutcome.SAVE_DISABLED } - val (lineText, rect) = found - if (!lineText.replace(" ", "").contains("保存本地")) { - return DouyinHotListCollector.SaveLocalOutcome.SAVE_DISABLED - } val tapped = runCatching { - kotlinx.coroutines.runBlocking { service.gestures.tapAt(rect.centerX(), rect.centerY(), retry = true) } + kotlinx.coroutines.runBlocking { service.gestures.tapAt(rect.centerX, rect.top + ((rect.bottom - rect.top) * 2 / 3), retry = true) } }.getOrDefault(false) if (!tapped) return DouyinHotListCollector.SaveLocalOutcome.FAILED - // 回执判据(v1-06 实证):「已保存」横幅(含「请去相册查看」) - val receipt = waitOcr(15_000, { lines -> + // 回执判据(v1-06 实证):「已保存」横幅。树通道优先(横幅为 text 节点),OCR 兜底。 + val receipt = waitTree(15_000) { t -> + t.selfAndDescendants().any { it.text.replace(" ", "").contains("已保存") } + } || waitOcr(6_000, { lines -> lines.any { it.replace(" ", "").contains("已保存") } }, "保存回执") return if (receipt) { @@ -569,23 +673,22 @@ internal class DouyinDevicePort( override fun copyShareLink(): Boolean { if (!openSharePanel()) return false - // 「分享链接」在功能行(p0-08 实证第 6 位;轻滑半格入视野后 OCR 定位点击) + // 「分享链接」第一页屏边半露(e2e panel dump 实证 [1042,2147]),轻滑半格入视野 val swiped = runCatching { kotlinx.coroutines.runBlocking { service.gestures.swipe(0.694f, 0.868f, 0.324f, 0.868f) } }.getOrDefault(false) if (!swiped) log("分享链接:功能行轻滑失败(可能已入视野)") - Thread.sleep(1_000) - val found = ocrFindLineWithBounds("分享链接") - if (found == null) { - log("分享链接:OCR 未定位到按钮") + Thread.sleep(1_200) + val rect = findPanelButton("分享链接") + if (rect == null) { + log("分享链接:树内未找到按钮") return false } - val (_, rect) = found val tapped = runCatching { - kotlinx.coroutines.runBlocking { service.gestures.tapAt(rect.centerX(), rect.centerY(), retry = true) } + kotlinx.coroutines.runBlocking { service.gestures.tapAt(rect.centerX, rect.top + ((rect.bottom - rect.top) * 2 / 3), retry = true) } }.getOrDefault(false) if (!tapped) return false - // 回执判据(p0-09 实证):「链接已复制」toast + 「链接已复制成功」面板标题 + // 回执判据(p0-09 实证):「链接已复制」toast。toast 不一定进树——OCR 兜底为主。 val receipt = waitOcr(10_000, { lines -> lines.any { it.replace(" ", "").contains("链接已复制") } }, "复制回执") @@ -595,32 +698,13 @@ internal class DouyinDevicePort( } override fun dismissSharePanel(): Boolean { - // 关闭面板:点右上 X(p0-05 实证 ≈(809,1462) 显示坐标 / 1.20 = 原始比例定位) - // X 是图标无文本,按面板结构定位:先 OCR 找「分享给」标题行,X 在其同行右端 - val found = ocrFindLineWithBounds("分享给") - if (found != null) { - val (_, rect) = found - // X 按钮在「分享给」行右端外侧(实测与标题行同 y,x≈屏宽 0.9) - val tapX = (captureScreen()?.width ?: 1080) - 60 - val tapped = runCatching { - kotlinx.coroutines.runBlocking { service.gestures.tapAt(tapX, rect.centerY(), retry = true) } - }.getOrDefault(false) - if (tapped) { - Thread.sleep(1_000) - val closed = runCatching { - ocrFindLineWithBounds("分享给") == null - }.getOrDefault(false) - if (closed) { - log("分享面板:X 关闭确认") - return true - } - } - } - // X 失败兜底:BACK 收拢(面板是弹层,BACK 等效关闭) + // 关闭面板:BACK(面板是弹层,BACK 等效关闭——e2e 第一轮 BACK 兜底实锤有效) runCatching { service.gestures.back() } - Thread.sleep(1_000) - val closedByBack = runCatching { ocrFindLineWithBounds("分享给") == null }.getOrDefault(false) - log("分享面板:BACK 兜底关闭 ${if (closedByBack) "成功" else "未确认"}") - return closedByBack + Thread.sleep(1_200) + val closed = waitTree(5_000) { t -> + t.selfAndDescendants().none { it.text == "分享给" } + } + log("分享面板:BACK 关闭 ${if (closed) "成功" else "未确认"}") + return closed } }