Android 12系统源码_输入系统(四)触摸异常问题排查

发布于:2025-03-31 ⋅ 阅读:(16) ⋅ 点赞:(0)

前言

系统开发过程中经常会遇到冻屏问题,所谓的冻屏问题就是指屏幕内容看起来一切正常,但是却触控无效、画面卡住、按键无反应,但系统可能仍在后台运行(如触控无效、画面卡住、按键无反应),这种问题有很多方面的原因:

  • 硬件故障 触控屏、显示控制器或内存硬件故障
  • GPU/显示驱动问题 GPU 渲染超时、驱动崩溃或帧缓冲区(FrameBuffer)错误
  • SurfaceFlinger 异常 图形合成服务(SurfaceFlinger)崩溃或死锁
  • 主线程阻塞 Activity/View 主线程执行耗时操作(如 I/O、死循环)
  • 输入系统故障 InputDispatcher 事件分发阻塞(如焦点窗口丢失、ANR)
  • 系统服务死锁 WindowManagerService/ActivityManager 等核心服务线程阻塞

本篇文章由于是输入系统系列的文章,所以我们不考虑其他场景,主要考虑当冻屏问题是因为输入系统故障而导致的,这个时候我们要如何层层剥茧,最终定位出输入系统故障具体原因。

设备节点是否正常

adb指令getevent的实现原理就是直接挂载dev/input/eventx事件节点,然后当这些事件节点有事件上报的时候将其打印出来。
因此当发生触摸异常问题的时候,我们可以通过这个指令可以将触摸异常的事件原因一分为二:

设备节点没有收到没有收到触摸事件

如果getevent都没有打印输入事件,则说明驱动层存在异常,事件直接没有上报,需要驱动层的相关人员进行问题的进一步分析

设备节点有收到没有收到触摸事件

正常情况下当我们触摸屏幕的时候,getevent会打印类似下面的日志信息,这就说明驱动层没有问题,需要我们做进一步分析
在这里插入图片描述

InputReader是否正常

可以在Android开发者选项中开启【显示触摸操作】,然后当手指在屏幕按下的时候,确认屏幕上是否会出现一个触摸反馈小圆点。
显示触摸操作

触摸反馈小圆点的实现原理主要是通过监听Input模块的InputReader是否有收到输入事件加工,如果触摸事件小圆点能正常显示,则说明InputReader大概率是正常的;反之则需要在InputReader模块添加相关日志信息进行问题排查。

InputDispatcher是否正常

可以在Android开发者选项中开启【指针位置】,然后当手指在屏幕按下滑动的时候,确认屏幕上是否会出现一系列线条轨迹。
在这里插入图片描述

触摸轨迹的实现原理主要是通过监听Input模块的InputDispatcher是否有收到输入事件分发,如果屏幕上能够正常出现一系列线条轨迹,则说明InputDispatcher大概率是正常的;反之则需要在InputDispatcher模块添加相关日志信息进行问题排查。

Input的堆栈信息是否正常

当我们手势按压在屏幕上行,然后输入dumpsys input指令,一般会得到类似下面的信息。

INPUT MANAGER (dumpsys input)

Input properties:
  persist.input.velocitytracker.strategy = default

//输入服务的状态
Input Manager State:
  Interactive: true	//表示设备处于互动模式,可以接受用户输入。
  System UI Lights Out: false	//系统 UI 没有进入熄灯模式。
  Pointer Speed: 0	//指针速度设置为 0,通常意味着没有加速或者速度控制。
  Pointer Acceleration: 3.000	//指针加速设置为 3,这可能影响触摸输入的速度和灵敏度。
  Pointer Gestures Enabled: true	//表示指针手势(如多点触摸、滑动等)已启用。
  Show Touches: true	//开启【显示触摸位置】开发者选项
  Pointer Capture: Disabled, seq=0	//指针捕获功能禁用,意味着没有一个输入设备会独占指针。

