Android AMS Activity 启动流程

上层应用通过调用startActivity,实际上最终是调用到了Framework中的ActivityManagerService,在ActivityManagerService中,根据Intent中所携带的信息,来启动Activity,通过调试系统Settings应用启动流程,来分析AMS是怎么启动Activity的.

冷启动Activity,并且内存中没有该Process

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
ASS#startActivitMayWait: activityInfo = ActivityInfo{4ee85f9 com.android.settings.Settings}
ASS#startActivityLocked: new ActivityRecord = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t-1}
ASS#startActivityLocked: -> startActivityUncheckedLocked: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t-1}
ASS#startActivityUncheckedLocked: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t-1}
ASK#moveToFront: reason = startingNewTask
ASK#moveToFront: task = null
ASK#createTaskRecord: -> addTask: task = TaskRecord{6c5e4d9 #24 A=com.android.settings U=0 sz=0} // C1
ASS#startActivityUncheckedLocked: -> ASK#startActivityLocked
ASK#startActivityLocked: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
ASK#startActivityLocked: rTask = TaskRecord{6c5e4d9 #24 A=com.android.settings U=0 sz=0}
ASK#startActivityLocked: -> ASS#resumeTopActivitiesLocked -> ASK#resumeTopActivityLocked
ASK#resumeTopActivityInnerLocked: prev = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
ASK#resumeTopActivityInnerLocked: next = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
ASS#startActivityUncheckedLocked: -> AMS#setFocusedActivityLocked: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
AMS#setFocusedActivityLocked: -> ASS#setFocusedStack
ASS#setFocusedStack: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}; reason = startedActivity setFocusedActivity
ASK#moveToFront: reason = startedActivity setFocusedActivity
ASK#moveToFront: task = TaskRecord{6c5e4d9 #24 A=com.android.settings U=0 sz=1}
AMS#activityPaused: -> ASK#activityPausedLocked
ASK#activityPausedLocked: r = ActivityRecord{c83a8b5 u0 com.android.launcher3/.Launcher t3}
ASK#completePauseLocked: resumeNext = true
ASK#completePauseLocked: ASS#resumeTopActivitiesLocked -> ASK#resumeTopActivityLocked
ASK#resumeTopActivityInnerLocked: prev = ActivityRecord{c83a8b5 u0 com.android.launcher3/.Launcher t3}
ASK#resumeTopActivityInnerLocked: next = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
ASK#resumeTopActivityInnerLocked: -> ASS#startSpecificActivityLocked: next = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
ASS#startSpecificActivityLocked: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
ASS#startSpecificActivityLocked: app = null
ASS#startSpecificActivityLocked: -> startProcessLocked
ASS#startSpecificActivityLocked: -> startProcessLocked
AMS#startProcessLocked: -> Process.start
AMS#startProcessLocked: startResult = android.os.Process$ProcessStartResult@71cdaf8
AMS#startProcessLocked: startResult = android.os.Process$ProcessStartResult@71cdaf8
AMS#attachApplication:
ASS#attachApplicationLocked: app = ProcessRecord{812a0c 7757:com.android.settings/1000}
ASS#attachApplicationLocked: -> realStartActivityLocked: app: ProcessRecord{812a0c 7757:com.android.settings/1000}
ASS#realStartActivityLocked: app = ProcessRecord{812a0c 7757:com.android.settings/1000}
ASS#realStartActivityLocked: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
ASS#realStartActivityLocked: -> app.thread#scheduleLaunchActivity

