参与公司项目遇到的camera中接收触摸屏幕坐标错误的问题

提出的bug:专业模式,横屏状态下,点击缩略图,进入图库,下滑图片返回camera,快速按住 shutterButton 持续约 1S 左右,松开, shutter 的 状态 仍 显示为 按住的 状态。

log中输出的关键信息:

    Line 52764: 12-07 16:24:14.496 23868 23868 V ViewRootImpl[Camera]: enqueueInputEvent: event = MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2026.0, y[0]=579.75, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=95786318, downTime=95786118, deviceId=4, source=0x1002, displayId=0, eventId=14271986 },processImmediately = true,mProcessInputEventsScheduled = false, this = android.view.ViewRootImpl@f312c09
	Line 52764: 12-07 16:24:14.496 23868 23868 V ViewRootImpl[Camera]: enqueueInputEvent: event = MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2026.0, y[0]=579.75, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=95786318, downTime=95786118, deviceId=4, source=0x1002, displayId=0, eventId=14271986 },processImmediately = true,mProcessInputEventsScheduled = false, this
	Line 52816: 12-07 16:24:14.505 23868 23900 I BufferQueueProducer: [ViewRootImpl[Camera]#59(BLAST Consumer)59](id:5d3c000000ae,api:1,p:23868,c:23868) disconnect: api 1
	Line 52828: 12-07 16:24:14.506 23868 23900 I BufferQueueProducer: [ViewRootImpl[Camera]#59(BLAST Consumer)59](id:5d3c000000ae,api:1,p:23868,c:23868) connect: api=1 producerControlledByApp=true
	Line 52890: 12-07 16:24:14.508 23868 23868 V ViewRootImpl[Camera]: enqueueInputEvent: event = MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=2026.0, y[0]=579.75, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=95786331, downTime=95786118, deviceId=4, source=0x1002, displayId=0, eventId=1797847677 },processImmediately = true,mProcessInputEventsScheduled = false, this = android.view.ViewRootImpl@f312c09
	Line 52890: 12-07 16:24:14.508 23868 23868 V ViewRootImpl[Camera]: enqueueInputEvent: event = MotionEvent { action=
	Line 52894: 12-07 16:24:14.508 23868 23868 E gaorui  : CameraManager - handleEdgeTouch - return 
	Line 52897: 12-07 16:24:14.509 23868 23868 E gaorui  : Camera - dispatchTouchEvent - (m.getX() ) = 2026.0
	Line 52899: 12-07 16:24:14.509 23868 23868 E gaorui  : Camera - dispatchTouchEvent - (m.getX() < 0) = false
	Line 52900: 12-07 16:24:14.509 23868 23868 E gaorui  : Camera - dispatchTouchEvent - (m.getY() < 0) = false
	Line 52901: 12-07 16:24:14.509 23868 23868 E gaorui  : Camera - dispatchTouchEvent - (m.getX() ) = 2026.0
	Line 52902: 12-07 16:24:14.509 23868 23868 E gaorui  : Camera - dispatchTouchEvent - Util.getScreenWidth() = 1080
	Line 52903: 12-07 16:24:14.509 23868 23868 E gaorui  : Camera - dispatchTouchEvent - return - 2

刚开始的怀疑点是: 横屏 状态下 触摸一个地方 与 竖屏状态下 触摸 同一个地方,显示的坐标是一样的,唯独 发生异常的 时候,接收到的 InputEvent 是 错误的,导致camera 直接退出 接收 按键的状态,所以无法响应接下来的 Up 事件。所以 去 询问了 frameWork 的同事,后来 提出 是不是 camera 再进入 的时候 重新 进行 二次布局,而触摸发送的坐标 是布局之前的。

于是就继续 查查 camera 中是否 会对 屏幕坐标系 进行 变换。(对于 屏幕坐标系 不是怎么熟悉的各位可以看看这个链接里的)。

这个推测原因很快被否定了,因为 在 异常发生的时候,状态栏 会再次出现,并且是横屏的状态,由此可见,此时 系统 还没有转过来 坐标。

最后解决办法就是,在接收到异常坐标的时候,将其再次置换回去,action 的话,可以选择 将其改成 down 事件,或者 不改变action,直接 执行 cancel事件。

Supongo que te gusta

Origin blog.csdn.net/ddcxxc/article/details/121805788
Recomendado
Clasificación