zoukankan      html  css  js  c++  java
  • Android电源管理

    研究了好几个月的Android电源管理了,有时间得自己写一些心得体会了,先转贴一份写得不错的文章吧

    [First written by Steve Guo, please keep the mark if forwarding.]

    Overview

    PowerManagement1

    The above picture shows the overall architecture design of Android power management module. Android implements a very simple power management mechanism. Currently it only supports set screen on/off, screen backlight on/off, keyboard backlight on/off, button backlight on/off and adjust screen brightness. It does not support Sleep or Standby mode to fully use CPU’s capability.

    The power management module has three channels to receive input: RPC call, Batter state change event and Power Setting change event. It communicated with other modules through either broadcasting intent or directly API call. The module also provide reboot and shutdown service. When battery is lower than thredshold, it will automatically shutdown the device.

    The module will automatically set screen dim and off according to whether any user activity happens or not. The full state machine is shown as follows:

    PowerManagement2

    Detail

    PowerManagerService.java is the core service. It calls Power.java to do the real work.

    PowerManager.java is the proxy to RPC call PowerManagerService.java.

    Power.java communicates with the low level through JNI.

    android_os_Power.cpp is the JNI native implementation for Power.java. It calls Power.c to do the real work.

    Power.c controls the power device driver through read/write the following sys files.

        "/sys/android_power/acquire_partial_wake_lock",

        "/sys/android_power/acquire_full_wake_lock",

        "/sys/android_power/release_wake_lock",

        "/sys/android_power/request_state"

        "/sys/android_power/auto_off_timeout",

        "/sys/class/leds/lcd-backlight/brightness",

        "/sys/class/leds/button-backlight/brightness",

        "/sys/class/leds/keyboard-backlight/brightness"

    BatteryService.java registers itself as a UEvent observer for the path “/sys/class/power_supply”. If anything is changed in this path, it gets current state through JNI and then broadcasts ACTION_BATTERY_CHANGED intent.

    com_android_server_BatteryService.cpp is the JNI native implementation for BatteryService.java. It gets current battery state through reading from the following files:

        "/sys/class/power_supply/ac/online"

        "/sys/class/power_supply/usb/online"

        "/sys/class/power_supply/battery/status"

        "/sys/class/power_supply/battery/health"

        "/sys/class/power_supply/battery/present"

        "/sys/class/power_supply/battery/capacity"

        "/sys/class/power_supply/battery/batt_vol"

        "/sys/class/power_supply/battery/batt_temp"

        "/sys/class/power_supply/battery/technology"

    How to use

    To call power module in app, the following is the sample code:

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

    PowerManager.WakeLock wl = pm.newWakeLock(

    PowerManager.SCREEN_DIM_WAKE_LOCK

    | PowerManager.ON_AFTER_RELEASE,

    TAG);

    wl.acquire();

    // ...

    wl.release();

        http://blog.csdn.net/hzdysymbol/archive/2009/03/04/3956462.aspx

  • 相关阅读:
    WHU-1551-Pairs(莫队算法+分块实现)
    JS日历控件 灵活设置: 精确的时分秒.
    java集群优化——多线程下的单例模式
    课程设计——银行系统
    互联网金融,巨头天下还是创业者天堂?
    Android 使用图片异步载入框架Universal Image Loader的问题
    程序C++ to C#交互
    浅谈asp.net通过本机cookie仿百度(google)实现搜索input框自己主动弹出搜索提示
    全栈JavaScript之路(十六)HTML5 HTMLDocument 类型的变化
    推荐安卓开发神器(里面有各种UI特效和实例)
  • 原文地址:https://www.cnblogs.com/eustoma/p/2415864.html
Copyright © 2011-2022 走看看