Bluetooth connection method and system and electronic equipment
By releasing the corresponding SDP resources in the Bluetooth protocol stack to solve the problem of connection conflict after Bluetooth restart, normal Bluetooth connection and interaction between electronic devices and wearable devices is achieved.
Patent Information
- Application Number
- CN202311138657.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-01
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2043-09-01
AI Technical Summary
When the Bluetooth switch of the electronic device is turned on again, the Bluetooth logo on the interface may appear to be displayed, but the normal connection between the sports and health applications and the wearable device is not possible, affecting the interaction.
By detecting error codes in the Bluetooth protocol stack, the SDP resource (such as an HFP connection) for processing the first connection is released, and the SDP resource (such as an SPP connection) for processing the second connection is released to avoid conflicts and wait states, ensuring that the next connection request can be processed normally.
It ensures that the Bluetooth of electronic devices can be connected to the wearable device normally after restarting, and ensures that the interaction between sports and health applications and watches is smooth.
Smart Images

Figure CN119603796A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Bluetooth technology, and in particular to a Bluetooth connection method, system and electronic device. Background Art
[0002] With the continuous development of wireless technology, Bluetooth technology is widely used in wearable devices, such as bracelets, watches and other devices. Electronic devices (such as mobile phones) are equipped with applications (such as sports health) that match wearable devices, so as to control wearable devices through the application and obtain data from wearable devices, such as updating the application software version in wearable devices, such as obtaining human body data detected by watches, etc.
[0003] When the Bluetooth switch in the electronic device is turned back on (including the three processes of turning the Bluetooth switch on-off-on), the Bluetooth of the electronic device will automatically reconnect to the hands-free profile (HFP) of the wearable device, and the sports health (application) will also request to establish a Bluetooth serial port profile (SPP) connection with the watch. However, the Bluetooth logo on the interface of the electronic device may show that Bluetooth is turned on, but the display interface of the sports health application shows that it is not connected to the wearable device, which affects the interaction between the sports health application and the wearable device. Summary of the invention
[0004] In order to solve the above technical problems, the present application provides a Bluetooth connection method, system and electronic device, so that after the Bluetooth of the electronic device is restarted, the sports health and the watch can establish a Bluetooth connection normally, ensuring the normal interaction between the sports health and the watch.
[0005] In a first aspect, the present application provides a Bluetooth connection method, which is applied to a first electronic device, the method comprising: a Bluetooth chip of the first electronic device establishes a physical link for Bluetooth communication with the second electronic device in response to a first connection request sent by a second electronic device; in the process of establishing the physical link for Bluetooth communication with the second electronic device, if the Bluetooth chip detects a second connection request initiated by the first electronic device through a Bluetooth protocol stack, the Bluetooth chip returns an error code to the Bluetooth protocol stack, the error code indicating that an operation of the Bluetooth chip in response to the second connection request conflicts with an operation in response to the first connection request sent by the second electronic device; the Bluetooth protocol stack releases a first service discovery protocol SDP resource in the Bluetooth protocol stack according to the error code, the first SDP resource being used to establish a first connection; when the Bluetooth protocol stack detects that the first SDP resource has been released, the second SDP resource in the Bluetooth protocol stack is released, the second SDP resource being used to establish a second connection, the first connection and the second connection being different protocol types in Bluetooth communication.
[0006] In this way, the Bluetooth protocol stack of the first electronic device (such as a mobile phone) releases the SDP resources used to process the first connection (such as an HFP connection) according to the error code, and when releasing the SDP resources used to process the first connection, releases the SDP resources used to process the second connection, so that the SDP resources in the Bluetooth protocol stack are restored to the default state, effectively avoiding the problem that the second connection (such as an SPP connection) is always in a waiting state or is in the process of processing the SPP connection, and ensures that the next time sports health or system Bluetooth sends a connection establishment request, the Bluetooth protocol stack can be executed according to the normal connection establishment process to establish a Bluetooth connection with the watch normally (such as including HFP connection and SPP connection, or including A2DP connection and SPP connection). Since the first electronic device and the second electronic device can establish a Bluetooth connection normally, the sports health of the mobile phone can interact normally with the watch. At the same time, the system Bluetooth (Bluetooth application) and sports health of the mobile phone both show that a Bluetooth connection is established with the watch.
[0007] According to the first aspect, the Bluetooth protocol stack releases the first service discovery protocol SDP resource in the Bluetooth protocol stack according to the error code, including: the link management module of the Bluetooth protocol stack responds to the error code and instructs the SDP module in the Bluetooth protocol stack to release the first SDP resource, wherein the first connection is a hands-free protocol HFP connection; the SDP module responds to the instruction of the link management module and obtains the first SDP resource; the SDP module changes the state of the first SDP resource from the first state to the second state, the first state indicating that the current SDP resource is processing the HFP connection, and the second state indicating that the state of the current SDP resource is an empty state. In this way, usually when the Bluetooth of the first electronic device is restarted, it will automatically reconnect to the HFP connection of the second electronic device. When the link management module of the Bluetooth protocol stack receives the error code, it obtains the first SDP resource and changes the state of the first SDP resource to the second state (i.e., the empty state), thereby providing conditions for establishing the HFP connection next time.
[0008] According to the first aspect, the SDP module obtains the first SDP resource in response to the instruction of the link management module, including: the SDP module searches for an SDP resource with a first tag as the first SDP resource, and the first tag is used to indicate that the current SDP resource is used to process the HFP connection. In this way, the SDP module marks the SDP resource used to process the HFP connection, so that when the SDP module can quickly find the SDP resource used to process the HFP connection according to the tag, the speed and accuracy of the search are improved.
[0009] According to the first aspect, when the Bluetooth protocol stack detects that the first SDP resource has been released, the second SDP resource in the Bluetooth protocol stack is released, including: when the SDP module in the Bluetooth protocol stack detects that the first SDP resource has been released, the second SDP resource is acquired, and the second connection is a Bluetooth serial port protocol SPP connection; the SDP module changes the state of the second SDP resource from a third state to a second state, the third state indicates that the current SDP resource is in a waiting state, and the second state indicates that the state of the current SDP resource is an empty state; the SDP module transmits information that the second SDP resource is in the second state to the Bluetooth data channel in the Bluetooth protocol stack; the Bluetooth data channel updates the identification identifier from the second identifier to the default identifier based on the information that the second SDP resource is in the second state, the default identifier is used to indicate that the SDP resource in the SDP module has not processed the Bluetooth serial port protocol SPP connection, and the second identifier is used to indicate that the SDP resource in the SDP module is processing the SPP connection. In this way, the second connection is an SPP connection, and the SDP module finds the SDP resources for processing the SPP connection, and updates the state of the SDP resources for processing the SPP connection to the second state, and the Bluetooth data channel updates the identification tag to the default state, so that the next time Sports Health initiates an SPP connection to the Bluetooth data channel, it will not be rejected by the Bluetooth data channel, thereby ensuring that the SDP module of the Bluetooth protocol stack can process the SPP connection request next time.
[0010] According to the first aspect, when the SDP module in the Bluetooth protocol stack detects that the first SDP resource has been released, the second SDP resource is obtained, including: when the SDP module detects that the first SDP resource has been released, the SDP module searches for the SDP resource generated based on the Bluetooth data channel indication as the basic SDP resource; the SDP module obtains the SDP resource in the third state from the basic SDP resource as the second SDP resource. In this way, the SDP module obtains the SDP resource generated based on the Bluetooth channel indication and obtains the SDP resource in the third state (i.e., the waiting state) in the SDP resource, and the second SDP resource can be quickly and accurately found through the dual conditions.
[0011] According to the first aspect, the SDP module transmits information that the second SDP resource is in the second state to a Bluetooth data channel in the Bluetooth protocol stack, including: the SDP module obtains a callback function bound to the second SDP resource; the SDP module transmits the information that the second SDP resource is in the second state to the Bluetooth data channel through the callback function. In this way, the SDP module can transmit the information that the second SDP resource is in the second state to the Bluetooth data channel through the callback function, and the information transmission method is simple and fast.
[0012] According to the first aspect, searching the SDP module for an SDP resource generated based on a Bluetooth data channel indication as a basic SDP resource includes: the SDP module obtains an SDP resource bound to a callback function as the basic SDP resource. In this way, the SDP module can quickly identify the SDP resource generated based on the Bluetooth data channel indication through the callback function.
[0013] According to the first aspect, the Bluetooth protocol stack releases the first service discovery protocol SDP resource in the Bluetooth protocol stack according to an error code, including: the link management module of the Bluetooth protocol stack responds to the error code, instructs the SDP module in the Bluetooth protocol stack to release the first SDP resource, wherein the first connection is a hands-free protocol HFP connection; the SDP module obtains the first SDP resource in response to the instruction of the link management module; the SDP module changes the state of the first SDP resource from a third state to a second state, the third state indicating that the current SDP resource is in a waiting state, and the second state indicating that the current SDP resource is in an empty state.
[0014] In this way, if the user manually triggers Sports Health to initiate a request for an SPP connection, and manually triggers the system Bluetooth to initiate a request to establish an HFP connection, the state of the first connection (i.e., the HFP connection) is in a waiting state, and the SDP module updates the state of the SDP resources used to process the HFP connection to the second state, thereby providing conditions for the next Bluetooth protocol stack to normally process the SPP connection request.
[0015] According to the first aspect, when the Bluetooth protocol stack detects that the first SDP resource has been released, the second SDP resource in the Bluetooth protocol stack is released, including: when the SDP module in the Bluetooth protocol stack detects that the first SDP resource has been released, the second SDP resource is acquired, and the second connection is a Bluetooth serial port protocol SPP connection; the SDP module changes the state of the second SDP resource from the fourth state to the second state, the fourth state indicates that the current SDP resource is processing the SPP connection, and the second state indicates that the state of the current SDP resource is an empty state; the SDP module transmits the information that the second SDP resource is in the second state to the Bluetooth data channel in the Bluetooth protocol stack; the Bluetooth data channel updates the identification mark from the second mark to the default mark based on the information that the second SDP resource is in the second state, the default mark is used to indicate that the SDP resource in the SDP module has not processed the Bluetooth serial port protocol SPP connection, and the second mark is used to indicate that the SDP resource in the SDP module is processing the SPP connection. In this way, the SDP module can release the SDP resources used to process the second connection in a timely manner.
[0016] According to the first aspect, before the Bluetooth chip of the first electronic device establishes a physical link for Bluetooth communication with the second electronic device in response to the first connection request sent by the second electronic device, the method also includes: the system Bluetooth of the first electronic device detects the user's operation of restarting the Bluetooth switch.
[0017] According to the first aspect, the method further includes: the first application interval preset duration sends a third connection request to the Bluetooth data channel; the Bluetooth data channel responds to the third connection request, the third connection request is a request to establish an SPP connection, and detects whether the identification identifier shown is a default identifier; if it is detected that it is, the Bluetooth data module requests the SDP module to process the SPP connection. In this way, when the Bluetooth protocol stack releases the SDP resources used to process the SPP connection, the SPP connection can be established according to the normal process.
[0018] In a second aspect, the present application provides an electronic device comprising: one or more processors; a memory; and one or more computer programs, wherein the one or more computer programs are stored in the memory, and when the computer programs are executed by the one or more processors, the electronic device executes the Bluetooth connection method corresponding to the first aspect and any one of the implementation methods of the first aspect.
[0019] The second aspect and any implementation of the second aspect correspond to the first aspect and any implementation of the first aspect respectively. The technical effects corresponding to the second aspect and any implementation of the second aspect can refer to the technical effects corresponding to the above-mentioned first aspect and any implementation of the first aspect, which will not be repeated here.
[0020] In a third aspect, the present application provides a computer-readable medium for storing a computer program. When the computer program is executed on an electronic device, the electronic device executes the Bluetooth connection method corresponding to the above-mentioned first aspect and any one of the implementations of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0022] Figure 1 is a schematic diagram of an application scenario in which a Bluetooth mobile phone is connected to a Bluetooth watch;
[0023] Figure 2 is a schematic diagram of a mobile phone interface showing an exemplary Bluetooth connection between a mobile phone and a watch;
[0024] Figure 3 is a schematic diagram showing an exemplary scenario of a mobile phone restarting Bluetooth;
[0025] Figure 4 is a schematic diagram showing an example of initiating a connection to a watch when the mobile phone turns on Bluetooth again;
[0026] Figure 5 is a schematic diagram exemplarily showing the structure of an electronic device;
[0027] Figure 6 is a software structure block diagram of an electronic device exemplarily shown;
[0028] Figure 7 is a schematic diagram showing exemplary operation of various modules of a Bluetooth connection;
[0029] Figure 8 is an exemplary diagram showing the interaction between various modules during the process of establishing a Bluetooth connection with a mobile phone after Bluetooth is turned on;
[0030] Fig. 9 The figure is a schematic diagram showing an exemplary scenario of a mobile phone restarting Bluetooth. DETAILED DESCRIPTION
[0031] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0032] The term "and / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0033] The terms "first" and "second" in the description and claims of the embodiments of the present application are used to distinguish different objects rather than to describe a specific order of objects. For example, a first target object and a second target object are used to distinguish different target objects rather than to describe a specific order of target objects.
[0034] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0035] In the description of the embodiments of the present application, unless otherwise specified, the meaning of "multiple" refers to two or more than two. For example, multiple processing units refer to two or more processing units; multiple systems refer to two or more systems.
[0036] The Bluetooth connection method provided in the present application is applied to a first electronic device, wherein a Bluetooth module is installed inside the first electronic device to provide a Bluetooth communication function, such as the first electronic device may be a mobile phone. The first electronic device communicates with a second electronic device via Bluetooth, and the second electronic device may be a wearable electronic device, such as a watch, a bracelet, etc.
[0037] In the present application, a mobile phone is taken as an example of an electronic device to which the Bluetooth connection method is applied. Figure 1 This is a schematic diagram of a scenario in which a Bluetooth connection is established between a Bluetooth mobile phone and a Bluetooth watch as exemplified in this application.
[0038] If the Bluetooth of the mobile phone 100 is not turned on, the user turns on the Bluetooth switch in the Bluetooth setting interface of the mobile phone. In response to the user turning on the Bluetooth switch, the mobile phone 100 turns on Bluetooth and sets the Bluetooth switch to the on state. Assuming that the default state of the Bluetooth of the watch 200 is on, when the mobile phone turns on the Bluetooth, the mobile phone will search for matching Bluetooth devices within the scanning range. In this example, the Bluetooth setting interface of the mobile phone shows that the devices that can be paired include the watch 200. In response to the user clicking the logo of the watch 200, the mobile phone establishes a Bluetooth connection with the watch 200.
[0039] Figure 1 The mobile phone 100 can establish a Bluetooth connection with the smart watch 200 through wireless communication technology, and the Bluetooth connection technology can be traditional Bluetooth or Bluetooth low energy (Bluetooh low energy, "BLE") technology.
[0040] The Bluetooth connection established between the mobile phone 100 and the watch 200 may include a hands-free profile (HFP) connection / Advance Audio Distribution Profile (A2DP) connection and a Bluetooth serial port profile (SPP) connection. In this example, the SPP may also be referred to as a Bluetooth socket. The watch and the mobile phone can transmit real-time voice calls via the HFP connection, and can transmit audio data (such as music) via the A2DP connection. The sports health application in the mobile phone can interact with the watch through the SPP connection, such as notification messages, human body data obtained by the watch, etc.
[0041] In some embodiments, a dynamic HFP connection is established between the mobile phone and the watch. For example, when the mobile phone responds to the operation of establishing a Bluetooth connection with the watch, a Bluetooth connection is established between the mobile phone and the watch, and the Bluetooth connection includes an HFP connection, an A2DP connection, and an SPP connection. After the Bluetooth connection between the mobile phone and the watch is established, the mobile phone disconnects the HFP connection. When the mobile phone receives an incoming call notification, the watch establishes an HFP connection with the mobile phone according to the incoming call notification sent by the mobile phone. When the mobile phone receives a request to hang up the call, the watch disconnects the HFP connection with the mobile phone according to the notification of the mobile phone turning off the call.
[0042] It should be noted that each time the mobile phone and the watch re-establish a Bluetooth connection, an HFP connection between the mobile phone and the watch needs to be established.
[0043] Figure 2 The figure is a schematic diagram of a mobile phone interface showing an exemplary establishment of a Bluetooth connection between a mobile phone and a watch.
[0044] like Figure 2 As shown in 2a in FIG. 2, when the mobile phone successfully establishes a Bluetooth connection with the mobile phone, the mobile phone displays a Bluetooth setting interface 201 in response to the user's operation of opening the Bluetooth setting interface. The Bluetooth setting interface 201 includes: a Bluetooth switch 203, and device information that the mobile phone can pair with (such as AAA, BBB shown in 2a). The Bluetooth switch 203 is used to control the opening and closing of the Bluetooth function. Figure 2 As shown in FIG. 2a , the Bluetooth switch 203 is turned on and a Bluetooth logo 202 is also displayed in the Bluetooth setting interface 201 , and the Bluetooth logo 202 is also used to indicate that the Bluetooth in the mobile phone is turned on.
[0045] like Figure 2 As shown in 2b, the user clicks the sports health (application) icon on the main screen interface 204, and the mobile phone responds to the user's click operation and displays the sports health application interface 205. The interface 205 displays a Bluetooth logo 206 and a first option 207, and the first option 207 is used to indicate the connection status between the mobile phone and the watch. Figure 2 As shown in 2c, the first option 207 in the interface 205 indicates that the mobile phone and the watch are connected.
[0046] The sports health application can obtain human body data monitored by the watch through the SPP connection, such as blood oxygen data, heart rate data, sleep monitoring, etc. The mobile phone can also update the software version information in the watch through the sports health application.
[0047] In some embodiments, when a Bluetooth connection is established between a mobile phone and a watch, if the mobile phone responds to the user's operation of restarting Bluetooth, the mobile phone system may display that a Bluetooth connection has been established with the watch, but the sports health application may display that the mobile phone and the watch are not connected. Figure 3The schematic diagram of the scenario in which a mobile phone restarts Bluetooth is shown as an example. Figure 3 3a, 3b and 3c in the figure indicate the process of the Bluetooth switch being turned on, turned off and turned on, which is the process of restarting the Bluetooth switch.
[0048] like Figure 3 As shown in Figure 3a, the Bluetooth setting interface 301 of the mobile phone includes a Bluetooth logo 302 and a Bluetooth switch 303. The Bluetooth switch 303 is in the on state. In response to the user clicking the Bluetooth switch 303, the mobile phone turns off Bluetooth, and the Bluetooth connection between the mobile phone and the watch is disconnected, that is, the HFP connection, the A2DP connection, and the SPP connection are all disconnected. The mobile phone updates the state of the Bluetooth switch to the off state, as shown in Figure 3a. Figure 3 As shown in 3b, the Bluetooth setting interface 304 does not display the Bluetooth logo, and the Bluetooth switch 305 is in the off state.
[0049] The user clicks the Bluetooth switch 305, and the mobile phone responds to the user's click operation, turns on Bluetooth and updates the state of the Bluetooth switch to the on state, such as Figure 3 As shown in 3c, the Bluetooth setting interface 306 displays a Bluetooth logo 307, and the Bluetooth switch 308 is turned on. When the mobile phone turns on Bluetooth, the watch will send a first connection request to the Bluetooth chip of the mobile phone. The Bluetooth chip of the mobile phone responds to the first connection request and establishes a physical link with the watch. The first connection request can be an HFP connection or an A2DP connection.
[0050] At the same time, when the mobile phone turns on Bluetooth, the system Bluetooth of the mobile phone will automatically connect back to the HFP call service of the watch (i.e. HFP connection). Specifically, the system Bluetooth (or Bluetooth application) sends an HFP connection request or an A2DP connection request to the Bluetooth chip of the mobile phone.
[0051] When the mobile phone's sports health application detects the Bluetooth switch is turned on, it can send an SPP connection request to the mobile phone's Bluetooth chip, wherein the request to establish an SPP connection is usually sent by the mobile phone's sports health. The mobile phone's Bluetooth chip first receives the first return connection request sent by the watch, and the mobile phone's Bluetooth chip, based on the first return connection request, starts to establish a physical link for Bluetooth communication with the watch as a slave device. When the mobile phone's Bluetooth chip receives the SPP connection request sent by the mobile phone's sports health or the HFP connection request sent by the system Bluetooth, the Bluetooth chip prepares to establish a physical link for communication with the watch as a master device based on the SPP connection request sent by the sports health or the HFP connection request sent by the system Bluetooth, resulting in a conflict between the mobile phone and the watch interconnection contact with different identities at the same time, and the mobile phone's Bluetooth chip returns an error code (such as Control busy) to the mobile phone's Bluetooth protocol stack. After receiving the error code, the Bluetooth protocol stack will release the SDP resources used to process the HFP connection, but will not release the SDP resources used to process the SPP connection (the SDP resources are in a waiting state), resulting in the inability to establish an SPP connection, and the mobile phone's sports health interface shows that it is not connected to the watch.
[0052] like Figure 3 As shown in 3d and 3e, the user clicks the icon of the sports health application in the main screen interface 309 to display the sports health application interface 310. The interface 310 displays a Bluetooth logo 312 and a first option 311, and the first option 311 is used to indicate the connection status between the mobile phone and the watch. Figure 3 As shown in 3e, the first option 311 indicates that the mobile phone and the watch are not connected.
[0053] Combine the following Figure 4 Specifically describes the process of initiating a Bluetooth connection to the watch when the phone turns Bluetooth back on.
[0054] Step 4101: The system Bluetooth of the mobile phone sends an HFP connection request to the SDP module in the Bluetooth protocol stack.
[0055] Exemplarily, when the watch detects that the mobile phone has turned on Bluetooth, it will initiate a connection request (such as an A2DP connection) to the Bluetooth chip of the mobile phone. In response to the connection request, the Bluetooth chip of the mobile phone establishes a physical link for Bluetooth communication with the watch. When the mobile phone turns on Bluetooth, the mobile phone will also initiate a connection request to the Bluetooth chip of the mobile phone through the Bluetooth protocol stack of the mobile phone. Optionally, the connection request of the mobile phone may include: HFP connection, A2DP connection and SPP connection. Among them, the system Bluetooth (or Bluetooth application) of the mobile phone sends a connection request to establish an HFP connection and a connection request to establish an A2DP connection to the Bluetooth protocol stack of the mobile phone. The sports health application of the mobile phone sends a connection request to establish an SPP connection to the Bluetooth protocol stack of the mobile phone.
[0056] The Bluetooth protocol stack runs in serial mode. The Bluetooth protocol stack can process HFP connection / A2DP connection and SPP connection in sequence. In this example, Figure 4 As shown, when the phone detects that the Bluetooth switch is turned on, the system Bluetooth will automatically connect to the watch's HFP call service (that is, the system Bluetooth will automatically request to establish an HFP connection with the watch).
[0057] In this example, the system Bluetooth sends a connection request to establish an HFP connection to the Bluetooth protocol stack first. After the system Bluetooth sends the HFP connection request to the Bluetooth protocol stack, Sports Health sends a connection request to establish an SPP connection to the Bluetooth protocol stack.
[0058] Step 4102: The SDP module allocates SDP resources for processing the HFP connection, sets the state of the SDP resources for processing the HFP connection to SETUP; and sends a link connection request to the link management layer.
[0059] Exemplarily, upon receiving an HFP connection request sent by the system Bluetooth, the SDP module allocates SDP resources for the request, and the allocated SDP resources are used to process the service discovery process of the HFP connection. The SDP module adds the SDP resources used to process the HFP connection to a queue, and sets the state of the SDP resources used to process the HFP connection to SETUP, where "SETUP" is used to indicate that the SDP resources are currently executing the service discovery process of the HFP connection. Optionally, the SDP module may also mark the SDP resources used to process the HFP connection.
[0060] After setting the state of the SDP resources for processing the HFP connection to SETUP, the SDP module sends a link connection request to the link management layer (ie, the link management module).
[0061] Step 4103: The link management layer sends a link connection request to the Bluetooth chip in response to the link connection request sent by the SDP module.
[0062] Step 4104: The Bluetooth chip takes the watch as the primary device and, in the process of establishing a physical link for Bluetooth communication with the watch, responds to the link connection request sent by the link management layer of the mobile phone and returns an error code to the link management layer.
[0063] Exemplarily, based on the first reconnection request (such as HFP connection request) sent by the watch, the mobile phone's Bluetooth chip uses the watch as the master device and the mobile phone as the slave device to start establishing a physical link for Bluetooth communication with the watch. During the process of the Bluetooth chip establishing a physical link for Bluetooth communication with the watch as a slave device, if the Bluetooth chip receives a link connection request (such as HCI_Create_Logical_Link) sent by the link management layer of the mobile phone, the Bluetooth chip prepares to establish a physical link for communication with the watch as a master device, resulting in a conflict between the mobile phone and the watch in interconnection contact with different identities at the same time, and the Bluetooth chip of the mobile phone returns an error code (such as Control busy) to the Bluetooth protocol stack of the mobile phone. The Bluetooth chip returns the error code to the link management layer.
[0064] Step 4105: The link management layer instructs the SDP module to release the SDP resources for processing the HFP connection.
[0065] Exemplarily, in response to the error code (i.e., Control busy), the link management layer instructs the SDP module to release the SDP resources that are processing the HFP connection. In this example, the link management layer may call a link request failure function to instruct the SDP module to release the SDP resources that are processing the HFP connection, such as SDP disconennect(fail).
[0066] Step 4106: The SDP module releases the SDP resources for processing the HFP connection.
[0067] Exemplarily, the SDP module receives an instruction sent by the link management layer and resets the SDP resource for processing the HFP connection. Specifically, the SDP module can search for the SDP resource for processing the HFP connection (hereinafter, the SDP resource may be referred to as the SDP resource of the HFP) according to the tag of the HFP connection. The SDP module sets the state of the SDP resource of the HFP to NONE.
[0068] In this example, Figure 4 Steps 4021 to 4023 in the figure are the process of Sports Health sending a Bluetooth Socket connection request to the Bluetooth protocol stack.
[0069] Step 4021: Sports Health sends a Bluetooth Socket connection request to the Bluetooth data channel in the Bluetooth protocol stack.
[0070] In some embodiments, after the sports health application detects that the Bluetooth switch is turned on, it sends a request to establish an SPP connection (ie, a Bluetooth Socket connection request) to the Bluetooth data channel of the Bluetooth protocol stack.
[0071] In this example, the time when the system Bluetooth sends a request for HFP connection to the SDP module is earlier than the time when the sports health application sends a request for establishing SPP connection to the Bluetooth data channel of the Bluetooth protocol stack.
[0072] Step 4202: The Bluetooth data channel detects whether the identification flag is NO. If so, the Bluetooth data channel sets the identification flag to YES and sends a Bluetooth Socket connection request to the SDP module.
[0073] Exemplarily, in response to a Bluetooth Socket connection (i.e., SPP connection) request sent by a sports health application, the Bluetooth data channel detects whether the value of the identification mark is NO. If so, a Bluetooth Socket connection request is sent to the SDP module, and the value of the identification mark is set to YSE, such as SDP = YES. When the value of the identification mark is YES, it is used to indicate that the SDP module is processing the SPP connection; when the value of the identification mark is NO, it is used to indicate that the SDP module is not processing the SPP connection.
[0074] Step 4203: The SDP module allocates SDP resources for processing the SPP connection, and sets the state of the SDP resources for processing the SPP connection to PEND.
[0075] Exemplarily, the SDP module receives a Bluetooth Socket connection request sent by the Bluetooth data channel, allocates SDP resources for the request, and the allocated SDP resources are used to process the service discovery process of the SPP connection (hereinafter, the SDP resources used to process the SPP connection are referred to as the SDP resources of the SPP). The SDP module adds the SDP resources used to process the SPP connection to the queue. Since the SDP resources of the HFP are in the SDP service of the HFP connection, the SDP module sets the state of the SDP resources of the SPP to PEND, and "PEND" is used to indicate that the SDP resources of the SPP are in a waiting state to wait for the SDP resources of the HFP to complete processing.
[0076] In this example, the Bluetooth chip returns Control busy to the link management layer. The link management layer instructs the SDP module to release the SDP resources of HFP based on the error code. However, the link management layer does not instruct the SDP module to release the SDP resources of SPP. The SDP resources of SPP are always in a waiting state, which makes it impossible to continue the process of establishing an SPP connection with the watch. When the sports health application sends a Bluetooth Socket connection request to the Bluetooth data channel again, it cannot connect successfully. For example, Figure 4 Steps 4301 to 4302 are shown.
[0077] Step 4301: Sports Health sends a Bluetooth Socket connection request to the Bluetooth data channel in the Bluetooth protocol stack.
[0078] Step 4302: The Bluetooth data channel detects whether the identification flag is NO. If not, the Bluetooth data channel rejects the request.
[0079] Exemplarily, in response to a Bluetooth Socket connection request sent by a sports health application, the Bluetooth data channel detects whether the value of the identification tag is NO. If not, the Bluetooth data channel rejects the Bluetooth Socket connection request and returns information of the rejection request to the sports health application.
[0080] The embodiment of the present application provides a method for Bluetooth connection, which is applied to a first electronic device, which can be a mobile phone. The Bluetooth chip of the first electronic device responds to the first connection request sent by the second electronic device to establish a physical link for Bluetooth communication with the second electronic device; in the process of establishing a physical link for Bluetooth communication with the second electronic device, if the Bluetooth chip detects the second connection request initiated by the first electronic device through the Bluetooth protocol stack, it returns an error code to the Bluetooth protocol stack, and the error code is used to indicate that the second connection request conflicts with the first connection request; the Bluetooth protocol stack releases the first service discovery protocol SDP resource in the Bluetooth protocol stack according to the error code, and the first SDP resource is used to establish the first connection; when the Bluetooth protocol stack detects that the first SDP resource has been released, the second SDP resource in the Bluetooth protocol stack is released, and the second SDP resource is used to establish the second connection, and the first connection and the second connection are different protocol types in Bluetooth communication. In this example, the Bluetooth protocol stack releases the SDP resources used to process the first connection and the SDP resources used to process the second connection, so as to avoid the problem that the watch and the mobile phone cannot be connected because the Bluetooth protocol stack is always in the process of processing a certain connection.
[0081] Figure 5 This is a schematic diagram of the structure of an electronic device 100 shown in an embodiment of the present application. It should be understood that: Figure 5 The electronic device 100 shown is only one example of an electronic device, and the electronic device 100 may have more or fewer components than shown in the drawings, may combine two or more components, or may have a different configuration of components. Figure 5 The various components shown in the figure can be implemented in hardware, software, or a combination of hardware and software including one or more signal processing and / or application specific integrated circuits. In this example, the electronic device 100 is taken as an example of a mobile phone.
[0082] The electronic device 100 may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, etc.
[0083] The Bluetooth chip of the electronic device 100 can be paired with the Bluetooth chip in the watch and establish a wireless connection to achieve wireless communication and business processing between the electronic device 100 and the watch through the wireless connection. Generally, the Bluetooth chip can support basic rate (BR) / enhanced data rate (EDR) Bluetooth and BLE, for example, it can receive / send paging information, receive / send BLE broadcast messages, etc.
[0084] Figure 6 It is a software structure block diagram of the electronic device according to an embodiment of the present application.
[0085] The layered architecture of electronic devices divides the software into several layers, each with a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: application layer, application framework layer, hardware abstraction layer (HAL) and kernel layer. It is understandable that Figure 4 The layers in the software structure and the components contained in each layer do not constitute a specific limitation on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer layers than shown in the figure, and each layer may include more or fewer components, which is not limited in the present application.
[0086] like Figure 6As shown, the application layer can include a series of application packages. The application packages can include sports health, Bluetooth, Wi-Fi, camera, gallery, short message and other applications. The application framework layer provides application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0087] like Figure 6 As shown, the application framework layer may include a Bluetooth manager, a Wi-Fi manager, and a camera manager. The application framework layer may also include: a window manager, a resource manager, a content provider, a view system, a phone manager, a notification manager, and the like.
[0088] The Bluetooth manager can provide a system Bluetooth programming interface (bluetooth API) so that the system Bluetooth and accessory management service applications, the system Bluetooth and hardware drivers (such as sensor drivers), and the accessory management service applications and hardware drivers (such as sensor drivers) can interact by calling the system Bluetooth programming interface.
[0089] Camera Manager System service used to query and establish camera connections.
[0090] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0091] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0092] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0093] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0094] The phone manager is used to provide communication functions of the electronic device 200, such as management of call status (including connecting, hanging up, etc.).
[0095] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0096] HAL can include the Bluetooth protocol stack, which can include multiple layers of Bluetooth protocols. Each layer of protocol defines the functions completed and the packet format of the used data to ensure the interoperability between Bluetooth devices. The transmission of Bluetooth audio data relies on the Bluetooth protocol. The Bluetooth protocol adopts a layered structure, forming a Bluetooth protocol stack from the bottom layer to the top layer. The protocols in the Bluetooth protocol system are divided into core protocols, cable replacement protocols, telephone transmission control protocols and optional protocols according to the degree of attention of the application layer control protocol (Session Initiation Protocol, SIG). Among them, the Bluetooth core protocol is composed of Bluetooth-specific protocols formulated by SIG, including baseband protocol, link management protocol (Link Manager Protocol, LMP), logical link control and adaptation protocol (Logical Link Control and Adaptation Protocol, L2CAP) and service discovery protocol (Service Discovery Protocol, SDP). L2CAP is the upper layer protocol of the baseband and works in parallel with LMP. SDP plays a vital role in the Bluetooth technology framework. It is the basis of all user modes. Using SDP, you can query device information and service types, so as to establish corresponding connections between Bluetooth devices.
[0097] The kernel layer is the layer between hardware and software. The kernel layer contains at least Bluetooth driver, display driver, camera driver, audio driver, sensor driver, etc.
[0098] Figure 7 The figure is a schematic diagram showing the operation of each module of the Bluetooth connection.
[0099] like Figure 7 As shown, the sports health at the application layer transmits an SPP connection request to the Bluetooth framework API. The Bluetooth framework API transmits the SPP connection request to the Bluetooth protocol stack. The system Bluetooth sends an HFP connection request or an A2DP connection request to the Bluetooth protocol stack. The SDP module of the Bluetooth protocol stack processes the HFP connection request or A2DP connection request sent by the system Bluetooth and the SPP connection request sent by the sports health in sequence according to the order of the requests.
[0100] Figure 8 is an interactive diagram of an exemplary Bluetooth connection, such as Figure 8 As shown, the Bluetooth connection process includes:
[0101] Step 801: The watch sends a link connection request to the Bluetooth chip of the mobile phone.
[0102] Step 802: The system Bluetooth requests the SDP module of the Bluetooth protocol stack to establish an HFP connection.
[0103] Step 803: In response to the request for establishing an HFP connection sent by the system Bluetooth, the SDP module allocates SDP resources for processing the HFP connection and sets the state of the SDP resources for processing the HFP connection to SETUP.
[0104] Step 804: The SDP module sends a link connection request to the link management layer.
[0105] Step 805: The link management layer sends a link connection request to the Bluetooth chip.
[0106] The relevant processes of step 801 to step 805 are similar to the processes of step 4101 to step 4103. The relevant descriptions can refer to step 4101 to step 4103, and will not be repeated here.
[0107] In one embodiment, Sports Health sends a connection request to the Bluetooth data channel to establish an SPP connection later than System Bluetooth sends a connection request to the Bluetooth data channel to establish an HFP connection. Steps 806 to 809 are steps executed by the Bluetooth protocol stack in response to the connection request to establish the SPP connection.
[0108] Step 806: The sports health application requests the Bluetooth data channel to establish an SPP connection.
[0109] This step can refer to the relevant description in step 4021 and will not be repeated here.
[0110] Step 807: The Bluetooth data channel responds to the request by detecting whether the identification flag is NO. If the identification flag is NO, the identification flag is set to YES.
[0111] Specifically, when the Bluetooth data channel receives a connection request to establish an SPP connection, it can detect whether the value of the identification mark is NO. If the Bluetooth data channel detects that the value of the identification mark is NO (such as SDP=NO), it is determined that the SDP module does not process the SPP connection. The Bluetooth data channel can request the SDP module to establish an SPP connection and set the value of the identification mark to YES, such as SDP=YES.
[0112] In this example, the Bluetooth data channel may first set the value of the identification mark to YES, and then request the SDP module to establish an SPP connection. Alternatively, the Bluetooth data channel may first request the SDP module to establish an SPP connection, and then set the value of the identification mark to YES.
[0113] Step 808: The Bluetooth data channel requests the SDP module to establish an SPP connection.
[0114] Exemplarily, the Bluetooth data channel sends a connection request for establishing an SPP connection to the SDP module, and the connection request may include: a callback function, and the callback function is used to transmit the state information of the SDP resources allocated by the SDP module based on the SPP connection request.
[0115] Step 809: The SDP module allocates SDP resources for processing the SPP connection in response to the request sent by the Bluetooth data channel, and sets the state of the SDP resources for processing the SPP connection to a waiting state.
[0116] Exemplarily, the SDP module adopts serial processing. Since the SDP module first receives the connection request for establishing the HFP connection, the SDP module first processes the HFP connection. Therefore, when the SDP module receives the request for establishing the SPP connection, it allocates SDP resources for processing the service discovery process of the SPP connection (hereinafter, the SDP resources for processing the SPP connection are referred to as SDP resources of the SPP). The SDP module adds the SDP resources of the SPP to the queue and sets the state of the SDP resources of the SPP to a waiting state (with PEND marking the waiting state), such as "con_state = PEND".
[0117] In this example, since the request to establish the SPP connection carries a callback function, the callback function can be bound to the SDP resource of the SPP, so that the callback function can return the status information of the SDP resource of the SPP to the Bluetooth data channel in time.
[0118] Step 810: The Bluetooth chip returns an error code to the link management layer.
[0119] For example, according to the first reconnection request (such as HFP connection request) sent by the watch, the mobile phone uses the watch as the master device and the mobile phone as the slave device to start establishing a physical link for Bluetooth communication with the watch. During the process of the Bluetooth chip establishing a physical link for Bluetooth communication with the watch as a slave device, if the Bluetooth chip receives a link connection request (such as HCI_Create_Logical_Link) sent by the link management layer of the mobile phone, the Bluetooth chip prepares to establish a physical link for communication with the watch as a master device, resulting in a conflict between the mobile phone and the watch in interconnection contact with different identities at the same time, and the Bluetooth chip of the mobile phone returns the error code to the link management layer.
[0120] Step 811: The link management layer instructs the SDP module to release the SDP resources for processing the HFP connection according to the error code.
[0121] Step 812: The SDP module marks the state of the SDP resource used to process the HFP connection as an empty state.
[0122] Exemplarily, the SDP module receives an instruction sent by the link management layer, searches for SDP resources of HFP, and resets the state of SDP resources of HFP to NONE, such as the SDP module changes the state of SDP resources of HFP from "con_state=SETUP" to "con_state=NONE".
[0123] Step 813: The SDP module detects that the SDP resources for processing the HFP connection have been released, and releases the SDP resources waiting to process the SPP connection.
[0124] Exemplarily, the SDP module detects that the state of the SDP resources of the HFP is an empty state, and determines that the SDP module has released the SDP resources of the HFP. When the SDP module determines that the SDP resources of the HFP have been released, the SDP resources of the SPP are searched. Optionally, the SDP module can search for SDP resources that are bound to the callback function and are in a waiting state, and use the found SDP resources as the SDP resources of the SPP.
[0125] The SDP module changes the state of the SDP resource of the SPP from the waiting state (con_state=PEND) to the empty state (con_state=NONE).
[0126] Since the SDP resource of the SPP is bound to the callback function, the SDP module can return the status of the SDP resource of the SPP to the Bluetooth data channel through the callback function.
[0127] Step 814: The SDP module instructs the Bluetooth data channel to reset the identification flag to NO.
[0128] Exemplarily, the SDP module receives the state of the SDP resource of the SPP returned by the SDP module (ie, an empty state), and the Bluetooth data channel sets the value of the identification flag to NO, ie, SDP=NO.
[0129] In one embodiment, before executing step 813, if Sports Health sends a connection request to the Bluetooth data channel to establish an SPP connection again, such as Figure 8 As shown in step 8211:
[0130] Step 8211: The sports health application requests the Bluetooth data channel to establish an SPP connection.
[0131] Step 8212: The Bluetooth data channel responds to the request and detects whether the identification mark is NO. If the identification mark is detected to be YES, the request to establish the SPP connection is rejected.
[0132] The Bluetooth data channel responds to the request and detects whether the value of the identification mark is NO. If the Bluetooth data channel detects that the identification mark is YES, information of rejecting the request to establish the SPP connection may be returned to the sports health application.
[0133] In one embodiment, after executing step 814, if Sports Health sends a connection request to the Bluetooth data channel to establish an SPP connection again, the Bluetooth data channel responds to the request and detects whether the value of the identification identifier is NO. Since step 814 has reset the identification identifier to NO. The Bluetooth data channel detects that the identification identifier is NO, and can send a request to the SDP module to establish an SPP connection. The SDP module allocates SDP resources for processing the service discovery process of the SPP connection, and since there are no SDP resources being processed at this time, the status of the SPP SDP resources can be set to an ongoing state (with the SETUP mark indicating the ongoing state), such as "con_state = SETUP". If a physical link has been established between the Bluetooth chip of the mobile phone and the Bluetooth chip of the watch, the SDP module can execute a service query process for the SPP connection. The subsequent process of establishing the SPP connection can be referred to, which will not be repeated here. The mobile phone establishes an SPP connection with the watch. Fig. 9 As shown in 9a of FIG. 9 , in the main screen interface 901, click the icon of the sports health application to display the interface 902 of the sports health application. Fig. 9 As shown in 9b of FIG. 9 , the interface 902 displays a Bluetooth logo 903 and a first option 904, and the first option 904 is used to indicate the connection status between the mobile phone and the watch. Fig. 9 As shown in 9b, the first option 904 indicates that the mobile phone and the watch are connected.
[0134] In this example, when the SDP module detects that the SDP resources of HFP have been released, it resets the SDP resources of SPP and returns the status of the SDP resources of SPP to the Bluetooth data channel, so that the Bluetooth data channel sets the identification mark according to the status of the SDP resources of SPP returned by the SDP module. Since the identification mark in the Bluetooth data channel is reset to the default value, the next request to establish an SPP connection sent by Sports Health will not be rejected, and the mobile phone and watch can establish an SPP connection.
[0135] In other embodiments, if the mobile phone restarts Bluetooth, the mobile phone's sports health responds to the user's first operation (such as the user clicking the connection operation), and the moment when the sports health sends a connection request to the Bluetooth chip to establish an SPP connection is earlier than the moment when the system Bluetooth sends a connection request to the Bluetooth chip to establish an HFP connection. The specific process is as follows:
[0136] Step 1001: Sports Health sends a Bluetooth Socket connection request to the Bluetooth data channel in the Bluetooth protocol stack.
[0137] Step 1002: The Bluetooth data channel detects whether the identification flag is NO. If so, the Bluetooth data channel sets the identification flag to YES and sends a Bluetooth Socket connection request to the SDP module.
[0138] Step 1001 to step 1002 are similar to step 806 to step 807 and will not be described again here.
[0139] Step 1003: The SDP module allocates SDP resources for processing the SPP connection, and sets the state of the SDP resources for processing the SPP connection to SETUP.
[0140] Exemplarily, the SDP module receives a Bluetooth Socket connection request sent by the Bluetooth data channel, allocates SDP resources for the request, and the allocated SDP resources are used to process the service discovery process of the SPP connection (hereinafter, the resources used to process the SPP connection may be referred to as the SDP resources of the SPP). The state of the SPP SDP resources is set to SETUP, and "SETUP" is used to indicate that the SPP SDP resources process the SPP connection.
[0141] In this example, since the request to establish the SPP connection carries a callback function, the callback function can be bound to the SDP resource of the SPP, so that the callback function can return the status information of the SDP resource of the SPP to the Bluetooth data channel in time.
[0142] Step 1004: The link management layer sends a link connection request to the Bluetooth chip in response to the link connection request sent by the SDP module.
[0143] In one embodiment, Sports Health sends a connection request to the Bluetooth data channel to establish an SPP connection earlier than the system Bluetooth sends a connection request to the Bluetooth data channel to establish an HFP connection. Steps 1005 to 1006 are steps executed by the Bluetooth protocol stack in response to the connection request to establish the HFP connection.
[0144] Step 1005: The system Bluetooth requests the SDP module of the Bluetooth protocol stack to establish an HFP connection.
[0145] This step is similar to step 802 and will not be described again here.
[0146] Step 1006: In response to the request for establishing an HFP connection sent by the system Bluetooth, the SDP module allocates SDP resources for processing the HFP connection and sets the SDP resources for processing the HFP connection as PEND.
[0147] The SDP module adopts serial processing. Since the SDP module first receives the connection request for establishing the SPP connection, the SDP module first processes the SPP connection. Therefore, when the SDP module receives the request for establishing the HFP connection, it allocates SDP resources for processing the service discovery process of the HFP connection (hereinafter, the SDP resources for processing the HFP connection are referred to as the SDP resources of the HFP), and adds the SDP resources of the HFP to the queue. The SDP module sets the state of the SDP resources of the HFP to the waiting state (with PEND to identify the waiting state), such as "con_state = PEND".
[0148] Step 1007: The Bluetooth chip returns an error code to the link management layer.
[0149] This step is similar to step 810 and will not be described again here.
[0150] Step 1008: The link management layer instructs the SDP module to release the SDP resources for processing the HFP connection.
[0151] Exemplarily, the SDP module receives an instruction from the link management layer and searches for the SDP resource of HFP. The SDP module resets the state of the SDP resource of HFP to NONE, such as changing the state of the SDP resource of HFP from "con_state=PEND" to "con_state=NONE".
[0152] Step 1009: When the SDP module detects that the SDP resources for processing the HFP connection have been released, the SDP module releases the SDP resources for processing the SPP connection.
[0153] Exemplarily, the SDP module detects that the state of the SDP resource of the HFP is an empty state, and determines that the SDP module has released the SDP resource of the HFP. When the SDP module determines that the SDP resource of the HFP has been released, the SDP resource of the SPP is searched. Optionally, the SDP module can search for an SDP resource that is bound to the callback function and has a state of SETUP, and use the found SDP resource as the SDP resource of the SPP.
[0154] The SDP module changes the state of the SDP resource of the SPP from SETUP (con_state=SETUP) to the null state (con_state=NONE).
[0155] Since the SDP resource of the SPP is bound to the callback function, the SDP module can return the status of the SDP resource of the SPP to the Bluetooth data channel through the callback function.
[0156] Step 1010: The SDP module instructs the Bluetooth data channel to reset the identification flag to NO.
[0157] Exemplarily, the SDP module receives the state of the SDP resource of the SPP returned by the SDP module (ie, an empty state), and the Bluetooth data channel sets the value of the identification flag to NO, ie, SDP=NO.
[0158] Regardless of whether the system application of the mobile phone sends a connection request before Sports Health, the link management layer instructs the SDP module to release the SDP resources used to process the HFP connection in response to the Controlbusy error code, resulting in the SDP resources used for the SPP connection cannot be released. Even if the mobile phone's Sports Health resends the SPP connection request, it cannot establish the SPP connection. In this example, the SDP module releases the SDP resources used to process the HFP connection, resets the status of the SPP SDP resources, and returns the status of the SPP SDP resources to the Bluetooth data channel, so that the Bluetooth data channel sets the identification mark according to the status of the SPP SDP resources returned by the SDP module, so that the SDP resources used to process the SPP connection will not always be in a waiting state or an ongoing state (such as SETUP), so that the mobile phone can establish a Bluetooth connection with the mobile phone.
[0159] It is understandable that, in order to realize the above functions, the electronic device includes hardware and / or software modules corresponding to the execution of each function. In combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to be beyond the scope of the present application.
[0160] This embodiment also provides a computer storage medium, in which computer instructions are stored. When the computer instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the Bluetooth connection method in the above-mentioned embodiment. The storage medium includes: a U disk, a mobile hard disk, a read only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0161] This embodiment further provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute the above-mentioned related steps to implement the Bluetooth connection method in the above-mentioned embodiment.
[0162] Among them, the electronic device, computer storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above and will not be repeated here.
[0163] Any content of each embodiment of the present application, as well as any content of the same embodiment, can be freely combined. Any combination of the above content is within the scope of the present application.
[0164] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A Bluetooth connection method, characterized in that: Applied to a first electronic device, the method includes: The Bluetooth chip of the first electronic device establishes a physical link for Bluetooth communication with the second electronic device in response to the first connection request sent by the second electronic device; During the process of establishing a physical link for Bluetooth communication with the second electronic device, if the Bluetooth chip detects a second connection request initiated by the first electronic device through the Bluetooth protocol stack, the Bluetooth chip returns an error code to the Bluetooth protocol stack, wherein the error code indicates that an operation of the Bluetooth chip in response to the second connection request conflicts with an operation in response to the first connection request sent by the second electronic device; The Bluetooth protocol stack releases a first service discovery protocol SDP resource in the Bluetooth protocol stack according to the error code, where the first SDP resource is used to establish a first connection; When the Bluetooth protocol stack detects that the first SDP resource is released, the second SDP resource in the Bluetooth protocol stack is released, where the second SDP resource is used to establish a second connection, and the first connection and the second connection are different protocol types in Bluetooth communication.
2. The method according to claim 1, characterized in that The Bluetooth protocol stack releases a first service discovery protocol SDP resource in the Bluetooth protocol stack according to the error code, including: The link management module of the Bluetooth protocol stack instructs the SDP module in the Bluetooth protocol stack to release the first SDP resource in response to the error code, wherein the first connection is a hands-free protocol HFP connection; The SDP module acquires the first SDP resource in response to an instruction of the link management module; The SDP module changes the state of the first SDP resource from a first state to a second state, wherein the first state indicates that the current SDP resource is processing an HFP connection, and the second state indicates that the state of the current SDP resource is an empty state.
3. The method according to claim 2, characterized in that The SDP module acquires the first SDP resource in response to an instruction of the link management module, including: The SDP module searches for an SDP resource with a first tag as a first SDP resource, where the first tag is used to indicate that a current SDP resource is used to process the HFP connection.
4. The method according to claim 1, characterized in that: When the Bluetooth protocol stack detects that the first SDP resource has been released, releasing the second SDP resource in the Bluetooth protocol stack includes: When the SDP module in the Bluetooth protocol stack detects that the first SDP resource has been released, the second SDP resource is acquired, where the second connection is a Bluetooth serial port protocol SPP connection; The SDP module changes the state of the second SDP resource from a third state to a second state, wherein the third state indicates that the current SDP resource is in a waiting state, and the second state indicates that the state of the current SDP resource is an empty state; The SDP module transmits information that the second SDP resource is in a second state to a Bluetooth data channel in the Bluetooth protocol stack; The Bluetooth data channel updates the identification identifier from the second identifier to a default identifier based on the information that the second SDP resource is in the second state, wherein the default identifier is used to indicate that the SDP resources in the SDP module are not processing the Bluetooth serial port protocol SPP connection, and the second identifier is used to indicate that the SDP resources in the SDP module are processing the SPP connection.
5. The method according to claim 4, characterized in that When the SDP module in the Bluetooth protocol stack detects that the first SDP resource is released, acquiring the second SDP resource includes: When the SDP module detects that the first SDP resource has been released, searching the SDP module for an SDP resource generated based on the Bluetooth data channel indication as a basic SDP resource; The SDP module obtains an SDP resource in a third state from the basic SDP resource as the second SDP resource.
6. The method according to claim 5, characterized in that The SDP module transmits information that the second SDP resource is in a second state to a Bluetooth data channel in the Bluetooth protocol stack, including: The SDP module obtains a callback function bound to the second SDP resource; The SDP module transmits information that the second SDP resource is in the second state to the Bluetooth data channel through the callback function.
7. The method according to claim 6, characterized in that Searching the SDP resource generated based on the Bluetooth data channel indication as a basic SDP resource in the SDP module includes: The SDP module obtains the SDP resource bound to the callback function as the basic SDP resource.
8. The method according to claim 1, characterized in that The Bluetooth protocol stack releases a first service discovery protocol SDP resource in the Bluetooth protocol stack according to the error code, including: The link management module of the Bluetooth protocol stack instructs the SDP module in the Bluetooth protocol stack to release the first SDP resource in response to the error code, wherein the first connection is a hands-free protocol HFP connection; The SDP module acquires the first SDP resource in response to an instruction of the link management module; The SDP module changes the state of the first SDP resource from a third state to a second state, wherein the third state indicates that the current SDP resource is in a waiting state, and the second state indicates that the current SDP resource is in an empty state.
9. The method according to claim 8, characterized in that When the Bluetooth protocol stack detects that the first SDP resource has been released, releasing the second SDP resource in the Bluetooth protocol stack includes: When the SDP module in the Bluetooth protocol stack detects that the first SDP resource has been released, the second SDP resource is acquired, where the second connection is a Bluetooth serial port protocol SPP connection; The SDP module changes the state of the second SDP resource from a fourth state to a second state, wherein the fourth state indicates that the current SDP resource is processing the SPP connection, and the second state indicates that the state of the current SDP resource is an empty state; The SDP module transmits information that the second SDP resource is in a second state to a Bluetooth data channel in the Bluetooth protocol stack; The Bluetooth data channel updates the identification identifier from the second identifier to a default identifier based on the information that the second SDP resource is in the second state, wherein the default identifier is used to indicate that the SDP resources in the SDP module are not processing the Bluetooth serial port protocol SPP connection, and the second identifier is used to indicate that the SDP resources in the SDP module are processing the SPP connection.
10. The method according to claim 1, characterized in that Before the Bluetooth chip of the first electronic device establishes a physical link for Bluetooth communication with the second electronic device in response to the first connection request sent by the second electronic device, the method further includes: The system Bluetooth of the first electronic device detects an operation of restarting the Bluetooth switch by the user.
11. The method according to claim 4, characterized in that The method further comprises: The first application interval presets a duration to send a third connection request to the Bluetooth data channel, where the third connection request is a request to establish an SPP connection; In response to the third connection request, the Bluetooth data channel detects whether the identification identifier is a default identifier; If it is detected that yes, the Bluetooth data module requests the SDP module to process the SPP connection.
12. An electronic device, characterized in that: include: a memory and a processor, the memory being coupled to the processor; The memory stores program instructions, and when the program instructions are executed by the processor, the electronic device executes the Bluetooth connection method according to any one of claims 1 to 11.
13. A computer-readable storage medium comprising a computer program, characterized in that: When the computer program is executed on an electronic device, the electronic device is enabled to execute the Bluetooth connection method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Communicator, central communication device and Bluetooth communication system
CN111132098A
Equipment reconnection method and related device
CN114158025A
Request processing method and device
CN114340021A
Bluetooth module, display device and Bluetooth abnormity recovery method
CN115190648A
Passive Bluetooth connection method and device and Bluetooth equipment
CN115734205A