自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
輸入路由
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在 Android 9 以下版本中,您無法透過觸控與多個螢幕互動,因為螢幕和輸入裝置之間沒有關聯機制。舉例來說,觸控螢幕顯示器可提供 HDMI 影像輸出 (會在 Android 上註冊為顯示器),以及觸控螢幕的 USB 輸出 (會註冊為輸入裝置)。如果以這種方式連接多部裝置,就無法判斷哪個輸入裝置屬於哪個螢幕。同樣的問題也適用於內建多個螢幕的摺疊式裝置。
Android 10 新增了一種機制,可指定哪些輸入裝置屬於哪些螢幕。關聯會透過通訊埠編號完成,其中「通訊埠」是指螢幕連接的實體通訊埠。
舉例來說,如果 Android 裝置有兩個 HDMI 連接埠,分別標示為 hdmi1
和 hdmi2
,則顯示埠值可能會是 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
如果有多部裝置已連線,請輕觸特定裝置,檢查輸入調度器狀態中的 RecentQueue
陣列。接著,您就可以找出產生最近事件的裝置。接著,您可以在 Event Hub 狀態中找到對應的裝置。
如要判斷已指派給已連接螢幕的顯示埠,請使用 adb shell dumpsys display
,然後在「顯示裝置」下尋找每部螢幕的 DisplayDeviceInfo
address
屬性。或者,您也可以使用 adb shell dumpsys SurfaceFlinger --display-id
將所有已連線顯示器的 ID 資訊轉儲。另請參閱「靜態顯示 ID」。
如果您為特定輸入裝置指定關聯,但系統中沒有對應的顯示畫面,輸入裝置就會停用,直到顯示畫面出現為止。關聯作業僅適用於觸控裝置。
動態多螢幕轉送
您可以使用 Android 10 設定靜態多螢幕裝置。動態關聯尚未啟用。不過,您可以為不一定會出現或使用虛擬輸入裝置的螢幕和輸入面板提供路由資訊,然後為這些虛擬裝置提供額外的路由資訊,以解決某些用途。如果裝置實作項目支援以下項目:
- 使用類似電腦的體驗,搭配擴充座,然後提供路由設定,將從連接至擴充座的輸入配件 (透過通訊埠獨立識別) 的目標輸入,傳送至外接螢幕 (透過通訊埠識別)。
- 當主要螢幕連接至外接螢幕時,會充當輸入來源 (例如觸控板),然後提供路由設定,將從虛擬觸控面板 (以獨特虛擬 ID 識別) 指定的輸入內容,轉送至外接螢幕 (以通訊埠識別)。
實作
- 對於實體裝置,輸入裝置連接的連接埠和螢幕連接的連接埠,用於將螢幕與觸控螢幕配對。
- 對應項目會儲存在
InputReaderConfiguration
中。
TouchInputMapper.mViewport
會設為與 InputDevice.location
指定的通訊埠相符的可視區域。
- 如果對應檔案中指定了輸入裝置埠,但目前沒有任何檢視區有相符的顯示埠,則該埠上的輸入裝置會停用。
- 如果未為特定輸入裝置指定通訊埠,系統會根據現有規則設定視區。
- 輸入驅動程式不需要進行任何核心變更。
- 系統會使用 EVIOCGPHYS ioctl 判斷輸入裝置通訊埠。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],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."]]