Android
Of
Power management is also an important part. For example, when the standby mode is used
After the screen and keyboard backlights are disabled, you need
The number of devices opened and so on are directly related to the product's standby time and user experience. On the Internet, you can find a reposted article about power management.
Of
Article http://blog.csdn.net/hzdysymbol/archive/2009/03/19/4004791.aspx
,
However, from top to bottom, it focuses more on how to apply the underlying layer. I will only talk about the framework in this article.
Layer Analysis, and how to customize as needed.
Framework
The layer mainly has these two files:
Frameworks/base/CORE/Java/Android/OS/powermanager. Java
Frameworks/base/services/Java/COM/Android/Server/powermanagerservice. Java
Powermanager. Java
Is provided to the application layer for calling, the final core is still in powermanagerservice. Java
.
This class is used to provide powermanager
And the running of the entire power management state machine. There are many functions and classes in it, from the external and internal points
For two parts. Let's talk about powermanagerservice.
How to manage the power supply, it is necessary to notify it when there is an external event, this master
In frameworks/base/services/Java/COM/Android/Server/windowmanagerservice. Java
Li
. Windowmanagerservice
The user's click screen and buttons are used as the user activity.
Things
To call useractivity
Function, powermanagerservice
In the useractivity
Li
Determine whether the event type is reflected, whether to light up the screen to provide the operation, or completely ignore it, or turn it off when it is only lit. Windowmanagerservice
Tune
You can also use Gotosleep.
And some other functions such as screenison
And so on.
Internally, useractivity acts as an external interface
The method is mainly through setpowerstate
Complete
Yes. Call setpowerstate as a parameter to set the power status, such as switching the screen backlight or something.
, Setpowerstate
First
Determine whether the desired status can be completed. For example, if you want to light up the screen, the screen is locked.
Otherwise, you can call power. setscreenstate (true)
Come
Through JNI
Run to driver
It lights up the screen. While the State loop of power supply is mainly through Handler
Come
. Powermanagerservice
In init
It starts a handlerthread
I
Background message loops to provide delayed task sending, you can use Handler
To delay the execution time of a task in order to realize the loop of the state machine. For example, timeout
,
After a period of time, no operation is required to darken the screen, and then disable it, which is reflected in the Code as follows: useractivity
Call setpowerstate.
Of
Settimeoutlocked will be used later
To set timeout
. Then in settimeoutlocked
Li
The plane calculates the next state and time based on the current state, and CALLS mhandler. postattime (mtimeouttask,
When)
To post
One timeouttask
. In this way, when
No
The timeouttask will be executed in seconds.
. In timeouttask
Setpowerstate is called Based on the set status.
Come
Change the power status, and then set a new status. For example, if you want to hide the screen, use settimeoutlocked (now,
Screen_off)
. If the screen is turned off this time, then the timeout of this round
Status Loop
Yes. If you want to customize it, for example, the requirement is in timeout.
After the screen is turned off, you need to turn off some peripheral devices and so on.
Li
After the screen is turned off, add the code to close other devices. Even if the new status requirement is completely different from the original one, use Handler
It should not be difficult. Logic
Just put the code in a proper place.
This article is from csdn
Blog, reprint please indicate the source: http://blog.csdn.net/dywe_ddm/archive/2010/05/17/5600396.aspx