Android 优化关机速度

1.1 Android reboot流程

[图片上传失败...(image-6eeea-1526054751305)]

**思路: **执行到shutdown::run时,
a.设置Flag QuickShutdown=true
b.以广播通知系统一键加速清理进程,此时联网、影响用户体验、最经使用的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相关调用栈

[图片上传失败...(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
    }
...
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容