From: luozheng <1732036298@qq.com> Date: Fri, 7 Feb 2025 07:35:24 +0000 (+0800) Subject: 解决蓝牙耳机在连接后手表重启,下拉菜单耳机状态和蓝牙耳机界面耳机连接状态不一致问题 X-Git-Tag: v1.3.113-repair_tp~3^2~16 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F1647%2F2;p=mirrors%2FFD230.git 解决蓝牙耳机在连接后手表重启,下拉菜单耳机状态和蓝牙耳机界面耳机连接状态不一致问题 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp index c59fc5b05..c1892ab8e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp @@ -115,7 +115,7 @@ namespace OHOS lastAddr->addr[3] == 0 && lastAddr->addr[4] == 0 && lastAddr->addr[5] == 0) && ret) { - BluetoothModel::GetInstance()->SetTagConnectNew(false); + BluetoothModel::GetInstance()->SetTagConnectNew(false); //主动断开连接不需要回连该设备 errcode_t retVal = gap_disconnect_remote_device(lastAddr); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[gap_disconnect_remote_device] retVal = %d", retVal); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp index 4bc004da7..96e50c9bb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -555,6 +555,7 @@ bool BluetoothModel::IsTagConnectView(void) return tagConnectView; } +//设置是否需要跳转连接失败界面 void BluetoothModel::SetTagDisconnectView(bool tag) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothModel::SetTagDisconnectView:%d", tag); @@ -582,13 +583,13 @@ bool BluetoothModel::IsTagReturnToDeviceListView(void) return tagReturnToDeviceListView; } -// 判断断开连接时是否需要马上连接新设备 +// 获取断开连接时是否需要马上连接新设备 bool BluetoothModel::IsTagConnectNew(void) { return tagConnectNew; } -// 获取断开连接时是否需要马上连接新设备 +// 设置断开连接时是否需要马上连接新设备 void BluetoothModel::SetTagConnectNew(bool tag) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothModel::SetTagConnectNew:%d", tag); @@ -607,6 +608,7 @@ bool BluetoothModel::IsTagScanDeviceClicked(void) return tagScanDeviceClicked; } +//检查给定的 BluetoothCaseInfo 结构体实例 caseInfo 所代表的蓝牙设备是否已经存在于已连接设备列表中 bool BluetoothModel::CheckExistConnedList(BluetoothCaseInfo caseInfo) { ListNode *node = btConnedDevicesList_ ->Begin(); @@ -642,7 +644,8 @@ bool BluetoothModel::FindNameByAddr(BluetoothCaseInfo &listInfo, BluetoothCaseIn return false; } } - +//在已连接设备列表 btConnedDevicesList_ 和扫描设备列表 btScansDevicesList_ +//中查找与输入的 BluetoothCaseInfo 结构体实例 caseInfo 地址匹配的设备,并尝试获取该设备的名称 bool BluetoothModel::FindNameFromList(BluetoothCaseInfo *caseInfo) { ListNode *node = btConnedDevicesList_->Begin(); @@ -699,6 +702,11 @@ int BluetoothModel::ConnectRemoteDevice(const bd_addr_t *addr) bool BluetoothModel::ConnectRemoteCheck(const bd_addr_t *addr) { bool ret; + if ((remoteConnectAddr.addr[0] == 0) && (remoteConnectAddr.addr[1] == 0) && + (remoteConnectAddr.addr[2] == 0) && (remoteConnectAddr.addr[3] == 0) && + (remoteConnectAddr.addr[4] == 0) && (remoteConnectAddr.addr[5] == 0)) { + return true; + } if ((remoteConnectAddr.addr[0] == addr->addr[0]) && (remoteConnectAddr.addr[1] == addr->addr[1]) && (remoteConnectAddr.addr[2] == addr->addr[2]) && (remoteConnectAddr.addr[3] == addr->addr[3]) && (remoteConnectAddr.addr[4] == addr->addr[4]) && (remoteConnectAddr.addr[5] == addr->addr[5])) { @@ -930,7 +938,7 @@ void HandleBeforeChangeView() } } -//处理蓝牙耳机连接成功操作 +//处理蓝牙耳机连接成功的UI操作 static void ACLConnectionSuss(const bd_addr_t &bdAddr) { // 判断是否已退出蓝牙模块(无需跳转) @@ -940,7 +948,7 @@ static void ACLConnectionSuss(const bd_addr_t &bdAddr) return; } // 成功提示 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GAP_ACL_STATE_CONNECTED"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "蓝牙耳机连接成功"); HandleBeforeChangeView(); if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { JumpView *jumpView = JumpView::GetInstance(); @@ -963,7 +971,7 @@ static void ACLConnectionSuss(const bd_addr_t &bdAddr) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ACLConnectionSuss tipsSuccMessageView GetInstance fail"); return; } - tipsSuccMessageView->RefreshNameLabel(bdAddr); + tipsSuccMessageView->RefreshNameLabel(bdAddr); //更新连接成功的提示视图的蓝牙名称 /* -------------------------------------------------------------------------- */ if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) { @@ -985,7 +993,7 @@ static void ACLConnectionFail(const bd_addr_t &bdAddr) return; } // 失败提示页 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "conn fail"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "蓝牙耳机连接失败"); HandleBeforeChangeView(); if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { JumpView *jumpView = JumpView::GetInstance(); @@ -1008,7 +1016,7 @@ static void ACLConnectionFail(const bd_addr_t &bdAddr) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ACLConnectionFail tipsConnFailMessageView GetInstance fail"); return; } - tipsConnFailMessageView->RefreshNameLabel(bdAddr); + tipsConnFailMessageView->RefreshNameLabel(bdAddr);//更新连接失败的提示视图的蓝牙名称 /* -------------------------------------------------------------------------- */ if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) { @@ -1018,7 +1026,7 @@ static void ACLConnectionFail(const bd_addr_t &bdAddr) /* -------------------------------------------------------------------------- */ } -//处理断开蓝牙耳机连接 +//处理断开蓝牙耳机连接的UI操作 static void DisconnectedHandle() { BluetoothModel::GetInstance()->SetTagDisconnectView(false); @@ -1032,22 +1040,18 @@ static void DisconnectedHandle() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisconnectedHandle deviceList nullptr"); return; } - deviceList->RefreshList(); - // BluetoothOptionsView *bluetoothOptionsView = BluetoothOptionsView::GetInstance(); - // if (bluetoothOptionsView == nullptr) { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AclStateChangedCallback bluetoothOptionsView == nullptr"); - // return; - // } - // bluetoothOptionsView->RefreshText(); + deviceList->RefreshList();//刷新列表 } void BluetoothModel::BtGapAclStateChangedHandle(gap_acl_state_t state, unsigned int reason, const bd_addr_t &bdAddr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"ACL回调,%d",state); bool tag = BluetoothModel::GetInstance()->IsTagScanDeviceClicked(); if ((reason == 0x13) || (reason == 0x14) || (reason == 0x15) || (reason == 0x3D) || (reason == 0x08 && (!tag))) { // 连接断开 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "The peer end is disconnected."); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "蓝牙设备主动断开与手表连接 reason is %x", reason); DisconnectedHandle(); } else if (reason == 0x16) { // 主动断开连接 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "手表主动断开与蓝牙设备连接,reason is%x", reason); DisconnectedHandle(); BluetoothCaseInfo *onClickBtCaseInfo = BluetoothModel::GetInstance()->GetTempMacValue(); if (BluetoothModel::GetInstance()->IsTagConnectNew()) { @@ -1077,16 +1081,19 @@ void BluetoothModel::BtGapAclStateChangedHandle(gap_acl_state_t state, unsigned int32_t retA2dp = a2dp_src_connect(&bdAddr); if (retA2dp) { ACLConnectionFail(bdAddr); - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "a2dp_src_connect result 0x%x", retA2dp); - #ifdef SUPPORT_CAT1_HFP_AG_SERV + #ifdef SUPPORT_CAT1_HFP_AG_SERV errcode_t rethfp= hfp_ag_cmd_conn_hfp(&bdAddr); - if(rethfp) + if(!rethfp) { - ACLConnectionFail(bdAddr); + errcode_t retVal = ConnectRemoteDevice((const bd_addr_t *)&onClickBtCaseInfo->addr); } - #endif - + #endif + } + else + { + errcode_t retVal = ConnectRemoteDevice((const bd_addr_t *)&onClickBtCaseInfo->addr); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "a2dp_src_connect result 0x%x", retA2dp); } else { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ingore a2dp_src_connect"); @@ -1206,6 +1213,8 @@ static void A2dpSrcConnectstateChanged(bd_addr_t *bdAddr, int connState) SendMsgToUIService(EARPHONE_CONNECTED_TO_UI, 0, nullptr, 0); uapi_dev_runtime_set_earphone_connect_stat(1); uapi_save_runtime_log(RUNTIME_LOG_BR_CONNECT_A2DP_HEADSET); + if(headset_Is_connect() == false) + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_CONNECT_AG, nullptr, 0); }