diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 23cfa0672cdf52dca6745ffc92660250444df5db..b9c589fdeaa2f9a5f3d61bac0b973da40dd89515 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -133,7 +133,6 @@ int32_t SensorAgentProxy::ActivateSensor(int32_t sensorId, const SensorUser *use { CHKPR(user, OHOS::Sensors::ERROR); CHKPR(user->callback, OHOS::Sensors::ERROR); - std::lock_guard subscribeLock(subscribeMutex_); if (g_samplingInterval < 0 || g_reportInterval < 0) { SEN_HILOGE("samplingPeriod or g_reportInterval is invalid"); return ERROR; @@ -142,6 +141,7 @@ int32_t SensorAgentProxy::ActivateSensor(int32_t sensorId, const SensorUser *use SEN_HILOGE("sensorId is invalid, %{public}d", sensorId); return PARAMETER_ERROR; } + std::lock_guard subscribeLock(subscribeMutex_); if ((g_subscribeMap.find(sensorId) == g_subscribeMap.end()) || (g_subscribeMap[sensorId] != user)) { SEN_HILOGE("subscribe sensorId first"); return ERROR;