//输入相关的设备信息
Event Hub State:
  BuiltInKeyboardId: 4
  Devices:
    1: ACCDET	//耳机插入检测
      Classes: KEYBOARD | SWITCH	//类型是键盘和开关
      Path: /dev/input/event0	//设备挂载路径
      Enabled: true	//可用状态
      Descriptor: 1c78f7e0d16d4dbc8d3ab93943523f379203f90b
      Location: 
      ControllerNumber: 0
      UniqueId: 
      Identifier: bus=0x0019, vendor=0x0000, product=0x0000, version=0x0000
      KeyLayoutFile: /system/usr/keylayout/ACCDET.kl
      KeyCharacterMapFile: /system/usr/keychars/Generic.kcm
      ConfigurationFile: 
      VideoDevice: <none>
    2: touchpanel //触摸面板
      Classes: KEYBOARD | TOUCH | TOUCH_MT	//类型是键盘、触摸和多点触控
      Path: /dev/input/event2	//设备挂载路径
      Enabled: true	//可用状态
      Descriptor: cda32dd32c9e529b964f707ef746a9e34b2b074f
      Location: 
      ControllerNumber: 0
      UniqueId: 
      Identifier: bus=0x0000, vendor=0x0000, product=0x0000, version=0x0000
      KeyLayoutFile: /system/usr/keylayout/Generic.kl
      KeyCharacterMapFile: /system/usr/keychars/Generic.kcm
      ConfigurationFile: 
      VideoDevice: <none>
    4: qwerty (aka device 0 - built-in keyboard)	//内建键盘
      Classes: KEYBOARD
      Path: /dev/input/event4
      Enabled: true
      Descriptor: 0a920d0216027e6e2f378f49650573230b560922
      Location: 
      ControllerNumber: 0
      UniqueId: 
      Identifier: bus=0x0000, vendor=0x0000, product=0x0000, version=0x0000
      KeyLayoutFile: /system/usr/keylayout/qwerty.kl
      KeyCharacterMapFile: /system/usr/keychars/qwerty.kcm
      ConfigurationFile: /system/usr/idc/qwerty.idc
      VideoDevice: <none>
    5: mtk-kpd	//MTK 键盘
      Classes: KEYBOARD
      Path: /dev/input/event1
      Enabled: true
      Descriptor: f0d2e427e7a05eb6d316f5e14800c5ac7b6aee79
      Location: 
      ControllerNumber: 0
      UniqueId: 
      Identifier: bus=0x0019, vendor=0x2454, product=0x6500, version=0x0010
      KeyLayoutFile: /system/usr/keylayout/Generic.kl
      KeyCharacterMapFile: /system/usr/keychars/Generic.kcm
      ConfigurationFile: 
      VideoDevice: <none>
    -1: Virtual	//虚拟键盘
      Classes: KEYBOARD | ALPHAKEY | DPAD | VIRTUAL	//键盘、字母键、方向键、虚拟输入
      Path: <virtual>
      Enabled: true
      Descriptor: a718a782d34bc767f4689c232d64d527998ea7fd
      Location: 
      ControllerNumber: 0
      UniqueId: <virtual>
      Identifier: bus=0x0000, vendor=0x0000, product=0x0000, version=0x0000
      KeyLayoutFile: /system/usr/keylayout/Generic.kl
      KeyCharacterMapFile: /system/usr/keychars/Virtual.kcm
      ConfigurationFile: 
      VideoDevice: <none>
  Unattached video devices:	//未连接的视屏设备
    <none>	//当前没有未连接的或分离的视觉设备

