Bluetooth connection processing method and electronic device

By actively disconnecting and reassigning the port number during the Bluetooth connection, the problem of abnormal data transmission caused by port number updates was resolved, ensuring the correct transmission of Bluetooth service data and improving the user experience.

WO2026031702A1PCT designated stage Publication Date: 2026-02-12HONOR DEVICE CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2025/095246
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-08-08
Filing Date
2025-05-15
Publication Date
2026-02-12

AI Technical Summary

Technical Problem

During the Bluetooth connection process, although the Bluetooth link is successfully established, data transmission is abnormal due to port number updates. In particular, data corresponding to the HFP service cannot be transmitted, affecting the user experience.

Method used

Upon receiving a connection request, the device actively disconnects the Bluetooth link corresponding to the original port number, reassigns and establishes a new port number to ensure the correctness of data transmission. It resolves the port number mismatch issue by actively obtaining the current port number and rebuilding the link.

Benefits of technology

This ensures the effective transmission of Bluetooth service data, avoids data transmission failures due to port number mismatches, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2025095246_12022026_PF_FP_ABST
    Figure CN2025095246_12022026_PF_FP_ABST
Patent Text Reader

Abstract

Embodiments of the present application relate to the technical field of terminals, and provide a Bluetooth connection processing method and an electronic device. The method comprises: a first device receiving a first connection request sent by a second device, the first connection request including a first port number historically assigned by the first device for a first service; in response to the first connection request, the first device establishing a first Bluetooth link with the second device; when a port number corresponding to the first Bluetooth link is the first port number, and a port number currently assigned by the first device for the first service is a second port number, and upon receiving a first message sent by the second device, a message format of the first message being a format corresponding to the first service, the first device disconnecting the first Bluetooth link; and after disconnecting the first Bluetooth link, the first device establishing, on the basis of a third port number currently assigned by the second device for the first service, a second Bluetooth link corresponding to the first service with the second device. In this way, a Bluetooth link for transmitting data of the first service can be effectively established.
Need to check novelty before this filing date? Find Prior Art

Description

Bluetooth connection processing method and electronic device

[0001] The present application claims priority to the Chinese patent application No. 202411093226.0, filed on August 8, 2024, and entitled "Bluetooth connection processing method and electronic device", the content of which is incorporated herein by reference in its entirety. TECHNICAL FIELD

[0002] The present application relates to the technical field of terminals, and in particular to a Bluetooth connection processing method and an electronic device. BACKGROUND

[0003] With the continuous development of Bluetooth technology, it has become a common data transmission scenario that electronic devices establish Bluetooth connections and transmit data through Bluetooth connections.

[0004] For electronic devices equipped with Bluetooth functions, the electronic devices can support multiple Bluetooth services. In one implementation, the electronic devices can assign a corresponding RFCOMM port number for each Bluetooth service available to the electronic devices, so that the remaining electronic devices can correctly connect to the corresponding Bluetooth service.

[0005] However, in some scenarios, two electronic devices establish a Bluetooth link corresponding to a Bluetooth service based on an RFCOMM port number, but cannot transmit data corresponding to the Bluetooth service based on the established Bluetooth link, resulting in abnormal data transmission based on Bluetooth technology. SUMMARY

[0006] The embodiments of the present application provide a Bluetooth connection processing method and an electronic device, which are applied to the technical field of terminals. The present application avoids the situation that a successfully established Bluetooth link cannot transmit data corresponding to a Bluetooth service.

[0007] In a first aspect, the embodiments of the present application provide a Bluetooth connection processing method applied to a first device. The method comprises:

[0008] receiving a first connection request sent by a second device, the first connection request carrying a first port number, the first port number being a port number assigned by the first device to a first service in history;

[0009] in response to the first connection request, establishing a first Bluetooth link corresponding to the first port number with the second device, wherein the first Bluetooth link may be, for example, an RFCOMM link;

[0010] In a case that the port number corresponding to the first Bluetooth link is the first port number, the first device currently allocates the second port number to the first service, and the first message sent by the second device through the first Bluetooth link is received, the first device disconnects the first Bluetooth link, where the message format of the first message is the format corresponding to the first service, and the first port number is different from the second port number.

[0011] After the first Bluetooth link is disconnected, the first device establishes the second Bluetooth link corresponding to the first service with the second device based on a third port number currently allocated by the second device to the first service.

[0012] In this way, after the first Bluetooth link corresponding to the first port number is established between the first device and the second device, in a case that the first device receives the first message sent by the second device through the first Bluetooth link, the first device can determine that the second device needs to transmit the data of the first service through the first Bluetooth link. Further, in a case that the port number corresponding to the first Bluetooth link is inconsistent with the port number currently allocated by the first device to the first service, the first device can actively disconnect the first Bluetooth link to avoid the existence of the first Bluetooth link affecting the data transmission of the first service. Then, the second Bluetooth link is established based on a third port number currently allocated by the second device to the first service, so that the data corresponding to the first service can be effectively transmitted based on the second Bluetooth link subsequently.

[0013] In a possible implementation, the method further includes:

[0014] In a case that the first device and the second device establish the Bluetooth connection for the first time, service first response information is sent to the second device in response to a service first discovery request sent by the second device.

[0015] The service first response information includes the port number allocated by the first device to each of a plurality of services available to the first device, the plurality of services available to the first device includes the first service, and the first device allocates the first port number to the first service at the moment when the service first response information is sent.

[0016] The first port number allocated by the first device to the first service is stored.

[0017] In this way, the first port number allocated by the first device to the first service at the moment when the Bluetooth connection is established for the first time can be effectively interacted. Then, the second device can store the first port number, so that the second device can initiate a request for establishing the Bluetooth link to the first device based on the first port number in the process of subsequent Bluetooth reconnection. Therefore, the first port number in this embodiment is the first port number allocated by the first device to the first service at the moment when the Bluetooth connection is established for the first time.

[0018] And the first device stores the first port number, and can determine whether the second port number currently allocated by the first device for the first service is updated based on the first port number in the subsequent Bluetooth reconnection process, and perform the subsequent disconnection and reconnection process in the case of update, so as to improve the necessity of subsequent processing.

[0019] In a possible implementation, the method further includes:

[0020] In the case that the plurality of services available to the first device is in the first state, the first device allocates port numbers to the plurality of services available in turn according to a first start order of the plurality of services available, wherein the first service is in a first ranking in the first start order, and the port number allocated by the first device for the first service is a first port number;

[0021] In the case that the plurality of services available to the first device is in the second state, the first device allocates port numbers to the plurality of services available in turn according to a second start order of the plurality of services available, wherein the first service is in a second ranking in the second start order, and the port number allocated by the first device for the first service is a second port number;

[0022] The plurality of services available to the first device in the first state is different from the plurality of services available to the first device in the second state, and the first ranking is different from the second ranking.

[0023] In this way, the first device can flexibly configure the available Bluetooth services according to actual needs, and when the available Bluetooth services of the first device change, the port number allocated by the first device for the Bluetooth service can also change. Based on the above-mentioned manner, even if the port number allocated by the first device for the Bluetooth service changes, the link for transmitting data of the Bluetooth service can be effectively established.

[0024] In a possible implementation, the establishing of the second Bluetooth link corresponding to the first service by the second device based on the third port number allocated by the second device for the first service includes:

[0025] Sending a service second discovery request to the second device, the service second discovery request being used to obtain the port number allocated by the second device for each of the plurality of services available to the second device;

[0026] Receiving service second response information from the second device, the service second response information including the port number allocated by the second device for each of the plurality of services available to the second device, the plurality of services available to the second device including the first service, and the port number allocated by the second device for the first service at the moment of sending the service second response information being the third port number;

[0027] Sending a second connection request to the second device, the second connection request carrying the third port number;

[0028] establish a second Bluetooth link with the second device based on the second connection request.

[0029] In this implementation, the first device can effectively obtain the third port number currently allocated by the second device for the first service, and then establish the second Bluetooth link based on the third port number, so that the data of the first service can be correctly and effectively transmitted through the second Bluetooth link.

[0030] In a possible implementation, the first Bluetooth link and the second Bluetooth link are links established based on a radio frequency communication (RFCOMM) protocol, and the first service is a hands-free profile (HFP) service.

