Concurrent write control method, concurrent write control device, and storage medium
By receiving response messages from Bluetooth devices and updating write flag information, the problem of applications being unable to distinguish between different Bluetooth devices during concurrent operation control is solved, ensuring the normal operation of Bluetooth devices and improving the user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING XIAOMI MOBILE SOFTWARE CO LTD
- Filing Date
- 2022-12-12
- Publication Date
- 2026-04-10
AI Technical Summary
In existing technologies, the concurrent operation control methods of Bluetooth devices cannot distinguish between different applications. As a result, when one application experiences a concurrent failure, other applications are also unable to operate the Bluetooth device normally, thus reducing the user experience.
By receiving the response message from the Bluetooth device, the application that sent the connection disconnection request is identified, and the write flag information of the Bluetooth device is updated according to the pre-stored connection configuration information to ensure that the Bluetooth device is in a write-allowed state when the writing application is the first application.
This feature enables timely updates to the write flag information when a Bluetooth device experiences a concurrent failure, ensuring that other applications can perform write operations normally and improving the user experience.
Smart Images

Figure CN116017775B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of terminal control technology, and more particularly to a concurrent write control method, concurrent write control device, and storage medium. Background Technology
[0002] Bluetooth Low Energy (BLE) technology has advantages such as shorter wireless startup time, faster connection establishment, and reduced peak power consumption during transmission and reception. It is widely used for data transmission between Bluetooth devices such as wireless headphones, wireless speakers, and smartwatches and terminal devices such as mobile phones and tablets.
[0003] After a terminal device establishes a connection with a Bluetooth device, multiple applications (APPs) within the terminal device can perform corresponding operations on the Bluetooth device (such as writing or reading data). Related technologies typically use a method of setting identification information for the Bluetooth device, and based on this identification information, control the concurrent operations of multiple APPs on the Bluetooth device. However, this concurrency control method does not differentiate between APPs using the Bluetooth device. This means that if one APP experiences a concurrency failure while using the Bluetooth device, other APPs that need to use the Bluetooth device will be unable to operate it, thus degrading the user experience. Summary of the Invention
[0004] To overcome the problems existing in related technologies, this disclosure provides a concurrent write control method, a concurrent write control device, and a storage medium.
[0005] According to a first aspect of the present disclosure, a concurrent write control method is provided, comprising:
[0006] Upon receiving a first response message from the target Bluetooth device in response to a connection disconnection request, the first application that sent the connection disconnection request is determined based on the first response message; wherein, the target Bluetooth device is any one of a plurality of Bluetooth devices connected to the terminal device;
[0007] Obtain the write flag information of the target Bluetooth device from the connection configuration information pre-stored in the terminal device;
[0008] When the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in a data writing state, determine whether the writing application currently performing the write operation on the target Bluetooth device is the first application;
[0009] If the application currently performing the write operation on the target Bluetooth device is the first application, the write flag information of the target Bluetooth device is updated, and the updated write flag information indicates that the target Bluetooth device is in a write-allowed state.
[0010] Optionally, the connection configuration information stores connection application information; wherein the connection application information at least includes a connection number of an application program in the terminal device that has a connection relationship with the target Bluetooth device; wherein the connection numbers corresponding to different application programs are different;
[0011] The write flag information of the target Bluetooth device is obtained from the connection configuration information pre-stored in the terminal device, including:
[0012] The connection application information of the target Bluetooth device is obtained from the connection configuration information;
[0013] Based on the connection number in the connection application information, it is determined whether there is a second application in the terminal device that has a connection relationship with the target Bluetooth device;
[0014] If there is the second application in the terminal device, the write flag information of the target Bluetooth device is obtained from the connection configuration information.
[0015] Optionally, the method comprises:
[0016] If there is no second application in the terminal device, the write flag information and the connection application information corresponding to the target Bluetooth device are deleted from the connection configuration information.
[0017] Optionally, the method comprises:
[0018] In response to a connection operation of any application program in the terminal device to the target Bluetooth device, a connection request is sent to the target Bluetooth device;
[0019] A second response message of the connection request returned by the target Bluetooth device is received, and the connection number is allocated to the application program;
[0020] Based on the first identification information of the target Bluetooth device carried by the second response message, it is determined whether the connection configuration information of the terminal device stores the write flag information corresponding to the first identification information;
[0021] If the connection configuration information does not store the write flag information corresponding to the first identification information, the write flag information corresponding to the target Bluetooth device is added in the connection configuration information, and the write flag information of the target Bluetooth device is initialized; wherein the write flag information after the initialization indicates that the target Bluetooth device is in the allowed write state.
[0022] Optionally, the method comprises:
[0023] If the connection configuration information stores the write flag information corresponding to the first identification information, the connection application information corresponding to the target Bluetooth device is updated based on the connection number of the application program.
[0024] Optionally, before the first response message returned by the target Bluetooth device in response to the connection disconnection request is received, the method comprises:
[0025] The write flag information of the target Bluetooth device is obtained from the connection configuration information of the terminal device, after a write operation of the first application for the target Bluetooth device is received;
[0026] Based on the write flag information of the target Bluetooth device, it is determined whether the target Bluetooth device is in the write-allowed state;
[0027] If the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the write-allowed state, a write request is sent to the target Bluetooth device;
[0028] And based on the connection number of the first application, the write flag information of the target Bluetooth device is updated; wherein the updated write flag information at least indicates that the target Bluetooth device is in the data write state, and the application currently performing the write operation on the target Bluetooth device is the first application.
[0029] Optionally, the method comprises:
[0030] After the first application completes the write operation on the target Bluetooth device, the write flag information of the target Bluetooth device is updated; wherein the updated write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the write-allowed state.
[0031] Optionally, the method comprises:
[0032] If the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the data write state, a prompt information of write failure is output.
[0033] According to a second aspect of the embodiments of the present disclosure, a concurrent write control device is provided, applied to a terminal device, comprising:
[0034] The first determination module is configured to receive a first response message returned by a target Bluetooth device in response to a connection disconnection request, and determine a first application sending the connection disconnection request based on the first response message; wherein the target Bluetooth device is any device in a plurality of Bluetooth devices connected by the terminal device;
[0035] obtain, from connection configuration information pre-stored by the terminal device, write flag information of the target Bluetooth device;
[0036] determine, when the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in a data write state, whether a write application currently performing a write operation on the target Bluetooth device is the first application;
[0037] update, when the write application currently performing the write operation on the target Bluetooth device is the first application, the write flag information of the target Bluetooth device, and the updated write flag information indicates that the target Bluetooth device is in an allowed write state.
[0038] Optionally, the connection configuration information stores connection application information; wherein the connection application information at least includes a connection number of an application program in the terminal device that has a connection relationship with the target Bluetooth device; wherein the connection numbers corresponding to different application programs are different;
[0039] The obtaining module is configured to:
[0040] obtain, from the connection configuration information, the connection application information of the target Bluetooth device;
[0041] determine, based on the connection number in the connection application information, whether there is a second application in the terminal device that has a connection relationship with the target Bluetooth device;
[0042] obtain, from the connection configuration information, the write flag information of the target Bluetooth device, if the terminal device has the second application.
[0043] Optionally, the obtaining module is configured to:
[0044] delete, from the connection configuration information, the write flag information and the connection application information corresponding to the target Bluetooth device, if the terminal device does not have the second application.
[0045] Optionally, the apparatus comprises a connection module configured to:
[0046] in response to a connection operation of any application program in the terminal device on the target Bluetooth device, send a connection request to the target Bluetooth device;
[0047] receive a second response message of the connection request returned by the target Bluetooth device, and assign the connection number to the application program;
[0048] determine, based on the first identification information of the target Bluetooth device carried in the second response message, whether the connection configuration information of the terminal device stores the write flag information corresponding to the first identification information;
[0049] If the connection configuration information does not store the write flag information corresponding to the first identification information, add the write flag information corresponding to the target Bluetooth device in the connection configuration information, and initialize the write flag information of the target Bluetooth device; wherein the write flag information after the initialization indicates that the target Bluetooth device is in the write-allowed state.
[0050] Optionally, the connection module is configured to:
[0051] If the connection configuration information stores the write flag information corresponding to the first identification information, update the connection application information corresponding to the target Bluetooth device based on the connection number of the application program.
[0052] Optionally, the device comprises a write module configured to:
[0053] receive the write operation of the first application on the target Bluetooth device, and obtain the write flag information of the target Bluetooth device from the connection configuration information of the terminal device;
[0054] determine, based on the write flag information of the target Bluetooth device, whether the target Bluetooth device is in the write-allowed state;
[0055] If the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the write-allowed state, send a write request to the target Bluetooth device;
[0056] and update the write flag information of the target Bluetooth device based on the connection number of the first application; wherein the updated write flag information at least indicates that the target Bluetooth device is in the data write state, and the application currently performing the write operation on the target Bluetooth device is the first application.
[0057] Optionally, the write module is configured to:
[0058] update the write flag information of the target Bluetooth device after the first application completes the write operation on the target Bluetooth device; wherein the updated write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the write-allowed state.
[0059] Optionally, the write module is configured to:
[0060] If the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the data write state, output prompt information of a write failure.
[0061] According to a third aspect of the embodiments of the present disclosure, a concurrent write control apparatus is provided, comprising:
[0062] a processor;
[0063] a memory for storing executable instructions;
[0064] The processor is configured to implement the steps in the concurrent write control method according to the first aspect of the embodiments of the present disclosure when executing the executable instructions stored in the memory.
[0065] According to a fourth aspect of the embodiments of the present disclosure, a non-transitory computer readable storage medium is provided, which, when the instructions in the storage medium are executed by a processor of a concurrent write control apparatus, enables the concurrent write control apparatus to perform the steps in the concurrent write control method according to the first aspect of the embodiments of the present disclosure.
[0066] The technical solutions provided by the embodiments of the present disclosure can include the following beneficial effects:
[0067] The embodiments of the present disclosure determine the first application that sends the connection disconnection request from a plurality of application programs of the terminal device after the terminal device receives the first response information returned by the target Bluetooth device, obtain the write flag information of the target Bluetooth device, and determine whether the write application currently performing the write operation on the target Bluetooth device is the first application when the write flag information indicates that the terminal device is in the data write state, to determine whether the write flag information of the target Bluetooth device is abnormal, and update the write flag information of the target Bluetooth device in time when the write application is the first application, i.e., the write flag information is abnormal, so that the updated write flag information can accurately indicate the current working state of the target Bluetooth device, so that the application programs in the terminal device can normally perform the write operation on the target Bluetooth device, and the user's use experience is improved.
[0068] It should be understood that the foregoing general description and the following detailed description are only exemplary and explanatory, and cannot limit the present disclosure. BRIEF DESCRIPTION OF DRAWINGS
[0069] The accompanying drawings, which are incorporated into and form part of the specification, illustrate embodiments consistent with the present disclosure and, together with the specification, serve to explain the principles of the present disclosure.
[0070] Figure 1 is a flowchart of a concurrent write control method according to an exemplary embodimentFigure 1 .
[0071] Figure 2 is a concurrent write control method according to an exemplary embodiment. Figure 2 .
[0072] Figure 3 is a structure diagram of a concurrent write control device according to an exemplary embodiment.
[0073] Figure 4 is a block diagram of a terminal device according to an exemplary embodiment. DETAILED DESCRIPTION
[0074] The exemplary embodiments will be described in detail herein below with reference to the drawings. When the following description refers to arrangements in the drawings, identical numbers on different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present invention. Instead, they are merely examples consistent with some aspects of the invention as detailed in the appended claims.
[0075] After the terminal device establishes a connection with the Bluetooth device, multiple application programs (APPs) in the terminal device can all perform corresponding operations (such as data writing or data reading, etc.) on the Bluetooth device; in order to reduce the concurrent operation of multiple APPs of the terminal device on the Bluetooth device, the related technology usually sets a flag bit for the Bluetooth device, when a certain APP (such as APP1) performs a corresponding operation on the Bluetooth device, the flag bit of the Bluetooth device is set as inaccessible, at this time, other APPs cannot perform operations on the Bluetooth device; when the APP1 completes the corresponding operation on the Bluetooth device, it will call a callback function to set the flag bit of the Bluetooth device as accessible, so as to facilitate other APPs to perform operations on the Bluetooth device, thereby reducing the concurrent operation conflict of the Bluetooth device.
[0076] But for some special use scenarios, for example, a Bluetooth device is connected with two APPs (APP1 and APP2) respectively, and the connection numbers of the two APPs are ConnectID1 and ConnectID2 respectively; when APP1 (or APP2) operates the Bluetooth device through the writeCharacteristic function, and disconnects the connection with the Bluetooth device immediately after calling the writeCharacteristic function, at this time, since the callback function onwriteCharacteristic is not called, the flag bit of the Bluetooth device always remains inaccessible, that is, the Bluetooth device has a concurrent fault; other APPs in the terminal device cannot perform corresponding operations on the Bluetooth device, even if APP1 (or APP2) connects the Bluetooth device again, the Bluetooth device cannot perform operations.
[0077] The embodiment of the present disclosure provides a concurrent write control method, as shown in Figure 1 Figure 1 is a flowchart of a concurrent write control method according to an example embodiment Figure 1 . The method comprises:
[0078] Step S101, receiving a first response message returned by a target Bluetooth device in response to a connection disconnection request, and determining a first application sending the connection disconnection request based on the first response message; wherein the target Bluetooth device is any device in a plurality of Bluetooth devices connected with the terminal device;
[0079] Step S102, obtaining write flag information of the target Bluetooth device from connection configuration information pre-stored in the terminal device;
[0080] Step S103, when the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in a data write state, determining whether a write application currently performing write operation on the target Bluetooth device is the first application;
[0081] Step S104, if the write application currently performing write operation on the target Bluetooth device is the first application, updating the write flag information of the target Bluetooth device, and the updated write flag information indicates that the target Bluetooth device is in an allowed write state.
[0082] The concurrent write control method shown in the embodiments of the present disclosure can be applied to any terminal device with Bluetooth function, which can be a smart phone, a tablet computer, a notebook computer or the like; the terminal device can simultaneously establish a communication connection with multiple Bluetooth devices, and the target Bluetooth device can be any one of the multiple Bluetooth devices connected with the terminal device. For example, the target Bluetooth device can be a wearable smart device such as a smart watch or a smart bracelet, or a smart home device such as a smart speaker or a smart gateway.
[0083] The first response message includes at least first identification information and second identification information.
[0084] The first identification information can be used to uniquely identify the target Bluetooth device; here, the first identification information can be device identification, a MAC address or the like of the target Bluetooth device.
[0085] The second identification information can be used to uniquely identify the first application, or based on the first identification information and the second identification information, the first application can be uniquely identified; here, the second identification information can be an application identification, an application name or the like of the first application.
[0086] The terminal device can include multiple application programs; if the multiple application programs need to interact with at least one Bluetooth device connected with the terminal device, the terminal device needs to establish a connection relationship between the application programs and the at least one Bluetooth device based on the communication connection.
[0087] For the same Bluetooth device, the Bluetooth device can establish a connection relationship with multiple different application programs in the terminal device; for the same application program, the application program can establish a connection relationship with multiple Bluetooth devices connected with the terminal device.
[0088] It can be understood that the connection relationship between different application programs and Bluetooth devices is independent of each other; any application program in the terminal device releases the connection relationship with a certain Bluetooth device, which will not affect the connection relationship between the application program and other Bluetooth devices, nor will it affect the connection relationship between other application programs in the terminal device and the Bluetooth device.
[0089] After receiving the first response message, the terminal device can determine the first application initiating the connection disconnection request and the target Bluetooth device returning the first response message based on the first identification information and the second identification information carried in the first response message.
[0090] The first application and the target Bluetooth device are connection objects of the target connection relationship requested to be released by the connection disconnection request.
[0091] It should be noted that after the terminal device receives the connection disconnection operation of the first application for the target Bluetooth device, the terminal device sends a connection disconnection request to the target Bluetooth device, so that the target Bluetooth device releases the connection relationship with the first application; and after the connection relationship is successfully released, the target Bluetooth device returns a first response message to the terminal device to notify the terminal device.
[0092] In step S102, the terminal device can store connection configuration information, which is used to record the communication configuration information of a plurality of Bluetooth devices connected by the terminal device.
[0093] The connection configuration information can include write flag information of a plurality of Bluetooth devices connected by the terminal device.
[0094] It should be noted that the connection configuration information can include first identification information of a plurality of Bluetooth devices connected by the terminal device and the write flag information of the plurality of Bluetooth devices, and the first identification information of the plurality of Bluetooth devices and the plurality of write flag information correspond one by one.
[0095] The write flag information corresponding to the first identification information can be determined from the connection configuration information based on the first identification information of the target Bluetooth device.
[0096] The write flag information is used to at least indicate the current working state of the Bluetooth device; the working state of the Bluetooth device can include an allowed write state and a data write state.
[0097] It should be noted that if the write flag information indicates that the Bluetooth device is in the allowed write state, it means that any application program in the terminal device that establishes a connection relationship with the Bluetooth device can perform a write operation on the Bluetooth device at this time; if the Bluetooth device is in the data write state, it means that an application program is currently performing a write operation on the Bluetooth device, and other application programs in the terminal device cannot perform a write operation on the Bluetooth device.
[0098] It can be understood that by using the write flag information of the Bluetooth device, the occurrence of concurrent write conflicts of the Bluetooth device can be reduced.
[0099] After the terminal device determines the write flag information corresponding to the target Bluetooth device, the terminal device can determine the current working state of the target Bluetooth device based on the write flag information.
[0100] In step S103, if the write flag information indicates that the target Bluetooth device is in the data write state, a write application currently performing a write operation on the target Bluetooth device can be determined from a plurality of application programs of the terminal device based on the write flag information.
[0101] Here, the write flag information can be used to indicate a write device performing the write operation on the target Bluetooth device in the data write state.
[0102] After determining the write application, it can be determined whether the write flag information of the target Bluetooth device is abnormal by determining whether the write application is the first application sending the connection disconnection request.
[0103] It should be noted that, in the process of the application program performing the write operation on the Bluetooth device, if the application program has not called the callback function corresponding to the write operation to change the write flag information of the Bluetooth device, the application program has disconnected the communication connection with the Bluetooth device, at this time, even if there is no application program performing the write operation on the Bluetooth device, the write flag information of the Bluetooth device still indicates that the Bluetooth device is in the data write state, that is, the write flag information of the Bluetooth device is abnormal, and cannot accurately indicate the current working state of the Bluetooth device, so that any application program in the terminal device cannot perform the write operation on the Bluetooth device.
[0104] It can be understood that, if the write application is the first application sending the connection disconnection request, it indicates that the write flag information of the target Bluetooth device has not been changed in time before the first application disconnects the communication connection with the target Bluetooth device, and the write flag information of the target Bluetooth device is abnormal.
[0105] If the write application is not the first application sending the connection disconnection request, it indicates that there is currently another application program performing the write operation on the target Bluetooth device, and the write flag information of the target Bluetooth device is not abnormal.
[0106] In step S104, if it is determined that the write application is the first application, that is, the write flag information of the target Bluetooth device is abnormal, the write flag information corresponding to the target Bluetooth device can be updated, so that the updated write flag information indicates that the target Bluetooth device is in the write-allowed state, so that the application program in the terminal device can normally perform the write operation on the target Bluetooth device.
[0107] It can be understood that, in the embodiment of the present disclosure, when it is determined that the write flag information of the target Bluetooth device is abnormal, the write flag information of the target Bluetooth device is updated in time, so that the updated write flag information can accurately indicate the current working state of the target Bluetooth device, so as not to affect the write operation of any application program in the terminal device on the target Bluetooth device.
[0108] The embodiments of the present disclosure determine the first application sending the connection disconnection request from a plurality of application programs of the terminal device after the terminal device receives the first response information returned by the target Bluetooth device; acquire the write flag information of the target Bluetooth device, and determine whether the write application currently performing the write operation on the target Bluetooth device is the first application when the write flag information indicates that the terminal device is in a data write state, to determine whether the write flag information of the target Bluetooth device is abnormal; and when the write application is the first application, that is, the write flag information is abnormal, the write flag information of the target Bluetooth device is updated in time, so that the updated write flag information can accurately indicate the current working state of the target Bluetooth device, so that the application programs in the terminal device can normally perform the write operation on the target Bluetooth device, and the user experience is improved.
[0109] Optionally, the connection configuration information stores connection application information; wherein the connection application information at least includes a connection number of an application program in the terminal device having a connection relationship with the target Bluetooth device; wherein the connection numbers corresponding to different application programs are different;
[0110] The write flag information of the target Bluetooth device is acquired from the connection configuration information pre-stored in the terminal device, including:
[0111] The connection application information of the target Bluetooth device is acquired from the connection configuration information;
[0112] Based on the connection number in the connection application information, it is determined whether there is a second application in the terminal device having a connection relationship with the target Bluetooth device;
[0113] If there is the second application in the terminal device, the write flag information of the target Bluetooth device is acquired from the connection configuration information.
[0114] In the embodiments of the present disclosure, the connection configuration information can include connection application information of a plurality of Bluetooth devices connected by the terminal device; it should be noted that the connection application information and the first identification information of the Bluetooth device one-to-one correspond;
[0115] It can be understood that the terminal device can simultaneously establish a connection relationship with a plurality of Bluetooth devices, and the connection configuration information stores the connection application information corresponding to the plurality of Bluetooth devices.
[0116] The connection application information of the target Bluetooth device at least includes a connection number of an application program in the terminal device having a connection relationship with the target Bluetooth device;
[0117] The connection number is a number allocated by the Bluetooth device to the application when the Bluetooth device establishes a connection relationship with the application. It can be understood that the connection numbers of different applications connected with the same Bluetooth device are different, but the connection numbers allocated by different Bluetooth devices to the same application can be the same or different.
[0118] It can be understood that the connection number can be the second identification information; based on the connection number, the first application can be uniquely determined from the multiple applications in the terminal device that have established a connection relationship with the target Bluetooth device.
[0119] Therefore, after receiving the first response message, the terminal device can determine the connection application information corresponding to the first identification information of the target Bluetooth device from the connection configuration information based on the first identification information of the target Bluetooth device carried in the first response message; and determine whether there is a second application in the terminal device that has established a connection relationship with the target Bluetooth device according to the connection number stored in the connection application information of the target Bluetooth device.
[0120] If the connection application information of the target Bluetooth device stores multiple connection numbers, it can be determined that there is at least one second application in the terminal device that has established a connection relationship with the target Bluetooth device.
[0121] It can be understood that, since there is at least one second application in the terminal device that has established a connection relationship with the target Bluetooth device, the disconnection of the connection relationship between the target Bluetooth device and the first application will not affect the connection relationship between the at least one second application and the target Bluetooth device, and the at least one second application can still interact with the target Bluetooth device.
[0122] At this time, the terminal device can delete the connection number corresponding to the first application from the connection application information of the target Bluetooth device, so that after the connection relationship between the target Bluetooth device and the multiple applications of the terminal device changes, the connection application information of the target Bluetooth device is updated in time, so that the connection application information can accurately reflect the connection relationship between the multiple applications in the terminal device and the target Bluetooth device.
[0123] After determining that at least one second application in the terminal device has a connection relationship with the target Bluetooth device, the terminal device can acquire the write flag information of the target Bluetooth device, and when the write flag information indicates that the target Bluetooth device is in a data write state, determine whether the write application currently performing the write operation on the target Bluetooth device is the first application, that is, determine whether the write flag information of the target Bluetooth device is abnormal; so that when the write flag information of the target Bluetooth device is abnormal, the write flag information of the target Bluetooth device is updated in time, and the write operation of the second application in the terminal device on the target Bluetooth device is not affected.
[0124] The embodiments of the present disclosure can acquire the connection application information of the target Bluetooth device after the terminal device receives the connection disconnection request sent by the target Bluetooth device, determine whether there is a second application in the terminal device that has a connection relationship with the target Bluetooth device based on the connection application information, and when it is determined that the terminal device has the second application, acquire the write flag information of the target Bluetooth device and determine whether the write flag information is abnormal, so as to reduce the case that the normal write operation of the second application on the target Bluetooth device is affected due to the write flag information not being updated in time before the first application releases the connection relationship with the target Bluetooth device during the write operation of the first application on the target Bluetooth device, and improve the user experience.
[0125] Optionally, the method comprises:
[0126] If there is no second application in the terminal device, the write flag information and the connection application information corresponding to the target Bluetooth device are deleted from the connection configuration information.
[0127] In the embodiments of the present disclosure, if the connection application information of the target Bluetooth device only stores the connection number of the first application, it can be determined that there is no second application in the terminal device that has a connection relationship with the target Bluetooth device.
[0128] It can be understood that there is only one application program (that is, the first application) in the terminal device that has a connection relationship with the target Bluetooth device, and when the connection relationship between the target Bluetooth device and the first application is released, since there is no second application in the terminal device that has a connection relationship with the target Bluetooth device, no matter whether the write flag information of the target Bluetooth device is abnormal, there is no application program in the terminal device that performs data interaction with the target Bluetooth device.
[0129] Based on this, the terminal device can delete the write flag information corresponding to the target Bluetooth device and the connection application information from the connection configuration information after determining that the second application does not have a connection relationship with the target Bluetooth device.
[0130] The embodiments of the present disclosure simplify the processing procedure and improve the user experience by obtaining the connection application information of the target Bluetooth device after the terminal device receives the connection disconnection request sent by the target Bluetooth device, determining whether there is a second application in the terminal device that has a connection relationship with the target Bluetooth device based on the connection application information, and directly deleting the write flag information corresponding to the target Bluetooth device and the connection application information in the connection configuration information when it is determined that the terminal device does not have the second application, i.e., no application program in the terminal device has a connection relationship with the target Bluetooth device, without further confirming whether the write flag information is abnormal.
[0131] Optionally, the method comprises:
[0132] In response to a connection operation of any application program in the terminal device to the target Bluetooth device, sending a connection request to the target Bluetooth device;
[0133] Receiving a second response message of the connection request returned by the target Bluetooth device, and allocating the connection number to the application program;
[0134] Based on the first identification information of the target Bluetooth device carried in the second response message, determining whether the connection configuration information of the terminal device stores the write flag information corresponding to the first identification information;
[0135] If the connection configuration information does not store the write flag information corresponding to the first identification information, adding the write flag information corresponding to the target Bluetooth device in the connection configuration information, and initializing the write flag information of the target Bluetooth device; wherein the initialized write flag information indicates that the target Bluetooth device is in the write-allowed state.
[0136] In the embodiments of the present disclosure, the terminal device receives a connection operation of any application program in the terminal device to the target Bluetooth device, and in response to the connection operation, the terminal device sends a connection request to the target Bluetooth device;
[0137] It should be noted that after the target Bluetooth device receives the connection request, the target Bluetooth device can establish a connection relationship with the application program indicated by the connection request. If the connection relationship is successfully established, the target Bluetooth device returns a second response message of the connection request to the terminal device to notify the terminal device. If the connection relationship fails to be established or the target Bluetooth device does not receive the connection request, the target Bluetooth device does not return the second response message to the terminal device.
[0138] Within a preset time period after sending the connection request, if the terminal device receives the second response message of the connection request returned by the target Bluetooth device, it indicates that the target Bluetooth device has successfully established a connection relationship with the application program, and the terminal device can assign a connection number to the application program.
[0139] Here, the second response message can carry first identification information of the target Bluetooth device. The terminal device can assign a connection number to the application program based on the first identification information of the target Bluetooth device, so that the application program can be uniquely determined based on the first identification information and the connection number.
[0140] If the terminal device does not receive the second response message within the preset time period, it indicates that the target Bluetooth device fails to establish a connection relationship with the application program, and the terminal device can resend the connection request to the target Bluetooth device.
[0141] Here, the preset time period can be set according to actual conditions, for example, the preset time period can be set to 3 minutes, 5 minutes, etc. The embodiments of the present disclosure do not limit this.
[0142] In some embodiments, if the terminal device resends the connection request to the target Bluetooth device a preset number of times, the terminal device outputs a connection failure prompt.
[0143] It can be understood that if the terminal device continuously sends multiple connection requests to the target Bluetooth device and does not receive the second response message of the target Bluetooth device, it indicates that the target Bluetooth device cannot establish a connection relationship with the application program. At this time, the terminal device outputs a connection failure prompt to prompt the user that the target Bluetooth device currently cannot establish a connection relationship with the application program.
[0144] After assigning the connection number to the application program, the terminal device can obtain pre-stored connection configuration information, and determine whether the first identification information corresponding to the write flag information is stored in the connection configuration information based on the first identification information of the target Bluetooth device.
[0145] It should be noted that the connection configuration information can include: first identification information of a plurality of Bluetooth devices connected by the terminal device and write flag information of the plurality of Bluetooth devices; and the plurality of first identification information and the plurality of write flag information correspond one by one.
[0146] By determining whether the write flag information corresponding to the first identification information is stored in the connection configuration information, it can be determined whether at least one other application program in the terminal device has established a connection relationship with the target Bluetooth device.
[0147] If the write flag information corresponding to the first identification information is not stored in the connection configuration information, it means that no other application program in the terminal device has established a connection relationship with the target Bluetooth device.
[0148] At this time, in order to facilitate the terminal device to accurately obtain the working state of the target Bluetooth device in the subsequent data interaction process, the terminal device can set the write flag information corresponding to the target Bluetooth device in the connection configuration information.
[0149] It can be understood that the terminal device can store the first identification information of the target Bluetooth device in the connection configuration information, and add a write flag information corresponding to the first identification information. The write flag information corresponding to the first identification information is initialized to indicate that the target Bluetooth device is in the write-allowed state.
[0150] In addition, the terminal device can add a connection application information corresponding to the first identification information, and add the connection number of the application program to the connection application information corresponding to the first identification information, so that the application program connected by the target Bluetooth device and the number of the application program can be determined according to the connection number in the connection application information corresponding to the first identification information in the subsequent process.
[0151] The embodiments of the present disclosure allocate a connection number to each application program that has established a connection relationship with the target Bluetooth device, so as to distinguish a plurality of application programs connected by the target Bluetooth device according to the connection number; determine whether the write flag information corresponding to the target Bluetooth device is stored in the connection configuration information, add the write flag information of the target Bluetooth device when the write flag information corresponding to the target Bluetooth device is not stored in the connection configuration information, and initialize the write flag information, so that the terminal device can obtain the working state of the target Bluetooth device based on the write flag information of the target Bluetooth device in the subsequent data interaction process between the target Bluetooth device and at least one application program in the terminal device, and reduce the occurrence of concurrent write conflicts of the target Bluetooth device.
[0152] Optionally, the method comprises:
[0153] If the connection configuration information stores the write flag information corresponding to the first identification information, the connection application information corresponding to the target Bluetooth device is updated based on the connection number of the application program.
[0154] In the embodiments of the present disclosure, the terminal device determines that the connection configuration information stores the write flag information corresponding to the first identification information, which indicates that the terminal device has already established a connection relationship with the target Bluetooth device by another application program;
[0155] At this time, the terminal device can add the connection number allocated for the application program to the connection application information corresponding to the first identification information, so that the application program connected to the target Bluetooth device and the number of the application program can be determined according to the connection number in the connection application information corresponding to the first identification information in the subsequent process.
[0156] It should be noted that the process of establishing and releasing the connection relationship between the target Bluetooth device and an application program is independent of the process of the write operation between the target Bluetooth device and other application programs; that is, while the application program 1 performs the write operation on the target Bluetooth device, the target Bluetooth device can also establish or release the connection relationship with the application program 2.
[0157] Since the connection configuration information already stores the write flag information corresponding to the first identification information, that is, the terminal device has already established a connection relationship with the target Bluetooth device by another application program, in order to reduce the influence of the write operation between the target Bluetooth device and other application programs on the establishment of the connection relationship between the target Bluetooth device and the application program indicated by the connection request, after receiving the second response message and determining that the connection configuration information stores the write flag information corresponding to the first identification information carried in the second response message, the terminal device only updates the connection application information corresponding to the first identification information, without performing any processing on the write flag information corresponding to the first identification information.
[0158] Optionally, before receiving the first response message returned by the target Bluetooth device in response to the connection disconnection request, the method comprises:
[0159] After receiving the write operation of the first application on the target Bluetooth device, the write flag information of the target Bluetooth device is obtained from the connection configuration information of the terminal device;
[0160] Based on the write flag information of the target Bluetooth device, it is determined whether the target Bluetooth device is in the write-allowed state.
[0161] if the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the write-allowed state, sending a write request to the target Bluetooth device;
[0162] and updating the write flag information of the target Bluetooth device based on the connection number of the first application; wherein the updated write flag information indicates at least that the target Bluetooth device is in the data write state and the application currently performing the write operation on the target Bluetooth device is the first application.
[0163] In the embodiments of the present disclosure, after receiving the write operation of the first application on the target Bluetooth device, the terminal device obtains the write flag information corresponding to the first identification information of the target Bluetooth device from the connection configuration information in response to the write operation;
[0164] Based on the write flag information of the target Bluetooth device, it is determined whether the target Bluetooth device is in the write-allowed state;
[0165] Here, the write flag information can include a write flag value. It can be understood that different write flag values can be used to indicate different working states of the target Bluetooth device.
[0166] The terminal device can obtain the write flag value of the target Bluetooth device, and determine whether the target Bluetooth device is in the write-allowed state by determining whether the write flag value of the target Bluetooth device is a preset flag value.
[0167] Here, the preset flag value can be set according to actual conditions, for example, the preset flag value is -1.
[0168] When the write flag value of the target Bluetooth device is the preset flag value (such as -1), it is determined that the target Bluetooth device is in the write-allowed state; if the write flag value of the target Bluetooth device is not the preset flag value (such as -1), it is determined that the target Bluetooth device is in the data write state.
[0169] When the terminal device determines that the target Bluetooth device is in the write-allowed state, it can send a write request to the target Bluetooth device based on the write operation; and in order to reduce the occurrence of concurrent write conflicts of the target Bluetooth device in the process of the first application performing the write operation on the target Bluetooth device, the embodiments of the present disclosure can update the write flag information of the target Bluetooth device.
[0170] Here, the terminal device can obtain the connection number of the first application, and set the write flag value of the target Bluetooth device to the connection number of the first application.
[0171] It can be understood that, by updating the write flag value of the target Bluetooth device based on the connection number of the application after the terminal device sends a write request of the application to the target Bluetooth device, the terminal device can determine the specific application currently performing the write operation on the target Bluetooth device according to the write flag value of the target Bluetooth device; and when the terminal device receives a connection disconnection request and the target Bluetooth device is in the data write state, the terminal device can determine whether the write application currently performing the write operation on the target Bluetooth device is the application indicated by the connection disconnection request according to the write flag value, that is, whether the write flag information of the target Bluetooth device is abnormal.
[0172] In an aspect, the write flag information of the target Bluetooth device is acquired after the terminal device receives a write operation of a first application on the target Bluetooth device, the working state of the target Bluetooth device is determined according to the write flag information, and when the write flag information indicates that the target Bluetooth device is in the allowed write state, a write request is sent to the target Bluetooth device, and the write flag information is updated in time, so that the updated write flag information indicates that the target Bluetooth device is in the data write state, thereby stopping the terminal device from sending a write request of another application to the target Bluetooth device when the first application performs a write operation on the target Bluetooth device, and reducing the concurrent write conflict of the target Bluetooth device.
[0173] In another aspect, in the present disclosure, the terminal device updates the write flag information by using the connection number of the first application, so that the updated write flag information can indicate the write application currently performing the write operation on the target Bluetooth device, thereby enabling the terminal device to determine whether the write application is the application indicated by the connection disconnection request according to the write flag information after receiving the connection disconnection request, and further determine whether the write flag information of the target Bluetooth device is abnormal.
[0174] Optionally, the method comprises:
[0175] After the first application completes the write operation on the target Bluetooth device, the write flag information of the target Bluetooth device is updated; wherein the updated write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the allowed write state.
[0176] In the embodiments of the present disclosure, after the terminal device detects that the first application has completed the write operation on the target Bluetooth device, in order to facilitate other application programs in the terminal device to be able to perform the write operation on the target Bluetooth device, the terminal device can update the write flag information of the target Bluetooth device, so that the updated write flag information indicates that the target Bluetooth device is in the write-allowed state.
[0177] Here, after completing the write operation on the target Bluetooth device, the first application can change the write flag value of the target Bluetooth device by calling the callback function corresponding to the write operation, and change the write flag value of the target Bluetooth device from the connection number of the first application to the preset flag value by using the callback function.
[0178] The embodiments of the present disclosure update the write flag information of the target Bluetooth device in a timely manner after detecting that the first application completes the write operation on the target Bluetooth device, so as to facilitate other application programs in the terminal device to continue to perform the write operation on the target Bluetooth device.
[0179] Optionally, the method comprises:
[0180] If the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the data write state, outputting prompt information of write failure.
[0181] In the embodiments of the present disclosure, the terminal device acquires the write flag information of the target Bluetooth device, and if the write flag information indicates that the target Bluetooth device is in the data write state, in order to reduce the concurrent write conflict of the target Bluetooth device, the terminal device can output prompt information of write failure to the user through the display interface of the first application.
[0182] Here, the terminal device can acquire the write flag value of the target Bluetooth device, and output prompt information of write failure to the user by determining whether the write flag value of the target Bluetooth device is a preset flag value.
[0183] In the embodiments of the present disclosure, when the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the data write state, prompt information of write failure is directly output to the user without sending a write request to the target Bluetooth device, so as to reduce the concurrent write conflict of the target Bluetooth device and improve the user experience.
[0184] The present disclosure also provides the following embodiments:
[0185] Figure 2 is a flowchart of a concurrent write control method according to an exemplary embodiment Figure 2The method comprises:
[0186] In step S201, a connection request is sent to the target Bluetooth device in response to a connection operation of any application program in the terminal device to the target Bluetooth device; a second response message of the connection request returned by the target Bluetooth device is received, and the connection number is allocated to the application program;
[0187] After the terminal device receives a connection operation of any application program to the target Bluetooth device, a connection request is sent to the target Bluetooth device to request to establish a connection relationship between the application program and the target Bluetooth device, and after receiving the second response message of the target Bluetooth device, the connection number (ConnectID) is allocated to the application program.
[0188] It should be noted that since one Bluetooth device can be connected by multiple application programs in the terminal device and used by multiple application programs, in order to distinguish the application programs using the Bluetooth device, a ConnectID can be allocated to each application program connected with the Bluetooth device. It can be understood that the ConnectIDs of multiple different application programs connected with the same Bluetooth device are different.
[0189] In step S202, whether the first identification information of the target Bluetooth device carried in the second response message is stored in the write flag information corresponding to the first identification information in the connection configuration information of the terminal device is determined.
[0190] It should be noted that the communication connection between the terminal device and the target Bluetooth device can perform data transmission based on a generic attribute (Generic Attributes, GATT) communication protocol.
[0191] The database defined by the GATT includes multiple GATT services, and the embodiment of the present disclosure increases the mPermits connection configuration information in the GATT service; the mPermits is used to represent a write application currently performing a write operation on a certain Bluetooth device.
[0192] The specific code is as follows:
[0193] {
[0194] private final HashMap<String, Integer> mPermits = new HashMap<>();
[0195] }
[0196] The first parameter of the mPermits write flag service indicates the MAC address of the Bluetooth device, and is used to distinguish a plurality of different Bluetooth devices connected by the terminal device; the second parameter indicates the ConnectID of the application program in the terminal device that has a connection relationship with the Bluetooth device.
[0197] When any application program in the terminal device successfully establishes a connection relationship with the target Bluetooth device, the onConnected function is called, wherein the onConnected function includes the MAC address of the target Bluetooth device and the ConnectID of the application program.
[0198] The write flag information corresponding to the MAC address of the target Bluetooth device can be queried in the mPermits.
[0199] In step S203, if the write flag information corresponding to the first identification information is not stored in the connection configuration information, the write flag information corresponding to the target Bluetooth device is added in the connection configuration information, and the write flag information of the target Bluetooth device is initialized and set.
[0200] The initialized write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the write permission state.
[0201] In the embodiment of the present disclosure, if the mPermits does not store the write flag information corresponding to the MAC address, the write flag information of the target Bluetooth device is added, and the write flag information is initialized and processed.
[0202] Here, the initial value of the write flag information of the target Bluetooth device can be set by calling the putIfAbsent function.
[0203] The specific code is as follows:
[0204] {
[0205] mPermits.putIfAbsent(address,-1);
[0206] }
[0207] Here, the initial value of the write flag information of the target Bluetooth device can be set to -1, indicating that no ConnectID currently performs the WriteCharacteristic operation on the target Bluetooth device.
[0208] Step S204: If the connection configuration information stores the write flag information corresponding to the first identification information, update the connection application information corresponding to the target Bluetooth device based on the connection number of the application.
[0209] In this embodiment of the disclosure, if mPermits does not store write flag information corresponding to the MAC address, then no processing is required on the write flag information of the target Bluetooth device.
[0210] Step S205: Upon receiving a write operation from the first application for the target Bluetooth device, obtain the write flag information of the target Bluetooth device from the connection configuration information of the terminal device; based on the write flag information of the target Bluetooth device, determine whether the target Bluetooth device is in the write-allowed state;
[0211] In this embodiment of the disclosure, when a terminal device receives a write operation on the target Bluetooth device from any of the multiple applications that have established a connection with the target Bluetooth device, it can obtain the write flag information of the target Bluetooth device from mPermits and determine whether the write flag information of the target Bluetooth device is -1.
[0212] Step S206: If the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the data writing state, output a write failure prompt message; if the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the write-allowed state, send a write request to the target Bluetooth device; and update the write flag information of the target Bluetooth device based on the connection number of the first application.
[0213] Here, the updated write flag information at least indicates that: the target Bluetooth device is in the data writing state, and the application currently performing the write operation on the target Bluetooth device is the first application;
[0214] If the write flag information of the target Bluetooth device is equal to -1, it indicates that a write operation can be performed on the target Bluetooth settings. Then, the ConnectID of the first application is set into the write flag information of the target Bluetooth device, indicating that the write operation of the target Bluetooth device is occupied by this ConnectID. If the write flag information of the target Bluetooth device is not equal to -1, it indicates that another ConnectID is currently operating on the target Bluetooth device. At this time, a write failure prompt message, namely BluetoothStatusCodes.ERROR_GATT_WRITE_REQUEST_BUSY, can be returned to the first application.
[0215] The specific code is as follows:
[0216]
[0217]
[0218] Step S207, after the first application completes the write operation on the target Bluetooth device, updating the write flag information of the target Bluetooth device;
[0219] Wherein, the updated write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the write-allowed state.
[0220] In the embodiments of the present disclosure, after the first application completes the write operation on the target Bluetooth device, the callback function onWriteCharacteristic is called to set the write flag information of the target Bluetooth device to -1, indicating that the previous write operation of the target Bluetooth device has been completed, and the write operation on the target Bluetooth device can continue.
[0221] The specific code is as follows:
[0222]
[0223] Step S208, receiving the first response message returned by the target Bluetooth device in response to the connection disconnection request, determining the first application sending the connection disconnection request based on the first response message; obtaining the connection application information of the target Bluetooth device from the connection configuration information; based on the connection number in the connection application information, determining whether there is a second application in the terminal device that has a connection relationship with the target Bluetooth device;
[0224] In the embodiments of the present disclosure, after the terminal device receives the connection disconnection operation of the first application on the target Bluetooth device, the terminal device sends a connection disconnection request to the target Bluetooth device to request to release the connection relationship between the first application and the target Bluetooth device.
[0225] When the first application releases the connection relationship with the target Bluetooth device, the callback function onDisconnected is triggered, and whether the target Bluetooth device is still connected to other connectId is determined to perform different processing on the write flag information of the target Bluetooth device.
[0226] Step S209, if the terminal device has the second application, obtaining the write flag information of the target Bluetooth device from the connection configuration information; when the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the data write state, determining whether the write application currently performing the write operation on the target Bluetooth device is the first application;
[0227] In the embodiment of the present disclosure, if it is determined that the target Bluetooth device is also connected with other connectId, write flag information of the target Bluetooth device is acquired, and it is determined whether the write flag information is -1; if the write flag information is not -1, it is determined, according to the connectId in the write flag information, whether the connectId in the write flag information is the connectId disconnected by the callback function onDisconnected.
[0228] In step S210, if the write application currently performing the write operation on the target Bluetooth device is the first application, the write flag information of the target Bluetooth device is updated, and the updated write flag information indicates that the target Bluetooth device is in the write-allowed state.
[0229] In the embodiment of the present disclosure, if the connectId in the write flag information is the connectId disconnected by the callback function onDisconnected, the write flag information of the target Bluetooth device is set to -1; if the connectId in the write flag information is not the connectId disconnected by the callback function onDisconnected, the write flag information of the target Bluetooth device is not processed.
[0230] In this way, after a certain connectId releases the connection relationship with the target Bluetooth device, the connectId will not exist in the write flag of the target Bluetooth device.
[0231] In step S211, if the second application does not exist in the terminal device, the write flag information and the connection application information corresponding to the target Bluetooth device are deleted from the connection configuration information.
[0232] In the embodiment of the present disclosure, if it is determined that the target Bluetooth device is not connected with other connectId, the write flag information of the target Bluetooth device is deleted from the connection configuration information.
[0233] The specific code is as follows:
[0234]
[0235]
[0236] The embodiment of the present disclosure also provides a concurrent write control device. Figure 3 The structure of a concurrent write control device according to an exemplary embodiment is shown in FIG. 1. Figure 3 As shown in FIG. 1, the device is applied to a terminal device, and the concurrent write control device 100 comprises:
[0237] The first determining module 101 is configured to receive a first response message returned by a target Bluetooth device in response to a connection disconnection request, and determine a first application sending the connection disconnection request based on the first response message; wherein the target Bluetooth device is any one of a plurality of Bluetooth devices connected by the terminal device.
[0238] The obtaining module 102 is configured to obtain write flag information of the target Bluetooth device from connection configuration information pre-stored by the terminal device.
[0239] The second determining module 103 is configured to determine whether a write application currently performing a write operation on the target Bluetooth device is the first application when the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in a data write state.
[0240] The updating module 104 is configured to update the write flag information of the target Bluetooth device if the write application currently performing the write operation on the target Bluetooth device is the first application, and the updated write flag information indicates that the target Bluetooth device is in an allowed write state.
[0241] Optionally, the connection configuration information stores connection application information; wherein the connection application information at least includes a connection number of an application program in the terminal device having a connection relationship with the target Bluetooth device; wherein the connection numbers corresponding to different application programs are different.
[0242] The obtaining module 102 is configured to:
[0243] Obtain the connection application information of the target Bluetooth device from the connection configuration information.
[0244] Determine whether there is a second application in the terminal device having a connection relationship with the target Bluetooth device based on the connection number in the connection application information.
[0245] If there is the second application in the terminal device, obtain the write flag information of the target Bluetooth device from the connection configuration information.
[0246] Optionally, the obtaining module 102 is configured to:
[0247] If there is no second application in the terminal device, delete the write flag information and the connection application information corresponding to the target Bluetooth device from the connection configuration information.
[0248] Optionally, the apparatus comprises a connection module 105 configured to:
[0249] In response to a connection operation of any application program in the terminal device aiming at the target Bluetooth device, a connection request is sent to the target Bluetooth device;
[0250] A second response message of the connection request returned by the target Bluetooth device is received, and the connection number is allocated to the application program;
[0251] Based on the first identification information of the target Bluetooth device carried in the second response message, it is determined whether the connection configuration information of the terminal device stores the write flag information corresponding to the first identification information;
[0252] If the connection configuration information does not store the write flag information corresponding to the first identification information, the write flag information corresponding to the target Bluetooth device is added in the connection configuration information, and the write flag information of the target Bluetooth device is initialized and set; wherein the write flag information after the initialization indicates that the target Bluetooth device is in the write-allowed state.
[0253] Optionally, the connection module 105 is configured to:
[0254] If the connection configuration information stores the write flag information corresponding to the first identification information, the connection application information corresponding to the target Bluetooth device is updated based on the connection number of the application program.
[0255] Optionally, the apparatus comprises a write module 106 configured to:
[0256] Upon receiving a write operation of the first application aiming at the target Bluetooth device, the write flag information of the target Bluetooth device is obtained from the connection configuration information of the terminal device;
[0257] Based on the write flag information of the target Bluetooth device, it is determined whether the target Bluetooth device is in the write-allowed state;
[0258] If the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the write-allowed state, a write request is sent to the target Bluetooth device;
[0259] and the write flag information of the target Bluetooth device is updated based on the connection number of the first application; wherein the updated write flag information at least indicates that the target Bluetooth device is in the data write state, and the application currently performing the write operation on the target Bluetooth device is the first application.
[0260] Optionally, the write module 106 is configured to:
[0261] After the first application completes the write operation on the target Bluetooth device, the write flag information of the target Bluetooth device is updated; wherein the updated write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the write-allowed state.
[0262] Optionally, the write module 106 is configured to:
[0263] If the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the data write state, output a prompt information of write failure.
[0264] Figure 4 is a block diagram of a terminal device according to an exemplary embodiment. For example, the terminal device 800 can be a mobile phone, a mobile computer, or the like.
[0265] Referring to Figure 4 , the terminal device 800 can include one or more of the following components: a processing component 802, a memory 804, a power supply component 806, a multimedia component 808, an audio component 810, an input / output (I / O) interface 812, a sensor component 814, and a communication component 816.
[0266] The processing component 802 usually controls overall operations of the terminal device 800, such as operations associated with displaying, making phone calls, data communications, camera operations, and recording operations. The processing component 802 can include one or more processors 820 to execute instructions to complete all or part of steps of the methods described above. In addition, the processing component 802 can include one or more modules to facilitate the interaction between the processing component 802 and other components. For example, the processing component 802 can include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.
[0267] The memory 804 is configured to store various types of data to support operations of the device 800. Examples of these data include instructions for any application or method operating on the terminal device 800, contact data, phonebook data, messages, pictures, videos, and the like. The memory 804 can be implemented by any type of volatile or non-volatile storage devices or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk.
[0268] The power supply component 806 provides power for various components of the terminal device 800. The power supply component 806 can include a power supply management system, one or more power supplies, and other components associated with generating, managing and distributing power for the terminal device 800.
[0269] The multimedia component 808 includes a screen providing an output interface between the terminal device 800 and a user. In some embodiments, the screen can include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense a touch, a slide and a gesture on the touch panel. The touch sensor can not only sense a boundary of a touching or a sliding action, but also detect duration and pressure related to the touching or sliding action. In some embodiments, the multimedia component 808 includes a front camera and / or a back camera. The front camera and / or the back camera can receive external multimedia data when the device 800 is in an operating mode, such as a shooting mode or a video mode. Each of the front and back camera can be a fixed optical lens system or have a focal length and optical zoom capability.
[0270] The audio component 810 is configured to output and / or input an audio signal. For example, the audio component 810 includes a microphone (MIC) configured to receive an external audio signal when the terminal device 800 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal can be further stored in the memory 804 or transmitted via the communication component 816. In some embodiments, the audio component 810 also includes a speaker for outputting an audio signal.
[0271] The I / O interface 812 provides an interface between the processing component 802 and peripheral interface modules, which can be a keypad, a click wheel, buttons, and the like. The buttons can include, but are not limited to, a home button, a volume button, a start button, and a lock button.
[0272] The sensor component 814 includes one or more sensors to provide various state assessments for the terminal device 800. For example, the sensor component 814 can detect an open / closed state of the device 800, relative positioning of components, such as a display and a keypad of the terminal device 800, a change in position of the terminal device 800 or a component of the terminal device 800, presence or absence of user contact with the terminal device 800, an orientation or acceleration / deceleration of the terminal device 800, and a temperature change of the terminal device 800. The sensor component 814 can include a proximity sensor configured to detect presence of a nearby object without any physical touch. The sensor component 814 can further include a light sensor such as a CMOS or CCD image sensor for use in an imaging application. In some embodiments, the sensor component 814 can further include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0273] The communication component 816 is configured to facilitate wired or wireless communication between the terminal device 800 and other devices. The terminal device 800 can access a wireless network based on a communication standard, such as Wi-Fi, 4G, or 5G, or a combination thereof. In an example embodiment, the communication component 816 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an example embodiment, the communication component 816 further includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technology.
[0274] In an example embodiment, the terminal device 800 can be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, micro-controllers, microprocessors or other electronic elements, for performing the above-described methods.
[0275] In an example embodiment, a non-transitory computer-readable storage medium including instructions, such as the memory 804 including instructions, is also provided, which can be executed by the processor 820 of the terminal device 800 to complete the above-described methods. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disc, and an optical data storage device, etc.
[0276] Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. It is intended that the present application cover any and all variations of the application that come within the scope of the present application, including custom and practice of the art known to those skilled in the art. It is intended that the specification and examples be considered exemplary only, with the true scope and spirit of the application indicated by the following claims.
[0277] It is to be understood that the application is not limited to the precise construction herein disclosed and shown in the drawings, and that various changes in form and detail can be made therein without departing from the scope thereof. The scope of the application is limited only by the claims that follow.
Claims
1. A concurrent write control method, characterized by, The method is applied to a terminal device, and comprises the following steps: receiving a first response message returned by a target Bluetooth device in response to a connection disconnection request, and determining a first application sending the connection disconnection request based on the first response message; wherein the target Bluetooth device is any device in a plurality of Bluetooth devices connected by the terminal device; the first response message is sent by the target Bluetooth device in the case that the connection relationship between the target Bluetooth device and the first application is successfully released; obtaining write flag information of the target Bluetooth device from connection configuration information pre-stored in the terminal device; when the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in a data write state, determining whether a write application currently performing a write operation on the target Bluetooth device is the first application; if the write application currently performing the write operation on the target Bluetooth device is the first application, determining that the target Bluetooth device has a concurrent fault, updating the write flag information of the target Bluetooth device, and the updated write flag information indicating that the target Bluetooth device is in an allowed write state.
2. The method of claim 1, wherein, The connection configuration information stores connection application information; wherein the connection application information at least comprises a connection number of an application program in the terminal device establishing a connection relationship with the target Bluetooth device; wherein the connection numbers corresponding to different application programs are different; The method comprises the following steps: obtaining the connection application information of the target Bluetooth device from the connection configuration information; determining whether there is a second application in the terminal device establishing a connection relationship with the target Bluetooth device based on the connection number in the connection application information; if there is the second application in the terminal device, obtaining the write flag information of the target Bluetooth device from the connection configuration information.
3. The method of claim 2, wherein, The method comprises the following steps: if there is no second application in the terminal device, deleting the write flag information and the connection application information corresponding to the target Bluetooth device from the connection configuration information.
4. The method of claim 2, wherein, The method comprises the following steps: sending a connection request to the target Bluetooth device in response to a connection operation of any application program in the terminal device to the target Bluetooth device; receiving a second response message of the connection request returned by the target Bluetooth device, and allocating the connection number to the application program; determining whether the connection configuration information of the terminal device stores the write flag information corresponding to the first identification information based on the first identification information of the target Bluetooth device carried by the second response message; if the connection configuration information does not store the write flag information corresponding to the first identification information, adding write flag information corresponding to the target Bluetooth device in the connection configuration information, and initializing the write flag information of the target Bluetooth device; wherein the write flag information after the initialization indicates that the target Bluetooth device is in the allowed write state.
5. The method of claim 4, wherein, The method comprises the following steps: If the connection configuration information stores the write flag information corresponding to the first identification information, the connection application information corresponding to the target Bluetooth device is updated based on the connection number of the application program.
6. The method of claim 1, wherein, Before the first response message returned by the target Bluetooth device in response to the connection disconnection request is received, the method comprises: The write flag information of the target Bluetooth device is obtained from the connection configuration information of the terminal device, after the first application receives a write operation for the target Bluetooth device; Based on the write flag information of the target Bluetooth device, it is determined whether the target Bluetooth device is in the allowed write state; If the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the allowed write state, a write request is sent to the target Bluetooth device; And based on the connection number of the first application, the write flag information of the target Bluetooth device is updated; wherein the updated write flag information at least indicates that the target Bluetooth device is in the data write state, and the application program currently performing the write operation on the target Bluetooth device is the first application.
7. The method of claim 6, wherein, The method comprises: After the first application completes the write operation on the target Bluetooth device, the write flag information of the target Bluetooth device is updated; wherein the updated write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the allowed write state.
8. The method of claim 6, wherein, The method comprises: If the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in the data write state, prompt information of write failure is output.
9. A concurrent write control apparatus characterized by comprising: Applied to a terminal device, the device comprises: A first determination module is configured to receive a first response message returned by a target Bluetooth device in response to a connection disconnection request, and determine a first application that sends the connection disconnection request based on the first response message; wherein the target Bluetooth device is any device in a plurality of Bluetooth devices connected by the terminal device; and the first response message is sent by the target Bluetooth device in the case of successfully releasing the connection relationship with the first application. A obtaining module is configured to obtain write flag information of the target Bluetooth device from connection configuration information stored in advance by the terminal device. A second determination module is configured to determine whether a write application currently performing a write operation on the target Bluetooth device is the first application when the write flag information of the target Bluetooth device indicates that the target Bluetooth device is in a data write state. An updating module is configured to determine that the target Bluetooth device has a concurrent fault if the write application currently performing the write operation on the target Bluetooth device is the first application, update the write flag information of the target Bluetooth device, and the updated write flag information indicates that the target Bluetooth device is in an allowed write state.
10. A concurrent write control apparatus characterized by comprising: Comprise: A processor; A memory for storing executable instructions; Wherein the processor is configured to execute the executable instructions stored in the memory to implement the concurrent write control method in any one of claims 1 to 8.
11. A non-transitory computer readable storage medium, when instructions in the storage medium are executed by a processor of a concurrent write control device, enable the concurrent write control device to perform the concurrent write control method of any one of claims 1 to 8.
Citation Information
Patent Citations
Method for quickly obtaining disconnection of Bluetooth equipment and terminal equipment
CN110545540A
Access control method, device and equipment and readable storage medium
CN111488175A