Program: 197779
Project: 197779
Buggy source:
final int startActivityUncheckedLocked(ActivityRecord r,ActivityRecord sourceRecord,IVoiceInteractionSession voiceSession,IVoiceInteractor voiceInteractor,int startFlags,boolean doResume,Bundle options,TaskRecord inTask){
  final Intent intent=r.intent;
  final int callingUid=r.launchedFromUid;
  if (inTask != null && !inTask.inRecents) {
    Slog.w(TAG,"String_Node_Str" + inTask);
    inTask=null;
  }
  final boolean launchSingleTop=r.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP;
  final boolean launchSingleInstance=r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE;
  final boolean launchSingleTask=r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK;
  int launchFlags=intent.getFlags();
  if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0 && (launchSingleInstance || launchSingleTask)) {
    Slog.i(TAG,"String_Node_Str" + "String_Node_Str");
    launchFlags&=~(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
  }
 else {
switch (r.info.documentLaunchMode) {
case ActivityInfo.DOCUMENT_LAUNCH_NONE:
      break;
case ActivityInfo.DOCUMENT_LAUNCH_INTO_EXISTING:
    launchFlags|=Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
  break;
case ActivityInfo.DOCUMENT_LAUNCH_ALWAYS:
launchFlags|=Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
break;
case ActivityInfo.DOCUMENT_LAUNCH_NEVER:
launchFlags&=~Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
break;
}
}
final boolean launchTaskBehind=r.mLaunchTaskBehind && !launchSingleTask && !launchSingleInstance&& (launchFlags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0;
if (r.resultTo != null && (launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
Slog.w(TAG,"String_Node_Str");
r.resultTo.task.stack.sendActivityResultLocked(-1,r.resultTo,r.resultWho,r.requestCode,Activity.RESULT_CANCELED,null);
r.resultTo=null;
}
if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0 && r.resultTo == null) {
launchFlags|=Intent.FLAG_ACTIVITY_NEW_TASK;
}
if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
if (launchTaskBehind || r.info.documentLaunchMode == ActivityInfo.DOCUMENT_LAUNCH_ALWAYS) {
launchFlags|=Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
}
}
mUserLeaving=(launchFlags & Intent.FLAG_ACTIVITY_NO_USER_ACTION) == 0;
if (DEBUG_USER_LEAVING) Slog.v(TAG,"String_Node_Str" + mUserLeaving);
if (!doResume) {
r.delayedResume=true;
}
ActivityRecord notTop=(launchFlags & Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP) != 0 ? r : null;
if ((startFlags & ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
ActivityRecord checkedCaller=sourceRecord;
if (checkedCaller == null) {
checkedCaller=getFocusedStack().topRunningNonDelayedActivityLocked(notTop);
}
if (!checkedCaller.realActivity.equals(r.realActivity)) {
startFlags&=~ActivityManager.START_FLAG_ONLY_IF_NEEDED;
}
}
if (sourceRecord == null) {
if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) == 0 && inTask == null) {
Slog.w(TAG,"String_Node_Str" + "String_Node_Str" + intent);
launchFlags|=Intent.FLAG_ACTIVITY_NEW_TASK;
}
}
 else if (sourceRecord.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
launchFlags|=Intent.FLAG_ACTIVITY_NEW_TASK;
}
 else if (launchSingleInstance || launchSingleTask) {
launchFlags|=Intent.FLAG_ACTIVITY_NEW_TASK;
}
ActivityInfo newTaskInfo=null;
Intent newTaskIntent=null;
ActivityStack sourceStack;
if (sourceRecord != null) {
if (sourceRecord.finishing) {
if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
Slog.w(TAG,"String_Node_Str" + sourceRecord + "String_Node_Str"+ "String_Node_Str"+ intent);
launchFlags|=Intent.FLAG_ACTIVITY_NEW_TASK;
newTaskInfo=sourceRecord.info;
newTaskIntent=sourceRecord.task.intent;
}
sourceRecord=null;
sourceStack=null;
}
 else {
sourceStack=sourceRecord.task.stack;
}
}
 else {
sourceStack=null;
}
boolean addingToTask=false;
boolean movedHome=false;
TaskRecord reuseTask=null;
ActivityStack targetStack;
intent.setFlags(launchFlags);
if (sourceRecord == null && inTask != null && inTask.stack != null) {
final Intent baseIntent=inTask.getBaseIntent();
final ActivityRecord root=inTask.getRootActivity();
if (baseIntent == null) {
ActivityOptions.abort(options);
throw new IllegalArgumentException("String_Node_Str" + inTask);
}
if (launchSingleInstance || launchSingleTask) {
if (!baseIntent.getComponent().equals(r.intent.getComponent())) {
ActivityOptions.abort(options);
throw new IllegalArgumentException("String_Node_Str" + r + "String_Node_Str"+ inTask);
}
if (root != null) {
ActivityOptions.abort(options);
throw new IllegalArgumentException("String_Node_Str" + inTask + "String_Node_Str"+ root+ "String_Node_Str");
}
}
if (root == null) {
final int flagsOfInterest=Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT| Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
launchFlags=(launchFlags & ~flagsOfInterest) | (baseIntent.getFlags() & flagsOfInterest);
intent.setFlags(launchFlags);
inTask.setIntent(r);
}
 else if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
ActivityOptions.abort(options);
throw new IllegalStateException("String_Node_Str" + inTask + "String_Node_Str");
}
reuseTask=inTask;
addingToTask=true;
}
 else {
inTask=null;
}
if (((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0 && (launchFlags & Intent.FLAG_ACTIVITY_MULTIPLE_TASK) == 0) || launchSingleInstance || launchSingleTask) {
if (inTask == null && r.resultTo == null) {
ActivityRecord intentActivity=!launchSingleInstance ? findTaskLocked(r) : findActivityLocked(intent,r.info);
if (intentActivity != null) {
if (isLockTaskModeViolation(intentActivity.task)) {
showLockTaskToast();
Slog.e(TAG,"String_Node_Str");
return ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
}
if (r.task == null) {
r.task=intentActivity.task;
}
targetStack=intentActivity.task.stack;
targetStack.mLastPausedActivity=null;
if (DEBUG_TASKS) Slog.d(TAG,"String_Node_Str" + targetStack + "String_Node_Str"+ intentActivity);
targetStack.moveToFront();
if (intentActivity.task.intent == null) {
intentActivity.task.setIntent(r);
}
final ActivityStack lastStack=getLastStack();
ActivityRecord curTop=lastStack == null ? null : lastStack.topRunningNonDelayedActivityLocked(notTop);
if (curTop != null && (curTop.task != intentActivity.task || curTop.task != lastStack.topTask())) {
r.intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
if (sourceRecord == null || (sourceStack.topActivity() != null && sourceStack.topActivity().task == sourceRecord.task)) {
if (launchTaskBehind && sourceRecord != null) {
intentActivity.setTaskToAffiliateWith(sourceRecord.task);
}
movedHome=true;
targetStack.moveTaskToFrontLocked(intentActivity.task,r,options);
if ((launchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) {
intentActivity.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE);
}
options=null;
}
}
if ((launchFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
intentActivity=targetStack.resetTaskIfNeededLocked(intentActivity,r);
}
if ((startFlags & ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
if (doResume) {
resumeTopActivitiesLocked(targetStack,null,options);
}
 else {
ActivityOptions.abort(options);
}
return ActivityManager.START_RETURN_INTENT_TO_CALLER;
}
if ((launchFlags & (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)) == (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)) {
reuseTask=intentActivity.task;
reuseTask.performClearTaskLocked();
reuseTask.setIntent(r);
}
 else if ((launchFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0 || launchSingleInstance || launchSingleTask) {
ActivityRecord top=intentActivity.task.performClearTaskLocked(r,launchFlags);
if (top != null) {
if (top.frontOfTask) {
top.task.setIntent(r);
}
ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,r,top.task);
top.deliverNewIntentLocked(callingUid,r.intent);
}
 else {
addingToTask=true;
sourceRecord=intentActivity;
}
}
 else if (r.realActivity.equals(intentActivity.task.realActivity)) {
if (((launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0 || launchSingleTop) && intentActivity.realActivity.equals(r.realActivity)) {
ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,r,intentActivity.task);
if (intentActivity.frontOfTask) {
intentActivity.task.setIntent(r);
}
intentActivity.deliverNewIntentLocked(callingUid,r.intent);
}
 else if (!r.intent.filterEquals(intentActivity.task.intent)) {
addingToTask=true;
sourceRecord=intentActivity;
}
}
 else if ((launchFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) == 0) {
addingToTask=true;
sourceRecord=intentActivity;
}
 else if (!intentActivity.task.rootWasReset) {
intentActivity.task.setIntent(r);
}
if (!addingToTask && reuseTask == null) {
if (doResume) {
targetStack.resumeTopActivityLocked(null,options);
}
 else {
ActivityOptions.abort(options);
}
return ActivityManager.START_TASK_TO_FRONT;
}
}
}
}
if (r.packageName != null) {
ActivityStack topStack=getFocusedStack();
ActivityRecord top=topStack.topRunningNonDelayedActivityLocked(notTop);
if (top != null && r.resultTo == null) {
if (top.realActivity.equals(r.realActivity) && top.userId == r.userId) {
if (top.app != null && top.app.thread != null) {
if ((launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0 || launchSingleTop || launchSingleTask) {
ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,top,top.task);
topStack.mLastPausedActivity=null;
if (doResume) {
resumeTopActivitiesLocked();
}
ActivityOptions.abort(options);
if ((startFlags & ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
return ActivityManager.START_RETURN_INTENT_TO_CALLER;
}
top.deliverNewIntentLocked(callingUid,r.intent);
return ActivityManager.START_DELIVERED_TO_TOP;
}
}
}
}
}
 else {
if (r.resultTo != null) {
r.resultTo.task.stack.sendActivityResultLocked(-1,r.resultTo,r.resultWho,r.requestCode,Activity.RESULT_CANCELED,null);
}
ActivityOptions.abort(options);
return ActivityManager.START_CLASS_NOT_FOUND;
}
boolean newTask=false;
boolean keepCurTransition=false;
TaskRecord taskToAffiliate=launchTaskBehind && sourceRecord != null ? sourceRecord.task : null;
if (r.resultTo == null && !addingToTask && (launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
if (isLockTaskModeViolation(reuseTask)) {
Slog.e(TAG,"String_Node_Str" + r);
return ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
}
newTask=true;
targetStack=adjustStackFocus(r,newTask);
if (!launchTaskBehind) {
targetStack.moveToFront();
}
if (reuseTask == null) {
r.setTask(targetStack.createTaskRecord(getNextTaskId(),newTaskInfo != null ? newTaskInfo : r.info,newTaskIntent != null ? newTaskIntent : intent,voiceSession,voiceInteractor,!launchTaskBehind),taskToAffiliate);
if (DEBUG_TASKS) Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task);
}
 else {
r.setTask(reuseTask,taskToAffiliate);
}
if (!movedHome) {
if ((launchFlags & (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME)) == (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME)) {
r.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE);
}
}
}
 else if (sourceRecord != null) {
final TaskRecord sourceTask=sourceRecord.task;
if (isLockTaskModeViolation(sourceTask)) {
Slog.e(TAG,"String_Node_Str" + r);
return ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
}
targetStack=sourceTask.stack;
targetStack.moveToFront();
mWindowManager.moveTaskToTop(targetStack.topTask().taskId);
if (!addingToTask && (launchFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) {
ActivityRecord top=sourceTask.performClearTaskLocked(r,launchFlags);
keepCurTransition=true;
if (top != null) {
ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,r,top.task);
top.deliverNewIntentLocked(callingUid,r.intent);
targetStack.mLastPausedActivity=null;
if (doResume) {
targetStack.resumeTopActivityLocked(null);
}
ActivityOptions.abort(options);
return ActivityManager.START_DELIVERED_TO_TOP;
}
}
 else if (!addingToTask && (launchFlags & Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) {
final ActivityRecord top=sourceTask.findActivityInHistoryLocked(r);
if (top != null) {
final TaskRecord task=top.task;
task.moveActivityToFrontLocked(top);
ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,r,task);
top.updateOptionsLocked(options);
top.deliverNewIntentLocked(callingUid,r.intent);
targetStack.mLastPausedActivity=null;
if (doResume) {
targetStack.resumeTopActivityLocked(null);
}
return ActivityManager.START_DELIVERED_TO_TOP;
}
}
r.setTask(sourceTask,null);
if (DEBUG_TASKS) Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task+ "String_Node_Str"+ sourceRecord);
}
 else if (inTask != null) {
if (isLockTaskModeViolation(inTask)) {
Slog.e(TAG,"String_Node_Str" + r);
return ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
}
targetStack=inTask.stack;
targetStack.moveTaskToFrontLocked(inTask,r,options);
mWindowManager.moveTaskToTop(inTask.taskId);
ActivityRecord top=inTask.getTopActivity();
if (top != null && top.realActivity.equals(r.realActivity) && top.userId == r.userId) {
if ((launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0 || launchSingleTop || launchSingleTask) {
ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,top,top.task);
if ((startFlags & ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
return ActivityManager.START_RETURN_INTENT_TO_CALLER;
}
top.deliverNewIntentLocked(callingUid,r.intent);
return ActivityManager.START_DELIVERED_TO_TOP;
}
}
r.setTask(inTask,null);
if (DEBUG_TASKS) Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task);
}
 else {
targetStack=adjustStackFocus(r,newTask);
targetStack.moveToFront();
ActivityRecord prev=targetStack.topActivity();
r.setTask(prev != null ? prev.task : targetStack.createTaskRecord(getNextTaskId(),r.info,intent,null,null,true),null);
mWindowManager.moveTaskToTop(r.task.taskId);
if (DEBUG_TASKS) Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task);
}
mService.grantUriPermissionFromIntentLocked(callingUid,r.packageName,intent,r.getUriPermissionsLocked(),r.userId);
if (sourceRecord != null && sourceRecord.isRecentsActivity()) {
r.task.setTaskToReturnTo(RECENTS_ACTIVITY_TYPE);
}
if (newTask) {
EventLog.writeEvent(EventLogTags.AM_CREATE_TASK,r.userId,r.task.taskId);
}
ActivityStack.logStartActivity(EventLogTags.AM_CREATE_ACTIVITY,r,r.task);
targetStack.mLastPausedActivity=null;
targetStack.startActivityLocked(r,newTask,doResume,keepCurTransition,options);
if (!launchTaskBehind) {
mService.setFocusedActivityLocked(r);
}
return ActivityManager.START_SUCCESS;
}