[0031] In a second aspect, an embodiment of the present application provides a Bluetooth connection processing apparatus. The Bluetooth connection processing apparatus can be an electronic device, or a chip or chip system in the electronic device. The Bluetooth connection processing apparatus can include a display unit and a processing unit.

[0032] When the Bluetooth connection processing apparatus is an electronic device, the display unit can be a display screen. The display unit is configured to perform the step of displaying, so that the electronic device implements the Bluetooth connection processing method described in the first aspect or any possible implementation of the first aspect.

[0033] When the Bluetooth connection processing apparatus is an electronic device, the processing unit can be a processor. The Bluetooth connection processing apparatus can further include a storage unit, which can be a memory. The storage unit is configured to store instructions, and the processing unit is configured to execute the instructions stored in the storage unit, so that the electronic device implements the Bluetooth connection processing method described in the first aspect or any possible implementation of the first aspect.

[0034] When the Bluetooth connection processing apparatus is a chip or chip system in an electronic device, the processing unit can be a processor. The processing unit is configured to execute instructions stored in a storage unit, so that the electronic device implements the Bluetooth connection processing method described in the first aspect or any possible implementation of the first aspect. The storage unit can be a storage unit (for example, a register, a cache, etc.) in the chip, or a storage unit (for example, a read-only memory, a random access memory, etc.) in the electronic device and located outside the chip.

[0035] In a third aspect, an embodiment of the present application provides an electronic device including a processor and a memory. The memory is configured to store code instructions, and the processor is configured to execute the code instructions to perform the method described in the first aspect or any possible implementation of the first aspect.

[0036] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program or instructions, and when the computer program or instructions are run on a computer, the computer is caused to execute the method described in the first aspect or any possible implementation manner of the first aspect.

[0037] In a fifth aspect, an embodiment of the present application provides a computer program product including a computer program, and when the computer program is run on a computer, the computer is caused to execute the method described in the first aspect or any possible implementation manner of the first aspect.

[0038] In a sixth aspect, the present application provides a chip or chip system, which includes at least one processor and a communication interface, the communication interface and the at least one processor are interconnected through a line, and the at least one processor is configured to run a computer program or instructions to execute the method described in the first aspect or any possible implementation manner of the first aspect. The communication interface in the chip can be an input / output interface, a pin or a circuit, etc.

[0039] In a possible implementation, the chip or chip system described in the present application further includes at least one memory, and the at least one memory stores instructions. The memory can be a storage unit inside the chip, such as a register, a cache, etc., or a storage unit of the chip (such as a read-only memory, a random access memory, etc.).

[0040] It should be understood that the second aspect to the sixth aspect of the present application correspond to the technical solution of the first aspect of the present application, and the beneficial effects obtained by each aspect and the corresponding possible implementation manner are similar, which will not be described again. BRIEF DESCRIPTION OF DRAWINGS

[0041] FIG. 1 is a schematic diagram of the relationship between a Bluetooth service and a port number according to an embodiment of the present application;

[0042] FIG. 2 is a schematic diagram of a Bluetooth link established between a vehicle-mounted device and a terminal device according to an embodiment of the present application;

[0043] FIG. 3 is an interaction flowchart of a Bluetooth connection according to an embodiment of the present application;

[0044] FIG. 4 is a schematic diagram of a hardware structure of a terminal device according to an embodiment of the present application;

[0045] FIG. 5 is a schematic diagram of a software structure of a terminal device according to an embodiment of the present application;

[0046] FIG. 6 is an interaction flowchart one of a Bluetooth connection processing method according to an embodiment of the present application;

[0047] FIG. 7 is an interaction flowchart two of a Bluetooth connection processing method according to an embodiment of the present application;

[0048] Fig. 8 is a third interactive flowchart of the Bluetooth connection processing method according to an embodiment of the present application;

[0049] Fig. 9 is a schematic diagram of a scenario in which the available services change according to an embodiment of the present application;

[0050] Fig. 10 is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0051] In order to clearly describe the technical solutions of the embodiments of the present application, the following briefly introduces some terms and technologies involved in the embodiments of the present application:

[0052] 1. BIP

[0053] BIP (Basic Imaging Profile) is a Bluetooth protocol used for image transmission between Bluetooth devices.

[0054] 2. HFP

[0055] HFP (Hands-Free Profile) is a Bluetooth protocol that allows Bluetooth devices (such as car devices) to pair with terminal devices (such as mobile phones) to realize hands-free calling.

[0056] In addition, based on the HFP service, in addition to transmitting call data, for example, the power data of the terminal device can also be transmitted, and the present application does not limit the specific data type transmitted based on the HFP service, which can be determined according to the actual situation.

[0057] 3. RFCOMM

[0058] RFCOMM (Radio Frequency Communication) is a protocol for serial communication between Bluetooth devices. Among them, RFCOMM provides a reliable transport layer for establishing a reliable data connection between Bluetooth devices. And RFCOMM is a connection-oriented protocol, which requires a connection to be established between the two communication parties first, and then data transmission can be carried out. This connection mode can ensure the stability and security of communication.

[0059] 4. SDP

[0060] SDP (Service Discovery Profile) is part of the Bluetooth protocol stack, used to discover available services and related information on Bluetooth devices.

[0061] Among them, the SDP allows the Bluetooth device to query and discover the services provided on the nearby devices. For example, the Bluetooth device can find the services on other devices through the SDP query, including the service type, service attribute and connection parameters of the service.

[0062] In addition, the Bluetooth device can also describe its available services through the service record of the SDP. The service record contains the detailed information of the available services of the Bluetooth device, such as the service type, service attribute and connection parameters of the service, etc., wherein the connection parameters of the service may, for example, include the port number allocated by the Bluetooth device for the Bluetooth service. Among them, the service record can be stored in the SDP database of the Bluetooth device and provided when queried by other devices.

[0063] 5. Other terms

[0064] In the embodiments of the present application, the same items or similar items with basically the same functions and effects are distinguished by using "first", "second", etc. For example, the first chip and the second chip are only used to distinguish different chips, and do not limit the sequence. Those skilled in the art can understand that "first", "second", etc. do not limit the quantity and execution sequence, and "first", "second", etc. do not necessarily mean different.

[0065] It should be noted that 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 present application should not be interpreted as being more preferred or having more advantages than other embodiments or design schemes. Rather, the use of "exemplary" or "for example" is intended to present the relevant concept in a specific manner.

[0066] In the embodiments of the present application, "at least one" means one or more, and "multiple" means two or more. The "and / or" describes the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B, which can represent the following three cases: A exists alone, A and B exist together, and B exists alone, wherein A and B can be singular or plural. The character " / " generally represents an "or" relationship between the front and rear associated objects. "At least one of the following" or similar expressions means any combination of these items, including any combination of single item or multiple items. For example, at least one of a, b, or c, can represent a, b, c, a-b, a-c, b-c, or a-b-c, wherein a, b, and c can be single or multiple.

[0067] 6. Electronic device

[0068] The electronic device of the embodiments of the present applicationapplicationinclude a handheld device with Bluetooth function, a vehicle-mounted device, etc. For example, some electronic devices are: a mobile phone, a tablet computer, a palm computer, a notebook computer, a mobile internet device (MID), a wearable device, a virtual reality (VR) device, an augmented reality (AR) device, a wireless terminal in industrial control, a wireless terminal in self driving, a wireless terminal in remote medical surgery, a wireless terminal in smart grid, a wireless terminal in transportation safety, a wireless terminal in smart city, a wireless terminal in smart home, a cellular phone, a cordless phone, a session initiation protocol (SIP) phone, a wireless local loop (WLL) station, a personal digital assistant (PDA), a handheld device with wireless communication function, a computing device or other processing device connected to a wireless modem, a vehicle-mounted device, a wearable device, a terminal device in a 5G network, or a terminal device in a future evolved public land mobile network (PLMN), etc., and the embodiments of the present application are not limited thereto.

[0069] By way of example and not limitation, in the embodiments of the present application, the electronic deviceapplicationalso be a wearable device. The wearable device can also be referred to as a wearable smart device, which is a general term for devices that are designed and developed by applying wearable technology to daily wear, such as glasses, gloves, watches, clothing, and shoes. The wearable device is a portable device that is directly worn on the body or integrated into the clothes or accessories of the user. The wearable device is not only a hardware device, but also a device that realizes powerful functions through software support and data interaction and cloud interaction. The general wearable smart device includes a device with full functions and large size, which can realize complete or partial functions without relying on a smart phone, such as a smart watch or smart glasses, and a device that focuses on a certain application function and needs to be used in cooperation with other devices such as a smart phone, such as various smart wristbands and smart jewelry for monitoring vital signs.