冷启动二级Activity页面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
ASS#startActivitMayWait: activityInfo = ActivityInfo{e00895e com.android.settings.SubSettings}
ASS#startActivityLocked: new ActivityRecord = ActivityRecord{f16f5b3 u0 com.android.settings/.SubSettings t-1}
ASS#startActivityLocked: -> startActivityUncheckedLocked: r = ActivityRecord{f16f5b3 u0 com.android.settings/.SubSettings t-1}
ASS#startActivityUncheckedLocked: r = ActivityRecord{f16f5b3 u0 com.android.settings/.SubSettings t-1}
ASK#moveToFront: reason = sourceStackToFront
ASK#moveToFront: task = TaskRecord{6c5e4d9 #24 A=com.android.settings U=0 sz=1}
ASS#startActivityUncheckedLocked: -> ASK#startActivityLocked
ASK#startActivityLocked: r = ActivityRecord{f16f5b3 u0 com.android.settings/.SubSettings t24}
ASK#startActivityLocked: rTask = TaskRecord{6c5e4d9 #24 A=com.android.settings U=0 sz=1}
ASK#startActivityLocked: -> ASS#resumeTopActivityLocked -> ASK#resumeTopActivityLocked
ASK#resumeTopActivityInnerLocked: prev = ActivityRecord{f16f5b3 u0 com.android.settings/.SubSettings t24}
ASK#resumeTopActivityInnerLocked: next = ActivityRecord{f16f5b3 u0 com.android.settings/.SubSettings t24}
ASS#startActivityUncheckedLocked: -> AMS#setFocusedActivityLocked: r = ActivityRecord{f16f5b3 u0 com.android.settings/.SubSettings t24}
AMS#setFocusedActivityLocked: -> ASS#setFocusedStack
ASS#setFocusedStack: r = ActivityRecord{f16f5b3 u0 com.android.settings/.SubSettings t24}; reason = startedActivity setFocusedActivity
ASK#moveToFront: reason = startedActivity setFocusedActivity
ASK#moveToFront: task = TaskRecord{6c5e4d9 #24 A=com.android.settings U=0 sz=2}
AMS#activityPaused: -> ASK#activityPausedLocked
ASK#activityPausedLocked: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
ASK#completePauseLocked: resumeNext = true
ASK#completePauseLocked: ASS#resumeTopActivitiesLocked -> ASK#resumeTopActivityLocked
ASK#resumeTopActivityInnerLocked: prev = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
ASK#resumeTopActivityInnerLocked: next = ActivityRecord{f16f5b3 u0 com.android.settings/.SubSettings t24}
ASK#resumeTopActivityInnerLocked: -> ASS#startSpecificActivityLocked: next = ActivityRecord{f16f5b3 u0 com.android.settings/.SubSettings t24}
ASS#startSpecificActivityLocked: r = ActivityRecord{f16f5b3 u0 com.android.settings/.SubSettings t24}
ASS#startSpecificActivityLocked: app = ProcessRecord{812a0c 7757:com.android.settings/1000}
ASS#startSpecificActivityLocked: app not null -> realStartActivityLocked
ASS#realStartActivityLocked: app = ProcessRecord{812a0c 7757:com.android.settings/1000}
ASS#realStartActivityLocked: r = ActivityRecord{f16f5b3 u0 com.android.settings/.SubSettings t24}
ASS#realStartActivityLocked: -> app.thread#scheduleLaunchActivity

