1. Problem description:
When the power is low, the system cannot continue to provide the call service. In order not to affect the quality of the call service or other problems, the call should be automatically suspended when the system shuts down automatically.
2. solution:
When a low-power automatic shutdown occurs, if there is a call at this time, call the interface for hanging up the phone and stop the phone.
3. Implementation Method:
Batteryservice. Java
Private void shutdownifnopowerlocked (){
// Shut down gracefully if our battery is critically low and we are not powered.
// Wait until the system has booted before attempting to display the shutdown dialog.
If (mbatteryprops. batterylevel = 0 &&! Ispoweredlocked (batterymanager. battery_plugged_any )){
Mhandler. Post (New runnable (){
@ Override
Public void run (){
If (activitymanagernative. issystemready ()){
If (featureoption. mtk_ipo_support = true ){
Systemproperties. Set ("SYS. IPO. battlow", "1 ");
}
Try {
Itelephony = itelephony. stub. asinterface (servicemanager. getservice (context. telephony_service ));
If (itelephony! = NULL ){
Itelephony. endcall ();
}
} Catch (exception e ){
E. printstacktrace ();
}
Intent intent = new intent (intent. action_request_shutdown );
Intent. putextra (intent. extra_key_confirm, false );
Intent. setflags (intent. flag_activity_new_task );
Mcontext. startactivityasuser (intent, userhandle. Current );
}
}
});
}
}
Note! The red part is the function implementation part.
Solve the Problem of automatic call shutdown when the power is low.