Article reprinted from: Http://blog.csdn.net/hzdysymbol/archive/2009/03/19/4004791.aspx
Kernel layer
Its main code is in the following locations :
Drivers/android/power.c
The interface functions provided to kernel are
Export_symbol (Android_init_suspend_lock); Initialize Suspend lock, which must be initialized before use
Export_symbol (Android_uninit_suspend_lock); Release suspend lock related resources
Export_symbol (Android_lock_suspend); To apply lock, you must call the appropriate unlock to release it .
Export_symbol (Android_lock_suspend_auto_expire);//apply for partial wakelock, which will be automatically released after the scheduled time
Export_symbol (Android_unlock_suspend); Release Lock
Export_symbol (Android_power_wakeup); Wake-up system to on
Export_symbol (Android_register_early_suspend); Registering The early suspend driver
Export_symbol (Android_unregister_early_suspend); Cancel the driver of the registered early suspend
the proc files provided to the Android framework layer are as follows :
"/sys/android_power/acquire_partial_wake_lock"//apply for partial wake lock
"/sys/android_power/acquire_full_wake_lock"//apply for full Wake lock
"/sys/android_power/release_wake_lock"//release the corresponding wake lock
"/sys/android_power/request_state"//Request Change System Status , enter standby and return to wakeup two states
"/sys/android_power/state"//indicates the status of the current system
The power management of Android is mainly implemented by Wake Lock , which is managed by the following three queues at the lowest level:
Static List_head (g_inactive_locks);
Static List_head (g_active_partial_wake_locks);
Static List_head (g_active_full_wake_locks);
After all the initializedLock will be inserted into theG_inactive_locks in the queue, while the current activeThe partial wake lock will be inserted into theG_active_partial_wake_locks in queue, the activefull wake Lock is inserted into inactive queue Span lang= "en-US" >< Span style= "LINE-HEIGHT:18PX; Font-family: ' Times New Roman '; >.
Use the wake Lock steps on the kernel layer as follows :
1. Call function Android_init_suspend_lock initialize a wake lock
2.Invoke related applicationThe function of lockAndroid_lock_suspend or Android_lock_suspend_auto_expire RequestLock, you can only apply herepartial Wake lock, If you want to apply for full wake Lock, you need to call the function Span lang= "en-US" >android_lock_partial_suspend _auto_expire (This function does not have export out
3. if is wake lock can ignore the Span lang= "en-US" >wake Lock released
4. Remember to call Android_uninit_suspend_lock release Resources in a timely manner when the driver unloads or no longer uses Wake lock.
Status of the system :
User_awake,//full on status
User_notification,//early suspended driver but CPU keep on
User_sleep//CPU Enter SLEEP mode
The status switches are as follows :
system normal boot into the awake state, backlight will slowly adjust from the lightest to user-defined brightness, System screen off timer (Settings->sound & display-> Display Settings-screen timeout) begins the timing of the reset screen off if any activity events occur, such as touch click, Keyboard pressed, before the time elapsed. Timer, the system remains in the awake state. If an application has applied for full wake lock during this time, the system will remain in the awake state unless the user presses power key. In the awake state, if the battery level is low, or if it is powered by AC, screen off timer time is checked and the keep screen on and pluged in option is selected, backlight is forced to adjust to the dim state.
If screen off timer time is reached and no full wake lock or the user presses power key, then the system state is switched to notification and all registered G_early_suspend_ are called. The handlers function typically registers the LCD and backlight drivers as early suspend types and, if necessary, registers other drivers as early suspend, which is closed in the first phase. Next, the system will determine if there is a partial wake lock acquired, if there is a wait for its release, in the process of waiting for the user activity event occurs, the system immediately back to awake state, if there is no partial wake lock Acquired, the system will immediately call the function Pm_suspend close other related drivers and let the CPU go into hibernation.
If any one wakeup source is detected in the sleep state, the CPU is awakened from the sleep state, and the associated driver's resume function is called, and the resume function of the pre-registered early suspend driver is immediately called. Finally, the system state goes back to the awake state. Here's the problem is that all functions that have registered early suspend are invoked in the first stage of the suspend, but at the time of the resume, Linux invokes all the driver's resume functions. What is the point of calling the resume function of the pre-registered early suspend driver at this time? Personally think that this early suspend and late resume function of Android should be used in conjunction with the suspend and resume under Linux Instead of using a single queue for management.