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

相关文章

Linux流媒体服务器部署流程

《Linux流媒体服务器部署流程》文章详细介绍了流媒体服务器的部署步骤,包括更新系统、安装依赖组件、编译安装Nginx和RTMP模块、配置Nginx和FFmpeg,以及测试流媒体服务器的搭建... 目录流媒体服务器部署部署安装1.更新系统2.安装依赖组件3.解压4.编译安装(添加RTMP和openssl模块

0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型的操作流程

《0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeekR1模型的操作流程》DeepSeekR1模型凭借其强大的自然语言处理能力,在未来具有广阔的应用前景,有望在多个领域发... 目录0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型,3步搞定一个应

Android里面的Service种类以及启动方式

《Android里面的Service种类以及启动方式》Android中的Service分为前台服务和后台服务,前台服务需要亮身份牌并显示通知,后台服务则有启动方式选择,包括startService和b... 目录一句话总结:一、Service 的两种类型:1. 前台服务(必须亮身份牌)2. 后台服务(偷偷干

Windows设置nginx启动端口的方法

《Windows设置nginx启动端口的方法》在服务器配置与开发过程中,nginx作为一款高效的HTTP和反向代理服务器,被广泛应用,而在Windows系统中,合理设置nginx的启动端口,是确保其正... 目录一、为什么要设置 nginx 启动端口二、设置步骤三、常见问题及解决一、为什么要设置 nginx

springboot启动流程过程

《springboot启动流程过程》SpringBoot简化了Spring框架的使用,通过创建`SpringApplication`对象,判断应用类型并设置初始化器和监听器,在`run`方法中,读取配... 目录springboot启动流程springboot程序启动入口1.创建SpringApplicat

树莓派启动python的实现方法

《树莓派启动python的实现方法》本文主要介绍了树莓派启动python的实现方法,文中通过图文介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录一、RASPBerry系统设置二、使用sandroidsh连接上开发板Raspberry Pi三、运

通过prometheus监控Tomcat运行状态的操作流程

《通过prometheus监控Tomcat运行状态的操作流程》文章介绍了如何安装和配置Tomcat,并使用Prometheus和TomcatExporter来监控Tomcat的运行状态,文章详细讲解了... 目录Tomcat安装配置以及prometheus监控Tomcat一. 安装并配置tomcat1、安装

MySQL的cpu使用率100%的问题排查流程

《MySQL的cpu使用率100%的问题排查流程》线上mysql服务器经常性出现cpu使用率100%的告警,因此本文整理一下排查该问题的常规流程,文中通过代码示例讲解的非常详细,对大家的学习或工作有一... 目录1. 确认CPU占用来源2. 实时分析mysql活动3. 分析慢查询与执行计划4. 检查索引与表

MYSQL关联关系查询方式

《MYSQL关联关系查询方式》文章详细介绍了MySQL中如何使用内连接和左外连接进行表的关联查询,并展示了如何选择列和使用别名,文章还提供了一些关于查询优化的建议,并鼓励读者参考和支持脚本之家... 目录mysql关联关系查询关联关系查询这个查询做了以下几件事MySQL自关联查询总结MYSQL关联关系查询

Git提交代码详细流程及问题总结

《Git提交代码详细流程及问题总结》:本文主要介绍Git的三大分区,分别是工作区、暂存区和版本库,并详细描述了提交、推送、拉取代码和合并分支的流程,文中通过代码介绍的非常详解,需要的朋友可以参考下... 目录1.git 三大分区2.Git提交、推送、拉取代码、合并分支详细流程3.问题总结4.git push