Program: 2111
Project: 2111
Buggy source:
final int startActivityUncheckedLocked(ActivityRecord r,ActivityRecord sourceRecord,int startFlags,boolean doResume,Bundle options){
  final Intent intent=r.intent;
  final int callingUid=r.launchedFromUid;
  int launchFlags=intent.getFlags();
  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) {
      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 (r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
    launchFlags|=Intent.FLAG_ACTIVITY_NEW_TASK;
  }
  final ActivityStack sourceStack;
  final TaskRecord sourceTask;
  if (sourceRecord != null) {
    sourceTask=sourceRecord.task;
    sourceStack=sourceTask.stack;
  }
 else {
    sourceTask=null;
    sourceStack=null;
  }
  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;
  }
  boolean addingToTask=false;
  boolean movedHome=false;
  TaskRecord reuseTask=null;
  ActivityStack targetStack;
  if (((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0 && (launchFlags & Intent.FLAG_ACTIVITY_MULTIPLE_TASK) == 0) || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK || r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
    if (r.resultTo == null) {
      ActivityRecord intentActivity=r.launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE ? findTaskLocked(intent,r.info) : findActivityLocked(intent,r.info);
      if (intentActivity != null) {
        if (r.task == null) {
          r.task=intentActivity.task;
        }
        targetStack=intentActivity.task.stack;
        moveHomeStack(targetStack.isHomeStack());
        if (intentActivity.task.intent == null) {
          intentActivity.task.setIntent(intent,r.info);
        }
        final ActivityStack lastStack=getLastStack();
        ActivityRecord curTop=lastStack == null ? null : lastStack.topRunningNonDelayedActivityLocked(notTop);
        if (curTop != null && curTop.task != intentActivity.task) {
          r.intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
          if (sourceRecord == null || sourceStack.topActivity() == sourceRecord) {
            movedHome=true;
            if ((launchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) {
              r.mLaunchHomeTaskNext=true;
            }
            targetStack.moveTaskToFrontLocked(intentActivity.task,r,options);
            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) {
            setLaunchHomeTaskNextFlag(sourceRecord,null,targetStack);
            targetStack.resumeTopActivityLocked(null,options);
          }
 else {
            ActivityOptions.abort(options);
          }
          if (r.task == null)           Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
          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.intent,r.info);
        }
 else         if ((launchFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0 || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK || r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
          ActivityRecord top=intentActivity.task.performClearTaskLocked(r,launchFlags);
          if (top != null) {
            if (top.frontOfTask) {
              top.task.setIntent(r.intent,r.info);
            }
            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 || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) && intentActivity.realActivity.equals(r.realActivity)) {
            ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,r,intentActivity.task);
            if (intentActivity.frontOfTask) {
              intentActivity.task.setIntent(r.intent,r.info);
            }
            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.intent,r.info);
        }
        if (!addingToTask && reuseTask == null) {
          if (doResume) {
            setLaunchHomeTaskNextFlag(sourceRecord,intentActivity,targetStack);
            targetStack.resumeTopActivityLocked(null,options);
          }
 else {
            ActivityOptions.abort(options);
          }
          if (r.task == null)           Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
          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 || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
            ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,top,top.task);
            if (doResume) {
              setLaunchHomeTaskNextFlag(sourceRecord,null,topStack);
              topStack.resumeTopActivityLocked(null);
            }
            ActivityOptions.abort(options);
            if ((startFlags & ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
              if (r.task == null)               Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
              return ActivityManager.START_RETURN_INTENT_TO_CALLER;
            }
            top.deliverNewIntentLocked(callingUid,r.intent);
            if (r.task == null)             Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
            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);
    if (r.task == null)     Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
    return ActivityManager.START_CLASS_NOT_FOUND;
  }
  boolean newTask=false;
  boolean keepCurTransition=false;
  if (r.resultTo == null && !addingToTask && (launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
    targetStack=getCorrectStack(r);
    moveHomeStack(targetStack.isHomeStack());
    if (reuseTask == null) {
      r.setTask(targetStack.createTaskRecord(getNextTaskId(),r.info,intent,true),null,true);
      if (DEBUG_TASKS)       Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task);
    }
 else {
      r.setTask(reuseTask,reuseTask,true);
    }
    newTask=true;
    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.mLaunchHomeTaskNext=true;
      }
    }
  }
 else   if (sourceRecord != null) {
    targetStack=sourceRecord.task.stack;
    moveHomeStack(targetStack.isHomeStack());
    if (!addingToTask && (launchFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) {
      ActivityRecord top=sourceRecord.task.performClearTaskLocked(r,launchFlags);
      keepCurTransition=true;
      if (top != null) {
        ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,r,top.task);
        top.deliverNewIntentLocked(callingUid,r.intent);
        if (doResume) {
          setLaunchHomeTaskNextFlag(sourceRecord,null,targetStack);
          targetStack.resumeTopActivityLocked(null);
        }
        ActivityOptions.abort(options);
        if (r.task == null)         Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
        return ActivityManager.START_DELIVERED_TO_TOP;
      }
    }
 else     if (!addingToTask && (launchFlags & Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) {
      final ActivityRecord top=targetStack.findActivityInHistoryLocked(r,sourceRecord.task);
      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);
        if (doResume) {
          setLaunchHomeTaskNextFlag(sourceRecord,null,targetStack);
          targetStack.resumeTopActivityLocked(null);
        }
        if (r.task == null)         Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
        return ActivityManager.START_DELIVERED_TO_TOP;
      }
    }
    r.setTask(sourceRecord.task,sourceRecord.thumbHolder,false);
    if (DEBUG_TASKS)     Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task);
  }
 else {
    ActivityStack lastStack=getLastStack();
    targetStack=lastStack != null ? lastStack : mHomeStack;
    moveHomeStack(targetStack.isHomeStack());
    ActivityRecord prev=lastStack == null ? null : targetStack.topActivity();
    r.setTask(prev != null ? prev.task : targetStack.createTaskRecord(getNextTaskId(),r.info,intent,true),null,true);
    if (DEBUG_TASKS)     Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task);
  }
  mService.grantUriPermissionFromIntentLocked(callingUid,r.packageName,intent,r.getUriPermissionsLocked());
  if (newTask) {
    EventLog.writeEvent(EventLogTags.AM_CREATE_TASK,r.userId,r.task.taskId);
  }
  ActivityStack.logStartActivity(EventLogTags.AM_CREATE_ACTIVITY,r,r.task);
  setLaunchHomeTaskNextFlag(sourceRecord,r,targetStack);
  targetStack.startActivityLocked(r,newTask,doResume,keepCurTransition,options);
  return ActivityManager.START_SUCCESS;
}

