Android待機狀態更新

來源:互聯網
上載者:User

標籤:

Android的待機狀態管理由PowerManagerService.java管理

主要的狀態更新方法在下面貼出代碼, 注釋寫的很清楚, 第一次看系統源碼感覺還比較爽

主要是更新喚醒, 螢幕休眠以及其他的一些狀態, 然後系統根據更新的狀態進行一些操作, 比如系統睡眠, 進入屏保, 或者電源模式變更等等.


 /**     * 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();    }

調用updatePowerStateLocked()方法的地方有:


可以發現, 基本都是接受到一些系統廣播之後進行調用(以handle開頭的方法), 以及系統設定後調用(set開頭的方法), 來更新電源狀態, 還有一些介面回調, 主要是給使用者的一些操作


先是public的回調方法, 回調方法把任務傳遞到內部的private方法(Internal結尾), 還有接收的native方法(Native結尾), 最後都是通過Locked結尾的方法調用updatePowerStateLocked()更新狀態.


Android待機狀態更新

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.