[关联唤醒拦截]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

相关文章

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

SpringBoot整合Flowable实现工作流的详细流程

《SpringBoot整合Flowable实现工作流的详细流程》Flowable是一个使用Java编写的轻量级业务流程引擎,Flowable流程引擎可用于部署BPMN2.0流程定义,创建这些流程定义的... 目录1、流程引擎介绍2、创建项目3、画流程图4、开发接口4.1 Java 类梳理4.2 查看流程图4

Nexus安装和启动的实现教程

《Nexus安装和启动的实现教程》:本文主要介绍Nexus安装和启动的实现教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Nexus下载二、Nexus安装和启动三、关闭Nexus总结一、Nexus下载官方下载链接:DownloadWindows系统根

java Long 与long之间的转换流程

《javaLong与long之间的转换流程》Long类提供了一些方法,用于在long和其他数据类型(如String)之间进行转换,本文将详细介绍如何在Java中实现Long和long之间的转换,感... 目录概述流程步骤1:将long转换为Long对象步骤2:将Longhttp://www.cppcns.c

Java中实现线程的创建和启动的方法

《Java中实现线程的创建和启动的方法》在Java中,实现线程的创建和启动是两个不同但紧密相关的概念,理解为什么要启动线程(调用start()方法)而非直接调用run()方法,是掌握多线程编程的关键,... 目录1. 线程的生命周期2. start() vs run() 的本质区别3. 为什么必须通过 st

Oracle修改端口号之后无法启动的解决方案

《Oracle修改端口号之后无法启动的解决方案》Oracle数据库更改端口后出现监听器无法启动的问题确实较为常见,但并非必然发生,这一问题通常源于​​配置错误或环境冲突​​,而非端口修改本身,以下是系... 目录一、问题根源分析​​​二、保姆级解决方案​​​​步骤1:修正监听器配置文件 (listener.

MySQL版本问题导致项目无法启动问题的解决方案

《MySQL版本问题导致项目无法启动问题的解决方案》本文记录了一次因MySQL版本不一致导致项目启动失败的经历,详细解析了连接错误的原因,并提供了两种解决方案:调整连接字符串禁用SSL或统一MySQL... 目录本地项目启动报错报错原因:解决方案第一个:第二种:容器启动mysql的坑两种修改时区的方法:本地

MySQL启动报错:InnoDB表空间丢失问题及解决方法

《MySQL启动报错:InnoDB表空间丢失问题及解决方法》在启动MySQL时,遇到了InnoDB:Tablespace5975wasnotfound,该错误表明MySQL在启动过程中无法找到指定的s... 目录mysql 启动报错:InnoDB 表空间丢失问题及解决方法错误分析解决方案1. 启用 inno

spring-gateway filters添加自定义过滤器实现流程分析(可插拔)

《spring-gatewayfilters添加自定义过滤器实现流程分析(可插拔)》:本文主要介绍spring-gatewayfilters添加自定义过滤器实现流程分析(可插拔),本文通过实例图... 目录需求背景需求拆解设计流程及作用域逻辑处理代码逻辑需求背景公司要求,通过公司网络代理访问的请求需要做请

使用JavaConfig配置Spring的流程步骤

《使用JavaConfig配置Spring的流程步骤》JavaConfig是Spring框架提供的一种基于Java的配置方式,它通过使用@Configuration注解标记的类来替代传统的XML配置文... 目录一、什么是 JavaConfig?1. 核心注解2. 与 XML 配置的对比二、JavaConf