Program: 195435
Project: 195435
Buggy source:
final void startActivityLocked(ActivityRecord r,boolean newTask,boolean doResume,boolean keepCurTransition,Bundle options){
  TaskRecord rTask=r.task;
  final int taskId=rTask.taskId;
  if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) {
    insertTaskAtTop(rTask);
    mWindowManager.moveTaskToTop(taskId);
  }
  TaskRecord task=null;
  if (!newTask) {
    boolean startIt=true;
    for (int taskNdx=mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
      task=mTaskHistory.get(taskNdx);
      if (task.getTopActivity() == null) {
        continue;
      }
      if (task == r.task) {
        if (!startIt) {
          if (DEBUG_ADD_REMOVE)           Slog.i(TAG,"String_Node_Str" + r + "String_Node_Str"+ task,new RuntimeException("String_Node_Str").fillInStackTrace());
          task.addActivityToTop(r);
          r.putInHistory();
          mWindowManager.addAppToken(task.mActivities.indexOf(r),r.appToken,r.task.taskId,mStackId,r.info.screenOrientation,r.fullscreen,(r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0,r.userId,r.info.configChanges,task.voiceSession != null,r.mLaunchTaskBehind);
          if (VALIDATE_TOKENS) {
            validateAppTokensLocked();
          }
          ActivityOptions.abort(options);
          return;
        }
        break;
      }
 else       if (task.numFullscreen > 0) {
        startIt=false;
      }
    }
  }
  if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) {
    mStackSupervisor.mUserLeaving=false;
    if (DEBUG_USER_LEAVING)     Slog.v(TAG_USER_LEAVING,"String_Node_Str");
  }
  task=r.task;
  if (DEBUG_ADD_REMOVE)   Slog.i(TAG,"String_Node_Str" + r + "String_Node_Str"+ task,new RuntimeException("String_Node_Str").fillInStackTrace());
  task.addActivityToTop(r);
  task.setFrontOfTask();
  r.putInHistory();
  if (!isHomeStack() || numActivities() > 0) {
    boolean showStartingIcon=newTask;
    ProcessRecord proc=r.app;
    if (proc == null) {
      proc=mService.mProcessNames.get(r.processName,r.info.applicationInfo.uid);
    }
    if (proc == null || proc.thread == null) {
      showStartingIcon=true;
    }
    if (DEBUG_TRANSITION)     Slog.v(TAG_TRANSITION,"String_Node_Str" + r);
    if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
      mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE,keepCurTransition);
      mNoAnimActivities.add(r);
    }
 else {
      mWindowManager.prepareAppTransition(newTask ? r.mLaunchTaskBehind ? AppTransition.TRANSIT_TASK_OPEN_BEHIND : AppTransition.TRANSIT_TASK_OPEN : AppTransition.TRANSIT_ACTIVITY_OPEN,keepCurTransition);
      mNoAnimActivities.remove(r);
    }
    mWindowManager.addAppToken(task.mActivities.indexOf(r),r.appToken,r.task.taskId,mStackId,r.info.screenOrientation,r.fullscreen,(r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0,r.userId,r.info.configChanges,task.voiceSession != null,r.mLaunchTaskBehind);
    boolean doShow=true;
    if (newTask) {
      if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
        resetTaskIfNeededLocked(r,r);
        doShow=topRunningNonDelayedActivityLocked(null) == r;
      }
    }
 else     if (options != null && new ActivityOptions(options).getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) {
      doShow=false;
    }
    if (r.mLaunchTaskBehind) {
      mWindowManager.setAppVisibility(r.appToken,true);
      ensureActivitiesVisibleLocked(null,0);
    }
 else     if (SHOW_APP_STARTING_PREVIEW && doShow) {
      ActivityRecord prev=mResumedActivity;
      if (prev != null) {
        if (prev.task != r.task) {
          prev=null;
        }
 else         if (prev.nowVisible) {
          prev=null;
        }
      }
      mWindowManager.setAppStartingWindow(r.appToken,r.packageName,r.theme,mService.compatibilityInfoForPackageLocked(r.info.applicationInfo),r.nonLocalizedLabel,r.labelRes,r.icon,r.logo,r.windowFlags,prev != null ? prev.appToken : null,showStartingIcon);
      r.mStartingWindowShown=true;
    }
  }
 else {
    mWindowManager.addAppToken(task.mActivities.indexOf(r),r.appToken,r.task.taskId,mStackId,r.info.screenOrientation,r.fullscreen,(r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0,r.userId,r.info.configChanges,task.voiceSession != null,r.mLaunchTaskBehind);
    ActivityOptions.abort(options);
    options=null;
  }
  if (VALIDATE_TOKENS) {
    validateAppTokensLocked();
  }
  if (doResume) {
    mStackSupervisor.resumeTopActivitiesLocked(this,r,options);
  }
}

