In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor takes you to understand how the Bluetooth hardware APP Company analyzes the Bluetooth automatic reconnection mechanism. The knowledge points in the article are introduced in great detail. Friends who feel helpful can browse the content of the article together with the editor, hoping to help more friends who want to solve this problem to find the answer to the problem. Let's follow the editor to learn in depth how the Bluetooth hardware APP Company analyzes the Bluetooth automatic reconnection mechanism.
In the daily process of using Bluetooth, everyone must have found such a phenomenon: when the phone connected to the Bluetooth device is turned off and then turned on again, it will automatically connect to the previously connected device. The same scenario has the same effect on Android mobile phones. So how does this come true? in this article, Changzhou develops Bluetooth hardware APP to talk about the automatic reconnection mechanism of Bluetooth in Android.
Since Bluetooth is divided into Server and Client, that is, mobile phones and Bluetooth devices (car-machine system), the Bluetooth reconnection mechanism will also be different, but the overall process is basically the same:
Listen for Bluetooth status changes-> get device information connected before Bluetooth is turned off-> automatically connect.
1. The Bluetooth automatic reconnection mechanism of mobile phone is mainly implemented in the process com.android.bluetooth, path:
Packages\ apps\ Bluetooth\ src\ com\ android\ bluetooth\ btservice\ PhonePolicy.java
In the For loop, the priority of a protocol of the device is judged to determine whether to initiate a connection to that protocol, and only the device with Priority = BluetoothProfile.PRIORITY_AUTO_CONNECT (1000) will connect automatically.
2. The Bluetooth automatic reconnection mechanism is mainly implemented in the process com.android.car, the path:
Packages\ services\ Car\ service\ src\ com\ android\ car\ BluetoothDeviceConnectionPolicy.java
Because the process is almost the same, this paper analyzes the implementation principle of the automatic reconnection mechanism from the point of view of the Bluetooth system, and the Bluetooth automatic reconnection mechanism on the mobile phone has the opportunity to give you a further analysis.
The automatic reconnection of Bluetooth is mainly realized in the service process of com.android.car. Let's take a look at this process as a whole. You can see from the manifest file of the process that it starts with CarService.java:
Read the information of the connected devices from the global variable Settings of the system, and then reconnect the corresponding protocols of these devices after listening to the Bluetooth status turned on.
The global variable storage path: / data/system/users/0/settings_secure.xml
There are several types of Bluetooth broadcasts for registered monitoring:
1. Pairing status of BluetoothDevice.ACTION_BOND_STATE_CHANGED- devices
2. BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED- Media Audio Protocol connection status
3. BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED- phone audio protocol connection status
4. BluetoothPan.ACTION_CONNECTION_STATE_CHANGED- shared network protocol connection status
5. BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED- phonebook protocol connection status
6. Connection status of BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED- SMS protocol
7. BluetoothAdapter.ACTION_STATE_CHANGED- Bluetooth switch status
8. BluetoothDevice.ACTION_UUID- device UUID
CarBluetoothUserService is enabled indirectly by getBluetoothUserService () after the bind service PerUserCarService.
Finally, the protocol reconnection is connected in the following protocol order:
1 、 BluetoothProfile.HEADSET_CLIENT
2 、 BluetoothProfile.A2DP_SINK
3 、 BluetoothProfile.PBAP_CLIENT
4 、 BluetoothProfile.MAP_CLIENT
5 、 BluetoothProfile.PAN
The most critical part of the analysis from the whole process is to read the data from the Setting and save the information of the connected device to the Setting when Bluetooth is turned off or the process exits.
In fact, the reconnection mechanism is not only applicable to the above scenario after Bluetooth is turned on, sometimes the link between Bluetooth devices is disconnected due to various reasons, and it is necessary to automatically reconnect the Bluetooth device after a period of time. This scenario is not applicable in the above reconnection mechanism, so how to achieve it?
There are also ways to do that. I still remember that I wrote an article explaining in detail several reasons for Bluetooth ACL link disconnection, but not every disconnection requires automatic reconnection. For example, it would be speechless for a user to initiate an automatic reconnection when the user disconnects Bluetooth manually.
So we only need to initiate a reconnection automatically when the ACL is disconnected due to the link timeout. In this way, when the two Bluetooth devices get close again, they can automatically connect successfully.
Because the time when two Bluetooth devices are disconnected after timeout is uncertain, if only one automatic reconnection is initiated, the device may not be connected successfully, so the automatic reconnection mechanism here needs to add a loop to ensure a successful connection.
Thank you for your reading, the above is "Mobile Bluetooth hardware APP how to analyze Bluetooth automatic reconnection mechanism" all the content, learn friends hurry up to operate it. I believe that the editor will certainly bring you better quality articles. Thank you for your support to the website!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.