Chinaunix首页 | 论坛 | 博客
  • 博客访问: 932675
  • 博文数量: 153
  • 博客积分: 4195
  • 博客等级: 上校
  • 技术积分: 2631
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-22 11:32





2009-09-03 16:09:15

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


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:

Detail is the core service. It calls to do the real work. is the proxy to RPC call communicates with the low level through JNI.

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

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








    "/sys/class/leds/keyboard-backlight/brightness" 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 It gets current battery state through reading from the following files:










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.ON_AFTER_RELEASE,



// ...




阅读(2034) | 评论(0) | 转发(0) |