退出二级页面,再次点击进入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
ASS#startActivitMayWait: activityInfo = ActivityInfo{e00895e com.android.settings.SubSettings}
ASS#startActivityLocked: new ActivityRecord = ActivityRecord{fff9faf u0 com.android.settings/.SubSettings t-1}
ASS#startActivityLocked: -> startActivityUncheckedLocked: r = ActivityRecord{fff9faf u0 com.android.settings/.SubSettings t-1}
ASS#startActivityUncheckedLocked: r = ActivityRecord{fff9faf u0 com.android.settings/.SubSettings t-1}
ASK#moveToFront: reason = sourceStackToFront
ASK#moveToFront: task = TaskRecord{6c5e4d9 #24 A=com.android.settings U=0 sz=1}
ASS#startActivityUncheckedLocked: -> ASK#startActivityLocked
ASK#startActivityLocked: r = ActivityRecord{fff9faf u0 com.android.settings/.SubSettings t24}
ASK#startActivityLocked: rTask = TaskRecord{6c5e4d9 #24 A=com.android.settings U=0 sz=1}
ASK#startActivityLocked: -> ASS#resumeTopActivityLocked -> ASK#resumeTopActivityLocked
ASK#resumeTopActivityInnerLocked: prev = ActivityRecord{fff9faf u0 com.android.settings/.SubSettings t24}
ASK#resumeTopActivityInnerLocked: next = ActivityRecord{fff9faf u0 com.android.settings/.SubSettings t24}
ASS#startActivityUncheckedLocked: -> AMS#setFocusedActivityLocked: r = ActivityRecord{fff9faf u0 com.android.settings/.SubSettings t24}
AMS#setFocusedActivityLocked: -> ASS#setFocusedStack
ASS#setFocusedStack: r = ActivityRecord{fff9faf u0 com.android.settings/.SubSettings t24}; reason = startedActivity setFocusedActivity
ASK#moveToFront: reason = startedActivity setFocusedActivity
ASK#moveToFront: task = TaskRecord{6c5e4d9 #24 A=com.android.settings U=0 sz=2}
AMS#activityPaused: -> ASK#activityPausedLocked
ASK#activityPausedLocked: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
ASK#completePauseLocked: resumeNext = true
ASK#completePauseLocked: ASS#resumeTopActivitiesLocked -> ASK#resumeTopActivityLocked
ASK#resumeTopActivityInnerLocked: prev = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
ASK#resumeTopActivityInnerLocked: next = ActivityRecord{fff9faf u0 com.android.settings/.SubSettings t24}
ASK#resumeTopActivityInnerLocked: -> ASS#startSpecificActivityLocked: next = ActivityRecord{fff9faf u0 com.android.settings/.SubSettings t24}
ASS#startSpecificActivityLocked: r = ActivityRecord{fff9faf u0 com.android.settings/.SubSettings t24}
ASS#startSpecificActivityLocked: app = ProcessRecord{812a0c 7757:com.android.settings/1000}
ASS#startSpecificActivityLocked: app not null -> realStartActivityLocked
ASS#realStartActivityLocked: app = ProcessRecord{812a0c 7757:com.android.settings/1000}
ASS#realStartActivityLocked: r = ActivityRecord{fff9faf u0 com.android.settings/.SubSettings t24}
ASS#realStartActivityLocked: -> app.thread#scheduleLaunchActivity

热启动Activity,系统中有Process

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
ASS#startActivitMayWait: activityInfo = ActivityInfo{4ee85f9 com.android.settings.Settings}
ASS#startActivityLocked: new ActivityRecord = ActivityRecord{9b016c u0 com.android.settings/.Settings t-1}
ASS#startActivityLocked: -> startActivityUncheckedLocked: r = ActivityRecord{9b016c u0 com.android.settings/.Settings t-1}
ASS#startActivityUncheckedLocked: r = ActivityRecord{9b016c u0 com.android.settings/.Settings t-1}
ASK#moveToFront: reason = startingNewTask
ASK#moveToFront: task = null
ASK#createTaskRecord: -> addTask: task = TaskRecord{70e01e9 #25 A=com.android.settings U=0 sz=0}
ASS#startActivityUncheckedLocked: -> ASK#startActivityLocked
ASK#startActivityLocked: r = ActivityRecord{9b016c u0 com.android.settings/.Settings t25}
ASK#startActivityLocked: rTask = TaskRecord{70e01e9 #25 A=com.android.settings U=0 sz=0}
ASK#startActivityLocked: -> ASS#resumeTopActivityLocked -> ASK#resumeTopActivityLocked
ASK#resumeTopActivityInnerLocked: prev = ActivityRecord{9b016c u0 com.android.settings/.Settings t25}
ASK#resumeTopActivityInnerLocked: next = ActivityRecord{9b016c u0 com.android.settings/.Settings t25}
ASS#startActivityUncheckedLocked: -> AMS#setFocusedActivityLocked: r = ActivityRecord{9b016c u0 com.android.settings/.Settings t25}
AMS#setFocusedActivityLocked: -> ASS#setFocusedStack
ASS#setFocusedStack: r = ActivityRecord{9b016c u0 com.android.settings/.Settings t25}; reason = startedActivity setFocusedActivity
ASK#moveToFront: reason = startedActivity setFocusedActivity
ASK#moveToFront: task = TaskRecord{70e01e9 #25 A=com.android.settings U=0 sz=1}
AMS#activityPaused: -> ASK#activityPausedLocked
ASK#activityPausedLocked: r = ActivityRecord{c83a8b5 u0 com.android.launcher3/.Launcher t3}
ASK#completePauseLocked: resumeNext = true
ASK#completePauseLocked: ASS#resumeTopActivitiesLocked -> ASK#resumeTopActivityLocked
ASK#resumeTopActivityInnerLocked: prev = ActivityRecord{c83a8b5 u0 com.android.launcher3/.Launcher t3}
ASK#resumeTopActivityInnerLocked: next = ActivityRecord{9b016c u0 com.android.settings/.Settings t25}
ASK#resumeTopActivityInnerLocked: -> ASS#startSpecificActivityLocked: next = ActivityRecord{9b016c u0 com.android.settings/.Settings t25}
ASS#startSpecificActivityLocked: r = ActivityRecord{9b016c u0 com.android.settings/.Settings t25}
ASS#startSpecificActivityLocked: app = ProcessRecord{812a0c 7757:com.android.settings/1000}
ASS#startSpecificActivityLocked: app not null -> realStartActivityLocked
ASS#realStartActivityLocked: app = ProcessRecord{812a0c 7757:com.android.settings/1000}
ASS#realStartActivityLocked: r = ActivityRecord{9b016c u0 com.android.settings/.Settings t25}
ASS#realStartActivityLocked: -> app.thread#scheduleLaunchActivity

