1. Framework 涉及流程
三块主要文件如下:
(1)TaskFragment 调用 ATMS
frameworks/base/services/core/java/com/android/server/wm/TaskFragment.java
resumeTopActivity-> ATMS.startProcessAsync
接着 ActivityTaskSupervisor 也会调用 ATMS
frameworks/base/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java
startSpecificActivity -> ATMS.startProcessAsync
(2) ActivityTaskManagerService 调用 AMS
frameworks/base/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
startProcessAsync 调用 ActivityManagerInternal::startProcess? --> 对的
(3) AMS 调用 Zygote (ProcessList/Process 可以看做是服务于 AMS的类)
frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
ActivityManagerService.LocalService.startProcess -> ActivityManagerService.startProcessLocked -> ProcessList.startProcessLocked, handleProcessStart, startProcess
-> Process.start -> Zygote
2. ATMS.startProcessAsync 的调用栈
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: startProcessAsync
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.ActivityTaskManagerService.startProcessAsync(ActivityTaskManagerService.java:6064)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.ActivityTaskManagerService.startProcessAsync(ActivityTaskManagerService.java:6055)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.TaskFragment.resumeTopActivity(TaskFragment.java:1464)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.TaskFragment.resumeTopActivity(TaskFragment.java:1307)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.Task.resumeTopActivityInnerLocked(Task.java:6449)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.Task.resumeTopActivityUncheckedLocked(Task.java:6350)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.RootWindowContainer.resumeFocusedTasksTopActivities(RootWindowContainer.java:2716)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.ActivityStarter.startActivityInner(ActivityStarter.java:3012)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.ActivityStarter.startActivityUnchecked(ActivityStarter.java:2470)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.ActivityStarter.executeRequest(ActivityStarter.java:1808)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:1026)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.ActivityTaskManagerService.startActivityAsUser(ActivityTaskManagerService.java:1942)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.ActivityTaskManagerService.startActivityAsUser(ActivityTaskManagerService.java:1815)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.ActivityTaskManagerService.startActivity(ActivityTaskManagerService.java:1766)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at android.app.IActivityTaskManager$Stub.onTransact(IActivityTaskManager.java:1244)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at com.android.server.wm.ActivityTaskManagerService.onTransact(ActivityTaskManagerService.java:6592)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at android.os.Binder.execTransactInternal(Binder.java:1316)
07-28 18:05:13.755 E 1880 4029 ActivityTaskManagerService: at android.os.Binder.execTransact(Binder.java:1280)
3. TaskFragment 发起启动 App 源码
frameworks/base/services/core/java/com/android/server/wm/TaskFragment.java
final boolean resumeTopActivity(ActivityRecord prev, ActivityOptions options,
boolean deferPause) {
if (pausing) {
ProtoLog.v(WM_DEBUG_STATES, "resumeTopActivity: Skip resume: need to"
+ " start pausing");
// At this point we want to put the upcoming activity's process
// at the top of the LRU list, since we know we will be needing it
// very soon and it would be a waste to let it get killed if it
// happens to be sitting towards the end.
if (next.attachedToProcess()) {
next.app.updateProcessInfo(false /* updateServiceConnectionActivities */,
true /* activityChange */, false /* updateOomAdj */,
false /* addPendingTopUid */);
} else if (!next.isProcessRunning()) {
// Since the start-process is asynchronous, if we already know the process of next
// activity isn't running, we can start the process earlier to save the time to wait
// for the current activity to be paused.
final boolean isTop = this == taskDisplayArea.getFocusedRootTask();
mAtmService.startProcessAsync(next, false /* knownToBeDead */, isTop,
isTop ? HostingRecord.HOSTING_TYPE_NEXT_TOP_ACTIVITY
: HostingRecord.HOSTING_TYPE_NEXT_ACTIVITY);
}
if (lastResumed != null) {
lastResumed.setWillCloseOrEnterPip(true);
}
return true;
}
...
}
注意到 mAtmService.startProcessAsync()
网友评论