单步调试Android Framework——App冷启动

发布于:2024-12-19 ⋅ 阅读:(12) ⋅ 点赞:(0)

在这里插入图片描述

纸上得来终觉浅,绝知此事要躬行。 —— [宋]陆游

基于aosp_cf_x86_64_phone-trunk_staging-eng , 下面是具体断点位置。

第一部分,桌面launcher进程

com.android.launcher3.touch.ItemClickHandler

  • onClick
  • onClickAppShortcut
  • startAppShortcutOrInfoActivity

com.android.launcher3.Launcher

  • startActivitySafely

com.android.launcher3.views.ActivityContext

  • startActivitySafely

android.app.Activity

  • startActivity(android.content.Intent, android.os.Bundle)

com.android.launcher3.uioverrides.QuickstepLauncher

  • startActivityForResult

com.android.launcher3.Launcher

  • startActivityForResult

android.app.Activity

  • startActivityForResult(android.content.Intent, int, android.os.Bundle)

android.app.Instrumentation

  • execStartActivity

第二部分,系统服务进程

com.android.server.wm.ActivityTaskManagerService

  • startActivity
  • startActivityAsUser
  • startActivityAsUser // 初始化了ActivityStarter

com.android.server.wm.ActivityStarter

  • execute
  • executeRequest // 准备了ActivityRecord
  • startActivityUnchecked
  • startActivityInner

com.android.server.wm.Task

  • startActivityLocked // 准备切换动画,此处WMS,showStartingWindow

com.android.server.wm.StartingSurfaceController

  • showStartingWindow

com.android.server.wm.ActivityRecord

  • showStartingWindow

com.android.server.wm.RootWindowContainer

  • resumeFocusedTasksTopActivities

com.android.server.wm.Task

  • resumeTopActivityUncheckedLocked
  • resumeTopActivityInnerLocked

com.android.server.wm.TaskFragment

  • resumeTopActivity

com.android.server.wm.ActivityTaskManagerService

  • startProcessAsync

com.android.server.am.ActivityManagerService.LocalService

  • startProcess
    com.android.server.am.ActivityManagerService
  • startProcessLocked

com.android.server.am.ProcessList

  • startProcessLocked

com.android.server.am.ProcessList

  • startProcessLocked

com.android.server.am.ProcessList

  • startProcess

android.os.Process

  • start

android.os.ZygoteProcess

  • start
  • startViaZygote
  • zygoteSendArgsAndGetResult
  • attemptZygoteSendArgsAndGetResult

android.app.ActivityThread

  • main
  • attach

com.android.server.am.ActivityManagerService

  • attachApplication // 目标进程已启动
  • attachApplicationLocked
  • finishAttachApplicationInner

// — ActivityThread
android.app.ActivityThread.ApplicationThread

  • bindApplication // 组装一个AppBindData

android.app.ActivityThread.H

  • handleMessage

android.app.ActivityThread

  • handleBindApplication

android.app.Instrumentation

  • callApplicationOnCreate
    // — ActivityThread

com.android.server.wm.ActivityTaskManagerService.LocalService

  • attachApplication

com.android.server.wm.RootWindowContainer

  • attachApplication

com.android.server.wm.ActivityTaskSupervisor // LaunchActivityItem

  • realStartActivityLocked
    // While there are activities pausing we skipping starting any new activities until pauses are complete.
    • if (!mRootWindowContainer.allPausedActivitiesComplete())

com.android.server.wm.ClientLifecycleManager

  • scheduleTransactionAndLifecycleItems
  • scheduleTransaction

android.app.servertransaction.ClientTransaction

  • schedule

第三部分,目标应用进程

android.app.ActivityThread.ApplicationThread

  • scheduleTransaction

android.app.ClientTransactionHandler // ActivityThread的父类,此时,ActivityThread已经启动了

  • scheduleTransaction

android.app.ActivityThread.H

  • handleMessage // EXECUTE_TRANSACTION

android.app.servertransaction.TransactionExecutor

  • execute
  • executeLifecycleState
  • executeLifecycleItem

android.app.servertransaction.ActivityTransactionItem

  • execute(android.app.ClientTransactionHandler, android.app.servertransaction.PendingTransactionActions)

android.app.servertransaction.LaunchActivityItem //ActivityClientRecord

  • execute

android.app.ActivityThread

  • handleLaunchActivity // 这里已经触发了ON_CREATE

android.app.ActivityThread

  • performLaunchActivity

android.app.Instrumentation

  • newActivity(java.lang.ClassLoader, java.lang.String, android.content.Intent)

android.app.Activity

  • attach // 此时出现PhoneWindow 窗口

android.app.Instrumentation

  • callActivityOnCreate(android.app.Activity, android.os.Bundle)

android.app.Activity

  • performCreate(android.os.Bundle)
  • onCreate(android.os.Bundle)

时序图

在这里插入图片描述