diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 02c4c67fdb21764891f6894f1bcd2dd471ec9873..64f6a848b7a10c021b29c4714163db8e7559e6ef 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -256,6 +256,9 @@ static uint32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value ca std::vector callbackInfos = g_onCallbackInfos[sensorTypeId]; std::vector::iterator iter; for (iter = callbackInfos.begin(); iter != callbackInfos.end(); iter++) { + if (*iter == nullptr || (*iter)->callback[0] == nullptr) { + continue; + } napi_value sensorCallback = nullptr; napi_get_reference_value(env, (*iter)->callback[0], &sensorCallback); if (IsNapiValueSame(env, callback, sensorCallback)) { @@ -264,12 +267,13 @@ static uint32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value ca delete *iter; *iter = nullptr; callbackInfos.erase(iter); - if (callbackInfos.empty()) { - g_onCallbackInfos.erase(sensorTypeId); - return 0; - } + break; } } + if (callbackInfos.empty()) { + g_onCallbackInfos.erase(sensorTypeId); + return 0; + } g_onCallbackInfos[sensorTypeId] = callbackInfos; return callbackInfos.size(); } diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index bc9c43ccc4abd5dc51b8d064345583bb2e0abb39..9b3e1bf382cf754bf8a5adb284f47a2751b9c27a 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -35,8 +35,8 @@ sptr sensorInterface_ = nullptr; sptr eventCallback_ = nullptr; std::map sensorBasicInfoMap_; std::mutex sensorBasicInfoMutex_; -constexpr int32_t GET_HDI_SERVICE_COUNT = 10; -constexpr uint32_t WAIT_MS = 100; +constexpr int32_t GET_HDI_SERVICE_COUNT = 30; +constexpr uint32_t WAIT_MS = 200; } ZReportDataCb HdiConnection::reportDataCb_ = nullptr;