PBAP-synchronization protocol analysis of Bluetooth phone
In the previous article "Analysis of PBAP Protocol for Bluetooth Phones", the content of the PBAP protocol was analyzed as a whole. In this chapter, we focus on analyzing the essence of the protocol-synchronous phone book. The purpose of the PBAP protocol is to synchronize the source data of the PSE to the PCE, so let's start this journey.
Each protocol defines related features, and PBAP synchronization is also not different. The following two functions are mainly defined in the protocol.
-
Download : This function is used to download all the contents of the phone book object
-
Browsing : This feature is especially suitable for applications that need to scroll through the phone book
The support of these two functions at both ends of PSE and PCE is shown in the figure below:
Because the Download function can synchronize all the contents of the phone book object to the PCE, the PCE can display the data to the interface through applications such as Bluetooth phones after obtaining the data, and the purpose of scrolling through the phone book information can also be achieved. Taking Download as the analysis point, students who are interested in Browsing, welcome to send me a private message to discuss how to use this feature point.
The Download function is particularly suitable for the relatively large capacity of the phone book stored on the PSE side. PCE devices usually download these large-capacity data from the PSE side and store the entire phone book locally. The PullPhonebook function is used to download the phone book objects of interest.
Since the PBAP protocol is based on OBEX, the PullPhonebook function, as the name suggests, also uses the form of request-response to transmit data.
Request format :
There are several options for the Name value of the synchronized phonebook object name:
Reply format :
The vCard object in the reply data should only contain the attributes indicated by the Attribute Selector parameter, and the data should be assembled in the format indicated by the Format parameter. The vCard version in the current Bluetooth PBAP protocol is only vCard 2.1 and vCard 3.0, so we can choose one of the vCard versions when constructing data.
There is only one parameter that needs to be emphasized in the request response format: Application Parameters Header , the data is the Application Parameters composed of a set of different tags. The optional tags are as shown in the figure below. The more commonly used ones are the six marked in the red box. tag:
The PropertySelector in these tags is used to indicate the attributes that should be included in the requested vCard object. PSE organizes the data contained in the body/End of Body Header in the response according to these attributes. PCE can only use this header to receive the requested vCard content , PSE shall not reply to any other performance data unless PCE has other requirements.
Because the value of PropertySelector is composed of a 64-bit data, each bit represents a property. If the phone book requested by the PCE needs to contain the corresponding data, set the data corresponding to the binary bit of the PropertySelector to true ( 1). The specific meaning of each is shown in the figure below:
When synchronizing information in the phone book, the main concern is the three parts of data: contact name, contact number, and contact avatar. Therefore, it is necessary to construct the PropertySelector value according to the real needs of your own business and synchronize it to the data required by the relevant application on the PCE side.
Since the current Android source code has not yet implemented the relevant interfaces of the PCE side, it needs to adapt and self-implement. The Android code I used here is based on the Qualcomm source code, plus a set of PBAP synchronization code implemented after functional adaptation. The process of synchronizing the phone book on the PCE side is roughly: Get the number of synchronized objects -> synchronize the objects.
Next, simply analyze the synchronization process from the perspective of HCI:
1. Synchronize contacts
Synchronizing contacts as a whole is divided into two steps. First obtain the number of contacts under the two Names, and then synchronize the contact data under the corresponding Names according to the number. The following two screenshots select Name=telecom/pb.vcf as an example for illustration , SIM card process is similar.
-
Get the number of contacts :
-
Sync contact data :
2. Synchronize call records
There are three types of call records and corresponding vcf files
-
MISSED: Call history of missed calls-mch.vcf
-
RECEIVED: Call record of received calls-ich.vcf
-
DIALED: Outgoing call record-och.vcf
But there is another type of vcf file that contains the above three types, namely cch.vcf, so you can choose which call records to synchronize according to your needs. What I have achieved here is to synchronize all types of call records (mainly in order of types) It’s too much trouble to synchronize call records)
After the PCE side obtains the phone book data synchronously, there are basically two ways to process the data:
- Report to the application via callback (relevant callbacks need to be added to get through the three-layer relationship of APK-API-Bluetooth service)
- Stored in the database provided by the Android system, report the application-related status, and then the application retrieves the corresponding data from the database
After actually using the above two methods, I feel that the speed of reporting data through the callback method is very fast, but the advantage of the database is that the data can be stored in the database, and there is no worry about data loss caused by the application or Android system crash. Therefore, it is recommended that you can use the two methods together.
Well, the analysis of the PBAP protocol synchronization data in the Bluetooth phone is summarized here. Interested friends are welcome to leave a message and discuss together
For more interconnection technologies, please pay attention to the WeChat public account: Connectivity