Home > database >  What exactly do wake-locks prevent?
What exactly do wake-locks prevent?

Time:07-04

In the wake-lock training doc it says:

If you need to keep the CPU running in order to complete some work before the device goes to sleep, you can use a PowerManager system service feature called wake locks.

It was my impression that "before the device goes to sleep" referred to doze mode. However, the answer to the SO post Wakelock and doze mode states:

Holding a PARTIAL_WAKE_LOCK is insufficient to block Doze mode

So, if a wake-lock doesn't prevent doze mode, then what exactly is meant by "keep the CPU running in order to complete some work before the device goes to sleep"?

Also, in the doze standby training doc it says:

An app that is partially exempt can use the network and hold partial wake locks during Doze and App Standby.

If (for some reason) "before the devices goes to sleep" does refer to doze mode, then does this mean that wake-locks have absolutely no effect unless you are on the white list for no battery optimizations?

Specifically, I'm talking about partial wake-locks on API 31 .

CodePudding user response:

what exactly is meant by "keep the CPU running in order to complete some work before the device goes to sleep"?

Android devices can power down their CPUs to reduce battery consumption. This usually happens shortly after the screen turns off.

A partial wakelock says "allow the screen to turn off but keep the CPU powered on". This is used for things like long-running audio playback (music, audiobooks, podcasts, etc.).

A full wakelock says "do not allow the screen to turn off either". This is used for things like video players, where the user's expectation is that the screen will stay on despite limited user input.

  • Related