相比较而言,在系统没有该Process时,startSpecificActivityLocked会先调用AMS#startProcessLocked,而不直接调用ASS#realStartActivityLocked,当对应的Process创建好后,通过Binder传递消息,调用AMS#attachApplication,而该方法最后会调用到ASS#realStartActivityLocked,此时再启动Activity

ActivityManagerService

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public final int startActivityAsUser(IApplicationThread caller, String callingPackage,
Intent intent, ...) {
enforceNotIsolatedCaller("startActivity");
userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
false, ALLOW_FULL_ONLY, "startActivity", null);
// TODO: Switch to user app stacks here.
// TODO: -> ASS#startActivityMayWait
return mStackSupervisor.startActivityMayWait(caller, -1, callingPackage, intent, ...);
}
final void setFocusedActivityLocked(ActivityRecord r, String reason) {
if (r != null && mFocusedActivity != r) {
// TODO: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
// TODO: -> ASS#setFocusedStack
if (mStackSupervisor.setFocusedStack(r, reason + " setFocusedActivity")) {
mWindowManager.setFocusedApp(r.appToken, true);
}
applyUpdateLockStateLocked(r);
}
}
public final void activityPaused(IBinder token) {
final long origId = Binder.clearCallingIdentity();
synchronized(this) {
ActivityStack stack = ActivityRecord.getStackLocked(token);
if (stack != null) {
// ASK#activityPausedLocked
stack.activityPausedLocked(token, false);
}
}
Binder.restoreCallingIdentity(origId);
}
private final void startProcessLocked(ProcessRecord app, String hostingType,
String hostingNameStr, String abiOverride, String entryPoint, String[] entryPointArgs) {
// entryPoint = "android.app.ActivityThread";
Process.ProcessStartResult startResult = Process.start(entryPoint,
app.processName, uid, uid, gids, debugFlags, mountExternal,
app.info.targetSdkVersion, app.info.seinfo, requiredAbi, instructionSet,
app.info.dataDir, entryPointArgs);
}

