Method, system and electronic device for bluetooth connection

By managing the SDP resource state in the Bluetooth protocol stack, the issue of inconsistent connection between sports and health applications and wearable devices after Bluetooth restart was resolved, ensuring normal Bluetooth connection and interaction processes.

CN119603796BActive Publication Date: 2025-11-21HONOR DEVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311138657.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-01
Publication Date
2025-11-21
Estimated Expiration
2043-09-01

AI Technical Summary

Technical Problem

After the Bluetooth of an electronic device is restarted, there is an issue where the Bluetooth connection between the fitness and health app and the wearable device is inconsistent with the interface display and the actual connection status, affecting the interactive experience.

Method used

By releasing SDP resources through the Bluetooth protocol stack, the SDP resources are restored to their default state to avoid connection request conflicts. An error code mechanism is used to manage the state of SDP resources to ensure that the Bluetooth connection is executed according to the normal process.

Benefits of technology

A normal Bluetooth connection was achieved between the sports and health application and the wearable device. The system Bluetooth and sports and health applications both showed the same connection status, ensuring a normal interaction process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119603796B_ABST
    Figure CN119603796B_ABST
Patent Text Reader

Abstract

The application provides a Bluetooth connection method, system and electronic device, and relates to the technical field of Bluetooth. The application provides a Bluetooth connection method. In the process of establishing a physical link for Bluetooth communication with a second electronic device, if a second connection request initiated by a first electronic device through a Bluetooth protocol stack is detected, an error code is returned to the Bluetooth protocol stack; according to the error code, the first service discovery protocol (SDP) resource in the Bluetooth protocol stack is released, and the first SDP resource is used for establishing a first connection; when the first SDP resource is detected to be released, the second SDP resource in the Bluetooth protocol stack is released, and the second SDP resource is used for establishing a second connection. By using the method in the application, after the Bluetooth of the electronic device is restarted, the system of the mobile phone displays that the mobile phone is connected with the watch, and the first application also normally displays that the Bluetooth connection between the mobile phone and the watch is established.
Need to check novelty before this filing date? Find Prior Art

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

[0002] With the continuous development of wireless technology, Bluetooth technology is widely used in wearable devices such as wristbands, watches and the like. An electronic device (such as a mobile phone) is provided with an application (such as sports health) matched with the wearable device, so as to control the wearable device through the application, and obtain data from the wearable device, such as updating the application software version in the wearable device, and obtaining human body data detected by the watch from the watch and the like.

[0003] When the Bluetooth switch in the electronic device is restarted (including the process of opening-closing-opening), the Bluetooth of the electronic device will automatically reconnect the Hands-free Profile (HFP) connection 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 electronic device may appear the situation that the Bluetooth identification of the interface displays that the Bluetooth is turned on, but the display interface of the sports health application displays that the wearable device is not connected, which affects the interaction between the sports health application and the wearable device. SUMMARY

[0004] In order to solve the above technical problems, the present application provides a Bluetooth connection method, system and electronic device, so that the Bluetooth of the electronic device can normally establish a Bluetooth connection with the watch after restarting, and ensure the normal interaction between the sports health and the watch.

[0005] In a first aspect, the present application provides a Bluetooth connection method applied to a first electronic device, the method comprising: a Bluetooth chip of the first electronic device establishing a physical link for Bluetooth communication with a second electronic device in response to a first connection request sent by the second electronic device; if the Bluetooth chip detects a second connection request initiated by the first electronic device through a Bluetooth protocol stack during the establishment of the physical link for Bluetooth communication with the second electronic device, the Bluetooth chip returns an error code to the Bluetooth protocol stack, the error code indicating that the operation of the Bluetooth chip in response to the second connection request conflicts with the 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 is released, the Bluetooth protocol stack releases a second SDP resource in the Bluetooth protocol stack, 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 resource (such as an HFP connection) used for processing the first connection according to the error code, and releases the SDP resource used for processing the second connection when the SDP resource used for processing the first connection is released, so that the SDP resource in the Bluetooth protocol stack returns to a default state, effectively avoiding the problem that the second connection (such as an SPP connection) is always in a waiting state or is being processed, and ensuring that the Bluetooth protocol stack can perform a normal connection establishment process when the next motion health or system Bluetooth sends a connection request, so as to normally establish a Bluetooth connection (such as including an HFP connection and an SPP connection, or including an A2DP connection and an SPP connection) with the watch. Because the first electronic device and the second electronic device can normally establish a Bluetooth connection, the motion health of the mobile phone can normally interact with the watch. At the same time, the system Bluetooth (Bluetooth application) and the motion health of the mobile phone both display 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: a link management module of the Bluetooth protocol stack instructs an 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 the instruction of the link management module; and the SDP module changes a state of the first SDP resource from a first state to a second state, the first state indicating that the current SDP resource is processing the HFP connection, and the second state indicating that a state of the current SDP resource is an empty state. In this way, generally, the first electronic device will automatically reconnect the HFP connection of the second electronic device when the Bluetooth is restarted, and when the link management module of the Bluetooth protocol stack receives the error code, the first SDP resource is acquired, and the state of the first SDP resource is changed to the second state (i.e., the empty state), thereby providing a condition for the next establishment of the HFP connection.

[0008] According to the first aspect, the SDP module acquires the first SDP resource in response to the instruction of the link management module, including: the SDP module finds an SDP resource with a first mark as the first SDP resource, the first mark being 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 the SDP module can quickly find the SDP resource used to process the HFP connection according to the mark, improving the speed and accuracy of the finding.

[0009] According to the first aspect, when the Bluetooth protocol stack detects that the first SDP resource is 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 is 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 indicating that the current SDP resource is in a waiting state, and the second state indicating 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 a Bluetooth data channel in the Bluetooth protocol stack; and the Bluetooth data channel updates an identification mark from a second identification to a default identification according to the information that the second SDP resource is in the second state, the default identification being used to indicate that the SDP resource in the SDP module is not processing the SPP connection, and the second identification being used to indicate that the SDP resource in the SDP module is processing the SPP connection. In this way, the second connection is the SPP connection, the SDP module finds the SDP resource for processing the SPP connection, updates the state of the SDP resource for processing the SPP connection to the second state, and the Bluetooth data channel updates the identification mark to the default state, so that the next time the motion health initiates the establishment of the SPP connection to the Bluetooth data channel, the Bluetooth data channel will not be rejected, thereby ensuring that the next time the SDP module of the Bluetooth protocol stack can process the SPP connection request.