[0070] In addition, in the embodiments of the present application, the electronic device can also be a terminal device in an Internet of Things (IoT) system. The IoT is an important part of future information technology development, and its main technical feature is to connect objects through communication technology and network, so as to realize the intelligent network of man-machine interconnection and object-object interconnection.

[0071] The electronic device in the embodiments of the present application can also be referred to as a terminal device, a user equipment (UE), a mobile station (MS), a mobile terminal (MT), an access terminal, a subscriber unit, a subscriber station, a mobile station, a mobile terminal, a remote station, a remote terminal, a mobile device, a user terminal, a terminal, a wireless communication device, a user agent, or a user apparatus, etc.

[0072] In the embodiments of the present application, the electronic device or each network device includes a hardware layer, an operating system layer running on the hardware layer, and an application layer running on the operating system layer. The hardware layer includes central processing unit (CPU), memory management unit (MMU), and memory (also known as main memory) and other hardware. The operating system can be any one or more computer operating systems that implement business processing through processes, such as Linux operating system, Unix operating system, Android operating system, iOS operating system, or windows operating system, etc. The application layer includes browser, address book, word processing software, instant messaging software, etc.

[0073] With the continuous development of Bluetooth technology, currently, establishing Bluetooth connection between electronic devices and conducting data transmission through Bluetooth connection has become a common data transmission scenario. For electronic devices equipped with Bluetooth function, the electronic devices can support multiple Bluetooth services. Among them, the electronic device supports certain Bluetooth services means that the electronic device has the functions and implementation of these Bluetooth services.

[0074] Further, the electronic device can enable at least part of the Bluetooth services in the multiple Bluetooth services it supports according to actual needs. The services that have been enabled by the Bluetooth device and can be provided to other devices for use can be referred to as available services (or available Bluetooth services) of the Bluetooth device. It can be understood that for a Bluetooth device, even if it supports multiple services, only the enabled services are considered as available services.

[0075] For example, assuming that the Bluetooth device supports Bluetooth service A, Bluetooth service B, Bluetooth service C and Bluetooth service D, and that the Bluetooth device enables Bluetooth service A, Bluetooth service B and Bluetooth service C (which can also be understood as the three services being in an enabled state), the Bluetooth services available to the Bluetooth device include Bluetooth service A, Bluetooth service B and Bluetooth service C. In actual implementation, the Bluetooth services supported by the Bluetooth device and the Bluetooth services available to the Bluetooth device can be set arbitrarily according to actual requirements. The Bluetooth services available to the Bluetooth device can be configured by a developer, or can also be set by a user, and the embodiment is not limited in this regard.

[0076] The Bluetooth services can include a BIP service and an HFP service, and the like, and the embodiment is not limited in this regard.

[0077] In one implementation, the electronic device can assign a corresponding RFCOMM port number (channel number) to each Bluetooth service available to the electronic device, so that the remaining electronic devices can correctly connect to the corresponding Bluetooth service, thereby correctly transmitting data corresponding to each Bluetooth service. The implementation of assigning a unique RFCOMM port number to each Bluetooth service can enable multiple services to run simultaneously on the same electronic device, thereby avoiding conflicts between Bluetooth services.

[0078] For example, a scenario in which a vehicle-mounted device and a terminal device establish a Bluetooth connection can be taken as an example, and reference can be made to FIG. 1, which is a schematic diagram of a relationship between Bluetooth services and port numbers provided by an embodiment of the present application.

[0079] As shown in FIG. 1, for example, the Bluetooth services available to the terminal device include Bluetooth service A, Bluetooth service B and Bluetooth service C, and it is assumed that the terminal device assigns an RFCOMM port number of 1 to Bluetooth service A, an RFCOMM port number of 2 to Bluetooth service B, and an RFCOMM port number of 3 to Bluetooth service C.

[0080] For example, when the vehicle-mounted device needs to transmit data corresponding to Bluetooth service A to the terminal device, the vehicle-mounted device can establish an RFCOMM link corresponding to Bluetooth service A with the terminal device based on the port number 1, and then transmit data corresponding to Bluetooth service A to the terminal device based on the RFCOMM link corresponding to Bluetooth service A.

[0081] In an implementation, the in-vehicle device can first establish a basic link (e.g., an ACL link) with the terminal device based on the pairing information of the terminal device, and then establish the RFCOMM link described above through the basic link, so as to transmit the data of the corresponding Bluetooth service based on the RFCOMM link. ACL is an asynchronous connection.

[0082] For example, the Bluetooth service supported by the terminal device can include an HFP service, and the in-vehicle device can establish an RFCOMM link corresponding to the HFP service with the terminal device, as shown in FIG. 2. Then the in-vehicle device can interact with the terminal device through the RFCOMM link to transmit the data corresponding to the HFP service.

[0083] Based on the above description, there are two possible implementations for the in-vehicle device and the terminal device to establish a Bluetooth connection:

[0084] One implementation is that the in-vehicle device and the terminal device establish a Bluetooth connection for the first time, and at this time, the user usually needs to perform a corresponding Bluetooth connection operation in the terminal device (or the in-vehicle device) to enable the in-vehicle device and the terminal device to establish a Bluetooth connection.

[0085] Another implementation is that the in-vehicle device and the terminal device can save the pairing information of each other after establishing a Bluetooth connection for the first time. Then when the in-vehicle device and the terminal device are close to each other, the in-vehicle device or the terminal device can discover the opposite device and automatically initiate a Bluetooth reconnection to the opposite device based on the saved pairing information, so as to establish a Bluetooth connection between the two devices.

[0086] It should be understood that the automatic reconnection of Bluetooth refers to the function that when two devices are close to each other again after a Bluetooth connection has been established between the two devices, the two devices automatically establish a Bluetooth connection and remain in a connected state.

[0087] In this implementation in which the in-vehicle device (or the terminal device) reconnects the opposite device to establish a Bluetooth connection, a problem that the Bluetooth connection between the in-vehicle device and the terminal device is established, but the data corresponding to the HFP service cannot be transmitted can occur. The data corresponding to the HFP service can include call data, which means that in an actual scenario, the call cannot be played through the in-vehicle device. The data corresponding to the HFP service can also include the power data of the terminal device, which means that in an actual scenario, the remaining power of the terminal device displayed in the in-vehicle device is abnormal. These problems can cause some data to fail to be transmitted through the Bluetooth link, thereby affecting the user experience.

[0088] The following analyzes the causes of the above problems, and takes the example of the vehicle-mounted device re-connecting the terminal device to establish a Bluetooth connection to introduce the following content. The possible Bluetooth connection interaction process between the vehicle-mounted device and the terminal device is introduced in combination with FIG. 3. FIG. 3 is an interaction process diagram of a Bluetooth connection provided by an embodiment of the present application.

[0089] As shown in FIG. 3, steps 1-6 can be understood as the interaction when the vehicle-mounted device and the terminal device establish a Bluetooth connection for the first time, and steps 7-9 can be understood as the interaction when the vehicle-mounted device and the terminal device perform Bluetooth automatic re-connection. The detailed implementation of these steps is introduced as follows:

[0090] 1. The vehicle-mounted device and the terminal device establish a Bluetooth link.

[0091] In an implementation manner, for example, the Bluetooth functions of the vehicle-mounted device and the terminal device can be controlled to be turned on, so that the devices enter a discoverable mode. Then the vehicle-mounted device and the terminal device can broadcast their device information to perform device discovery. In addition, the vehicle-mounted device and the terminal device can scan the surrounding Bluetooth devices.

[0092] In actual implementation, the Bluetooth connection can be initiated by the vehicle-mounted device to the terminal device, or the Bluetooth connection can be initiated by the terminal device to the vehicle-mounted device, and the processing procedures of the two implementation manners are similar. The following takes the example of the vehicle-mounted device initiating the Bluetooth connection to the terminal device to illustrate.

[0093] For example, the user can select the terminal device in the Bluetooth settings of the vehicle-mounted device to perform pairing, and correspondingly, the pairing request can be displayed in the terminal device. Then the terminal device can respond to the user operation to determine to agree to the pairing.