ActivityStackSupervisor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
final int startActivityMayWait(IApplicationThread caller, int callingUid,
String callingPackage, Intent intent,
// Collect information about the target of the Intent.
ActivityInfo aInfo = resolveActivity(intent, resolvedType, startFlags, profilerInfo, userId);
// TODO: aInfo = ActivityInfo{4ee85f9 com.android.settings.Settings}
// TODO: -> startActivityLocked
int res = startActivityLocked(caller, intent, resolvedType, aInfo, ...);
}
final int startActivityLocked(IApplicationThread caller,
Intent intent, String resolvedType, ActivityInfo aInfo, ...) {
// TODO: 创建ActivityRecord
ActivityRecord r = new ActivityRecord(mService, callerApp, callingUid, callingPackage,
intent, ...);
// TODO: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t-1}
doPendingActivityLaunchesLocked(false);
// TODO: -> startActivityUncheckedLocked
err = startActivityUncheckedLocked(r, sourceRecord, voiceSession, voiceInteractor,
startFlags, true, options, inTask);
return err;
}
final int startActivityUncheckedLocked(final ActivityRecord r, ActivityRecord sourceRecord,
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, int startFlags,
boolean doResume, Bundle options, TaskRecord inTask) {
final Intent intent = r.intent;
// TODO: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t-1}
if (r.resultTo == null && inTask == null && !addingToTask
&& (launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
newTask = true;
targetStack = computeStackFocus(r, newTask);
// TODO: ASK#moveToFront: reason = startingNewTask
targetStack.moveToFront("startingNewTask");
// TODO: {C1}
if (reuseTask == null) {
// TODO: ASK#createTaskRecord
r.setTask(targetStack.createTaskRecord(getNextTaskId(),
newTaskInfo != null ? newTaskInfo : r.info,
newTaskIntent != null ? newTaskIntent : intent,
voiceSession, voiceInteractor, !launchTaskBehind /* toTop */),
taskToAffiliate);
}
}
// TODO: ASK#startActivityLocked
targetStack.startActivityLocked(r, newTask, doResume, keepCurTransition, options);
if (!launchTaskBehind) {
// Don't set focus on an activity that's going to the back.
// TODO: AMS#setFocusedActivityLocked
mService.setFocusedActivityLocked(r, "startedActivity");
}
return ActivityManager.START_SUCCESS;
}
boolean resumeTopActivitiesLocked(ActivityStack targetStack, ActivityRecord target,
Bundle targetOptions) {
if (targetStack == null) {
targetStack = mFocusedStack;
}
// Do targetStack first.
boolean result = false;
if (isFrontStack(targetStack)) {
// TODO: ASK#resumeTopActivityLocked
result = targetStack.resumeTopActivityLocked(target, targetOptions);
}
return result;
}
boolean setFocusedStack(ActivityRecord r, String reason) {
final TaskRecord task = r.task;
if (task == null || task.stack == null) {
return false;
}
// TODO: ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
// TODO: reason = startedActivity setFocusedActivity
task.stack.moveToFront(reason);
// TODO: ASK#moveToFront
return true;
}
void startSpecificActivityLocked(ActivityRecord r, boolean andResume, boolean checkConfig) {
// Is this activity's application already running?
ProcessRecord app = mService.getProcessRecordLocked(r.processName,
r.info.applicationInfo.uid, true);
r.task.stack.setLaunchTime(r);
//
// TODO: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
// TODO: app = null
if (app != null && app.thread != null) {
try {
// TODO: -> realStartActivityLocked
realStartActivityLocked(r, app, andResume, checkConfig);
return;
} catch (RemoteException e) {
Slog.w(TAG, "Exception when starting activity "
+ r.intent.getComponent().flattenToShortString(), e);
}
}
// TODO: AMS#startProcessLocked
mService.startProcessLocked(r.processName, r.info.applicationInfo, true, 0,
"activity", r.intent.getComponent(), false, false, true);
}
final boolean realStartActivityLocked(ActivityRecord r,
ProcessRecord app, boolean andResume, boolean checkConfig)
throws RemoteException {
final ActivityStack stack = task.stack;
try {
if (r.isHomeActivity() && r.isNotResolverActivity()) {
// Home process is the root process of the task.
mService.mHomeProcess = task.mActivities.get(0).app;
}
app.forceProcessStateUpTo(mService.mTopProcessState);
app.thread.scheduleLaunchActivity(new Intent(r.intent), r.appToken,
System.identityHashCode(r), r.info, new Configuration(mService.mConfiguration),
new Configuration(stack.mOverrideConfig), r.compat, r.launchedFromPackage,
task.voiceInteractor, app.repProcState, r.icicle, r.persistentState, results,
newIntents, !andResume, mService.isNextTransitionForward(), profilerInfo);
} catch (RemoteException e) {
if (r.launchFailed) {
stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null,
"2nd-crash", false);
return false;
}
app.activities.remove(r);
throw e;
}
return true;
}
boolean attachApplicationLocked(ProcessRecord app) throws RemoteException {
final String processName = app.processName;
boolean didSomething = false;
for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
final ActivityStack stack = stacks.get(stackNdx);
if (!isFrontStack(stack)) {
continue;
}
ActivityRecord hr = stack.topRunningActivityLocked(null);
if (hr != null) {
if (hr.app == null && app.uid == hr.info.applicationInfo.uid
&& processName.equals(hr.processName)) {
try {
// TODO: -> realStartActivityLocked
if (realStartActivityLocked(hr, app, true, true)) {
// TODO: app = ProcessRecord{812a0c 7757:com.android.settings/1000}
didSomething = true;
}
} catch (RemoteException e) {
}
}
}
}
}
return didSomething;
}

