自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
输入路由
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在 Android 9 及更低版本中,无法通过轻触与多个屏幕进行交互,因为屏幕和输入设备之间没有关联机制。例如,触摸屏幕可以提供 HDMI 视频输出(将在 Android 上注册为屏幕)以及用于触摸屏的 USB 输出(将注册为输入设备)。如果以这种方式连接多个设备,则无法确定哪个输入设备属于哪个屏幕。对于具有多个内置屏幕的可折叠设备,也同样存在该问题。
Android 10 增加了一种机制来指定哪些输入设备属于哪些屏幕。这种关联由端口号完成,其中端口是指与屏幕连接的物理端口。
例如,如果 Android 设备有两个标记为 hdmi1
和 hdmi2
的 HDMI 端口,则屏幕端口值可以为 1
和 2
。即使将不同的屏幕(例如不同的屏幕型号或制造商)连接到同一物理 HDMI 端口,端口值也保持不变。这样一来,设备制造商就能够提供组装和升级屏幕的说明。
这种关联在 /vendor/etc/input-port-associations.xml
中配置。例如:
<ports>
<port display="0" input="usb-xhci-hcd.0.auto-1.1/input0" />
<port display="1" input="usb-xhci-hcd.0.auto-1.2/input0" />
</ports>
在上面的示例中,display="0"
指定与屏幕连接的端口。input="usb-xhci-hcd.0.auto-1.1/input0"
指定与输入设备连接的端口。如需确定与特定设备关联的端口,请使用以下终端命令,然后在 Event Hub 状态中查看这些设备的 location
属性。
adb shell dumpsys input
如果连接了很多设备,请点按特定设备,以在 Input Dispatcher 状态中检查 RecentQueue
数组。然后,您可以确定生成最新事件的设备。之后,您可以在 Event Hub 状态中找到相应的设备。
如需确定分配给连接的屏幕的屏幕端口,请使用 adb shell dumpsys display
,然后在“Display Devices”下针对每个屏幕查找 DisplayDeviceInfo
的 address
属性。或者,使用 adb shell dumpsys SurfaceFlinger --display-id
转储所有已连接屏幕的标识信息。另请参阅静态屏幕标识符。
如果为特定输入设备指定关联,并且系统中不存在相应的屏幕,则该输入设备会被禁用,直到出现相应的屏幕为止。这种关联仅对触摸屏设备执行。
动态多屏幕的路由
您可以通过 Android 10 设置静态多屏幕设备。动态关联尚未启用。不过,某些用例可以通过为并非始终存在的屏幕和输入面板提供路由信息,或者使用虚拟输入设备,然后向这些虚拟设备提供其他路由信息加以解决。如果设备实现支持:
- 使用坞站的桌面式体验,则可以为从连接到插入基座的输入附件(由端口唯一标识)到外部屏幕(由端口标识)的目标输入提供路由配置。
- 主屏幕在连接到外部屏幕时充当输入源(例如触控板),则可以为从虚拟触摸面板(由唯一虚拟 ID 标识)到外部屏幕(由端口标识)的目标输入提供路由配置。
实现
- 对于物理设备,与输入设备连接的端口以及与屏幕连接的端口用于将屏幕与触摸屏匹配。
- 映射存储在
InputReaderConfiguration
中。
- 将
TouchInputMapper.mViewport
设置为与为 InputDevice.location
指定的端口相匹配的视口。
- 如果在映射文件中指定了输入设备端口,并且当前没有具有匹配屏幕端口的视口,则该端口上的输入设备会被禁用。
- 如果没有为特定输入设备指定端口,则根据现有规则设置视口。
- 输入驱动程序中不需要任何内核更改。
- 输入设备端口通过使用 EVIOCGPHYS ioctl 确定。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Input routing\n\nIn Android 9 and lower, there was no way to interact with multiple displays\nvia touch, because there was no association mechanism between displays and input\ndevices. For example, a touchscreen display could provide an HDMI video output\n(that would register as a display on Android) and a USB output for touchscreen\n(that would register as an input device). If multiple devices were connected in\nthis manner, there would be no way to determine which input device belongs to\nwhich display. The same issue applies to foldable devices with multiple built-in\ndisplays.\n\nAndroid 10 added a mechanism to specify which input\ndevices belong to which displays. The association is done by port numbers where\n*port* refers to the physical port to which a display is connected.\n\nFor example, if an Android device has two HDMI ports labeled `hdmi1`\nand `hdmi2`, then the display port values could be `1` and\n`2`. The port values remain the same even when a different display is\nconnected (such as a different display model or manufacturer) to the same physical\nHDMI port. This enables device manufacturers to provide instructions to assemble\nand upgrade displays.\n\nThe association is configured in `/vendor/etc/input-port-associations.xml`.\nFor example: \n\n \u003cports\u003e\n \u003cport display=\"0\" input=\"usb-xhci-hcd.0.auto-1.1/input0\" /\u003e\n \u003cport display=\"1\" input=\"usb-xhci-hcd.0.auto-1.2/input0\" /\u003e\n \u003c/ports\u003e\n\nIn the example above, `display=\"0\"` specifies the port to which the\ndisplay is connected. `input=\"usb-xhci-hcd.0.auto-1.1/input0\"`\nspecifies the port to which the input device is connected. To determine the ports\nassociated with specific devices, use the following terminal command, and then\nreview the`location` property of those devices in the Event Hub State. \n\n```\nadb shell dumpsys input\n```\n\nIf many devices are connected, tap a specific device to examine the\n`RecentQueue` array in the Input Dispatcher State. You can then identify\nthose devices that generated the most recent event. You can then find the\ncorresponding device in the Event Hub State.\n\nTo determine the display ports assigned to the connected displays, use\n`adb shell dumpsys display` and then look for the `address`\nproperty of `DisplayDeviceInfo` for each display under Display Devices.\nAlternatively, use `adb shell dumpsys SurfaceFlinger --display-id` to dump\nidentification information for all connected displays. See also\n[Static display identifiers](/docs/core/display/multi_display/displays#static).\n\nIf you specify an association for a specific input device and the corresponding\ndisplay isn't present in the system, the input device is disabled until the respective\ndisplay appears. The association is performed only for touch devices.\n\nRouting for dynamic multi-displays\n----------------------------------\n\nAndroid 10 enables you to set up static multi-display\ndevices. Dynamic associations are not yet enabled. However, some use cases can be\naddressed by providing routing information for displays and input panels that aren't\nalways present or using virtual input devices and then providing additional routing\ninformation to those virtual devices. If a device implementation supports a:\n\n- Desktop-like experience with a docking station, then a routing config could be provided to target input from input accessory connected to the dock (identified uniquely by port) to the external display (identified by port).\n- Primary screen acting as an input source (such as a touchpad) when connected to the external display, then a routing config could be provided to target input from virtual touch panel (identified by unique virtual ID) to the external display (identified by port).\n\n### Implementation\n\n- For physical devices, the port to which the input device is connected and the port to which the display is connected, are used to match the displays with touchscreens.\n- The mappings are stored in `InputReaderConfiguration`.\n- `TouchInputMapper.mViewport` is set to the viewport that matches the port specified for `InputDevice.location`.\n- If an input device port is specified in the mapping file, and there currently isn't a viewport that has a matching display port, then the input device on that port is disabled.\n- If a port isn't specified for a particular input device, then viewport is set according to the existing rules.\n- No kernel changes are required in the input drivers.\n- The input device ports are determined using the EVIOCGPHYS ioctl."]]