//设备事件的输入状态
Input Reader State (Nums of device: 5):
  Device 3: touchpanel	//触摸面板
    EventHub Devices: [ 2 ] 
    Generation: 19	//版本
    IsExternal: false
    AssociatedDisplayPort: <none>
    AssociatedDisplayUniqueId: <none>
    HasMic:     false
    Sources: 0x00001103
    KeyboardType: 1
    ControllerNum: 0
    Motion Ranges:
      X: source=0x00001002, min=0.000, max=1079.000, flat=0.000, fuzz=0.000, resolution=0.000	//X坐标范围0-1080
      Y: source=0x00001002, min=0.000, max=2399.000, flat=0.000, fuzz=0.000, resolution=0.000	//Y坐标范围0-2400
      PRESSURE: source=0x00001002, min=0.000, max=1.000, flat=0.000, fuzz=0.000, resolution=0.000
      SIZE: source=0x00001002, min=0.000, max=1.000, flat=0.000, fuzz=0.000, resolution=0.000
      TOUCH_MAJOR: source=0x00001002, min=0.000, max=2631.805, flat=0.000, fuzz=0.000, resolution=0.000
      TOUCH_MINOR: source=0x00001002, min=0.000, max=2631.805, flat=0.000, fuzz=0.000, resolution=0.000
      TOOL_MAJOR: source=0x00001002, min=0.000, max=2631.805, flat=0.000, fuzz=0.000, resolution=0.000
      TOOL_MINOR: source=0x00001002, min=0.000, max=2631.805, flat=0.000, fuzz=0.000, resolution=0.000
    Keyboard Input Mapper:
      Parameters:
        OrientationAware: false
        HandlesKeyRepeat: false
      KeyboardType: 1
      Orientation: 0
      KeyDowns: 0 keys currently down
      MetaState: 0x0
      DownTime: 0
    Touch Input Mapper (mode - DIRECT):
      Parameters:
        GestureMode: MULTI_TOUCH
        DeviceType: TOUCH_SCREEN
        AssociatedDisplay: hasAssociatedDisplay=true, isExternal=false, displayId=''
        OrientationAware: true
        Orientation: ORIENTATION_0
      Raw Touch Axes:
        X: min=0, max=5399, flat=0, fuzz=0, resolution=0
        Y: min=0, max=11999, flat=0, fuzz=0, resolution=0
        Pressure: unknown range
        TouchMajor: min=0, max=255, flat=0, fuzz=0, resolution=0
        TouchMinor: unknown range
        ToolMajor: unknown range
        ToolMinor: unknown range
        Orientation: unknown range
        Distance: unknown range
        TiltX: unknown range
        TiltY: unknown range
        TrackingId: min=0, max=65535, flat=0, fuzz=0, resolution=0
        Slot: min=0, max=9, flat=0, fuzz=0, resolution=0
      Calibration:
        touch.size.calibration: GEOMETRIC
        touch.pressure.calibration: none
        touch.orientation.calibration: none
        touch.distance.calibration: none
        touch.coverage.calibration: none
      Affine Transformation:
        X scale: 1.000
        X ymix: 0.000
        X offset: 0.000
        Y xmix: 0.000
        Y scale: 1.000
        Y offset: 0.000
	  //对应的屏幕id为0,屏幕物理尺寸为[0, 0, 1080, 2400],输入设备分辨率为[1080, 2400]
      Viewport INTERNAL: displayId=0, uniqueId=local:0, port=0, orientation=0, logicalFrame=[0, 0, 1080, 2400], physicalFrame=[0, 0, 1080, 2400], deviceSize=[1080, 2400], isActive=[1]
      DisplayWidth: 1080px
      DisplayHeight: 2400px
      PhysicalWidth: 1080px
      PhysicalHeight: 2400px
      PhysicalLeft: 0
      PhysicalTop: 0
      InputDeviceOrientation: 0
      Translation and Scaling Factors:
        XScale: 0.200
        YScale: 0.200
        XPrecision: 5.000
        YPrecision: 5.000
        GeometricScale: 0.200
        PressureScale: 0.000
        SizeScale: 0.004
        OrientationScale: 0.000
        DistanceScale: 0.000
        HaveTilt: false
        TiltXCenter: 0.000
        TiltXScale: 0.000
        TiltYCenter: 0.000
        TiltYScale: 0.000
      Last Raw Button State: 0x00000000
      Last Raw Touch: pointerCount=1
        [0]: id=0, x=2302, y=5635, pressure=10, touchMajor=5, touchMinor=5, toolMajor=10, toolMinor=10, orientation=0, tiltX=0, tiltY=0, distance=0, toolType=1, isHovering=false
      Last Cooked Button State: 0x00000000
      Last Cooked Touch: pointerCount=1
        [0]: id=0, x=460.400, y=1127.000, dx=0.000, dy=0.000, pressure=1.000, touchMajor=1.000, touchMinor=1.000, toolMajor=1.000, toolMinor=1.000, orientation=0.000, tilt=0.000, distance=0.000, toolType=1, isHovering=false
      Stylus Fusion:
        ExternalStylusConnected: false
        External Stylus ID: -1
        External Stylus Data Timeout: 9223372036854775807
      External Stylus State:
        When: 9223372036854775807
        Pressure: 0.000000
        Button State: 0x00000000
        Tool Type: 0
  Device 4: ACCDET //耳机插入检测
    EventHub Devices: [ 1 ] 
    Generation: 15
    IsExternal: false
    AssociatedDisplayPort: <none>
    AssociatedDisplayUniqueId: <none>
    HasMic:     false
    Sources: 0x80000101
    KeyboardType: 1
    ControllerNum: 0
    Switch Input Mapper:
      SwitchValues: 0
    Keyboard Input Mapper:
      Parameters:
        OrientationAware: false
        HandlesKeyRepeat: false
      KeyboardType: 1
      Orientation: 0
      KeyDowns: 0 keys currently down
      MetaState: 0x0
      DownTime: 0
  Device 0: qwerty //内建键盘
    EventHub Devices: [ 0 ] 
    Generation: 9
    IsExternal: false
    AssociatedDisplayPort: <none>
    AssociatedDisplayUniqueId: <none>
    HasMic:     false
    Sources: 0x00000101
    KeyboardType: 1
    ControllerNum: 0
    Keyboard Input Mapper:
      Parameters:
        OrientationAware: true
        HandlesKeyRepeat: false
      KeyboardType: 1
      Orientation: 0
      KeyDowns: 0 keys currently down
      MetaState: 0x0
      DownTime: 0
  Device 2: mtk-kpd //MTK键盘
    EventHub Devices: [ 5 ] 
    Generation: 6
    IsExternal: false
    AssociatedDisplayPort: <none>
    AssociatedDisplayUniqueId: <none>
    HasMic:     false
    Sources: 0x00000101
    KeyboardType: 1
    ControllerNum: 0
    Keyboard Input Mapper:
      Parameters:
        OrientationAware: false
        HandlesKeyRepeat: false
      KeyboardType: 1
      Orientation: 0
      KeyDowns: 0 keys currently down
      MetaState: 0x0
      DownTime: 226639450000
  Device -1: Virtual  //虚拟键盘
    EventHub Devices: [ -1 ] 
    Generation: 3
    IsExternal: false
    AssociatedDisplayPort: <none>
    AssociatedDisplayUniqueId: <none>
    HasMic:     false
    Sources: 0x00000301
    KeyboardType: 2
    ControllerNum: 0
    Keyboard Input Mapper:
      Parameters:
        OrientationAware:<