Reputation: 1502
The rules for holding cpu partial wake locks are very vague. Can someone explain when and why we should acquire one? When can the system decide the service should be suspended while doing some work on a thread?
I would like to understand the details of the cpu scheduler / activity / service manager.
Is the best place the android source code? if so which package?
Upvotes: 2
Views: 1901
Reputation: 1006674
Can someone explain when and why we should acquire one?
You acquire one when you need the CPU to stay running to complete some bit of work. You release it when that work is done.
So, for example, suppose you have an IntentService
triggered by AlarmManager
. You want the IntentService
to check for new email messages for your email client. You would want to acquire a WakeLock
so the CPU will not fall asleep while you are in the middle of doing that, then ensure that you release it. This sort of pattern is why I created the WakefulIntentService
.
When can the system decide the service should be suspended while doing some work on a thread?
The fact that you are doing "some work on a thread" is immaterial. The CPU will fall asleep based on user inactivity. If the user is not keeping the device awake, and you are not keeping the device awake with a WakeLock
, the device will fall asleep.
Having the CPU fall asleep is very important for power consumption. If you, say, decide that you are going to keep the CPU running 24x7, the battery will run dry relatively quickly.
Upvotes: 3