Android Power Management
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(./frameworks/base/services/java/com/android/server/PowerManagerService.java) is the core service. It calls Power.java(./frameworks/base/core/java/android/os/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(./frameworks/base/core/jni/android_os_Power.cpp) is the JNI native implementation for Power.java. It calls Power.c(./hardware/libhardware_legacy/power/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();
分享到:
相关推荐
Android Power Management Framework
Android Power Management.pdf
android power management document 上传点存货,赚点积分,谢谢各位
两个文档,一个分别从Java应用层面,framework层面, Linux内核层面对android电源管理进行详细的讨论;另一个介绍了Linux系统Suspend框架,以及Wake Lock和Suspend/Resume的构架和接口实现。
Power Management from Linux Kernel to Android Introduction to Linux Power Management Concepts behind Android Power Management Design and Implementation Room for Improvements
8 Android Power Management 35 9 Android Property System 38 10 Build ALSA with Android's tool chain 40 11 Disable Android screen saver 44 12 Hack Android SD Card support 45 13 How to add permission for...
Android电源的整体架构及内核电源管理的介绍
android-power-management android平台电源管理描述,做安卓电源管理必须的文档。
LibreTorrent ...LibreTorrent is a Free as in Freedom...Ability to fine tune (network settings, power management, battery control, UI settings, etc.) Supports torrents with large number of files and big fi
Power Management 83 Introduction 84 Wake Locks 85 Driver API 87 User-space API 87 Types of Wake Locks 88 Exploring a Wake Lock Example 88 PowerManager class 89 Registering Drivers with the PM Driver ...
Game engines such as Unity are the power-tools behind the games we know and love. Unity is one of the most widely-used and best loved packages for game development and is used by everyone, from ...
3.8.9. Input Management 3.8.10. Lock Screen Media Control 3.8.11. Screen savers (previously Dreams) 3.8.12. Location 3.8.13. Unicode and Font 3.8.14. Multi-windows 3.8.15. Display Cutout 3.9. Device ...
Focus Management and Accessibility Miscellaneous UI Tricks Event Bus Alternatives Tasks The Assist API (“Now On Tap”) The Data Binding Framework Desktop Android Apps Drag and Drop Keyboard and Mouse...
Practicing Good File Management 302 Understanding Android File Permissions 303 Working with Files and Directories 303 Exploring with the Android Application Directories 304 Working with Other ...
Android 架构的概述,全英文,讲的很棒! 1.Introduction and overview of android 2.Application anatomy ...4.Power management and kernel 5.Application Framework APIs 6.Testing and debug 7.Summary
Focus Management and Accessibility Miscellaneous UI Tricks Event Bus Alternatives Tasks The Assist API (“Now On Tap”) The Autofill API The Data Binding Framework Drag and Drop Keyboard and Mouse ...
* Coverage of Android's communication abilities including SMS, the telephony APIs, network management, and a guide to using Internet resources * Details for using Android hardware, including media ...