1.1 Android reboot流程
[圖片上傳失敗...(image-6eeea-1526054751305)]
**思路: **執(zhí)行到shutdown::run時,
a.設置Flag QuickShutdown=true
b.以廣播通知系統(tǒng)一鍵加速清理進程,此時聯(lián)網(wǎng)、影響用戶體驗、最經(jīng)使用的TopN應用均需清理;
一鍵加速原理參考:
2.1 AMS::startProcessLocked
private final void startProcessLocked(ProcessRecord app, String hostingType,
String hostingNameStr, String abiOverride, String entryPoint, String[] entryPointArgs) {
if(QuickShutdown) return;
...
}
2.2 AMS::handleAppDiedLocked
/**
* Main function for removing an existing process from the activity manager
* as a result of that process going away. Clears out all connections
* to the process.
*/
private final void handleAppDiedLocked(ProcessRecord app,
boolean restarting, boolean allowRestart) {
if(QuickShutdown) { // 禁止Process重啟
restarting = false;
allowRestart = false;
}
...
}
handleAppDiedLocked相關調(diào)用棧
[圖片上傳失敗...(image-f39c4e-1526054751305)]
左邊分支cleanUpApplicationRecordLocked用于清理死亡進程中運行的四大組件service, BroadcastReceiver, ContentProvider相關信息;
右邊分支ASS.handleAppDiedLocked清理死亡進程中運行的activity相關信息
參考:
binder_died
2.3 AMS::killPackageProcessesLocked
private final boolean killPackageProcessesLocked(String packageName, int appId, int userId, int minOomAdj, boolean callerWillRestart, boolean allowRestart,
boolean doit, boolean evenPersistent, String reason) {
if (QuickShutdown) {
callerWillRestart = false;
allowRestart = false;
evenPersistent = true; //persistent 進程需清理
doit = true; //app.removed=true時,添加進程到procs中,procs中的進程將被removeProcessLocked
}
...
}