Article reprinted from: Http://blog.csdn.net/hzdysymbol/archive/2009/03/19/4004791.aspx
Android Power ManagementIn General, the power management of Android is relatively simple , mainly through the lock and timer to switch the state of the system, so that the system's power consumption is minimized , the entire system power management architecture diagram is as follows : (note that the figure from Steve Guo) Then we'll start withJava application level , the Android framework layer , the Linux kernel level are discussed in detail :
Use of the application layer :
Android provides an off-the-shelf Android.os.PowerManager class that controls the switching of the power state of the device .
There are three interface functions on the outside of this class :
void Gotosleep (long time); Force device into sleep state
Note:
An attempt to invoke the function at the application level does not succeed , and the error appears to be insufficient permissions , but it is OK to call in the service under the framework .
Newwakelock (int flags, String tag);//obtain a corresponding level of lock
Flags parameter Description :
Partial_wake_lock:screen off, keyboard light off
Screen_dim_wake_lock:screen DIM, keyboard light off
Screen_bright_wake_lock:screen BRIGHT, keyboard light off
Full_wake_lock:screen Bright, keyboard bright
Acquire_causes_wakeup: Force open screen and keyboard Light Once there is a request lock
On_after_release: Reset Activity timer When a lock is released
Note:
If you have applied for partial Wakelock, So even press power key < Span style= "LINE-HEIGHT:18PX; Font-family: ' Times New Roman '; >sleep, such as music when playing
If you have applied for another power key < Span style= "LINE-HEIGHT:18PX; Font-family: ' Times New Roman '; >, the system will still enter sleep
void Useractivity (Long when, Boolean nochangelights),//user activity event occurs , the device is switched to the full-on state , while Reset screen off timer.
Sample Code:
PowerManager pm = (powermanager) getsystemservice (Context.power_service);
Powermanager.wakelock wl = Pm.newwakelock (Powermanager.screen_dim_wake_lock, "My Tag");
Wl.acquire ();
.......
Wl.release ();
Note:
1. In an application that uses the above functions , the following permissions must be included in its manifest.xml file :
<uses-permission android:name="Android.permission.WAKE_LOCK" />
< Uses-permission android:name= "Android.permission.DEVICE_POWER" />
2. All locks must be used in pairs , and if the application is not released in a timely manner will cause a system failure . If you apply for partial wakelock and do not release it in time , the system will never get into sleep mode .
Note: For more information on PowerManager, please refer to "PowerManager"
Android Framework level :
The main code files are as follows :
Frameworks\base\core\java\android\os\powermanager.java
Frameworks\base\services\java\com\android\server\powermanagerservice.java
Frameworks\base\core\java\android\os\power.java
Frameworks\base\core\jni\android_os_power.cpp
Hardware\libhardware\power\power.c
Where jni layer interacts < Span style= "LINE-HEIGHT:18PX; Font-family: ' Times New Roman '; >, JNI layer code is mainly in the file android_os_power.cpp linux kernel interaction is through power.c to achieve the kernel the interaction is mainly through SYS file to achieve the kernel Layer introduction .
This layer of functionality is relatively complex ,wake lock application and release, etc. Span lang= "en-us", but this layer is not related to the hardware platform google "en-us" by