mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Added APIs to allow/prevent sleep in session manager
PiperOrigin-RevId: 552958620
This commit is contained in:
committed by
Copybara-Service
parent
33b2748a8c
commit
20f2291476
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user