From 7723cf545811d23a7a6b8dce29663dc085ff7c49 Mon Sep 17 00:00:00 2001 From: hui Date: Mon, 24 Feb 2025 19:47:44 +0800 Subject: [PATCH 01/17] add opp Signed-off-by: hui --- frameworks/js/napi/src/parser/napi_parser_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/js/napi/src/parser/napi_parser_utils.cpp b/frameworks/js/napi/src/parser/napi_parser_utils.cpp index c57ba2c4..0c8f9d21 100644 --- a/frameworks/js/napi/src/parser/napi_parser_utils.cpp +++ b/frameworks/js/napi/src/parser/napi_parser_utils.cpp @@ -368,7 +368,7 @@ napi_status NapiParseFileHolder(napi_env env, napi_value object, FileHolder &out NAPI_BT_CALL_RETURN(NapiParseObjectString(env, object, "filePath", filePath)); NAPI_BT_CALL_RETURN(NapiParseObjectInt64(env, object, "fileSize", fileSize)); NAPI_BT_CALL_RETURN(NapiParseObjectInt32(env, object, "fileFd", fileFd)); - HILOGI("fileSize: %{public}Ld fileFd: %{public}d", fileSize, fileFd); + HILOGI("fileSize: %{public}ld fileFd: %{public}d", fileSize, fileFd); FileHolder fileHolder; fileHolder.filePath = filePath; -- Gitee From a4ffe99a53141428e4a0f0791eff270d7d348f74 Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 13 Mar 2025 20:04:53 +0800 Subject: [PATCH 02/17] modify memory leak Signed-off-by: lee --- ...bluetooth_ble_central_manager_callback.cpp | 43 ++++++++++++++----- .../napi/src/common/napi_bluetooth_event.cpp | 8 +++- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/frameworks/js/napi/src/ble/napi_bluetooth_ble_central_manager_callback.cpp b/frameworks/js/napi/src/ble/napi_bluetooth_ble_central_manager_callback.cpp index 17a309a4..00be3a7e 100644 --- a/frameworks/js/napi/src/ble/napi_bluetooth_ble_central_manager_callback.cpp +++ b/frameworks/js/napi/src/ble/napi_bluetooth_ble_central_manager_callback.cpp @@ -113,6 +113,8 @@ void AfterWorkCallbackToSysBLEScan(uv_work_t *work, int status) napi_call_function(env, undefine, funcFail, ARGS_SIZE_TWO, callbackValue, &callbackResult); } napi_call_function(env, undefine, funcComplete, 0, nullptr, &callbackResult); + delete work; + work = nullptr; } void AfterWorkCallbackToSysBLEDeviceFound(uv_work_t *work, int status) @@ -139,6 +141,8 @@ void AfterWorkCallbackToSysBLEDeviceFound(uv_work_t *work, int status) napi_value funcSuccess = nullptr; napi_get_reference_value(env, data->callbackSuccess, &funcSuccess); napi_call_function(env, undefine, funcSuccess, ARGS_SIZE_ONE, &object, &callbackResult); + delete work; + work = nullptr; } void SysOnScanCallBack(sysBLEMap &observers, const BleScanResult &result) @@ -168,8 +172,14 @@ void SysOnScanCallBack(sysBLEMap &observers, const BleScanResult &result) data->callbackFail = callbackInfos[PARAM1]->callback_; data->result = std::make_shared(result); work->data = static_cast(data); - uv_queue_work( + int ret = uv_queue_work( loop, work, [](uv_work_t *work) {}, AfterWorkCallbackToSysBLEDeviceFound); + if (ret != 0) { + delete data; + data = nullptr; + delete work; + work = nullptr; + } } } // namespace @@ -311,16 +321,8 @@ void NapiBluetoothBleCentralManagerCallback::OnBleBatchScanResultsEvent(const st } } -void NapiBluetoothBleCentralManagerCallback::OnStartOrStopScanEvent(int resultCode, bool isStartScan) +static void StartBLESysScanTask(int resultCode) { - HILOGI("resultCode: %{public}d, isStartScan: %{public}d", resultCode, isStartScan); - auto napiIsStartScan = std::make_shared(isStartScan); - if (isStartScan) { - AsyncWorkCallFunction(asyncWorkMap_, NapiAsyncType::BLE_START_SCAN, napiIsStartScan, resultCode); - } else { - AsyncWorkCallFunction(asyncWorkMap_, NapiAsyncType::BLE_STOP_SCAN, napiIsStartScan, resultCode); - } - std::array, ARGS_SIZE_THREE> callbackInfos; { std::lock_guard lock(g_sysBLEObserverMutex); @@ -359,8 +361,27 @@ void NapiBluetoothBleCentralManagerCallback::OnStartOrStopScanEvent(int resultCo data->callbackFail = callbackInfos[PARAM1]->callback_; data->callbackComplete = callbackInfos[PARAM2]->callback_; work->data = static_cast(data); - uv_queue_work( + int ret = uv_queue_work( loop, work, [](uv_work_t *work) {}, AfterWorkCallbackToSysBLEScan); + if (ret != 0) { + delete data; + data = nullptr; + delete work; + work = nullptr; + } +} + +void NapiBluetoothBleCentralManagerCallback::OnStartOrStopScanEvent(int resultCode, bool isStartScan) +{ + HILOGI("resultCode: %{public}d, isStartScan: %{public}d", resultCode, isStartScan); + auto napiIsStartScan = std::make_shared(isStartScan); + if (isStartScan) { + AsyncWorkCallFunction(asyncWorkMap_, NapiAsyncType::BLE_START_SCAN, napiIsStartScan, resultCode); + } else { + AsyncWorkCallFunction(asyncWorkMap_, NapiAsyncType::BLE_STOP_SCAN, napiIsStartScan, resultCode); + } + + StartBLESysScanTask(resultCode); } napi_value NapiNativeBleScanResult::ToNapiValue(napi_env env) const diff --git a/frameworks/js/napi/src/common/napi_bluetooth_event.cpp b/frameworks/js/napi/src/common/napi_bluetooth_event.cpp index 80549006..51dfa52e 100644 --- a/frameworks/js/napi/src/common/napi_bluetooth_event.cpp +++ b/frameworks/js/napi/src/common/napi_bluetooth_event.cpp @@ -37,7 +37,7 @@ void NapiEvent::EventNotify(AsyncEventData *asyncEvent) } work->data = asyncEvent; - uv_queue_work( + int ret = uv_queue_work( loop, work, [](uv_work_t *work) {}, @@ -62,6 +62,12 @@ void NapiEvent::EventNotify(AsyncEventData *asyncEvent) work = nullptr; } ); + if (ret != 0) { + delete asyncEvent; + asyncEvent = nullptr; + delete work; + work = nullptr; + } } napi_value NapiEvent::CreateResult(const std::shared_ptr &cb, int value) -- Gitee From 09a5dd323f6f68f72dff482c37bb95b15e6d6d3c Mon Sep 17 00:00:00 2001 From: lee Date: Sat, 15 Mar 2025 15:00:02 +0800 Subject: [PATCH 03/17] delete address print Signed-off-by: lee --- frameworks/js/napi/src/common/napi_async_callback.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/js/napi/src/common/napi_async_callback.cpp b/frameworks/js/napi/src/common/napi_async_callback.cpp index 92faaa89..8d3856c7 100644 --- a/frameworks/js/napi/src/common/napi_async_callback.cpp +++ b/frameworks/js/napi/src/common/napi_async_callback.cpp @@ -94,7 +94,7 @@ void NapiCallFunction(napi_env env, napi_ref callbackRef, napi_value *argv, size HILOGI("Clear JS application's exception"); napi_value exception = nullptr; status = napi_get_and_clear_last_exception(env, &exception); - HILOGD("napi_get_and_clear_last_exception status: %{public}d, exception: %{public}p", status, exception); + HILOGD("napi_get_and_clear_last_exception status: %{public}d", status); } } } // namespace {} -- Gitee From ec1a7dd4ce7550b82cd785b5e29fb392e5f08dfc Mon Sep 17 00:00:00 2001 From: lee Date: Tue, 18 Mar 2025 20:59:06 +0800 Subject: [PATCH 04/17] fix persistent bugfix Signed-off-by: lee Change-Id: Ie77c8938dda48b76dd4e7bd1daa2d3ea85dc4626 --- frameworks/inner/src/bluetooth_host.cpp | 1 + frameworks/js/napi/src/access/napi_bluetooth_access.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frameworks/inner/src/bluetooth_host.cpp b/frameworks/inner/src/bluetooth_host.cpp index a8a24bd5..de33b352 100644 --- a/frameworks/inner/src/bluetooth_host.cpp +++ b/frameworks/inner/src/bluetooth_host.cpp @@ -1306,6 +1306,7 @@ int64_t BluetoothHost::GetRefusePolicyProhibitedTime() int32_t BluetoothHost::ProcessRandomDeviceIdCommand( int32_t command, std::vector &deviceIdVec, bool &isValid) { + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr"); return proxy->ProcessRandomDeviceIdCommand(command, deviceIdVec, isValid); diff --git a/frameworks/js/napi/src/access/napi_bluetooth_access.cpp b/frameworks/js/napi/src/access/napi_bluetooth_access.cpp index de93ae55..5b771ba1 100644 --- a/frameworks/js/napi/src/access/napi_bluetooth_access.cpp +++ b/frameworks/js/napi/src/access/napi_bluetooth_access.cpp @@ -230,7 +230,7 @@ napi_value NapiAccess::GetPersistentDeviceIds(napi_env env, napi_callback_info i int32_t ret = BluetoothHost::GetDefaultHost().ProcessRandomDeviceIdCommand( static_cast(RandomDeviceIdCommand::GET), deviceIdVec, isValid); HILOGI("GetPersistentDeviceIds ret: %{public}d", ret); - NAPI_BT_ASSERT_RETURN_UNDEF(env, ret == BT_NO_ERROR, BT_ERR_INTERNAL_ERROR); + NAPI_BT_ASSERT_RETURN_UNDEF(env, ret == BT_NO_ERROR, ret); NapiNativeStringArray object(deviceIdVec); return object.ToNapiValue(env); @@ -247,7 +247,7 @@ napi_value NapiAccess::isValidRandomDeviceId(napi_env env, napi_callback_info in int32_t ret = BluetoothHost::GetDefaultHost().ProcessRandomDeviceIdCommand( static_cast(RandomDeviceIdCommand::IS_VALID), deviceIdVec, isValid); HILOGI("isValidRandomDeviceId ret: %{public}d", ret); - NAPI_BT_ASSERT_RETURN_UNDEF(env, ret == BT_NO_ERROR, BT_ERR_INTERNAL_ERROR); + NAPI_BT_ASSERT_RETURN_UNDEF(env, ret == BT_NO_ERROR, ret); NapiNativeBool object(isValid); return object.ToNapiValue(env); -- Gitee From 12e4107742ee0ac8d9ea8d090e60b3236a58366c Mon Sep 17 00:00:00 2001 From: chenjie Date: Thu, 20 Mar 2025 14:45:18 +0800 Subject: [PATCH 05/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E6=89=AB=E6=8F=8F=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenjie --- frameworks/inner/c_adapter/ohos_bt_gatt.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frameworks/inner/c_adapter/ohos_bt_gatt.cpp b/frameworks/inner/c_adapter/ohos_bt_gatt.cpp index 240576a7..3cb7a22f 100644 --- a/frameworks/inner/c_adapter/ohos_bt_gatt.cpp +++ b/frameworks/inner/c_adapter/ohos_bt_gatt.cpp @@ -979,8 +979,7 @@ int BleStartScanEx(int32_t scannerId, const BleScanConfigs *configs, const BleSc BleScanSettings settings; settings.SetScanMode(configs->scanMode); - bleCentralManager->StartScan(settings, scanFilters); - return OHOS_BT_STATUS_SUCCESS; + return bleCentralManager->StartScan(settings, scanFilters); } /** -- Gitee From 3be882a35a51e3a0d0ab0e1d79ba073f6bbf02ea Mon Sep 17 00:00:00 2001 From: huwenjie Date: Thu, 20 Mar 2025 09:05:29 +0000 Subject: [PATCH 06/17] update frameworks/inner/ipc/common/bt_def.h. Signed-off-by: huwenjie --- frameworks/inner/ipc/common/bt_def.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frameworks/inner/ipc/common/bt_def.h b/frameworks/inner/ipc/common/bt_def.h index 4794f05a..db04e00f 100644 --- a/frameworks/inner/ipc/common/bt_def.h +++ b/frameworks/inner/ipc/common/bt_def.h @@ -342,6 +342,8 @@ enum class GattPermission : uint16_t { enum class GattConnectionPriority : int { BALANCED, HIGH, LOW_POWER }; enum GattStatus { + EMPTY_FILTER = -31, + MAX_FILTERS = -30, INVALID_REMOTE_DEVICE = -29, INCLUDE_SERVICE_NOT_FOUND, REFERENCED_BY_OTHER_SERVICE, -- Gitee From b207e45ae00f9605f5f0b3a0eb4005ccc45ded85 Mon Sep 17 00:00:00 2001 From: hui Date: Fri, 21 Mar 2025 12:33:33 +0800 Subject: [PATCH 07/17] fix opp security Signed-off-by: hui --- .../inner/ipc/include/bluetooth_opp_proxy.h | 2 +- frameworks/inner/ipc/interface/i_bluetooth_opp.h | 2 +- frameworks/inner/ipc/src/bluetooth_opp_proxy.cpp | 15 ++++++++------- frameworks/inner/src/bluetooth_opp.cpp | 3 ++- .../js/napi/src/parser/napi_parser_utils.cpp | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/frameworks/inner/ipc/include/bluetooth_opp_proxy.h b/frameworks/inner/ipc/include/bluetooth_opp_proxy.h index 2dbcd651..2fb262dd 100644 --- a/frameworks/inner/ipc/include/bluetooth_opp_proxy.h +++ b/frameworks/inner/ipc/include/bluetooth_opp_proxy.h @@ -31,7 +31,7 @@ public: const std::vector &fileHolders, bool& result) override; int32_t SetIncomingFileConfirmation(bool accept, int fd) override; int32_t GetCurrentTransferInformation(BluetoothIOppTransferInformation &transferInformation) override; - int32_t CancelTransfer(bool &result) override; + int32_t CancelTransfer() override; int32_t SetLastReceivedFileUri(const std::string &uri) override; void RegisterObserver(const sptr &observer) override; void DeregisterObserver(const sptr &observer) override; diff --git a/frameworks/inner/ipc/interface/i_bluetooth_opp.h b/frameworks/inner/ipc/interface/i_bluetooth_opp.h index afebc077..38a947b9 100644 --- a/frameworks/inner/ipc/interface/i_bluetooth_opp.h +++ b/frameworks/inner/ipc/interface/i_bluetooth_opp.h @@ -35,7 +35,7 @@ public: const std::vector &fileHolders, bool& result) = 0; virtual int32_t SetIncomingFileConfirmation(bool accept, int fd) = 0; virtual int32_t GetCurrentTransferInformation(BluetoothIOppTransferInformation &transferInformation) = 0; - virtual int32_t CancelTransfer(bool &result) = 0; + virtual int32_t CancelTransfer() = 0; virtual int32_t SetLastReceivedFileUri(const std::string &uri) = 0; virtual void RegisterObserver(const sptr &observer) = 0; virtual void DeregisterObserver(const sptr &observer) = 0; diff --git a/frameworks/inner/ipc/src/bluetooth_opp_proxy.cpp b/frameworks/inner/ipc/src/bluetooth_opp_proxy.cpp index 493752af..352e0792 100644 --- a/frameworks/inner/ipc/src/bluetooth_opp_proxy.cpp +++ b/frameworks/inner/ipc/src/bluetooth_opp_proxy.cpp @@ -80,6 +80,8 @@ int32_t BluetoothOppProxy::GetCurrentTransferInformation(BluetoothIOppTransferIn int error = Remote()->SendRequest(static_cast( BluetoothOppInterfaceCode::COMMAND_GET_CURRENT_TRANSFER_INFORMATION), data, reply, option); CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error); + int32_t ret = reply.ReadInt32(); + CHECK_AND_RETURN_LOG_RET((ret == BT_NO_ERROR), ret, "reply errCode: %{public}d", ret); std::unique_ptr oppInformation_(reply.ReadParcelable()); CHECK_AND_RETURN_LOG_RET((oppInformation_ != nullptr), BT_ERR_DEVICE_DISCONNECTED, "oppInformation is nullptr"); @@ -87,7 +89,7 @@ int32_t BluetoothOppProxy::GetCurrentTransferInformation(BluetoothIOppTransferIn return BT_NO_ERROR; } -int32_t BluetoothOppProxy::CancelTransfer(bool &result) +int32_t BluetoothOppProxy::CancelTransfer() { MessageParcel data; CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothOppProxy::GetDescriptor()), @@ -101,8 +103,7 @@ int32_t BluetoothOppProxy::CancelTransfer(bool &result) static_cast(BluetoothOppInterfaceCode::COMMAND_CANCEL_TRANSFER), data, reply, option); CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error); - result = reply.ReadInt32() == BT_NO_ERROR ? true : false; - return BT_NO_ERROR; + return reply.ReadInt32(); } int32_t BluetoothOppProxy::SetLastReceivedFileUri(const std::string &uri) @@ -176,10 +177,8 @@ int32_t BluetoothOppProxy::GetDeviceState(const BluetoothRawAddress &device, int static_cast(BluetoothOppInterfaceCode::COMMAND_GET_DEVICE_STATE), data, reply, option); CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error); - int32_t ec = reply.ReadInt32(); - if (FAILED(ec)) { - return ec; - } + int32_t ret = reply.ReadInt32(); + CHECK_AND_RETURN_LOG_RET((ret == BT_NO_ERROR), ret, "reply errCode: %{public}d", ret); result = reply.ReadInt32(); return BT_NO_ERROR; @@ -201,6 +200,8 @@ int32_t BluetoothOppProxy::GetDevicesByStates( int error = Remote()->SendRequest( static_cast(BluetoothOppInterfaceCode::COMMAND_GET_DEVICES_BY_STATES), data, reply, option); CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error); + int32_t ret = reply.ReadInt32(); + CHECK_AND_RETURN_LOG_RET((ret == BT_NO_ERROR), ret, "reply errCode: %{public}d", ret); int32_t rawAddsSize = reply.ReadInt32(); const int32_t maxSize = 100; if (rawAddsSize > maxSize) { diff --git a/frameworks/inner/src/bluetooth_opp.cpp b/frameworks/inner/src/bluetooth_opp.cpp index a75dbe41..12f58c03 100644 --- a/frameworks/inner/src/bluetooth_opp.cpp +++ b/frameworks/inner/src/bluetooth_opp.cpp @@ -416,7 +416,8 @@ int32_t Opp::CancelTransfer(bool &result) sptr proxy = GetRemoteProxy(PROFILE_OPP_SERVER); CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr"); - int ret = proxy->CancelTransfer(result); + int ret = proxy->CancelTransfer(); + result = (ret == BT_NO_ERROR) ? true : false; HILOGI("cancelTransfer result is : %{public}d", ret); return ret; } diff --git a/frameworks/js/napi/src/parser/napi_parser_utils.cpp b/frameworks/js/napi/src/parser/napi_parser_utils.cpp index 0c8f9d21..b052f0af 100644 --- a/frameworks/js/napi/src/parser/napi_parser_utils.cpp +++ b/frameworks/js/napi/src/parser/napi_parser_utils.cpp @@ -368,7 +368,7 @@ napi_status NapiParseFileHolder(napi_env env, napi_value object, FileHolder &out NAPI_BT_CALL_RETURN(NapiParseObjectString(env, object, "filePath", filePath)); NAPI_BT_CALL_RETURN(NapiParseObjectInt64(env, object, "fileSize", fileSize)); NAPI_BT_CALL_RETURN(NapiParseObjectInt32(env, object, "fileFd", fileFd)); - HILOGI("fileSize: %{public}ld fileFd: %{public}d", fileSize, fileFd); + HILOGI("fileSize: %{public}lld fileFd: %{public}d", fileSize, fileFd); FileHolder fileHolder; fileHolder.filePath = filePath; -- Gitee From 722ba7ac4d166397e7ec73bb8cd5a8fe76d04ddd Mon Sep 17 00:00:00 2001 From: fengyong Date: Fri, 28 Mar 2025 09:37:06 +0800 Subject: [PATCH 08/17] =?UTF-8?q?write=E6=97=B6=E8=AE=BE=E7=BD=AE50s?= =?UTF-8?q?=E8=B6=85=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyong --- .../inner/src/bluetooth_socket_outputstream.cpp | 13 +++++++++++++ .../include/bluetooth_socket_outputstream.h | 1 + 2 files changed, 14 insertions(+) diff --git a/frameworks/inner/src/bluetooth_socket_outputstream.cpp b/frameworks/inner/src/bluetooth_socket_outputstream.cpp index d6946ffb..d07a273c 100644 --- a/frameworks/inner/src/bluetooth_socket_outputstream.cpp +++ b/frameworks/inner/src/bluetooth_socket_outputstream.cpp @@ -29,6 +29,7 @@ namespace Bluetooth { static constexpr int32_t SOCKET_PACKET_HEAD_LENGTH = 1512; static constexpr int32_t AAM_UID = 7878; static constexpr int32_t AAM_BAD_RET = -978974; +static constexpr int32_t SOFTBUS_UID = 1024; OutputStream::OutputStream(int socketFd) : socketFd_(socketFd) {} @@ -61,11 +62,23 @@ int OutputStream::Write(const uint8_t *buf, size_t length) } } } + + if (getuid() == SOFTBUS_UID && setTimeoutFlag_ == false) { + HILOGD("Softbus write set timeout."); + timeval timeVals; + if (setsockopt(socketFd_, SOL_SOCKET, SO_SNDTIMEO, &) == -1) { + HILOGE("setsockopt failed"); + return -1; + } + setTimeoutFlag_ == true; + } + auto ret = send(socketFd_, buf, length, MSG_NOSIGNAL); HILOGD("ret: %{public}zd", ret); if (ret <= 0) { + setTimeoutFlag_ == false; HILOGE("socket write exception! ret:%{public}zd errno:%{public}d", ret, errno); } return ret; diff --git a/interfaces/inner_api/include/bluetooth_socket_outputstream.h b/interfaces/inner_api/include/bluetooth_socket_outputstream.h index 37de05b9..36344c57 100644 --- a/interfaces/inner_api/include/bluetooth_socket_outputstream.h +++ b/interfaces/inner_api/include/bluetooth_socket_outputstream.h @@ -75,6 +75,7 @@ public: private: int socketFd_; + bool setTimeoutFlag_ = false; OutputStream() = delete; }; } // namespace Bluetooth -- Gitee From 8595a725a03364978937f7e4ef698d24a4619e41 Mon Sep 17 00:00:00 2001 From: fengyong Date: Fri, 28 Mar 2025 01:48:44 +0000 Subject: [PATCH 09/17] update frameworks/inner/src/bluetooth_socket_outputstream.cpp. Signed-off-by: fengyong --- .../inner/src/bluetooth_socket_outputstream.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/frameworks/inner/src/bluetooth_socket_outputstream.cpp b/frameworks/inner/src/bluetooth_socket_outputstream.cpp index d07a273c..84097574 100644 --- a/frameworks/inner/src/bluetooth_socket_outputstream.cpp +++ b/frameworks/inner/src/bluetooth_socket_outputstream.cpp @@ -30,7 +30,7 @@ static constexpr int32_t SOCKET_PACKET_HEAD_LENGTH = 1512; static constexpr int32_t AAM_UID = 7878; static constexpr int32_t AAM_BAD_RET = -978974; static constexpr int32_t SOFTBUS_UID = 1024; - +static constexpr int32_t SOCKET_WRITE_TIMEOUT_50_SEC = 50; OutputStream::OutputStream(int socketFd) : socketFd_(socketFd) {} @@ -62,15 +62,16 @@ int OutputStream::Write(const uint8_t *buf, size_t length) } } } - if (getuid() == SOFTBUS_UID && setTimeoutFlag_ == false) { - HILOGD("Softbus write set timeout."); - timeval timeVals; - if (setsockopt(socketFd_, SOL_SOCKET, SO_SNDTIMEO, &) == -1) { - HILOGE("setsockopt failed"); + HILOGD("SOFTBUS write data set 50s tiemout."); + timeval timeout; + timeout.tv_sec = SOCKET_WRITE_TIMEOUT_50_SEC; + timeout.tv_usec = 0; + if (setsockopt(socketFd_, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) < 0) { + HILOGW("Failed to set send timeout"); return -1; } - setTimeoutFlag_ == true; + setTimeoutFlag_ = true; } auto ret = send(socketFd_, buf, length, MSG_NOSIGNAL); -- Gitee From f2c545861d1eea4750f9c23c2a4dd621f02e5300 Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 27 Mar 2025 22:40:21 +0800 Subject: [PATCH 10/17] add dlclose clear bluetoothSystemAbility_ Signed-off-by: lee --- .../inner/include/bluetooth_profile_manager.h | 9 +++++++++ frameworks/inner/src/bluetooth_host.cpp | 5 +++++ .../inner/src/bluetooth_profile_manager.cpp | 15 +++++++++++++++ interfaces/inner_api/include/bluetooth_host.h | 2 ++ 4 files changed, 31 insertions(+) diff --git a/frameworks/inner/include/bluetooth_profile_manager.h b/frameworks/inner/include/bluetooth_profile_manager.h index 169154b8..a6f88694 100644 --- a/frameworks/inner/include/bluetooth_profile_manager.h +++ b/frameworks/inner/include/bluetooth_profile_manager.h @@ -87,6 +87,15 @@ public: * @brief check bluetooth service is on or not */ bool IsBluetoothServiceOn(); + /** + * @brief clear resource when dlclose + */ + static void ClearSystemAbility(); + + /** + * @brief clear resource when dlclose + */ + void Close(); static BluetoothProfileManager &GetInstance(); diff --git a/frameworks/inner/src/bluetooth_host.cpp b/frameworks/inner/src/bluetooth_host.cpp index de33b352..e12535e9 100644 --- a/frameworks/inner/src/bluetooth_host.cpp +++ b/frameworks/inner/src/bluetooth_host.cpp @@ -1311,5 +1311,10 @@ int32_t BluetoothHost::ProcessRandomDeviceIdCommand( CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr"); return proxy->ProcessRandomDeviceIdCommand(command, deviceIdVec, isValid); } + +void BluetoothHost::CleanResourceWhenDlclose() +{ + BluetoothProfileManager::GetInstance().Close(); +} } // namespace Bluetooth } // namespace OHOS diff --git a/frameworks/inner/src/bluetooth_profile_manager.cpp b/frameworks/inner/src/bluetooth_profile_manager.cpp index a44fcbd6..c68ffcf7 100644 --- a/frameworks/inner/src/bluetooth_profile_manager.cpp +++ b/frameworks/inner/src/bluetooth_profile_manager.cpp @@ -50,6 +50,21 @@ BluetoothProfileManager &BluetoothProfileManager::GetInstance() return *instance; } +extern "C" __attribute__((destructor)) void BluetoothProfileManager::ClearSystemAbility() +{ + BluetoothHost::GetDefaultHost().CleanResourceWhenDlclose(); +} + +void BluetoothProfileManager::Close() +{ + sptr samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + CHECK_AND_RETURN_LOG(samgrProxy != nullptr, "[BLUETOOTH_PROFILE_MANAGER] failed to get samgrProxy"); + int32_t ret = samgrProxy->UnSubscribeSystemAbility(BLUETOOTH_HOST_SYS_ABILITY_ID, bluetoothSystemAbility_); + CHECK_AND_RETURN_LOG(ret == ERR_OK, + "[BLUETOOTH_PROFILE_MANAGER] Unsubscribe systemAbilityId: bluetooth service failed!"); + bluetoothSystemAbility_ = nullptr; +} + void BluetoothProfileManager::SubScribeBluetoothSystemAbility() { sptr samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); diff --git a/interfaces/inner_api/include/bluetooth_host.h b/interfaces/inner_api/include/bluetooth_host.h index 04feabfe..2b2dd7d4 100644 --- a/interfaces/inner_api/include/bluetooth_host.h +++ b/interfaces/inner_api/include/bluetooth_host.h @@ -855,6 +855,8 @@ public: int64_t GetRefusePolicyProhibitedTime(); int32_t ProcessRandomDeviceIdCommand(int32_t command, std::vector &deviceIdVec, bool &isValid); + + void CleanResourceWhenDlclose(); private: /** * @brief A constructor used to create a BluetoothHost instance. -- Gitee From 18f57e9d49774bdd2d47a76e0d2b03bf0740f98e Mon Sep 17 00:00:00 2001 From: yexiaokang Date: Fri, 28 Mar 2025 16:10:43 +0800 Subject: [PATCH 11/17] Revert "add collaboration msg defination between AP and lpdevice" This reverts commit 395add7263b1ed7e04e9e567a8933691c0cbfcfc. Signed-off-by: yexiaokang --- frameworks/inner/ipc/common/bt_def.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/frameworks/inner/ipc/common/bt_def.h b/frameworks/inner/ipc/common/bt_def.h index db04e00f..3efb5669 100644 --- a/frameworks/inner/ipc/common/bt_def.h +++ b/frameworks/inner/ipc/common/bt_def.h @@ -457,7 +457,6 @@ typedef enum { SCAN_MODE_OP_P2_30_1500 = 0x09, SCAN_MODE_OP_P75_30_40 = 0x0A, SCAN_MODE_OP_P50_30_60 = 0x0B, - SCAN_MODE_OP_MAX, } SCAN_MODE; // Scan callback type @@ -520,17 +519,6 @@ constexpr int8_t BLE_LPDEVICE_MSG_UUID_DATA = 0x0a; constexpr int8_t BLE_LPDEVICE_MSG_ADV_HANDLE = 0x0b; constexpr int8_t BLE_LPDEVICE_MSG_SCAN_STATUS = 0x0c; constexpr int8_t BLE_LPDEVICE_MSG_SCAN_PARAM = 0x0d; -constexpr int8_t BLE_LPDEVICE_MSG_CAPABILITY_QUERY = 0x13; -constexpr int8_t BLE_LPDEVICE_MSG_SCAN_COLLABORATION_QUERY = 0x14; -constexpr int8_t BLE_LPDEVICE_MSG_SCAN_COLLABORATION_RESULT = 0x15; -constexpr int8_t BLE_LPDEVICE_MSG_GATT_CONN_COLLABORATION_QUERY = 0x16; -constexpr int8_t BLE_LPDEVICE_MSG_GATT_CONN_COLLABORATION_RESULT = 0x17; -constexpr int8_t BLE_LPDEVICE_MSG_SET_BLE_BUFFER_SIZE_AND_NUM = 0x18; - -// collaboration msg from lpdevice -constexpr uint8_t BLE_LPDEVICE_MSG_CAPABILITY = 0x01; -constexpr uint8_t BLE_LPDEVICE_MSG_SCAN_COLLABORATION_NOTIFY_STATUS = 0x02; -constexpr uint8_t BLE_LPDEVICE_MSG_GATT_CONN_COLLABORATION_NOTIFY_STATUS = 0x03; constexpr uint8_t BLE_LPDEVICE_MSG_TYPE_NOTICE_UP_DATA = 0x02; -- Gitee From e67075ed49a3de1fc8e0b357195d568be04d6231 Mon Sep 17 00:00:00 2001 From: linzlinz <2495670683@qq.com> Date: Sat, 29 Mar 2025 17:10:15 +0800 Subject: [PATCH 12/17] add GetDeviceId for spp Signed-off-by: linzlinz <2495670683@qq.com> --- frameworks/inner/src/bluetooth_host.cpp | 6 ++-- frameworks/inner/src/bluetooth_socket.cpp | 6 +++- .../napi/include/napi_bluetooth_spp_client.h | 1 + .../src/socket/napi_bluetooth_spp_client.cpp | 28 +++++++++++++++++++ .../src/socket/napi_bluetooth_spp_server.cpp | 1 + 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/frameworks/inner/src/bluetooth_host.cpp b/frameworks/inner/src/bluetooth_host.cpp index de33b352..1fc67eeb 100644 --- a/frameworks/inner/src/bluetooth_host.cpp +++ b/frameworks/inner/src/bluetooth_host.cpp @@ -1165,8 +1165,10 @@ int BluetoothHost::SetFastScan(bool isEnable) int BluetoothHost::GetRandomAddress(const std::string &realAddr, std::string &randomAddr) const { - randomAddr = realAddr; - return BT_NO_ERROR; + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); + sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "pimpl or bluetooth host is nullptr"); + return proxy->GetRandomAddress(realAddr, randomAddr); } int BluetoothHost::ConnectAllowedProfiles(const std::string &remoteAddr) const diff --git a/frameworks/inner/src/bluetooth_socket.cpp b/frameworks/inner/src/bluetooth_socket.cpp index 57963c34..28c04279 100644 --- a/frameworks/inner/src/bluetooth_socket.cpp +++ b/frameworks/inner/src/bluetooth_socket.cpp @@ -721,7 +721,11 @@ struct ServerSocket::impl { (void)sprintf_s(token, sizeof(token), "%02X:%02X:%02X:%02X:%02X:%02X", buf[0x05], buf[0x04], buf[0x03], buf[0x02], buf[0x01], buf[0x00]); BluetoothRawAddress rawAddr {token}; - acceptAddress_ = rawAddr.GetAddress().c_str(); + // If the random address fails to be obtained, the actual address is returned by default. + std::string randomAddr = rawAddr.GetAddress(); + BluetoothHost *host = &BluetoothHost::GetDefaultHost(); + host->GetRandomAddress(rawAddr.GetAddress(), randomAddr); + acceptAddress_ = randomAddr; maxTxPacketSize_ = GetPacketSizeFromBuf(recvBuf + TX_OFFSET, rv - TX_OFFSET); maxRxPacketSize_ = GetPacketSizeFromBuf(recvBuf + RX_OFFSET, rv - RX_OFFSET); diff --git a/frameworks/js/napi/include/napi_bluetooth_spp_client.h b/frameworks/js/napi/include/napi_bluetooth_spp_client.h index 5bf300f2..34d25d0b 100644 --- a/frameworks/js/napi/include/napi_bluetooth_spp_client.h +++ b/frameworks/js/napi/include/napi_bluetooth_spp_client.h @@ -69,6 +69,7 @@ struct NapiSppClient { static void SppRead(int id); static napi_value SppWriteAsync(napi_env env, napi_callback_info info); static napi_value SppReadAsync(napi_env env, napi_callback_info info); + static napi_value GetDeviceId(napi_env env, napi_callback_info info); static int count; static std::map> clientMap; diff --git a/frameworks/js/napi/src/socket/napi_bluetooth_spp_client.cpp b/frameworks/js/napi/src/socket/napi_bluetooth_spp_client.cpp index fb84a463..19d3bad2 100644 --- a/frameworks/js/napi/src/socket/napi_bluetooth_spp_client.cpp +++ b/frameworks/js/napi/src/socket/napi_bluetooth_spp_client.cpp @@ -28,6 +28,7 @@ #include #include #include +#include "../parser/napi_parser_utils.h" namespace OHOS { namespace Bluetooth { @@ -577,5 +578,32 @@ napi_value NapiSppClient::SppReadAsync(napi_env env, napi_callback_info info) asyncWork->Run(); return asyncWork->GetRet(); } + +static napi_status CheckSppFdParams(napi_env env, napi_callback_info info, int &id) +{ + size_t argc = ARGS_SIZE_ONE; + napi_value argv[ARGS_SIZE_ONE] = {0}; + + NAPI_BT_CALL_RETURN(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + NAPI_BT_RETURN_IF(argc != ARGS_SIZE_ONE, "Requires 1 arguments.", napi_invalid_arg); + NAPI_BT_CALL_RETURN(NapiParseInt32(env, argv[PARAM0], id)); + return napi_ok; +} + +napi_value NapiSppClient::GetDeviceId(napi_env env, napi_callback_info info) +{ + HILOGD("enter"); + int id = -1; + auto status = CheckSppFdParams(env, info, id); + NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); + auto client = clientMap[id]; + NAPI_BT_ASSERT_RETURN_UNDEF(env, client != nullptr, BT_ERR_INVALID_PARAM); + NAPI_BT_ASSERT_RETURN_UNDEF(env, client->client_ != nullptr, BT_ERR_INVALID_PARAM); + BluetoothRemoteDevice remoteDevice = client->client_->GetRemoteDevice(); + std::string addr = remoteDevice.GetDeviceAddr(); + napi_value result = nullptr; + napi_create_string_utf8(env, addr.c_str(), addr.size(), &result); + return result; +} } // namespace Bluetooth } // namespace OHOS diff --git a/frameworks/js/napi/src/socket/napi_bluetooth_spp_server.cpp b/frameworks/js/napi/src/socket/napi_bluetooth_spp_server.cpp index 02693778..ae275f01 100644 --- a/frameworks/js/napi/src/socket/napi_bluetooth_spp_server.cpp +++ b/frameworks/js/napi/src/socket/napi_bluetooth_spp_server.cpp @@ -39,6 +39,7 @@ void DefineSppFunctions(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("sppCloseServerSocket", NapiSppServer::SppCloseServerSocket), DECLARE_NAPI_FUNCTION("sppCloseClientSocket", NapiSppClient::SppCloseClientSocket), DECLARE_NAPI_FUNCTION("sppWrite", NapiSppClient::SppWrite), + DECLARE_NAPI_FUNCTION("getDeviceId", NapiSppClient::GetDeviceId), #ifdef BLUETOOTH_API_SINCE_10 DECLARE_NAPI_FUNCTION("on", NapiSppServer::RegisterSocketObserver), DECLARE_NAPI_FUNCTION("off", NapiSppServer::DeRegisterSocketObserver), -- Gitee From 0d6ea11f47e410ee79edc7509449ec5453b2e98b Mon Sep 17 00:00:00 2001 From: c00429280 Date: Mon, 31 Mar 2025 20:55:56 +0800 Subject: [PATCH 13/17] * avoid cloud dev when bluetooth off Signed-off-by: c00429280 --- frameworks/inner/src/bluetooth_host.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/inner/src/bluetooth_host.cpp b/frameworks/inner/src/bluetooth_host.cpp index 90a3a6c5..c62586e5 100644 --- a/frameworks/inner/src/bluetooth_host.cpp +++ b/frameworks/inner/src/bluetooth_host.cpp @@ -1274,6 +1274,7 @@ void BluetoothHost::Close(void) int32_t BluetoothHost::UpdateCloudBluetoothDevice(const std::vector &cloudDevices) { + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); HILOGI("[CLOUD_DEV] UpdateCloudBluetoothDevice enter"); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "pimpl or bluetooth host is nullptr"); -- Gitee From d5b5a616dda60f5f9b5b12bae0860f6ea54ffbad Mon Sep 17 00:00:00 2001 From: linzlinz <2495670683@qq.com> Date: Tue, 1 Apr 2025 15:01:26 +0800 Subject: [PATCH 14/17] ble advertising handle Signed-off-by: linzlinz <2495670683@qq.com> --- frameworks/inner/ipc/include/bluetooth_ble_advertiser_proxy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/inner/ipc/include/bluetooth_ble_advertiser_proxy.h b/frameworks/inner/ipc/include/bluetooth_ble_advertiser_proxy.h index 96a397ab..6e56e32f 100644 --- a/frameworks/inner/ipc/include/bluetooth_ble_advertiser_proxy.h +++ b/frameworks/inner/ipc/include/bluetooth_ble_advertiser_proxy.h @@ -36,7 +36,7 @@ public: int DisableAdvertising(uint8_t advHandle) override; int StopAdvertising(int32_t advHandle) override; void Close(int32_t advHandle) override; - int32_t GetAdvertiserHandle(int32_t &advHandle) override; + int32_t GetAdvertiserHandle(int32_t &advHandle, const sptr &callback) override; void SetAdvertisingData(const BluetoothBleAdvertiserData &advData, const BluetoothBleAdvertiserData &scanResponse, int32_t advHandle) override; int ChangeAdvertisingParams(uint8_t advHandle, const BluetoothBleAdvertiserSettings &settings) override; -- Gitee From a520b5433d0d5b0c8483f61693cd415cd63b4233 Mon Sep 17 00:00:00 2001 From: linzlinz <2495670683@qq.com> Date: Tue, 1 Apr 2025 15:11:24 +0800 Subject: [PATCH 15/17] ble advertising handle Signed-off-by: linzlinz <2495670683@qq.com> --- .../inner/ipc/include/bluetooth_ble_advertiser_proxy.h | 2 +- .../inner/ipc/interface/i_bluetooth_ble_advertiser.h | 2 +- .../inner/ipc/src/bluetooth_ble_advertiser_proxy.cpp | 7 ++++++- frameworks/inner/src/bluetooth_ble_advertiser.cpp | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/frameworks/inner/ipc/include/bluetooth_ble_advertiser_proxy.h b/frameworks/inner/ipc/include/bluetooth_ble_advertiser_proxy.h index 96a397ab..6e56e32f 100644 --- a/frameworks/inner/ipc/include/bluetooth_ble_advertiser_proxy.h +++ b/frameworks/inner/ipc/include/bluetooth_ble_advertiser_proxy.h @@ -36,7 +36,7 @@ public: int DisableAdvertising(uint8_t advHandle) override; int StopAdvertising(int32_t advHandle) override; void Close(int32_t advHandle) override; - int32_t GetAdvertiserHandle(int32_t &advHandle) override; + int32_t GetAdvertiserHandle(int32_t &advHandle, const sptr &callback) override; void SetAdvertisingData(const BluetoothBleAdvertiserData &advData, const BluetoothBleAdvertiserData &scanResponse, int32_t advHandle) override; int ChangeAdvertisingParams(uint8_t advHandle, const BluetoothBleAdvertiserSettings &settings) override; diff --git a/frameworks/inner/ipc/interface/i_bluetooth_ble_advertiser.h b/frameworks/inner/ipc/interface/i_bluetooth_ble_advertiser.h index 8185ec2f..d8a62673 100644 --- a/frameworks/inner/ipc/interface/i_bluetooth_ble_advertiser.h +++ b/frameworks/inner/ipc/interface/i_bluetooth_ble_advertiser.h @@ -39,7 +39,7 @@ public: virtual int DisableAdvertising(uint8_t advHandle) = 0; virtual int StopAdvertising(int32_t advHandle) = 0; virtual void Close(int32_t advHandle) = 0; - virtual int32_t GetAdvertiserHandle(int32_t &advHandle) = 0; + virtual int32_t GetAdvertiserHandle(int32_t &advHandle, const sptr &callback) = 0; virtual void SetAdvertisingData(const BluetoothBleAdvertiserData &advData, const BluetoothBleAdvertiserData &scanResponse, int32_t advHandle) = 0; virtual int ChangeAdvertisingParams(uint8_t advHandle, const BluetoothBleAdvertiserSettings &settings) = 0; diff --git a/frameworks/inner/ipc/src/bluetooth_ble_advertiser_proxy.cpp b/frameworks/inner/ipc/src/bluetooth_ble_advertiser_proxy.cpp index b9654c7e..94ff3853 100644 --- a/frameworks/inner/ipc/src/bluetooth_ble_advertiser_proxy.cpp +++ b/frameworks/inner/ipc/src/bluetooth_ble_advertiser_proxy.cpp @@ -216,13 +216,18 @@ void BluetoothBleAdvertiserProxy::Close(int32_t advHandle) } } -int32_t BluetoothBleAdvertiserProxy::GetAdvertiserHandle(int32_t &advHandle) +int32_t BluetoothBleAdvertiserProxy::GetAdvertiserHandle(int32_t &advHandle, + const sptr &callback) { MessageParcel data; if (!data.WriteInterfaceToken(BluetoothBleAdvertiserProxy::GetDescriptor())) { HILOGW("[GetAdvertiserHandle] fail: write interface token failed."); return BT_ERR_INTERNAL_ERROR; } + if (!data.WriteRemoteObject(callback->AsObject())) { + HILOGW("[GetAdvertiserHandle] fail: write callback failed."); + return BT_ERR_INTERNAL_ERROR; + } MessageParcel reply; MessageOption option = {MessageOption::TF_SYNC}; diff --git a/frameworks/inner/src/bluetooth_ble_advertiser.cpp b/frameworks/inner/src/bluetooth_ble_advertiser.cpp index d3bba56e..91805659 100644 --- a/frameworks/inner/src/bluetooth_ble_advertiser.cpp +++ b/frameworks/inner/src/bluetooth_ble_advertiser.cpp @@ -365,7 +365,7 @@ int BleAdvertiser::StartAdvertising(const BleAdvertiserSettings &settings, const if (pimpl->callbacks_.IsExistAdvertiserCallback(callback, advHandle)) { ret = proxy->StartAdvertising(setting, bleAdvertiserData, bleScanResponse, advHandle, duration, false); } else { - ret = proxy->GetAdvertiserHandle(advHandle); + ret = proxy->GetAdvertiserHandle(advHandle, pimpl->callbackImp_); if (ret != BT_NO_ERROR || advHandle == BLE_INVALID_ADVERTISING_HANDLE) { HILOGE("Invalid advertising handle"); callback->OnStartResultEvent(BT_ERR_INTERNAL_ERROR, static_cast(BLE_INVALID_ADVERTISING_HANDLE)); @@ -413,7 +413,7 @@ int BleAdvertiser::StartAdvertising(const BleAdvertiserSettings &settings, const if (pimpl->callbacks_.IsExistAdvertiserCallback(callback, advHandle)) { ret = proxy->StartAdvertising(setting, bleAdvertiserData, bleScanResponse, advHandle, duration, true); } else { - ret = proxy->GetAdvertiserHandle(advHandle); + ret = proxy->GetAdvertiserHandle(advHandle, pimpl->callbackImp_); if (ret != BT_NO_ERROR || advHandle == BLE_INVALID_ADVERTISING_HANDLE) { HILOGE("Invalid advertising handle"); callback->OnStartResultEvent(BT_ERR_INTERNAL_ERROR, BLE_INVALID_ADVERTISING_HANDLE); -- Gitee From cbe043beb98f3807cea106b619214cdd8c9a6b3f Mon Sep 17 00:00:00 2001 From: lee Date: Tue, 1 Apr 2025 18:45:24 +0800 Subject: [PATCH 16/17] fix TDD CRASH Signed-off-by: lee --- frameworks/inner/include/bluetooth_profile_manager.h | 7 +------ frameworks/inner/src/bluetooth_host.cpp | 5 ----- frameworks/inner/src/bluetooth_profile_manager.cpp | 7 ++----- interfaces/inner_api/include/bluetooth_host.h | 2 -- 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/frameworks/inner/include/bluetooth_profile_manager.h b/frameworks/inner/include/bluetooth_profile_manager.h index a6f88694..6aca4a0b 100644 --- a/frameworks/inner/include/bluetooth_profile_manager.h +++ b/frameworks/inner/include/bluetooth_profile_manager.h @@ -92,11 +92,6 @@ public: */ static void ClearSystemAbility(); - /** - * @brief clear resource when dlclose - */ - void Close(); - static BluetoothProfileManager &GetInstance(); private: @@ -116,7 +111,7 @@ private: SafeMap profileIdFuncMap_; std::atomic_bool isBluetoothServiceOn_ = false; std::atomic_bool isNeedCheckBluetoothServiceOn_ = true; - sptr bluetoothSystemAbility_ = nullptr; + static sptr bluetoothSystemAbility_; int32_t registerValidId_ = BEGIN_ID; std::mutex idMutex_; std::mutex getProfileRemoteMutex_; diff --git a/frameworks/inner/src/bluetooth_host.cpp b/frameworks/inner/src/bluetooth_host.cpp index e12535e9..de33b352 100644 --- a/frameworks/inner/src/bluetooth_host.cpp +++ b/frameworks/inner/src/bluetooth_host.cpp @@ -1311,10 +1311,5 @@ int32_t BluetoothHost::ProcessRandomDeviceIdCommand( CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr"); return proxy->ProcessRandomDeviceIdCommand(command, deviceIdVec, isValid); } - -void BluetoothHost::CleanResourceWhenDlclose() -{ - BluetoothProfileManager::GetInstance().Close(); -} } // namespace Bluetooth } // namespace OHOS diff --git a/frameworks/inner/src/bluetooth_profile_manager.cpp b/frameworks/inner/src/bluetooth_profile_manager.cpp index c68ffcf7..d95fed46 100644 --- a/frameworks/inner/src/bluetooth_profile_manager.cpp +++ b/frameworks/inner/src/bluetooth_profile_manager.cpp @@ -33,6 +33,8 @@ namespace OHOS { namespace Bluetooth { +sptr BluetoothProfileManager::bluetoothSystemAbility_ = nullptr; + BluetoothProfileManager::BluetoothProfileManager() { bluetoothSystemAbility_ = new BluetoothSystemAbility(); @@ -51,11 +53,6 @@ BluetoothProfileManager &BluetoothProfileManager::GetInstance() } extern "C" __attribute__((destructor)) void BluetoothProfileManager::ClearSystemAbility() -{ - BluetoothHost::GetDefaultHost().CleanResourceWhenDlclose(); -} - -void BluetoothProfileManager::Close() { sptr samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); CHECK_AND_RETURN_LOG(samgrProxy != nullptr, "[BLUETOOTH_PROFILE_MANAGER] failed to get samgrProxy"); diff --git a/interfaces/inner_api/include/bluetooth_host.h b/interfaces/inner_api/include/bluetooth_host.h index 2b2dd7d4..04feabfe 100644 --- a/interfaces/inner_api/include/bluetooth_host.h +++ b/interfaces/inner_api/include/bluetooth_host.h @@ -855,8 +855,6 @@ public: int64_t GetRefusePolicyProhibitedTime(); int32_t ProcessRandomDeviceIdCommand(int32_t command, std::vector &deviceIdVec, bool &isValid); - - void CleanResourceWhenDlclose(); private: /** * @brief A constructor used to create a BluetoothHost instance. -- Gitee From 6cf4721260dd8b1fff336ac6faed44a3fd21aaad Mon Sep 17 00:00:00 2001 From: shinezxy Date: Mon, 7 Apr 2025 21:49:13 +0800 Subject: [PATCH 17/17] add get device uuid check bt enable Signed-off-by: shinezxy --- frameworks/inner/src/bluetooth_remote_device.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/inner/src/bluetooth_remote_device.cpp b/frameworks/inner/src/bluetooth_remote_device.cpp index 35cf7683..13c5904d 100644 --- a/frameworks/inner/src/bluetooth_remote_device.cpp +++ b/frameworks/inner/src/bluetooth_remote_device.cpp @@ -275,6 +275,7 @@ int BluetoothRemoteDevice::GetDeviceUuids(std::vector &uuids) const { HILOGI("enter"); CHECK_AND_RETURN_LOG_RET(IsValidBluetoothRemoteDevice(), BT_ERR_INTERNAL_ERROR, "Invalid remote device"); + CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr hostProxy = GetRemoteProxy(BLUETOOTH_HOST); CHECK_AND_RETURN_LOG_RET(hostProxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr."); return hostProxy->GetDeviceUuids(address_, uuids); -- Gitee