<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-1  評(píng)論-68  文章-98  trackbacks-0
    整理:徐建祥(netpirate@gmail.com)
    日期:2009/09/16
    網(wǎng)址:http://www.anymobile.org

    Index
    1. Introduction
    2. Architecture
    3. How to Work
    4. Wake Locks
    5. Wake Lock Example
    6. Music Application

    1.Introduction

    Android supports its own Power Management (on top of the standard Linux Power Management) designed with the premise that the CPU shouldn't consume power if no applications or services require power. For more information regarding standard Linux power management, please see Linux Power Management Support at http://kernel.org.
    Android requires that applications and services request CPU resources with "wake locks" through the Android application framework and native Linux libraries. If there are no active wake locks, Android will shut down the CPU.

    2.Architecture




    Framework Layer
    /frameworks/base/core/java/android/os/PowerManager.java
    /frameworks/base/services/java/com/android/server/PowerManagerService.java
    /frameworks/base/core/java/android/os/Power.java
    /frameworks/base/core/jni/android_os_power.cpp
    /hardware/libhardware_legacy/power/power.c
        "/sys/power/wake_lock"
        "/sys/power/wake_unlock"
        "/sys/power/state"
        "/sys/android_power/acquire_partial_wake_lock"
        "/sys/android_power/release_wake_lock"
        "/sys/android_power/request_state"
        … …
    Kernel Layer
    /drivers/android/power.c
    /drivers/power/apm_power.c (Advanced Power Management)


    3.How to Work

    系統(tǒng)正常開機(jī)后進(jìn)入到AWAKE狀態(tài),Backlight會(huì)從最亮慢慢調(diào)節(jié)到用戶設(shè)定的亮度,系統(tǒng)screen off timer(settings->sound & display-> Display settings -> Screen timeout)開始計(jì)時(shí),在計(jì)時(shí)時(shí)間到之前,如果有任何的activity事件發(fā)生,如Touch click, keyboard pressed等事件,則將Reset screen off timer, 系統(tǒng)保持在AWAKE狀態(tài)。如果有應(yīng)用程序在這段時(shí)間內(nèi)申請(qǐng)了Full wake lock,那么系統(tǒng)也將保持在AWAKE狀態(tài),除非用戶按下power key. 在AWAKE狀態(tài)下如果電池電量低或者是用AC供電screen off timer時(shí)間到并且選中Keep screen on while pluged in選項(xiàng),backlight會(huì)被強(qiáng)制調(diào)節(jié)到DIM的狀態(tài)。
    如果Screen off timer時(shí)間到并且沒有Full wake lock或者用戶按了power key,那么系統(tǒng)狀態(tài)將被切換到NOTIFICATION,并且調(diào)用所有已經(jīng)注冊(cè)的g_early_suspend_handlers函數(shù),通常會(huì)把LCD和Backlight驅(qū)動(dòng)注冊(cè)成early suspend類型,如有需要也可以把別的驅(qū)動(dòng)注冊(cè)成early suspend,這樣就會(huì)在第一階段被關(guān)閉. 接下來(lái)系統(tǒng)會(huì)判斷是否有partial wake lock acquired,如果有則等待其釋放,在等待的過(guò)程中如果有user activity事件發(fā)生,系統(tǒng)則馬上回到AWAKE狀態(tài);如果沒有partial wake lock acquired,則系統(tǒng)會(huì)馬上調(diào)用函數(shù)pm_suspend關(guān)閉其它相關(guān)的驅(qū)動(dòng),讓CPU進(jìn)入休眠狀態(tài)。
    系統(tǒng)在Sleep狀態(tài)時(shí)如果檢測(cè)到任何一個(gè)Wakeup source,則CPU會(huì)從Sleep狀態(tài)被喚醒,并且調(diào)用相關(guān)的驅(qū)動(dòng)的resume函數(shù),接下來(lái)馬上調(diào)用前期注冊(cè)的early suspend驅(qū)動(dòng)的resume函數(shù),最后系統(tǒng)狀態(tài)回到AWAKE狀態(tài).

    Registering Kernel-level Drivers with the PM Driver
    #Be notified immediately before power down
    android_register_early_suspend(android_early_suspend_t *handler)
    #Be notified immediately after power up
    android_register_early_resume(android_early_resume_t *handler)
    HARDWARE LIGHTS
    #define LIGHT_ID_BACKLIGHT          "backlight"
    #define LIGHT_ID_KEYBOARD           "keyboard"
    #define LIGHT_ID_BUTTONS            "buttons"
    #define LIGHT_ID_BATTERY            "battery"
    #define LIGHT_ID_NOTIFICATIONS      "notifications"
    #define LIGHT_ID_ATTENTION          "attention"
    #define LIGHT_ID_BLUETOOTH          "bluetooth"
    #define LIGHT_ID_WIFI               "wifi"

    4.Wake Locks

    Wake locks are used by applications and services to request CPU resources.
    Types of Wake Locks:
    -ACQUIRE_CAUSES_WAKEUP: Normally wake locks don't actually wake the device, they just cause it to remain on once it's already on.
    -FULL_WAKE_LOCK:  The screen and keyboard are on at full brightness
    -ON_AFTER_RELEASE: When this wake lock is released, poke the user activity timer
    -PARTIAL_WAKE_LOCK: The CPU is running, The screen might not be on.
    -SCREEN_BRIGHT_WAKE_LOCK: The screen is on at full brightness; the keyboard backlight will be allowed to go off.
    -SCREEN_DIM_WAKE_LOCK: The screen is on, but the keyboard backlight will be allowed to go off, and the screen backlight will be allowed to go dim.

    5.Wake Lock Example

    1). Acquire handle to the PowerManager service.
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.DEVICE_POWER" />

    PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);

    2). Create a wake lock and specify the power management flags for screen, timeout, etc.

    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);

    3). Acquire wake lock.
    wl.acquire();

    4). Perform operation (play MP3, open HTML page, etc.).

    5). Release wake lock.
    wl.release();

    6.Music Application

    /packages/apps/Music/AndroidManifest.xml
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    /packages/apps/Music/src/.../MediaPlayerService.java PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
    WakeLock mWakeLock =
        pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,    
       this.getClass().getName());
    #Sets this WakeLock is not ref counted.
    mWakeLock.setReferenceCounted(false);

    #The lock will be released after 30 seconds.
    mWakeLock.acquire(30000);

    mHandler.sendEmptyMessage(RELEASE_WAKELOCK);
    #Release the claim to the CPU or screen being on.
    mWakeLock.release();

    Reference

    Android Platform Development Kit:Power Management
    http://www.netmite.com/android/mydroid/development/pdk/docs/power_management.html

    Android Power Management(Steve Guo)
    http://letsgoustc.spaces.live.com/blog/cns!89AD27DFB5E249BA!526.entry

    Android 電源管理(hzdysymbol)
    http://blog.csdn.net/hzdysymbol/archive/2009/03/19/4004791.aspx

    Linux Power Management Support
    http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.24.y.git;a=blob;f=Documentation/pm.txt

     

    posted on 2010-08-12 02:27 Xu Jianxiang 閱讀(2302) 評(píng)論(0)  編輯  收藏 所屬分類: Android
    主站蜘蛛池模板: 亚洲综合激情视频| 亚洲中文字幕无码久久精品1| 亚洲一区免费观看| 亚洲免费人成在线视频观看| 亚洲一区视频在线播放| 色爽黄1000部免费软件下载| 免费A级毛片无码A∨男男| 精品无码专区亚洲| 免费大黄网站在线看| 欧洲美女大片免费播放器视频| 国产成人一区二区三区免费视频 | 色老板亚洲视频免在线观| 日韩亚洲国产综合久久久| 亚洲人成未满十八禁网站| 成年男女免费视频网站| 亚洲精品一二三区| 欧亚精品一区三区免费| 亚洲一区二区三区国产精华液| 成年性羞羞视频免费观看无限| 亚洲欧美日韩一区二区三区| 日本不卡高清中文字幕免费| 美女免费精品高清毛片在线视| 亚洲色一色噜一噜噜噜| 青青操在线免费观看| 亚洲综合自拍成人| 成人毛片免费观看视频| 国产精品亚洲二区在线| 曰韩亚洲av人人夜夜澡人人爽 | 永久免费毛片手机版在线看| 国产亚洲精品欧洲在线观看| 亚洲一区二区高清| 日本视频一区在线观看免费| 亚洲另类无码一区二区三区| 亚洲精品无码久久久| 久久久久久久久久国产精品免费| 亚洲大尺码专区影院| 午夜国产大片免费观看| 污污网站18禁在线永久免费观看| 学生妹亚洲一区二区| 亚洲一区二区精品视频| 久久久久久久免费视频|