Android source code avoidance guide 6-call record is empty to trigger Bluetooth restart

Call record is empty, trigger Bluetooth restart

Insert picture description here

I think everyone will feel very strange about the empty phone records. Today, I will share with you the original problem of Bluetooth crash caused by empty phone records.

The generation of empty phone records : In today's society, personal information is flying all over the sky. After relevant practitioners dial your phone through the network dial-up software, an empty phone record will be generated on your mobile phone.

Triggering Bluetooth restart refers to the crash of the Bluetooth process on the PCE side of the PBAP protocol, which causes the problem of automatic Bluetooth restart. After tracking and analysis, the root cause of the problem is mainly in CallLogPullRequest.updateTimesContacted() . This method is used to count the number of calls of the same contact in the call log and synchronize it to the address book database.

updateTimesContacted() is a new method from android-9, so this problem does not exist on android-8 and below, only exists on android-9 and above.

How did the empty call record trigger the Bluetooth restart step by step? Not much to say, go directly to the synchronized call log data analysis process.

The Bluetooth protocol stack on the PCE side receives the call record data:
Insert picture description here

The phone number information in the received call log VCARD displays abnormally on the HCI layer. In fact, the call log is the empty call log discussed in this article. The mobile phone (PSE) sends the call record data to the requester via Bluetooth when assembling the call record data. Since the number does not exist, the string "unknown number" or "no number" will be converted into corresponding data through UTF-8 encoding format and sent To PCE.

The phone number data received by the PCE in the above figure is: 0xE69CAAE79FA5E58FB7E7A081
Insert picture description here

Converted into the corresponding string after UTF-8 encoding: unknown number

When the data passes through VCardEntry.addPhone() to add a phone number, it will extract char characters in turn to determine whether the character meets the standard. Because it is the data converted from the "unknown number" string, it is obvious that the builder is an empty string at the end, so the last added The phone number data is a null value.
Insert picture description here

After all the call log data is analyzed, the Bluetooth process writes the call log into the database through CallLogPullRequest.onPullComplete() , and counts the number of calls for each phone number. After writing the database, it is judged that the type of the last call record is OUTGOING_TYPE (outgoing type), and then the number of contacts in the address book is updated. (This logic of judging the call type feels unnecessary...)

If the above conditions are met, an empty phone number is used to query the database in the updateTimesContacted() method of updating the number of contacts, triggering an IllegalArgumentException parameter error, and triggering a Bluetooth process crash.
Insert picture description here

The root cause analysis of the problem is very clear here. The solution to avoid such problems in the source code of android-9 and above is a piece of cake. You only need to first set the key value (corresponding (In the phone number) add blank processing.
Insert picture description here

Interested friends welcome private messages and leave a message to discuss together, learn together, and make progress together!

For more interconnection technologies, please pay attention to the WeChat public account: Connectivity
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44260005/article/details/108491426