[0094] Then from the perspective of the device, the vehicle-mounted device sends the Bluetooth connection to the terminal device, and the terminal device responds to the Bluetooth connection to establish a preliminary connection with the vehicle-mounted device. Then the vehicle-mounted device and the terminal device can exchange a pairing code (usually a PIN code or automatically generated number). The vehicle-mounted device and the terminal device can perform identity verification through the pairing code. In the case of identity verification passing, the vehicle-mounted device and the terminal device can exchange an encryption key to establish a secure connection.

[0095] After the above process is completed, it can be understood that the pairing of the vehicle-mounted device and the terminal device is completed. After the pairing is successful, the vehicle-mounted device and the terminal device can establish an ACL link, that is, the Bluetooth link introduced above.

[0096] 2. The vehicle-mounted device sends a service discovery request to the terminal device.

[0097] After the vehicle-mounted device and the terminal device establish the Bluetooth link, the vehicle-mounted device can send a service discovery request to the terminal device based on the Bluetooth link, for example. The service discovery request is used to request the Bluetooth services available to the terminal device and the port numbers respectively assigned by the terminal device to the Bluetooth services available.

[0098] In an implementation manner, the vehicle-mounted device can send the service discovery request to the terminal device based on the SDP protocol, for example.

[0099] 3. The terminal device sends a service discovery response to the vehicle-mounted device.

[0100] The terminal device can send a service discovery response to the vehicle-mounted device in response to the service discovery request after receiving the service discovery request sent by the vehicle-mounted device. The service discovery response can include the Bluetooth services available to the terminal device and the port numbers respectively assigned by the terminal device to the Bluetooth services available. The service discovery response can also include the remaining information related to the Bluetooth services available to the terminal device, which is not limited in the embodiment.

[0101] For example, assuming that the Bluetooth services available to the terminal device include the HFP service, the service discovery response sent by the terminal device to the vehicle-mounted device can include the HFP service and the port number assigned by the terminal device to the HFP service, assuming that the assigned port number is 3, as shown in FIG. 3.

[0102] 4. The vehicle-mounted device sends a connection request to the terminal device based on the port number corresponding to the HFP service.

[0103] The vehicle-mounted device can determine that the port number assigned by the terminal device to the HFP service is 3 based on the service discovery response. When the vehicle-mounted device needs to establish an RFCOMM link for transmitting the HFP service with the terminal device, the vehicle-mounted device can send a connection request to the terminal device, for example, which can include the port number corresponding to the HFP service obtained by the vehicle-mounted device based on the service discovery response, i.e., the port number assigned by the terminal device to the HFP service.

[0104] Referring to FIG. 3, assuming that the port number assigned by the terminal device to the HFP service is 3, the connection request sent by the vehicle-mounted device to the terminal device can include the port number 3.

[0105] 5. The terminal device and the vehicle-mounted device establish a link corresponding to the HFP service.

[0106] The terminal device can obtain the port number included in the connection request by analyzing the connection request after receiving the connection request sent by the vehicle-mounted device. Then the terminal device can establish a link corresponding to the port number based on the port number included in the connection request.

[0107] For example, in the example introduced in Fig. 3, the port number included in the connection request is 3, then the terminal device can establish an RFCOMM link with the vehicle-mounted device based on the port number 3. The RFCOMM link with the port number 3 is the link used for transmitting the data corresponding to the HFP service.

[0108] 6、The vehicle-mounted device and the terminal device transmit the data corresponding to the HFP service.

[0109] After the RFCOMM link corresponding to the HFP service is successfully established, the vehicle-mounted device and the terminal device can transmit the data corresponding to the HFP service based on the RFCOMM link.

[0110] And it needs to be understood that the above steps 3-6 are introduced by taking the HFP service as an example, and the establishment of the link corresponding to the Bluetooth service between the two devices and the transmission of the data corresponding to the Bluetooth service on the corresponding link are implemented. In fact, the implementation manners of various Bluetooth services are similar, and only the HFP service introduced above needs to be replaced by the rest of the services, which is not particularly limited in the embodiment.

[0111] 7、The terminal device updates the port number of the HFP service to 4.

[0112] After the first connection ends, it is assumed that the port number allocated by the terminal device for the HFP service is updated, referring to Fig. 3, it is assumed that the port number allocated by the terminal device for the HFP service is updated from 3 to 4. Then when the vehicle-mounted device and the terminal device perform Bluetooth reconnection again, the problem introduced above will occur. The occurrence process of the problem will be described below in combination with the contents of steps 8-11 shown in Fig. 3, it can be understood that steps 8-11 in Fig. 3 correspond to the implementation when Bluetooth is automatically reconnected.

[0113] 8、The vehicle-mounted device and the terminal device establish a Bluetooth link.

[0114] The current step corresponds to the scenario of Bluetooth automatic reconnection, it can be understood that after the vehicle-mounted device and the terminal device first establish Bluetooth connection, the vehicle-mounted device and the terminal device can save the pairing information of each other, then when the vehicle-mounted device and the terminal device are close, the vehicle-mounted device can automatically initiate Bluetooth connection to the terminal device based on the pairing information of the terminal device, so as to establish the Bluetooth link of the vehicle-mounted device and the terminal device.

[0115] Or the terminal device can also automatically initiate Bluetooth connection to the vehicle-mounted device based on the pairing information of the vehicle-mounted device, so as to establish the Bluetooth link of the vehicle-mounted device and the terminal device.

[0116] 9、The vehicle-mounted device sends a connection request to the terminal device based on the port number 3.

[0117] Based on the above introduction, it can be determined that the vehicle-mounted device will obtain the port number allocated by the terminal device for multiple available services based on the service discovery request in the process of establishing Bluetooth connection with the terminal device for the first time.

[0118] In addition, in the infotainment system of some vehicle-mounted devices, in order to improve the Bluetooth connection speed, the vehicle-mounted device will save the port number allocated by the terminal device for multiple available services obtained in the first Bluetooth connection process. Then, in the Bluetooth reconnection process, the vehicle-mounted device will initiate a connection request to the terminal device based on the saved port number allocated by the terminal device for the available services.

[0119] In the example of FIG. 3, the vehicle-mounted device obtains the port number allocated by the terminal device for the HFP service as 3 in the first Bluetooth connection process, and then the vehicle-mounted device can save this information. In the Bluetooth reconnection process, when the vehicle-mounted device needs to establish a link corresponding to the HFP service, the vehicle-mounted device can directly send a connection request to the terminal device based on the port number 3. As shown in FIG. 3, the connection request sent by the vehicle-mounted device can include the port number 3.

[0120] 10、The terminal device establishes a link corresponding to the port number 3 with the vehicle-mounted device in response to the connection request.

[0121] Similar to the implementation method introduced in step 5 above, the terminal device can establish a link corresponding to the port number with the vehicle-mounted device based on the port number included in the connection request. For example, in the example introduced in FIG. 3, the port number included in the connection request is 3, and then the terminal device can establish an RFCOMM link with the vehicle-mounted device based on the port number 3. The RFCOMM link can be understood as a link corresponding to the port number 3.

[0122] 11、The vehicle-mounted device transmits HFP service data through the link corresponding to the port number 3.

[0123] After the establishment of the RFCOMM link corresponding to the port 3, the vehicle-mounted device understands that the link is used to transmit data corresponding to the HFP service, and then the vehicle-mounted device transmits HFP data through the link, for example. However, based on the above introduction, it can be determined that the port number allocated by the terminal device for the HFP service has been updated to port number 4 at this time, and therefore it is actually impossible to complete data transmission based on the RFCOMM link corresponding to the port number 3 to transmit data corresponding to the HFP service. It can be understood that the transmission of data corresponding to the HFP service based on the RFCOMM link corresponding to the port number 3 will result in a data transmission failure.

[0124] In one implementation, a protocol of the HFP service defines a set of AT commands and events for controlling transmission of data corresponding to the HFP service. When the RFCOMM link is not used for transmitting data corresponding to the HFP service, the AT commands and related commands transmitted on the RFCOMM link are parsed unsuccessfully, thus causing subsequent data transmission to fail.

[0125] When the transmission of data corresponding to the HFP service fails, the problems described above occur, i.e., although the Bluetooth connection is successful, the call cannot be played through the vehicle-mounted device, and the power of the terminal device displayed on the vehicle-mounted device is abnormal.