Fixed version (ground truth):
final int startActivityUncheckedLocked(ActivityRecord r,ActivityRecord sourceRecord,IVoiceInteractionSession voiceSession,IVoiceInteractor voiceInteractor,int startFlags,boolean doResume,Bundle options,TaskRecord inTask){
  final Intent intent=r.intent;
  final int callingUid=r.launchedFromUid;
  if (inTask != null && !inTask.inRecents) {
    Slog.w(TAG,"String_Node_Str" + inTask);
    inTask=null;
  }
  final boolean launchSingleTop=r.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP;
  final boolean launchSingleInstance=r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE;
  final boolean launchSingleTask=r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK;
  int launchFlags=intent.getFlags();
  if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0 && (launchSingleInstance || launchSingleTask)) {
    Slog.i(TAG,"String_Node_Str" + "String_Node_Str");
    launchFlags&=~(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
  }
 else {
switch (r.info.documentLaunchMode) {
case ActivityInfo.DOCUMENT_LAUNCH_NONE:
      break;
case ActivityInfo.DOCUMENT_LAUNCH_INTO_EXISTING:
    launchFlags|=Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
  break;
case ActivityInfo.DOCUMENT_LAUNCH_ALWAYS:
launchFlags|=Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
break;
case ActivityInfo.DOCUMENT_LAUNCH_NEVER:
launchFlags&=~Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
break;
}
}
final boolean launchTaskBehind=r.mLaunchTaskBehind && !launchSingleTask && !launchSingleInstance&& (launchFlags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0;
if (r.resultTo != null && (launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
Slog.w(TAG,"String_Node_Str");
r.resultTo.task.stack.sendActivityResultLocked(-1,r.resultTo,r.resultWho,r.requestCode,Activity.RESULT_CANCELED,null);
r.resultTo=null;
}
if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0 && r.resultTo == null) {
launchFlags|=Intent.FLAG_ACTIVITY_NEW_TASK;
}
if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
if (launchTaskBehind || r.info.documentLaunchMode == ActivityInfo.DOCUMENT_LAUNCH_ALWAYS) {
launchFlags|=Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
}
}
mUserLeaving=(launchFlags & Intent.FLAG_ACTIVITY_NO_USER_ACTION) == 0;
if (DEBUG_USER_LEAVING) Slog.v(TAG,"String_Node_Str" + mUserLeaving);
if (!doResume) {
r.delayedResume=true;
}
ActivityRecord notTop=(launchFlags & Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP) != 0 ? r : null;
if ((startFlags & ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
ActivityRecord checkedCaller=sourceRecord;
if (checkedCaller == null) {
checkedCaller=getFocusedStack().topRunningNonDelayedActivityLocked(notTop);
}
if (!checkedCaller.realActivity.equals(r.realActivity)) {
startFlags&=~ActivityManager.START_FLAG_ONLY_IF_NEEDED;
}
}
if (sourceRecord == null) {
if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) == 0 && inTask == null) {
Slog.w(TAG,"String_Node_Str" + "String_Node_Str" + intent);
launchFlags|=Intent.FLAG_ACTIVITY_NEW_TASK;
}
}
 else if (sourceRecord.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
launchFlags|=Intent.FLAG_ACTIVITY_NEW_TASK;
}
 else if (launchSingleInstance || launchSingleTask) {
launchFlags|=Intent.FLAG_ACTIVITY_NEW_TASK;
}
ActivityInfo newTaskInfo=null;
Intent newTaskIntent=null;
ActivityStack sourceStack;
if (sourceRecord != null) {
if (sourceRecord.finishing) {
if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
Slog.w(TAG,"String_Node_Str" + sourceRecord + "String_Node_Str"+ "String_Node_Str"+ intent);
launchFlags|=Intent.FLAG_ACTIVITY_NEW_TASK;
newTaskInfo=sourceRecord.info;
newTaskIntent=sourceRecord.task.intent;
}
sourceRecord=null;
sourceStack=null;
}
 else {
sourceStack=sourceRecord.task.stack;
}
}
 else {
sourceStack=null;
}
boolean addingToTask=false;
boolean movedHome=false;
TaskRecord reuseTask=null;
ActivityStack targetStack;
intent.setFlags(launchFlags);
if (sourceRecord == null && inTask != null && inTask.stack != null) {
final Intent baseIntent=inTask.getBaseIntent();
final ActivityRecord root=inTask.getRootActivity();
if (baseIntent == null) {
ActivityOptions.abort(options);
throw new IllegalArgumentException("String_Node_Str" + inTask);
}
if (launchSingleInstance || launchSingleTask) {
if (!baseIntent.getComponent().equals(r.intent.getComponent())) {
ActivityOptions.abort(options);
throw new IllegalArgumentException("String_Node_Str" + r + "String_Node_Str"+ inTask);
}
if (root != null) {
ActivityOptions.abort(options);
throw new IllegalArgumentException("String_Node_Str" + inTask + "String_Node_Str"+ root+ "String_Node_Str");
}
}
if (root == null) {
final int flagsOfInterest=Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT| Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
launchFlags=(launchFlags & ~flagsOfInterest) | (baseIntent.getFlags() & flagsOfInterest);
intent.setFlags(launchFlags);
inTask.setIntent(r);
addingToTask=true;
}
 else if ((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
addingToTask=false;
}
 else {
addingToTask=true;
}
reuseTask=inTask;
}
 else {
inTask=null;
}
if (((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0 && (launchFlags & Intent.FLAG_ACTIVITY_MULTIPLE_TASK) == 0) || launchSingleInstance || launchSingleTask) {
if (inTask == null && r.resultTo == null) {
ActivityRecord intentActivity=!launchSingleInstance ? findTaskLocked(r) : findActivityLocked(intent,r.info);
if (intentActivity != null) {
if (isLockTaskModeViolation(intentActivity.task)) {
showLockTaskToast();
Slog.e(TAG,"String_Node_Str");
return ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
}
if (r.task == null) {
r.task=intentActivity.task;
}
targetStack=intentActivity.task.stack;
targetStack.mLastPausedActivity=null;
if (DEBUG_TASKS) Slog.d(TAG,"String_Node_Str" + targetStack + "String_Node_Str"+ intentActivity);
targetStack.moveToFront();
if (intentActivity.task.intent == null) {
intentActivity.task.setIntent(r);
}
final ActivityStack lastStack=getLastStack();
ActivityRecord curTop=lastStack == null ? null : lastStack.topRunningNonDelayedActivityLocked(notTop);
if (curTop != null && (curTop.task != intentActivity.task || curTop.task != lastStack.topTask())) {
r.intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
if (sourceRecord == null || (sourceStack.topActivity() != null && sourceStack.topActivity().task == sourceRecord.task)) {
if (launchTaskBehind && sourceRecord != null) {
intentActivity.setTaskToAffiliateWith(sourceRecord.task);
}
movedHome=true;
targetStack.moveTaskToFrontLocked(intentActivity.task,r,options);
if ((launchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) {
intentActivity.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE);
}
options=null;
}
}
if ((launchFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
intentActivity=targetStack.resetTaskIfNeededLocked(intentActivity,r);
}
if ((startFlags & ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
if (doResume) {
resumeTopActivitiesLocked(targetStack,null,options);
}
 else {
ActivityOptions.abort(options);
}
return ActivityManager.START_RETURN_INTENT_TO_CALLER;
}
if ((launchFlags & (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)) == (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)) {
reuseTask=intentActivity.task;
reuseTask.performClearTaskLocked();
reuseTask.setIntent(r);
}
 else if ((launchFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0 || launchSingleInstance || launchSingleTask) {
ActivityRecord top=intentActivity.task.performClearTaskLocked(r,launchFlags);
if (top != null) {
if (top.frontOfTask) {
top.task.setIntent(r);
}
ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,r,top.task);
top.deliverNewIntentLocked(callingUid,r.intent);
}
 else {
addingToTask=true;
sourceRecord=intentActivity;
}
}
 else if (r.realActivity.equals(intentActivity.task.realActivity)) {
if (((launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0 || launchSingleTop) && intentActivity.realActivity.equals(r.realActivity)) {
ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,r,intentActivity.task);
if (intentActivity.frontOfTask) {
intentActivity.task.setIntent(r);
}
intentActivity.deliverNewIntentLocked(callingUid,r.intent);
}
 else if (!r.intent.filterEquals(intentActivity.task.intent)) {
addingToTask=true;
sourceRecord=intentActivity;
}
}
 else if ((launchFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) == 0) {
addingToTask=true;
sourceRecord=intentActivity;
}
 else if (!intentActivity.task.rootWasReset) {
intentActivity.task.setIntent(r);
}
if (!addingToTask && reuseTask == null) {
if (doResume) {
targetStack.resumeTopActivityLocked(null,options);
}
 else {
ActivityOptions.abort(options);
}
return ActivityManager.START_TASK_TO_FRONT;
}
}
}
}
if (r.packageName != null) {
ActivityStack topStack=getFocusedStack();
ActivityRecord top=topStack.topRunningNonDelayedActivityLocked(notTop);
if (top != null && r.resultTo == null) {
if (top.realActivity.equals(r.realActivity) && top.userId == r.userId) {
if (top.app != null && top.app.thread != null) {
if ((launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0 || launchSingleTop || launchSingleTask) {
ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,top,top.task);
topStack.mLastPausedActivity=null;
if (doResume) {
resumeTopActivitiesLocked();
}
ActivityOptions.abort(options);
if ((startFlags & ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
return ActivityManager.START_RETURN_INTENT_TO_CALLER;
}
top.deliverNewIntentLocked(callingUid,r.intent);
return ActivityManager.START_DELIVERED_TO_TOP;
}
}
}
}
}
 else {
if (r.resultTo != null) {
r.resultTo.task.stack.sendActivityResultLocked(-1,r.resultTo,r.resultWho,r.requestCode,Activity.RESULT_CANCELED,null);
}
ActivityOptions.abort(options);
return ActivityManager.START_CLASS_NOT_FOUND;
}
boolean newTask=false;
boolean keepCurTransition=false;
TaskRecord taskToAffiliate=launchTaskBehind && sourceRecord != null ? sourceRecord.task : null;
if (r.resultTo == null && inTask == null && !addingToTask && (launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
if (isLockTaskModeViolation(reuseTask)) {
Slog.e(TAG,"String_Node_Str" + r);
return ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
}
newTask=true;
targetStack=adjustStackFocus(r,newTask);
if (!launchTaskBehind) {
targetStack.moveToFront();
}
if (reuseTask == null) {
r.setTask(targetStack.createTaskRecord(getNextTaskId(),newTaskInfo != null ? newTaskInfo : r.info,newTaskIntent != null ? newTaskIntent : intent,voiceSession,voiceInteractor,!launchTaskBehind),taskToAffiliate);
if (DEBUG_TASKS) Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task);
}
 else {
r.setTask(reuseTask,taskToAffiliate);
}
if (!movedHome) {
if ((launchFlags & (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME)) == (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME)) {
r.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE);
}
}
}
 else if (sourceRecord != null) {
final TaskRecord sourceTask=sourceRecord.task;
if (isLockTaskModeViolation(sourceTask)) {
Slog.e(TAG,"String_Node_Str" + r);
return ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
}
targetStack=sourceTask.stack;
targetStack.moveToFront();
mWindowManager.moveTaskToTop(targetStack.topTask().taskId);
if (!addingToTask && (launchFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) {
ActivityRecord top=sourceTask.performClearTaskLocked(r,launchFlags);
keepCurTransition=true;
if (top != null) {
ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,r,top.task);
top.deliverNewIntentLocked(callingUid,r.intent);
targetStack.mLastPausedActivity=null;
if (doResume) {
targetStack.resumeTopActivityLocked(null);
}
ActivityOptions.abort(options);
return ActivityManager.START_DELIVERED_TO_TOP;
}
}
 else if (!addingToTask && (launchFlags & Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) {
final ActivityRecord top=sourceTask.findActivityInHistoryLocked(r);
if (top != null) {
final TaskRecord task=top.task;
task.moveActivityToFrontLocked(top);
ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,r,task);
top.updateOptionsLocked(options);
top.deliverNewIntentLocked(callingUid,r.intent);
targetStack.mLastPausedActivity=null;
if (doResume) {
targetStack.resumeTopActivityLocked(null);
}
return ActivityManager.START_DELIVERED_TO_TOP;
}
}
r.setTask(sourceTask,null);
if (DEBUG_TASKS) Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task+ "String_Node_Str"+ sourceRecord);
}
 else if (inTask != null) {
if (isLockTaskModeViolation(inTask)) {
Slog.e(TAG,"String_Node_Str" + r);
return ActivityManager.START_RETURN_LOCK_TASK_MODE_VIOLATION;
}
targetStack=inTask.stack;
targetStack.moveTaskToFrontLocked(inTask,r,options);
mWindowManager.moveTaskToTop(inTask.taskId);
ActivityRecord top=inTask.getTopActivity();
if (top != null && top.realActivity.equals(r.realActivity) && top.userId == r.userId) {
if ((launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0 || launchSingleTop || launchSingleTask) {
ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,top,top.task);
if ((startFlags & ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
return ActivityManager.START_RETURN_INTENT_TO_CALLER;
}
top.deliverNewIntentLocked(callingUid,r.intent);
return ActivityManager.START_DELIVERED_TO_TOP;
}
}
if (!addingToTask) {
ActivityOptions.abort(options);
return ActivityManager.START_TASK_TO_FRONT;
}
r.setTask(inTask,null);
if (DEBUG_TASKS) Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task);
}
 else {
targetStack=adjustStackFocus(r,newTask);
targetStack.moveToFront();
ActivityRecord prev=targetStack.topActivity();
r.setTask(prev != null ? prev.task : targetStack.createTaskRecord(getNextTaskId(),r.info,intent,null,null,true),null);
mWindowManager.moveTaskToTop(r.task.taskId);
if (DEBUG_TASKS) Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task);
}
mService.grantUriPermissionFromIntentLocked(callingUid,r.packageName,intent,r.getUriPermissionsLocked(),r.userId);
if (sourceRecord != null && sourceRecord.isRecentsActivity()) {
r.task.setTaskToReturnTo(RECENTS_ACTIVITY_TYPE);
}
if (newTask) {
EventLog.writeEvent(EventLogTags.AM_CREATE_TASK,r.userId,r.task.taskId);
}
ActivityStack.logStartActivity(EventLogTags.AM_CREATE_ACTIVITY,r,r.task);
targetStack.mLastPausedActivity=null;
targetStack.startActivityLocked(r,newTask,doResume,keepCurTransition,options);
if (!launchTaskBehind) {
mService.setFocusedActivityLocked(r);
}
return ActivityManager.START_SUCCESS;
}