From 4ce4da337f15fa2ff4029fab44be188763abdcff Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Fri, 28 Nov 2025 19:08:19 +0800 Subject: [PATCH] =?utf8?q?=E6=B7=BB=E5=8A=A0=E8=80=B3=E6=9C=BA=E8=BF=9E?= =?utf8?q?=E6=8E=A5=E7=8A=B6=E6=80=81ui=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/bluetooth/src/BluetoothModel.cpp | 13 ++++++++-- .../bluetooth/src/Ln_Bluetooth_apiC.cpp | 25 ++++++++----------- .../nativeui/include/uiservice/ui_service.h | 1 + .../thunderbird/include/ThunderBirdModel.h | 2 ++ .../thunderbird/src/ThunderBirdBlueView.cpp | 11 ++++++++ .../thunderbird/src/ThunderBirdModel.cpp | 10 ++++++++ .../thunderbird/src/ThunderBirdPresenter.cpp | 4 ++- .../nativeui/uiservice/src/ui_service.cpp | 14 +++++++++++ 8 files changed, 63 insertions(+), 17 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 eb21b342c..5b24f5281 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 @@ -938,6 +938,7 @@ static void ACLConnectionFail(const bd_addr_t &bdAddr) } void BluetoothModel::BtGapAclStateChangedHandle(gap_acl_state_t state, unsigned int reason, const bd_addr_t &bdAddr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BtGapAclStateChangedHandle reason is %x", reason); bool tag = BluetoothModel::GetInstance()->IsTagScanDeviceClicked(); if ((reason == 0x13) || (reason == 0x14) || (reason == 0x15) || (reason == 0x3D) || (reason == 0x08 && (!tag))) { // 连接断开 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "蓝牙设备主动断开连接 reason is %x", reason); @@ -962,6 +963,10 @@ void BluetoothModel::BtGapAclStateChangedHandle(gap_acl_state_t state, unsigned AddConnedDevicesCase(*info); } } + else + { + ACLConnectionFail(bdAddr); + } if ((state == GAP_ACL_STATE_CONNECTED) || (state == GAP_ACL_STATE_LE_CONNECTED)) { if (BluetoothModel::GetInstance()->ConnectRemoteCheck(&bdAddr)) { @@ -1006,8 +1011,8 @@ void ChangeBleConnectToDefault() // 回调:ACL连接状态上报 void GapAclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, unsigned int reason) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bt GapAclStateChangedCallback state %d, reason %x succ or err", state, reason); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "addr: %02x%02x%02x%02x%02x%02x", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bt GapAclStateChangedCallback state %d, reason %x succ or err", state, reason); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr: %02x%02x%02x%02x%02x%02x", bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* mac下标 0 1 2 3 4 5 */ bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */ static bd_addr_t gapAclConnectAddr{0}; /* 连接后保存手机地址,手表清除手机配对后查询不到class比较手机地址 */ @@ -1085,11 +1090,15 @@ static void A2dpSrcConnectstateChanged(bd_addr_t *bdAddr, int connState) WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "avrcp_ct_connect ret = 0x%x", ret); PhoneAudioManagerSetDeviceConnState(OUT_BLUETOOTH_A2DP, AUDIO_DEVICE_CONNECTED); GraphicService::GetInstance()->PostGraphicEvent(std::bind(ACLConnectionSuss, *bdAddr)); + int earphoneConnectStatus = 1; + SendMsgToUIService(HAND_BLUETOOTH_EARPHONE_CONNECT_STATUS_NOTIFY, 0, &earphoneConnectStatus, sizeof(earphoneConnectStatus)); } if (connState == PROFILE_STATE_DISCONNECTED) { PhoneAudioManagerSetDeviceConnState(OUT_BLUETOOTH_A2DP, AUDIO_DEVICE_DISCONNECTED); GraphicService::GetInstance()->PostGraphicEvent(std::bind(ACLConnectionFail, *bdAddr)); + int earphoneConnectStatus = 0; + SendMsgToUIService(HAND_BLUETOOTH_EARPHONE_CONNECT_STATUS_NOTIFY, 0, &earphoneConnectStatus, sizeof(earphoneConnectStatus)); /* 实验室测试耳机回连场景,用户根据需要调整策略 */ bool ret = gap_br_set_bt_scan_mode(GAP_SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 60); // start scan if (!ret) { diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/Ln_Bluetooth_apiC.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/Ln_Bluetooth_apiC.cpp index 29bbb9604..74694c81c 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/Ln_Bluetooth_apiC.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/bluetooth/src/Ln_Bluetooth_apiC.cpp @@ -35,22 +35,19 @@ namespace OHOS { if (BluetoothModel::GetInstance()->GetCase().size() == 0) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "扫描结果为空"); - if (BluetoothModel::GetInstance()->GetScanStatus() == true) // 如果是扫描状态 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "扫描结果为空,%d", BluetoothModel::GetInstance()->GetScanStatus()); + BluetoothModel::GetInstance()->SetScanStatus(false); + ThunderBirdMainView *thunderBirdMainView = ThunderBirdMainView::GetInstance(); + if (thunderBirdMainView == nullptr) { - BluetoothModel::GetInstance()->SetScanStatus(false); - ThunderBirdMainView *thunderBirdMainView = ThunderBirdMainView::GetInstance(); - if (thunderBirdMainView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "thunderBirdMainView nullptr"); - return; - } - int currentView = thunderBirdMainView->GetCurrentView(); - thunderBirdMainView->ChangeView( - currentView, - THUNDERBIRD_BLUEVIEW, - ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_SREACHING_FAILED); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "thunderBirdMainView nullptr"); + return; } + int currentView = thunderBirdMainView->GetCurrentView(); + thunderBirdMainView->ChangeView( + currentView, + THUNDERBIRD_BLUEVIEW, + ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_SREACHING_FAILED); } // 扫描结束后关闭屏幕常亮 ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/include/uiservice/ui_service.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/include/uiservice/ui_service.h index 1a2efcbec..85bba0198 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/include/uiservice/ui_service.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/include/uiservice/ui_service.h @@ -77,6 +77,7 @@ typedef enum { HAND_DIALOGUE_RESPONSE_FINISHED_NOTIFY, // 对话响应finished通知 HAND_VAD_INITIALIZED_NOTIFY, // VAD初始化完成通知 HAND_BLUETOOTH_CONNECT_NOTIFY, // 蓝牙耳机连接通知 + HAND_BLUETOOTH_EARPHONE_CONNECT_STATUS_NOTIFY, // 蓝牙耳机连接状态通知 MAX_NUM_HANDLER, } UiServiceMsgId; diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h index 8a2140bef..b2505aed6 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h @@ -233,6 +233,8 @@ namespace OHOS // 处理蓝牙耳机连接通知 void HandleBluetoothConnect(const char *bluetoothAddress); + // 处理蓝牙耳机断开通知 + void HandleBluetoothEarphoneConnectStatus(int connectStatus); // 处理对话响应消息的finished标志 void HandleDialogueResponseFinished(bool finished); diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueView.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueView.cpp index c00e3c201..eb52bbd59 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueView.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueView.cpp @@ -840,6 +840,17 @@ namespace OHOS WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "LastDevice addr: %02x%02x%02x%02x%02x%02x is connected", lastAddr->addr[5], lastAddr->addr[4], lastAddr->addr[3], lastAddr->addr[2], lastAddr->addr[1], lastAddr->addr[0]); + if(lastAddr->addr[5] == selectedDevice->addr[5] && + lastAddr->addr[4] == selectedDevice->addr[4] && + lastAddr->addr[3] == selectedDevice->addr[3] && + lastAddr->addr[2] == selectedDevice->addr[2] && + lastAddr->addr[1] == selectedDevice->addr[1] && + lastAddr->addr[0] == selectedDevice->addr[0]) + { + //如果地址相同,且地址相同不断开连接 + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Same device selected, not disconnect"); + return; + } BluetoothModel::GetInstance()->DisconnectRemoteDevice(); BluetoothModel::GetInstance()->SetTagConnectNew(true); } diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp index 2950d993b..52b93bd9e 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp @@ -2600,6 +2600,16 @@ extern "C" { ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_BLUEVIEW, ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_ENTER); } } + + //更新耳机图标 + void ThunderBirdModel::HandleBluetoothEarphoneConnectStatus(int connectStatus) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::HandleBluetoothEarphoneConnectStatus: 收到蓝牙耳机连接状态通知,connectStatus=%d", connectStatus); + if(ThunderBirdMainView::GetInstance()){ + int currentView = ThunderBirdMainView::GetInstance()->GetCurrentView(); //获取当前视图 + // ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_BLUEVIEW, ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_EXIT); + } + } void ThunderBirdModel::HandleBindAndUnbind(int is_bind) { diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp index d317442a1..796c142a5 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp @@ -847,7 +847,9 @@ namespace OHOS ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_STATUS_SHOW); break; case ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_DEVICE_LIST: - ThunderBirdBlueView::GetInstance()->OnKeyUp();// 音量+键:选择上一个设备 + // ThunderBirdBlueView::GetInstance()->OnKeyUp();// 音量+键:选择上一个设备 + //重新搜索设备 + ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_BLUEVIEW, ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_SREACHING); break; case ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_CONNECT_FAILED: //重新发送连接操作 diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp index 28b81fea1..3de60b6b3 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp @@ -118,6 +118,7 @@ static void HandStoryResponseFinishedNotify(Request *request); static void HandDialogueResponseFinishedNotify(Request *request); static void HandVadInitializedNotify(Request *request); static void HandBluetoothConnectNotify(Request *request); +static void HandBluetoothEarphoneConnectStatusNotify(Request *request); // 消息处理程序项数组(每个消息类型对应一个处理函数,函数名以 Handle 开头) MsgHandlerEntry msgHandlers[] = { @@ -148,6 +149,7 @@ MsgHandlerEntry msgHandlers[] = { {HAND_DIALOGUE_RESPONSE_FINISHED_NOTIFY,HandDialogueResponseFinishedNotify}, {HAND_VAD_INITIALIZED_NOTIFY,HandVadInitializedNotify}, {HAND_BLUETOOTH_CONNECT_NOTIFY,HandBluetoothConnectNotify}, + {HAND_BLUETOOTH_EARPHONE_CONNECT_STATUS_NOTIFY,HandBluetoothEarphoneConnectStatusNotify}, }; /* -------------------------------------------------------------------------- */ void ScreenTurnOn(int32_t timeout) @@ -848,6 +850,18 @@ void HandBluetoothConnectNotify(Request *request) OHOS::ThunderBirdModel::GetInstance(), "AA:BB:CC:DD:EE:FF"));//要连接的蓝牙设备MAC地址,保留字段,暂时无用 } +// 通知蓝牙耳机连接状态变化 +void HandBluetoothEarphoneConnectStatusNotify(Request *request) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandBluetoothEarphoneConnectStatusNotify msg_id = %d", request->msgId); + if (request->data && request->len == sizeof(int)) { + int connectStatus = *(static_cast(request->data)); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandBluetoothEarphoneConnectStatusNotify connectStatus = %d", connectStatus); + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(&OHOS::ThunderBirdModel::HandleBluetoothEarphoneConnectStatus, + OHOS::ThunderBirdModel::GetInstance(), connectStatus)); + } +} /* -------------------------------------------------------------------------- */ #ifdef __cplusplus } -- 2.17.1