Android standby status update
The standby status of Android is managedPowerManagerService. javaManagement
The main status update method is to post the code below, and the comments are clearly written. The first time I saw the system source code, I felt pretty good.
Update wake-up, screen sleep, and other statuses. Then, the system performs some operations based on the updated status, such as system sleep, screen saver, or power mode change.
/** * Updates the global power state based on dirty bits recorded in mDirty. * * This is the main function that performs power state transitions. * We centralize them here so that we can recompute the power state completely * each time something important changes, and ensure that we do it the same * way each time. The point is to 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 was 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 are influenced // by changes in wakefulness. final long now = SystemClock.uptimeMillis(); int dirtyPhase2 = 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 first! updateSuspendBlockerLocked(); }
The updatePowerStateLocked () method is called in the following ways:
It can be found that, after receiving some System Broadcasts, call (Methods Starting with handle) and call (Methods Starting with set) after system settings to update the power status, there are also some interface callbacks, mainly for some user operations
First, the public callback method is used. The callback method transmits the task to the Internal private method (ending with Internal) and the received native METHOD (ending with Native ), the last step is to call updatePowerStateLocked () to update the status through the method ending with Locked.