[0010] According to the first aspect, when the SDP module in the Bluetooth protocol stack detects that the first SDP resource is released, the second SDP resource is acquired, including: when the SDP module detects that the first SDP resource is released, the SDP module finds, in the SDP module, an SDP resource generated based on an indication of the Bluetooth data channel as a basic SDP resource; and the SDP module acquires, from the basic SDP resource, an SDP resource in a third state as the second SDP resource. In this way, the SDP module acquires the SDP resource generated based on the indication of the Bluetooth channel and acquires the SDP resource in the third state (i.e., the waiting state), and the second SDP resource can be quickly and accurately found through the double 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 acquires a callback function bound to the second SDP resource; and 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 transmission information method is simple and fast.

[0012] According to the first aspect, the SDP module acquires the SDP resource bound to the 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 the error code, including: a link management module of the Bluetooth protocol stack instructs an 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 the instruction of the link management module; and 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 state of the current SDP resource is an empty state.

[0014] In this way, if the user manually triggers a request for initiating a motion health SPP connection first, in the scenario where the system Bluetooth is manually triggered to initiate a request for establishing 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 resource used for processing the HFP connection to the second state, thereby providing a condition for the Bluetooth protocol stack to normally process the SPP connection request next time.

[0015] According to the first aspect, the Bluetooth protocol stack releases the second SDP resource in the Bluetooth protocol stack when the Bluetooth protocol stack detects that the first SDP resource is released, including: the SDP module in the Bluetooth protocol stack acquires the second SDP resource when the SDP module detects that the first SDP resource is released, wherein the second connection is a Bluetooth serial port profile (SPP) connection; the SDP module changes the state of the second SDP resource from a fourth state to the 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 the second state to a Bluetooth data channel in the Bluetooth protocol stack; and the Bluetooth data channel updates an identification mark from a second identification to a default identification according to the information that the second SDP resource is in the second state, wherein the default identification is used to indicate that the SDP resource in the SDP module is not processing the SPP connection, and the second identification 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 resource used for processing the second connection in time.

