CN114173315B - Bluetooth reconnection method and terminal equipment - Google Patents

Bluetooth reconnection method and terminal equipment Download PDF

Info

Publication number
CN114173315B
CN114173315B CN202210131306.5A CN202210131306A CN114173315B CN 114173315 B CN114173315 B CN 114173315B CN 202210131306 A CN202210131306 A CN 202210131306A CN 114173315 B CN114173315 B CN 114173315B
Authority
CN
China
Prior art keywords
bluetooth
application
protocol stack
adsorption state
terminal device
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210131306.5A
Other languages
Chinese (zh)
Other versions
CN114173315A (en
Inventor
张瑞芳
黄鹏飞
宋业全
牛永民
张雅姝
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Honor Device Co Ltd
Original Assignee
Honor Device Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Honor Device Co Ltd filed Critical Honor Device Co Ltd
Priority to CN202210131306.5A priority Critical patent/CN114173315B/en
Publication of CN114173315A publication Critical patent/CN114173315A/en
Application granted granted Critical
Publication of CN114173315B publication Critical patent/CN114173315B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W4/00Services specially adapted for wireless communication networks; Facilities therefor
    • H04W4/80Services using short range communication, e.g. near-field communication [NFC], radio-frequency identification [RFID] or low energy communication
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W76/00Connection management
    • H04W76/10Connection setup
    • H04W76/14Direct-mode setup
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W76/00Connection management
    • H04W76/10Connection setup
    • H04W76/19Connection re-establishment
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W8/00Network data management
    • H04W8/005Discovery of network devices, e.g. terminals

Abstract

The embodiment of the application provides a Bluetooth connection method and terminal equipment, and is applied to the technical field of terminals. In the method, in the process of starting the Bluetooth function of the terminal equipment, the Bluetooth application acquires the adsorption state of the Bluetooth equipment and sends a connection instruction back to the Bluetooth protocol stack, when the adsorption state of the Bluetooth equipment is in the adsorbed state, the Bluetooth application updates the adsorption state value to be a first attribute value, the Bluetooth protocol stack reads the adsorption state value according to the connection instruction, and when the acquired adsorption state value is the first attribute value, the Bluetooth protocol stack controls the Bluetooth module to execute scanning operation so as to connect the Bluetooth equipment back. Therefore, the updating process of the adsorption state value is executed in the Bluetooth application in advance, when the Bluetooth protocol stack reads the adsorption state value, the Bluetooth application finishes updating the adsorption state value, and the adsorption state value read by the Bluetooth protocol stack is the first attribute value, so that the terminal equipment can be automatically connected back with the Bluetooth equipment, and the operation steps of a user are reduced.

Description

Bluetooth reconnection method and terminal equipment
Technical Field
The application relates to the technical field of terminals, in particular to a Bluetooth connection method and terminal equipment.
Background
With the development of wireless technology and the popularization of terminal devices, people have been accustomed to connecting terminal devices with bluetooth devices in a wireless manner. The bluetooth technology is widely applied to terminal devices as a relatively mature short-distance wireless technology at present, for example, the bluetooth keyboard is connected with a tablet computer through bluetooth.
However, after the bluetooth connection is established between the terminal device and the bluetooth device, if the terminal device and the bluetooth device are closed and placed overnight, and the terminal device and the bluetooth device are opened again, the terminal device may not be automatically connected back to the bluetooth device.
Disclosure of Invention
The embodiment of the application provides a Bluetooth reconnection method and terminal equipment, wherein after the terminal equipment and the Bluetooth equipment are connected in a Bluetooth mode, if the terminal equipment and the Bluetooth equipment are placed in a closed mode for one night, the terminal equipment and the Bluetooth equipment are opened again, and then the terminal equipment and the Bluetooth equipment can be automatically reconnected to achieve success.
In a first aspect, an embodiment of the present application provides a bluetooth backhaul method, which is applied to a terminal device, where the terminal device includes a bluetooth application, a bluetooth protocol stack, and a bluetooth module, and the method includes: in the process of starting the Bluetooth function of the terminal equipment, the Bluetooth application acquires the adsorption state of the Bluetooth equipment and sends a connection instruction back to a Bluetooth protocol stack; when the adsorption state of the Bluetooth equipment is the adsorbed state, the Bluetooth application updates the adsorption state value to a first attribute value; the first attribute value represents that the terminal equipment and the Bluetooth equipment are in an adsorbed state; the Bluetooth protocol stack reads the adsorption state value according to the loop connection instruction; and when the adsorption state value read by the Bluetooth protocol stack is the first attribute value, the Bluetooth protocol stack controls the Bluetooth module to execute scanning operation so as to connect the Bluetooth equipment back.
Therefore, the time consumption caused by starting the accessory management service application and monitoring the adsorption state of the Bluetooth device through the accessory management service application can be effectively reduced, the process of updating the adsorption state value can be earlier than the process of reading the adsorption state value by the Bluetooth protocol stack, and therefore when the adsorption state value is read by the Bluetooth protocol stack, the adsorption state value is updated and completed by the Bluetooth application, the adsorption state value read by the Bluetooth protocol stack is the first attribute value, the terminal device can be automatically connected back with the Bluetooth device, and the operation steps of a user are reduced.
In an optional implementation manner, the reading, by the bluetooth protocol stack, of the adsorption state value according to the loopback instruction includes: and when the Bluetooth protocol stack receives the loopback instruction, the Bluetooth protocol stack reads the adsorption state value after delaying the preset time. Therefore, after the Bluetooth protocol stack receives the reconnection instruction, the process of directly reading the adsorption state value is removed, the time for reading the adsorption state value by the Bluetooth protocol stack is delayed for the preset time, the adsorption state value read by the Bluetooth protocol stack can be the first attribute value, and the terminal device can be automatically reconnected with the Bluetooth device.
In an alternative embodiment, the loopback instruction includes a first device identification of the bluetooth device; the bluetooth protocol stack controls the bluetooth module to perform a scanning operation to loop back the bluetooth device, including: the Bluetooth protocol stack sends the first equipment identification to the Bluetooth module; the Bluetooth module adds the first equipment identifier into a white list; and the Bluetooth module executes scanning operation according to the white list so as to connect the Bluetooth equipment back.
In an alternative embodiment, the bluetooth module performs a scan operation according to a white list to loop back the bluetooth device, including: when at least one Bluetooth device identifier exists in the white list, the Bluetooth module executes scanning operation; when the scanned broadcast message includes a second device identification matching the first device identification, the bluetooth module initiates a connection back request to the bluetooth device to connect back to the bluetooth device. In this way, the bluetooth module may reestablish a bluetooth connection with the bluetooth device based on the first device identification of the bluetooth device.
In an alternative embodiment, the bluetooth application includes a device management service and a bluetooth peripheral control service; the bluetooth is used and is acquireed bluetooth equipment's adsorption state, includes: the Bluetooth application starts the equipment management service; the equipment management service starts a Bluetooth peripheral control service; the Bluetooth peripheral control service acquires the adsorption state of the Bluetooth equipment.
In an alternative embodiment, the terminal device further comprises a first sensor driving and adsorbing sensor; the bluetooth peripheral hardware control service acquires the adsorption state of the bluetooth device, including: the Bluetooth peripheral control service sends an adsorption state acquisition instruction to the first sensor drive; the first sensor drive acquires an instruction according to the adsorption state, and acquires the adsorption state of the Bluetooth equipment acquired by the adsorption sensor; the adsorption state comprises an adsorbed state and an unadsorbed state; and the Bluetooth peripheral control service receives the adsorption state reported by the first sensor drive. In this way, based on the first sensor drive, the bluetooth application can be made to acquire the adsorption state of the bluetooth device.
In an alternative embodiment, the bluetooth application comprises a bluetooth upper layer service; sending a link instruction back to the bluetooth protocol stack, comprising: the Bluetooth application starts Bluetooth upper layer service; the bluetooth upper layer service sends a connection instruction back to the bluetooth protocol stack.
In an optional implementation manner, in a process that a bluetooth function of the terminal device is turned on, before the bluetooth application acquires an adsorption state of the bluetooth device and sends a connection instruction back to the bluetooth protocol stack, the method further includes: and when the terminal equipment meets the preset condition, the Bluetooth application executes the starting operation of the Bluetooth function aiming at the terminal equipment. The preset condition may also be referred to as a second preset condition.
In an optional implementation, the terminal device further includes a power saving application; when the terminal device satisfies the preset condition, the bluetooth application executes the opening operation of the bluetooth function for the terminal device, including: when the system time of the terminal equipment reaches the preset time, the power-saving application sends a Bluetooth function starting request to the Bluetooth application; and the Bluetooth application executes the starting operation of the Bluetooth function aiming at the terminal equipment according to the Bluetooth function starting request. Wherein, the preset time can also be called as a second preset time; thus, the bluetooth application can be notified by the power saving application to turn on the bluetooth function.
In an optional embodiment, the terminal device further comprises a second sensor driving and cover opening and closing detection sensor; when the terminal device satisfies the preset condition, the bluetooth application executes the opening operation of the bluetooth function for the terminal device, including: the second sensor drives the cover opening and closing state acquired by the cover opening and closing detection sensor to be reported to the Bluetooth application; and when the cover opening and closing state is the cover opening state, the Bluetooth application executes opening operation aiming at the Bluetooth function of the terminal equipment. In this way, the bluetooth application can be informed to turn on the bluetooth function through the second sensor driving.
In a second aspect, an embodiment of the present application provides a terminal device, which includes a memory and a processor, where the memory is used to store a computer program, and the processor is used to call the computer program to execute the bluetooth backhaul method described above.
In a third aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program or instructions are stored, and when the computer program or instructions are executed, the bluetooth loopback method described above is implemented.
In a fourth aspect, an embodiment of the present application provides a computer program product, which includes a computer program and when the computer program is executed, causes a computer to execute the bluetooth backhaul method described above.
In each of the possible implementations of the second aspect to the fourth aspect, the effect is similar to that in the first aspect and the possible design of the first aspect, and details are not repeated here.
Drawings
Fig. 1 is a schematic diagram of a terminal device and a bluetooth device in an uncapped state according to an embodiment of the present application;
fig. 2 is a schematic diagram of a terminal device and a bluetooth device in a closed state according to an embodiment of the present application;
fig. 3 is a flowchart of a bluetooth connection method provided in the related art;
fig. 4 is a schematic diagram illustrating transition between bluetooth states according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of a hardware system of a terminal device according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of a terminal device software system according to an embodiment of the present application;
fig. 7 is a schematic structural diagram of a bluetooth architecture according to an embodiment of the present application;
fig. 8 is a flowchart of a bluetooth backhaul method according to an embodiment of the present application;
fig. 9 is a flowchart of a bluetooth connection method according to an embodiment of the present application;
fig. 10 is a schematic structural diagram of a terminal device according to an embodiment of the present disclosure.
Detailed Description
In order to facilitate clear description of technical solutions of the embodiments of the present application, in the embodiments of the present application, words such as "first" and "second" are used to distinguish identical items or similar items with substantially the same functions and actions. For example, the first chip and the second chip are only used for distinguishing different chips, and the sequence order thereof is not limited. Those skilled in the art will appreciate that the terms "first," "second," etc. do not denote any order or quantity, nor do the terms "first," "second," etc. denote any order or importance.
It should be noted that in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described herein as "exemplary" or "such as" is not necessarily to be construed as preferred or advantageous over other embodiments or designs. Rather, use of the word "exemplary" or "such as" is intended to present relevant concepts in a concrete fashion.
In the embodiments of the present application, "at least one" means one or more, "a plurality" means two or more. "and/or" describes the association relationship of the associated objects, meaning that there may be three relationships, e.g., a and/or B, which may mean: a exists alone, A and B exist simultaneously, and B exists alone, wherein A and B can be singular or plural. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship. "at least one of the following" or similar expressions refer to any combination of these items, including any combination of the singular or plural items. For example, at least one (one) of a, b, or c, may represent: a, b, c, a-b, a-c, b-c, or a-b-c, wherein a, b, c may be single or multiple.
The bluetooth technology is a radio technology supporting short-distance communication of devices, can realize short-distance wireless data transmission between terminal devices and bluetooth devices, and has the advantages of convenience, rapidness, flexibility and safety. In order to better understand the present application, in the following embodiments, a terminal device is a tablet computer, and a bluetooth device is a bluetooth keyboard.
As shown in fig. 1, the terminal device 100 and the bluetooth device 200 are in an open cover state. If the terminal device 100 needs to be connected with the bluetooth device 200 via bluetooth, the terminal device 100 needs to be attached to the bluetooth device 200, and then the bluetooth switch of the terminal device 100 is turned on, so that the terminal device 100 is connected with the bluetooth device 200 via bluetooth. The terminal device 100 and the bluetooth device 200 may establish a bluetooth connection through Bluetooth Low Energy (BLE) or classic bluetooth rate (BR/EDR).
After the terminal device 100 establishes the bluetooth connection with the bluetooth device 200, the bluetooth device 200 may provide an input to the terminal device 100, and the terminal device 100 performs an operation in response to the input based on the input of the bluetooth device 200.
In some scenarios, power saving applications, such as power saving sprites and other applications, are installed in the terminal device 100, and these power saving applications conveniently control some power consuming hardware and setting items in the terminal device 100 mainly through a power saving mode, and intelligently remind a current power consuming program, a service maliciously started in a background, and the like, so that the standby time is improved to the maximum extent, and the electric quantity of the terminal device 100 can be effectively saved.
In some embodiments, when the terminal device 100 satisfies the first preset condition, in order to save power consumption of the terminal device 100, the power saving application in the terminal device 100 is set to a power saving mode, and the power saving application sends a bluetooth function shutdown request to the bluetooth application, so that the bluetooth application shuts down the bluetooth function of the terminal device 100 according to the bluetooth function shutdown request.
Illustratively, the first preset condition may be that the terminal device 100 and the bluetooth device 200 are placed in a closed manner, and when the system time of the terminal device 100 reaches the first preset time, the bluetooth application is not in a bluetooth communication state with any bluetooth device.
For example, when the user does not use the terminal device 100, as shown in fig. 2, the user may close the terminal device 100 and the bluetooth device 200 (that is, the terminal device 100 and the bluetooth device 200 are in a closed state), and when the system time of the terminal device 100 reaches a first preset time, for example, the first preset time is 00:00 a morning, the power saving application may call an Application Programming Interface (API) in an application framework layer, determine whether the current bluetooth application is in a bluetooth communication state with any bluetooth device, and if the bluetooth application is not in the bluetooth communication state with any bluetooth device, may determine that the terminal device 100 satisfies the first preset condition.
Of course, it is understood that the first preset condition may be other conditions. For example, the first preset condition is that the terminal device 100 and the bluetooth device 200 are placed in a closed manner; or, the first preset condition is that the system time of the terminal device 100 reaches a first preset time; or, the first preset condition is that the terminal device 100 and the bluetooth device 200 are covered and placed, and the time length of covering and placing reaches a certain time length (for example, 10 minutes). The embodiment of the present application does not limit this.
When the terminal device 100 meets the second preset condition, for example, the system time of the terminal device 100 reaches the second preset time, or the bluetooth application restarts the bluetooth function when it is detected that the terminal device 100 and the bluetooth device 200 are opened. However, after the bluetooth function is restarted, a phenomenon may occur in which the terminal device 100 cannot automatically connect back to the bluetooth device 200, for a specific reason, refer to the following description.
Fig. 3 is a flowchart of a bluetooth backhaul method provided in the related art. Referring to fig. 3, the bluetooth backhaul method may specifically include the following steps:
step 301, switching the bluetooth function of the terminal device from the off state to the TurningOn state.
When the terminal device 100 satisfies the first preset condition, the power saving application in the terminal device 100 notifies the bluetooth application to turn off the bluetooth function of the terminal device 100. And when the terminal device 100 meets the second preset condition, the bluetooth application restarts the bluetooth function. At this time, the adsorption state value of the terminal device 100 defaults to the second attribute value.
As shown in fig. 4, during the bluetooth function being turned On, the bluetooth states of the bluetooth function include the following 5 states, which are Off state, TurningBleOn state, BleOn state, TurningOn state and On state, respectively. When opening bluetooth function, bluetooth function's bluetooth state passes through closed state, TurningBleOn state, BleOn state, TurningOn state in proper order and reaches the open mode.
It is understood that TurningBleOn state, BleOn state, and TurningOn state are intermediate states from the off state to the on state; the BleOn state is a state when part of the Bluetooth functions are started, and the starting state is a state when all the Bluetooth functions are started; the TurningBleOn state refers to a state when entering into the BleOn state is being performed from the off state, and the TurningOn state refers to a state when entering into the on state is being performed from the BleOn state.
Accordingly, during the shutdown process of the bluetooth function, the bluetooth states of the bluetooth function include the following 5 states, which are an on state, a TurningOff state, a BleOn state, a TurningBleOff state, and an off state, respectively. When the Bluetooth switch is turned off, the Bluetooth state of the Bluetooth function reaches the off state through the on state, the TurningOff state, the BleOn state and the TurningBleOff state in sequence.
It is understood that the TurningOff state and the TurningBleOff state are intermediate states from the on state to the off state; the TurningOff state refers to a state when entering the BleOn state is being performed from the on state, and TurningBleOff refers to a state when entering the off state is being performed from the BleOn state.
Step 302, when the bluetooth function enters into TurningOn state, the bluetooth application starts the bluetooth upper layer service to send a connection instruction back to the bluetooth protocol stack through the bluetooth upper layer service.
And step 303, the bluetooth protocol stack reads the adsorption state value according to the loop connection instruction.
Specifically, the bluetooth protocol stack may read the current adsorption state value by calling the Android native code bta _ hh _ le _ add _ dev _ bg _ conn.
And step 304, the Bluetooth protocol stack determines whether the Bluetooth equipment is adsorbed according to the read adsorption state value.
Wherein, the adsorption state value can be the first attribute value or the second attribute value. When the adsorption state value in the terminal device 100 is the first attribute value, it represents that the bluetooth device adsorbs; and when the adsorption state value in the terminal device 100 is the second attribute value, it indicates that the bluetooth device is not adsorbed. The first attribute value may be referred to as true and the second attribute value may be referred to as false.
And 305, when the Bluetooth equipment is adsorbed, the Bluetooth protocol stack reads the adsorption state value again after delaying the preset time.
And step 306, the bluetooth protocol stack determines whether the bluetooth device is attached according to the re-read attachment state value.
And 307, when the bluetooth device is determined to be adsorbed again, the bluetooth protocol stack sends the first device identifier of the bluetooth device to the bluetooth module, so that the bluetooth module adds the first device identifier to a white list to connect back to the bluetooth device.
And 308, when the Bluetooth device is not adsorbed, the Bluetooth protocol stack ignores the first device identification of the Bluetooth device.
That is to say, when the bluetooth device 200 is not attached, the bluetooth protocol stack will not send the first device identifier of the bluetooth device to the bluetooth module, so that the bluetooth module does not add the first device identifier to the white list, and the bluetooth module does not connect back to the bluetooth device 200.
It should be noted that, when it is determined in step 304 that the bluetooth device 200 is not attached, step 308 is directly performed; accordingly, when it is determined in step 306 that the bluetooth device 200 is not attached, step 308 is also directly performed.
Step 309, when the bluetooth function enters into TurningOn state, the bluetooth application starts monitoring for the adsorption state of the bluetooth device.
In step 310, the bluetooth application detects whether the bluetooth device is attached.
In step 311, when the bluetooth device is attached, the bluetooth application starts an accessory management service application.
At step 312, the accessory management service application initiates a listen for the attachment status of the bluetooth device.
In step 313, the accessory management service application detects whether a bluetooth device is attached.
In step 314, when the bluetooth device is attached, the accessory management service application updates the attachment status value to the first attribute value.
It should be noted that, in the above implementation process, after the bluetooth function enters the TurningOn state, steps 302 to 308 and steps 309 to 314 are respectively implemented. That is, when the bluetooth function is started, the terminal device 100 attempts to initiate a loopback based on the bluetooth protocol stack and the bluetooth module on the one hand, and starts the adsorption state listening based on the bluetooth application and the accessory management service application on the other hand, to update the adsorption state value, both of which are processed in parallel.
Generally, in the starting process of the bluetooth function, when the bluetooth application monitors the adsorption of the bluetooth device, the accessory management service application is started to monitor the adsorption state of the bluetooth device, and when the bluetooth device adsorbs, the accessory management service application updates the adsorption state value from the second attribute value to the first attribute value. Therefore, the adsorption state value has more updating processes and the time consumption is obviously increased. The bluetooth protocol stack may start the operation of the bluetooth device 200 only when the adsorption state values read twice are the first attribute values.
Because the Bluetooth protocol stack reads the adsorption state value and the accessory management service application updates the adsorption state value, a timing sequence problem exists between the two operations, and if the time when the Bluetooth protocol stack reads the adsorption state value is earlier than the time when the accessory management service application updates the adsorption state value. Therefore, when the bluetooth protocol stack reads the adsorption state value, the accessory management service application does not update the adsorption state value yet, which may cause the adsorption state value read by the bluetooth protocol stack to be the second attribute value.
If the adsorption state value read by the bluetooth protocol stack is the second attribute value, the bluetooth protocol stack does not send the first device identifier of the bluetooth device to the bluetooth module, so that the bluetooth module does not add the first device identifier to the white list, and the bluetooth module does not reconnect the bluetooth device 200, and the terminal device 100 and the bluetooth device 200 cannot automatically reconnect.
If the terminal device 100 and the bluetooth device 200 cannot perform automatic connection back, the user needs to manually click back connection operation in the paired list displayed on the terminal device 100 to connect back the terminal device 100 and the bluetooth device 200, which results in complicated operation for the user.
Based on this, according to the bluetooth loopback method and the terminal device provided in the embodiment of the present application, in the process of starting the bluetooth function of the terminal device, the bluetooth application acquires the adsorption state of the bluetooth device and sends a loopback instruction back to the bluetooth protocol stack, when the adsorption state of the bluetooth device is in the adsorbed state, the bluetooth application updates the adsorption state value to the first attribute value, the bluetooth protocol stack reads the adsorption state value according to the loopback instruction, and when the adsorption state value read by the bluetooth protocol stack is the first attribute value, the bluetooth protocol stack controls the bluetooth module to execute a scanning operation to loop back the bluetooth device. Therefore, the updating process of the adsorption state value is executed in the Bluetooth application in advance, time consumption caused by starting the accessory management service application and monitoring the adsorption state of the Bluetooth device through the accessory management service application can be effectively reduced, and the updating process of the adsorption state value can be earlier than the process of reading the adsorption state value by a Bluetooth protocol stack.
The Bluetooth connection method provided by the embodiment of the application can be applied to terminal equipment with a Bluetooth function. In order to better understand the embodiments of the present application, the following describes the structure of the terminal device according to the embodiments of the present application:
fig. 5 shows a schematic configuration diagram of the terminal device 100. The terminal device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a Universal Serial Bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a key 190, a motor 191, an indicator 192, a camera 193, a display screen 194, a Subscriber Identification Module (SIM) card interface 195, and the like. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air 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, and the like.
It is to be understood that the illustrated structure of the embodiment of the present application does not constitute a specific limitation to the terminal device 100. In other embodiments of the present application, terminal device 100 may include more or fewer components than shown, or some components may be combined, some components may be split, or a different arrangement of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
The processor 110 may include one or more processing units, wherein the different processing units may be stand-alone devices or may be integrated in one or more processors.
The wireless communication function of the terminal device 100 may be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, a modem processor, a baseband processor, and the like.
The antennas 1 and 2 are used for transmitting and receiving electromagnetic wave signals. The antennas in terminal device 100 may be used to cover a single or multiple communication bands. Different antennas can also be multiplexed to improve the utilization of the antennas.
The mobile communication module 150 may provide a solution including wireless communication of 2G/3G/4G/5G, etc. applied to the terminal device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a Low Noise Amplifier (LNA), and the like. Modulation
The wireless communication module 160 may provide solutions for wireless communication applied to the terminal device 100, including Wireless Local Area Networks (WLANs) (e.g., wireless fidelity (Wi-Fi) networks), bluetooth (bluetooth, BT), Global Navigation Satellite System (GNSS), Frequency Modulation (FM), Near Field Communication (NFC), Infrared (IR), and the like. The wireless communication module 160 may be one or more devices integrating 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 electromagnetic wave signals, and transmits the processed signals to the processor 110. The wireless communication module 160 may also receive a signal to be transmitted from the processor 110, perform frequency modulation and amplification on the signal, and convert the signal into electromagnetic waves through the antenna 2 to radiate the electromagnetic waves.
In some embodiments, the antenna 1 of the terminal device 100 is coupled to the mobile communication module 150 and the antenna 2 is coupled to the wireless communication module 160 so that the terminal device 100 can communicate with the network and other devices through wireless communication technology.
The terminal device 100 implements a display function by the GPU, the display screen 194, and the application processor. The display screen 194 is used for displaying images, displaying videos, receiving slide operations, and the like. In some embodiments, the terminal device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1. The terminal device 100 can implement a photographing function through the ISP, the camera 193, the video codec, the GPU, the display screen 194, and the application processor, etc.
The external memory interface 120 may be used to connect an external memory card, such as a Micro SD card, to extend the storage capability of the terminal device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. The internal memory 121 may be used to store computer-executable program code, which includes instructions. The processor 110 executes various functional applications of the terminal device 100 and data processing by executing instructions stored in the internal memory 121 and/or instructions stored in a memory provided in the processor.
The terminal device 100 may implement an audio function through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor. Such as music playing, recording, etc.
The audio module 170 is used to convert digital audio information into analog audio signals for output, and also used to convert analog audio inputs into digital audio signals. The audio module 170 may also be used to encode and decode audio signals.
The speaker 170A, also called a "horn", is used to convert the audio electrical signal into an acoustic signal. The terminal device 100 can listen to music through the speaker 170A, or listen to a handsfree call. The receiver 170B, also called "earpiece", is used to convert the electrical audio signal into an acoustic signal. When the terminal device 100 answers a call or voice information, it is possible to answer a voice by bringing the receiver 170B close to the human ear. The microphone 170C, also referred to as a "microphone," is used to convert sound signals into electrical signals. The headphone interface 170D is used to connect a wired headphone.
The pressure sensor 180A is used for sensing a pressure signal, and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A may be disposed on the display screen 194. The gyro sensor 180B may be used to determine the motion attitude of the terminal device 100. The air pressure sensor 180C is used to measure air pressure.
The magnetic sensor 180D includes a hall sensor. The terminal device 100 may detect whether it is attached to the bluetooth device 200 using the magnetic sensor 180D; alternatively, the terminal device 100 may detect the open/close cover state of the terminal device 100 and the bluetooth device 200 using the magnetic sensor 180D.
The acceleration sensor 180E can detect the magnitude of acceleration of the terminal device 100 in various directions (generally, three axes). A distance sensor 180F for measuring a distance. The terminal device 100 may measure the distance by infrared or laser. The proximity light sensor 180G may include, for example, a Light Emitting Diode (LED) and a light detector, such as a photodiode. The terminal device 100 can utilize the proximity light sensor 180G to detect that the user holds the terminal device 100 close to the ear for talking, so as to automatically turn off the screen to achieve the purpose of saving power. The proximity light sensor 180G may also be used in a holster mode, a pocket mode automatically unlocks and locks the screen. The ambient light sensor 180L is used to sense the ambient light level. The fingerprint sensor 180H is used to collect a fingerprint. The temperature sensor 180J is used to detect temperature. The touch sensor 180K is also called a "touch device". The touch sensor 180K may be disposed on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, which is also called a "touch screen". The touch sensor 180K is used to detect a touch operation applied thereto or nearby. The bone conduction sensor 180M may acquire a vibration signal.
The keys 190 include a power-on key, a volume key, and the like. The keys 190 may be mechanical keys. Or may be touch keys. The motor 191 may generate a vibration cue. The motor 191 may be used for incoming call vibration prompts as well as for touch vibration feedback. Indicator 192 may be an indicator light that may be used to indicate a state of charge, a change in charge, or a message, missed call, notification, etc. The SIM card interface 195 is used to connect a SIM card. The SIM card can be brought into and out of contact with the terminal device 100 by being inserted into the SIM card interface 195 or being pulled out of the SIM card interface 195.
The software system of the terminal device 100 may adopt a hierarchical architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, a cloud architecture, or the like. The embodiment of the present application takes an Android system with a layered architecture as an example, and exemplarily illustrates a software structure of the terminal device 100.
Fig. 6 is a block diagram of a software configuration of the terminal device 100 according to the embodiment of the present application.
The layered architecture divides the software into several layers, each layer having a clear role and division of labor. The layers communicate with each other through a software interface. In some embodiments, the Android system is divided into four layers, an application layer, an application framework layer, an Android runtime (Android runtime) and system library, and a kernel layer from top to bottom.
The application layer may include a series of application packages.
As shown in fig. 6, the application package may include applications such as a power saving application, a bluetooth application, an accessory management service application, and a setup application.
The application framework layer provides an API and programming framework for the applications of the application layer. The application framework layer includes a number of predefined functions.
As shown in fig. 6, the application framework layer may include an input system, an activity manager, a location manager, a notification manager, a resource manager, a phone manager, a view system, a bluetooth service, and the like.
The input system is used to manage the programs of the input device. For example, the input system may determine input operations such as mouse click operations, keyboard input operations, and touch swipe operations.
The activity manager is used for managing the life cycle of each application program and the navigation backspacing function. The method is responsible for the creation of the main thread of the Android and the maintenance of the life cycle of each application program.
The location manager is used to provide location services for applications including querying for a last known location, registering and deregistering location updates from some periodic basis, etc.
The notification manager enables the application to display notification information in the status bar, can be used to convey notification-type messages, can disappear automatically after a brief dwell, and does not require user interaction. Such as a notification manager used to inform download completion, message alerts, etc. The notification manager may also be a notification that appears in the form of a chart or scroll bar text at the top status bar of the system, such as a notification of a background running application, or a notification that appears on the screen in the form of a dialog window. For example, text information is prompted in the status bar, a prompt tone is given, the terminal device vibrates, and an indicator light flashes.
The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, and the like.
The telephone manager is used for managing the functions of the mobile device, and comprises the following components: the method comprises the steps of mobile phone call state, obtaining phone information (equipment, sim card and network information), monitoring phone state and calling a phone dialer to make a call.
The view system includes visual controls such as controls to display text, controls to display pictures, and the like. The view system may be used to build applications. The display interface may be composed of one or more views. For example, the display interface including the short message notification icon may include a view for displaying text and a view for displaying pictures.
The bluetooth service may provide a bluetooth application programming interface (bluetooth API) such that interaction between the bluetooth application and the power saving application, between the bluetooth application and the accessory management service application, and between the accessory management service application and a hardware driver (e.g., a sensor driver) may occur by calling the bluetooth application programming interface.
The Android runtime comprises a core library and a virtual machine. The Android runtime is responsible for scheduling and managing an Android system.
The core library comprises two parts: one part is a function which needs to be called by java language, and the other part is a core library of android.
The application layer and the application framework layer run in a virtual machine. And executing java files of the application layer and the application framework layer into a binary file by the virtual machine. The virtual machine is used for performing the functions of object life cycle management, stack management, thread management, safety and exception management, garbage collection and the like.
The system library may include a plurality of functional modules. For example: the system comprises an image drawing module, an image rendering module, an image synthesis module, a function library, a Bluetooth protocol stack and the like.
The image drawing module is used for drawing two-dimensional or three-dimensional images. The image rendering module is used for rendering two-dimensional or three-dimensional images. The image synthesis module is used for synthesizing two-dimensional or three-dimensional images.
In a possible implementation manner, the application draws the image through the image drawing module, then renders the drawn image through the image rendering module, and then sends the rendered image to the buffer queue of the display synthesis process. Whenever the vsync signal arrives, a display synthesis process (e.g., surfaflinger) sequentially acquires one frame of image to be synthesized from the buffer queue, and then performs image synthesis through an image synthesis module.
The function library provides macros, type definitions, character string operation functions, mathematical calculation functions, input and output functions, and the like used in the C language.
The kernel layer is a layer between hardware and software. The kernel layer at least comprises a touch panel driver, an LCD/LED screen driver, a display driver, a Bluetooth driver, a WIFI driver, a keyboard driver, a shared memory driver, a camera driver, a sensor driver and the like.
The hardware can be an audio module, a Bluetooth module, a sensor module and the like.
In order to more clearly understand modules involved in the bluetooth loopback operation in the present application, a bluetooth part in an Android system architecture is split, and fig. 7 is a schematic structural diagram of a bluetooth architecture provided in an embodiment of the present application.
As shown in fig. 7, the bluetooth architecture includes a framework layer, a bluetooth process, a Java Native Interface (JNI) layer, a bluetooth protocol stack, a hardware abstraction layer interface definition language (HIDL) interface, and a bluetooth module.
Among them, the framework layer can be understood as a part related to the bluetooth loopback process in the application layer and the application framework layer shown in fig. 6, which includes an accessory management service application in the application layer, a power saving application, a bluetooth service in the application framework layer, and the like. The bluetooth process may be understood as a bluetooth application in the application layer shown in fig. 6, which includes a bluetooth profile and some management services, where the management services may include bluetooth upper layer services, Device management services, bluetooth peripheral control services, and the like, and the bluetooth upper layer services mainly include services related to Human Interface Devices (HIDs) such as headsets, keyboards, and mice.
The bluetooth protocol stack is code that implements the bluetooth protocol, providing the actual operation of bluetooth. The bluetooth protocol stack defines a plurality of applications (profiles) and core protocols (protocols) in the bluetooth framework, and each profile defines a respective corresponding message format and application rule. In order to achieve interconnection and interworking of different devices under different platforms, bluetooth protocols are defined in various possible and generally meaningful application scenarios, such as bluetooth audio transmission model agreement (A2 DP), hands-free protocols (HFP), and the like.
The HIDL interface defines the interface between the bluetooth protocol stack and the bluetooth module. And the bluetooth module defines the bottom hardware part, which includes Radio Frequency (RF), baseband (BB), Link Manager (LM), and the like.
Fig. 8 is a schematic flowchart of a bluetooth backhaul method according to an embodiment of the present application. Referring to fig. 8, the bluetooth loopback method may be applied to a terminal device, where the terminal device includes a bluetooth application, an accessory management service application, a bluetooth protocol stack, a bluetooth module, and the like, and the bluetooth module may also be referred to as a bluetooth chip, and the bluetooth loopback method may specifically include the following steps:
step 801, when the terminal device meets a preset condition, the bluetooth application executes a starting operation for a bluetooth function of the terminal device.
In some embodiments, the terminal device includes a power saving application, and when the terminal device 100 satisfies the first preset condition, in order to save power consumption of the terminal device 100, the power saving application in the terminal device 100 is set to a power saving mode, and the power saving application causes the bluetooth application to turn off the bluetooth function of the terminal device 100 according to the bluetooth function turning-off request by sending the bluetooth function turning-off request to the bluetooth application.
And when the terminal device 100 meets the second preset condition, the bluetooth application may execute an opening operation for the bluetooth function of the terminal device, that is, the bluetooth application may restart the bluetooth function, so that the bluetooth state of the bluetooth function sequentially passes through the off state, the TurningBleOn state, the BleOn state, and the TurningOn state to reach the on state.
After the bluetooth function of the terminal device is turned off, the adsorption state value of the terminal device defaults to be the second attribute value, and the second attribute value may be called false. Therefore, when the bluetooth application executes the start operation of the bluetooth function for the terminal device, the adsorption state value of the terminal device remains as the second attribute value.
The second preset condition may be the following two cases.
In one case, the second preset condition is that the system time of the terminal device reaches a second preset time. Therefore, when the system time of the terminal device reaches a second preset time, the power saving application sends a bluetooth function starting request to the bluetooth application by calling the bluetooth API included in the bluetooth service in the application framework layer so as to inform the bluetooth application that the bluetooth function of the terminal device needs to be started; after receiving the bluetooth function starting request sent by the power saving application, the bluetooth application executes the starting operation of the bluetooth function according to the bluetooth function starting request so as to start the bluetooth function of the terminal equipment.
For example, the second preset time is 05:00, and when the current system time of the terminal device reaches 05:00, the power saving application sends a bluetooth function activation request to the bluetooth application.
In another case, the second preset condition is that the cover opening of the terminal device and the bluetooth device is detected. The terminal equipment is also provided with a second sensor drive and cover opening and closing detection sensor; the cover opening and closing detection sensor is a sensor in the sensor module and is used for detecting the cover opening and closing states of the terminal equipment and the Bluetooth equipment, the cover opening and closing state can be an uncovering state or a covering state, and the cover opening and closing detection sensor can be a magnetic sensor 180D; the second sensor drive is one of the sensor drives of the inner core layer and is used for driving the cover opening and closing detection sensor to detect the cover opening and closing states of the terminal equipment and the Bluetooth equipment.
The second sensor drive can monitor the opening and closing state collected by the opening and closing cover detection sensor, and when the opening and closing state of the terminal device and the Bluetooth device is monitored to change, if the terminal device and the Bluetooth device change from the closing state to the opening state, the second sensor drive can report the opening and closing state collected by the opening and closing cover detection sensor to the Bluetooth application. When the Bluetooth application receives that the cover opening and closing state reported by the second sensor drive is the cover opening state, the Bluetooth application determines that the terminal device and the Bluetooth device are changed from the cover closing state to the cover opening state, and the Bluetooth application executes the opening operation of the Bluetooth function to open the Bluetooth function of the terminal device.
Step 802, in the process of starting the bluetooth function of the terminal device, the bluetooth application acquires the adsorption state of the bluetooth device.
In this embodiment of the application, when the bluetooth application switches the bluetooth function from the off state to the TurningOn state, the bluetooth application needs to acquire the adsorption state of the bluetooth device.
In some embodiments, when the bluetooth function enters the TurningOn state, the bluetooth application first starts the device management service; after the device management service is started, the device management service starts a Bluetooth peripheral control service; after the bluetooth peripheral control service is started, the bluetooth peripheral control service acquires the adsorption state of the bluetooth device.
Wherein, the terminal equipment also comprises a first sensor driving and adsorbing sensor. Specifically, the bluetooth peripheral control service sends an adsorption state acquisition instruction to the first sensor drive by calling a bluetooth API included in the bluetooth service in the application framework layer; the first sensor drive acquires the instruction according to the adsorption state, acquires the adsorption state of the Bluetooth equipment acquired by the adsorption sensor, wherein the adsorption state comprises an adsorbed state and an unadsorbed state, the adsorbed state refers to mutual adsorption between the terminal equipment and the Bluetooth equipment, and the unadsorbed state refers to non-adsorption between the terminal equipment and the Bluetooth equipment. Then, the first sensor driver reports the adsorption state of the Bluetooth equipment to the Bluetooth peripheral control service, and the Bluetooth peripheral control service receives the adsorption state reported by the sensor driver to acquire the adsorption state of the Bluetooth equipment.
Wherein, adsorb the sensor for whether detection terminal equipment adsorbs with bluetooth equipment, should adsorb the sensor and can be magnetic sensor 180D in the sensor module. The first sensor drive is one of the sensor drives of the inner core layer and is used for driving the adsorption sensor to detect whether the terminal equipment and the Bluetooth equipment are adsorbed or not.
In some embodiments, if both the open-close cover detection sensor and the suction sensor are the magnetic sensor 180D, the first sensor drive and the second sensor drive may be the same drive.
In step 803, when the attachment status of the bluetooth device is the attached status, the bluetooth application updates the attachment status value to the first attribute value.
In this embodiment of the application, when the bluetooth application acquires that the adsorption state of the bluetooth device is the adsorbed state, the bluetooth application updates the adsorption state value from the second attribute value to the first attribute value. The first attribute value may be referred to as true, and the first attribute value indicates that the terminal device and the bluetooth device are in an attached state.
Step 804, in the process of starting the bluetooth function of the terminal device, the bluetooth application sends a connection instruction back to the bluetooth protocol stack.
In this embodiment of the application, when the bluetooth application switches the bluetooth function from the off state to the TurningOn state, the bluetooth application further sends a connection instruction back to the bluetooth protocol stack through the JNI layer to notify the bluetooth protocol stack to initiate scanning according to the connection instruction, and connect back the paired bluetooth devices.
Wherein the bluetooth application includes a bluetooth upper layer service. When the Bluetooth function enters a TurningOn state, the Bluetooth application starts the Bluetooth upper layer service firstly, and the Bluetooth upper layer service sends a connection instruction back to the Bluetooth protocol stack through the JNI layer.
Step 805, the bluetooth protocol stack reads the adsorption state value after delaying the preset duration.
In the embodiment of the application, when the bluetooth protocol stack receives a loopback instruction sent by a bluetooth application, the adsorption state value is not read directly, but read after delaying for a preset time by calling a code Background _ connect _ add.
For example, the preset duration may be 200ms, and when the bluetooth protocol stack receives a loopback instruction sent by a bluetooth application, the adsorption state value is read after 200ms delay.
According to the embodiment of the application, the updating process of the adsorption state value is executed in the Bluetooth application in advance, so that the time consumption caused by starting the accessory management service application and monitoring the adsorption state of the Bluetooth equipment through the accessory management service application can be effectively reduced; and after receiving the connection-back instruction, the bluetooth protocol stack removes the process of directly reading the adsorption state value, and delays the time for reading the adsorption state value by the bluetooth protocol stack for a preset time. Therefore, the updating process of the adsorption state value is as early as possible than the process of reading the adsorption state value by the bluetooth protocol stack, and when the bluetooth protocol stack reads the adsorption state value, the bluetooth application finishes updating the adsorption state value, so that the adsorption state value read by the bluetooth protocol stack is the updated adsorption state value, that is, the adsorption state value read by the bluetooth protocol stack is the first attribute value.
It should be noted that step 802 and step 804 are executed synchronously, step 803 is executed after step 802, and step 805 to step 808 are executed in sequence after step 804.
In step 806, when the adsorption state value read by the bluetooth protocol stack is the first attribute value, the bluetooth protocol stack sends the first device identifier of the bluetooth device to the bluetooth module.
In this embodiment of the present application, the loopback instruction sent by the bluetooth application to the bluetooth protocol stack includes a first device identifier of the bluetooth device, where the first device identifier may be identification information such as a Media Access Control (MAC) address and a device model of the bluetooth device.
And when the adsorption state value read by the Bluetooth protocol stack is a first attribute value, the Bluetooth protocol stack extracts a first equipment identifier from the loop connection instruction, adds the first equipment identifier into a white list corresponding to the Bluetooth protocol stack, and sends the first equipment identifier to the Bluetooth module through the HIDL interface.
In step 807, the bluetooth module adds the first device identifier to a white list.
In this embodiment of the application, after the bluetooth module receives the first device identifier sent by the bluetooth protocol stack, the bluetooth module adds the first device identifier to a white list corresponding to the bluetooth module.
It should be noted that the bluetooth protocol stack and the bluetooth module have a white list respectively, and when the bluetooth protocol stack acquires a bluetooth device identifier, the bluetooth protocol stack adds the bluetooth device identifier to the white list of the bluetooth protocol stack, and in addition, the bluetooth protocol stack also sends the bluetooth device identifier to the bluetooth module, so that the bluetooth module adds the bluetooth device identifier to the white list of the bluetooth module.
And 808, the bluetooth module executes scanning operation according to the white list to connect the bluetooth device back.
In the embodiment of the application, after the bluetooth module adds the first device identifier to the white list, when at least one bluetooth device identifier exists in the white list, the bluetooth module executes a scanning operation; when the scanned broadcast message comprises a second device identifier matched with the first device identifier, the Bluetooth module initiates a connection back request to the Bluetooth device; the Bluetooth device receives the connection request and sends a response message to the Bluetooth module, wherein the response message indicates the Bluetooth device to establish Bluetooth connection with the terminal device again; and the Bluetooth module receives the response message sent by the Bluetooth equipment and enables the terminal equipment and the Bluetooth equipment to establish Bluetooth connection again according to the response message.
For example, the first device identifier is a1, after the bluetooth module adds the first device identifier to the white list, the bluetooth device identifiers existing in the white list corresponding to the bluetooth module are a1, a2, and A3, respectively, so that the white list corresponding to the bluetooth module is not empty, and therefore, the bluetooth module may perform a scanning operation, and when the scanned broadcast message includes the second device identifier a1, the bluetooth module initiates a connection back request to the bluetooth device, where the connection back request is used to connect back the bluetooth device with the second device identifier a 1.
The connection back of the terminal equipment and the Bluetooth equipment refers to the reconnection of the terminal equipment and the Bluetooth equipment after pairing. Because the Bluetooth protocol is followed between the Bluetooth equipment and the terminal equipment, the Bluetooth connection and information exchange are realized, and after the terminal equipment and the Bluetooth equipment are firstly paired and establish the Bluetooth connection, the terminal equipment can store the related information (such as a first equipment identifier) of the Bluetooth equipment, and the subsequent terminal equipment and the Bluetooth equipment do not need to be paired when establishing the Bluetooth connection again and are directly and automatically connected back.
In practical application, after the terminal device and the bluetooth device are closed and placed, the bluetooth device can stop sending the broadcast message, and after the terminal device and the bluetooth device are opened, the bluetooth device starts sending the broadcast message.
Therefore, when the bluetooth module determines that at least one bluetooth device identifier exists in the white list, the terminal device and the bluetooth device may be in an open state or a closed state at this time. If the terminal device and the Bluetooth device are in a cover closing state at the moment, the Bluetooth module can execute scanning operation all the time until the terminal device and the Bluetooth device are opened, and the Bluetooth module scans the broadcast message sent by the Bluetooth device.
In order to more clearly show the difference between the embodiment of the present application and the bluetooth connection method of the related art, fig. 9 is a flowchart of the bluetooth connection method provided in the embodiment of the present application, which may specifically include the following steps:
step 901, switching the bluetooth function of the terminal device from the off state to a TurningOn state.
Step 902, when the bluetooth function enters into TurningOn state, the bluetooth application starts the bluetooth upper layer service to send a connection instruction back to the bluetooth protocol stack through the bluetooth upper layer service.
And step 903, the Bluetooth protocol stack reads the adsorption state value after delaying the preset time according to the loop connection instruction.
And step 904, the bluetooth protocol stack determines whether the bluetooth device is adsorbed according to the read adsorption state value.
Step 905, when the bluetooth device is attached, the bluetooth protocol stack sends the first device identifier of the bluetooth device to the bluetooth module, so that the bluetooth module adds the first device identifier to a white list to reconnect the bluetooth device.
And step 906, when the Bluetooth device is not adsorbed, the Bluetooth protocol stack ignores the first device identification of the terminal device.
Step 907, when the bluetooth function enters into TurningOn state, the bluetooth application starts listening to the adsorption state of the bluetooth device.
Step 908, the bluetooth application detects whether the bluetooth device is attached.
When the bluetooth device is attached, the bluetooth application updates the attached status value to the first attribute value, step 909.
It should be noted that, in the above-mentioned implementation process, after the bluetooth function enters into TurningOn state, step 902 to step 906 and step 907 to step 909 are respectively implemented. When the bluetooth function is started, the terminal device tries to initiate a loopback based on the bluetooth protocol stack and the bluetooth module on the one hand, and starts adsorption state monitoring based on the bluetooth application on the other hand to update the adsorption state value, and the two are processed in parallel.
It can be seen that, in the related art shown in fig. 3, after receiving a loopback instruction sent by a bluetooth application, a bluetooth protocol stack directly reads an adsorption state value, when the read adsorption state value is a first attribute value, the adsorption state value is read again after delaying for a preset time, and when the adsorption state value read again is also the first attribute value, the bluetooth protocol stack sends a first device identifier to a bluetooth module to add to a white list. Therefore, when the bluetooth protocol stack reads the adsorption state value for the first time, it is highly likely that the read adsorption state value is the second attribute value.
In addition, in the related art shown in fig. 3, when the bluetooth application detects that the bluetooth device is attached, the accessory management service application is started to monitor the attachment state of the bluetooth device, and only when the bluetooth device is attached, the accessory management service application updates the attachment state value from the second attribute value to the first attribute value. Therefore, the number of the adsorption state values is large, and the time consumption is obviously increased, so that the adsorption state values read by the bluetooth protocol stack are likely to be the second attribute values.
When the adsorption state value read by the Bluetooth protocol stack is the second attribute value, the Bluetooth protocol stack cannot send the first equipment identifier to the Bluetooth module, so that the Bluetooth module cannot be connected with the Bluetooth equipment according to the first equipment identifier, and further the terminal equipment and the Bluetooth equipment cannot be automatically connected.
In fig. 9, the updating process of the adsorption state value is performed in advance in the bluetooth application according to the embodiment of the present application, and when the bluetooth application detects that the bluetooth device is adsorbed, the bluetooth application directly updates the adsorption state value from the second attribute value to the first attribute value, which can effectively reduce the time consumption caused by starting the accessory management service application and monitoring the adsorption state of the bluetooth device through the accessory management service application. In fig. 9, after receiving the loopback instruction, the bluetooth protocol stack removes the process of directly reading the adsorption state value, and delays the time for reading the adsorption state value by the bluetooth protocol stack by a preset time length, so that the adsorption state value read by the bluetooth protocol stack is the first attribute value.
That is to say, in the embodiment of the present application, the updating process of the adsorption state value is advanced, and the reading process of the adsorption state value is delayed, so that the updating process of the adsorption state value is earlier than the process of the bluetooth protocol stack reading the adsorption state value, when the bluetooth protocol stack reads the adsorption state value, the bluetooth application has updated the adsorption state value, so that the adsorption state value read by the bluetooth protocol stack is the first attribute value, thereby enabling the terminal device to automatically reconnect to the bluetooth device, and reducing the operation steps of the user.
In an optional implementation manner, when the bluetooth application in this embodiment detects that the bluetooth device is attached, the bluetooth application directly updates the attachment state value from the second attribute value to the first attribute value; and after receiving the reconnection instruction, the Bluetooth protocol stack directly reads the adsorption state value according to the reconnection instruction, and after the read adsorption state value is the first attribute value, the adsorption state value is read again after delaying the preset time length, and when the adsorption state value read again is also the first attribute value, the first equipment identifier is sent to the Bluetooth module.
That is to say, this application embodiment also can advance the update process of the adsorption state value, and does not change the reading process of the adsorption state value, and it also can make the update process of the adsorption state value earlier than the process that the bluetooth protocol stack reads the adsorption state value to a certain extent, and then makes the adsorption state value that the bluetooth protocol stack reads for the first time and the second time be the first attribute value.
In addition, in this embodiment of the application, when the bluetooth application detects that the adsorption state of the bluetooth device is the adsorbed state, the bluetooth application updates the adsorption state value to the first attribute value, and also starts an accessory management service application, and the accessory management service application starts monitoring on the adsorption state of the bluetooth device, and determines that the adsorption state of the bluetooth device changes.
For example, when the accessory management service application monitors that the adsorption state of the bluetooth device is changed from the adsorbed state to the non-adsorbed state, the accessory management service application controls the terminal device to be disconnected from the bluetooth device; and when the accessory management service application monitors that the adsorption state of the Bluetooth device is changed from the unadsorbed state to the adsorbed state again, the accessory management service application scans the adsorbed Bluetooth device to connect back to the Bluetooth device.
Fig. 10 is a schematic hardware structure diagram of a terminal device according to an embodiment of the present application. The terminal device 100 shown in fig. 10 includes: memory 101, processor 110, and communication interface 102, wherein memory 101, processor 110, communication interface 102 may communicate; illustratively, the memory 101, processor 110, and communication interface 102 may communicate via a communication bus.
The memory 101 may be a Read Only Memory (ROM), a static memory device, a dynamic memory device, or a Random Access Memory (RAM). The memory 101 may store computer programs, which are controlled by the processor 110 to execute, and the communication interface 102 to execute the communication, so as to implement the bluetooth backhaul method provided by the above-mentioned embodiment of the present application.
The processor 110 may be a general-purpose Central Processing Unit (CPU), a microprocessor, an Application Specific Integrated Circuit (ASIC), a graphics processor, or one or more integrated circuits.
The processor 110 may also be an integrated circuit chip having signal processing capabilities. In implementation, the functions of the bluetooth loopback method of the present application can be performed by instructions in the form of hardware integrated logic circuits or software in the processor 110. The processor 110 may also be a general purpose processor, a digital signal processor, an Application Specific Integrated Circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, and may implement or perform the methods, steps, and logic blocks disclosed in the embodiments of the present application below. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the methods disclosed in the embodiments below in connection with the present application may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory 101, and the processor 110 reads the information in the memory 101 and completes the functions of the bluetooth loopback method of the embodiment of the present application in combination with the hardware thereof.
The communication interface 102 in the chip may be an input/output interface, a pin or a circuit, etc.
The terminal device 100 of this embodiment may be correspondingly configured to perform the steps performed in the foregoing method embodiments, and the implementation principle and the technical effect are similar, which are not described herein again.
The embodiment of the application also provides a computer readable storage medium. The methods described in the above embodiments may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. If implemented in software, the functions may be stored on or transmitted over as one or more instructions or code on a computer-readable medium. Computer-readable media may include computer storage media and communication media, and may include any medium that can communicate a computer program from one place to another. A storage medium may be any target medium that can be accessed by a computer.
In one possible implementation, the computer-readable medium may include RAM, ROM, a compact disk read-only memory (CD-ROM) or other optical disk storage, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer. Also, any connection is properly termed a computer-readable medium. For example, if the 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 technologies such as infrared, radio, and microwave, then the coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of medium. Disk and disc, as used herein, includes disc, laser disc, optical disc, Digital Versatile Disc (DVD), floppy disk and blu-ray disc where disks usually reproduce data magnetically, while discs reproduce data optically with lasers. Combinations of the above should also be included within the scope of computer-readable media.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. The procedures or functions according to the embodiments of the present application are all or partially generated when the computer program instructions are loaded and executed on a computer. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored on a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (e.g., coaxial cable, fiber optic, digital subscriber line) or wirelessly (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
Embodiments of the present application are described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processing unit of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processing unit of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above embodiments are provided to explain the purpose, technical solutions and advantages of the present application in further detail, and it should be understood that the above embodiments are merely illustrative of the present application and are not intended to limit the scope of the present application, and any modifications, equivalent substitutions, improvements and the like made on the basis of the technical solutions of the present application should be included in the scope of the present application.

Claims (12)

1. A Bluetooth connection-back method is applied to a terminal device, wherein the terminal device comprises a Bluetooth application, a Bluetooth protocol stack and a Bluetooth module, and the method comprises the following steps:
in the process of starting the Bluetooth function of the terminal equipment, the Bluetooth application acquires the adsorption state of the Bluetooth equipment and sends a connection instruction back to the Bluetooth protocol stack;
when the adsorption state of the Bluetooth equipment is an adsorbed state, the Bluetooth application updates the adsorption state value to a first attribute value; the first attribute value represents that the terminal equipment and the Bluetooth equipment are in an absorbed state;
the Bluetooth protocol stack reads the adsorption state value according to the loop connection instruction;
and when the adsorption state value read by the Bluetooth protocol stack is the first attribute value, the Bluetooth protocol stack controls the Bluetooth module to execute scanning operation so as to connect the Bluetooth equipment back.
2. The method according to claim 1, wherein the bluetooth protocol stack reads the adsorption status value according to the loopback instruction, and comprises:
and when the Bluetooth protocol stack receives the reconnection instruction, the Bluetooth protocol stack reads the adsorption state value after delaying for a preset time.
3. The method of claim 1, wherein the loopback instruction comprises a first device identification of the Bluetooth device; the bluetooth protocol stack controls the bluetooth module to execute a scanning operation to loop back the bluetooth device, including:
the Bluetooth protocol stack sends the first equipment identification to the Bluetooth module;
the Bluetooth module adds the first equipment identification into a white list;
and the Bluetooth module executes scanning operation according to the white list so as to connect the Bluetooth equipment in a loop.
4. The method of claim 3, wherein the Bluetooth module performs a scanning operation to loop back to the Bluetooth device according to the white list, comprising:
when at least one Bluetooth device identification exists in the white list, the Bluetooth module executes scanning operation;
and when the scanned broadcast message comprises a second device identification matched with the first device identification, the Bluetooth module initiates a connection back request to the Bluetooth device to connect back the Bluetooth device.
5. The method of claim 1, wherein the bluetooth application comprises a device management service and a bluetooth peripheral control service; the bluetooth application acquires the adsorption state of the bluetooth device, including:
the Bluetooth application starts the equipment management service;
the equipment management service starts the Bluetooth peripheral control service;
the Bluetooth peripheral control service acquires the adsorption state of the Bluetooth equipment.
6. The method of claim 5, wherein the terminal device further comprises a first sensor drive and adsorption sensor; the bluetooth peripheral control service acquires the adsorption state of the bluetooth device, including:
the Bluetooth peripheral control service sends an adsorption state acquisition instruction to the first sensor drive;
the first sensor drive acquires an instruction according to the adsorption state, and acquires the adsorption state of the Bluetooth equipment acquired by the adsorption sensor; the adsorption state comprises an adsorbed state and an unadsorbed state;
and the Bluetooth peripheral control service receives the adsorption state reported by the first sensor drive.
7. The method of claim 1, wherein the bluetooth application comprises a bluetooth upper layer service; the sending a connection instruction back to the bluetooth protocol stack includes:
the Bluetooth application starts the Bluetooth upper layer service;
and the Bluetooth upper layer service sends a connection instruction back to the Bluetooth protocol stack.
8. The method of claim 1, wherein before the bluetooth application acquiring the adsorption status of the bluetooth device and sending a connection instruction back to the bluetooth protocol stack during the process of starting the bluetooth function of the terminal device, the method further comprises:
and when the terminal equipment meets a preset condition, the Bluetooth application executes the starting operation of the Bluetooth function of the terminal equipment.
9. The method of claim 8, wherein the terminal device further comprises a power saving application; when the terminal device meets the preset condition, the Bluetooth application executes the starting operation of the Bluetooth function of the terminal device, and the starting operation comprises the following steps:
when the system time of the terminal equipment reaches preset time, the power-saving application sends a Bluetooth function starting request to the Bluetooth application;
and the Bluetooth application executes the starting operation of the Bluetooth function aiming at the terminal equipment according to the Bluetooth function starting request.
10. The method of claim 8, wherein the terminal device further comprises a second sensor drive and open/close cover detection sensor; when the terminal device meets the preset condition, the Bluetooth application executes the starting operation of the Bluetooth function of the terminal device, and the starting operation comprises the following steps:
the second sensor drives the cover opening and closing state acquired by the cover opening and closing detection sensor to be reported to the Bluetooth application;
and when the cover opening and closing state is the cover opening state, the Bluetooth application executes opening operation aiming at the Bluetooth function of the terminal equipment.
11. A terminal device comprising a memory for storing a computer program and a processor for invoking the computer program to perform the bluetooth fallback method as claimed in any one of claims 1 to 10.
12. A computer-readable storage medium, having stored thereon a computer program or instructions which, when executed, implement the bluetooth fallback method as claimed in any one of claims 1 to 10.
CN202210131306.5A 2022-02-14 2022-02-14 Bluetooth reconnection method and terminal equipment Active CN114173315B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210131306.5A CN114173315B (en) 2022-02-14 2022-02-14 Bluetooth reconnection method and terminal equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210131306.5A CN114173315B (en) 2022-02-14 2022-02-14 Bluetooth reconnection method and terminal equipment

Publications (2)

Publication Number Publication Date
CN114173315A CN114173315A (en) 2022-03-11
CN114173315B true CN114173315B (en) 2022-06-14

Family

ID=80489850

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210131306.5A Active CN114173315B (en) 2022-02-14 2022-02-14 Bluetooth reconnection method and terminal equipment

Country Status (1)

Country Link
CN (1) CN114173315B (en)

Family Cites Families (20)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100544443C (en) * 2007-07-27 2009-09-23 中兴通讯股份有限公司 A kind of set-top-box system and method that realizes the IP communication
CN101634976B (en) * 2009-08-27 2012-02-29 中兴通讯股份有限公司 Method and terminal for providing Bluetooth function for computer
US8942632B2 (en) * 2012-08-28 2015-01-27 Qualcomm Incorporated Processor-independent communication of network availability
US9654906B2 (en) * 2014-06-12 2017-05-16 Samsung Electronics Co., Ltd Method for processing data based on bluetooth protocol and electronic device thereof
CN105846859B (en) * 2015-01-12 2019-05-24 芋头科技(杭州)有限公司 A kind of embedded OS realizes the system and method for Bluetooth slave devices function
CN205594864U (en) * 2016-04-08 2016-09-21 深圳卡尔拓客科技有限公司 Vehicle -mounted bluetooth control device and system
CN106412656B (en) * 2016-10-26 2019-08-06 四川长虹电器股份有限公司 The method that Android smart machine quickly connects bluetooth
WO2019090454A1 (en) * 2017-11-07 2019-05-16 深圳市汇顶科技股份有限公司 Bluetooth test system and method
CN109413626B (en) * 2018-10-08 2021-06-22 四川长虹电器股份有限公司 Automatic back-connection compatible method for white list and non-white list of remote Bluetooth equipment
EP3644661B1 (en) * 2018-10-26 2022-08-17 Google LLC A synchronization method for synchronizing clocks of a bluetooth device
CN115580854B (en) * 2019-04-16 2023-08-04 华为技术有限公司 Bluetooth scanning method and electronic equipment
CN112822663B (en) * 2019-10-31 2022-06-14 华为技术有限公司 Bluetooth connection method and related device
CN115442783A (en) * 2020-01-21 2022-12-06 华为技术有限公司 Bluetooth connection method, system and electronic equipment
CN111327933A (en) * 2020-02-18 2020-06-23 展讯通信(上海)有限公司 Equipment awakening method and device and electronic equipment
CN111447602B (en) * 2020-06-17 2020-09-29 成都极米科技股份有限公司 Bluetooth device, Bluetooth preemption method and device thereof, and computer-readable storage medium
US20230292379A1 (en) * 2020-07-20 2023-09-14 Lg Electronics Inc. Method and device for scanning for and connecting bluetooth device
CN112203132A (en) * 2020-11-13 2021-01-08 四川长虹电器股份有限公司 Method for quickly connecting Bluetooth remote controller during startup of android smart television
CN112839303B (en) * 2021-04-12 2021-08-31 荣耀终端有限公司 Method and related device for device reconnection
CN113543104B (en) * 2021-07-13 2023-10-24 深圳创维-Rgb电子有限公司 Bluetooth communication method, multimedia device and storage medium
CN113923641B (en) * 2021-12-07 2022-05-06 荣耀终端有限公司 Connection method and device

Also Published As

Publication number Publication date
CN114173315A (en) 2022-03-11

Similar Documents

Publication Publication Date Title
CN112399390B (en) Bluetooth connection method and related device
US20230049548A1 (en) Audio Output Method and Terminal Device
CN113497909B (en) Equipment interaction method and electronic equipment
CN113885759A (en) Notification message processing method, device, system and computer readable storage medium
US20230069398A1 (en) Method for Implementing Wi-Fi Peer-To-Peer Service and Related Device
CN110602686B (en) Method for using remote SIM module and electronic equipment
WO2022033296A1 (en) Bluetooth communication method, wearable device, and system
JP7234379B2 (en) Methods and associated devices for accessing networks by smart home devices
WO2022037480A1 (en) Task processing method and related electronic device
CN114500716A (en) Cooperative call method, apparatus, device, storage medium and program product
CN109495769B (en) Video communication method, terminal, smart television, server and storage medium
CN112789934B (en) Bluetooth service query method and electronic equipment
CN113727289A (en) Electronic equipment and communication method
CN114173315B (en) Bluetooth reconnection method and terminal equipment
CN114125805B (en) Bluetooth reconnection method and terminal equipment
CN115942253B (en) Prompting method and related device
CN114697438B (en) Method, device, equipment and storage medium for carrying out call by utilizing intelligent equipment
WO2024067170A1 (en) Device management method and electronic device
CN114006969B (en) Window starting method and electronic equipment
CN115515112A (en) Bluetooth communication method and system
CN114980045A (en) Bluetooth connection method and electronic equipment
CN117956371A (en) Audio service recovery processing method, electronic equipment and computer storage medium
CN117118970A (en) File downloading method and device
CN116264600A (en) Incoming call reminding method, electronic device and computer readable storage medium
CN116737258A (en) Method and related device for unloading application

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant