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

Overview

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

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();

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. android The project target (Android 2.
  2. Android XML布局文件优化
  3. Android WebView中javascript和java的互
  4. usbmanger android 底下USB的工作模式
  5. Android 颜色和颜色透明度列表
  6. 第四章 Android开发三大基石—Activity、
  7. Android Touch 触摸事件
  8. android 播放rtsp协议流媒体
  9. Android Studio 使用二三事----' ' canno
  10. Android中SharedPreferences的使用(登陆,