[0126] The problems described above can be extended to various Bluetooth services. In fact, for any Bluetooth service, as long as the port number of the RFCOMM link corresponding to the Bluetooth service is abnormal, the transmission of data corresponding to the Bluetooth service will fail, thus causing the data corresponding to the Bluetooth service to not be correctly presented on the vehicle-mounted device or the terminal device. The specific conditions of other Bluetooth services are not described in detail, and can be described with reference to the content described in the above embodiments.

[0127] It can be determined from the above analysis that, when the vehicle machine system of the vehicle-mounted device performs Bluetooth automatic reconnection, the port number allocated by the terminal device to the available Bluetooth service is read after the first Bluetooth connection process, and then the corresponding RFCOMM link is established based on the port number of the corresponding service and the terminal device, and the data of the corresponding Bluetooth service is transmitted based on the RFCOMM link and the terminal device. However, when the port number allocated by the terminal device to the Bluetooth service is updated, the RFCOMM link established by the vehicle-mounted device based on the saved port number is actually an incorrect link. Therefore, when the data of the Bluetooth service is transmitted based on the incorrect link, the transmission of data corresponding to the Bluetooth service will fail.

[0128] To solve the technical problems described above, some embodiments of the present application propose a technical concept. When the terminal device receives the connection request for establishing the RFCOMM link corresponding to a certain Bluetooth service sent by the vehicle-mounted device, the terminal device can first determine whether the port number included in the connection request is a historical port number allocated by the terminal device to the Bluetooth service. If it is determined that the port number included in the connection request is the historical port number, the terminal device can actively obtain the port number allocated by the vehicle-mounted device to the Bluetooth service, and actively initiate the reconstruction of the corresponding RFCOMM link to the vehicle-mounted device based on the port number, so that a correct RFCOMM link can be established, thereby realizing the successful transmission of data corresponding to the Bluetooth service, and ensuring the correctness and stability of Bluetooth data transmission.

[0129] On the basis of the foregoing introduction, the Bluetooth connection processing method provided in the present application will be described in detail below in combination with specific embodiments.

[0130] The Bluetooth connection processing method of the embodiments of the present application can be executed by an electronic device equipped with Bluetooth function, or by a chip, chip system or processor supporting the electronic device to implement the Bluetooth connection processing method, or by a logic module or software capable of implementing all or part of the functions of the electronic device, and the present application does not make specific limitation thereon. The Bluetooth connection processing method of the embodiments of the present application will be described in detail below taking the electronic device as an example.

[0131] The electronic device may, for example, be a terminal device, and the terminal device will be described first in combination with FIG. 4 and FIG. 5.

[0132] For example, FIG. 4 is a schematic diagram of the hardware structure of a terminal device provided in an embodiment of the present application.

[0133] FIG. 4 is a schematic diagram of the structure of a terminal device provided in an embodiment of the present application. The terminal 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 loudspeaker 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 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0134] It can be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the terminal device 100. In other embodiments of the present application, the terminal device 100 can include more or fewer components than those illustrated, or combine certain components, or split certain components, or different arrangement of components. The illustrated components can be implemented in hardware, software or a combination of software and hardware.

[0135] The wireless communication function of the terminal device 100 can be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, the baseband processor, and the like.

[0136] The antenna 1 and the antenna 2 are used for transmitting and receiving electromagnetic wave signals. The antennas in the terminal device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization of the antennas. For example, the antenna 1 can be multiplexed as a diversity antenna of a wireless local area network. In some other embodiments, the antennas can be used in combination with a tuning switch.

[0137] The wireless communication module 160 can provide a wireless communication solution applied to the terminal device 100, including wireless local area networks (WLAN) (such as a wireless fidelity (Wi-Fi) network), Bluetooth (BT), a global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared technology (IR), and the like.

[0138] The wireless communication module 160 can be one or more devices integrated with at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, performs frequency modulation and filtering processing on the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 160 can also receive signals to be sent from the processor 110, perform frequency modulation, amplification, and convert the signals to electromagnetic wave radiation via the antenna 2, thereby realizing the wireless communication function.

[0139] In the present application, the wireless communication module 160 can include, for example, a first chip for implementing the Bluetooth function of the terminal device. For example, the first chip for processing the Bluetooth function can be used to execute the Bluetooth connection processing method described in the embodiments of the present application. Alternatively, the Bluetooth connection processing method described in the embodiments of the present application can also be executed by using other processing devices in the terminal device, which is not limited in the present embodiment as long as the selected device has a data processing function.

[0140] It should be understood that the software system of the terminal device 100 can adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture. The software structure of the terminal device 100 is exemplarily described in the present embodiment by taking an Android system with a layered architecture as an example.

[0141] For example, FIG. 5 is a schematic diagram of a software structure of a terminal device provided by an embodiment of the present application.

[0142] As shown in FIG. 5, the layered architecture divides the software into several layers, each of which has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the system can include an application layer, an application framework layer, an Android runtime and a system library, a hardware abstraction layer (HAL), and a kernel layer. It should be noted that the embodiments of the present application take the Android system as an example for illustration, and in other operating systems (such as the Hongmeng system, the IOS system, etc.), as long as the functions of each functional module are similar to the embodiments of the present application, the scheme of the present application can also be implemented.

[0143] The application layer can include a series of application packages.

[0144] As shown in FIG. 5, the application packages can include camera, calendar, phone, map, phone, music, settings, mailbox, video, social, etc. application programs. Of course, the application layer can also include other application packages, such as payment applications, shopping applications, bank applications, social applications, etc. third-party applications, which are not limited by the present application.

[0145] The application framework layer provides the application programs of the application layer with application programming interfaces (APIs) and programming frameworks. The application framework layer includes some pre-defined functions.

[0146] As shown in FIG. 5, the application framework layer can include a window manager, a content provider, a resource manager, a view system, a notification manager, etc.

[0147] In addition, the Android runtime includes a core library and a virtual machine. The Android runtime is responsible for the scheduling and management of the Android system.

[0148] The system library can include a plurality of function modules. For example, a Bluetooth protocol stack, media libraries, a three-dimensional graphics processing library (for example, OpenGL ES), a 2D graphics engine (for example, SGL), and the like. The Bluetooth protocol stack is used to define a processing flow of data communication between Bluetooth devices. In this embodiment, for example, the data communication processing flow defined by the Bluetooth protocol stack can be adjusted, so that when the terminal device receives a connection request sent by the remaining Bluetooth device, the terminal device can first determine whether the port number included in the connection request is a historical port number allocated by the terminal device for the corresponding Bluetooth service. If yes, the terminal device can actively acquire the port number allocated by the remaining Bluetooth device for the Bluetooth service, and actively initiate a corresponding link reconstruction to the remaining Bluetooth device based on the port number, so that a correct transmission link can be established, thereby realizing successful transmission of data corresponding to the Bluetooth service, to ensure the correctness and stability of Bluetooth data transmission.

[0149] The HAL layer is a package of the Linux kernel driver, and provides an interface upward and shields implementation details of a low layer hardware.

[0150] The Bluetooth HAL, an audio (audio) HAL, a camera service (Camera HAL Server) unit of the HAL layer, and a software code library can be included in the HAL layer. In this embodiment, the Bluetooth HAL is used to provide a set of interfaces, so that the upper layer software (such as an application program in the application layer) of the system can communicate with the underlying Bluetooth hardware without processing hardware details. Meanwhile, the Bluetooth HAL can also interact with the underlying Bluetooth hardware to realize the data transmission function corresponding to Bluetooth. For example, the Bluetooth protocol stack can communicate with the Bluetooth chip through the Bluetooth HAL, thereby realizing the sending and receiving of data.

[0151] The kernel layer is a layer between hardware and software. The kernel layer at least includes a display driver, a camera driver, an audio driver, and a sensor driver.

[0152] The technical solutions of the embodiments of the present application and how the technical solutions of the embodiments of the present application solve the above technical problems will be described in detail below with specific embodiments in combination with the drawings. The following specific embodiments can be implemented independently, or can be combined with each other. For the same or similar concepts or processes, some embodiments can not be described again.

[0153] First, the Bluetooth connection processing method provided by the present application will be described in combination with FIG. 6 and FIG. 7. FIG. 6 is an interaction flowchart one of the Bluetooth connection processing method provided by the embodiments of the present application, and FIG. 7 is an interaction flowchart two of the Bluetooth connection processing method provided by the embodiments of the present application.

