Android系统关机的全流程解析

2019-12-10 19:02:04刘景俊
易采站长站为您分析Android系统关机的全流程解析,从上层空间一直深入到内核全面讲解,非常推荐!需要的朋友可以参考下  

在PowerManager的API文档中,给出了一个关机/重启接口:
public void reboot (String reason)

对于这个接口的描述很简单,就是几句话。
接口的作用就是重启设备,而且,就算重启成功了也没有返回值。
需要包含REBOOT权限,也就是android.permission.REBOOT
唯一参数reason代表需要的特定重启模式,比如recovery,当然也可以为null。

一、上层空间 
1.frameworks/base/core/java/android/os/PowerManager.java

/** 
 * Reboot the device. Will not return if the reboot is 
 * successful. Requires the {@link android.Manifest.permission#REBOOT} 
 * permission. 
 * 
 * @param reason code to pass to the kernel (e.g., "recovery") to 
 *        request special boot modes, or null. 
 */ 
public void reboot(String reason) 
{   
  try { 
    mService.reboot(reason); 
  } catch (RemoteException e) { 
  }   
}  

mService为IPowerManager Binder接口服务。

/** 
 * {@hide} 
 */ 
public PowerManager(IPowerManager service, Handler handler) 
{ 
  mService = service; 
  mHandler = handler; 
} 

2.frameworks/base/core/java/android/os/IPowerManager.aidl

interface IPowerManager 
{ 
... 
void reboot(String reason); 
... 
}