Android 優(yōu)化關機速度

1.1 Android reboot流程

[圖片上傳失敗...(image-6eeea-1526054751305)]

**思路: **執(zhí)行到shutdown::run時,
a.設置Flag QuickShutdown=true
b.以廣播通知系統(tǒng)一鍵加速清理進程,此時聯(lián)網(wǎng)、影響用戶體驗、最經(jīng)使用的TopN應用均需清理;

一鍵加速原理參考:

手機管理應用研究【4】—— 手機加速篇

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
    }
...
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容