[0154] As shown in FIG. 6, the method comprises:

[0155] S601, the second device sends a first connection request to the first device, and the first connection request carries a first port number, which is a port number allocated by the first device for the first service in history.

[0156] In this embodiment, the first device and the second device are two-end devices for establishing a Bluetooth connection. For example, the first device can be the terminal device described above, and the second device can be the vehicle-mounted device described above. This embodiment does not limit the specific form or specific implementation of the first device and the second device, as long as the first device and the second device support Bluetooth function and the first device and the second device can establish a Bluetooth connection.

[0157] Suppose that the second device has established a Bluetooth connection with the first device before performing the steps described in this embodiment, the scenario of this embodiment can be understood as a scenario in which the second device initiates Bluetooth reconnection to the first device. Based on this, the second device may, for example, send a first connection request to the first device. In one implementation, before the second device sends the first connection request to the first device, for example, a Bluetooth basic link has been established between the second device and the first device, and then the second device may, for example, send the first connection request to the first device through the Bluetooth basic link.

[0158] In this embodiment, the first connection request carries the first port number, which is a port number allocated by the first device for the first service in history.

[0159] In one implementation, the first port number can be a port number allocated by the first device for the first service in the process of establishing a Bluetooth connection with the second device for the first time.

[0160] For example, one implementation of the second device determining the first port number can be understood with reference to FIG. 7. As shown in FIG. 7, in the process of establishing a Bluetooth connection for the first time, the second device may, for example, send a service first discovery request to the first device, wherein the service first discovery request is used to request to obtain a plurality of services available to the first device and a port number allocated by the first device for each of the plurality of services available to the first device.

[0161] Then the first device may, for example, send a service first discovery response to the second device in response to the service first discovery request, and the service first discovery response may, for example, include the port number allocated by the first device for the plurality of services available to the first device. In this embodiment, the first service can be included in the plurality of services available to the first device, and the port number allocated by the first device for the first service at the time of sending the service first discovery response is the first port number. That is, the first port number is the first port number allocated by the first device for the first service at the time of establishing a Bluetooth connection for the first time.

[0162] Afterwards, the second device can store the first port number assigned by the first device for the first service. Afterwards, in the scenario that the second device initiates Bluetooth reconnection to the first device, if the second device needs to establish an RFCOMM link corresponding to the first service with the first device, the second device can read the first port number assigned by the first device for the first service which it stores. And send a first connection request to the first device based on the first port number.

[0163] In another implementation, the first port number can be a port number assigned by the first device for the first service in the process of Bluetooth connection established by the second device with the first device historically any time. Wherein the first port number is different from the second port number.

[0164] That is to say, it is not limited whether it is the first time to establish Bluetooth connection, as long as the first port number assigned by the first device for the first service is obtained by the second device in the process of establishing Bluetooth connection historically, it can be the first port number in this embodiment. As long as the first port number is different from the second port number.

[0165] For example, for some device systems of the second device, they can save the port number assigned by the first device for the first service obtained in the process of Bluetooth connection in the manner introduced above. And when the time length of the port number assigned by the first device for the first service saved by the second device exceeds the preset time length, it can also re-obtain the port number assigned by the first device for the first service in the process of next Bluetooth connection, and save the re-obtained port number assigned by the first device for the first service. In this implementation, the first port number included in the first connection request sent by the second device can be the port number assigned by the first device for the first service obtained in the process of Bluetooth connection historically any time.

[0166] This embodiment does not limit the implementation of determining the first port number, which can be set arbitrarily according to actual needs, as long as the first port number is the port number assigned by the first device for the first service historically, and the first port number is different from the second port number.

[0167] In one implementation, it can be understood that the first port number is the port number assigned by the first device for the first service at the first time, and the second port number is the port number assigned by the first device for the first service at the second time, wherein the first time is before the second time. And the second time can be understood as the current time, and further, the current time can be understood as the present when the technical solution of this embodiment is executed.

[0168] It can be understood from the above description that the second device stores the first port number allocated by the first device to the first service in history. When the second device needs to establish a Bluetooth link with the first device for transmitting data of the first service in a subsequent Bluetooth reconnection process, the second device can initiate a connection request to the first device based on the first port number. Therefore, in this embodiment, the first connection request includes the first port number, and the first connection request is used to request establishment of the first Bluetooth link corresponding to the first port number, where the first Bluetooth link can be an RFCOMM link.

[0169] In addition, the second device requests establishment of the first Bluetooth link for the purpose of transmitting data of the first service through the first Bluetooth link. In this embodiment, the first service can be the HFP service described above, or the first service can also be any Bluetooth service, such as a BIP service. The specific implementation of the first service is not limited in this embodiment, and can be set according to actual needs.

[0170] S602, the first device establishes the first Bluetooth link with the second device.

[0171] After the first device receives the first connection request sent by the second device, the first device parses the first connection request to obtain the port number contained in the first connection request, and establishes a Bluetooth link corresponding to the port number based on the port number contained in the first connection request, that is, the first Bluetooth link in this embodiment. The purpose of the second device sending the first connection request is to establish a Bluetooth link corresponding to the first service, so the first Bluetooth link can also be understood as a Bluetooth link corresponding to the first service.

[0172] In this embodiment, the port number established in the first connection request is the first port number, and accordingly the first device and the second device establish the first Bluetooth link corresponding to the first port number.

[0173] S603, the second device sends a first message to the first device through the first Bluetooth link, and a message format of the first message is a format corresponding to the first service.

[0174] The purpose of the second device establishing the first Bluetooth link with the first device through the first connection request is to transmit data of the first service through the second Bluetooth link. Therefore, after the first device and the second device establish the first Bluetooth link, the second device can send a first message to the first device through the first Bluetooth link. The first message can be a message related to the first service, for example, the first message can be a message for initializing data transmission of the first service, or the first message can also be service data corresponding to the first service, and the specific message content of the first message is not limited in this embodiment.

[0175] To transmit the first message corresponding to the first service, the message format of the first message needs to be limited, and in this embodiment, the message format of the first message is the format corresponding to the first service. For example, when the first service is the HFP service, the message format of the first message is the message format corresponding to the HFP service.

[0176] S604, in the case that the port number corresponding to the first Bluetooth link is the first port number, the port number currently allocated by the first device for the first service is the second port number, and the first device receives the first message sent by the second device through the first Bluetooth link, the first device disconnects the first Bluetooth link.

[0177] It can be understood that the first port number is the port number historically allocated by the first device for the first service, so when the port number corresponding to the first Bluetooth link is the first port number, and the port number currently allocated by the first device for the first service is the second port number, it means that the port number used when the first Bluetooth link is currently established is inconsistent with the port number actually allocated by the first device for the first service.

[0178] After that, if the first device receives the first message sent by the second device through the first Bluetooth link, because the message format of the first message is the format corresponding to the first service, the first device can determine that the purpose of the second device to establish the first Bluetooth link is to transmit data corresponding to the first service through the first Bluetooth link. At the same time, the first device can determine based on the above information that the first port number corresponding to the first Bluetooth link is different from the second port number currently allocated by the first device for the first service, so that the first Bluetooth link cannot actually effectively transmit data corresponding to the first service at this time.

[0179] Therefore, the first device can disconnect the first Bluetooth link between the first device and the second device when it is determined that the above conditions are met, and then re-establish a correct Bluetooth link to avoid the situation that the existence of the first Bluetooth link causes the data transmission of the first service to fail.

[0180] In an implementation manner, before performing the process introduced in step 604, the first device can further perform the following judgment: whether the second port number currently allocated by the first device for the first service is the same as the first port number.

[0181] In this embodiment, in addition to the second device, the first device can also store the first port number to determine whether the port number allocated by the first device for the first service is updated in subsequent processing.

[0182] If the port number assigned by the first device for the first service is not updated, that is, the second port number assigned by the first device for the first service at the present time is still the first port number assigned when the first connection or the historical connection is connected, then the first Bluetooth link corresponding to the first port number can effectively transmit the data corresponding to the first service. In this case, there is actually no need to perform S604 and the related operations thereafter, and the data corresponding to the first service can be directly transmitted based on the first Bluetooth link.

[0183] In addition, in the case where the port number assigned by the first device for the first service is not updated, if the operation of disconnecting the first Bluetooth link and subsequently establishing the second Bluetooth link introduced in S604 is performed, these operations are actually unnecessary.

