Android电源管理

news/2024/7/10 16:28:32 标签: android, module, jni, keyboard, path, button

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

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

Overview

PowerManagement1

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:

PowerManagement2

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://blog.csdn.net/hzdysymbol/archive/2009/03/04/3956462.aspx


http://www.niftyadmin.cn/n/1720199.html

相关文章

JDBC的事务代理

1、事务 (1)事务的概念 事务指逻辑上的一组操作,组成这组操作的各个单元,要不全部成功,要不全部不成功。 例如:A——B转帐,对应于如下两条sql语句 update account set moneymoney-100 where nam…

VS内存泄漏检查 tcy

VS内存泄漏检查 2020/3/151.1.说明:VS调试器和C运行时(CRT)库为我们提供了检测和识别内存泄漏的有效方法 1.2.原理:内存分配要通过CRT在运行时实现,只要在分配内存和释放内存时分别做好记录,程序结束时对比分配内存和释放内存的…

BZOJ 3083 遥远的国度 树链剖分+脑子

唉。。又调了半天QWQ。。为何读入挂了。。。。。莫非读入是反着的????据ywy学长所言如是。。。OvO震惊 这啥骚题啊、、、还要换根、、、不过清明讲过、、、(然鹅我现在才做、、、 先随便选个点(比如选1&…

dbc file

DBC文件是用来描述CAN网络通信信号的一种格式文件。它可以用来监测与分析CAN网络上的报文数据,也可以用来模拟某个CAN节点。(DBC file is a format file used to describe CAN network communication signal. It can be used to monitor and analyze packet data on…

linux下的内存映射函数mmap详解及示例代码

自:http://hi.baidu.com/flying5/blog 不错的博客,大家可以去看看Linux的mmap文件内存映射机制mmap: memory map 在讲述文件映射的概念时, 不可避免的要牵涉到虚存(SVR 4的VM). 实际上, 文件映射是虚存的中心概念 , 文件映射一方面给用户提供了一组…

更新缓存

更新缓存的时候涉及两个问题: 删除(del)还是 修改(set)?先操作数据库,还是 先操作缓存?组合起来就有四种情况: 第一种情况:先删除缓存,后更新数据…

C/C++动态内存tcy

动态内存管理 2020/3/15C推荐用容器1.1.概念: 1) 栈stack:在函数内部声明的所有变量都将占用栈内存。 2) 堆heap:这是程序中未使用的内存, 在程序运行时可用于动态分配内存。 3) 当对象在stack上时析构函数自动调用;在heap上时需调用delete后…

bus,device,driver三者关系

bus,device,driver三者关系 bus: 总线作为主机和外设的连接通道,有些总线是比较规范的,形成了很多协议。如 PCI,USB,1394,IIC等。任何设备都可以选择合适的总线连接到主机。当然主机也可能就是CPU本身。内存也是通过BUS连接到主机的,可内存 …