[关联唤醒拦截]AMS的启动流程

2024-02-09 20:18

本文主要是介绍[关联唤醒拦截]AMS的启动流程,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

0. 流程图

SystemServer->AMS->PowerController->BackgroundCleanHelper

1. SystemServer.java

  • frameworks/base/services/java/com/android/server/SystemServer.java
    很多framewrok层的服务都是从这里定义启动的

1.1 SystemServer.startBootstrapServices()

package com.android.server;public final class SystemServer {private static final String TAG = "SystemServer";/*** Starts the small tangle of critical services that are needed to get* the system off the ground.  These services have complex mutual dependencies* which is why we initialize them all in one place here.  Unless your service* is also entwined in these dependencies, it should be initialized in one of* the other functions.*/private void startBootstrapServices() {...// 启动 AMS// Activity manager runs the show.traceBeginAndSlog("StartActivityManager");mActivityManagerService = mSystemServiceManager.startService(ActivityManagerService.Lifecycle.class).getService();mActivityManagerService.setSystemServiceManager(mSystemServiceManager);mActivityManagerService.setInstaller(installer);traceEnd();

1.2 初始化关联唤醒服务

// inone add start by suhuazhi powersave
import com.android.server.power.PowerController;
//inone add end by suhuazhi powersave/*** Starts a miscellaneous grab bag of stuff that has yet to be refactored* and organized.*/private void startOtherServices() {...// inone add start by suhuazhi for powersavePowerController powerctl = null;// inone add end by suhuazhi for powersave...// inone add start by suhuazhi powersavetry {Slog.i(TAG, "PowerController Service");// 实例化关联唤醒服务powerctl = new PowerController(context, mActivityManagerService);} catch (Throwable e) {reportWtf("starting PowerController", e);}// inone add end by suhuazhi powersave...}

2. AMS启动-ActivityManagerService.Lifecycle

  • frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
    public static final class Lifecycle extends SystemService {private final ActivityManagerService mService;public Lifecycle(Context context) {super(context);// 启动入口mService = new ActivityManagerServiceEx(context);}@Overridepublic void onStart() {mService.start();}@Overridepublic void onCleanupUser(int userId) {mService.mBatteryStatsService.onCleanupUser(userId);}public ActivityManagerService getService() {return mService;}}

3. AMS相关初始化

package com.android.server.am;public class ActivityManagerService extends ActivityManagerServiceExAbsimplements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {public class ActivityManagerServiceEx extends ActivityManagerService {

3.1 ActivityManagerService.systemReady()

package com.android.server;public final class SystemServer {private static final String TAG = "SystemServer";// We now tell the activity manager it is okay to run third party// code.  It will call back into us once it has gotten to the state// where third party code can really run (but before it has actually// started launching the initial applications), for us to complete our// initialization.mActivityManagerService.systemReady(() -> {...// inone add start by suhuazhi for power policytry {powerctlF.setWindowManager(windowManagerF);Slog.i(TAG, "PowerController Service systemReady");powerctlF.systemReady();} catch (Throwable e) {reportWtf("starting PowerController", e);}// inone add end by suhuazhi for power policy...}

4. PowerController 初始化

4.1 构造器

package com.android.server.power;// SystemServer.startOtherServices()public PowerController(Context context, IActivityManager activityManager) {mContext = context;mActivityManager = activityManager;}

4.2 AMS.systemReady()

    // call before AMS.SystemReadby// 系统触摸事件监听public void setWindowManager(WindowManagerService wm) {mWindowManagerFuncs = wm;}// called when system is AMS.ready ( that is all the service is started)public void systemReady() {HandlerThread handlerThread = new HandlerThread(TAG);handlerThread.start();msgHandler = new MyHandler(handlerThread.getLooper());// to init Data firstmsgHandler.sendMessage(msgHandler.obtainMessage(MSG_INIT));}

4.3 AMS.initData()

    private void initData() {createPowerSaveHelpers();}// create helpersprivate void createPowerSaveHelpers() {mBackgroundCleanHelper = new BackgroundCleanHelper(mContext, mActivityManager, msgHandler);}

至此打通SystemServer->AMS->PowerController->BackgroundCleanHelper

这篇关于[关联唤醒拦截]AMS的启动流程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/695195

相关文章

将Java项目提交到云服务器的流程步骤

《将Java项目提交到云服务器的流程步骤》所谓将项目提交到云服务器即将你的项目打成一个jar包然后提交到云服务器即可,因此我们需要准备服务器环境为:Linux+JDK+MariDB(MySQL)+Gi... 目录1. 安装 jdk1.1 查看 jdk 版本1.2 下载 jdk2. 安装 mariadb(my

SQL表间关联查询实例详解

《SQL表间关联查询实例详解》本文主要讲解SQL语句中常用的表间关联查询方式,包括:左连接(leftjoin)、右连接(rightjoin)、全连接(fulljoin)、内连接(innerjoin)、... 目录简介样例准备左外连接右外连接全外连接内连接交叉连接自然连接简介本文主要讲解SQL语句中常用的表

Redis在windows环境下如何启动

《Redis在windows环境下如何启动》:本文主要介绍Redis在windows环境下如何启动的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Redis在Windows环境下启动1.在redis的安装目录下2.输入·redis-server.exe

如何高效移除C++关联容器中的元素

《如何高效移除C++关联容器中的元素》关联容器和顺序容器有着很大不同,关联容器中的元素是按照关键字来保存和访问的,而顺序容器中的元素是按它们在容器中的位置来顺序保存和访问的,本文介绍了如何高效移除C+... 目录一、简介二、移除给定位置的元素三、移除与特定键值等价的元素四、移除满足特android定条件的元

解决SpringBoot启动报错:Failed to load property source from location 'classpath:/application.yml'

《解决SpringBoot启动报错:Failedtoloadpropertysourcefromlocationclasspath:/application.yml问题》这篇文章主要介绍... 目录在启动SpringBoot项目时报如下错误原因可能是1.yml中语法错误2.yml文件格式是GBK总结在启动S

springboot filter实现请求响应全链路拦截

《springbootfilter实现请求响应全链路拦截》这篇文章主要为大家详细介绍了SpringBoot如何结合Filter同时拦截请求和响应,从而实现​​日志采集自动化,感兴趣的小伙伴可以跟随小... 目录一、为什么你需要这个过滤器?​​​二、核心实现:一个Filter搞定双向数据流​​​​三、完整代码

SpringBoot启动报错的11个高频问题排查与解决终极指南

《SpringBoot启动报错的11个高频问题排查与解决终极指南》这篇文章主要为大家详细介绍了SpringBoot启动报错的11个高频问题的排查与解决,文中的示例代码讲解详细,感兴趣的小伙伴可以了解一... 目录1. 依赖冲突:NoSuchMethodError 的终极解法2. Bean注入失败:No qu

一文带你了解SpringBoot中启动参数的各种用法

《一文带你了解SpringBoot中启动参数的各种用法》在使用SpringBoot开发应用时,我们通常需要根据不同的环境或特定需求调整启动参数,那么,SpringBoot提供了哪些方式来配置这些启动参... 目录一、启动参数的常见传递方式二、通过命令行参数传递启动参数三、使用 application.pro

SpringBoot项目启动报错"找不到或无法加载主类"的解决方法

《SpringBoot项目启动报错找不到或无法加载主类的解决方法》在使用IntelliJIDEA开发基于SpringBoot框架的Java程序时,可能会出现找不到或无法加载主类com.example.... 目录一、问题描述二、排查过程三、解决方案一、问题描述在使用 IntelliJ IDEA 开发基于

Spring AI ectorStore的使用流程

《SpringAIectorStore的使用流程》SpringAI中的VectorStore是一种用于存储和检索高维向量数据的数据库或存储解决方案,它在AI应用中发挥着至关重要的作用,本文给大家介... 目录一、VectorStore的基本概念二、VectorStore的核心接口三、VectorStore的