From bc25dd7f58b12180a09b31aeef3a2575f210a448 Mon Sep 17 00:00:00 2001 From: "snickersun@163.com" Date: Thu, 13 Jun 2024 10:19:31 +0000 Subject: [PATCH] Merge #275 into sdk602patch0521 from refs/changes/275/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from snickersun@163.com * refs/changes/275/head: (2 commits squashed) - 修复蓝牙耳机扫描窗口不记录历史配对记录问题 - Merge branch 'sdk602patch0521' of codeup.aliyun.com:64191456b9581d62e8f81ac0/FD230 into sdk602patch0521 Signed-off-by: snickersun@163.com Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/275 --- .../bluetooth/src/BluetoothEarPhoneView.cpp | 5 +- .../nativeui/bluetooth/src/BluetoothModel.cpp | 51 ++++++++++--------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp index 808ae5040..eee47cb07 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp @@ -222,10 +222,11 @@ void BluetoothEarPhoneView::BtEnable() bool results; // 经典蓝牙扫描 setScanStatus(true); // 开始扫描标记 - BluetoothModel::GetInstance()->SetCaseListClear(); // 扫描list清空 + // BluetoothModel::GetInstance()->SetCaseListClear(); // 扫描list清空 + BluetoothModel::GetInstance()->Init(); //清空list,获取paired devicelist ret = is_bt_discovering(BT_TRANSPORT_BR_EDR); if (ret) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable Bt is Discovering"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable Bt is Discovering"); return; } else { results = gap_br_start_discovery(); 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 fb3f7ae5e..7e6bac81d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -29,7 +29,7 @@ #include "audio_manager_c_wrapper.h" #include "bts_avrcp_target.h" #include "msg_center_msg.h" - +#include "custom_runtime.h" namespace OHOS { #define BT_SPP_TASK_STACK_SIZE 2048 @@ -183,32 +183,35 @@ void BluetoothModel::SetUpConnedDevicesList() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothModel btConnedDevicesList_ new fail"); return; } - SetConnedDevicesListClear(); - unsigned int connedDevicesNum = 0; - bool ret = gap_get_paired_devices_num(&connedDevicesNum); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Setup GetPariedDevicesNum ret = %d, num = %d", ret, connedDevicesNum); - - gap_paired_device_info_t *devInfo = (gap_paired_device_info_t*)malloc(sizeof(gap_paired_device_info_t) *connedDevicesNum); - if (devInfo == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DevInfo malloc failed %u", sizeof(gap_paired_device_info_t) *connedDevicesNum); - return; - } - ret = gap_get_paired_devices_list(devInfo, (int *)&connedDevicesNum); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpConnedDevicesList gap_get_paired_devices_list ret = %d", ret); + + } + SetConnedDevicesListClear(); + unsigned int connedDevicesNum = 0; + int btpower = uapi_dev_runtime_get_bt_powerstat(); - BluetoothCaseInfo caseInfo{}; - for (int i = 0; i < static_cast(connedDevicesNum); ++i) { - if ((gap_get_device_class((const bd_addr_t *)devInfo[i].addr.addr) & 0x200) != 0) { - continue; - } - (void)memcpy_s(caseInfo.addr, BD_ADDR_LEN, - devInfo[i].addr.addr, BD_ADDR_LEN); - (void)memcpy_s(caseInfo.deviceName, BD_NAME_LEN, - devInfo[i].device_name, BD_NAME_LEN); - AddConnedDevicesCase(caseInfo); + bool ret = gap_get_paired_devices_num(&connedDevicesNum); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BT Power %s , Setup GetPariedDevicesNum ret = %d, num = %d", btpower==1?"On":"Off",ret, connedDevicesNum); + + gap_paired_device_info_t *devInfo = (gap_paired_device_info_t*)malloc(sizeof(gap_paired_device_info_t) *connedDevicesNum); + if (devInfo == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DevInfo malloc failed %u", sizeof(gap_paired_device_info_t) *connedDevicesNum); + return; + } + ret = gap_get_paired_devices_list(devInfo, (int *)&connedDevicesNum); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpConnedDevicesList gap_get_paired_devices_list ret = %d", ret); + + BluetoothCaseInfo caseInfo{}; + for (int i = 0; i < static_cast(connedDevicesNum); ++i) { + if ((gap_get_device_class((const bd_addr_t *)devInfo[i].addr.addr) & 0x200) != 0) { + continue; } - free(devInfo); + (void)memcpy_s(caseInfo.addr, BD_ADDR_LEN, + devInfo[i].addr.addr, BD_ADDR_LEN); + (void)memcpy_s(caseInfo.deviceName, BD_NAME_LEN, + devInfo[i].device_name, BD_NAME_LEN); + AddConnedDevicesCase(caseInfo); } + free(devInfo); } void BluetoothModel::AddConnedDevicesCase(BluetoothCaseInfo caseInfo) -- 2.17.1