Repository navigation
Conversation
CATMIAOZHI
self-requested a review
November 13, 2026 19:37
CATMIAOZHI
approved these changes
Nov 13, 2026
CATMIAOZHI
left a comment
Collaborator
There was a problem hiding this comment.
审计结论:✅ 批准合并
改动(4 个文件,+204/−42):悬浮窗窗口模式(FloatingMode.WINDOW)坐标统一钳制在屏幕内,补齐四个拖拽手势的 onDragCancel 收尾,FloatingWindowDelegate 关闭分支状态同步;新增 FloatingWindowBoundsTest 单元测试。
通过的检查:
- 目标分支为
dev,符合要求。 - 根因定位与修复一致:
dumpsys取证的x = -231越界坐标,源头是createLayoutParams()/switchMode()/onMove()三处允许负向 X 的钳制区间,新clampWindowPosition()在四处调用点统一收口为0..(screenWidth - width),且updateWindowSizeInLayoutParams()缩放时也会重新钳制,旧坐标的持久化来源已堵住。 clampWindowPosition()边界处理正确:窗口大于屏幕时maxX/maxY经coerceAtLeast(0)退化为0,不会触发coerceIn空区间异常;isFromBall分支传minVisibleHeight = height,与旧逻辑(整窗可见)一致;纵向保留height * 2 / 3可见高度,顶部 TitleBar 始终可达。switchMode()四个分支在state.x / state.y同步后都补了callback.saveState(),持久化的是切换完成后的真实坐标,修复了"先保存旧坐标、后写新坐标"的失步问题;switchMode开头已有的saveState()(模式切换时)不受影响。FloatingChatWindowScreen四处detectDragGestures(TitleBar、右缘、角落、底部)均补齐onDragCancel,与onDragEnd对称收尾,CornerScaleHandle结束/取消时都会触发saveWindowState;ACTION_CANCEL导致拖拽态锁死的问题已覆盖。FloatingWindowDelegate三处失步均已修:onServiceConnected增加isBoundToService守卫并同步_isFloatingMode = true;ACTION_FLOATING_CHAT_SERVICE_STOPPED改为disconnectFromService(updateFloatingMode = true);关闭分支在floatingService为空时回退FloatingChatService.getInstance()?.onClose()或stopService()并复位状态。getInstance()在FloatingChatService伴生对象中存在,disconnectFromService幂等(重复调用无害)。- 球模式(
BALL/VOICE_BALL)的半贴边边界、全屏/识图/结果气泡模式均未改动,与 PR 描述的"明确不包含"一致。 - 新增单测覆盖左越界
-231 -> 0、右越界、上下越界及超大窗口防空区间四种场景,断言与clampWindowPosition的实现一致。 - PR 描述与 diff 一致,验证方式与未运行项(本地未跑 Gradle 编译/单测,原因已说明,由 CI 验证)已如实记录。
问题:
- [P3]
switchMode()球模式切换的两条postDelayed回调(150ms / 100ms)在执行时不校验当前模式:若用户在 150ms 内连续切换两次,先发出的回调可能在后一次切换已完成持久化之后才执行,把中间过渡态的坐标写回state.x / state.y并saveState()。后果有限(下次启动时createLayoutParams会再钳制到屏内,不会重现卡死),但恢复的位置可能不是用户最后停留的位置。建议回调执行时校验当前state.currentMode是否仍为本次切换的目标模式,或在新一次switchMode时取消旧的延迟回调。 - [P3]
FloatingWindowDelegate.toggleFloatingMode()关闭回退分支里context.stopService(...)的catch (_: Exception) {}为空吞异常,出错时无日志,排障困难;建议至少记一条日志(注:同文件disconnectFromService/cleanup等处已有同类空 catch,可顺手统一处理,不阻塞)。
后续可跟进(不阻塞):本地未跑 Gradle 编译与 FloatingWindowBoundsTest,以 CI 的 android_build / android_tests 结果为准;若 CI 单测失败请按失败信息处理。
由 水晴喵的muse 审计
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明 / Description
修复悬浮窗窗口模式(
FloatingMode.WINDOW)在贴边切换或拖拽时滑入负向/越界 X 坐标后无法移动、无法收起也无法从主界面关闭的卡死问题。背景与动机 / Context and motivation
在 Android 16(ColorOS 16,1080×2400,系统左右侧滑返回手势区
0..72px/1008..1080px)真机复现到悬浮窗完全锁死在屏幕左上角的现场(dumpsys window windows实测ty=APPLICATION_OVERLAY,frame=[-231,120][460,888],operit.log记录Floating view added at (-231, 0)):FloatingWindowManager在createLayoutParams()、switchMode()非球分支以及onMove()中对FloatingMode.WINDOW使用了-(width - minVisibleWidth)(即-width / 3,691px 宽窗口下可达-231px)与screenWidth - minVisibleWidth / 2。FloatingChatWindowScreen的TitleBar左侧放置了History / Fullscreen / Minimize三个按钮、右侧放置了Home / Close按钮,仅中间空白段挂了detectDragGestures。一旦窗口落到x = -231(或右侧越界),左侧按钮直接移出屏幕外,残留在屏幕最左缘的按钮落入 Android 24dp(72px)系统侧滑返回手势拦截区(ColorSideGestureLeft),每次触摸都会被系统手势抢走并下发ACTION_CANCEL,导致既拖不动也点不到最小化。updateWindowSizeInLayoutParams()在缩放/拉宽窗口时未重新钳制坐标,靠右缩放会把右侧Home / Close按钮顶出屏幕外。switchMode()在更新state.currentMode时过早调用了callback.saveState(),而后续postDelayed真正写入目标state.x / state.y后未再次持久化,导致floating_chat_prefs保存的是切换前的旧坐标(如贴边悬浮球的负坐标)。ACTION_CANCEL导致拖拽/缩放状态锁死:FloatingChatWindowScreen中TitleBar、RightEdgeScaleHandle、CornerScaleHandle、BottomResizeHandle四个detectDragGestures均未提供onDragCancel。当触摸靠近屏幕边缘被系统侧滑手势以ACTION_CANCEL打断时,viewModel.isDragging、floatContext.isEdgeResizing及缩放态会一直停留在true,后续syncWindowState()因if (!isDragging)条件永远不再同步窗口状态,且不会触发saveWindowState。FloatingWindowDelegate状态失步导致无法兜底关闭:FloatingChatService已在运行而主界面通过tryBindToRunningService()绑定时,onServiceConnected未将_isFloatingMode.value置为true,主界面点击悬浮窗按钮不会走关闭分支;ACTION_FLOATING_CHAT_SERVICE_STOPPED时,disconnectFromService(updateFloatingMode = false)未复位_isFloatingMode;toggleFloatingMode()关闭分支仅调用floatingService?.onClose(),若尚未完成绑定或连接已断开则变成空操作,既关不掉残留的TYPE_APPLICATION_OVERLAY窗口也无法复位按钮状态。改动范围 / Changes
FloatingWindowManager.kt:clampWindowPosition(...),统一约束FloatingMode.WINDOW横向坐标在0..(screenWidth - width).coerceAtLeast(0)内、纵向顶部不小于0且保留可见高度(窗口尺寸极端大于屏幕时退化为0,避免coerceIn抛空区间异常)。createLayoutParams()、updateWindowSizeInLayoutParams()、switchMode()(FloatingMode.WINDOW分支)与onMove()统一接入clampWindowPosition(...)。switchMode()各分支完成state.x / state.y同步后补充callback.saveState(),确保持久化的是切换完成后的真实窗口坐标。FloatingChatWindowScreen.kt:TitleBar、RightEdgeScaleHandle、CornerScaleHandle、BottomResizeHandle全部四个detectDragGestures补齐onDragCancel收尾逻辑;在CornerScaleHandle结束/取消缩放时同步触发saveWindowState。FloatingWindowDelegate.kt:onServiceConnected在仍处于绑定态时同步_isFloatingMode.value = true;ACTION_FLOATING_CHAT_SERVICE_STOPPED调用disconnectFromService(updateFloatingMode = true);toggleFloatingMode()关闭分支在floatingService为空时回退尝试FloatingChatService.getInstance()?.onClose()或context.stopService(...)并复位状态。FloatingWindowBoundsTest.kt,覆盖左越界(-231 -> 0)、右越界、上下越界及超大窗口尺寸防空区间异常。明确不包含:
FloatingMode.BALL/VOICE_BALL)原有的半贴边隐藏边界(-ballSize + ballSize / 2)。FULLSCREEN)、屏幕识图(SCREEN_OCR)和结果气泡(RESULT_DISPLAY)的布局策略,不涉及字符串资源与持久化字段格式变更。兼容性与风险 / Compatibility and risks
FloatingMode.WINDOW)将不再允许左右拖出屏幕边界外;此前历史floating_chat_prefs中已写入负向或越界window_x / window_y的用户在升级后首次启动悬浮窗时会自动被钳制回屏幕安全区内,无需手动清应用数据。关联 Issue / Related issue
N/A(真机使用过程中复现并定位的悬浮窗交互缺陷,未检索到已有重复 Issue;背景与真机窗口现场见上文及下方证据段。)
验证方式 / Verification
证据 / Evidence
真机卡死现场
dumpsys window windows与operit.log关键取证记录(windowWidth = 288dp * 3.0 * 0.8 = 691px,x = -(691 - 460) = -231px):修复后对同一参数(
x = -231, y = 0, width = 691, height = 768, screenWidth = 1080, screenHeight = 2280),FloatingWindowManager.clampWindowPosition将坐标钳制为(0, 0),TitleBar左侧控制按钮与中间拖拽热区、右侧关闭按钮均完整保留在屏幕可见区域内。检查清单 / Checklist
dev;如目标为main,我已说明这是维护者发布同步 / The target branch isdevfor regular work; if it ismain, I explained why this is a maintainer-led release syncCandidate checks覆盖改动范围,并会处理技术失败项 /Candidate checkscovers the change scope and technical failures will be addressed