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