From: luozheng <1732036298@qq.com> Date: Tue, 2 Dec 2025 09:41:27 +0000 (+0800) Subject: 解决连接蓝牙出现地址为0情况导致连不上bug X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F2845%2Ftarget%2F1;p=mirrors%2FFD230.git 解决连接蓝牙出现地址为0情况导致连不上bug --- diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueView.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueView.h index 40c18ce38..532712cd7 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueView.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueView.h @@ -9,6 +9,7 @@ #include "components/ui_image_animator.h" #include "components/ui_list.h" #include "UiConfig.h" +#include "bluetooth/BluetoothModel.h" namespace OHOS { @@ -118,6 +119,8 @@ namespace OHOS // 当前视图状态 int16_t currentShowView_{-1}; + + bd_addr_t targetAddr{0}; }; } 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 9350f483b..e780264ad 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 @@ -6,7 +6,6 @@ #include "custom_utils.h" #include "vibrator_service.h" #include "bluetooth/Ln_Bluetooth_apiC.h" -#include "bluetooth/BluetoothModel.h" namespace OHOS @@ -834,7 +833,14 @@ namespace OHOS RefreshDeviceList(); // 发起连接 - BluetoothModel::GetInstance()->ConnectRemoteDevice((const bd_addr_t*)&selectedDevice->addr); + // 注意:BluetoothCaseInfo::addr 只是一个 6 字节数组,这里需要组装成 bd_addr_t 结构再传给 ConnectRemoteDevice + memset(&targetAddr, 0, sizeof(bd_addr_t)); + (void)memcpy_s(targetAddr.addr, BD_ADDR_LEN, BluetoothModel::GetInstance()->GetTempMacValue()->addr, BD_ADDR_LEN); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "OnKeyConfirm: ConnectRemoteDevice targetAddr=%02x%02x%02x%02x%02x%02x", + targetAddr.addr[5], targetAddr.addr[4], targetAddr.addr[3], + targetAddr.addr[2], targetAddr.addr[1], targetAddr.addr[0]); + BluetoothModel::GetInstance()->ConnectRemoteDevice(&targetAddr); return; } @@ -882,7 +888,14 @@ namespace OHOS RefreshDeviceList(); // 发起连接 - BluetoothModel::GetInstance()->ConnectRemoteDevice((const bd_addr_t*)&caseInfo->addr); + // 注意:BluetoothCaseInfo::addr 只是一个 6 字节数组,这里需要组装成 bd_addr_t 结构再传给 ConnectRemoteDevice + memset(&targetAddr, 0, sizeof(bd_addr_t)); + (void)memcpy_s(targetAddr.addr, BD_ADDR_LEN, caseInfo->addr, BD_ADDR_LEN); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "OnConnectFailed: ConnectRemoteDevice targetAddr=%02x%02x%02x%02x%02x%02x", + targetAddr.addr[5], targetAddr.addr[4], targetAddr.addr[3], + targetAddr.addr[2], targetAddr.addr[1], targetAddr.addr[0]); + BluetoothModel::GetInstance()->ConnectRemoteDevice(&targetAddr); return; } 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 bdce4603a..86af911ae 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 @@ -2916,6 +2916,8 @@ extern "C" { int currentView = ThunderBirdMainView::GetInstance()->GetCurrentView(); //获取当前视图 ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_ADJUSTVIEW, ThunderBirdAdjustView::THUNDERBIRD_ADJUSTVIEW_BIND_SUCCESS); } + int volume = AudioManager::GetInstance().SetVolume(AUDIO_STREAM_VOICE_ASSISTANT, 50); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::HandleBindAndUnbind: 绑定成功,当前音量=%d", volume); bind_status = true; return; } diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp index c5e0947f9..e70e9f530 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp @@ -101,6 +101,9 @@ namespace OHOS { VolumeProgress->SetPosition(118, 132, 124, 4); VolumeProgress->SetRange(100, 0); + int volumeDelta = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_VOICE_ASSISTANT); + printf("volumeDelta = %d\n", volumeDelta); + VolumeProgress->SetValue(volumeDelta); VolumeProgress->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 0xff); VolumeProgress->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xffb4a9a0); VolumeProgress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); @@ -476,7 +479,7 @@ namespace OHOS { return; } - int16_t newVal = remindProgressValue_ + delta; + int16_t newVal = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_VOICE_ASSISTANT) + delta; SetRemindProgress(newVal); // 若当前处于音量界面,确保控件可见 if (RemindButton) { RemindButton->SetVisible(true); }