Skip to content

Commit

Permalink
Auto hibernation: make sure auto-hibernation feature only happens whe…
Browse files Browse the repository at this point in the history
…n hibernatemode is set to 3. (Never when mode 0 or 25). (#3)

* Auto hibernation: make sure auto-hibernation feature only happens when hibernatemode is set to 3. (Never when mode 0 or 25).

* Update Changelog.md

* Auto hibernation: remove redundant pmset_default_mode checks in the while loop.
  • Loading branch information
leon9078 authored Apr 16, 2024
1 parent 1eb0ddb commit c309e34
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
HibernationFixup Changelog
============================

#### v1.5.0
- Auto hibernation: make sure auto-hibernate feature only happens when hibernatemode is set to 3. (Never with mode 0 or 25).

#### v1.4.9
- Add macOS 14 (Sonoma) constants

Expand Down
12 changes: 6 additions & 6 deletions HibernationFixup/kern_hbfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ IOReturn HBFX::X86PlatformPlugin_sleepPolicyHandler(void * target, IOPMSystemSle
uint32_t standby_delay = 0;
bool pmset_default_mode = false;
auto autoHibernateMode = ADDPR(hbfx_config).autoHibernateMode;
while (callbackHBFX->isStandbyEnabled(standby_delay, pmset_default_mode) &&
while (callbackHBFX->isStandbyEnabled(standby_delay, pmset_default_mode) && pmset_default_mode &&
(params->sleepType == kIOPMSleepTypeDeepIdle || params->sleepType == kIOPMSleepTypeStandby || params->sleepType == kIOPMSleepTypeNormalSleep))
{
IOPMPowerSource *power_source = callbackHBFX->getPowerSource();
Expand All @@ -378,7 +378,7 @@ IOReturn HBFX::X86PlatformPlugin_sleepPolicyHandler(void * target, IOPMSystemSle
if (callbackHBFX->sleepPhase > kIOPMSleepPhase0)
{
callbackHBFX->sleepServiceWake = false;
if (pmset_default_mode && standby_delay != 0 && !callbackHBFX->wakeCalendarSet && callbackHBFX->sleepPhase > kIOPMSleepPhase0)
if (standby_delay != 0 && !callbackHBFX->wakeCalendarSet && callbackHBFX->sleepPhase > kIOPMSleepPhase0)
callbackHBFX->explicitlyCallSetMaintenanceWakeCalendar();
}
break;
Expand All @@ -389,7 +389,7 @@ IOReturn HBFX::X86PlatformPlugin_sleepPolicyHandler(void * target, IOPMSystemSle
if (callbackHBFX->sleepPhase > kIOPMSleepPhase0)
{
callbackHBFX->sleepServiceWake = false;
if (pmset_default_mode && standby_delay != 0 && !callbackHBFX->wakeCalendarSet && callbackHBFX->sleepPhase > kIOPMSleepPhase0)
if (standby_delay != 0 && !callbackHBFX->wakeCalendarSet && callbackHBFX->sleepPhase > kIOPMSleepPhase0)
callbackHBFX->explicitlyCallSetMaintenanceWakeCalendar();
}
break;
Expand Down Expand Up @@ -425,15 +425,15 @@ IOReturn HBFX::X86PlatformPlugin_sleepPolicyHandler(void * target, IOPMSystemSle
if (callbackHBFX->sleepPhase > kIOPMSleepPhase0)
{
callbackHBFX->sleepServiceWake = false;
if (pmset_default_mode && standby_delay != 0 && !callbackHBFX->wakeCalendarSet && callbackHBFX->sleepPhase > kIOPMSleepPhase0)
if (standby_delay != 0 && !callbackHBFX->wakeCalendarSet && callbackHBFX->sleepPhase > kIOPMSleepPhase0)
callbackHBFX->explicitlyCallSetMaintenanceWakeCalendar();
}
break;
}

if (callbackHBFX->sleepPhase > kIOPMSleepPhase0)
{
if (pmset_default_mode && standby_delay != 0 && !forceHibernate && !callbackHBFX->wakeCalendarSet && !callbackHBFX->sleepServiceWake)
if (standby_delay != 0 && !forceHibernate && !callbackHBFX->wakeCalendarSet && !callbackHBFX->sleepServiceWake)
callbackHBFX->explicitlyCallSetMaintenanceWakeCalendar();
}

Expand All @@ -445,7 +445,7 @@ IOReturn HBFX::X86PlatformPlugin_sleepPolicyHandler(void * target, IOPMSystemSle
#endif

bool doNotOverrideWakeUpTime = (ADDPR(hbfx_config).autoHibernateMode & Configuration::DoNotOverrideWakeUpTime);
bool setupHibernate = (forceHibernate || !callbackHBFX->wakeCalendarSet || callbackHBFX->sleepServiceWake || (pmset_default_mode && standby_delay == 0));
bool setupHibernate = (forceHibernate || !callbackHBFX->wakeCalendarSet || callbackHBFX->sleepServiceWake || standby_delay == 0);
if (setupHibernate && doNotOverrideWakeUpTime && !forceHibernate)
{
if (vars->standbyTimer != 0)
Expand Down

0 comments on commit c309e34

Please sign in to comment.