}
// 回调:ACL连接失败
-static void ACLConnectionFail(const bd_addr_t &bdAddr)
+static void ACLConnectionFail(const bd_addr_t &bdAddr, bool isPeerDisconnect = false)
{
// 如果当前正处于“切换到新耳机”的流程中(用户点了另一台设备准备自动重连),
// 就不要弹出“连接已断开”页面,直接走后续新设备连接流程,避免多余页面跳转。
}
if(strcmp((const char *)caseInfo.deviceName, BluetoothModel::GetInstance()->GetLastConnedDeviceName()) == 0)
{
+ // 如果是耳机端主动断开连接,需要解绑设备
+ if (isPeerDisconnect) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ACLConnectionFail: 耳机端自动断开连接,执行解绑操作");
+ // 将 bd_addr_t 转换为字符串格式(MAC地址格式:AA:BB:CC:DD:EE:FF)
+ char macStr[32] = {0};
+ snprintf(macStr, sizeof(macStr), "%02X:%02X:%02X:%02X:%02X:%02X",
+ bdAddr.addr[5], bdAddr.addr[4], bdAddr.addr[3],
+ bdAddr.addr[2], bdAddr.addr[1], bdAddr.addr[0]);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ACLConnectionFail: 解绑设备 MAC: %s", macStr);
+ // 执行解绑操作
+ BluetoothModel::GetInstance()->UnBindRemoteDevice(macStr);
+ }
//亮屏操作
uapi_set_screen_on_api();
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BtGapAclStateChangedHandle reason is %x", reason);
bool tag = BluetoothModel::GetInstance()->IsTagScanDeviceClicked();
+ bool isPeerDisconnect = false; // 是否是耳机端主动断开
if ((reason == 0x13) || (reason == 0x14) || (reason == 0x15) || (reason == 0x3D) || (reason == 0x08 && (!tag))) { // 连接断开
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "蓝牙设备主动断开连接 reason is %x", reason);
+ isPeerDisconnect = true; // 标记为耳机端主动断开
} else if (reason == 0x16) { // 主动断开连接
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "主动断开与蓝牙设备连接,reason is%x", reason);
BluetoothCaseInfo *onClickBtCaseInfo = BluetoothModel::GetInstance()->GetTempMacValue();
}
else
{
- ACLConnectionFail(bdAddr);
+ ACLConnectionFail(bdAddr, isPeerDisconnect);
}
if ((state == GAP_ACL_STATE_CONNECTED) || (state == GAP_ACL_STATE_LE_CONNECTED)) {
set_a2dp_is_connect(false);
- GraphicService::GetInstance()->PostGraphicEvent(std::bind(ACLConnectionFail, *bdAddr));
+ GraphicService::GetInstance()->PostGraphicEvent(std::bind(ACLConnectionFail, *bdAddr, false));
int earphoneConnectStatus = 0;
SendMsgToUIService(HAND_BLUETOOTH_EARPHONE_CONNECT_STATUS_NOTIFY, 0, &earphoneConnectStatus, sizeof(earphoneConnectStatus));
/* 实验室测试耳机回连场景,用户根据需要调整策略 */