[0184] Therefore, in the embodiment, it is first determined whether the port number assigned by the first device for the first service at the present time is the same as the first port number, and in the case where they are not the same, the subsequent link disconnection processing and link reestablishment processing are performed, so as to ensure the necessity of the subsequent operations. The system resource waste caused by the unnecessary subsequent link disconnection and link establishment operations is avoided.

[0185] S605, the first device establishes a second Bluetooth link with the second device based on the third port number currently assigned by the second device for the first service.

[0186] Subsequently, the first device can actively initiate a connection request to the second device, so as to establish a correct Bluetooth link for transmitting the data of the first service. For example, the first device can establish a second Bluetooth link with the second device based on the third port number currently assigned by the second device for the first service, wherein the third port number can be understood as the port number currently assigned by the second device for the first service at the present time, so that the established second Bluetooth link can be effectively used to correctly transmit the data corresponding to the first service.

[0187] Subsequently, the first device and the second device can transmit the data corresponding to the first service based on the second Bluetooth link, because the port number corresponding to the second Bluetooth link is the third port number, and the third port number is the port number currently assigned by the second device for the first service, so that it can be ensured that the data corresponding to the first service can be effectively and correctly transmitted based on the second Bluetooth link.

[0188] In the embodiment, after the first device establishes the first Bluetooth link corresponding to the first port number between the first device and the second device, in the case that the first device receives the first message sent by the second device through the first Bluetooth link, the first device can determine that the second device needs to transmit the data of the first service through the first Bluetooth link. Further, in the case that the port number corresponding to the first Bluetooth link does not match the port number currently allocated by the first device for the first service, the first device can actively disconnect the first Bluetooth link to avoid the existence of the first Bluetooth link affecting the data transmission of the first service. Then, the second Bluetooth link is established based on the third port number currently allocated by the second device for the first service, so that the data corresponding to the first service can be effectively transmitted based on the second Bluetooth link subsequently.

[0189] Based on the above-mentioned embodiment introduction, the implementation manner of establishing the second Bluetooth link by the first device and the second device will be further introduced in combination with FIG. 8. FIG. 8 is an interactive flowchart III of the Bluetooth connection processing method provided by the embodiment of the application.

[0190] As shown in FIG. 8, the method comprises:

[0191] S801, the first device sends a service second discovery request to the second device.

[0192] The service second discovery request is used to obtain a plurality of services available to the second device and the port numbers allocated by the second device for the plurality of available services. It should be understood that the services in the plurality of available services mentioned in the application can be understood as Bluetooth services.

[0193] S802, the second device sends a service second discovery response to the first device.

[0194] Then, the second device can send a service second discovery response to the second device in response to the service second discovery request, and the port numbers allocated by the second device for the plurality of available services can be included in the service second discovery response. In the embodiment, the first service can be included in the plurality of services available to the second device, and the port number allocated by the second device for the first service at the moment of sending the service second discovery response is the third port number. That is, the latest port number allocated by the second device for the first service, which is referred to as the third port number in the embodiment, is included in the service second discovery response.

[0195] S803, the first device sends a second connection request to the second device, and the third port number is included in the second connection request.

[0196] The second connection request is used to initiate a connection request of the Bluetooth link corresponding to the first service to the second device based on a third port number, wherein the third port number is the latest port number allocated by the second device for the first service, and thus the Bluetooth link corresponding to the first service is established based on the third port number, which can effectively ensure the correctness of the Bluetooth link.

[0197] S804, the first device establishes a second Bluetooth link with the second device.

[0198] The port number corresponding to the second Bluetooth link is the third port number described above, and thus based on the second Bluetooth link, the data corresponding to the first service can be accurately and effectively transmitted between the first device and the second device.

[0199] In this embodiment, the first device initiates a service first discovery request to the second device in real time, so that the third port number allocated by the second device for the first service can be accurately and effectively obtained, and then the second Bluetooth link is established with the second device based on the third port number, so that the data corresponding to the first service can be effectively transmitted through the second Bluetooth link.

[0200] Based on the above description, the case where the port number allocated by the first device for the first service is updated will be described below. In combination with FIG. 9, a scene diagram of a change in available services is provided.

[0201] As shown in FIG. 9, it is assumed that in the first time period, the multiple services available to the first device are in the first state shown in (a) of FIG. 9. In the first state, the multiple services available to the first device include, for example, the illustrated service A, service B, service D, and service E.

[0202] In addition, the first device can allocate a respective port number to each of the multiple services available to the first device. For example, the first device can allocate a respective port number to each of the multiple services available to the first device when the Bluetooth function is started. The first device can include an SDP server, and the SDP server can allocate a respective port number to each of the multiple services available to the first device when the Bluetooth function is started.

[0203] Generally, the first device allocates port numbers to the multiple services available to the first device in the order of starting of the multiple Bluetooth services. For example, the process of allocating port numbers to the multiple Bluetooth services available to the first device can be understood with reference to (a) of FIG. 9.

[0204] Referring to FIG. 9, it is assumed that at time t1, service A is started, at which time the first device can assign, for example, service A a port number of 1. At time t2, service B is started, at which time the first device can assign, for example, service B a port number of 2. At time t3, service D is started, at which time the first device can assign, for example, service D a port number of 3. At time t4, service E is started, at which time the first device can assign, for example, service E a port number of 4.

[0205] However, as the requirements of the device vary, the plurality of services available to the first device can change. The plurality of services available to the first device can change in a scenario including:

[0206] Scenario one, the device system of the first device is upgraded, and the plurality of services available to the first device after the device system is upgraded is different from the plurality of services available to the first device before the device system is upgraded. The plurality of services available to the first device before and after the device system is upgraded can be configured by a system developer in the background, for example.

[0207] Scenario two, the plurality of services available to the first device is adjusted in the background. For example, a developer can dynamically adjust the plurality of services available to the first device in the background according to actual requirements.

[0208] Scenario three, a user manually adjusts the plurality of services available to the first device in the first device. In the Bluetooth function of some devices, a function of adjusting the Bluetooth services available to the first device can be provided to the user. In this scenario, the plurality of services available to the first device can be changed in response to the user adjustment.

[0209] The embodiment does not limit the scenario in which the Bluetooth services available to the first device change, and any scenario that can cause the Bluetooth services available to the first device to change can be used as the applicable scenario of the embodiment.

[0210] Further, the change in the Bluetooth services available to the first device can be divided into two cases, one case is that the first device adds the Bluetooth services available to the first device, and the other case is that the first device reduces the Bluetooth services available to the first device, which will be introduced below.

[0211] In the case of adding the Bluetooth services available to the first device, the first device can add a supported Bluetooth service, and the added supported Bluetooth service is set to a start state. Alternatively, the first device can switch a Bluetooth service that is originally supported but in a shutdown state to a start state.

[0212] Further, in the case of reducing the Bluetooth services available to the first device, the first device can cancel support for some Bluetooth services. Alternatively, the first device can switch some Bluetooth services in a start state to a shutdown state.

[0213] In one example, it is assumed that in the second time period, the plurality of services available to the first device changes to the second state shown in (b) of FIG. 9. It can be understood that the second time period is in time sequence after the first time period. In the second state, the plurality of services available to the first device includes, for example, the illustrated service A, service B, service C, service D, and service E. By comparing (a) and (b) of FIG. 9, it can be determined that the plurality of services available to the first device increases service C.

[0214] In which the first device assigns port numbers to the plurality of services available in turn according to the start order of the plurality of Bluetooth services available. For example, the process of the first device assigning port numbers to the plurality of Bluetooth services available corresponding to the second state can be understood with reference to (b) of FIG. 9.

[0215] With reference to FIG. 9, it is assumed that at t5, service A starts, at which time the first device can assign service A a port number of 1, for example. At t6, service B starts, at which time the first device can assign service B a port number of 2, for example. At t7, service C starts, at which time the first device can assign service C a port number of 3, for example. At t8, service D starts, at which time the first device can assign service D a port number of 4, for example. At t9, service E starts, at which time the first device can assign service E a port number of 5, for example.

[0216] It is assumed that service D in the above example is the first service, so it can be understood that in the first state shown in (a) of FIG. 9, service D is ranked third in the start order, and in the second state shown in (b) of FIG. 9, service D is ranked fourth in the start order. In which, the Bluetooth services available to the first device change, causing the ranking of service D in the start order to change, which in turn causes the port number assigned by the first device to service D to change.

