!669 修改数据上报转换数据crash

Merge pull request !669 from 17349030869/master
This commit is contained in:
openharmony_ci 2024-11-09 07:51:42 +00:00 committed by Gitee
commit 1009177bb3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -31,6 +31,7 @@ namespace Sensors {
namespace {
constexpr int32_t STRING_LENGTH_MAX = 64;
} // namespace
static std::mutex g_sensorAttrListMutex;
bool IsSameValue(const napi_env &env, const napi_value &lhs, const napi_value &rhs)
{
CALL_LOG_ENTER;
@ -321,6 +322,7 @@ bool ConvertToSensorData(const napi_env &env, sptr<AsyncCallbackInfo> asyncCallb
{
CHKPF(asyncCallbackInfo);
int32_t sensorTypeId = asyncCallbackInfo->data.sensorData.sensorTypeId;
std::lock_guard<std::mutex> sensorAttrListLock(g_sensorAttrListMutex);
CHKNCF(env, (g_sensorAttributeList.find(sensorTypeId) != g_sensorAttributeList.end()), "Invalid sensor type");
if (sensorTypeId == SENSOR_TYPE_ID_WEAR_DETECTION && asyncCallbackInfo->type == SUBSCRIBE_CALLBACK) {
return ConvertToBodyData(env, asyncCallbackInfo, result);