问题现象:
由于设备有两个Display设备,分为主屏和副屏,正常情况下startActivity如果不指定displayId的话,都会默认显示在主屏上,但是在某些情况下launcher启动的应用Activity会显示到副屏上面去。
根据现象来分析,初步判断问题原因是startActivity的流程出现异常导致的,那么就需要从startActivity流程开始查找原因。
先看framework\base\services\core\java\com\android\server\am\ActivityStarter.java中的:
```
int startActivityLocked(IApplicationThread caller, Intent intent, Intent ephemeralIntent,
...) {
...
mLastStartActivityResult = startActivity(caller, intent, ephemeralIntent, resolvedType,
aInfo, rInfo, voiceSession, voiceInteractor, resultTo, resultWho, requestCode,
callingPid, callingUid, callingPackage, realCallingPid, realCallingUid, startFlags,
options, ignoreTargetSecurity, componentSpecified, mLastStartActivityRecord,
inTask);
...
}
```
一步一步往下查之后看到startActivityUnchecked函数中有对task和stack的变更与displayId相关的操作,重点看这个地方:
// Note: This method should only be called from {@link startActivity}.
private int startActivityUnchecked(final ActivityRecord r, ActivityRecord sourceRecord,
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
int startFlags, boolean doResume, ActivityOptions options, TaskReco