diff --git a/services/native/src/power_mgr_service.cpp b/services/native/src/power_mgr_service.cpp index 6736045758c5c9d552cecd4a26126bf07edc3394..f59b9f7cbd97dbf74d7e7ffb945878e78a525652 100644 --- a/services/native/src/power_mgr_service.cpp +++ b/services/native/src/power_mgr_service.cpp @@ -1287,6 +1287,12 @@ PowerErrors PowerMgrService::Hibernate(bool clearMemory, const std::string& reas return PowerErrors::ERR_PERMISSION_DENIED; } #ifdef POWER_MANAGER_POWER_ENABLE_S4 + if (hibernating_) { + POWER_HILOGE(FEATURE_SUSPEND, "the device is hibernating, please try again later."); + return false; + } + + hibernating_ = true; std::lock_guard lock(hibernateMutex_); pid_t pid = IPCSkeleton::GetCallingPid(); auto uid = IPCSkeleton::GetCallingUid(); diff --git a/services/native/src/power_state_machine.cpp b/services/native/src/power_state_machine.cpp index fa655a547e55d75e4426a7463018ebde0aead646..e1b4f7901804b4d272117c3c9c84d401dbb1533a 100644 --- a/services/native/src/power_state_machine.cpp +++ b/services/native/src/power_state_machine.cpp @@ -965,12 +965,7 @@ bool PowerStateMachine::HibernateInner(bool clearMemory, const std::string& reas return true; } } - if (hibernating_) { - POWER_HILOGE(FEATURE_SUSPEND, "the device is hibernating, please try again later."); - return false; - } - hibernating_ = true; PowerState originalState = GetState(); bool needShutdown = clearMemory || reason == "LowCapacity"; notify->PublishEnterHibernateEvent(GetTickCount());