An analysis of the wakelock mechanism of Android

Source: Internet
Author: User

Transferred from: http://blog.sina.com.cn/s/blog_4ad7c2540101n2k2.html

The essence of the application power consumption is that the enabled hardware is consuming electricity.
Power consumption unit of mobile phone
CPU: Application Processor (application Processor) and baseband processor (base Band)

SOC (System-level chip): GPU (graphics processing unit),

Video codec and other peripherals: WIFI,BT, GPS,LCD, etc.
Power consumption Situation:
Application Processor (application Processor) 40~60ma

GPU is larger than 100mA when it is turned on

Baseband processor (base Band) 3~5ma

100~200ma during a call

LCD 100mA

Wifi 100mA
BT 60mA

The AP is an arm-architected processor for running the linux+android system;

BP is used to run a real-time operating system (RTOS), and the communication protocol stack runs on the BP RTOs.

Non-talk time, BP's energy consumption is basically around 5mA, and the AP as long as the non-dormant state, energy consumption at least 50mA, the implementation of graphics operations will be higher. In addition, the LCD operating power consumption around 100mA, WiFi is also around 100mA.

When the phone is in standby, the AP, LCD, WiFi all go to sleep, then the Android application code will stop execution, only the baseband processor (base Band) power consumption.

As an example of Motorola's milestone phone, the official parameters are as follows:

Lithium Battery (1400mAh) Talk time 450 minutes standby time 420 hours

That is, 1400/(450/60) = 186.67mA at the time of the call

Standby Time 1400/420 = 3.33mA
Power-saving principles: Use hardware on demand and at minimum standards


Wakelock mechanism:

In order to ensure the proper execution of critical code in the application, Android provides the API for Wake Lock, which allows the application to have permission to prevent the AP from entering hibernation through code.
Wakelock Blocks the application processor (application Processor) from suspending, ensuring critical code runs, and by interrupting the application processor (application Processor), you can prevent the screen from darkening. After all the Wakelock are released, the system hangs.
PowerManager pm = (powermanager) context.getsystemservice (Context.power_service); WakeLock Scpuwakelock = Pm.newwakelock (
Powermanager.full_wake_lock |
Powermanager.acquire_causes_wakeup, "Oktag");

if (scpuwakelock!= null) {

Scpuwakelock.release ();

Scpuwakelock = null;

}


Partial_wake_lock: Keep the CPU running, and the screen and keyboard lights may be off.
Screen_dim_wake_lock: Keep the CPU running, allow the screen to be displayed but may be gray, allow to turn off the keyboard light
Screen_bright_wake_lock: Keep the CPU running, keep the screen highlighted, allow the keyboard light to turn off
Full_wake_lock: Keep the CPU running, keep the screen highlighted, and the keyboard lights remain bright
Acquire_causes_wakeup: Does not wake the device, force the screen to be highlighted immediately, the keyboard light is turned on. With one exception, if a notification pops up, the device will wake up.
On_after_release:wakelock is released, maintain the brightness of the screen for a short period of time, reduce the flicker when the WakeLock cycle
If you apply for partial wakelock, the system does not enter sleep even if you press the power key, such as music playback if you apply for other wakelocks, press the Power key, the system will still go to sleep

However, if you do not understand the intentions of the Android designer to misuse the wake Lock API, in order to its own program in the background of the normal operation and long time to prevent the AP into hibernation, will become a standby battery killer.

Alarm Manager
Alarmmanage has a alarmmanagerservice, the service program is mainly to maintain the app registered alarm, and always monitor the alarm device, once there is a alarm trigger, or alarm event occurred, Alarmmanagerservice will traverse the alarm list, find the appropriate registration alarm and issue the broadcast

Alarm Manager will maintain a wake lock on the CPU. This ensures that when the phone sleeps, it can also handle alarm broadcasts. Once alarm receiver's onreceive () method is executed, Wake Lock is released quickly. If a service is turned on in receiver, it is possible that the service has not been started and Wake Lock has been released. So this is the time to implement a separate wake lock policy.

There are 4 types of alarm:
1) rtc_wakeup
At the specified moment (when setting the alarm), wake the device to trigger the intent.

2) RTC
Triggers the intent at an explicit time, but does not wake the device.
3) Elapsed_realtime
After booting from the device, if the elapsed time reaches the total time, the intent is triggered, but the device is not awakened. The elapsed time includes any time the device sleeps. Note that the calculation point for the time lapse is since it was last started.
4) Elapsed_realtime_wakeup
When the total elapsed time is reached after the device is booted, the device is awakened and intent is triggered if necessary.

An analysis of the wakelock mechanism of Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.