Android power management [by Steve Guo]

Source: Internet
Author: User

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 is the core service. It callpower. 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 is the JNI native implementation for power. java. It callpower. 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 ();

 

Address: http://letsgoustc.spaces.live.com/blog/cns! 89ad27dfb5e249ba! 526. Entry

Related Article

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.