Bluetooth device sharing method and apparatus, electronic device, and storage medium
By registering a data transmission module in the host operating system, capturing Bluetooth data from the virtual machine operating system, and transmitting it through a unique Bluetooth protocol stack, the problem of poor data transmission quality caused by frequent switching of Bluetooth protocol stacks in multiple operating systems is solved, achieving more efficient data transmission.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ECARX (HUBEI) TECHCO LTD
- Filing Date
- 2023-08-14
- Publication Date
- 2026-07-24
AI Technical Summary
In electronic devices with multiple operating systems, frequent switching of the Bluetooth protocol stack results in poor data transmission performance.
Register a data transmission module in the host operating system to capture Bluetooth data from the virtual machine operating system and transmit it to Bluetooth devices through a unique Bluetooth protocol stack, thus avoiding frequent switching of the Bluetooth protocol stack.
It improves the data transmission performance of multiple virtual machine operating systems sharing Bluetooth devices, reduces the switching frequency of the Bluetooth protocol stack, and improves data transmission efficiency.
Smart Images

Figure CN116828434B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of vehicle computer technology, and more particularly to a Bluetooth device sharing method, apparatus, electronic device, and storage medium. Background Technology
[0002] Electronic devices can use virtualization technology to run multiple operating systems simultaneously. These multiple operating systems can share hardware resources, such as sharing a graphics processing unit (GPU) in a vehicle or sharing Bluetooth devices.
[0003] In some implementations, electronic devices need to transmit data with Bluetooth devices via a Bluetooth protocol stack. For electronic devices running multiple operating systems, a Bluetooth protocol stack needs to run in each operating system. If operating system 1 in the electronic device needs to transmit data with a Bluetooth device, then operating system 1 transmits data with the Bluetooth device through Bluetooth protocol stack 1 running in operating system 1. If operating system 2 in the electronic device needs to transmit data with a Bluetooth device, then after operating system 1 completes its data transmission, operating system 2 transmits data with the Bluetooth device through Bluetooth protocol stack 2 running in operating system 2, thus enabling multiple operating systems to share a Bluetooth device.
[0004] However, in the above implementation, when multiple operating systems share a Bluetooth device, there may be frequent switching of the Bluetooth protocol stack to enable different operating systems to transmit data with the Bluetooth device, which may result in poor data transmission performance. Summary of the Invention
[0005] This application provides a Bluetooth device sharing method, apparatus, electronic device, and storage medium, which can improve the efficiency of Bluetooth data transmission.
[0006] In a first aspect, embodiments of this application provide a Bluetooth device sharing method, applied to an electronic device, wherein the electronic device runs a host operating system and multiple virtual machine operating systems, and a first virtual machine operating system among the multiple virtual machine operating systems runs a Bluetooth protocol stack, including:
[0007] The data transmission module in the host operating system captures the first data to be transmitted to the Bluetooth device by the second virtual machine operating system, wherein the second virtual machine operating system is at least one virtual machine operating system other than the first virtual machine operating system among the plurality of virtual machine operating systems.
[0008] The first data is transmitted to the Bluetooth protocol stack via the data transmission module.
[0009] The first data is transmitted to the Bluetooth device via the Bluetooth protocol stack.
[0010] In one possible implementation, the data transmission module includes a hook module that runs in the virtualization driver backend of the host operating system, and the virtualization driver backend is paired with the virtualization driver frontend in the second virtual machine operating system.
[0011] The step of capturing the first data to be transmitted from the second virtual machine operating system to the Bluetooth device through the data transmission module in the host operating system includes:
[0012] The hook module captures the first data to be transmitted to the Bluetooth device in the virtualization driver front-end of the second virtual machine operating system. The first data is generated by an application in the second virtual machine operating system.
[0013] In one possible implementation, the data transmission module includes a hook module, and the method further includes:
[0014] When a Bluetooth device is detected to be connected, the virtual machine operating system that needs to transmit data with the Bluetooth device is detected.
[0015] When it is detected that the virtual machine operating system that needs to transmit data with the Bluetooth device is a second virtual machine operating system, a hook module is registered in the virtualization driver backend of the host operating system.
[0016] In one possible implementation, a Bluetooth device management module runs in the first virtual machine operating system, and a hook processing module runs in the host operating system;
[0017] When a Bluetooth device is detected to be connected, the step of detecting the virtual machine operating system that needs to transmit data with the Bluetooth device includes:
[0018] The Bluetooth device management module detects whether any Bluetooth devices are connected.
[0019] When the Bluetooth device management module detects that a Bluetooth device has been connected, it controls the hook processing module to detect whether there is a virtual machine operating system that needs to transmit data to the Bluetooth device.
[0020] In one possible implementation, when it is detected that the virtual machine operating system that needs to transmit data with the Bluetooth device is a second virtual machine operating system, a hook module is registered in the virtualization driver backend of the host operating system, including:
[0021] When the hook processing module detects that the second virtual machine operating system needs to transmit data to the Bluetooth device, it registers the hook module in the virtualization driver backend of the host operating system.
[0022] In one possible implementation, a first Bluetooth data processing module runs in the host operating system, and a second Bluetooth data processing module runs in the first virtual machine operating system; the method further includes:
[0023] When the hook module is successfully registered, the hook processing module controls the first Bluetooth data processing module and the hook module to establish a first data connection, and controls the first Bluetooth data processing module and the second Bluetooth data processing module to establish a second data connection.
[0024] The second Bluetooth data processing module is controlled to establish a third data connection with the Bluetooth protocol stack.
[0025] In one possible implementation, transmitting the first data to the Bluetooth protocol stack via the data transmission module includes:
[0026] The first data is transmitted to the first Bluetooth data processing module via the hook module and the first data connection.
[0027] The first received data is transmitted to the second Bluetooth data processing module through the first Bluetooth data processing module and the second data connection.
[0028] The first data is transmitted to the Bluetooth protocol stack via the second Bluetooth data processing module and the third data connection.
[0029] In one possible implementation, the method further includes:
[0030] The hook module captures second data from the first Bluetooth data processing module. The second data is transmitted from the Bluetooth device to the first Bluetooth data processing module through the Bluetooth protocol stack and the second Bluetooth data processing module.
[0031] The hook module transmits the second data to the second virtual machine operating system via the virtualization driver front-end.
[0032] In one possible implementation, the first virtual machine operating system runs a Bluetooth device management module and a second Bluetooth data processing module, and the method further includes:
[0033] When the first virtual machine operating system is detected as the virtual machine operating system that needs to transmit data with the Bluetooth device, the Bluetooth device management module controls the second Bluetooth data processing module to establish a third data connection with the Bluetooth protocol stack.
[0034] The Bluetooth device management module obtains third data from the first virtual machine operating system that is to be transmitted to the Bluetooth device, and the third data is generated by an application in the first virtual machine operating system.
[0035] The third data is transmitted to the second Bluetooth data processing module via the Bluetooth device management module.
[0036] The third data is transmitted to the Bluetooth protocol stack via the second Bluetooth data processing module and the third data connection.
[0037] The third data is transmitted to the Bluetooth device via the Bluetooth protocol stack.
[0038] In one possible implementation, the method further includes:
[0039] The Bluetooth protocol stack is used to receive multiple fourth data, which come from at least two virtual machine operating systems.
[0040] The Bluetooth protocol stack transmits the plurality of fourth data to the Bluetooth device according to the priority of the application to which the plurality of fourth data belong.
[0041] Alternatively, the plurality of fourth data may be transmitted to the Bluetooth device simultaneously.
[0042] In one possible implementation, the method further includes:
[0043] When the Bluetooth device management module detects that the Bluetooth device has disconnected from the electronic device, the Bluetooth device management module controls the hook processing module to unregister the hook module in the host operating system.
[0044] In one possible implementation, the method further includes:
[0045] When the hook module successfully logs out, the hook processing module controls the disconnection of the first data connection between the first Bluetooth data processing module and the hook module, the second data connection between the first Bluetooth data processing module and the second Bluetooth data processing module, and the third data connection between the second Bluetooth data processing module and the Bluetooth protocol stack.
[0046] Secondly, embodiments of this application provide a Bluetooth device sharing device, the Bluetooth device sharing device comprising:
[0047] The acquisition module is used to capture first data to be transmitted to the Bluetooth device by the data transmission module in the host operating system. The second virtual machine operating system is at least one virtual machine operating system other than the first virtual machine operating system among the plurality of virtual machine operating systems.
[0048] A transmission module is used to transmit the first data to the Bluetooth protocol stack via the data transmission module; and to transmit the first data to the Bluetooth device via the Bluetooth protocol stack.
[0049] In one possible implementation, the data transmission module includes a hook module that runs in the virtualization driver backend of the host operating system. The virtualization driver backend is paired with the virtualization driver frontend in the second virtual machine operating system. Specifically, the acquisition module uses the hook module to capture the first data to be transmitted to the Bluetooth device in the virtualization driver frontend of the second virtual machine operating system. The first data is generated by an application in the second virtual machine operating system.
[0050] In one possible implementation, the data transmission module includes a hook module, and the device further includes a registration module. The registration module is specifically used to detect the virtual machine operating system that needs to transmit data with the Bluetooth device when a Bluetooth device is detected to be connected; and to register the hook module in the virtualization driver backend of the host operating system when the virtual machine operating system that needs to transmit data with the Bluetooth device is detected to be a second virtual machine operating system.
[0051] In one possible implementation, a Bluetooth device management module runs in the first virtual machine operating system, and a hook processing module runs in the host operating system; the registration module is specifically used to detect whether a Bluetooth device is connected through the Bluetooth device management module; when the Bluetooth device management module detects that a Bluetooth device is connected, it controls the hook processing module to detect whether there is a virtual machine operating system that needs to transmit data to the Bluetooth device.
[0052] In one possible implementation, the registration module is specifically used to register the hook module in the virtualization driver backend of the host operating system when the hook processing module detects that the second virtual machine operating system needs to transmit data to the Bluetooth device.
[0053] In one possible implementation, a first Bluetooth data processing module runs in the host operating system, and a second Bluetooth data processing module runs in the first virtual machine operating system; the device further includes a control module, which is used to control the first Bluetooth data processing module and the hook module to establish a first data connection when the hook module is successfully registered, and to control the first Bluetooth data processing module and the second Bluetooth data processing module to establish a second data connection; and to control the second Bluetooth data processing module to establish a third data connection with the Bluetooth protocol stack.
[0054] In one possible implementation, the transmission module is specifically used to transmit the first data to the first Bluetooth data processing module via the hook module and the first data connection; transmit the received first data to the second Bluetooth data processing module via the first Bluetooth data processing module and the second data connection; and transmit the first data to the Bluetooth protocol stack via the second Bluetooth data processing module and the third data connection.
[0055] In one possible implementation, the acquisition module is further configured to capture second data from the first Bluetooth data processing module via the hook module. This second data is transmitted from the Bluetooth device to the first Bluetooth data processing module via the Bluetooth protocol stack and the second Bluetooth data processing module. The transmission module is further configured to transmit the second data to the second virtual machine operating system via the virtualization driver front-end through the hook module.
[0056] In one possible implementation, the first virtual machine operating system runs a Bluetooth device management module and a second Bluetooth data processing module.
[0057] The control module is further configured to, when it detects that the virtual machine operating system that needs to transmit data with the Bluetooth device is the first virtual machine operating system, control the second Bluetooth data processing module to establish a third data connection with the Bluetooth protocol stack through the Bluetooth device management module.
[0058] The acquisition module is further configured to acquire third data to be transmitted to the Bluetooth device from the first virtual machine operating system through the Bluetooth device management module, wherein the third data is generated by an application in the first virtual machine operating system.
[0059] The transmission module is further configured to transmit the third data to the second Bluetooth data processing module via the Bluetooth device management module; transmit the third data to the Bluetooth protocol stack via the second Bluetooth data processing module and the third data connection; and transmit the third data to the Bluetooth device via the Bluetooth protocol stack.
[0060] In one possible implementation, the transmission module is further configured to receive multiple fourth data sources from at least two virtual machine operating systems via the Bluetooth protocol stack. The Bluetooth protocol stack then transmits the multiple fourth data sources to the Bluetooth device according to the priority of the applications to which they belong; or, simultaneously transmits the multiple fourth data sources to the Bluetooth device.
[0061] In one possible implementation, the control module is further configured to, when the Bluetooth device management module detects that the Bluetooth device has disconnected from the electronic device, control the hook processing module to unregister the hook module in the host operating system.
[0062] In one possible implementation, the control module is further configured to, when the hook module successfully logs out, control the disconnection of the first data connection between the first Bluetooth data processing module and the hook module, the second data connection between the first Bluetooth data processing module and the second Bluetooth data processing module, and the third data connection between the second Bluetooth data processing module and the Bluetooth protocol stack via the hook processing module.
[0063] Thirdly, embodiments of this application also provide an electronic device, which includes: a processor and a memory communicatively connected to the processor;
[0064] The memory stores computer-executed instructions;
[0065] The processor executes computer execution instructions stored in the memory to implement the method described in any possible implementation of the first aspect above.
[0066] Fourthly, embodiments of this application also provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the method described in any possible implementation of the first aspect.
[0067] Therefore, this application provides a Bluetooth device sharing method, apparatus, electronic device, and storage medium, applied to an electronic device. The electronic device runs a host operating system and multiple virtual machine operating systems. A first virtual machine operating system runs a Bluetooth protocol stack. The method includes: when a Bluetooth device is detected to be connected, registering a data transmission module in the host operating system; capturing first data to be transmitted to the Bluetooth device in a second virtual machine operating system through the data transmission module, wherein the second virtual machine operating system is at least one of the multiple operating systems other than the first virtual machine operating system; transmitting the first data to the Bluetooth protocol stack through the data transmission module; and transmitting the first data to the Bluetooth device through the Bluetooth protocol stack. The method provided in this application allows for data transmission between the virtual machine operating systems and the Bluetooth device when sharing a Bluetooth device. This data transmission module can capture data transmitted between the virtual machine operating system and the Bluetooth device, thereby enabling data transmission between the virtual machine operating system and the Bluetooth device through the Bluetooth protocol stack running in the first virtual machine operating system. This eliminates the need for the Bluetooth protocol stack to run in only one of the multiple virtual machine operating systems, improving data transmission efficiency. Attached Figure Description
[0068] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0069] Figure 1 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;
[0070] Figure 2 A flowchart illustrating a Bluetooth device sharing method provided in an embodiment of this application;
[0071] Figure 3 This application provides a schematic flowchart of a method for data transmission between a second virtual machine operating system and a Bluetooth device, as illustrated in an embodiment of the present application.
[0072] Figure 4 This application provides a schematic flowchart of a method for data transmission between a first virtual machine operating system and a Bluetooth device, as illustrated in an embodiment of the present application.
[0073] Figure 5 This is a schematic diagram of the structure of another electronic device provided in an embodiment of this application;
[0074] Figure 6 A flowchart illustrating another Bluetooth device sharing method provided in an embodiment of this application;
[0075] Figure 7A flowchart illustrating a method for disconnecting a Bluetooth device from an electronic device, provided in an embodiment of this application;
[0076] Figure 8 A schematic diagram illustrating the data flow between a virtual machine operating system and a Bluetooth headset, provided as an embodiment of this application;
[0077] Figure 9 This is a schematic diagram of the structure of a Bluetooth device sharing device provided in an embodiment of this application;
[0078] Figure 10 This is a schematic diagram of another electronic device structure provided in an embodiment of this application.
[0079] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0080] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0081] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.
[0082] In the embodiments of this application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone, where A and B can be singular or plural. In the textual description of this application, the character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0083] Virtualization technology has revolutionized the automotive electronics ecosystem by enabling resource sharing and secure isolation. For electronic devices running multiple virtual machine operating systems, hardware resources such as the central processing unit (CPU), memory, GPU, and input / output (e.g., Bluetooth devices) can all be shared through virtualization technology.
[0084] Electronic devices in a virtualization architecture typically include a host virtual machine operating system and multiple guest virtual machine operating systems. These operating systems run on the same hardware devices. Device virtualization technology allows each virtual machine operating system to share access to real hardware resources, such as GPUs and input / output devices, through virtualized hardware.
[0085] Bluetooth devices, as peripheral input / output devices, require virtualization if they need to be shared by multiple virtual machine operating systems. The Bluetooth protocol used for data transmission with Bluetooth devices in electronic devices consists of two parts: the Bluetooth protocol stack (Host) and the Bluetooth control module (Controller). The actual hardware part is the Controller, while the Bluetooth protocol stack is the software part running on a virtual machine operating system.
[0086] In some implementations, for electronic devices running multiple operating systems, a Bluetooth protocol stack can be run in each operating system, and a controller can be set up in the electronic device. If operating system 1 needs to transmit data with a Bluetooth device, operating system 1 establishes a connection with the controller through Bluetooth protocol stack 1 running in operating system 1, so that data transmission can occur through the controller. If operating system 2 needs to transmit data with a Bluetooth device, after operating system 1 completes data transmission and Bluetooth protocol stack 1 disconnects from the controller, operating system 2 establishes a connection with the controller through Bluetooth protocol stack 2 running in operating system 2, so that data transmission can occur through the controller.
[0087] However, in the above implementation, when multiple operating systems share a Bluetooth device, there may be frequent switching of the Bluetooth protocol stack. For example, if operating system 1 and operating system 2 alternately transmit data with the Bluetooth device for 2 seconds, it is necessary to frequently switch the Bluetooth protocol stack connected to the controller, which may cause data loss during data transmission and result in poor data transmission performance.
[0088] Based on this, this application provides a Bluetooth sharing method that runs the Bluetooth protocol stack only in one of multiple virtual machine operating systems. Since the host system can interact with each virtual machine operating system, a data transmission module for data capture is registered in the host system. Thus, when a Bluetooth device connects to an electronic device, the data transmission module in the host system can capture data from the virtual machine operating system to be transmitted to the Bluetooth device and transmit it to the Bluetooth device. When multiple virtual machine operating systems alternately transmit data with the Bluetooth device, multiple virtual machine operating systems can share the Bluetooth device without switching Bluetooth protocol stacks, improving the efficiency of Bluetooth data transmission.
[0089] It should be noted that the Bluetooth devices provided in this application embodiment may include Bluetooth headsets, Bluetooth keyboards, Bluetooth mice and other devices, and this application embodiment does not specifically limit the Bluetooth devices.
[0090] The Bluetooth device sharing method provided in this application will now be described in detail through specific embodiments. It is understood that the following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0091] The Bluetooth device sharing method provided in this application can be applied to electronic devices running multiple operating systems.
[0092] For example, Figure 1 A schematic diagram of the structure of an electronic device is shown.
[0093] like Figure 1 As shown, the electronic device runs a host operating system and multiple virtual machine operating systems. These virtual machine operating systems may include a first virtual machine operating system, virtual machine operating system 1, virtual machine operating system 2, ..., virtual machine operating system N. The first virtual machine operating system runs a Bluetooth protocol stack.
[0094] For example, a data transmission module may run in the host operating system. This data transmission module may be established in the host operating system when the electronic device detects that a Bluetooth device has been connected.
[0095] The data transmission module can be used to capture Bluetooth data generated by the operating system other than the first virtual machine operating system, and can transmit Bluetooth data to the Bluetooth protocol stack.
[0096] The Bluetooth protocol stack can be used to transmit data with Bluetooth devices, transferring received Bluetooth data to the Bluetooth devices.
[0097] based on Figure 1As shown, when an electronic device detects a Bluetooth device connected, it can register a data transmission module in the host operating system. This data transmission module can capture Bluetooth data from virtual machine operating systems other than the first virtual machine operating system and transmit the captured Bluetooth data to the Bluetooth protocol stack in the first virtual machine operating system. When the Bluetooth protocol stack receives the Bluetooth data, it can transmit the Bluetooth data to the Bluetooth device.
[0098] In one possible implementation, when virtual machine operating system 1 and virtual machine operating system 2 in multiple virtual machine operating systems alternately transmit data with a Bluetooth device, the Bluetooth data of virtual machine operating system 1 and virtual machine operating system 2 can be captured by the data transmission module, and the Bluetooth data can be transmitted to the Bluetooth device through the Bluetooth protocol stack in the first virtual machine operating system.
[0099] It is understood that an electronic device can connect to multiple Bluetooth devices. In this embodiment of the application, the electronic device may register a data transmission module in the host operating system when the first connected Bluetooth device is detected.
[0100] Thus, the Bluetooth device sharing method provided in this application embodiment enables multiple virtual machine operating systems to share Bluetooth devices by running a Bluetooth protocol stack in any one of the multiple virtual machine operating systems and registering a data transmission module in the host operating system. This eliminates the need to run a Bluetooth protocol stack in each virtual machine operating system and avoids frequent switching of the Bluetooth protocol stack.
[0101] based on Figure 1 The structure of the electronic device shown is illustrated below. The Bluetooth device sharing method provided in the embodiments of this application will be described in detail below. Figure 2 This is a flowchart illustrating a Bluetooth device sharing method provided in an embodiment of this application. The Bluetooth device sharing method can be executed by software and / or hardware devices. For example, the hardware device can be a Bluetooth device sharing device, which can be an electronic device or a processing chip within an electronic device. For an example, please refer to [link to example]. Figure 2 As shown, the Bluetooth device sharing method may include:
[0102] S201. Capture the first data to be transmitted from the second virtual machine operating system to the Bluetooth device through the data transmission module in the host operating system.
[0103] The second virtual machine operating system is at least one virtual machine operating system other than the first virtual machine operating system. The first data to be transmitted to the Bluetooth device in the second virtual machine operating system can be the first data that an application running in the second virtual machine operating system needs to transmit to the Bluetooth device.
[0104] In this embodiment of the application, the data transmission module can be used to capture Bluetooth data from the virtual machine operating system and transmit the captured Bluetooth data to the Bluetooth device through the Bluetooth protocol stack.
[0105] For example, when an electronic device captures the first data to be transmitted to a Bluetooth device in a second virtual machine operating system through a data transmission module, the electronic device can also capture the data that the application running in the second virtual machine operating system needs to transmit to the Bluetooth device.
[0106] In this embodiment, the electronic device may employ a front-end / back-end separated virtualization driver device virtualization mode. When the electronic device adopts this mode, a virtualization driver front-end can run in the virtual machine operating system, and correspondingly, a virtualization driver back-end can run in the host virtual system. Thus, the data transmission module can be a module registered in the virtualization driver back-end of the host system.
[0107] For example, when an electronic device adopts a device virtualization mode with a front-end and back-end separated virtualization driver, the virtualization driver front-end in the virtual machine operating system can pass through the data that needs to be transmitted to the Bluetooth device to the virtualization driver back-end, so that the data transmission module registered in the virtualization back-end can capture the Bluetooth data passed through by the virtualization driver front-end to the virtualization back-end.
[0108] It is understandable that a data transmission module can be registered in the host system before data is acquired through the data transmission module.
[0109] For example, when an electronic device detects that a Bluetooth device has been connected, the electronic device can further detect whether there is a virtual machine operating system among multiple virtual machine operating systems that needs to interact with the Bluetooth device.
[0110] For example, an electronic device can detect the running status of applications in various virtual machine operating systems. When an application that needs to transmit data with a Bluetooth device is running, it can be determined that the virtual machine operating system in which the application is running is the virtual machine operating system that needs to interact with the Bluetooth device.
[0111] For example, if the Bluetooth device is a Bluetooth headset, when the electronic device detects that a music application is running, that is, when the music application is playing music, the electronic device can determine that the virtual machine operating system on which the music application is running is the virtual machine operating system that needs to interact with the Bluetooth headset.
[0112] It should be noted that the embodiments in this application are only used as an example to illustrate the determination of the virtual machine operating system that needs to transmit data with the Bluetooth device by detecting the running status of the application, but do not constitute any limitation.
[0113] For example, the electronic device in this application may be connected to multiple Bluetooth devices. In the scenario where multiple Bluetooth devices are connected to the electronic device, the electronic device can execute the above-mentioned registration data transmission module process when it detects the first connected Bluetooth device.
[0114] S202, The first data is transmitted to the Bluetooth protocol stack via the data transmission module.
[0115] Based on the first data captured by the data transmission module in step S201 above, the electronic device can transmit the first data to the Bluetooth protocol stack through the data transmission module.
[0116] For example, both the host system and the first virtual machine operating system can run Bluetooth data processing modules. When a Bluetooth device is connected to an electronic device, data can be transmitted between the Bluetooth data processing module and the data transmission module in the host system, and data can be transmitted between the Bluetooth data processing module and the Bluetooth protocol stack in the first virtual machine operating system. This allows the first data to be sequentially sent to the Bluetooth protocol stack via the data transmission module, the Bluetooth data processing module in the host system, and the Bluetooth data processing module in the first virtual machine operating system.
[0117] S203. Transmit the first data to the Bluetooth device via the Bluetooth protocol stack.
[0118] In this embodiment, the first virtual machine operating system in the electronic device runs a Bluetooth protocol stack, while other virtual machine operating systems do not need to run a Bluetooth protocol stack.
[0119] For example, when an electronic device transmits the first data to a Bluetooth device via the Bluetooth protocol stack, the electronic device can transmit the first data to a Bluetooth controller via the Bluetooth protocol stack, and the controller can then transmit the first data to a Bluetooth device.
[0120] Therefore, the Bluetooth device sharing method provided in this application, by running a Bluetooth protocol stack in a first virtual machine operating system among multiple virtual machine operating systems, allows a data transmission module that can be used to acquire and transmit Bluetooth data to be registered in the host system when a Bluetooth device connects. In this way, the electronic device can obtain the data that each virtual machine operating system needs to transmit to the Bluetooth device through the data transmission module and transmit it to the Bluetooth device through a unique Bluetooth protocol stack. This eliminates the need to run multiple Bluetooth protocol stacks, and in scenarios where multiple virtual machine operating systems alternately transmit data with Bluetooth devices, frequent switching of the Bluetooth protocol stack is avoided, improving the efficiency of data transmission between the electronic device and the Bluetooth device.
[0121] In this embodiment, the data transmission module may include a hook module. Taking a device virtualization mode with a front-end and back-end separated virtualization driver as an example, when the electronic device detects a Bluetooth device connection, it can detect the virtual machine operating system that needs to transmit data with the Bluetooth device.
[0122] In one possible implementation, when the virtual machine operating system that needs to transmit data with the Bluetooth device is detected to be a second virtual machine operating system, a hook module can be registered in the virtualization driver backend of the host operating system. The virtualization driver backend is paired with the virtualization driver frontend in the second virtual machine operating system.
[0123] The hook module can be used to capture data from the virtualization driver front end and transmit the captured data to the Bluetooth protocol stack module.
[0124] It should be noted that the virtualization driver backend in the host system can be paired with the virtualization driver frontend in any virtual machine operating system.
[0125] In this way, since data transmission between the virtual machine operating system and the host system can be achieved through transparent transmission between the virtualization driver front-end and the virtualization driver back-end, and when the virtual machine operating system that needs to transmit data with the Bluetooth device is a virtual machine operating system other than the first virtual machine operating system, a hook module is registered in the virtualization driver back-end of the host operating system. This allows the hook module to capture the data transparently transmitted from the virtualization driver front-end to the virtualization driver back-end, enabling the virtual machine operating system to transmit Bluetooth data to the Bluetooth device. This allows multiple virtual machine operating systems to share a Bluetooth device without running multiple Bluetooth protocol stacks.
[0126] For example, a Bluetooth device management module runs in the first virtual machine operating system, and a hook processing module runs in the host operating system. When a Bluetooth device is detected to be connected, the virtual machine operating system that needs to transmit data with the Bluetooth device is detected, which can be done through the Bluetooth device management module. When the Bluetooth device management module detects that a Bluetooth device is connected, it controls the hook processing module to detect whether a virtual machine operating system that needs to transmit data to the Bluetooth device exists.
[0127] In this way, the Bluetooth device management module running on the first virtual machine operating system detects Bluetooth device access, and controls the hook processing module to detect the virtual machine operating system that needs to transmit data to the Bluetooth device. This allows for the detection of both Bluetooth device access and the virtual machine operating system transmitting data, thus determining whether hook module registration is necessary. Furthermore, detecting the virtual machine operating system through the hook processing module does not require the use of other programs on the host system, reducing interference with other programs on the host system.
[0128] In another possible implementation, when the virtual machine operating system that needs to transmit data with the Bluetooth device is detected to be a first virtual machine operating system, data transmission with the Bluetooth device can be achieved through modules inside the first virtual machine.
[0129] The following describes the data transmission process between the second virtual machine operating system and the Bluetooth device, as well as the data transmission process between the first virtual machine operating system and the Bluetooth device.
[0130] Figure 3 This is a schematic flowchart illustrating a method for data transmission between a second virtual machine operating system and a Bluetooth device, provided in an embodiment of this application.
[0131] like Figure 3 As shown, the method for data transmission between the second virtual machine operating system and the Bluetooth device may include the following steps:
[0132] S301. When it is detected that the virtual machine operating system that needs to transmit data with the Bluetooth device is a second virtual machine operating system, register a hook module in the virtualization driver backend of the host operating system.
[0133] For example, when the hook processing module detects that the second virtual machine operating system needs to transmit data to the Bluetooth device, the hook processing module registers the hook module in the virtualization driver backend of the host operating system.
[0134] In this way, when the hook processing module detects that the virtual machine operating system that needs to transmit data is not the first virtual machine operating system, it registers the hook module, which can reduce the waste of resources caused by registering the hook module when the first virtual machine is transmitting data with the Bluetooth device.
[0135] S302, Control the establishment of a data connection for data transmission.
[0136] In this embodiment of the application, a first Bluetooth data processing module may run in the host operating system, and a second Bluetooth data processing module may run in the first virtual machine operating system.
[0137] When the hook module is successfully registered in step S301, the hook processing module can control the first Bluetooth data processing module and the hook module to establish a first data connection, and control the first Bluetooth data processing module and the second Bluetooth data processing module to establish a second data connection; and control the second Bluetooth data processing module to establish a third data connection with the Bluetooth protocol stack.
[0138] In this way, by establishing data connections between the hook module, the first Bluetooth data processing module, the second Bluetooth data processing module, and the Bluetooth protocol stack,
[0139] S303. Capture the first data to be transmitted to the Bluetooth device in the second virtual machine operating system through the hook module.
[0140] For example, when capturing the first data to be transmitted to the Bluetooth device in the second virtual machine operating system through the hook module, the first data can be captured in the virtualization driver front end of the second virtual machine operating system through the hook module. The first data is generated by the application in the second virtual machine operating system.
[0141] In this way, since the data generated by the application in the second virtual machine operating system that needs to be transmitted to the Bluetooth device can be done through the virtualization driver front end, the data transmitted to the Bluetooth device can be captured in the virtualization driver front end to facilitate data transmission with the Bluetooth device.
[0142] S304. The first data is transmitted to the Bluetooth protocol stack via the hook module and the established data connection.
[0143] For example, the first data is transmitted to the Bluetooth protocol stack via the hook module and the established data connection. Alternatively, the first data can be transmitted to the first Bluetooth data processing module via the hook module and the first data connection; the received first data can be transmitted to the second Bluetooth data processing module via the first Bluetooth data processing module and the second data connection; and the first data can be transmitted to the Bluetooth protocol stack via the second Bluetooth data processing module and the third data connection.
[0144] For example, when a Bluetooth headset transmits data to an application in the second virtual machine operating system of an electronic device, the user can input audio data through the Bluetooth headset. This audio data can be transmitted to the second virtual machine operating system in sequence through the Bluetooth protocol stack, the second Bluetooth data processing module, the first Bluetooth data processing module, the hook module, and the virtualization driver front-end in the first virtual machine operating system.
[0145] In this way, Bluetooth data is transmitted to the Bluetooth protocol stack sequentially through the hook module, the first Bluetooth data processing module, and the second Bluetooth data processing module, realizing data transmission between the virtual machine operating system other than the first virtual machine operating system and the Bluetooth protocol stack, so that the Bluetooth protocol stack running in the first virtual machine operating system can receive data from other virtual machine operating systems.
[0146] S305 transmits the first data to the Bluetooth device via the Bluetooth protocol stack.
[0147] For example, when transmitting the first data to a Bluetooth device via the Bluetooth protocol stack, the first data can be transmitted to a hardware controller via the Bluetooth protocol stack, so that the hardware controller can transmit the first data to the Bluetooth device.
[0148] Therefore, by running modules related to Bluetooth data transmission in the first operating system and the host system, Bluetooth data generated by different virtual machine operating systems can be transmitted to Bluetooth devices through the Bluetooth protocol stack running in the first virtual machine operating system. This enables Bluetooth data transmission even in a one-to-one manner between the Bluetooth protocol stack and the controller, thus realizing the sharing of Bluetooth devices by multiple virtual machine operating systems.
[0149] Combination Figure 3 In the described embodiment, the second virtual machine operating system can send Bluetooth data to the Bluetooth device, and of course, the second virtual machine operating system can also receive Bluetooth data sent by the Bluetooth device.
[0150] For example, for the second data sent by the Bluetooth device to the second virtual machine operating system, a hook module can be used to capture the second data in the first Bluetooth data processing module. This second data is transmitted from the Bluetooth device to the first Bluetooth data processing module via the Bluetooth protocol stack and the second Bluetooth data processing module. The hook module then transmits the second data to the second virtual machine operating system through the virtualization driver front-end.
[0151] The process by which a Bluetooth device transmits second data to a first Bluetooth data processing module via the Bluetooth protocol stack and the second Bluetooth data processing module may include: Second data from the second virtual machine operating system sent by the Bluetooth device can be transmitted to the Bluetooth protocol stack via the controller. After receiving the second data, the Bluetooth protocol stack can transmit the received second data to the second Bluetooth data processing module via a third data connection between the Bluetooth protocol stack and the second Bluetooth data processing module. After receiving the second data, the second Bluetooth data processing module can transmit the received second data to the first Bluetooth data processing module via a second data connection between the first and second Bluetooth data processing modules.
[0152] In this way, the hook module can capture data not only in the virtualization driver front end, but also in the first Bluetooth data processing module, thereby enabling data transmission between the second virtual machine operating system and the Bluetooth device.
[0153] Figure 4 This is a schematic flowchart illustrating a method for data transmission between a first virtual machine operating system and a Bluetooth device, provided as an embodiment of this application.
[0154] like Figure 4 As shown, the method for data transmission between the first virtual machine operating system and the Bluetooth device may include:
[0155] S401. When the virtual machine operating system that needs to transmit data with the Bluetooth device is detected to be the first virtual machine operating system, the second Bluetooth data processing module is controlled by the Bluetooth device management module to establish a third data connection with the Bluetooth protocol stack.
[0156] For example, this step can be performed when a Bluetooth device connects and the operating system that first transmits data with the Bluetooth device is a first virtual machine operating system.
[0157] S402. Obtain the third data to be transmitted to the Bluetooth device from the first virtual machine operating system through the Bluetooth device management module. The third data is generated by the application in the first virtual machine operating system.
[0158] The applications in the first virtual machine operating system can be music applications, etc. This application embodiment does not specifically limit the applications in the first virtual machine operating system.
[0159] S403, the second Bluetooth data processing module transmits the third data to the Bluetooth protocol stack via the third data connection.
[0160] The third data connection is the data connection between the second Bluetooth data processing module and the Bluetooth protocol stack.
[0161] S404 transmits third-party data to Bluetooth devices via the Bluetooth protocol stack.
[0162] The method for transmitting third-party data to Bluetooth devices via the Bluetooth protocol stack can be found in the above embodiments and will not be repeated here.
[0163] Therefore, it can be seen that by using the Bluetooth device management module and the second Bluetooth data processing module running in the first virtual machine operating system, the data that needs to be transmitted from the first virtual machine operating system to the Bluetooth device can be transmitted to the Bluetooth device through the Bluetooth protocol stack, thus realizing the sharing of Bluetooth devices by multiple virtual machine operating systems.
[0164] Combination Figure 4 In the described embodiment, the first virtual machine operating system can send Bluetooth data to the Bluetooth device, and of course, the first virtual machine operating system can also receive Bluetooth data sent by the Bluetooth device.
[0165] For example, data sent by a Bluetooth device to a first virtual machine operating system can be transmitted to the first virtual machine operating system sequentially through the Bluetooth protocol stack and the second Bluetooth data processing module.
[0166] In this embodiment, when the virtual machine operating system in an electronic device transmits Bluetooth data to a Bluetooth device, there may be a situation where Bluetooth data from multiple applications are transmitted simultaneously. These multiple applications may be applications running in the same virtual machine operating system or applications running in different virtual machine operating systems; this embodiment does not limit this. The following describes the situation where the electronic device transmits Bluetooth data from multiple applications simultaneously.
[0167] For example, when an electronic device transmits Bluetooth data from multiple applications simultaneously, it can receive multiple fourth data streams from at least two virtual machine operating systems via the Bluetooth protocol stack. The transmission of multiple fourth data streams by the electronic device can be implemented in two possible ways:
[0168] In one possible implementation, the electronic device can transmit multiple fourth data to the Bluetooth device according to the priority of the application to which the multiple fourth data belong, through the Bluetooth protocol stack.
[0169] For example, when the Bluetooth protocol stack simultaneously receives Bluetooth data transmitted to the Bluetooth device from application 1 in the first virtual machine operating system and application 2 in the second virtual machine operating system, the Bluetooth protocol stack can determine the priority of application 1 and application 2 from the pre-stored correspondence between application and priority. When the priority of application 1 is higher than that of application 2, the Bluetooth protocol stack can transmit the Bluetooth data of application 1 first, and then transmit the Bluetooth data of application 2.
[0170] In another possible implementation, the electronic device can transmit multiple fourth data to the Bluetooth device simultaneously.
[0171] It should be noted that when the Bluetooth protocol stack transmits data from the Bluetooth device to the virtual machine operating system, the Bluetooth protocol stack can do so through the two possible implementations mentioned above, which will not be elaborated further here.
[0172] In this way, when an electronic device transmits Bluetooth data from multiple applications simultaneously, the data generated by each application can be transmitted to the Bluetooth device, reducing the possibility of Bluetooth data loss and further improving the efficiency of data transmission.
[0173] Based on the module described in the above embodiments, when the electronic device detects that the Bluetooth device has disconnected from the electronic device through the Bluetooth device management module, the electronic device can control the hook processing module to unregister the hook module in the host operating system through the Bluetooth device management module.
[0174] In this way, when the Bluetooth device disconnects from the electronic device, the hook module is deregistered, ensuring that the hook module no longer captures Bluetooth data when the Bluetooth device disconnects from the electronic device.
[0175] Furthermore, when the hook module successfully deregisters, the electronic device can control the disconnection of the first data connection between the first Bluetooth data processing module and the hook module, the second data connection between the first Bluetooth data processing module and the second Bluetooth data processing module, and the third data connection between the second Bluetooth data processing module and the Bluetooth protocol stack through the hook processing module.
[0176] In this way, by disconnecting the data connections between modules, other data can be prevented from being transmitted through the established data connections, thus avoiding interference with data transmission after subsequent Bluetooth devices are connected.
[0177] In conjunction with the above embodiments, in Figure 1 Based on this, the structure of electronic devices can be seen in [reference]. Figure 5 As shown, Figure 5 This is a schematic diagram of the structure of another electronic device provided in an embodiment of this application.
[0178] like Figure 5 As shown, the electronic device may include a host operating system, a first virtual machine operating system, a second virtual machine operating system, and Bluetooth hardware. The Bluetooth hardware can be a Bluetooth controller, used to interact with Bluetooth devices to transmit Bluetooth data.
[0179] It should be noted that electronic devices can also run other virtual machine operating systems. Figure 5 It is not shown in the middle.
[0180] The host operating system acts as the host virtual machine operating system, running a client Bluetooth module and a virtualization driver backend. The client Bluetooth module may include a hook processing module and a first Bluetooth data processing module. The hook module is registered in the virtualization driver backend. The first virtual machine operating system can act as a Bluetooth device server, running a Bluetooth protocol stack and a server Bluetooth module. The server Bluetooth module may include a Bluetooth device management module and a second Bluetooth data processing module. The second virtual machine operating system can act as a Bluetooth device client, running an application and a virtualization driver frontend.
[0181] Hook modules can be used to intercept and inject Bluetooth data. The interception function of a hook module can be used to intercept data that needs to be injected into a Bluetooth device.
[0182] Taking a Bluetooth headset as an example, the hook module can intercept audio data and forward it to the virtual machine operating system acting as a Bluetooth server, allowing the audio data to be played from the Bluetooth headset. The hook module can capture data received by the Bluetooth headset microphone within the Bluetooth server virtual machine operating system and inject it into the virtualization driver frontend.
[0183] The hook connection processing module can communicate with the virtualization driver backend through various connection methods, such as network and message queues. It can also handle control flow, responding to Bluetooth device access and disconnection requests from the second virtual machine operating system. For example, when a Bluetooth device accesses, the hook connection processing module can respond to control signals from the Bluetooth device management module to register the hook module. When the Bluetooth device disconnects, it no longer responds to control signals from the Bluetooth device management module.
[0184] The first Bluetooth data processing module can be used to establish and disconnect data connections under the control of the hook connection processing module. Specifically, it can include: establishing or disconnecting data connections with the hook module of the virtualization driver backend, and establishing or disconnecting data connections with the Bluetooth data processing module of the first virtual machine operating system.
[0185] The Bluetooth device management module is used to interact with the user. It can transfer or disconnect paired Bluetooth devices to a second virtual machine operating system that acts as a Bluetooth client, and maintain the process status of Bluetooth device transfer.
[0186] The second Bluetooth data processing module is used to establish a data connection with the first Bluetooth data processing module in the host operating system, initialize and format the Bluetooth data stream. It can also be used to establish a connection with the Bluetooth protocol stack to transmit Bluetooth data to the Bluetooth hardware via the Bluetooth protocol stack.
[0187] Bluetooth data stream is the data stream generated during Bluetooth data transmission.
[0188] exist Figure 5 In the diagram, dashed lines represent control flow, and solid lines represent data flow.
[0189] For example, when a Bluetooth device is connected, the Bluetooth device management module can control the hook processing module to register the hook module. The Bluetooth device management module can also control the second Bluetooth data processing module to establish a data connection with the first Bluetooth data processing module, and control the second Bluetooth data processing module to establish a data connection with the Bluetooth protocol stack. The hook processing module can control the first Bluetooth data processing module to establish a data connection with the hook module.
[0190] Furthermore, once the data connection is established, the hook module can capture Bluetooth data generated by applications in the second virtual machine operating system and transmit the Bluetooth data to the Bluetooth hardware through the first Bluetooth data processing module, the second Bluetooth data processing module, and the Bluetooth protocol stack, so as to transmit it to the Bluetooth device through the Bluetooth hardware.
[0191] For example, when a Bluetooth device disconnects from an electronic device, the Bluetooth device management module can control the hook processing module to deregister the hook module. The Bluetooth device management module can also control the second Bluetooth data processing module to disconnect from the first Bluetooth data processing module, and control the second Bluetooth data processing module to disconnect from the Bluetooth protocol stack. The hook processing module can control the first Bluetooth data processing module and the hook module to disconnect from each other.
[0192] To facilitate understanding of the Bluetooth device sharing method provided in the embodiments of this application, the following will be combined with... Figure 5 As shown, taking a Bluetooth headset as an example, the Bluetooth device sharing method provided in this application embodiment is described in detail from two aspects: when the Bluetooth device is connected to an electronic device, and when the Bluetooth device is disconnected from the electronic device.
[0193] When a Bluetooth device connects to an electronic device, the method for the virtual machine operating system in the electronic device to interact with the Bluetooth device can be found in [reference needed]. Figure 6 As shown, Figure 6 This is a flowchart illustrating another Bluetooth device sharing method provided in an embodiment of this application.
[0194] like Figure 6 As shown, the Bluetooth device sharing method may include the following steps:
[0195] S601, Bluetooth headset connection and pairing.
[0196] S602, The Bluetooth device management module initiates a connection between the Bluetooth headset and the second virtual machine operating system, which acts as a Bluetooth client.
[0197] For example, the Bluetooth device management module in the first virtual machine operating system, which acts as the Bluetooth server, interacts with the user, initiates a paired headphone connection, and sends control messages to the hook connection processing module of the ClientBluetooth Module in the host virtual machine operating system to trigger the hook module registration process.
[0198] S603, the hook connection processing module finds the second virtual machine operating system of the shared target Bluetooth client and registers the hook module in the backend of the sound virtualization driver.
[0199] For example, when the hook connection processing module of the Client Bluetooth Module located in the Host virtual machine operating system receives a Bluetooth headset connection request, it identifies the second virtual machine operating system sharing the Bluetooth headset and initiates the hook module registration process. If the hook module registration is successful, it notifies the Bluetooth device management module of the Server to update the hook module registration status.
[0200] The Bluetooth device management module can update the hook module's unregistered status to a successfully registered status.
[0201] S604, the first Bluetooth data processing module establishes a data connection with the sound virtualization driver backend.
[0202] The first Bluetooth data processing module of the Client Bluetooth Module located in the host virtual machine operating system receives the control command, establishes a data connection with the hook module in the virtualization driver backend, and feeds back the connection status to the hook connection processing module through the control command. The hook connection processing module then returns the connection status to the Bluetooth device management module in the first virtual machine operating system, which acts as the Bluetooth Server, and updates the connection status of the hook module.
[0203] The Bluetooth device management module can update the connection status of the hook module from not connected to connected.
[0204] S605, The first Bluetooth data processing module establishes a data connection with the second Bluetooth data processing module.
[0205] For example, the first Bluetooth data processing module of the Client Bluetooth Module located in the host virtual machine operating system initiates a connection request to connect to the second Bluetooth data processing module in the first virtual machine operating system, which acts as the Bluetooth Server, and establishes a data connection between the first Bluetooth data processing module and the second Bluetooth data processing module based on the request.
[0206] It is understood that the embodiments in this application are only used as an example of the first Bluetooth data processing module initiating a connection request with the second Bluetooth data processing module, and do not constitute any limitation.
[0207] S606, the second Bluetooth data processing module initializes the Bluetooth data from the second virtual machine operating system and establishes communication with the Bluetooth protocol stack according to the preset Bluetooth data audio format.
[0208] For example, the second Bluetooth data processing module of the Server BluetoothModule located in the first virtual machine operating system of the Bluetooth Server accepts the connection from the host operating system, constructs the Bluetooth audio data stream, establishes a connection with the Bluetooth protocol stack, and sends connection status information to the Bluetooth device management module.
[0209] S607, Bluetooth device management module updates the connection status with Bluetooth client.
[0210] For example, the Bluetooth device management module of the Server BluetoothModule located in the first virtual machine operating system of the Bluetooth Server updates the status of the Bluetooth headset and monitors the usage of the Bluetooth headset.
[0211] Monitoring the usage of Bluetooth headsets can involve monitoring their connection status, specifically whether the headset has disconnected from electronic devices.
[0212] The S608, acting as a second virtual machine operating system for Bluetooth clients, normally functions as a Bluetooth headset.
[0213] The connection process is complete, and the second virtual machine operating system, acting as the Bluetooth Client, can now normally use the Bluetooth headset playback function.
[0214] The normal use of Bluetooth headset playback function in the virtual machine operating system can follow the data transmission process described in the above embodiments, which can be referred to in the above embodiments and will not be repeated here.
[0215] In this way, multiple virtual machine operating systems in electronic devices can interact with Bluetooth headsets without having to run multiple Bluetooth protocol stacks.
[0216] In this embodiment of the application, when the Bluetooth device disconnects from the electronic device, the method performed by the electronic device can be found in [reference needed]. Figure 7 As shown, Figure 7 This is a flowchart illustrating a method for disconnecting a Bluetooth device from an electronic device, as provided in an embodiment of this application.
[0217] like Figure 7 As shown, the method for a Bluetooth device to disconnect from an electronic device may include the following steps:
[0218] S701, Bluetooth headset disconnects from electronic devices.
[0219] The disconnection of a Bluetooth headset can be caused by the Bluetooth headset disconnecting from an electronic device. This can be determined by the Bluetooth device management module detecting a disconnection operation initiated by the user through interface interaction, or by other means. This application embodiment does not limit this.
[0220] S702, the Bluetooth device management module disconnects the Bluetooth headset from the second virtual machine operating system, which acts as the Bluetooth client.
[0221] For example, when the Bluetooth device management module in the virtual machine operating system acting as the Bluetooth server detects a change in the state of a shared Bluetooth device, it can initiate a process to disconnect the shared Bluetooth headset and send a control message to the hook connection processing module of the ClientBluetooth Module to trigger the hook module deregistration process.
[0222] S703. Hook connection processing module unregister: Unregister the hook module in the sound virtualization driver of the host virtual machine operating system.
[0223] For example, when the hook connection processing module of the Client Bluetooth Module located in the host virtual machine operating system receives a Bluetooth device disconnection request, it can find the second virtual machine operating system of the shared Bluetooth headset, initiate the hook module deregistration process, and if the hook module deregistration is successful, it sends a control command to the first Bluetooth data processing module of the host virtual machine operating system to notify the Bluetooth device management module in the first virtual machine operating system, which acts as the Bluetooth server, to update the deregistration status of the hook module.
[0224] The Bluetooth device management module update hook module status can be found in the above embodiments and will not be repeated here.
[0225] S704, the first Bluetooth data processing module disconnects from the data connection of the sound virtualization driver backend.
[0226] For example, when the first Bluetooth data processing module of the Client Bluetooth Module located in the host virtual machine operating system receives a disconnection control command, it disconnects the data connection with the hook module in the virtualization driver backend and feeds back the connection status to the hook connection processing module by sending a control command. The hook connection processing module then feeds back the data connection status to the Bluetooth device management module. The Bluetooth device management module can update the connection status of the hook module.
[0227] The Bluetooth device management module updates the connection status of the hook module as described in the above embodiments, and will not be repeated here.
[0228] S705, the first Bluetooth data processing module disconnects from the data connection with the second Bluetooth data processing module.
[0229] For example, the first Bluetooth data processing module of the Client Bluetooth Module located in the host virtual machine operating system disconnects its data connection with the second Bluetooth data processing module in the first virtual machine operating system, which acts as the Bluetooth Server.
[0230] The disconnection between the first Bluetooth data processing module and the second Bluetooth data processing module can be controlled by the Bluetooth device management module.
[0231] S706, the second Bluetooth data processing module disconnects from the Bluetooth protocol stack and cleans up the relevant Bluetooth data structures.
[0232] For example, when the second Bluetooth data processing module of the Server BluetoothModule located in the first virtual machine operating system of the Bluetooth Server determines that the data connection from the host operating system has been disconnected, it can parse the Bluetooth audio data stream, disconnect the connection with the Bluetooth protocol stack, and send connection status information to the Bluetooth device management module.
[0233] S707, Bluetooth device management module updates connection status with host operating system.
[0234] For example, the Bluetooth device management module of the Server BluetoothModule located in the first virtual machine operating system of the Bluetooth Server can update the status of the Bluetooth headset and monitor its usage.
[0235] It should be noted that the Bluetooth device management module monitors the usage of Bluetooth headsets, which can include monitoring the connection status of the Bluetooth headsets.
[0236] S708, as a second virtual machine operating system acting as a Bluetooth client, resumes routing to the sound hardware.
[0237] For example, after the Bluetooth headset disconnection process in the above steps is completed, the sound of the second virtual machine operating system, which is the Bluetooth Client, is restored to be played through the sound hardware.
[0238] The sound hardware can be any hardware in an electronic device used to play audio, such as speakers, but this application does not limit this.
[0239] In summary, the Bluetooth device sharing method provided in this application implements Bluetooth device sharing across multiple virtual machine operating systems by designing a client-server architecture-based Bluetooth device sharing system on a virtualized system. When a virtual machine operating system acting as a Bluetooth client needs to use a shared Bluetooth device, it intercepts and injects Bluetooth data into the virtual machine operating system acting as a Bluetooth server. Only one Bluetooth protocol stack needs to be set up; it does not require intervention in the integrity of the overall Bluetooth protocol stack Host-Controller architecture, enabling multiple virtual machine operating systems to use Bluetooth devices. This improves the data transmission performance when multiple virtual machine operating systems use Bluetooth devices.
[0240] Based on the above Figures 5-7 In the illustrated embodiment, the data stream for data transmission between the virtual machine operating system and the Bluetooth headset when the Bluetooth headset is connected and disconnected can be found in [reference needed]. Figure 8 As shown. Figure 8 This is a schematic diagram of a data stream for data transmission between a virtual machine operating system and a Bluetooth headset, provided as an embodiment of this application.
[0241] It should be noted that, in Figure 8 In the diagram, the dashed line represents the audio data stream when the Bluetooth headset is not connected, and the solid line represents the audio data stream when the Bluetooth headset is connected.
[0242] like Figure 8 As shown, when the Bluetooth headset is not connected to an electronic device, the first audio data generated by the application of the second virtual machine operating system is transmitted to the audio virtualization driver backend of the host operating system through the audio virtualization driver frontend in the second virtual machine operating system. The audio virtualization driver backend then transmits the first audio data to the sound hardware, which plays the first audio data.
[0243] Correspondingly, the second audio data input through the sound hardware can be transmitted to the audio virtualization driver backend, and the audio virtualization driver backend transmits the second audio data to the audio virtualization driver frontend, so as to transmit it to the application of the second virtual machine operating system.
[0244] like Figure 8As shown, when the Bluetooth headset is connected to the electronic device, the third audio data generated by the application in the second virtual machine operating system is transmitted to the audio virtualization driver backend of the host operating system via the audio virtualization driver frontend in the second virtual machine operating system. The transmission of the third audio data from the audio virtualization driver frontend to the audio virtualization driver backend can be achieved through audio data capture by the hook module of the audio virtualization driver backend. This third audio data is then transmitted to the Bluetooth protocol stack via the client Bluetooth module and the server Bluetooth module, and finally transmitted to the Bluetooth hardware controller via the Bluetooth protocol stack, thus enabling the transmission of the third audio data to the Bluetooth headset.
[0245] Correspondingly, the fourth audio data input through the Bluetooth headset can be transmitted to the Bluetooth protocol stack via the Bluetooth hardware controller. The Bluetooth protocol stack and the server-side Bluetooth module then transmit the fourth audio data to the client-side Bluetooth module. The hook module in the audio virtualization driver backend can capture the fourth audio data from the client-side Bluetooth module and transmit it to the audio virtualization driver frontend via the audio virtualization driver backend, for transmission to the application in the second virtual machine operating system.
[0246] It should be noted that the process of registering the data transmission module in the host operating system is executed when the electronic device first detects the Bluetooth device's access. Therefore, the registration of the data transmission module and the establishment of connections between modules described in the embodiments of this application are all executed when the electronic device first detects the Bluetooth device's access. During Bluetooth data transmission, the electronic device may pair and connect with multiple Bluetooth devices. Therefore, in the above embodiments, the Bluetooth device performing data transmission and the Bluetooth device that detects access and executes the registration of the data transmission module and the establishment of connections between modules can be the same Bluetooth device or different Bluetooth devices. The embodiments in this application are not specifically limited.
[0247] For example, when an electronic device is not connected to a Bluetooth device, if a Bluetooth headset is first connected to the electronic device, and then a Bluetooth keyboard is connected, then two Bluetooth devices are connected to the electronic device. When the Bluetooth headset is connected to the electronic device, methods such as registering the data transmission module and establishing connections between modules can be executed. Once the data transmission module is successfully registered and data connections are established between the modules, both the Bluetooth headset and the Bluetooth keyboard can transmit data to the electronic device using the methods described in this application.
[0248] Figure 9 This is a schematic diagram of the structure of a Bluetooth device sharing device 90 provided in an embodiment of this application. For example, please refer to [link to example diagram]. Figure 9 As shown, the Bluetooth device sharing device 90 may include:
[0249] The acquisition module 901 is used to capture the first data to be transmitted to the Bluetooth device by the data transmission module in the host operating system. The second virtual machine operating system is at least one virtual machine operating system other than the first virtual machine operating system among a plurality of virtual machine operating systems.
[0250] The transmission module 902 is used to transmit the first data to the Bluetooth protocol stack via the data transmission module; and to transmit the first data to the Bluetooth device via the Bluetooth protocol stack.
[0251] In one possible implementation, the data transmission module includes a hook module that runs in the virtualization driver backend of the host operating system. The virtualization driver backend is paired with the virtualization driver frontend in the second virtual machine operating system. Specifically, the acquisition module uses the hook module to capture the first data to be transmitted to the Bluetooth device in the virtualization driver frontend of the second virtual machine operating system. The first data is generated by an application in the second virtual machine operating system.
[0252] In one possible implementation, the data transmission module includes a hook module, and the device further includes a registration module 903. The registration module 903 is used to detect the virtual machine operating system that needs to transmit data with the Bluetooth device when a Bluetooth device is detected to be connected; when the virtual machine operating system that needs to transmit data with the Bluetooth device is detected to be a second virtual machine operating system, the hook module is registered in the virtualization driver backend in the host operating system, and the virtualization driver backend is paired with the virtualization driver frontend in the second virtual machine operating system for use.
[0253] In one possible implementation, a Bluetooth device management module runs in the first virtual machine operating system, and a hook processing module runs in the host operating system; the registration module 903 is specifically used to detect whether a Bluetooth device is connected through the Bluetooth device management module; when a Bluetooth device is detected to be connected through the Bluetooth device management module, the Bluetooth device management module controls the hook processing module to detect whether there is a virtual machine operating system that needs to transmit data to the Bluetooth device.
[0254] In one possible implementation, the registration module 903 is specifically used to register the hook module in the virtualization driver backend of the host operating system when the hook processing module detects that the second virtual machine operating system needs to transmit data to the Bluetooth device.
[0255] In one possible implementation, a first Bluetooth data processing module runs in the host operating system, and a second Bluetooth data processing module runs in the first virtual machine operating system; the device further includes a control module 904, which is used to control the first Bluetooth data processing module and the hook module to establish a first data connection when the hook module is successfully registered, and to control the first Bluetooth data processing module and the second Bluetooth data processing module to establish a second data connection; and to control the second Bluetooth data processing module to establish a third data connection with the Bluetooth protocol stack.
[0256] In one possible implementation, the transmission module 902 is specifically used to transmit the first data to the first Bluetooth data processing module via the hook module and the first data connection; transmit the received first data to the second Bluetooth data processing module via the first Bluetooth data processing module and the second data connection; and transmit the first data to the Bluetooth protocol stack via the second Bluetooth data processing module and the third data connection.
[0257] In one possible implementation, the acquisition module 901 is further configured to capture second data from the first Bluetooth data processing module via a hook module. This second data is transmitted from the Bluetooth device to the first Bluetooth data processing module via the Bluetooth protocol stack and the second Bluetooth data processing module. The transmission module 902 is further configured to transmit the second data to the second virtual machine operating system via the virtualization driver front-end through the hook module.
[0258] In one possible implementation, a Bluetooth device management module and a second Bluetooth data processing module run in the first virtual machine operating system.
[0259] The control module 904 is also used to control the second Bluetooth data processing module to establish a third data connection with the Bluetooth protocol stack through the Bluetooth device management module when it is detected that the virtual machine operating system that needs to transmit data with the Bluetooth device is the first virtual machine operating system.
[0260] The acquisition module 901 is also used to acquire third data to be transmitted to the Bluetooth device in the first virtual machine operating system through the Bluetooth device management module. The third data is generated by the application in the first virtual machine operating system.
[0261] The transmission module 902 is also used to transmit the third data to the second Bluetooth data processing module via the Bluetooth device management module; transmit the third data to the Bluetooth protocol stack via the second Bluetooth data processing module and the third data connection; and transmit the third data to the Bluetooth device via the Bluetooth protocol stack.
[0262] In one possible implementation, the transmission module 902 is further configured to receive multiple fourth data items via the Bluetooth protocol stack, the fourth data items originating from at least two virtual machine operating systems. The Bluetooth protocol stack then transmits the multiple fourth data items to a Bluetooth device according to the priority of the applications to which they belong; or, simultaneously transmits the multiple fourth data items to the Bluetooth device.
[0263] In one possible implementation, the control module 904 is further configured to, when the Bluetooth device management module detects that the Bluetooth device has disconnected from the electronic device, control the hook processing module to unregister the hook module in the host operating system.
[0264] In one possible implementation, the control module 904 is further configured to, when the hook module successfully logs out, control the disconnection of the first data connection between the first Bluetooth data processing module and the hook module, the second data connection between the first Bluetooth data processing module and the second Bluetooth data processing module, and the third data connection between the second Bluetooth data processing module and the Bluetooth protocol stack via the hook processing module.
[0265] The Bluetooth device sharing device provided in this application embodiment can execute the technical solution of the Bluetooth device sharing method in any of the above embodiments. Its implementation principle and beneficial effects are similar to those of the Bluetooth device sharing method. Please refer to the implementation principle and beneficial effects of the Bluetooth device sharing method. It will not be repeated here.
[0266] Figure 10 This is a schematic diagram of another electronic device structure provided in an embodiment of this application. For example... Figure 10 As shown, the electronic device 1000 may include at least one processor 1001 and a memory 1002.
[0267] The memory 1002 is used to store programs. Specifically, the program may include program code, which includes computer operation instructions.
[0268] The memory 1002 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.
[0269] The processor 1001 executes computer execution instructions stored in the memory 1002 to implement the Bluetooth device sharing method described in the foregoing method embodiments. The processor 1001 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application. Specifically, when implementing the Bluetooth device sharing method described in the foregoing method embodiments, the electronic device may be, for example, a terminal, a server, or other electronic device with processing capabilities. When implementing the Bluetooth device sharing method described in the foregoing method embodiments, the electronic device may be, for example, an electronic control unit in a vehicle.
[0270] Optionally, the electronic device 1000 may also include a communication interface 1003. In specific implementations, if the communication interface 1003, memory 1002, and processor 1001 are implemented independently, they can be interconnected via a bus to complete communication. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc., but this does not imply that there is only one bus or one type of bus.
[0271] Optionally, in a specific implementation, if the communication interface 1003, memory 1002 and processor 1001 are integrated on a single chip, then the communication interface 1003, memory 1002 and processor 1001 can communicate through an internal interface.
[0272] This application also provides a computer-readable storage medium, which may include various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk. Specifically, the computer-readable storage medium stores program instructions, which are used in the methods described in the above embodiments.
[0273] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A Bluetooth device sharing method, applied to an electronic device, wherein the electronic device runs a host operating system and multiple virtual machine operating systems, wherein a first virtual machine operating system among the multiple virtual machine operating systems runs a Bluetooth protocol stack, and the other virtual machine operating systems do not need to run a Bluetooth protocol stack, characterized in that, include: The data transmission module in the host operating system captures the first data to be transmitted to the Bluetooth device by the second virtual machine operating system, wherein the second virtual machine operating system is at least one virtual machine operating system other than the first virtual machine operating system among the plurality of virtual machine operating systems. The first data is transmitted to the Bluetooth protocol stack via the data transmission module. The first data is transmitted to the Bluetooth device via the Bluetooth protocol stack. The data transmission module includes a hook module, which runs in the virtualization driver backend of the host operating system. The virtualization driver backend is paired with the virtualization driver frontend in the second virtual machine operating system. The step of capturing the first data to be transmitted from the second virtual machine operating system to the Bluetooth device through the data transmission module in the host operating system includes: The hook module captures the first data to be transmitted to the Bluetooth device in the virtualization driver front-end of the second virtual machine operating system. The first data is generated by an application in the second virtual machine operating system.
2. The method according to claim 1, characterized in that, The data transmission module includes a hook module, and the method further includes: When a Bluetooth device is detected to be connected, the virtual machine operating system that needs to transmit data with the Bluetooth device is detected. When it is detected that the virtual machine operating system that needs to transmit data with the Bluetooth device is a second virtual machine operating system, a hook module is registered in the virtualization driver backend of the host operating system.
3. The method according to claim 2, characterized in that, The first virtual machine operating system runs a Bluetooth device management module, and the host operating system runs a hook processing module; When a Bluetooth device is detected to be connected, the step of detecting the virtual machine operating system that needs to transmit data with the Bluetooth device includes: The Bluetooth device management module detects whether any Bluetooth devices are connected. When the Bluetooth device management module detects that a Bluetooth device has been connected, it controls the hook processing module to detect whether there is a virtual machine operating system that needs to transmit data to the Bluetooth device.
4. The method according to claim 3, characterized in that, When it is detected that the virtual machine operating system that needs to transmit data with the Bluetooth device is a second virtual machine operating system, a hook module is registered in the virtualization driver backend of the host operating system, including: When the hook processing module detects that the second virtual machine operating system needs to transmit data to the Bluetooth device, it registers the hook module in the virtualization driver backend of the host operating system.
5. The method according to claim 4, characterized in that, The host operating system runs a first Bluetooth data processing module, and the first virtual machine operating system runs a second Bluetooth data processing module; the method further includes: When the hook module is successfully registered, the hook processing module controls the first Bluetooth data processing module and the hook module to establish a first data connection, and controls the first Bluetooth data processing module and the second Bluetooth data processing module to establish a second data connection. The second Bluetooth data processing module is controlled to establish a third data connection with the Bluetooth protocol stack.
6. The method according to claim 5, characterized in that, The step of transmitting the first data to the Bluetooth protocol stack via the data transmission module includes: The first data is transmitted to the first Bluetooth data processing module via the hook module and the first data connection. The first received data is transmitted to the second Bluetooth data processing module through the first Bluetooth data processing module and the second data connection. The first data is transmitted to the Bluetooth protocol stack via the second Bluetooth data processing module and the third data connection.
7. The method according to claim 6, characterized in that, The method further includes: The hook module captures second data from the first Bluetooth data processing module. The second data is transmitted from the Bluetooth device to the first Bluetooth data processing module through the Bluetooth protocol stack and the second Bluetooth data processing module. The hook module transmits the second data to the second virtual machine operating system via the virtualization driver front-end.
8. The method according to claim 1, characterized in that, The first virtual machine operating system runs a Bluetooth device management module and a second Bluetooth data processing module, and the method further includes: When the first virtual machine operating system is detected as the virtual machine operating system that needs to transmit data with the Bluetooth device, the Bluetooth device management module controls the second Bluetooth data processing module to establish a third data connection with the Bluetooth protocol stack. The Bluetooth device management module obtains third data from the first virtual machine operating system that is to be transmitted to the Bluetooth device, and the third data is generated by an application in the first virtual machine operating system. The third data is transmitted to the second Bluetooth data processing module via the Bluetooth device management module. The third data is transmitted to the Bluetooth protocol stack via the second Bluetooth data processing module and the third data connection. The third data is transmitted to the Bluetooth device via the Bluetooth protocol stack.
9. The method according to any one of claims 1-8, characterized in that, The method further includes: The Bluetooth protocol stack is used to receive multiple fourth data, which come from at least two virtual machine operating systems. The Bluetooth protocol stack transmits the plurality of fourth data to the Bluetooth device according to the priority of the application to which the plurality of fourth data belong. Alternatively, the plurality of fourth data may be transmitted to the Bluetooth device simultaneously.
10. The method according to any one of claims 1-8, characterized in that, The method further includes: When the Bluetooth device management module detects that the Bluetooth device has disconnected from the electronic device, the Bluetooth device management module controls the hook processing module to unregister the hook module in the host operating system.
11. The method according to claim 10, characterized in that, The method further includes: When the hook module successfully logs out, the hook processing module controls the disconnection of the first data connection between the first Bluetooth data processing module and the hook module, the second data connection between the first Bluetooth data processing module and the second Bluetooth data processing module, and the third data connection between the second Bluetooth data processing module and the Bluetooth protocol stack.
12. A Bluetooth device sharing device, wherein a host operating system and multiple virtual machine operating systems run in the device, wherein a first virtual machine operating system among the multiple virtual machine operating systems runs a Bluetooth protocol stack, and the other virtual machine operating systems do not need to run a Bluetooth protocol stack, characterized in that, include: The acquisition module is used to capture first data to be transmitted to the Bluetooth device by the data transmission module in the host operating system. The second virtual machine operating system is at least one virtual machine operating system other than the first virtual machine operating system among multiple virtual machine operating systems running in the electronic device. The first virtual machine operating system is a virtual machine operating system running a Bluetooth protocol stack. The data transmission module includes a hook module, which runs in the virtualization driver backend of the host operating system. The virtualization driver backend is paired with the virtualization driver frontend in the second virtual machine operating system. The acquisition module is specifically used to capture the first data to be transmitted to the Bluetooth device in the virtualization driver front-end of the second virtual machine operating system through the hook module. The first data is generated by an application in the second virtual machine operating system. A transmission module is used to transmit the first data to the Bluetooth protocol stack via the data transmission module; and to transmit the first data to the Bluetooth device via the Bluetooth protocol stack.
13. A Bluetooth device sharing device, characterized in that, Includes memory and processor; among which, The memory is used to store computer programs; The processor is configured to read the computer program stored in the memory and execute the Bluetooth device sharing method according to any one of claims 1-11 based on the computer program in the memory.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by the processor, implement the Bluetooth device sharing method according to any one of claims 1-11.