Android's standby state management is managed by Powermanagerservice.java
The main state Update method is posted below the code, comments written very clearly, the first time to see the system source sense is still relatively cool
The main is the update wake-up, screen hibernation and some other status, and then the system according to the updated state of some operations, such as system sleep, into the screensaver, or power mode changes and so on.
/** * Updates The global power state based on dirty bits recorded in Mdirty. * * This is the main function, the performs power state transitions. * We centralize them here so We can recompute the power state completely * each time something important changes, and ensure that we do it the same * to each time. The gather all of the transition logic here. */private void updatepowerstatelocked () {if (!msystemready | | mdirty = = 0) {return; } if (! Thread.holdslock (MLock)) {SLOG.WTF (TAG, "Power Manager lock is not held when calling updatepowerstatelocked") ; }//Phase 0:basic State updates. Updateispoweredlocked (Mdirty); Updatestayonlocked (Mdirty); Phase 1:update wakefulness. Loop because the wake Lock and user activity computations is influenced//by changes in wakefulness. Final Long now = Systemclock.uptimemillis (); IntDirtyPhase2 = 0; for (;;) {int dirtyPhase1 = Mdirty; DirtyPhase2 |= dirtyPhase1; Mdirty = 0; Updatewakelocksummarylocked (DIRTYPHASE1); Updateuseractivitysummarylocked (now, DIRTYPHASE1); if (!updatewakefulnesslocked (dirtyPhase1)) {break; }}//Phase 2:update dreams and display power state. Updatedreamlocked (DIRTYPHASE2); Updatedisplaypowerstatelocked (DIRTYPHASE2); Phase 3:send notifications, if needed. if (Mdisplayready) {sendpendingnotificationslocked (); }//Phase 4:update suspend blocker. Because we might release the last suspend blocker here, we need to make sure//we finished everything else firs T! Updatesuspendblockerlocked (); }
The place to call the Updatepowerstatelocked () method is:
It can be found that the basic is to accept some system broadcast after the call (the method beginning with handle), as well as the system set after the call (set the beginning of the method), to update the power state, there are some interface callback, mainly to the user some operations
First, the public callback method, the callback method to pass the task to the internal private method (internal end), as well as the received native method (native end), and finally through the locked end of the method call updatepowerstatelocked () Update status.
Android Standby status update