600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > Android 10 手机端关闭蓝牙再打开 蓝牙不会自动回连设备蓝牙

Android 10 手机端关闭蓝牙再打开 蓝牙不会自动回连设备蓝牙

时间:2024-03-09 06:44:42

相关推荐

Android 10 手机端关闭蓝牙再打开 蓝牙不会自动回连设备蓝牙

代码路径:

system/bt//internal_include/bt_target.h

packages/apps/Bluetooth/src/com/android/bluetooth/btservice/PhonePolicy.java

在bt_target.h文件中修改BLE_LOCAL_PRIVACY_ENABLED 变量就可以解决不能回连的问题

--- a/internal_include/bt_target.h+++ b/internal_include/bt_target.h@@ -618,7 +618,7 @@* Enables or disables support for local privacy (ex. address rotation)*/#ifndef BLE_LOCAL_PRIVACY_ENABLED-#define BLE_LOCAL_PRIVACY_ENABLED TRUE+#define BLE_LOCAL_PRIVACY_ENABLED FALSE#endif/*

1、手机蓝牙自动重连机制的主要在进程com.android.bluetooth中PhonePolicy.java文件中autoConnect()实现的

private void autoConnect() {if (mAdapterService.getState() != BluetoothAdapter.STATE_ON) {errorLog("autoConnect: BT is not ON. Exiting autoConnect");return;}if (!mAdapterService.isQuietModeEnabled()) {debugLog("autoConnect: Initiate auto connection on BT on...");final BluetoothDevice[] bondedDevices = mAdapterService.getBondedDevices();if (bondedDevices == null) {errorLog("autoConnect: bondedDevices are null");return;}//手机蓝牙自动重连Headset、A2dpfor (BluetoothDevice device : bondedDevices) {autoConnectHeadset(device);autoConnectA2dp(device);if (SystemProperties.get("persist.ivi.feature", "0").equals("1")) {autoConnectHeadsetClient();autoConnectA2dpSink();autoConnectPbapClient();}}} else {debugLog("autoConnect() - BT is in quiet mode. Not initiating auto connections");}}

For循环中通过判断设备某一个协议的优先级决定是否发起该协议的连接,只有Priority = BluetoothProfile.PRIORITY_AUTO_CONNECT(1000)的设备才会自动连接

2、车机蓝牙自动重连机制的主要在进程com.android.car中实现的,路径

packages\services\Car\service\src\com\android\car\BluetoothDeviceConnectionPolicy.java

车机蓝牙的自动重连主要是在com.android.car这个服务进程中实现的,先来整体认识下这个进程吧。从该进程的清单文件中可以知道其始于CarService.java:

从系统的全局变量Settings中读取已连接的设备信息,后面等监听到蓝牙状态打开后,再去重连这些设备对应的各个协议。该全局变量存储路径:/data/system/users/0/settings_secure.xml

注册监听的蓝牙广播有如下几种类型:

BluetoothDevice.ACTION_BOND_STATE_CHANGED—设备配对状BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED—媒体音频协议连接状态BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED—手机音频协议连接状态BluetoothPan.ACTION_CONNECTION_STATE_CHANGED—共享网络协议连接状态BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED—电话簿协议连接状态BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED—短信协议连接状态BluetoothAdapter.ACTION_STATE_CHANGED—蓝牙开关状态BluetoothDevice.ACTION_UUID—设备UUID

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。