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、A2dp
        for (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
  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值