博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android电源管理
阅读量:4457 次
发布时间:2019-06-08

本文共 2907 字,大约阅读时间需要 9 分钟。

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

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

 

   

转载于:https://www.cnblogs.com/eustoma/archive/2011/05/28/2415864.html

你可能感兴趣的文章
자주 쓰이는 정규표현식
查看>>
超简单的listview单选模式SingleMode(自定义listview item)
查看>>
vue-11-路由嵌套-参数传递-路由高亮
查看>>
HDU 1199 - Color the Ball 离散化
查看>>
[SCOI2005]骑士精神
查看>>
Hibernate原理解析-Hibernate中实体的状态
查看>>
六时车主 App 隐私政策
查看>>
C语言常见问题 如何用Visual Studio编写C语言程序测试
查看>>
Web用户的身份验证及WebApi权限验证流程的设计和实现
查看>>
hdu 2098 分拆素数和
查看>>
ECMAScript6-let与const命令详解
查看>>
iOS 使用系统相机、相册显示中文
查看>>
什么是敏捷设计
查看>>
SCSS的基本操作
查看>>
"安装程序无法定位现有系统分区" 问题解决
查看>>
.NET中栈和堆的比较
查看>>
【莫队】bzoj 3781,bzoj 2038,bzoj 3289
查看>>
如何优化limit
查看>>
几种常用数据库字段类型查询语句
查看>>
字符全排列
查看>>