解决连接蓝牙出现地址为0情况导致连不上bug 2843/1 2843/head 2844/target/1 2845/target/1
authorluozheng <1732036298@qq.com>
Tue, 2 Dec 2025 09:41:27 +0000 (17:41 +0800)
committerluozheng <1732036298@qq.com>
Tue, 2 Dec 2025 09:41:27 +0000 (17:41 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueView.h
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueView.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp

index 40c18ce..532712c 100644 (file)
@@ -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};
     };
 }
 
index 9350f48..e780264 100644 (file)
@@ -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;
     }
     
index bdce460..86af911 100644 (file)
@@ -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;
             }
index c5e0947..e70e9f5 100644 (file)
@@ -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); }