Added APIs to allow/prevent sleep in session manager

PiperOrigin-RevId: 552958620
This commit is contained in:
Guogang Li
2023-08-01 16:26:47 -07:00
committed by Copybara-Service
parent 33b2748a8c
commit 20f2291476
2 changed files with 27 additions and 0 deletions
@@ -167,6 +167,27 @@ bool SessionManager::IsScreenLocked() const {
return (session_state == WTS_SESSIONSTATE_LOCK);
}
bool SessionManager::PreventSleep() const {
EXECUTION_STATE execution_state =
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
if (execution_state == 0) {
NEARBY_LOGS(ERROR) << __func__
<< ": Failed to set execution state of the thread.";
return false;
}
return true;
}
bool SessionManager::AllowSleep() const {
EXECUTION_STATE execution_state = SetThreadExecutionState(ES_CONTINUOUS);
if (execution_state == 0) {
NEARBY_LOGS(ERROR) << __func__
<< ": Failed to set execution state of the thread.";
return false;
}
return true;
}
void SessionManager::StartSession(absl::Notification& notification) {
kSessionHwnd = CreateNearbyWindow();
if (kSessionHwnd == nullptr) {
@@ -43,6 +43,12 @@ class SessionManager {
bool IsScreenLocked() const;
// Prevents the Windows device from sleeping state.
bool PreventSleep() const;
// Allows the Windows device to sleep state.
bool AllowSleep() const;
private:
void StartSession(absl::Notification& notification);
void StopSession();