首页 > 其他分享 >Android开机启动流程

Android开机启动流程

时间:2024-09-10 12:52:40浏览次数:12  
标签:java 流程 server services base 开机 Android com android

Android开机启动流程

systemReady启动"added application"

@frameworks/base/services/java/com/android/server/SystemServer.java
main
    new SystemServer().run();
        startBootstrapServices
            mActivityManagerService = ActivityManagerService.Lifecycle.startService(mSystemServiceManager, atm);
            mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class);
            mActivityManagerService.setSystemProcess();
@frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
                ServiceManager.addService(Context.ACTIVITY_SERVICE
                ServiceManager.addService("meminfo", new MemBinder(this)
                ServiceManager.addService("gfxinfo", new GraphicsBinder(this))
                ApplicationInfo info = mContext.getPackageManager().getApplicationInfo( "android", STOCK_PM_FLAGS | MATCH_SYSTEM_ONLY);
                mSystemThread.installSystemApplicationInfo(info, getClass().getClassLoader());
                ProcessRecord app = mProcessList.newProcessRecordLocked(info, info.processName,   
        startOtherServices
@frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
            mActivityManagerService.systemReady(() -> {
                mLocalDeviceIdleController = LocalServices.getService(DeviceIdleInternal.class);
@frameworks/base/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
                mActivityTaskManager.onSystemReady();
@frameworks/base/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java
                    mTaskSupervisor.onSystemReady();
@frameworks/base/services/core/java/com/android/server/wm/LaunchParamsPersister.java
                        mLaunchParamsPersister.onSystemReady();
                            PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
                            mPackageList = pmi.getPackageList(new PackageListObserver());
@frameworks/base/services/core/java/com/android/server/am/UserController.java
                mUserController.onSystemReady();
@frameworks/base/services/core/java/com/android/server/appop/AppOpsService.java
                mAppOpsService.systemReady();
                mProcessList.onSystemReady();
                    mAppExitInfoTracker.onSystemReady();
                ArrayList<ProcessRecord> procsToKill = null;  //杀应用名单
                for (int i=mPidsSelfLocked.size()-1; i>=0; i--) {
                    ProcessRecord proc = mPidsSelfLocked.valueAt(i);
                    procsToKill.add(proc);
@frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
                startPersistentApps(PackageManager.MATCH_DIRECT_BOOT_AWARE);
                    final List<ApplicationInfo> apps = AppGlobals.getPackageManager().getPersistentApplications(STOCK_PM_FLAGS | matchFlags).getList();
                    addAppLocked(app, null, false, null 
                        ProcessRecord app;
                        app = mProcessList.newProcessRecordLocked(info, customProcess, isolated, 0,
                        mProcessList.startProcessLocked(app, new HostingRecord("added application", customProcess != null ? customProcess : app.processName),
                            Start proc 1056:com.android.se/1068 for type:added application type end com.android.se
                            Start proc 1078:com.android.phone/1001 for type:added application type end com.android.phone
                            Start proc 1079:com.android.systemui/u0a50 for type:added application type end com.android.systemui
        

Home应用程序

Android系统在启动时安装应用程序的过程,这些应用程序安装好之后,还需要有一个Home应用程序来负责把它们在桌面上展示出来,在Android系统中,这个默认的Home应用程序就是Launcher了.

@frameworks/base/services/core/java/com/android/server/am/UserController.java
finishUserUnlocking
    mHandler.obtainMessage(USER_UNLOCK_MSG, userId, 0, uss).sendToTarget();
        case USER_UNLOCK_MSG: finishUserUnlocked
            finishUserUnlockedCompleted
                mHandler.obtainMessage(USER_UNLOCKED_MSG, userId, 0).sendToTarget();
                    case USER_UNLOCKED_MSG: mInjector.getSystemServiceManager().onUserUnlocked(msg.arg1);
                        mService.mTaskSupervisor.onUserUnlocked(user.getUserIdentifier());
@frameworks/base/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java
                            scheduleStartHome("userUnlocked");
                                mHandler.obtainMessage(START_HOME_MSG, reason).sendToTarget();
                                    case START_HOME_MSG: { mRootWindowContainer.startHomeOnEmptyDisplays((String) msg.obj);    
                                    @frameworks/base/services/core/java/com/android/server/wm/RootWindowContainer.java
                                        startHomeOnEmptyDisplays
                                            forAllTaskDisplayAreas(taskDisplayArea -> {
                                                startHomeOnTaskDisplayArea(mCurrentUser, myReason, taskDisplayArea,        
@frameworks/base/services/core/java/com/android/server/wm/ActivityStartController.java
                                                    Service.getActivityStartController().startHomeActivity(homeIntent, aInfo, myReason, taskDisplayArea);
@frameworks/base/services/core/java/com/android/server/wm/ActivityStarter.java
                                                        mLastHomeActivityStartResult = obtainStarter(intent, "startHomeActivity: " + reason).setActivityOptions(options.toBundle()).execute();
                                                            res = executeRequest(mRequest);
                                                                ActivityRecord r = new ActivityRecord.Builder(mService)..setActivityInfo(aInfo)
                                                                mLastStartActivityResult = startActivityUnchecked(r, sourceRecord, voiceSession,
                                                                    result = startActivityInner(r, sourceRecord, voiceSession, voiceInteractor,startFlags, doResume, options, inTask, inTaskFragment, restrictedBgActivity,
                                                                        mTargetRootTask.startActivityLocked(mStartActivity,
@frameworks/base/services/core/java/com/android/server/wm/RootWindowContainer.java
                                                                        mRootWindowContainer.resumeFocusedTasksTopActivities(mTargetRootTask, mStartActivity, mOptions, mTransientLaunch);
                                                                            final Task focusedRoot = display.getFocusedRootTask();
@frameworks/base/services/core/java/com/android/server/wm/Task.java
                                                                            focusedRoot.resumeTopActivityUncheckedLocked(target, targetOptions);
                                                                                someActivityResumed = resumeTopActivityInnerLocked(prev, options, deferPause);
@frameworks/base/services/core/java/com/android/server/wm/TaskFragment.java
                                                                                    resumed[0] = topFragment.resumeTopActivity(prev, options, deferPause);
                                                                                        ActivityRecord next = topRunningActivity(true /* focusableOnly */);
                                                                                        pausing |= startPausing(mTaskSupervisor.mUserLeaving, false /* uiSleeping */, next, "resumeTopActivity");  //这里就是stop上一个activity的地方
                                                                                        if (next.attachedToProcess()) {   //要启动的activity所在的进程已经起来了,直接通过事务的形式去启动activity
                                                                                            final ClientTransaction transaction = ClientTransaction.obtain(next.app.getThread(), next.appToken);
                                                                                            mAtmService.getLifecycleManager().scheduleTransaction(transaction);
                                                                                        } else {   //如果进程没启动,调用ActivityTaskSupervisor的startSpecificActivity
@frameworks/base/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java
                                                                                            mTaskSupervisor.startSpecificActivity(next, true, true);
@base/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
                                                                                                mService.startProcessAsync(r, knownToBeDead, isTop, isTop ? "top-activity" : "activity");
                                                                                                    final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::startProcess, mAmInternal, activity.processName,
                                                                                                    mH.sendMessage(m);
                                                                                                        LocalService::startProcess  //class LocalService extends ActivityManagerInternal
                                                                                                            startProcessLocked(processName, info, knownToBeDead, 0 /* intentFlags */, new HostingRecord(hostingType, hostingName, isTop),
@frameworks/base/services/core/java/com/android/server/am/ProcessList.java
                                                                                                                return mProcessList.startProcessLocked(processName, info, knownToBeDead, intentFlags,
                                                                                                                    startProcessLocked(app, hostingRecord, zygotePolicyFlags, abiOverride);
                                                                                                                        startProcessLocked(app, hostingRecord, zygotePolicyFlags, false
                                                                                                                            startProcessLocked(hostingRecord, entryPoint, app, uid, gids, runtimeFlags, zygotePolicyFlags, mountExternal, seInfo, requiredAbi,
                                                                                                                                mService.mProcStartHandler.post(() -> handleProcessStart( app,
                                                                                                                                    handleProcessStartedLocked(app, startResult, startSeq);
                                                                                                                                        return handleProcessStartedLocked(pending, startResult.pid, startResult.usingWrapper,
                                                                                                                                            buf.append("Start proc ");  //Start proc 1486:com.dynabook.VDlauncher/1000 for top-activity {com.dynabook.VDlauncher/com.dynabook.VDlauncher.MainActivity}
                                                                                                                                            buf.append(pid);
                                                                                                                                            buf.append(':');
                                                                                                                                            buf.append(app.processName);
                                                                                                                                            buf.append('/');
                                                                                                                                            buf.append(app.getHostingRecord().getType());
                                                                                                                                            buf.append(app.getHostingRecord().getName());
                                                                                                                                            
                                                                                                                                            ..............
@src/main/java/com/xxx/launcher/MainActivity.java
                                                                                                                                                MainActivity::onCreate 

@frameworks/base/services/java/com/android/server/SystemServer.java
main
    new SystemServer().run();
        startBootstrapServices
            mActivityManagerService = ActivityManagerService.Lifecycle.startService(mSystemServiceManager, atm);
            mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class);
            mActivityManagerService.setSystemProcess();
@frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
                ServiceManager.addService(Context.ACTIVITY_SERVICE
                ServiceManager.addService("meminfo", new MemBinder(this)
                ServiceManager.addService("gfxinfo", new GraphicsBinder(this))
                ApplicationInfo info = mContext.getPackageManager().getApplicationInfo( "android", STOCK_PM_FLAGS | MATCH_SYSTEM_ONLY);
                mSystemThread.installSystemApplicationInfo(info, getClass().getClassLoader());
                ProcessRecord app = mProcessList.newProcessRecordLocked(info, info.processName,   
        startOtherServices
@frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
            mActivityManagerService.systemReady(() -> {
                mLocalDeviceIdleController = LocalServices.getService(DeviceIdleInternal.class);
@frameworks/base/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
                mActivityTaskManager.onSystemReady();
@frameworks/base/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java
                    mTaskSupervisor.onSystemReady();
@frameworks/base/services/core/java/com/android/server/wm/LaunchParamsPersister.java
                        mLaunchParamsPersister.onSystemReady();
                            PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
                            mPackageList = pmi.getPackageList(new PackageListObserver());
@frameworks/base/services/core/java/com/android/server/am/UserController.java
                mUserController.onSystemReady();
@frameworks/base/services/core/java/com/android/server/appop/AppOpsService.java
                mAppOpsService.systemReady();
                mProcessList.onSystemReady();
                    mAppExitInfoTracker.onSystemReady();
                ArrayList<ProcessRecord> procsToKill = null;  //杀应用名单
                for (int i=mPidsSelfLocked.size()-1; i>=0; i--) {
                    ProcessRecord proc = mPidsSelfLocked.valueAt(i);
                    procsToKill.add(proc);
@frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
                startPersistentApps(PackageManager.MATCH_DIRECT_BOOT_AWARE);
                    final List<ApplicationInfo> apps = AppGlobals.getPackageManager().getPersistentApplications(STOCK_PM_FLAGS | matchFlags).getList();
                    addAppLocked(app, null, false, null 
                        ProcessRecord app;
                        app = mProcessList.newProcessRecordLocked(info, customProcess, isolated, 0,
                        mProcessList.startProcessLocked(app, new HostingRecord("added application", customProcess != null ? customProcess : app.processName),
                            Start proc 1056:com.android.se/1068 for type:added application type end com.android.se
                            Start proc 1078:com.android.phone/1001 for type:added application type end com.android.phone
                            Start proc 1079:com.android.systemui/u0a50 for type:added application type end com.android.systemui
        
@frameworks/base/services/core/java/com/android/server/am/UserController.java
finishUserUnlocking
    mHandler.obtainMessage(USER_UNLOCK_MSG, userId, 0, uss).sendToTarget();
        case USER_UNLOCK_MSG: finishUserUnlocked
            finishUserUnlockedCompleted
                mHandler.obtainMessage(USER_UNLOCKED_MSG, userId, 0).sendToTarget();
                    case USER_UNLOCKED_MSG: mInjector.getSystemServiceManager().onUserUnlocked(msg.arg1);
                        mService.mTaskSupervisor.onUserUnlocked(user.getUserIdentifier());
@frameworks/base/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java
                            scheduleStartHome("userUnlocked");
                                mHandler.obtainMessage(START_HOME_MSG, reason).sendToTarget();
                                    case START_HOME_MSG: { mRootWindowContainer.startHomeOnEmptyDisplays((String) msg.obj);    
                                    @frameworks/base/services/core/java/com/android/server/wm/RootWindowContainer.java
                                        startHomeOnEmptyDisplays
                                            forAllTaskDisplayAreas(taskDisplayArea -> {
                                                startHomeOnTaskDisplayArea(mCurrentUser, myReason, taskDisplayArea,        
@frameworks/base/services/core/java/com/android/server/wm/ActivityStartController.java
                                                    Service.getActivityStartController().startHomeActivity(homeIntent, aInfo, myReason, taskDisplayArea);
@frameworks/base/services/core/java/com/android/server/wm/ActivityStarter.java
                                                        mLastHomeActivityStartResult = obtainStarter(intent, "startHomeActivity: " + reason).setActivityOptions(options.toBundle()).execute();
                                                            res = executeRequest(mRequest);
                                                                ActivityRecord r = new ActivityRecord.Builder(mService)..setActivityInfo(aInfo)
                                                                mLastStartActivityResult = startActivityUnchecked(r, sourceRecord, voiceSession,
                                                                    result = startActivityInner(r, sourceRecord, voiceSession, voiceInteractor,startFlags, doResume, options, inTask, inTaskFragment, restrictedBgActivity,
                                                                        mTargetRootTask.startActivityLocked(mStartActivity,
@frameworks/base/services/core/java/com/android/server/wm/RootWindowContainer.java
                                                                        mRootWindowContainer.resumeFocusedTasksTopActivities(mTargetRootTask, mStartActivity, mOptions, mTransientLaunch);
                                                                            final Task focusedRoot = display.getFocusedRootTask();
@frameworks/base/services/core/java/com/android/server/wm/Task.java
                                                                            focusedRoot.resumeTopActivityUncheckedLocked(target, targetOptions);
                                                                                someActivityResumed = resumeTopActivityInnerLocked(prev, options, deferPause);
@frameworks/base/services/core/java/com/android/server/wm/TaskFragment.java
                                                                                    resumed[0] = topFragment.resumeTopActivity(prev, options, deferPause);
                                                                                        ActivityRecord next = topRunningActivity(true /* focusableOnly */);
                                                                                        pausing |= startPausing(mTaskSupervisor.mUserLeaving, false /* uiSleeping */, next, "resumeTopActivity");  //这里就是stop上一个activity的地方
                                                                                        if (next.attachedToProcess()) {   //要启动的activity所在的进程已经起来了,直接通过事务的形式去启动activity
                                                                                            final ClientTransaction transaction = ClientTransaction.obtain(next.app.getThread(), next.appToken);
                                                                                            mAtmService.getLifecycleManager().scheduleTransaction(transaction);
                                                                                        } else {   //如果进程没启动,调用ActivityTaskSupervisor的startSpecificActivity
@frameworks/base/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java
                                                                                            mTaskSupervisor.startSpecificActivity(next, true, true);
@base/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
                                                                                                mService.startProcessAsync(r, knownToBeDead, isTop, isTop ? "top-activity" : "activity");
                                                                                                    final Message m = PooledLambda.obtainMessage(ActivityManagerInternal::startProcess, mAmInternal, activity.processName,
                                                                                                    mH.sendMessage(m);
                                                                                                        LocalService::startProcess  //class LocalService extends ActivityManagerInternal
                                                                                                            startProcessLocked(processName, info, knownToBeDead, 0 /* intentFlags */, new HostingRecord(hostingType, hostingName, isTop),
@frameworks/base/services/core/java/com/android/server/am/ProcessList.java
                                                                                                                return mProcessList.startProcessLocked(processName, info, knownToBeDead, intentFlags,
                                                                                                                    startProcessLocked(app, hostingRecord, zygotePolicyFlags, abiOverride);
                                                                                                                        startProcessLocked(app, hostingRecord, zygotePolicyFlags, false
                                                                                                                            startProcessLocked(hostingRecord, entryPoint, app, uid, gids, runtimeFlags, zygotePolicyFlags, mountExternal, seInfo, requiredAbi,
                                                                                                                                mService.mProcStartHandler.post(() -> handleProcessStart( app,
                                                                                                                                    handleProcessStartedLocked(app, startResult, startSeq);
                                                                                                                                        return handleProcessStartedLocked(pending, startResult.pid, startResult.usingWrapper,
                                                                                                                                            buf.append("Start proc ");  //Start proc 1486:com.dynabook.VDlauncher/1000 for top-activity {com.dynabook.VDlauncher/com.dynabook.VDlauncher.MainActivity}
                                                                                                                                            buf.append(pid);
                                                                                                                                            buf.append(':');
                                                                                                                                            buf.append(app.processName);
                                                                                                                                            buf.append('/');
                                                                                                                                            buf.append(app.getHostingRecord().getType());
                                                                                                                                            buf.append(app.getHostingRecord().getName());
                                                                                                                                            
                                                                                                                                            ..............
@src/main/java/com/xxx/launcher/MainActivity.java
                                                                                                                                                MainActivity::onCreate 

标签:java,流程,server,services,base,开机,Android,com,android
From: https://blog.csdn.net/wenwang88/article/details/142066718

相关文章

  • 审批流程超简单实现(Java版)
    ##审批流程超简单实现(Java版)在企业管理中,审批流程是不可或缺的一部分,它贯穿于各种业务场景,例如请假申请、报销审批、合同签署等等。传统的审批流程往往依赖于纸质文件和人工传递,效率低下且容易出错。随着信息化的发展,越来越多的企业开始采用电子化的审批流程,以提高效率、降低成本......
  • 考试环境部署方案流程及疑难解决!
     在数字化时代,考试系统的选择和应用已成为教育、培训和企业招聘、认证中不可或缺的一环。今天来介绍下锐起RDV云桌面是如何部署考试环境的: 第一步:安装考试系统 通过镜像克隆功能,创建一个干净的基本系统(没有其他教学软件),在管理平台上只需要操作几个按钮,整个过程只需一分钟......
  • 如何集成Android平台GB28181设备接入模块?
    技术优势大牛直播SDK的Android平台GB28181设备接入模块在适用场景、音视频能力、定位与通信、数据管理、安全性与稳定性、配置与扩展性以及集成与维护等方面均表现出显著的优势。这些优势使得该模块在视频监控、巡检抢修、远程指挥等多个领域具有广泛的应用前景和重要的应用价值。......
  • 第20篇 window系统安装Redis流程
    1.下载RedisforWindowsRedis官方并没有提供Windows版本的安装包,但你可以使用Microsoft维护的Windows版本的Redis。你可以从以下链接下载RedisforWindows:2.安装Redis运行安装程序:双击下载的.msi文件,启动安装程序。按照安装向导的提示进行安装。这里记得......
  • Android中SurfaceView的双缓冲机制和普通View叠加问题解决办法
    本文首发于公众号“AntDream”,欢迎微信搜索“AntDream”或扫描文章底部二维码关注,和我一起每天进步一点点SurfaceView是Android平台上用于高效渲染图形的视图控件。它将内容绘制在一个独立的Surface上,可以直接由渲染线程访问,从而提高性能,尤其是在需要频繁刷新和更新......
  • MapBox Android版开发 4 国际化功能v11
    MapBoxAndroid版开发4国际化功能v11前言遇到的问题国际化功能原文给出的方案(V10版)migrate-to-v11适用于V11版的代码示例MapStyle类运行效果图前言在前文MapBox地图样式v11中,使用Style的localizeLabels方法本地化地图语言。但MapboxStandard样式和MapboxStan......
  • Android视频编辑:利用FFmpeg实现高级功能
    在移动设备上进行视频编辑的需求日益增长,用户期望能够在智能手机或平板电脑上轻松地编辑视频,以满足社交媒体分享或个人存档的需求。Android平台因其广泛的用户基础和开放的生态系统,成为视频编辑应用的理想选择。FFmpeg,作为一个强大的多媒体框架,为Android视频编辑应用提供了......
  • 基于STM32的智能宿舍安全管理系统:集成电流监测、烟雾探测与无线通信技术,实现高效用电
    一、项目概述随着校园生活的日益便利,宿舍用电管理成为了一个重要的课题。本项目旨在开发一个宿舍用电管理系统,通过STM32单片机实现对宿舍用电功率的监管,实时监测用电量,并计算费用。系统还具备远程控制功能,可以对每个宿舍的用电进行管理,包括开关控制、统一断电等。此外,系统......
  • 基于微信小程序与嵌入式系统的智能小车开发(详细流程)
    一、项目概述本项目旨在开发一款智能小车,结合微信小程序与嵌入式系统,提供实时图像处理与控制功能。用户可以通过微信小程序远程操控小车,并实时接收摄像头采集的图像。该项目解决了传统遥控小车在图像反馈和控制延迟方面的问题,提升了小车的智能化水平,适用于教育、科研和娱乐......
  • 基于ARM芯片与OpenCV的工业分拣机器人项目设计与实现流程详解
    一、项目概述项目目标和用途本项目旨在设计和实现一套工业分拣机器人系统,能够高效、准确地对不同类型的物品进行自动分拣。该系统广泛应用于物流、仓储和制造业,能够显著提高工作效率,降低人工成本。技术栈关键词ARM芯片步进电机控制OpenCV图像识别无线通信模块......