[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 further comprises: detecting, by the system Bluetooth of the first electronic device, an operation of restarting the Bluetooth switch by the user.

[0017] According to the first aspect, the method further comprises: sending, by the first application, a third connection request to the Bluetooth data channel, the third connection request being a request for establishing an SPP connection; detecting, by the Bluetooth data channel, whether the identification is a default identification in response to the third connection request; and requesting, by the Bluetooth data module, the SDP module to process the SPP connection if it is detected that the identification is the default identification. In this way, when the Bluetooth protocol stack releases the SDP resource for processing the SPP connection, the SPP connection can be established according to the normal process.

[0018] The second aspect 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 is caused to perform the method of Bluetooth connection of the first aspect and any implementation manner of the first aspect.

[0019] The second aspect and any implementation manner of the second aspect correspond to the first aspect and any implementation manner of the first aspect respectively. The technical effects corresponding to the second aspect and any implementation manner of the second aspect can be referred to the technical effects corresponding to the first aspect and any implementation manner of the first aspect, which will not be described here.

[0020] The third aspect provides a computer readable medium for storing a computer program, when the computer program is executed on an electronic device, the electronic device is caused to perform the method of Bluetooth connection of the first aspect and any implementation manner of the first aspect. BRIEF DESCRIPTION OF DRAWINGS

[0021] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the description of the embodiments of the present application. Obviously, the drawings in the following description are only some embodiments of the present application, and those skilled in the art can obtain other drawings according to these drawings without any creative labor.

[0022] Figure 1 is an exemplary application scenario diagram of the connection between a Bluetooth mobile phone and a Bluetooth watch;

[0023] Figure 2 is a schematic diagram of a mobile phone interface in which a mobile phone and a watch have established Bluetooth connection;

[0024] Figure 3 is an example of a scenario diagram showing a phone restarting Bluetooth;

[0025] Figure 4 is an example of a scenario diagram showing a phone initiating a connection to a watch when Bluetooth is restarted;

[0026] Figure 5 is an example of a structural diagram of an electronic device;

[0027] Figure 6 is an example of a software structure block diagram of an electronic device;

[0028] Figure 7 is an example of a scenario diagram showing a phone restarting Bluetooth;

[0029] Figure 8 is an example of a scenario diagram showing a phone initiating a connection to a watch when Bluetooth is restarted;

[0030] Figure 9 is an example of a scenario diagram showing a phone restarting Bluetooth. DETAILED DESCRIPTION

[0031] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some of the embodiments of the present application, but not all of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of the present application.

[0032] The term "and / or" in the present document is only used to describe an association relationship of associated objects, and means that three relationships can exist, for example, A and / or B can mean that A exists alone, A and B exist together, and B exists alone.

[0033] The terms "first" and "second" and the like in the specification and claims of the embodiments of the present application are used to distinguish different objects, and are not used to describe a specific order of the objects. For example, the first target object and the second target object are used to distinguish different target objects, and are not used to describe a specific order of the target objects.

[0034] In the embodiments of the present application, the words "exemplary" or "for example" are used to mean serving as an example, instance, or illustration. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or advantageous than other embodiments or design schemes. Rather, the use of the words "exemplary" or "for example" is intended to present the relevant concept in a specific manner.

[0035] In the description of the embodiments of the present application, the meaning of "a plurality of" is two or more, unless otherwise specified. For example, a plurality of processing units means two or more processing units; a plurality of systems means two or more systems.

[0036] The method for Bluetooth connection provided by the present application is applied to a first electronic device, which is internally installed with a Bluetooth module to provide the function of Bluetooth communication, such as a mobile phone. The first electronic device is in Bluetooth communication with a second electronic device, which can be a wearable electronic device, such as a watch, a bracelet, etc.

[0037] The electronic device to which the method for Bluetooth connection is applied in the present application is exemplified by a mobile phone. Figure 1 The scene schematic diagram of the Bluetooth mobile phone and the Bluetooth watch establishing Bluetooth connection is exemplarily shown in the present application.

[0038] If the mobile phone 100 does not open Bluetooth, the user opens the Bluetooth switch in the Bluetooth setting interface of the mobile phone. The mobile phone 100 opens Bluetooth and sets the Bluetooth switch to the on state in response to the operation of the user opening the Bluetooth switch. Assuming that the Bluetooth default state of the watch 200 is the on state, when the mobile phone opens Bluetooth, the mobile phone will search for a Bluetooth device that can be matched in the scanning range. In the present example, the Bluetooth setting interface of the mobile phone displays that the devices that can be paired include the watch 200. The mobile phone establishes Bluetooth connection with the watch 200 in response to the operation of the user clicking the identification of the watch 200.

[0039] Figure 1 The mobile phone 100 can establish Bluetooth connection with the smart watch 200 through wireless communication technology, which can be traditional Bluetooth or Bluetooth low energy (BLE) technology.

[0040] The Bluetooth connection established by the mobile phone 100 and the watch 200 can include Hands-free Profile (HFP) connection / Advance Audio Distribution Profile (A2DP) connection and Serial Port Profile (SPP) connection. In the present example, the SPP can also be referred to as Bluetooth Socket. Among them, the watch and the mobile phone can transmit real-time voice calls through the HFP connection and transmit audio data (such as music) through the A2DP connection. The motion 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, the phone and watch establish an HFP connection dynamically. For example, when the phone responds to an operation to establish a Bluetooth connection with the watch, a Bluetooth connection is established between the phone and the watch. This Bluetooth connection includes an HFP connection, an A2DP connection, and an SPP connection. After the Bluetooth connection between the phone and the watch is established, the phone disconnects the HFP connection. When the phone receives an incoming call notification, the watch establishes an HFP connection with the phone based on the call notification sent by the phone. When the phone receives a request to hang up the call, the watch disconnects the HFP connection with the phone based on the notification from the phone to turn off the call.

[0042] It should be noted that each time the phone and watch re-establish a Bluetooth connection, an HFP connection needs to be established between the phone and watch.

[0043] Figure 2 This is a schematic diagram of the phone interface where a Bluetooth connection has been established between the phone and the watch, as an example.

[0044] like Figure 2 As shown in 2a, after a successful Bluetooth connection is established between two phones, the phone responds to the user's action of opening the Bluetooth settings interface by displaying Bluetooth settings interface 201. This Bluetooth settings interface 201 includes: a Bluetooth switch 203 and information on devices that the phone can pair with (such as AAA and BBB as shown in 2a). The Bluetooth switch 203 is used to control the Bluetooth function to be turned on and off. Figure 2 As shown in 2a, the Bluetooth switch 203 is turned on and the Bluetooth icon 202 is also displayed in the Bluetooth settings interface 201. The Bluetooth icon 202 is also used to indicate that Bluetooth is turned on in the mobile phone.

[0045] like Figure 2 As shown in 2b, when the user clicks the Health & Fitness (application) icon on the main screen 204, the phone responds to the user's click and displays the Health & Fitness application interface 205. This interface 205 displays a Bluetooth icon 206 and a first option 207, which indicates the connection status between the phone and the watch. Figure 2 As shown in 2c, the first option 207 in interface 205 indicates that the phone and watch are connected.

[0046] This fitness and health app can connect via SPP to the watch to obtain human data monitored by the watch, such as blood oxygen data, heart rate data, and sleep monitoring. The phone can also update the watch's software version information through the fitness and health app.

[0047] In some embodiments, if the phone and watch have established a Bluetooth connection, and the phone responds to the user's Bluetooth restart operation, the phone system may show that a Bluetooth connection has been established with the watch, but the fitness app may show that the phone and watch are not connected. Figure 3An illustrative diagram illustrating a scenario where a mobile phone restarts its Bluetooth connection is shown. Figure 3 3a, 3b, and 3c indicate the Bluetooth switch's cycle of being turned on, off, and on again, which is the process of restarting the Bluetooth switch.

[0048] like Figure 3 As shown in Figure 3a, the Bluetooth settings interface 301 of the mobile phone includes a Bluetooth icon 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, A2DP connection, and SPP connection are all disconnected. Furthermore, the mobile phone updates the Bluetooth switch status to OFF. Figure 3 As shown in 3b, the Bluetooth settings interface 304 does not display the Bluetooth icon, and the Bluetooth switch 305 is in the off state.

[0049] When the user clicks the Bluetooth switch 305, the phone responds by turning on Bluetooth and updating the Bluetooth switch status to "on". Figure 3 As shown in 3c, the Bluetooth settings interface 306 displays the Bluetooth icon 307, and the Bluetooth switch 308 is in the on state. When the phone turns on Bluetooth, the watch sends a first connection request to the phone's Bluetooth chip. The phone's Bluetooth chip responds to the first connection request and establishes a physical link with the watch. This first connection request can be an HFP connection or an A2DP connection.

[0050] Meanwhile, when Bluetooth is enabled on the phone, the phone's system Bluetooth will automatically reconnect to the watch's HFP calling service (i.e., HFP connection). Specifically, the system Bluetooth (or Bluetooth application) sends an HFP connection request or an A2DP connection request to the phone's Bluetooth chip.

[0051] When the motion health application of the mobile phone detects the opening operation of the Bluetooth switch, the motion health application of the mobile phone can send an SPP connection request to the Bluetooth chip of the mobile phone. Generally, the mobile phone sends a request to establish an SPP connection. The Bluetooth chip of the mobile phone first receives the first connection request sent by the watch, and establishes a physical link for Bluetooth communication with the watch in the identity of a slave device according to the first connection request. When the Bluetooth chip of the mobile phone receives the SPP connection request sent by the motion health application of the mobile phone or the HFP connection request sent by the system Bluetooth, the Bluetooth chip prepares to establish a physical link for communication with the watch in the identity of a master device according to the SPP connection request sent by the motion health application of the mobile phone or the HFP connection request sent by the system Bluetooth, which causes the mobile phone to simultaneously contact the watch in different identities, resulting in a conflict. The Bluetooth chip of the mobile phone returns an error code (such as Control busy) to the Bluetooth protocol stack of the mobile phone. After receiving the error code, the Bluetooth protocol stack releases the SDP resource for processing the HFP connection, but does not release the SDP resource for processing the SPP connection (the SDP resource is in a waiting state), which causes the SPP connection to be unable to be established, and the interface of the motion health application of the mobile phone displays that the mobile phone is not connected to the watch.

[0052] As shown in 3d and 3e of FIG. 13, Figure 3 As shown in 3d and 3e of FIG. 13, Figure 3 As shown in 3e of FIG. 13, the first option 311 indicates that the mobile phone is not connected to the watch.

[0053] The following specifically describes the process of initiating a Bluetooth connection to the watch when the mobile phone reopens the Bluetooth. Figure 4 The following specifically describes the process of initiating a Bluetooth connection to the watch when the mobile phone reopens the Bluetooth.

[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 opens the Bluetooth, the watch initiates a connection request (such as an A2DP connection) to the Bluetooth chip of the mobile phone. The Bluetooth chip of the mobile phone responds to the connection request and establishes a physical link for Bluetooth communication with the watch. When the mobile phone opens the Bluetooth, the mobile phone also initiates 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 can include an HFP connection, an A2DP connection, and an SPP connection. The system Bluetooth (or the Bluetooth application) of the mobile phone sends a connection request for establishing an HFP connection and a connection request for establishing an A2DP connection to the Bluetooth protocol stack of the mobile phone. The motion health application of the mobile phone sends a connection request for establishing an SPP connection to the Bluetooth protocol stack of the mobile phone.

[0056] The Bluetooth protocol stack runs in a serial manner. The Bluetooth protocol stack can process the HFP connection / A2DP connection, and the SPP connection in sequence. In this example, as shown in Figure 4 When the mobile phone detects that the Bluetooth switch is turned on, the system Bluetooth automatically connects the HFP call service of the watch (i.e., the system Bluetooth automatically requests to establish an HFP connection with the watch).

[0057] In this example, the system Bluetooth is taken as an example to send a connection request to the Bluetooth protocol stack to establish an HFP connection. After the system Bluetooth sends the HFP connection request to the Bluetooth protocol stack, the sports health sends a connection request to the Bluetooth protocol stack to establish an SPP connection.

[0058] Step 4102: The SDP module allocates an SDP resource for processing the HFP connection, sets the state of the SDP resource for processing the HFP connection as SETUP, and sends a link connection request to the link management layer.

[0059] For example, the SDP module receives the HFP connection request sent by the system Bluetooth, allocates an SDP resource for the request, and the allocated SDP resource is used for processing the service discovery process of the HFP connection. The SDP module adds the SDP resource for processing the HFP connection to a queue, and sets the state of the SDP resource for processing the HFP connection as SETUP, which is used to indicate that the current SDP resource is executing the service discovery process of the HFP connection. Optionally, the SDP module can also mark the SDP resource for processing the HFP connection.

[0060] After setting the state of the SDP resource for processing the HFP connection as SETUP, the SDP module sends a link connection request to the link management layer (i.e., the link management module).

[0061] Step 4103: The link management layer responds to the link connection request sent by the SDP module, and sends a link connection request to the Bluetooth chip.

[0062] Step 4104: In the process of establishing a physical link for Bluetooth communication with the watch as the master device, the Bluetooth chip returns an error code to the link management layer in response to the link connection request sent by the link management layer of the mobile phone.

[0063] Exemplarily, the Bluetooth chip of the mobile phone starts to establish the physical link for Bluetooth communication with the watch in the master device and the slave device identity of the mobile phone according to the first reconnection request (such as the HFP connection request) sent by the watch. During the process of the Bluetooth chip establishing the physical link for Bluetooth communication with the watch in the slave device identity, if the Bluetooth chip receives the link connection request (such as HCI_Create_Logical_Link) sent by the link management layer of the mobile phone, the Bluetooth chip is ready to establish the physical link for Bluetooth communication with the watch in the master device identity, which causes the mobile phone to simultaneously contact the watch in different identities, resulting in a conflict. 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 resource processing the HFP connection.

[0065] Exemplarily, the link management layer responds to the error code (i.e. Control busy) and instructs the SDP module to release the SDP resource processing the HFP connection. In this example, the link management layer can call a link request failure function, such as SDP disconennect (fail), to instruct the SDP module to release the SDP resource processing the HFP connection.

[0066] Step 4106: The SDP module releases the SDP resource processing the HFP connection.

[0067] Exemplarily, the SDP module receives the instruction sent by the link management layer and resets the SDP resource processing the HFP connection. Specifically, the SDP module can find the SDP resource processing the HFP connection (hereinafter referred to as the HFP SDP resource) according to the mark of the HFP connection. The SDP module sets the state of the HFP SDP resource to NONE.

[0068] In this example, Figure 4 Steps 4021-4023 in the process of sending a Bluetooth Socket connection request to the Bluetooth protocol stack by the sports health application.

[0069] Step 4021: The sports health application 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, the sports health application sends a request (i.e. a Bluetooth Socket connection request) for establishing an SPP connection to the Bluetooth data channel of the Bluetooth protocol stack.

[0071] In this example, the system Bluetooth sends the request for HFP connection to the SDP module at an earlier time than the request for establishing SPP connection sent by the sports health application 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 YES, the Bluetooth data channel sets the identification flag to YES and sends a Bluetooth Socket connection request to the SDP module.

[0073] Exemplarily, the Bluetooth data channel detects whether the value of the identification flag is NO in response to the Bluetooth Socket connection (i.e. SPP connection) request sent by the sports health application. If YES, the Bluetooth data channel sends a Bluetooth Socket connection request to the SDP module and sets the value of the identification flag to YES (i.e. SDP= YES). When the value of the identification flag is YES, it indicates that the SDP module is processing the SPP connection. When the value of the identification flag is NO, it indicates that the SDP module is not processing the SPP connection.

[0074] Step 4203: The SDP module allocates an SDP resource for processing the SPP connection and sets the state of the SDP resource for processing the SPP connection to PEND.

[0075] Exemplarily, the SDP module receives the Bluetooth Socket connection request sent by the Bluetooth data channel and allocates an SDP resource for the request. The allocated SDP resource is used for processing the service discovery procedure of the SPP connection (hereinafter, the SDP resource for processing the SPP connection is referred to as the SDP resource of the SPP). The SDP module adds the SDP resource of the SPP into a queue. Since the SDP resource of the HFP is processing the SDP service of the HFP connection, the SDP module sets the state of the SDP resource of the SPP to PEND, which indicates that the SDP resource of the SPP is in a waiting state and waits for the SDP resource of the HFP to complete processing.

[0076] In this example, the Bluetooth chip returns Control busy to the link management layer, which instructs the SDP module to release the SDP resource of the HFP according to the error code. However, the link management layer does not instruct the SDP module to release the SDP resource of the SPP. The SDP resource of the SPP is in a waiting state all the time, which causes the process of establishing the SPP connection with the watch to fail to continue. When the sports health application sends a Bluetooth Socket connection request to the Bluetooth data channel again, the connection fails as well, as shown in steps 4301-4302. Figure 4

[0077] Step 4301: The sports health application sends a Bluetooth Socket connection request to the Bluetooth data channel in the Bluetooth protocol stack.​

[0078] Step 4302: The Bluetooth data channel detects and identifies whether the flag is NO, if not, the Bluetooth data channel rejects the request.

[0079] Exemplarily, the Bluetooth data channel detects and identifies whether the value of the flag is NO in response to the Bluetooth Socket connection request sent by the sports health application, if not, the Bluetooth data channel rejects the Bluetooth Socket connection request and returns the information of the rejected request to the sports health application.

[0080] The embodiment of the present application provides a Bluetooth connection method, which is applied to a first electronic device, and the first electronic device can be a mobile phone. A Bluetooth chip of the first electronic device establishes a physical link for Bluetooth communication with a second electronic device in response to a first connection request sent by the second electronic device; when detecting a second connection request initiated by the first electronic device through a Bluetooth protocol stack in the process of establishing the physical link for Bluetooth communication with the second electronic device, the Bluetooth chip 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 a 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 detecting that the first SDP resource is released, the Bluetooth protocol stack releases a second SDP resource in the Bluetooth protocol stack, and 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. In the example, the Bluetooth protocol stack releases the SDP resource used to process the first connection and the SDP resource used to process the second connection, thereby avoiding the problem that the watch and the mobile phone cannot be connected due to the fact that the Bluetooth protocol stack is always in the processing flow of a certain connection.

[0081] Figure 5 A structural schematic diagram of an electronic device 100 is shown in the embodiment of the present application. It should be understood that, Figure 5 The electronic device 100 shown is only an example of the electronic device, and the electronic device 100 can have more or fewer components than shown in the figure, can combine two or more components, or can have a different component configuration. 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 the example, the electronic device 100 takes a mobile phone as an example.

[0082] The electronic device 100 can 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, a headset interface 170D, a sensor module 180, a key 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 can include a pressure sensor, a gyroscope sensor, a barometric 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, so as to realize wireless communication and service 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, can receive / transmit page information, receive / transmit BLE broadcast messages, etc.

[0084] Figure 6 is a software structure block diagram of the electronic device of the embodiments of the present application.

[0085] The layered architecture of the electronic device divides the software into several layers, each layer has a clear role and division of labor. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, the application layer, the application framework layer, the hardware abstraction layer (HAL), and the kernel layer. It can be understood 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 can include more or fewer layers than illustrated, and each layer can include more or fewer components, which are not limited in the present application.

[0086] As Figure 6As shown, the application layer can include a series of application packages. The application packages can include motion health, Bluetooth, Wi-Fi, camera, gallery, short message, etc. The application framework layer provides application programming interface (API) and programming framework for the applications of the application layer. The application framework layer includes some pre-defined functions.

[0087] As shown, the application framework layer can include Bluetooth manager, Wi-Fi manager, camera manager. The application framework layer can also include window manager, resource manager, content provider, view system, phone manager, notification manager, etc. Figure 6

[0088] The Bluetooth manager can provide system Bluetooth programming interface (Bluetooth API) so that system Bluetooth and accessory management service application, system Bluetooth and hardware driver (such as sensor driver), and accessory management service application and hardware driver (such as sensor driver) can interact through calling system Bluetooth programming interface.

[0089] The camera manager is used to query and establish system service of camera connection.

[0090] The window manager is used to manage window program. The window manager can obtain display screen size, judge whether there is status bar, lock screen, intercept screen, etc.

[0091] The resource manager provides various resources for the application, such as localized string, icon, picture, layout file, video file, etc.

[0092] The content provider is used to store and obtain data, and make the data accessible by the application. The data can include video, image, audio, dialed and received phone, browsing history and bookmark, phone book, etc.

[0093] The view system includes visual control, such as control for displaying text, control for displaying picture, etc. The view system can be used to build application. The display interface can be composed of one or more views. For example, the display interface including short message notification icon can include view for displaying text and view for displaying picture.

[0094] The phone manager is used to provide communication function of the electronic device 200. For example, management of call state (including call connection, call hang-up, etc.).

[0095] ​The notification manager enables an application to display notification information in a status bar, which can be used to convey an alert-type message that can automatically disappear after a brief stay without user interaction. For example, the notification manager is used to inform of a download completion, a message reminder, etc. The notification manager can also be a notification that appears in a system top status bar in a form of a graph or a scroll bar text, for example, a notification of a background running application, and can also be a notification that appears on a screen in a form of a dialog window. For example, a text information is prompted in a status bar, a prompt sound is emitted, an electronic device is vibrated, an indicator light is blinked, etc.

[0096] The HAL can include a Bluetooth protocol stack, which can include multiple layers of Bluetooth protocols that define the functions performed and the packet formats of the data used to ensure interoperability between Bluetooth devices. The transmission of Bluetooth audio data is implemented by means of Bluetooth protocols, which adopt a layered structure to form a Bluetooth protocol stack. 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 Session Initiation Protocol (SIG). Among them, the Bluetooth core protocols consist of Bluetooth-specific protocols formulated by the SIG, including baseband protocols, Link Manager Protocol (LMP), Logical Link Control and Adaptation Protocol (L2CAP), and Service Discovery Protocol (SDP). L2CAP is an upper layer protocol of the baseband and works in parallel with LMP. SDP plays a crucial role in the Bluetooth technology framework, and is the basis of all user modes. Using SDP, device information and service types can be queried to establish corresponding connections between Bluetooth devices.

[0097] The kernel layer is the layer between hardware and software. The kernel layer at least contains Bluetooth drivers, display drivers, camera drivers, audio drivers, sensor drivers, and the like.

[0098] Figure 7 A schematic diagram showing the operation of the modules of the Bluetooth connection shown by way of example.

[0099] As Figure 7 shown, the motion health located in 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 the A2DP connection request sent by the system Bluetooth and the SPP connection request sent by the motion health in turn according to the order of the requests.

[0100] Figure 8 The interaction diagram of the Bluetooth connection is shown in the following figure for example: Figure 8 The process of the Bluetooth connection 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 of establishing an HFP connection sent by the system Bluetooth, the SDP module allocates an SDP resource for processing the HFP connection, and sets the state of the SDP resource for processing the HFP connection as 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 related process of steps 801-805 is similar to the process of steps 4101-4103, and the related description can refer to steps 4101-4103, which will not be repeated here.

[0107] In an embodiment, the sports health sends a connection request of establishing an SPP connection to the Bluetooth data channel later than the system Bluetooth sends a connection request of establishing an HFP connection to the Bluetooth data channel, and steps 806-809 are steps executed by the Bluetooth protocol stack in response to the connection request of establishing an 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 related description in step 4021, which will not be repeated here.

[0110] Step 807: In response to the request, the Bluetooth data channel detects whether the identification is NO, and if the identification is detected as NO, sets the identification as YES.

[0111] Specifically, the Bluetooth data channel receiving the connection request of establishing an SPP connection can detect whether the value of the identification is NO. If the Bluetooth data channel detects that the value of the identification 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 as YES, such as SDP=YES.

[0112] In this example, the Bluetooth data channel can first set the value of the identification to YES, and then request the SDP module to establish the SPP connection. Alternatively, the Bluetooth data channel can first request the SDP module to establish the SPP connection, and then set the value of the identification to YES.

[0113] Step 808: The Bluetooth data channel requests the SDP module to establish the SPP connection.

[0114] In an example, the Bluetooth data channel sends a connection request for establishing the SPP connection to the SDP module, which can include a callback function for transmitting the status information of the SDP resource allocated by the SDP module based on the SPP connection request.

[0115] Step 809: The SDP module allocates an SDP resource for processing the SPP connection in response to the request sent by the Bluetooth data channel, and sets the status of the SDP resource for processing the SPP connection to a waiting state.

[0116] In an example, the SDP module adopts a serial processing manner. 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, the SDP module allocates an SDP resource for processing the service discovery procedure of the SPP connection (hereinafter referred to as the SDP resource of the SPP). The SDP module adds the SDP resource of the SPP to a queue, and sets the status of the SDP resource of the SPP to a waiting state (indicated by PEND).

[0117] In this example, since the request for establishing the SPP connection carries the 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] In an example, the Bluetooth chip of the mobile phone establishes a physical link for Bluetooth communication with the watch as the master device and the mobile phone as the slave device based on the first reconnection request (e.g., the HFP connection request) sent by the watch. During the process of establishing the physical link for Bluetooth communication with the watch as the slave device, if the Bluetooth chip receives the link connection request (e.g., the HCI_Create_Logical_Link) sent by the link management layer of the mobile phone, the Bluetooth chip prepares to establish the physical link for Bluetooth communication with the watch as the master device, which causes a conflict between the mobile phone and the watch in the process of simultaneously connecting to each other in different identities. Therefore, 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 resource for processing the HFP connection according to the error code.

[0121] Step 812: The SDP module marks the state of the SDP resource for processing the HFP connection as the null state.

[0122] For example, the SDP module receives the instruction sent by the link management layer, finds the SDP resource for HFP, and resets the state of the SDP resource for HFP as the null state, i.e., the SDP module changes the state of the SDP resource for HFP from "con_state=SETUP" to "con_state=NONE".

[0123] Step 813: The SDP module detects that the SDP resource for processing the HFP connection has been released, and releases the SDP resource for processing the SPP connection.

[0124] For example, the SDP module detects that the state of the SDP resource for HFP is the null state, and determines that the SDP module has released the SDP resource for HFP. When the SDP module determines that the SDP resource for HFP has been released, the SDP module finds the SDP resource for SPP. Optionally, the SDP module can find the SDP resource that is bound to the callback function and has the waiting state, and take the found SDP resource as the SDP resource for SPP.

[0125] The SDP module changes the state of the SDP resource for SPP from the waiting state (con_state=PEND) to the null state (con_state=NONE).

[0126] Since the SDP resource for SPP is bound to the callback function, through the callback function, the SDP module can return the state of the SDP resource for SPP to the Bluetooth data channel.

[0127] Step 814: The SDP module instructs the Bluetooth data channel to reset the identification mark as NO.

[0128] For example, the Bluetooth data channel receives the state of the SDP resource for SPP returned by the SDP module (i.e., the null state), and sets the value of the identification mark as NO, i.e., SDP=NO.

[0129] In one embodiment, before step 813 is performed, if the sports health application sends a connection request for establishing the SPP connection to the Bluetooth data channel again, as shown in step 8211 in Figure 8

[0130] Step 8211: The sports health application requests the Bluetooth data channel to establish the SPP connection. ​

[0131] Step 8212: The Bluetooth data channel detects whether the identification flag is NO in response to the request. If the identification flag is YES, the Bluetooth data channel rejects the request for establishing the SPP connection.

[0132] The Bluetooth data channel detects whether the value of the identification flag is NO in response to the request. If the Bluetooth data channel detects that the identification flag is YES, the Bluetooth data channel can return information rejecting the request for establishing the SPP connection to the sports health application.

[0133] In one embodiment, after step 814 is performed, if the sports health application sends a connection request for establishing the SPP connection to the Bluetooth data channel again, the Bluetooth data channel detects whether the value of the identification flag is NO in response to the request. Since step 814 has reset the identification flag to NO. The Bluetooth data channel detects that the identification flag is NO, and can send the request for establishing the SPP connection to the SDP module. The SDP module allocates an SDP resource for processing the service discovery procedure of the SPP connection, and since there is no SDP resource being processed at this time, the state of the SDP resource of the SPP can be set to the ongoing state (to indicate the ongoing state by the SETUP flag), 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 perform a service query procedure for the SPP connection. Subsequently, the process of establishing the SPP connection can be referred to, and will not be described here. The mobile phone and the watch establish the SPP connection. As shown in 9a of FIG. 9A, the icon of the sports health application is clicked in the home screen 901, and the interface 902 of the sports health application is displayed. As shown in 9b of FIG. 9B, the Bluetooth identification 903 and the first option 904 are displayed in the interface 902, and the first option 904 is used to indicate the connection state between the mobile phone and the watch. As shown in 9b of FIG. 9B, the first option 904 indicates that the mobile phone and the watch have been connected. Figure 9 Figure 9 Figure 9

[0134] In this example, the SDP module resets the SDP resource of the SPP and returns the state of the SDP resource of the SPP to the Bluetooth data channel when it is detected that the SDP resource of the HFP has been released. The Bluetooth data channel sets the identification flag according to the state of the SDP resource of the SPP returned by the SDP module. Since the identification flag in the Bluetooth data channel is reset to the default value, the next request for establishing the SPP connection sent by the sports health application will not be rejected, and the mobile phone and the watch can establish the SPP connection.

[0135] ​​​In some other embodiments, if the mobile phone restarts Bluetooth, the motion health of the mobile phone responds to the first operation of the user (such as the operation of the user clicking the connection), and the motion health sends a connection request for establishing an SPP connection to the Bluetooth chip at a time earlier than the time at which the system Bluetooth sends a connection request for establishing an HFP connection to the Bluetooth chip. The specific process is as follows:

[0136] Step 1001: The motion 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 is NO, and if so, the Bluetooth data channel sets the identification to YES and sends a Bluetooth Socket connection request to the SDP module.

[0138] Steps 1001-1002 are similar to steps 806-807, and will not be described again here.

[0139] Step 1003: The SDP module allocates an SDP resource for processing the SPP connection and sets the state of the SDP resource for processing the SPP connection to SETUP.

[0140] For example, the SDP module receives the Bluetooth Socket connection request sent by the Bluetooth data channel, allocates an SDP resource for the request, and the allocated SDP resource is used for processing the service discovery process of the SPP connection (hereinafter, the SDP resource used for processing the SPP connection can be referred to as the SPP SDP resource). The state of the SPP SDP resource is set to SETUP, and "SETUP" is used to indicate that the SPP SDP resource processes the SPP connection.

[0141] In this example, since the request for establishing the SPP connection carries a callback function, the callback function can be bound to the SPP SDP resource, so that the callback function can return the state information of the SPP SDP resource 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, the motion health sends a connection request for establishing an SPP connection to the Bluetooth data channel earlier than the system Bluetooth sends a connection request for establishing an HFP connection to the Bluetooth data channel, and steps 1005-1006 are the steps executed by the Bluetooth protocol stack in response to the connection request for establishing 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 thus will not be repeated here.

[0146] Step 1006: In response to the request for establishing the HFP connection sent by the system Bluetooth, the SDP module allocates an SDP resource for processing the HFP connection, and sets the SDP resource for processing the HFP connection as PEND.

[0147] The SDP module adopts serial processing. Since the SDP module receives the request for establishing the SPP connection first, the SDP module processes the SPP connection first. Therefore, when the SDP module receives the request for establishing the HFP connection, the SDP module allocates an SDP resource for processing the service discovery procedure of the HFP connection (hereinafter referred to as the SDP resource for processing the HFP connection), and adds the SDP resource for processing the HFP connection to the queue. The SDP module sets the state of the SDP resource for processing the HFP connection as a waiting state (indicated by PEND), 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 thus will not be repeated here.

[0150] Step 1008: The link management layer instructs the SDP module to release the SDP resource for processing the HFP connection.

[0151] For example, the SDP module receives the instruction from the link management layer, and searches for the SDP resource for processing the HFP connection. The SDP module resets the state of the SDP resource for processing the HFP connection as NONE, such as changing the state of the SDP resource for processing the HFP connection from "con_state=PEND" to "con_state=NONE".

[0152] Step 1009: The SDP module releases the SDP resource for processing the SPP connection when detecting that the SDP resource for processing the HFP connection has been released.

[0153] For example, the SDP module detects that the state of the SDP resource for processing the HFP connection is empty, and determines that the SDP module has released the SDP resource for processing the HFP connection. When the SDP module determines that the SDP resource for processing the HFP connection has been released, the SDP module searches for the SDP resource for processing the SPP connection. Optionally, the SDP module can search for the SDP resource bound to the callback function and in the state of SETUP, and take the searched SDP resource as the SDP resource for processing the SPP connection.

[0154] The SDP module changes the state of the SDP resource for processing the SPP connection from SETUP (con_state=SETUP) to the empty state (con_state=NONE).

[0155] Since the SDP resource of the SPP is bound with the callback function, through the callback function, the SDP module can return the state of the SDP resource of the SPP to the Bluetooth data channel.

[0156] Step 1010: The SDP module instructs the Bluetooth data channel to reset the identification mark as NO.

[0157] Exemplarily, the SDP module receives the state of the SDP resource of the SPP returned by the SDP module (i.e. the empty state), and the Bluetooth data channel sets the value of the identification mark as NO, i.e. SDP = NO.

[0158] Regardless of whether the system application of the mobile phone sends a connection request prior to the motion health, the link management layer instructs the SDP module to release the SDP resource for processing the HFP connection in view of the Controlbusy error code, resulting in that the SDP resource for the SPP connection cannot be released, and the motion health of the mobile phone cannot establish the SPP connection even if the SPP connection request is re-sent. In this example, the SDP module releases the SDP resource for processing the HFP connection, resets the state of the SDP resource of the SPP and returns the state of the SDP resource of the SPP to the Bluetooth data channel, so that the Bluetooth data channel sets the identification mark according to the state of the SDP resource of the SPP returned by the SDP module, so that the SDP resource for processing the SPP connection will not be in the waiting state or the ongoing state (such as SETUP) all the time, thereby enabling the mobile phone to establish a Bluetooth connection with the mobile phone.

[0159] It can be understood that, in order to implement the above functions, the electronic device comprises hardware and / or software modules corresponding to each function. The algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in hardware or a combination of hardware and computer software. Whether a certain function is implemented in hardware or computer software driven 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 conjunction with the embodiments, but such implementation should not be considered beyond the scope of the present application.

[0160] The embodiment also provides a computer storage medium, which stores computer instructions, when the computer instructions run on the electronic device, the electronic device executes the related method steps to implement the Bluetooth connection method in the above embodiments. 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 various storage medium capable of storing program codes.

[0161] The embodiment also provides a computer program product, which, when running on a computer, causes the computer to execute the above related steps to realize the method of Bluetooth connection in the above embodiment.

[0162] Wherein, the electronic device, computer storage medium, computer program product or chip provided by the embodiment are all used to execute the corresponding method provided above, thus the beneficial effects achieved thereby can refer to the beneficial effects in the corresponding method provided above, which will not be repeated here.

[0163] Any content of each embodiment of the present application, and any content of the same embodiment, can be freely combined. Any combination of the above is within the scope of the present application.

[0164] The embodiments of the present application are described above in combination with the drawings, but the present application is not limited to the specific embodiments described above, which are only illustrative rather than limiting, and those of ordinary skill in the art can make many forms under the inspiration of the present application without departing from the scope of the present application and the scope protected by the claims.

Claims

1. A method for Bluetooth connection, characterized in that, Applied to a first electronic device, the method includes: The Bluetooth chip of the first electronic device responds to the first connection request sent by the second electronic device and establishes a physical link for Bluetooth communication with 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, it returns an error code to the Bluetooth protocol stack. The error code indicates that the operation of the Bluetooth chip in response to the second connection request conflicts with the operation in response to the first connection request sent by the second electronic device. The Bluetooth protocol stack releases the first service discovery protocol (SDP) resource in the Bluetooth protocol stack according to the error code. 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, it releases the second SDP resource in the Bluetooth protocol stack. The second SDP resource is used to establish a second connection. 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 the first Service Discovery Protocol (SDP) resources in the Bluetooth protocol stack according to the error code, including: In response to the error code, the link management module of the Bluetooth protocol stack 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, in response to the instruction of the link management module, acquires the first SDP resource; The SDP module changes the state of the first SDP resource from a first state to a second state. The first state indicates that the current SDP resource is processing an HFP connection, and the second state indicates that the current SDP resource is in an empty state.

3. The method according to claim 2, characterized in that, The SDP module, in response to the instruction of the link management module, acquires the first SDP resource, including: The SDP module finds 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.

4. The method according to claim 1, characterized in that, When the Bluetooth protocol stack detects that the first SDP resource has been released, it releases the second SDP resource in the Bluetooth protocol stack, including: When the SDP module in the Bluetooth protocol stack detects that the first SDP resource has been released, it acquires the second SDP resource. The second connection is a Bluetooth serial port protocol SPP connection. The SDP module changes the state of the second SDP resource from the third state to the second state. 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. 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 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 is not processing the Bluetooth Serial Protocol (SPP) connection, and the second identifier is used to indicate that the SDP resource in the SDP module is 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 has been released, it acquires the second SDP resource, including: When the SDP module detects that the first SDP resource has been released, it 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.

6. The method according to claim 5, characterized in that, The SDP module transmits information about the second SDP resource being in a second state to the Bluetooth data channel in the Bluetooth protocol stack, including: The SDP module obtains the callback function bound to the second SDP resource; The SDP module transmits information about the second SDP resource being in a second state to the Bluetooth data channel through the callback function.

7. The method according to claim 6, characterized in that, The process of retrieving SDP resources generated based on the Bluetooth data channel indication in the SDP module as base SDP resources 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 the first Service Discovery Protocol (SDP) resources in the Bluetooth protocol stack according to the error code, including: In response to the error code, the link management module of the Bluetooth protocol stack 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, in response to the instruction of the link management module, acquires the first SDP resource; The SDP module changes the state of the first SDP resource from the third state to the second state. 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, it releases the second SDP resource in the Bluetooth protocol stack, including: When the SDP module in the Bluetooth protocol stack detects that the first SDP resource has been released, it acquires the second SDP resource. 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 current SDP resource is in 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 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 is not processing the Bluetooth Serial Protocol (SPP) connection, and the second identifier is used to indicate that the SDP resource in the SDP module is 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 a first connection request sent by the second electronic device, the method further includes: The first electronic device's system Bluetooth detected the user's action of restarting the Bluetooth switch.

11. The method according to claim 4, characterized in that, The method further includes: The first application interval sends a third connection request to the Bluetooth data channel after a preset time interval. 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 this is detected, the Bluetooth data channel requests the SDP module to process the SPP connection.

12. An electronic device, characterized in that, include: A memory and a processor, wherein the memory is coupled to the processor; The memory stores program instructions that, when executed by the processor, cause the electronic device to perform 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 run on an electronic device, it causes the electronic device to perform the Bluetooth connection method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Equipment reconnection method and related device

    CN114158025A

  • Bluetooth module, display device and Bluetooth abnormity recovery method

    CN115190648A