Fixed version (ground truth):
final int startActivityUncheckedLocked(ActivityRecord r,ActivityRecord sourceRecord,int startFlags,boolean doResume,Bundle options){
  final Intent intent=r.intent;
  final int callingUid=r.launchedFromUid;
  int launchFlags=intent.getFlags();
  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) {
      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 (r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
    launchFlags|=Intent.FLAG_ACTIVITY_NEW_TASK;
  }
  final ActivityStack sourceStack;
  final TaskRecord sourceTask;
  if (sourceRecord != null) {
    sourceTask=sourceRecord.task;
    sourceStack=sourceTask.stack;
  }
 else {
    sourceTask=null;
    sourceStack=null;
  }
  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;
  }
  boolean addingToTask=false;
  boolean movedHome=false;
  TaskRecord reuseTask=null;
  ActivityStack targetStack;
  if (((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0 && (launchFlags & Intent.FLAG_ACTIVITY_MULTIPLE_TASK) == 0) || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK || r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
    if (r.resultTo == null) {
      ActivityRecord intentActivity=r.launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE ? findTaskLocked(intent,r.info) : findActivityLocked(intent,r.info);
      if (intentActivity != null) {
        if (r.task == null) {
          r.task=intentActivity.task;
        }
        targetStack=intentActivity.task.stack;
        moveHomeStack(targetStack.isHomeStack());
        if (intentActivity.task.intent == null) {
          intentActivity.task.setIntent(intent,r.info);
        }
        final ActivityStack lastStack=getLastStack();
        ActivityRecord curTop=lastStack == null ? null : lastStack.topRunningNonDelayedActivityLocked(notTop);
        if (curTop != null && curTop.task != intentActivity.task) {
          r.intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
          if (sourceRecord == null || sourceStack.topActivity() == sourceRecord) {
            movedHome=true;
            if ((launchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) {
              r.mLaunchHomeTaskNext=true;
            }
            targetStack.moveTaskToFrontLocked(intentActivity.task,r,options);
            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) {
            setLaunchHomeTaskNextFlag(sourceRecord,null,targetStack);
            resumeTopActivitiesLocked(targetStack,null,options);
          }
 else {
            ActivityOptions.abort(options);
          }
          if (r.task == null)           Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
          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.intent,r.info);
        }
 else         if ((launchFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0 || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK || r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
          ActivityRecord top=intentActivity.task.performClearTaskLocked(r,launchFlags);
          if (top != null) {
            if (top.frontOfTask) {
              top.task.setIntent(r.intent,r.info);
            }
            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 || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) && intentActivity.realActivity.equals(r.realActivity)) {
            ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,r,intentActivity.task);
            if (intentActivity.frontOfTask) {
              intentActivity.task.setIntent(r.intent,r.info);
            }
            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.intent,r.info);
        }
        if (!addingToTask && reuseTask == null) {
          if (doResume) {
            setLaunchHomeTaskNextFlag(sourceRecord,intentActivity,targetStack);
            targetStack.resumeTopActivityLocked(null,options);
          }
 else {
            ActivityOptions.abort(options);
          }
          if (r.task == null)           Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
          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 || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
            ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,top,top.task);
            if (doResume) {
              setLaunchHomeTaskNextFlag(sourceRecord,null,topStack);
              resumeTopActivitiesLocked();
            }
            ActivityOptions.abort(options);
            if ((startFlags & ActivityManager.START_FLAG_ONLY_IF_NEEDED) != 0) {
              if (r.task == null)               Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
              return ActivityManager.START_RETURN_INTENT_TO_CALLER;
            }
            top.deliverNewIntentLocked(callingUid,r.intent);
            if (r.task == null)             Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
            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);
    if (r.task == null)     Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
    return ActivityManager.START_CLASS_NOT_FOUND;
  }
  boolean newTask=false;
  boolean keepCurTransition=false;
  if (r.resultTo == null && !addingToTask && (launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
    targetStack=getCorrectStack(r);
    moveHomeStack(targetStack.isHomeStack());
    if (reuseTask == null) {
      r.setTask(targetStack.createTaskRecord(getNextTaskId(),r.info,intent,true),null,true);
      if (DEBUG_TASKS)       Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task);
    }
 else {
      r.setTask(reuseTask,reuseTask,true);
    }
    newTask=true;
    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.mLaunchHomeTaskNext=true;
      }
    }
  }
 else   if (sourceRecord != null) {
    targetStack=sourceRecord.task.stack;
    moveHomeStack(targetStack.isHomeStack());
    if (!addingToTask && (launchFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) {
      ActivityRecord top=sourceRecord.task.performClearTaskLocked(r,launchFlags);
      keepCurTransition=true;
      if (top != null) {
        ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,r,top.task);
        top.deliverNewIntentLocked(callingUid,r.intent);
        if (doResume) {
          setLaunchHomeTaskNextFlag(sourceRecord,null,targetStack);
          targetStack.resumeTopActivityLocked(null);
        }
        ActivityOptions.abort(options);
        if (r.task == null)         Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
        return ActivityManager.START_DELIVERED_TO_TOP;
      }
    }
 else     if (!addingToTask && (launchFlags & Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) {
      final ActivityRecord top=targetStack.findActivityInHistoryLocked(r,sourceRecord.task);
      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);
        if (doResume) {
          setLaunchHomeTaskNextFlag(sourceRecord,null,targetStack);
          targetStack.resumeTopActivityLocked(null);
        }
        if (r.task == null)         Slog.v(TAG,"String_Node_Str",new RuntimeException("String_Node_Str").fillInStackTrace());
        return ActivityManager.START_DELIVERED_TO_TOP;
      }
    }
    r.setTask(sourceRecord.task,sourceRecord.thumbHolder,false);
    if (DEBUG_TASKS)     Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task);
  }
 else {
    ActivityStack lastStack=getLastStack();
    targetStack=lastStack != null ? lastStack : mHomeStack;
    moveHomeStack(targetStack.isHomeStack());
    ActivityRecord prev=lastStack == null ? null : targetStack.topActivity();
    r.setTask(prev != null ? prev.task : targetStack.createTaskRecord(getNextTaskId(),r.info,intent,true),null,true);
    if (DEBUG_TASKS)     Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.task);
  }
  mService.grantUriPermissionFromIntentLocked(callingUid,r.packageName,intent,r.getUriPermissionsLocked());
  if (newTask) {
    EventLog.writeEvent(EventLogTags.AM_CREATE_TASK,r.userId,r.task.taskId);
  }
  ActivityStack.logStartActivity(EventLogTags.AM_CREATE_ACTIVITY,r,r.task);
  setLaunchHomeTaskNextFlag(sourceRecord,r,targetStack);
  targetStack.startActivityLocked(r,newTask,doResume,keepCurTransition,options);
  return ActivityManager.START_SUCCESS;
}