Android系统关机的全流程解析

2019-12-10 19:02:04刘景俊

三、关机怎么用?
本文的分析是由Android给出的reboot接口开始的,但是分析来分析去,回头想一想会发现,Android给出的接口reboot就真的只能重启而已,不能进行关机操作,可以在跟踪这个流程的过程中会发现,确实是有存在关机的相关接口的。那么关机该怎么用呢?
frameworks/base/services/java/com/android/serverBatteryService.java

private final void shutdownIfNoPower() { 
// 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 (mBatteryLevel == 0 && !isPowered() && ActivityManagerNative.isSystemReady()) { 
  Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN); 
  intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false); 
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
  mContext.startActivity(intent); 
} 
 

注:相关教程知识阅读请移步到Android开发频道。