Android Standby status update

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.