From b2f004cde309d978ffc74c588864839793a6770e Mon Sep 17 00:00:00 2001 From: xue <2144439972@qq.com> Date: Fri, 16 Jan 2026 15:18:51 +0800 Subject: [PATCH] =?utf8?q?=E8=93=9D=E7=89=99=E4=B8=BB=E5=8A=A8=E6=96=AD?= =?utf8?q?=E5=BC=80=EF=BC=8C=E8=AE=BE=E5=A4=87=E5=90=8C=E6=84=8F=E8=A7=A3?= =?utf8?q?=E7=BB=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/bluetooth/src/BluetoothModel.cpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp index 679437dcc..0f53a6a30 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp @@ -948,7 +948,7 @@ static void ACLConnectionSuss(const bd_addr_t &bdAddr) } // 回调:ACL连接失败 -static void ACLConnectionFail(const bd_addr_t &bdAddr) +static void ACLConnectionFail(const bd_addr_t &bdAddr, bool isPeerDisconnect = false) { // 如果当前正处于“切换到新耳机”的流程中(用户点了另一台设备准备自动重连), // 就不要弹出“连接已断开”页面,直接走后续新设备连接流程,避免多余页面跳转。 @@ -972,6 +972,18 @@ static void ACLConnectionFail(const bd_addr_t &bdAddr) } 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(); @@ -993,8 +1005,10 @@ void BluetoothModel::BtGapAclStateChangedHandle(gap_acl_state_t state, unsigned { 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(); @@ -1049,7 +1063,7 @@ void BluetoothModel::BtGapAclStateChangedHandle(gap_acl_state_t state, unsigned } else { - ACLConnectionFail(bdAddr); + ACLConnectionFail(bdAddr, isPeerDisconnect); } if ((state == GAP_ACL_STATE_CONNECTED) || (state == GAP_ACL_STATE_LE_CONNECTED)) { @@ -1204,7 +1218,7 @@ static void A2dpSrcConnectstateChanged(bd_addr_t *bdAddr, int connState) 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)); /* 实验室测试耳机回连场景,用户根据需要调整策略 */ -- 2.17.1