Overview

Android Power Management【by Steve Guo】_第1张图片

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:

Android Power Management【by Steve Guo】_第2张图片

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://letsgoustc.spaces.live.com/blog/cns!89AD27DFB5E249BA!526.entry

更多相关文章

  1. android里图片下载工具类AsyncImageLoader分析
  2. android图片压缩并转为base64字符串
  3. android > 图片旋转
  4. android 滚动的缓冲图片
  5. android:设计一个能在图片上涂鸦的程序。
  6. android NinePatchDrawable 9.png图片使用制作
  7. Android 查看保存图片到相册
  8. Android 下拉刷新 ListRefresh 从网络加载图片
  9. android 双击图片放大缩小

随机推荐

  1. 鲁迅检索系统首日上线!访问量巨大挤崩服务
  2. NASA供应商造假19年致两颗卫星坠毁,损失超
  3. 揭秘亚洲10万鉴黄师的痛苦与挣扎:干着全网
  4. GitHub等三大平台遭勒索,***给出十天期限:
  5. 【解决办法】火狐浏览器扩展突然禁用和神
  6. 国内加速访问Github的办法,超级简单
  7. 点进垃圾网页后返回按钮失效?谷歌承诺将彻
  8. 全国416个本科专业被撤销,你的专业“出局
  9. B站十门全领域基础实用课程推荐,PS设计司
  10. 宝可梦与Chrome联名,推出官方插件“皮卡丘