Fixed version (ground truth):
final void startActivityLocked(ActivityRecord r,boolean newTask,boolean doResume,boolean keepCurTransition,Bundle options){
  TaskRecord rTask=r.task;
  final int taskId=rTask.taskId;
  if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) {
    insertTaskAtTop(rTask,r);
    mWindowManager.moveTaskToTop(taskId);
  }
  TaskRecord task=null;
  if (!newTask) {
    boolean startIt=true;
    for (int taskNdx=mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
      task=mTaskHistory.get(taskNdx);
      if (task.getTopActivity() == null) {
        continue;
      }
      if (task == r.task) {
        if (!startIt) {
          if (DEBUG_ADD_REMOVE)           Slog.i(TAG,"String_Node_Str" + r + "String_Node_Str"+ task,new RuntimeException("String_Node_Str").fillInStackTrace());
          task.addActivityToTop(r);
          r.putInHistory();
          mWindowManager.addAppToken(task.mActivities.indexOf(r),r.appToken,r.task.taskId,mStackId,r.info.screenOrientation,r.fullscreen,(r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0,r.userId,r.info.configChanges,task.voiceSession != null,r.mLaunchTaskBehind);
          if (VALIDATE_TOKENS) {
            validateAppTokensLocked();
          }
          ActivityOptions.abort(options);
          return;
        }
        break;
      }
 else       if (task.numFullscreen > 0) {
        startIt=false;
      }
    }
  }
  if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) {
    mStackSupervisor.mUserLeaving=false;
    if (DEBUG_USER_LEAVING)     Slog.v(TAG_USER_LEAVING,"String_Node_Str");
  }
  task=r.task;
  if (DEBUG_ADD_REMOVE)   Slog.i(TAG,"String_Node_Str" + r + "String_Node_Str"+ task,new RuntimeException("String_Node_Str").fillInStackTrace());
  task.addActivityToTop(r);
  task.setFrontOfTask();
  r.putInHistory();
  if (!isHomeStack() || numActivities() > 0) {
    boolean showStartingIcon=newTask;
    ProcessRecord proc=r.app;
    if (proc == null) {
      proc=mService.mProcessNames.get(r.processName,r.info.applicationInfo.uid);
    }
    if (proc == null || proc.thread == null) {
      showStartingIcon=true;
    }
    if (DEBUG_TRANSITION)     Slog.v(TAG_TRANSITION,"String_Node_Str" + r);
    if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
      mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE,keepCurTransition);
      mNoAnimActivities.add(r);
    }
 else {
      mWindowManager.prepareAppTransition(newTask ? r.mLaunchTaskBehind ? AppTransition.TRANSIT_TASK_OPEN_BEHIND : AppTransition.TRANSIT_TASK_OPEN : AppTransition.TRANSIT_ACTIVITY_OPEN,keepCurTransition);
      mNoAnimActivities.remove(r);
    }
    mWindowManager.addAppToken(task.mActivities.indexOf(r),r.appToken,r.task.taskId,mStackId,r.info.screenOrientation,r.fullscreen,(r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0,r.userId,r.info.configChanges,task.voiceSession != null,r.mLaunchTaskBehind);
    boolean doShow=true;
    if (newTask) {
      if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
        resetTaskIfNeededLocked(r,r);
        doShow=topRunningNonDelayedActivityLocked(null) == r;
      }
    }
 else     if (options != null && new ActivityOptions(options).getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) {
      doShow=false;
    }
    if (r.mLaunchTaskBehind) {
      mWindowManager.setAppVisibility(r.appToken,true);
      ensureActivitiesVisibleLocked(null,0);
    }
 else     if (SHOW_APP_STARTING_PREVIEW && doShow) {
      ActivityRecord prev=mResumedActivity;
      if (prev != null) {
        if (prev.task != r.task) {
          prev=null;
        }
 else         if (prev.nowVisible) {
          prev=null;
        }
      }
      mWindowManager.setAppStartingWindow(r.appToken,r.packageName,r.theme,mService.compatibilityInfoForPackageLocked(r.info.applicationInfo),r.nonLocalizedLabel,r.labelRes,r.icon,r.logo,r.windowFlags,prev != null ? prev.appToken : null,showStartingIcon);
      r.mStartingWindowShown=true;
    }
  }
 else {
    mWindowManager.addAppToken(task.mActivities.indexOf(r),r.appToken,r.task.taskId,mStackId,r.info.screenOrientation,r.fullscreen,(r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0,r.userId,r.info.configChanges,task.voiceSession != null,r.mLaunchTaskBehind);
    ActivityOptions.abort(options);
    options=null;
  }
  if (VALIDATE_TOKENS) {
    validateAppTokensLocked();
  }
  if (doResume) {
    mStackSupervisor.resumeTopActivitiesLocked(this,r,options);
  }
}