免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2399 | 回复: 0
打印 上一主题 下一主题

Android Power Management [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-08 11:51 |只看该作者 |倒序浏览
转载:Android Power Management

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


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/66024/showart_1893565.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP