diff --git a/bundle.json b/bundle.json index b52073198c24e5f2ba2c0977b19bb978d8256cdc..e3dd35de5fefd5cef63f1f88e8d7db7a06ed73e7 100755 --- a/bundle.json +++ b/bundle.json @@ -32,7 +32,8 @@ "memmgr", "safwk", "samgr", - "eventhandler" + "eventhandler", + "hicollie" ], "third_party": [] }, diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index 5b048b1b2505e73ba7debfbd6a65e7474df2c870..54f979cb72bf3d7abaa3eb575cbf0c652e5361ac 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -87,6 +87,7 @@ ohos_shared_library("libsensor_client") { external_deps = [ "c_utils:utils", "eventhandler:libeventhandler", + "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_single", "samgr:samgr_proxy", diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index caeb154dcfd4dd891f679a560d47e941d8eeb0ab..2b10d9025f8c2cfc577b9b942084884bb9ee1067 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -17,6 +17,7 @@ #include "print_sensor_data.h" #include "sensor_service_client.h" +#include "sensor_xcollie.h" #undef LOG_TAG #define LOG_TAG "SensorAgentProxy" using namespace OHOS::HiviewDFX; @@ -110,7 +111,10 @@ int32_t SensorAgentProxy::CreateSensorDataChannel() SEN_HILOGE("Create data channel failed, ret:%{public}d", ret); return ret; } - ret = SEN_CLIENT.TransferDataChannel(dataChannel_); + { + SensorXcollie SensorXcollie("SensorAgentProxy:TransferDataChannel", XCOLLIE_TIMEOUT_5S); + ret = SEN_CLIENT.TransferDataChannel(dataChannel_); + } if (ret != ERR_OK) { auto destroyRet = dataChannel_->DestroySensorDataChannel(); SEN_HILOGE("Transfer data channel failed, ret:%{public}d, destroyRet:%{public}d", ret, destroyRet); @@ -135,7 +139,10 @@ int32_t SensorAgentProxy::DestroySensorDataChannel() SEN_HILOGE("Destroy data channel failed, ret:%{public}d", ret); return ret; } - ret = SEN_CLIENT.DestroyDataChannel(); + { + SensorXcollie SensorXcollie("SensorAgentProxy:DestroyDataChannel", XCOLLIE_TIMEOUT_5S); + ret = SEN_CLIENT.DestroyDataChannel(); + } if (ret != ERR_OK) { SEN_HILOGE("Destroy service data channel fail, ret:%{public}d", ret); return ret; @@ -168,7 +175,11 @@ int32_t SensorAgentProxy::ActivateSensor(int32_t sensorId, const SensorUser *use SEN_HILOGE("Subscribe user first"); return ERROR; } - int32_t ret = SEN_CLIENT.EnableSensor(sensorId, samplingInterval_, reportInterval_); + int32_t ret = 0; + { + SensorXcollie SensorXcollie("SensorAgentProxy:EnableSensor", XCOLLIE_TIMEOUT_15S); + ret = SEN_CLIENT.EnableSensor(sensorId, samplingInterval_, reportInterval_); + } if (ret != 0) { SEN_HILOGE("Enable sensor failed, ret:%{public}d", ret); subscribeSet.erase(user); @@ -207,7 +218,11 @@ int32_t SensorAgentProxy::DeactivateSensor(int32_t sensorId, const SensorUser *u subscribeSet.erase(user); if (subscribeSet.empty()) { subscribeMap_.erase(sensorId); - int32_t ret = SEN_CLIENT.DisableSensor(sensorId); + int32_t ret = 0; + { + SensorXcollie SensorXcollie("SensorAgentProxy:DisableSensor", XCOLLIE_TIMEOUT_15S); + ret = SEN_CLIENT.DisableSensor(sensorId); + } if (ret != 0) { SEN_HILOGE("DisableSensor failed, ret:%{public}d", ret); return ret; @@ -352,7 +367,11 @@ void SensorAgentProxy::ClearSensorInfos() const int32_t SensorAgentProxy::ConvertSensorInfos() const { CALL_LOG_ENTER; - std::vector sensorList = SEN_CLIENT.GetSensorList(); + std::vector sensorList; + { + SensorXcollie SensorXcollie("SensorAgentProxy:GetSensorList", XCOLLIE_TIMEOUT_5S); + sensorList = SEN_CLIENT.GetSensorList(); + } if (sensorList.empty()) { SEN_HILOGE("Get sensor lists failed"); return ERROR; @@ -416,7 +435,11 @@ int32_t SensorAgentProxy::SuspendSensors(int32_t pid) SEN_HILOGE("Pid is invalid, pid:%{public}d", pid); return PARAMETER_ERROR; } - int32_t ret = SEN_CLIENT.SuspendSensors(pid); + int32_t ret = 0; + { + SensorXcollie SensorXcollie("SensorAgentProxy:SuspendSensors", XCOLLIE_TIMEOUT_5S); + ret = SEN_CLIENT.SuspendSensors(pid); + } if (ret != ERR_OK) { SEN_HILOGD("Suspend sensors failed, ret:%{public}d", ret); } @@ -430,7 +453,11 @@ int32_t SensorAgentProxy::ResumeSensors(int32_t pid) SEN_HILOGE("Pid is invalid, pid:%{public}d", pid); return PARAMETER_ERROR; } - int32_t ret = SEN_CLIENT.ResumeSensors(pid); + int32_t ret = 0; + { + SensorXcollie SensorXcollie("SensorAgentProxy:ResumeSensors", XCOLLIE_TIMEOUT_5S); + ret = SEN_CLIENT.ResumeSensors(pid); + } if (ret != ERR_OK) { SEN_HILOGD("Resume sensors failed, ret:%{public}d", ret); } @@ -453,7 +480,11 @@ int32_t SensorAgentProxy::GetSensorActiveInfos(int32_t pid, sensorActiveInfos_ = nullptr; } std::vector activeInfoList; - int32_t ret = SEN_CLIENT.GetActiveInfoList(pid, activeInfoList); + int32_t ret = 0; + { + SensorXcollie SensorXcollie("SensorAgentProxy:GetActiveInfoList", XCOLLIE_TIMEOUT_5S); + ret = SEN_CLIENT.GetActiveInfoList(pid, activeInfoList); + } if (ret != ERR_OK) { SEN_HILOGE("Get active info list failed, ret:%{public}d", ret); return ret; @@ -487,7 +518,11 @@ int32_t SensorAgentProxy::Register(SensorActiveInfoCB callback) { CHKPR(callback, OHOS::Sensors::ERROR); CHKPR(dataChannel_, INVALID_POINTER); - int32_t ret = SEN_CLIENT.Register(callback, dataChannel_); + int32_t ret = 0; + { + SensorXcollie SensorXcollie("SensorAgentProxy:Register", XCOLLIE_TIMEOUT_5S); + ret = SEN_CLIENT.Register(callback, dataChannel_); + } if (ret != ERR_OK) { SEN_HILOGE("Register sensor active info callback failed, ret:%{public}d", ret); } @@ -497,7 +532,11 @@ int32_t SensorAgentProxy::Register(SensorActiveInfoCB callback) int32_t SensorAgentProxy::Unregister(SensorActiveInfoCB callback) { CHKPR(callback, OHOS::Sensors::ERROR); - int32_t ret = SEN_CLIENT.Unregister(callback); + int32_t ret = 0; + { + SensorXcollie SensorXcollie("SensorAgentProxy:Unregister", XCOLLIE_TIMEOUT_5S); + ret = SEN_CLIENT.Unregister(callback); + } if (ret != ERR_OK) { SEN_HILOGE("Unregister sensor active info callback failed, ret:%{public}d", ret); } @@ -506,7 +545,11 @@ int32_t SensorAgentProxy::Unregister(SensorActiveInfoCB callback) int32_t SensorAgentProxy::ResetSensors() const { - int32_t ret = SEN_CLIENT.ResetSensors(); + int32_t ret = 0; + { + SensorXcollie SensorXcollie("SensorAgentProxy:ResetSensors", XCOLLIE_TIMEOUT_5S); + ret = SEN_CLIENT.ResetSensors(); + } if (ret != ERR_OK) { SEN_HILOGE("Reset sensors failed, ret:%{public}d", ret); } diff --git a/utils/common/BUILD.gn b/utils/common/BUILD.gn index e250a34d364786876a0c58d1baab2204a4fe2238..84ff5e44328d45a81455a8f1a40189fd6311afaf 100644 --- a/utils/common/BUILD.gn +++ b/utils/common/BUILD.gn @@ -24,6 +24,7 @@ ohos_shared_library("libsensor_utils") { "src/sensor_basic_data_channel.cpp", "src/sensor_basic_info.cpp", "src/sensor_channel_info.cpp", + "src/sensor_xcollie.cpp", ] cflags = [ @@ -55,6 +56,7 @@ ohos_shared_library("libsensor_utils") { "access_token:libaccesstoken_sdk", "access_token:libprivacy_sdk", "c_utils:utils", + "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_single", ] diff --git a/utils/common/include/sensor_xcollie.h b/utils/common/include/sensor_xcollie.h new file mode 100644 index 0000000000000000000000000000000000000000..34f540559e3ce132ea171b36079a00eb1c0e689c --- /dev/null +++ b/utils/common/include/sensor_xcollie.h @@ -0,0 +1,41 @@ +/* +* 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 MISCDEVICE_XCOLLIE_H +#define MISCDEVICE_XCOLLIE_H + +#include + +#include "xcollie/xcollie.h" +#include "xcollie/xcollie_define.h" + +namespace OHOS { +namespace Sensors { +const unsigned int XCOLLIE_TIMEOUT_15S = 15; +const unsigned int XCOLLIE_TIMEOUT_5S = 5; + +class SensorXcollie { +public: + SensorXcollie(const std::string& tag, unsigned int timeoutSeconds = 10, + std::function func = nullptr, void *arg = nullptr, + unsigned int flag = HiviewDFX::XCOLLIE_FLAG_LOG); + ~SensorXcollie(); +private: + int id_; + std::string tag_; +}; +} // namespace Sensors +} // namespace OHOS +#endif // MISCDEVICE_XCOLLIE_H diff --git a/utils/common/src/sensor_xcollie.cpp b/utils/common/src/sensor_xcollie.cpp new file mode 100644 index 0000000000000000000000000000000000000000..527c774b95c9d85c9bf3edca0b5064750185a0d6 --- /dev/null +++ b/utils/common/src/sensor_xcollie.cpp @@ -0,0 +1,32 @@ +/* +* 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. +*/ + +#include "sensor_xcollie.h" + +namespace OHOS { +namespace Sensors { +SensorXcollie::SensorXcollie(const std::string& tag, unsigned int timeoutSeconds, + std::function func, void *arg, unsigned int flag) +{ + id_ = HiviewDFX::XCollie::GetInstance().SetTimer(tag, timeoutSeconds, func, arg, flag); + tag_ = tag; +} + +SensorXcollie::~SensorXcollie() +{ + HiviewDFX::XCollie::GetInstance().CancelTimer(id_); +} +} // namespace Sensors +} // namespace OHOS \ No newline at end of file