[转载]Android Power Management 电源管理
来源:互联网 发布:阿里云 邮件超时 编辑:程序博客网 时间:2024/05/18 16:18
Android supports its own Power Management (on top of the standard Linux Power Management) designed with the premise that the CPU shouldn't consume power if no applications or services require power. For more information regarding standard Linux power management, please seeLinux Power Management Supportathttp://kernel.org.
Android requires that applications and services request CPU resources with "wake locks" through the Android application framework and native Linux libraries. If there are no active wake locks, Android will shut down the CPU.
A locked wakelock, depending on its type, prevents the system from entering suspend or other low-power states. This document describes how to employ wakelocks.
WAKE_LOCK_IDLE: low-power states, which often cause large interrupt latencies or that disable a set of interrupts, will not be entered from idle until the wakelocks are released.
If the suspend operation has already started when locking a wakelock, the system will abort the suspend operation as long it has not already reached the suspend_late stage. This means that locking a wakelock from an interrupt handler or a freezeable thread always works, but if you lock a wakelock from a suspend_late handler, you must also return an error from that handler to abort suspend. You can use wakelocks to allow the user-space to decide which keys should wake the full system and turn on the screen. Use set_irq_wake or a platform-specific API to ensure that the keypad interrupt wakes up the CPU. On
1,The Keypad driver receives an interrupt, locks the keypad-scan wakelock, and starts scanning the keypad matrix.
3,The input-event driver sees the key change, enqueues an event, and locks the input-event-queue wakelock.
4,The keypad-scan co
5,The user-space input-event thread returns from select/poll, locks the process-input-events wakelock, and calls read in the input-event device.
7,The input-event driver dequeues the key-event and, since the queue is now empty, unlocks the input-event-queue wakelock.
7,The user-space input-event thread returns from read. It determines that the key should not wake up the full system, releases the process-input-events wakelock, and calls select or poll.
Key pressed Key released
| |
input-event-queue +++ +++
struct state {
struct wakelock wakelock;
}
init() {
wake_lock_init(&state->wakelock, WAKE_LOCK_SUSPEND, "wakelockname");
}
Before freeing the memory, wake_lock_destroy must be called:
uninit() {
wake_lock_destroy(&state->wakelock);
}
wake_lock(&state->wakelock);
wake_unlock(&state->wakelock);
This works whether or not the wakelock is already held. It is useful if the driver woke up other parts of the system that do not use wakelocks but still need to run. Avoid this when possible, since it will waste power if the timeout is long or may fail to finish needed work if the timeout is short.
Acquire handle to the PowerManager service.Create a wake lock and specify the power management flags for screen, timeout, etc.Acquire wake lock.Perform operation (play MP3, open HTML page, etc.).Release wake lock.
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();
User space native libraries (any hardware function in //device/lib/hardware/ meant to serve as supporting libraries for Android runtime) should never call into Android Power Management directly (see the image above). Bypassing the power management policy in the Android runtime will destabilize the system.
You can register Kernel-level drivers with the Android Power Manager driver so that they're notified immediately before power down or after power up. For example, you might set a display driver to completely power down when a request comes in to power down from the user space (see the Android MSM MDDI display driver for a sample implementation).
To register drivers with the Android PM driver, implement call-back handlers and register them with the Android PM, as illustrated in the snippet below:
android_register_early_suspend(android_early_suspend_t *handler)
android_register_early_resume(android_early_resume_t *handler)
The early-suspend API allows drivers to get notified when user-space writes to /sys/power/request_state to indicate that the user visible sleep state should change. Suspend handlers are called in order of low to high (4 - 1 below) and resume handlers are called in order of high to low (1 - 4 below).
1,EARLY_SUSPEND_LEVEL_BLANK_SCREEN:
on suspend: the screen should be turned off but the framebuffer must still be accessible.
2,EARLY_SUSPEND_LEVEL_STOP_DRAWING:
on suspend: this level notifies user-space that it should stop accessing the framebuffer and it waits for it to complete.
on resume: it notifies user-space that it should resume screen access. Two methods are provided, console switch or a sysfs interface.
3,EARLY_SUSPEND_LEVEL_DISABLE_FB: Turn off the framebuffer
4,EARLY_SUSPEND_LEVEL_STOP_INPUT:
on suspend: turn off input devices that are not capable of wakeup or where wakeup is disabled.
- [转载]Android Power Management 电源管理
- Android电源管理 Android Power Management
- Android平台开发-Power management-电源管理
- android 内核power电源管理
- arm 时钟(CLOCK)和电源管理(POWER MANAGEMENT )
- **arm 时钟(CLOCK)和电源管理(POWER MANAGEMENT )
- Android 电源管理 (转载)
- 中关村-DIY电脑之BIOS的电源管理(Power Management)
- Linux 2.6内核配置说明(6----Power management options电源管理选项)
- ACPI---高级配置和电源管理接口(Advanced Configuration and Power Management Interface)
- Android Power Management
- 转帖:Android Power Management
- Android Power Management
- Android Power Management
- Android Power Management
- [转]Android Power Management
- Android Power Management
- Android Power Management
- 光束平差法(Bundle Adjust)
- android应用如何在有需要时申请root权限?在程序中要调用哪些语句来实现?
- java之数组Array使用
- Android 自己的程序中添加系统重启的提示框
- Idea打包成war包+javaweb项目部署到服务器的tomcat上 史上最详细教程
- [转载]Android Power Management 电源管理
- [转载]基于Android的Linux内核的电源管理:Early Suspend
- 「转载」 Debug Android and Linux suspend and resume (中文)
- 「转」 Android中休眠与唤醒之wake_lock, early_suspend, late_resume
- 几种同步机制的比较
- 「原」从android层面分析early suspend
- [转」SIM卡中存中文联系人,重启之后,中文联系人名字会消失
- 「转」sim卡中的汉字存储格式
- [转]git查看某个文件的修改历史