[0217] And the change in the port number assigned by the first device to service D will cause the above-mentioned problem, and in the technical solution of the present application, by detecting the port number corresponding to the first Bluetooth link corresponding to service D when the second device initiates Bluetooth reconnection to the first device, the correct Bluetooth link for transmitting data corresponding to service D can be established based on the above-mentioned technical solution, thereby ensuring the accuracy and stability of subsequent Bluetooth data transmission.

[0218] It should be noted that the module names involved in the embodiments of the present application can be defined as other names, as long as the functions of the modules can be realized, and the names of the modules are not limited specifically.

[0219] It should be noted that the user information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the embodiments of the present application are all information and data authorized by the user or authorized by all parties, and the collection, use and processing of related data need to comply with relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation portal for user to choose authorization or refusal.

[0220] The Bluetooth connection processing method provided by the embodiments of the present application has been described above, and the device for executing the above method provided by the embodiments of the present application will be described below. Those skilled in the art can understand that the method and the device can be combined and referred to each other, and the related device provided by the embodiments of the present application can execute the steps in the above Bluetooth connection processing method.

[0221] The Bluetooth connection processing method provided by the embodiments of the present application can be applied in electronic devices with Bluetooth function. The electronic device includes a terminal device, and the specific device form of the terminal device can refer to the above related description, which will not be repeated here.

[0222] In one implementation manner, the embodiments of the present application provide an electronic device, and FIG. 10 is a schematic diagram of the hardware structure of the electronic device provided by the embodiments of the present application.

[0223] As shown in FIG. 10, the electronic device 100 includes: a processor 1001 and a memory 1002; the memory 1002 stores computer execution instructions; the processor 1001 executes the computer execution instructions stored in the memory 1002, so that the electronic device 100 executes the above method.

[0224] When the memory 1002 is independently arranged, the electronic device further includes a bus 1003 for connecting the memory 1002 and the processor 1001.

[0225] The embodiments of the present application provide a chip. The chip includes a processor, and the processor is used to call a computer program in a memory to execute the technical solutions in the above embodiments. The implementation principle and technical effects are similar to those of the above related embodiments, which will not be repeated here.

[0226] The embodiments of the present application further provide a computer readable storage medium. The computer readable storage medium stores a computer program. The computer program is executed by a processor to implement the method described above. The method described in the above embodiments can be implemented by software, hardware, firmware or any combination thereof, in whole or in part. If implemented by software, the functions can be stored in or transmitted as one or more instructions or code on a computer readable medium. The computer readable medium can include computer storage medium and communication medium, and can further include any medium that can carry the computer program from one place to another. The storage medium can be any target medium that can be accessed by a computer.

[0227] In a possible implementation, the computer readable medium can include RAM, ROM, compact disc read-only memory (CD-ROM) or other optical disk storage, magnetic disk storage or other magnetic storage devices, or any other medium that is targeted to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer. Moreover, any connection is properly referred to as a computer readable medium. For example, if software is transmitted from a website, server or other remote source using a coaxial cable, fiber optic cable, twisted pair, digital subscriber line (DSL) or wireless technology (such as infrared, radio and microwave), the coaxial cable, fiber optic cable, twisted pair, DSL or wireless technology (such as infrared, radio and microwave) is included in the definition of medium. As used herein, magnetic disks and optical disks include compact disks, laser disks, optical disks, digital versatile disks (DVDs), floppy disks and Blu-ray disks, in which magnetic disks usually reproduce data magnetically and optical disks reproduce data optically with a laser. Combinations of the above should also be included within the scope of computer readable medium.

[0228] The embodiments of the present application provide a computer program product, which includes a computer program. When the computer program is executed, the computer program causes the computer to execute the method described above.

[0229] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams can be implemented by computer program instructions. These computer program instructions can be provided to a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing devices to produce a machine, so that the instructions executed by the computer or other programmable data processing devices produce a device that implements the functions specified in one or more flows in the flowcharts and / or one or more blocks in the block diagrams.

[0230] The above detailed description of the application is further detailed, the purpose, technical solutions and beneficial effects of the present application are further detailed, it should be understood that the above is only the specific embodiment of the present application, and is not used to limit the protection scope of the present application, any modification, equivalent replacement, improvement, etc. made on the basis of the technical solutions of the present application should be included in the protection scope of the present application.

Claims

1. A Bluetooth connection processing method, characterized by, Applied to a first device, the method comprises: receiving a first connection request sent by a second device, the first connection request carrying a first port number, the first port number being a port number historically allocated by the first device for a first service; in response to the first connection request, establishing a first Bluetooth link corresponding to the first port number with the second device; in a case where the port number corresponding to the first Bluetooth link is the first port number, the first device currently allocates a second port number for the first service, and a first message sent by the second device through the first Bluetooth link is received, the first message being in a format corresponding to the first service, and the first port number being different from the second port number, disconnecting the first Bluetooth link; after disconnecting the first Bluetooth link, establishing a second Bluetooth link corresponding to the first service with the second device based on a third port number currently allocated by the second device for the first service.

2. The method of claim 1, wherein, The method further comprises: in a case where the first device and the second device establish a Bluetooth connection for the first time, in response to a service first discovery request sent by the second device, sending service first response information to the second device; wherein the service first response information includes a port number allocated by the first device for each of a plurality of services available to the first device, the plurality of services available to the first device including the first service, and the port number allocated by the first device for the first service at the time of sending the service first response information being the first port number; storing the first port number allocated by the first device for the first service.

3. The method according to claim 1 or 2, characterized in that, The method further comprises: in a case where the plurality of services available to the first device are in a first state, the first device sequentially allocating port numbers to the plurality of services available to the first device in a first start order of the plurality of services available to the first device, wherein the first service is in a first ranking in the first start order, and the port number allocated by the first device for the first service is the first port number; in a case where the plurality of services available to the first device are in a second state, the first device sequentially allocating port numbers to the plurality of services available to the first device in a second start order of the plurality of services available to the first device, wherein the first service is in a second ranking in the second start order, and the port number allocated by the first device for the first service is the second port number; the plurality of services available to the first device in the first state being different from the plurality of services available to the first device in the second state, and the first ranking being different from the second ranking.

4. The method according to any one of claims 1 to 3, characterized in that, The method further comprises: establishing the second Bluetooth link corresponding to the first service with the second device based on the third port number allocated by the second device for the first service, comprising: sending a service second discovery request to the second device, the service second discovery request being used to obtain a port number allocated by the second device for each of a plurality of services available to the second device; receive service second response information from the second device, the service second response information including a port number allocated to each of a plurality of services available to the second device, the plurality of services available to the second device including the first service, and the second device allocating the third port number to the first service at the time of sending the service second response information; send a second connection request to the second device, the second connection request carrying the third port number; establish the second Bluetooth link with the second device based on the second connection request.

5. The method according to any one of claims 1 to 4, characterized in that, The first Bluetooth link and the second Bluetooth link are links established based on a radio frequency communication (RFCOMM) protocol, and the first service is a hands-free profile (HFP) service.

6. An electronic device, comprising: The electronic device includes one or more processors and a memory; The memory is coupled to the one or more processors, and the memory is configured to store computer program code including computer instructions, and the one or more processors are configured to invoke the computer instructions to cause the electronic device to perform the method of any one of claims 1 to 5.

7. A chip system, characterized by The chip system is applied to an electronic device, and the chip system includes one or more processors configured to invoke computer instructions to cause the electronic device to perform the method of any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, The computer readable storage medium includes computer instructions configured to cause an electronic device to perform the method of any one of claims 1 to 5 when the computer instructions are executed on the electronic device.

9. A computer program product, characterised in that, The computer program product includes computer program code configured to cause an electronic device to perform the method of any one of claims 1 to 5 when the computer program code is executed on the electronic device.

Citation Information

Patent Citations

  • Communication method and device

    CN109314564A

  • Bluetooth connection method and device, storage medium and terminal

    CN110944313A

  • Method and apparatus for controlling electronic device in wireless communication system supporting bluetooth communication

    US20170215113A1

  • Efficient service registration for legacy applications in a bluetooth environment

    US6826387B1

  • Bluetooth device control method and apparatus, and device and storage medium

    WO2023225869A1