diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index 740409292dc0418247b09fb1067bbac9704668d2..a714a3cb2b87cbd4c89c418373ac75634e93406d 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -182,15 +182,13 @@ int32_t SensorAgentProxy::DeactivateSensor(int32_t sensorId, const SensorUser *u SEN_HILOGE("Subscribe user first"); return OHOS::Sensors::ERROR; } - subscribeSet.erase(user); - if (subscribeSet.empty()) { - subscribeMap_.erase(sensorId); - } auto status = unsubscribeMap_[sensorId].insert(user); if (!status.second) { SEN_HILOGD("User has been unsubscribed"); } + subscribeSet.erase(user); if (subscribeSet.empty()) { + subscribeMap_.erase(sensorId); int32_t ret = SEN_CLIENT.DisableSensor(sensorId); if (ret != 0) { SEN_HILOGE("DisableSensor failed, ret:%{public}d", ret);