diff --git a/bundle.json b/bundle.json index b77272fde39fbdb7b3a2706a22abc0d35b93e814..f6b8e5b9b342b2b53efde46108accfbd6ca9f80a 100644 --- a/bundle.json +++ b/bundle.json @@ -63,6 +63,7 @@ "hicollie", "hilog", "hisysevent", + "hiappevent", "hitrace", "init", "ipc", diff --git a/frameworks/inner/BUILD.gn b/frameworks/inner/BUILD.gn index 85c789019f22527957dff59cf87766c2c26b70a5..1718da4a5e8207c9e1d35843a6fbf747b15f2d74 100644 --- a/frameworks/inner/BUILD.gn +++ b/frameworks/inner/BUILD.gn @@ -62,6 +62,7 @@ FwkSrc = [ "src/bluetooth_audio_manager.cpp", "src/uuid.cpp", "src/bluetooth_switch_module.cpp", + "src/api_event_util.cpp", ] BT_IPCSRC_DIR = "ipc/src" @@ -157,6 +158,7 @@ ohos_shared_library("btframework") { "init:libbegetutil", "ipc:ipc_core", "samgr:samgr_proxy", + "hiappevent:hiappevent_innerapi", ] if (bluetooth_service_resourceschedule) { diff --git a/frameworks/inner/include/api_event_util.h b/frameworks/inner/include/api_event_util.h new file mode 100644 index 0000000000000000000000000000000000000000..6a01edf36def6b8609ec0ca0fe0f7bae43611a9d --- /dev/null +++ b/frameworks/inner/include/api_event_util.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef API_EVENT_UTIL_H +#define API_EVENT_UTIL_H + +#include +#include + +namespace OHOS { +namespace Bluetooth { + +enum ApiResult { + RESULT_SUCCESS = 0, + RESULT_FAILED +}; + +class ApiEventUtil { +public: + explicit ApiEventUtil(const std::string &apiName); + ~ApiEventUtil(); + void WriteEndEvent(const int32_t result, const int32_t errCode); + +private: + ApiEventUtil() = delete; + static void GenerateProcessorId(); + static int64_t AddProcessor(); + int64_t GetNowTimeMs() const; + std::string RandomTransId() const; + void WriteEndEvent() const; + +private: + static int64_t processorId_; + static std::mutex processorLock_; + std::string apiName_; + int64_t beginTime_; + int32_t result_; + int32_t errCode_; +}; + +} // namespace Bluetooth +} // namespace OHOS +#endif /* API_EVENT_UTIL_H */ + diff --git a/frameworks/inner/src/api_event_util.cpp b/frameworks/inner/src/api_event_util.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c72619ad67c8ff32dcf33312324041678b6bec45 --- /dev/null +++ b/frameworks/inner/src/api_event_util.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2025-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LOG_TAG +#define LOG_TAG "bt_api_event_util" +#endif + +#include "api_event_util.h" +#include "bluetooth_log.h" +#include "bluetooth_errorcode.h" +#include "app_event.h" +#include "app_event_processor_mgr.h" + +namespace OHOS { +namespace Bluetooth { + +constexpr int64_t INVALID_PROCESSOR_ID = -200; +const std::string SDK_NAME = "ConnectivityKit"; +constexpr int32_t TIMEOUT = 90; // 每90s触发上报一次 +constexpr int32_t ROW = 30; // 或30条数据触发一次上报 +constexpr int32_t TIME_MS_PER_SECOND = 1000; +constexpr int32_t TIME_NS_PER_MS = 1000000; + +int64_t ApiEventUtil::processorId_ = -1; +std::mutex ApiEventUtil::processorLock_; + +ApiEventUtil::ApiEventUtil(const std::string &apiName): apiName_(apiName) +{ + beginTime_ = GetNowTimeMs(); + result_ = RESULT_FAILED; + errCode_ = BT_ERR_INTERNAL_ERROR; + GenerateProcessorId(); +} + +ApiEventUtil::~ApiEventUtil() +{ + WriteEndEvent(); +} + +void ApiEventUtil::WriteEndEvent(const int32_t result, const int32_t errCode) +{ + result_ = result; + errCode_ = errCode; +} + +void ApiEventUtil::GenerateProcessorId() +{ + std::lock_guard lock(processorLock_); + if (processorId_ == -1) { + processorId_ = AddProcessor(); + HILOGW("add processorId:%{public}lld", processorId_); + } + + if (processorId_ == INVALID_PROCESSOR_ID) { + HILOGE("invaild processorId !!!"); + return; + } +} + +int64_t ApiEventUtil::GetNowTimeMs() const +{ + struct timespec ts = {}; + clock_gettime(CLOCK_BOOTTIME, &ts); + return (int64_t)ts.tv_sec * TIME_MS_PER_SECOND + (int64_t)ts.tv_nsec / TIME_NS_PER_MS; +} + +int64_t ApiEventUtil::AddProcessor() +{ + HiviewDFX::HiAppEvent::ReportConfig config; + config.name = "ha_app_event"; // 系统预制so,实现上报功能,由HA提供 + config.appId = "com_huawei_hmos_sdk_ocg"; + config.routeInfo = "AUTO"; + config.triggerCond.timeout = TIMEOUT; + config.triggerCond.row = ROW; + config.eventConfigs.clear(); + { // 固定内容,所有Kit全量完整复制,不允许修改 + OHOS::HiviewDFX::HiAppEvent::EventConfig event1; + event1.domain = "api_diagnostic"; + event1.name = "api_exec_end"; + event1.isRealTime = false; + config.eventConfigs.push_back(event1); + } + { // 固定内容,所有Kit全量完整复制,不允许修改 + OHOS::HiviewDFX::HiAppEvent::EventConfig event2; + event2.domain = "api_diagnostic"; + event2.name = "api_called_stat"; + event2.isRealTime = true; + config.eventConfigs.push_back(event2); + } + { // 固定内容,所有Kit全量完整复制,不允许修改 + OHOS::HiviewDFX::HiAppEvent::EventConfig event3; + event3.domain = "api_diagnostic"; + event3.name = "api_called_stat_cnt"; + event3.isRealTime = true; + config.eventConfigs.push_back(event3); + } + return HiviewDFX::HiAppEvent::AppEventProcessorMgr::AddProcessor(config); +} + +std::string ApiEventUtil::RandomTransId() const +{ + return std::string("transId_") + std::to_string(std::rand()); +} + +void ApiEventUtil::WriteEndEvent() const +{ + HiviewDFX::HiAppEvent::Event event("api_diagnostic", "api_exec_end", HiviewDFX::HiAppEvent::BEHAVIOR); + std::string transId = RandomTransId(); + event.AddParam("trans_id", transId); + event.AddParam("api_name", apiName_); + event.AddParam("sdk_name", SDK_NAME); + event.AddParam("begin_time", beginTime_); + event.AddParam("end_time", GetNowTimeMs()); + event.AddParam("result", result_); + event.AddParam("error_code", errCode_); + int ret = Write(event); + HILOGD("WriteEndEvent transId:%{public}s, apiName:%{public}s, sdkName:%{public}s, " + "result:%{public}d, errCode:%{public}d, ret:%{public}d", + transId.c_str(), apiName_.c_str(), SDK_NAME.c_str(), result_, errCode_, ret); +} + +} // namespace Bluetooth +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/inner/src/bluetooth_a2dp_src.cpp b/frameworks/inner/src/bluetooth_a2dp_src.cpp index 3b9b5a3bb31ec8f89e2cb8647d4210a125bd15f7..af0b10eeaa2819667533bbe1903c58c67bb16054 100644 --- a/frameworks/inner/src/bluetooth_a2dp_src.cpp +++ b/frameworks/inner/src/bluetooth_a2dp_src.cpp @@ -31,6 +31,7 @@ #include "bluetooth_log.h" #include "bluetooth_utils.h" +#include "api_event_util.h" #include "iservice_registry.h" #include "system_ability_definition.h" @@ -271,38 +272,50 @@ int32_t A2dpSource::GetPlayingState(const BluetoothRemoteDevice &device, int &st int32_t A2dpSource::Connect(const BluetoothRemoteDevice &device) { HILOGI("a2dp connect remote device: %{public}s", GET_ENCRYPT_ADDR(device)); + ApiEventUtil haUtil("a2dp.A2dpSourceProfile.Connect"); if (!IS_BT_ENABLED()) { HILOGE("bluetooth is off."); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_STATE); return BT_ERR_INVALID_STATE; } sptr proxy = GetRemoteProxy(PROFILE_A2DP_SRC); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_UNAVAILABLE_PROXY); CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); if (!device.IsValidBluetoothRemoteDevice()) { HILOGE("input parameter error."); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_PARAM); return BT_ERR_INVALID_PARAM; } - return proxy->Connect(RawAddress(device.GetDeviceAddr())); + int32_t ret = proxy->Connect(RawAddress(device.GetDeviceAddr())); + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); + return ret; } int32_t A2dpSource::Disconnect(const BluetoothRemoteDevice &device) { HILOGI("a2dp disconnect remote device: %{public}s", GET_ENCRYPT_ADDR(device)); + ApiEventUtil haUtil("a2dp.A2dpSourceProfile.Disconnect"); if (!IS_BT_ENABLED()) { HILOGE("bluetooth is off."); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_STATE); return BT_ERR_INVALID_STATE; } sptr proxy = GetRemoteProxy(PROFILE_A2DP_SRC); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_UNAVAILABLE_PROXY); CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "failed: no proxy"); if (!device.IsValidBluetoothRemoteDevice()) { HILOGE("input parameter error."); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_PARAM); return BT_ERR_INVALID_PARAM; } - return proxy->Disconnect(RawAddress(device.GetDeviceAddr())); + int32_t ret = proxy->Disconnect(RawAddress(device.GetDeviceAddr())); + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); + return ret; } A2dpSource *A2dpSource::GetProfile() diff --git a/frameworks/inner/src/bluetooth_ble_advertiser.cpp b/frameworks/inner/src/bluetooth_ble_advertiser.cpp index 91805659093b1772b7d256b019cee8fec0f18fe7..57c0375f62c141046e5f875bc8240c7457d9b272 100644 --- a/frameworks/inner/src/bluetooth_ble_advertiser.cpp +++ b/frameworks/inner/src/bluetooth_ble_advertiser.cpp @@ -24,6 +24,7 @@ #include "bluetooth_log.h" #include "bluetooth_observer_map.h" #include "bluetooth_utils.h" +#include "api_event_util.h" #include "i_bluetooth_ble_advertiser.h" #include "iservice_registry.h" #include "system_ability_definition.h" @@ -329,8 +330,10 @@ int32_t BleAdvertiser::impl::CheckAdvertiserData(const BluetoothBleAdvertiserSet int BleAdvertiser::StartAdvertising(const BleAdvertiserSettings &settings, const BleAdvertiserData &advData, const BleAdvertiserData &scanResponse, uint16_t duration, std::shared_ptr callback) { + ApiEventUtil haUtil("StartAdvertising"); if (!IS_BLE_ENABLED()) { HILOGE("bluetooth is off."); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_STATE); return BT_ERR_INVALID_STATE; } sptr proxy = GetRemoteProxy(BLE_ADVERTISER_SERVER); @@ -338,9 +341,8 @@ int BleAdvertiser::StartAdvertising(const BleAdvertiserSettings &settings, const CHECK_AND_RETURN_LOG_RET(callback != nullptr, BT_ERR_INTERNAL_ERROR, "callback is nullptr"); int ret = pimpl->CheckAdvertiserSettings(settings); - if (ret != BT_NO_ERROR) { - return ret; - } + haUtil.WriteEndEvent(RESULT_FAILED, ret); + CHECK_AND_RETURN_LOG_RET(ret == BT_NO_ERROR, ret, "check advsersettings failed"); BluetoothBleAdvertiserSettings setting; setting.SetConnectable(settings.IsConnectable()); setting.SetInterval(settings.GetInterval()); @@ -356,9 +358,7 @@ int BleAdvertiser::StartAdvertising(const BleAdvertiserSettings &settings, const pimpl->ConvertBleAdvertiserData(scanResponse, bleScanResponse); ret = pimpl->CheckAdvertiserData(setting, bleAdvertiserData, bleScanResponse); - if (ret != BT_NO_ERROR) { - return ret; - } + CHECK_AND_RETURN_LOG_RET(ret == BT_NO_ERROR, ret, "check advsersdate failed"); HILOGD("duration=%{public}d", duration); int32_t advHandle = BLE_INVALID_ADVERTISING_HANDLE; @@ -369,20 +369,24 @@ int BleAdvertiser::StartAdvertising(const BleAdvertiserSettings &settings, const 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)); + haUtil.WriteEndEvent(RESULT_FAILED, ret); return ret; } callback->OnGetAdvHandleEvent(0, advHandle); pimpl->callbacks_.Register(advHandle, callback); ret = proxy->StartAdvertising(setting, bleAdvertiserData, bleScanResponse, advHandle, duration, false); } + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); return ret; } int BleAdvertiser::StartAdvertising(const BleAdvertiserSettings &settings, const std::vector &advData, const std::vector &scanResponse, uint16_t duration, std::shared_ptr callback) { + ApiEventUtil haUtil("StartAdvertising"); if (!IS_BLE_ENABLED()) { HILOGE("bluetooth is off."); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_STATE); return BT_ERR_INVALID_STATE; } @@ -392,6 +396,7 @@ int BleAdvertiser::StartAdvertising(const BleAdvertiserSettings &settings, const int ret = pimpl->CheckAdvertiserSettings(settings); if (ret != BT_NO_ERROR) { + haUtil.WriteEndEvent(RESULT_FAILED, ret); return ret; } BluetoothBleAdvertiserSettings setting; @@ -417,11 +422,13 @@ int BleAdvertiser::StartAdvertising(const BleAdvertiserSettings &settings, const if (ret != BT_NO_ERROR || advHandle == BLE_INVALID_ADVERTISING_HANDLE) { HILOGE("Invalid advertising handle"); callback->OnStartResultEvent(BT_ERR_INTERNAL_ERROR, BLE_INVALID_ADVERTISING_HANDLE); + haUtil.WriteEndEvent(RESULT_FAILED, ret); return ret; } pimpl->callbacks_.Register(advHandle, callback); ret = proxy->StartAdvertising(setting, bleAdvertiserData, bleScanResponse, advHandle, duration, true); } + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); return ret; } @@ -528,8 +535,10 @@ int BleAdvertiser::DisableAdvertising(uint8_t advHandle, std::shared_ptr callback) { + ApiEventUtil haUtil("StopAdvertising"); if (!IS_BLE_ENABLED()) { HILOGE("bluetooth is off."); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_STATE); return BT_ERR_INVALID_STATE; } @@ -545,6 +554,7 @@ int BleAdvertiser::StopAdvertising(std::shared_ptr callbac } int ret = proxy->StopAdvertising(advHandle); + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); return ret; } diff --git a/frameworks/inner/src/bluetooth_ble_central_manager.cpp b/frameworks/inner/src/bluetooth_ble_central_manager.cpp index d576208ea8b92f1c9e611529bf5dff8154538b52..c60bd462e6eac16f159180062daa42487e4ee4fd 100644 --- a/frameworks/inner/src/bluetooth_ble_central_manager.cpp +++ b/frameworks/inner/src/bluetooth_ble_central_manager.cpp @@ -23,6 +23,7 @@ #include "bluetooth_log.h" #include "bluetooth_observer_list.h" #include "bluetooth_utils.h" +#include "api_event_util.h" #include "i_bluetooth_ble_central_manager.h" #include "iservice_registry.h" #include "system_ability_definition.h" @@ -345,13 +346,16 @@ BleCentralManager::~BleCentralManager() int BleCentralManager::StartScan(const BleScanSettings &settings, const std::vector &filters) { + ApiEventUtil haUtil("StartScan"); if (!IS_BLE_ENABLED()) { HILOGD("bluetooth is off."); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_STATE); return BT_ERR_INVALID_STATE; } int ret = pimpl->CheckScanParams(settings, filters, true); if (ret != BT_NO_ERROR) { + haUtil.WriteEndEvent(RESULT_FAILED, ret); return ret; } @@ -371,13 +375,17 @@ int BleCentralManager::StartScan(const BleScanSettings &settings, const std::vec sptr proxy = GetRemoteProxy(BLE_CENTRAL_MANAGER_SERVER); CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "failed: no proxy"); - return proxy->StartScan(pimpl->scannerId_, parcelSettings, parcelFilters, isNewApi_); + ret = proxy->StartScan(pimpl->scannerId_, parcelSettings, parcelFilters, isNewApi_); + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); + return ret; } int BleCentralManager::StopScan() { + ApiEventUtil haUtil("StopScan"); if (!IS_BLE_ENABLED()) { HILOGD("bluetooth is off."); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_STATE); return BT_ERR_INVALID_STATE; } @@ -393,6 +401,7 @@ int BleCentralManager::StopScan() int ret = proxy->StopScan(pimpl->scannerId_); proxy->RemoveScanFilter(pimpl->scannerId_); + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); return ret; } diff --git a/frameworks/inner/src/bluetooth_gatt_client.cpp b/frameworks/inner/src/bluetooth_gatt_client.cpp index e1bcaa525b5e51d023167d3f4cb27fc35b74a9a5..921550e0c02cfc204bbec9eedda167ff846acb9a 100644 --- a/frameworks/inner/src/bluetooth_gatt_client.cpp +++ b/frameworks/inner/src/bluetooth_gatt_client.cpp @@ -28,6 +28,7 @@ #include "bluetooth_host_proxy.h" #include "bluetooth_log.h" #include "bluetooth_utils.h" +#include "api_event_util.h" #include "gatt_data.h" #include "i_bluetooth_gatt_client.h" #include "iservice_registry.h" @@ -612,11 +613,27 @@ GattClient::~GattClient() } } +bool GattClient::CheckIsSupportMode(bool isAutoConnect, int transport) const +{ + if ((transport == GATT_TRANSPORT_TYPE_LE && !IS_BLE_ENABLED()) || + (transport == GATT_TRANSPORT_TYPE_CLASSIC && !IS_BT_ENABLED())) { + HILOGE("Unsupported mode"); + return false; + } + if (transport == GATT_TRANSPORT_TYPE_CLASSIC && isAutoConnect) { + HILOGE("AutoConnect Unsupported mode"); + return false; + } + return true; +} + int GattClient::Connect(std::weak_ptr callback, bool isAutoConnect, int transport) { HILOGI("enter, isAutoConnect: %{public}d, transport: %{public}d", isAutoConnect, transport); + ApiEventUtil haUtil("ble.GattClientDevice.Connect"); if (!IS_BLE_ENABLED()) { HILOGE("bluetooth is off."); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_STATE); return BT_ERR_INVALID_STATE; } @@ -637,13 +654,7 @@ int GattClient::Connect(std::weak_ptr callback, bool isAutoC return proxy->Connect(pimpl->applicationId_, isAutoConnect); } pimpl->callback_ = callback; - if ((transport == GATT_TRANSPORT_TYPE_LE && !IS_BLE_ENABLED()) || - (transport == GATT_TRANSPORT_TYPE_CLASSIC && !IS_BT_ENABLED())) { - HILOGE("Unsupported mode"); - return BT_ERR_INTERNAL_ERROR; - } - if (transport == GATT_TRANSPORT_TYPE_CLASSIC && isAutoConnect) { - HILOGE("Unsupported mode"); + if (!CheckIsSupportMode(isAutoConnect, transport)) { return BT_ERR_INTERNAL_ERROR; } if (!pimpl->device_.IsValidBluetoothRemoteDevice()) { @@ -657,6 +668,7 @@ int GattClient::Connect(std::weak_ptr callback, bool isAutoC HILOGI("Proxy register application : %{public}d", appId); if (result != BT_NO_ERROR) { HILOGE("register application fail"); + haUtil.WriteEndEvent(RESULT_FAILED, result); return result; } if (appId > 0) { @@ -664,14 +676,17 @@ int GattClient::Connect(std::weak_ptr callback, bool isAutoC pimpl->isRegisterSucceeded_ = true; result = proxy->Connect(pimpl->applicationId_, isAutoConnect); } + haUtil.WriteEndEvent((result == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, result); return result; } int GattClient::Disconnect() { HILOGI("enter"); + ApiEventUtil haUtil("ble.GattClientDevice.Disconnect"); if (!IS_BLE_ENABLED()) { HILOGE("bluetooth is off."); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_STATE); return BT_ERR_INVALID_STATE; } @@ -689,6 +704,7 @@ int GattClient::Disconnect() sptr proxy = GetRemoteProxy(PROFILE_GATT_CLIENT); CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_INTERNAL_ERROR, "failed: no proxy"); result = proxy->Disconnect(pimpl->applicationId_); + haUtil.WriteEndEvent((result == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, result); return result; } diff --git a/frameworks/inner/src/bluetooth_hfp_ag.cpp b/frameworks/inner/src/bluetooth_hfp_ag.cpp index aafa3a00b1c52f92cfd5d2b81a22d023da94c3d7..d94605ddd4085d5833e9eed02716e333b4b93c14 100644 --- a/frameworks/inner/src/bluetooth_hfp_ag.cpp +++ b/frameworks/inner/src/bluetooth_hfp_ag.cpp @@ -23,6 +23,7 @@ #include "bluetooth_profile_manager.h" #include "bluetooth_log.h" #include "bluetooth_utils.h" +#include "api_event_util.h" #include "bluetooth_observer_list.h" #include "bluetooth_phone_state.h" #include "i_bluetooth_hfp_ag.h" @@ -167,23 +168,31 @@ struct HandsFreeAudioGateway::impl { int32_t Connect(const BluetoothRemoteDevice &device) { HILOGI("hfp connect remote device: %{public}s", GET_ENCRYPT_ADDR(device)); + ApiEventUtil haUtil("hfp.HandsFreeAudioGatewayProfile.Connect"); sptr proxy = GetRemoteProxy(PROFILE_HFP_AG); if (proxy == nullptr || !device.IsValidBluetoothRemoteDevice()) { HILOGE("invalid param."); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_PARAM); return BT_ERR_INVALID_PARAM; } - return proxy->Connect(BluetoothRawAddress(device.GetDeviceAddr())); + int32_t ret = proxy->Connect(BluetoothRawAddress(device.GetDeviceAddr())); + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); + return ret; } int32_t Disconnect(const BluetoothRemoteDevice &device) { HILOGI("hfp disconnect remote device: %{public}s", GET_ENCRYPT_ADDR(device)); + ApiEventUtil haUtil("hfp.HandsFreeAudioGatewayProfile.Disconnect"); sptr proxy = GetRemoteProxy(PROFILE_HFP_AG); if (proxy == nullptr || !device.IsValidBluetoothRemoteDevice()) { HILOGE("invalid param."); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_PARAM); return BT_ERR_INVALID_PARAM; } - return proxy->Disconnect(BluetoothRawAddress(device.GetDeviceAddr())); + int32_t ret = proxy->Disconnect(BluetoothRawAddress(device.GetDeviceAddr())); + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); + return ret; } int GetScoState(const BluetoothRemoteDevice &device) diff --git a/frameworks/inner/src/bluetooth_host.cpp b/frameworks/inner/src/bluetooth_host.cpp index efacb698ec6599659c35a0f77452f080ea397fb8..fb52f9393b83195644648c21b675b139e31a2cbd 100644 --- a/frameworks/inner/src/bluetooth_host.cpp +++ b/frameworks/inner/src/bluetooth_host.cpp @@ -29,6 +29,7 @@ #include "bluetooth_profile_manager.h" #include "bluetooth_log.h" #include "bluetooth_utils.h" +#include "api_event_util.h" #include "bluetooth_observer_list.h" #include "bluetooth_remote_device_observer_stub.h" #include "bluetooth_resource_manager_observer_stub.h" @@ -1086,13 +1087,17 @@ int32_t BluetoothHost::GetPairedDevices(int transport, std::vector proxy = GetRemoteProxy(BLUETOOTH_HOST); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_UNAVAILABLE_PROXY); CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); sptr rawAddrSptr = new BluetoothRawAddress(device.GetDeviceAddr()); - return proxy->RemovePair(device.GetTransportType(), rawAddrSptr); + int32_t ret = proxy->RemovePair(device.GetTransportType(), rawAddrSptr); + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); + return ret; } bool BluetoothHost::RemoveAllPairs() @@ -1174,23 +1179,31 @@ int BluetoothHost::GetRandomAddress(const std::string &realAddr, std::string &ra int BluetoothHost::ConnectAllowedProfiles(const std::string &remoteAddr) const { HILOGI("enter"); + ApiEventUtil haUtil("ConnectAllowedProfiles"); CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_UNAVAILABLE_PROXY); CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "pimpl or bluetooth host is nullptr"); - return proxy->ConnectAllowedProfiles(remoteAddr); + int ret = proxy->ConnectAllowedProfiles(remoteAddr); + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); + return ret; } int BluetoothHost::DisconnectAllowedProfiles(const std::string &remoteAddr) const { HILOGI("enter"); + ApiEventUtil haUtil("DisconnectAllowedProfiles"); CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_UNAVAILABLE_PROXY); CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "pimpl or bluetooth host is nullptr"); - return proxy->DisconnectAllowedProfiles(remoteAddr); + int ret = proxy->DisconnectAllowedProfiles(remoteAddr); + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); + return ret; } void BluetoothHost::RegisterBtResourceManagerObserver(std::shared_ptr observer) diff --git a/frameworks/inner/src/bluetooth_remote_device.cpp b/frameworks/inner/src/bluetooth_remote_device.cpp index 13c5904d8d1788161fbc3dde6f3f57dd3a49ff1c..9017b83e110f91d6a0c38de7d84bfe6b4d1676ff 100644 --- a/frameworks/inner/src/bluetooth_remote_device.cpp +++ b/frameworks/inner/src/bluetooth_remote_device.cpp @@ -25,6 +25,7 @@ #include "bluetooth_host_proxy.h" #include "bluetooth_log.h" #include "bluetooth_utils.h" +#include "api_event_util.h" #include "bluetooth_profile_manager.h" #include "bluetooth_remote_device.h" #include "iservice_registry.h" @@ -188,31 +189,45 @@ int BluetoothRemoteDevice::GetPairState(int &pairState) const int BluetoothRemoteDevice::StartPair() { HILOGI("enter"); + ApiEventUtil haUtil("StartPair"); CHECK_AND_RETURN_LOG_RET(IsValidBluetoothRemoteDevice(), BT_ERR_INTERNAL_ERROR, "Invalid remote device"); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_STATE); CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr hostProxy = GetRemoteProxy(BLUETOOTH_HOST); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INTERNAL_ERROR); CHECK_AND_RETURN_LOG_RET(hostProxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr."); - return hostProxy->StartPair(transport_, address_); + int ret = hostProxy->StartPair(transport_, address_); + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); + return ret; } int BluetoothRemoteDevice::StartCrediblePair() { HILOGI("enter"); + ApiEventUtil haUtil("StartCrediblePair"); CHECK_AND_RETURN_LOG_RET(IsValidBluetoothRemoteDevice(), BT_ERR_INTERNAL_ERROR, "Invalid remote device"); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_STATE); CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr hostProxy = GetRemoteProxy(BLUETOOTH_HOST); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INTERNAL_ERROR); CHECK_AND_RETURN_LOG_RET(hostProxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr."); - return hostProxy->StartCrediblePair(transport_, address_); + int ret = hostProxy->StartCrediblePair(transport_, address_); + haUtil.WriteEndEvent((ret == BT_NO_ERROR) ? RESULT_SUCCESS : RESULT_FAILED, ret); + return ret; } int BluetoothRemoteDevice::CancelPairing() { HILOGI("enter"); + ApiEventUtil haUtil("CancelPairing"); CHECK_AND_RETURN_LOG_RET(IsValidBluetoothRemoteDevice(), BT_ERR_INTERNAL_ERROR, "Invalid remote device"); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INVALID_STATE); CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_ERR_INVALID_STATE, "bluetooth is off."); sptr hostProxy = GetRemoteProxy(BLUETOOTH_HOST); + haUtil.WriteEndEvent(RESULT_FAILED, BT_ERR_INTERNAL_ERROR); CHECK_AND_RETURN_LOG_RET(hostProxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr."); if (hostProxy->CancelPairing(transport_, address_)) { + haUtil.WriteEndEvent(RESULT_SUCCESS, BT_NO_ERROR); return BT_NO_ERROR; } return BT_ERR_INTERNAL_ERROR; diff --git a/frameworks/inner/src/bluetooth_socket.cpp b/frameworks/inner/src/bluetooth_socket.cpp index 28c0427995aca3559a81dbeff1c964f08043bd9f..893946ec1d5c21e5bf982453e4b6d264a19e79da 100644 --- a/frameworks/inner/src/bluetooth_socket.cpp +++ b/frameworks/inner/src/bluetooth_socket.cpp @@ -26,6 +26,7 @@ #include "bluetooth_host.h" #include "bluetooth_host_proxy.h" #include "bluetooth_utils.h" +#include "api_event_util.h" #include "bluetooth_socket_proxy.h" #include "hisysevent.h" #include "ipc_skeleton.h" @@ -429,6 +430,7 @@ bool ClientSocket::Init() int ClientSocket::Connect(int psm) { HILOGD("enter"); + ApiEventUtil haUtil("sppConnect"); CHECK_AND_RETURN_LOG_RET(pimpl != nullptr, BT_ERR_DEVICE_DISCONNECTED, "pimpl is nullptr!"); if (pimpl->type_ == TYPE_L2CAP_LE) { CHECK_AND_RETURN_LOG_RET(IS_BLE_ENABLED(), BT_ERR_INVALID_STATE, "BLE is not TURN_ON"); @@ -461,6 +463,7 @@ int ClientSocket::Connect(int psm) .psm = psm }; ret = proxy->Connect(param, pimpl->fd_); + haUtil.WriteEndEvent(RESULT_FAILED, ret); CHECK_AND_RETURN_LOG_RET(ret == BT_NO_ERROR, ret, "Connect error %{public}d", ret); HILOGI("fd_: %{public}d", pimpl->fd_); @@ -478,6 +481,7 @@ int ClientSocket::Connect(int psm) GetEncryptAddr(tempAddress), "PID", IPCSkeleton::GetCallingPid(), "UID", IPCSkeleton::GetCallingUid()); ReportDataToRss("connect", pimpl->fd_, GetEncryptAddr(tempAddress), IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid()); + haUtil.WriteEndEvent(RESULT_SUCCESS, BtStatus::BT_SUCCESS); return BtStatus::BT_SUCCESS; } diff --git a/interfaces/inner_api/include/bluetooth_gatt_client.h b/interfaces/inner_api/include/bluetooth_gatt_client.h index 8aa2d9e4a71025a18a9089d23927bbb98c1fc843..550228607f768cce0d64fe1b146ef9e9b906d150 100644 --- a/interfaces/inner_api/include/bluetooth_gatt_client.h +++ b/interfaces/inner_api/include/bluetooth_gatt_client.h @@ -384,6 +384,7 @@ private: int SetNotifyCharacteristicInner(GattCharacteristic &characteristic, bool enable, const std::vector &descriptorValue); + bool CheckIsSupportMode(bool isAutoConnect, int transport) const; }; } // namespace Bluetooth } // namespace OHOS