ActivityStack

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
final void moveToFront(String reason) {
// TODO: reason = startingNewTask
if (isAttached()) {
final boolean homeStack = isHomeStack()
|| (mActivityContainer.mParentActivity != null
&& mActivityContainer.mParentActivity.isHomeActivity());
ActivityStack lastFocusStack = null;
if (!homeStack) {
// Need to move this stack to the front before calling
// {@link ActivityStackSupervisor#moveHomeStack} below.
lastFocusStack = mStacks.get(mStacks.size() - 1);
mStacks.remove(this);
mStacks.add(this);
}
// TODO(multi-display): Focus stack currently adjusted in call to move home stack.
// Needs to also work if focus is moving to the non-home display.
if (isOnHomeDisplay()) {
mStackSupervisor.moveHomeStack(homeStack, reason, lastFocusStack);
}
final TaskRecord task = topTask();
// TODO: task = null {C1}
if (task != null) {
mWindowManager.moveTaskToTop(task.taskId);
}
}
}
TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent,
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
boolean toTop) {
TaskRecord task = new TaskRecord(mService, taskId, info, intent, voiceSession,
voiceInteractor);
addTask(task, toTop, false);
// TODO: task = TaskRecord{6c5e4d9 #24 A=com.android.settings U=0 sz=0}
return task;
}
final void startActivityLocked(ActivityRecord r, boolean newTask,
boolean doResume, boolean keepCurTransition, Bundle options) {
TaskRecord rTask = r.task;
// TODO: r = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
final int taskId = rTask.taskId;
// TODO: rTask = TaskRecord{6c5e4d9 #24 A=com.android.settings U=0 sz=0}
if (doResume) {
// TODO: ASS#resumeTopActivitiesLocked
mStackSupervisor.resumeTopActivitiesLocked(this, r, options);
}
}
final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) {
if (mStackSupervisor.inResumeTopActivity) {
// Don't even start recursing.
return false;
}
boolean result = false;
try {
// TODO: -> resumeTopActivityInnerLocked
result = resumeTopActivityInnerLocked(prev, options);
} finally {
mStackSupervisor.inResumeTopActivity = false;
}
return result;
}
private boolean resumeTopActivityInnerLocked(ActivityRecord prev, Bundle options) {
// TODO: prev = ActivityRecord{c83a8b5 u0 com.android.launcher3/.Launcher t3}
// Find the first activity that is not finishing.
final ActivityRecord next = topRunningActivityLocked(null);
// TODO: next = ActivityRecord{9b4fdee u0 com.android.settings/.Settings t24}
// Remember how we'll process this pause/resume situation, and ensure
// that the state is reset however we wind up proceeding.
final boolean userLeaving = mStackSupervisor.mUserLeaving;
mStackSupervisor.mUserLeaving = false;
final TaskRecord prevTask = prev != null ? prev.task : null;
}
final void activityPausedLocked(IBinder token, boolean timeout) {
final ActivityRecord r = isInStackLocked(token);
if (r != null) {
mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
if (mPausingActivity == r) {
// TODO: -> completePauseLocked
completePauseLocked(true);
// TODO: r = ActivityRecord{c83a8b5 u0 com.android.launcher3/.Launcher t3}
}
}
}
private void completePauseLocked(boolean resumeNext) {
ActivityRecord prev = mPausingActivity;
if (resumeNext) {
final ActivityStack topStack = mStackSupervisor.getFocusedStack();
if (!mService.isSleepingOrShuttingDown()) {
// TODO: ASS#resumeTopActivitiesLocked
mStackSupervisor.resumeTopActivitiesLocked(topStack, prev, null);
}
}
}

AMS_sequence