A method and device for managing multiple USB ports, and an electronic device
Patent Information
- Application Number
- CN202611352048.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-02
- Publication Date
- 2026-10-09
AI Technical Summary
若仍沿用单端口设备“自动切换、无需知会”的逻辑,用户将无法直观判断当前究竟是哪一个端口上的外设处于有效工作状态,哪些端口处于无效的挂起状态
通过仲裁管理多USB端口,实现了对多端口请求的合理调度,使多USB端口的数据通信稳定可控;通过引入各个USB端口的状态可视化机制,改变了传统USB驱动“静默切换”的模式,将原本黑盒的“端口挂起”状态转化为用户可感知的视觉信息,改善了用户体验。
Smart Images

Figure CN122884893A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of USB management technology, and more particularly to a management method and apparatus for multiple USB ports, and an electronic device. Background Technology
[0002] In the field of electronic devices, USB (Universal Serial Bus) is a widely used interface technology that provides a convenient and efficient solution for data transmission between devices.
[0003] Currently, the native USB drivers for Android systems are primarily designed for devices with a single USB port (such as smartphones and tablets). In this traditional application scenario, the USB port follows a single-role principle: when the device is connected to a personal computer, the port acts as a Device, enabling file transfer; when the device is connected to a peripheral device such as a USB flash drive, the port switches to the Host role, reading data from the USB flash drive.
[0004] In this single-port architecture, the device can automatically and uniquely determine the data communication role of the port based on changes in the connected object, and ensure its stable operation. Because the role switching result is unique, no special prompts are needed to the user, thus guaranteeing a plug-and-play experience.
[0005] However, directly transplanting this design concept to devices with multiple USB ports reveals significant technical flaws. In scenarios where multiple ports operate in parallel, different USB ports may simultaneously connect peripherals with conflicting requirements: one port may require the device to act as a host, while another port may require it to act as a device. Due to limitations in the underlying driver architecture, the system cannot operate in both roles simultaneously, leading to conflicts in the role requirements between the ports.
[0006] Because a device can only select one role at a time, this results in the following: when the device is running in Host mode, all ports requiring the Device role are actually physically connected but in a suspended, inactive state; and vice versa. If the logic of "automatic switching without notification" is still used for single-port devices, users will not be able to intuitively determine which port's peripheral is currently active and which ports are in an invalid, suspended state. This lack of transparency severely impacts the user experience of multi-port devices, increasing user confusion and the risk of misoperation. Summary of the Invention
[0007] One of the objectives of this invention is to overcome the shortcomings of the prior art and provide a method, apparatus, and electronic device for managing multiple USB ports.
[0008] The technical solution provided by this invention is as follows: A method for managing multiple USB ports, for a device containing multiple USB ports, comprising: Monitor insertion and removal events for each USB port; When a USB port insertion or removal event is detected, the target working port is determined from all USB ports of connected external devices according to a preset arbitration rule, and the USB physical layer of the device is configured to operate in a role that matches the needs of the target working port; at the same time, the remaining non-target working ports are configured to be suspended. The device's display interface shows the real-time status of each USB port.
[0009] In some embodiments, when an insertion or removal event is detected at a USB port, determining the target working port from all USB ports of connected external devices according to a preset arbitration rule includes: When a USB port insertion event is detected, the data communication role of the USB port is identified; the data communication role includes a host role and a device role. Determine whether the data communication role of the USB port is consistent with the current data communication role of the device; the current data communication role of the device is determined according to the operating mode of the device's USB physical layer. If the data communication role of the USB port is inconsistent with the current data communication role, and the priority of the data communication role of the USB port is lower than the priority of the current data communication role, then the USB port is set as a non-target working port. The real-time status display of each USB port through the device's display interface includes: The device's display interface will prompt the user that the USB port is suspended.
[0010] In some embodiments, the method includes: if the data communication role of the USB port is inconsistent with the current data communication role, and the priority of the data communication role of the USB port is higher than the priority of the current data communication role, then the USB port is set as the target working port, the original target working port is changed to a non-target working port, and the current data communication role is switched. The real-time status display of each USB port through the device's display interface includes: The device's display interface indicates to the user that the USB port is active, while other USB ports that were previously active are suspended.
[0011] In some embodiments, the method includes: if the data communication role of the USB port is consistent with the current data communication role of the device, then the USB port is set as the target working port; The real-time status display of each USB port through the device's display interface includes: The device's display interface will indicate to the user that the USB port is in operation.
[0012] In some embodiments, after identifying the data communication role of the USB port, the method further includes: If the USB port does not support the data communication role, the user will be prompted through the device's display interface that the USB port does not support the corresponding function.
[0013] The step of determining whether the data communication role of the USB port is consistent with the current data communication role of the device includes: if the USB port supports the data communication role, then determining whether the data communication role of the USB port is consistent with the current data communication role of the device.
[0014] In some embodiments, when an insertion or removal event is detected at a USB port, determining the target working port from all USB ports of connected external devices according to a preset arbitration rule includes: When a USB port is detected to have been unplugged, the data communication path of that USB port is closed. Determine whether the data communication role of the USB port is consistent with the current data communication role of the device; If the data communication role of the USB port is consistent with the current data communication role, and it is the only USB port that is consistent with the current data communication role, and the device has a USB port that is inconsistent with the current data communication role, then the USB port that was originally a non-target working port will be changed to a target working port, and the current data communication role will be switched. The real-time status display of each USB port through the device's display interface includes: The device's display interface prompts the user to restore the previously suspended USB port to normal operation.
[0015] In some embodiments, including: If the data communication role of the USB port where the unplugging event occurs is consistent with the current data communication role, and the device also has other USB ports that are consistent with the current data communication role, then the current data transmission state of the device is maintained.
[0016] The present invention also provides a management device for multiple USB ports, comprising: The insertion and removal detection module is used to monitor insertion and removal events of each USB port; The communication arbitration module is used to determine the target working port from all USB ports of connected external devices according to preset arbitration rules when a USB port insertion or removal event is detected, and configure the USB physical layer of the device to operate in a role that matches the needs of the target working port; at the same time, the remaining non-target working ports are configured to be in a suspended state. The user notification module is used to display the real-time status of each USB port through the device's display interface.
[0017] In one embodiment, the communication arbitration module is further configured to, when an insertion event is detected at a USB port, identify the data communication role of the USB port; the data communication role includes a host role and a device role; determine whether the data communication role of the USB port is consistent with the current data communication role of the device; the current data communication role of the device is determined according to the operating mode of the USB physical layer of the device; if the data communication role of the USB port is inconsistent with the current data communication role, and the priority of the data communication role of the USB port is lower than the priority of the current data communication role, then the USB port is set as a non-target working port; The user notification module is also used to prompt the user that the USB port is suspended through the device's display interface.
[0018] The present invention also provides an electronic device, comprising: Memory, used to store computer programs; A processor for implementing the multi-USB port management method described in any of the foregoing embodiments when running a computer program.
[0019] The multi-USB port management method, apparatus, and electronic device provided by this invention can bring at least the following beneficial effects: By managing multiple USB ports through arbitration, reasonable scheduling of multi-port requests is achieved, making data communication between multiple USB ports stable and controllable. By introducing a status visualization mechanism for each USB port, the traditional "silent switching" mode of USB drivers is changed, transforming the original black-box "port suspension" state into visual information that users can perceive, thus improving the user experience. Attached Figure Description
[0020] The preferred embodiments will now be described in a clear and easy-to-understand manner, with reference to the accompanying drawings, to further explain the above-mentioned characteristics, technical features, advantages, and implementation methods of a multi-USB port management method and apparatus, and an electronic device.
[0021] Figure 1This is a flowchart of an embodiment of a multi-USB port management method of the present invention; Figure 2 This is a schematic diagram of one embodiment of a multi-USB port management device according to the present invention; Figure 3 This is a schematic diagram of the structure of an embodiment of an electronic device according to the present invention. Detailed Implementation
[0022] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the specific implementation methods of the present invention will be described below with reference to the accompanying drawings. Obviously, the drawings described below are merely some embodiments of the present invention. For those skilled in the art, other drawings and other implementation methods can be obtained based on these drawings without any creative effort.
[0023] To keep the drawings concise, only the parts relevant to the invention are shown schematically in each figure, and they do not represent the actual structure of the product. Furthermore, for ease of understanding, in some figures, components with the same structure or function are shown only schematically, or only one is labeled. In this document, "a" can mean not only "only one" but also "more than one".
[0024] One embodiment of the present invention, such as Figure 1 As shown, a method for managing multiple USB ports is provided for a device containing multiple USB ports, including: Step S100: Monitor insertion and removal events for each USB port; Step S200: When a USB port is detected to have an insertion or removal event, the target working port is determined from all USB ports of connected external devices according to the preset arbitration rules, and the USB physical layer of the device is configured to operate in a role that matches the needs of the target working port; at the same time, the remaining non-target working ports are configured to be in a suspended state. Step S300 displays the real-time status of each USB port through the device's display interface.
[0025] Specifically, the USB bus is based on a master-slave communication mechanism, and its data communication includes two operating modes: master mode and device mode. Under this mechanism, each USB port in the system can be configured as one of two data communication roles: a master role that actively initiates communication, or a device role that passively responds to commands.
[0026] Monitor the physical connection status of multiple USB ports on the device in real time. An insertion event refers to an event where an external device is inserted into a USB port, and an removal event refers to an event where an external device is removed from a USB port.
[0027] The type of external device inserted or removed determines the data communication role of the USB port required for normal communication. For example, if the external device inserted into the USB port is a PC, then the data communication role of the USB port is Device. If the external device removed is a USB flash drive, then the data communication role of the USB port is Host.
[0028] When a device has multiple USB ports, their data communication roles may conflict. When a USB port experiences an insertion or removal event, the original port conflict situation may change. Therefore, based on preset arbitration rules, the system re-determines which ports are target working ports and which are non-target working ports from all USB ports connected to external devices, and configures the device's USB physical layer to operate in a role matching the needs of the target working ports. A target working port may have one or more USB ports. The same applies to non-target working ports. For target working ports, the system establishes a data communication path for them, making them operational. For non-target working ports, the system suspends them, making them temporarily unavailable.
[0029] The "preset arbitration rules" can be flexibly adjusted according to the product definition. For example, they can be set to "prioritize keeping Host mode", "prioritize keeping Device mode", or "prioritize keeping the first connected device" to adapt to different application scenarios.
[0030] Then, the real-time status of each USB port is displayed on the device's display interface. For example, for the target working port, "Working" or the corresponding function icon is displayed; for ports that are not in the target working state, "Unavailable / Suspended" is displayed, and the reason for suspension can also be included; for unused ports, special marks such as gray are used. In this way, the user can be intuitively informed of the currently active ports and the reasons for the suspension of non-working ports.
[0031] For example, suppose a device with multiple USB ports is connected to both a computer (requiring the device to be in the Device role) and a USB flash drive (requiring the device to be in the Host role). Assuming the default arbitration rule is "Device takes precedence," the system configures the USB physical layer to Device mode. The computer's connection port works normally (displaying "Working"), while the USB flash drive port is suspended due to role mismatch. The interface displays "Suspended: USB flash drive connected, but current Device mode takes precedence," thus avoiding user confusion caused by the USB flash drive being inserted but unable to transfer files.
[0032] In this embodiment, arbitration management of multiple USB ports enables reasonable scheduling of requests from multiple ports, making data communication between multiple USB ports stable and controllable. By introducing a status visualization mechanism for each USB port, the traditional "silent switching" mode of USB drivers is changed, transforming the original black-box "port suspension" state into visual information that users can perceive, thus improving the user experience.
[0033] In one embodiment, step S200 includes: Step S2000: When an insertion event is detected at a USB port, process the insertion event at the USB port, including: Step S2100 identifies the data communication role of the USB port; the data communication role includes the host role and the device role; Step S2200: If the USB port supports the data communication role, then perform the following steps: Step S2210 determines whether the data communication role of the USB port is consistent with the current data communication role of the device; If step S2220 is consistent, then set the USB port as the target working port; If step S2230 is inconsistent, and the priority of the data communication role of the USB port is lower than the priority of the current data communication role, then the USB port is set as a non-target working port, and the target working port remains unchanged. If step S2240 is inconsistent, and the priority of the data communication role of the USB port is higher than the priority of the current data communication role, then set the USB port as the target working port, the original target working port as the non-target working port, and switch the current data communication role to the data communication role of the USB port.
[0034] Specifically, the data communication role of the USB port can be determined based on the type of external device inserted. It is then determined whether the USB port physically supports the desired data communication role. If the USB port does not support the data communication role, the user will be notified via the device's display interface that the USB port does not support the corresponding function.
[0035] If the USB port supports this data communication role, then further processing is required: Obtain the device's current data communication role: Determine the device's current data communication role based on the current operating mode of the device's USB physical layer. Corresponding to the USB communication operating mode, the USB physical layer also has two operating modes: host mode and device mode. If the current operating mode of the USB physical layer is host mode, the device's current data communication role is Host; if the current operating mode of the USB physical layer is device mode, the device's current data communication role is Device.
[0036] Determine whether the data communication role of the USB port is consistent with the current data communication role of the device.
[0037] If the data communication roles are consistent, then the USB port is set as the target working port, that is, the data communication path of the USB port is established, and the data transmission of the port is started. The user is also notified through the device's display interface that the USB port is working.
[0038] If the data communication roles are inconsistent, and the priority of the data communication role of the USB port is lower than the priority of the current data communication role of the device, then the USB port is set as a non-target working port, that is, the USB port is suspended. The user is also prompted by the device's display interface that the USB port is suspended. The reason for suspension may also be included, such as low priority or a high-priority function in use.
[0039] If the data communication roles are inconsistent, and the priority of the data communication role of this USB port is higher than the priority of the current data communication role, then this USB port is set as the target working port, the original target working port is changed to a non-target working port, the device's USB physical layer working mode and current data communication role are switched, the non-target working ports are suspended, the data communication path of this USB port is established, and data transmission of this USB port begins. The device's display interface also prompts the user that this USB port is working, and other previously working USB ports have been suspended because they were preempted by higher-priority functions.
[0040] In one embodiment, step S200 further includes: Step S3000: When a USB port unplugging event is detected, process the unplugging event of the USB port, including: Step S3100: Close the data communication path of the USB port; Step S3200 determines whether the data communication role of the USB port is consistent with the current data communication role of the device; If step S3210 is inconsistent, then maintain the current data transmission state of the device; If step S3220 is consistent, and the USB port is the only USB port that matches the current data communication role of the device, and the device has a USB port that does not match the current data communication role, then the USB port that was originally a non-target working port will be changed to a target working port, and the current data communication role will be switched to the data communication role of the target working port.
[0041] If step S3230 is consistent, and there are other USB ports that have the same role as the current data communication port, then the current data transmission state of the device is maintained.
[0042] Specifically, if the USB port where the unplugging event occurred has already established a data communication path, then the data communication path of that USB port is closed. If the USB port where the unplugging event occurred has not yet established a data communication path, then step S3100 can be omitted.
[0043] Determine whether the data communication role of the USB port where the unplugging event occurred is consistent with the current data communication role of the device. If they are inconsistent, maintain the current data transmission state of the device, that is, maintain the current data communication roles of the remaining target working ports. If they are consistent, in the scenario where the current data communication role of the device changes (as in step S3220), also prompt the user through the display interface to resume the previously suspended USB port. As in step S3230, maintain the current data communication roles of the remaining target working ports.
[0044] In this embodiment, by analyzing the plugging and unplugging events of the USB port, the device can communicate with the device connected to the USB port in a defined USB data communication type, avoiding the problem of communication state disorder caused by data communication role conflicts in multi-port scenarios, and making multi-port USB data communication stable and controllable. Furthermore, by displaying the interface to prompt the user with the current port's active and execution status, as well as the active and execution status of affected ports, the user experience in multi-port scenarios can be improved.
[0045] One embodiment of the present invention, such as Figure 2 As shown, a multi-USB port management device includes: The insertion and removal identification module 210 is used to monitor insertion and removal events of each USB port.
[0046] The communication arbitration module 220 is used to determine the target working port from all USB ports of connected external devices according to preset arbitration rules when a USB port insertion or removal event is detected, and configure the USB physical layer of the device to operate in a role that matches the needs of the target working port; at the same time, the remaining non-target working ports are configured to be in a suspended state. User notification module 230 is used to display the real-time status of each USB port through the device's display interface.
[0047] In one embodiment, the communication arbitration module is further configured to, when an insertion event is detected at a USB port, identify the data communication role of the USB port; the data communication role includes a host role and a device role; determine whether the data communication role of the USB port is consistent with the current data communication role of the device; the current data communication role of the device is determined according to the operating mode of the USB physical layer of the device; if the data communication role of the USB port is inconsistent with the current data communication role, and the priority of the data communication role of the USB port is lower than the priority of the current data communication role, then the USB port is set as a non-target working port; The user notification module is also used to notify the user that the USB port is suspended through the device's display interface.
[0048] In one embodiment, the communication arbitration module is further configured to, if the data communication role of the USB port is inconsistent with the current data communication role, and the priority of the data communication role of the USB port is higher than the priority of the current data communication role, then set the USB port as the target working port, change the original target working port to a non-target working port, and switch the current data communication role. The user notification module is also used to notify the user through the device's display interface that the USB port is working, and other USB ports that were previously working are suspended.
[0049] In one embodiment, the communication arbitration module is further configured to set the USB port as the target working port if the data communication role of the USB port is consistent with the current data communication role of the device. The user notification module is also used to notify the user that the USB port is working through the device's display interface.
[0050] In one embodiment, the user notification module is further configured to prompt the user through the device's display interface if the USB port does not support the required data communication role; The communication arbitration module is also used to determine whether the data communication role of the USB port is consistent with the current data communication role of the device if the USB port supports the data communication role.
[0051] In one embodiment, the communication arbitration module is further configured to close the data communication path of a USB port when a USB port unplugging event is detected. Determine whether the data communication role of the USB port is consistent with the current data communication role of the device; If the data communication role of the USB port is consistent with the current data communication role, and it is the only USB port that is consistent with the current data communication role, and the device has a USB port that is inconsistent with the current data communication role (i.e., a non-target working port), then the USB port that was originally a non-target working port will be changed to a target working port, and the current data communication role will be switched. The user notification module is also used to prompt users through the device's display interface that previously suspended USB ports have been restored to work.
[0052] In one embodiment, the communication arbitration module is further configured to maintain the current data transmission state of the device when the data communication role of the USB port where the unplugging event occurred is consistent with the current data communication role, and there are other USB ports on the device that are consistent with the current data communication role.
[0053] It should be noted that the embodiments of the multi-USB port management device provided by this invention and the embodiments of the multi-USB port management method described above are both based on the same inventive concept and can achieve the same technical effects. Therefore, other specific details of the embodiments of the multi-USB port management device can be found in the description of the embodiments of the multi-USB port management method described above.
[0054] Another embodiment of the present invention, such as Figure 3 As shown, an electronic device 100 includes a memory 110 and a processor 130; Memory 110 is used to store computer program 120; The processor 130 is used to implement any of the multi-USB port management methods provided in the embodiments of this application when running the computer program 120.
[0055] Memory can be any internal storage unit and / or external storage device capable of storing data and programs. For example, memory can be a plug-in hard drive, a smart memory card (SMC), a flash memory card, an SD card, etc.
[0056] Depending on the requirements, the processor can be a central processing unit (CPU), a graphics processing unit (GPU), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a general-purpose processor, or other logic devices.
[0057] This application also provides a product including a computer program, which, when run on an electronic device, enables the electronic device to implement any of the multi-USB port management methods provided in this application.
[0058] It should be noted that the above embodiments can be freely combined as needed. The above description is only a preferred embodiment of the present invention. It should be pointed out that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for managing multiple USB ports, used in a device containing multiple USB ports, characterized in that, include: Monitor insertion and removal events for each USB port; When a USB port insertion or removal event is detected, the target working port is determined from all USB ports of connected external devices according to a preset arbitration rule, and the USB physical layer of the device is configured to operate in a role that matches the needs of the target working port; at the same time, the remaining non-target working ports are configured to be suspended. The device's display interface shows the real-time status of each USB port.
2. The management method for multiple USB ports according to claim 1, characterized in that, When a USB port insertion or removal event is detected, the target working port is determined from all USB ports of connected external devices according to a preset arbitration rule, including: When a USB port insertion event is detected, the data communication role of the USB port is identified; the data communication role includes a host role and a device role. Determine whether the data communication role of the USB port is consistent with the current data communication role of the device; the current data communication role of the device is determined according to the operating mode of the device's USB physical layer. If the data communication role of the USB port is inconsistent with the current data communication role, and the priority of the data communication role of the USB port is lower than the priority of the current data communication role, then the USB port is set as a non-target working port. The real-time status display of each USB port through the device's display interface includes: The device's display interface will prompt the user that the USB port is suspended.
3. The management method for multiple USB ports according to claim 2, characterized in that, include: If the data communication role of the USB port is inconsistent with the current data communication role, and the priority of the data communication role of the USB port is higher than the priority of the current data communication role, then the USB port is set as the target working port, the original target working port is changed to a non-target working port, and the current data communication role is switched. The real-time status display of each USB port through the device's display interface includes: The device's display interface indicates to the user that the USB port is active, while other USB ports that were previously active are suspended.
4. The management method for multiple USB ports according to claim 2, characterized in that, include: If the data communication role of the USB port is consistent with the current data communication role of the device, then the USB port is set as the target working port; The real-time status display of each USB port through the device's display interface includes: The device's display interface will indicate to the user that the USB port is in operation.
5. The method for managing multiple USB ports according to claim 2, characterized in that, After identifying the data communication role of the USB port, the following is also included: If the USB port does not support the data communication role, the user will be prompted through the device's display interface that the USB port does not support the corresponding function; The step of determining whether the data communication role of the USB port is consistent with the current data communication role of the device includes: if the USB port supports the data communication role, then determining whether the data communication role of the USB port is consistent with the current data communication role of the device.
6. The method for managing multiple USB ports according to claim 1, characterized in that, When a USB port insertion or removal event is detected, the target working port is determined from all USB ports of connected external devices according to a preset arbitration rule, including: When a USB port is detected to have been unplugged, the data communication path of that USB port is closed. Determine whether the data communication role of the USB port is consistent with the current data communication role of the device; If the data communication role of the USB port is consistent with the current data communication role, and it is the only USB port that is consistent with the current data communication role, and the device has a USB port that is inconsistent with the current data communication role, then the USB port that was originally a non-target working port will be changed to a target working port, and the current data communication role will be switched. The real-time status display of each USB port through the device's display interface includes: The device's display interface prompts the user to restore the previously suspended USB port to normal operation.
7. The method for managing multiple USB ports according to claim 6, characterized in that, include: If the data communication role of the USB port where the unplugging event occurs is consistent with the current data communication role, and the device also has other USB ports that are consistent with the current data communication role, then the current data transmission state of the device is maintained.
8. A management device for multiple USB ports, characterized in that, include: The insertion and removal detection module is used to monitor insertion and removal events of each USB port; The communication arbitration module is used to determine the target working port from all USB ports of connected external devices according to preset arbitration rules when a USB port insertion or removal event is detected, and configure the USB physical layer of the device to operate in a role that matches the needs of the target working port; at the same time, the remaining non-target working ports are configured to be in a suspended state. The user notification module is used to display the real-time status of each USB port through the device's display interface.
9. The management device for multiple USB ports according to claim 8, characterized in that, The communication arbitration module is further configured to identify the data communication role of a USB port when an insertion event is detected; the data communication role includes a host role and a device role; determine whether the data communication role of the USB port is consistent with the current data communication role of the device; the current data communication role of the device is determined according to the operating mode of the USB physical layer of the device; if the data communication role of the USB port is inconsistent with the current data communication role, and the priority of the data communication role of the USB port is lower than the priority of the current data communication role, then the USB port is set as a non-target working port; The user notification module is also used to prompt the user that the USB port is suspended through the device's display interface.
10. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for implementing the management method for multiple USB ports as described in any one of claims 1 to 7 when running a computer program.