8.4 Android Lighting System _ Source Analysis _ Battery Light

Source: Internet
Author: User

The Java code of the battery lamp is in Batteryservice.java

The status of the battery and other information is driven by the driver, but the driver does not actively do these things, so there must be an app call driver read the battery information, said the app is a application.

There is also an app B, according to the low Battery situation prompt dialog box: Prompt Charging, dialog box: will be automatically shut down within 30S, application A will issue some notifications

Description

(1) APP0: Read driver, when driver detects a battery event occurs, wakes up APP0

(2)  app1,2,3 ... Registration Notification response function

(3) APP0 to give notice

(4) app1,2,3. Execute the corresponding function

Ctrl+shift+n input Batteryservice.java Punch-in

First register a listener event in the OnStart () function, in the Batterylistener class, if the battery attribute changes, the Batterypropertieschanged method is called

A. Batterypropertiesregistrar.registerlistener (new Batterylistener ());

The Batterypropertieschanged method calls the Update method, broadcasts the message in the update, the message property is intent.action_battery_changed, searches the android source, It is used in many places, such as Powermanagerservice.java, which registers a recipient
B. sendintentlocked ();

APP0 will continue to call the light's updatelightslocked function after the broadcast message is issued
C. mled.updatelightslocked ();

APP1/2/3 registers the recipient, waits for the message, receives the intent of interest, calls the OnReceive function in the Batteryreceiver class
D.
Register for broadcasts from and components of the system.
Intentfilter filter = new Intentfilter ();
Filter.addaction (intent.action_battery_changed);
Filter.setpriority (intentfilter.system_high_priority);
Mcontext.registerreceiver (New Batteryreceiver (), filter, NULL, Mhandler);

APP1/2/3 after receiving the message, call the following:

E.
OnReceive
Handlebatterystatechangedlocked
Updatepowerstatelocked

Reference articles
Android4.4 Battery Management
http://blog.csdn.net/wlwl0071986/article/details/38778897

8.4 Android Lighting System _ Source Analysis _ Battery Light

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.