Program: 192632
Project: 192632
Buggy source:
private int startActivityUnchecked(final ActivityRecord r,ActivityRecord sourceRecord,IVoiceInteractionSession voiceSession,IVoiceInteractor voiceInteractor,int startFlags,boolean doResume,ActivityOptions options,TaskRecord inTask){
  setInitialState(r,options,inTask,doResume,startFlags,sourceRecord,voiceSession,voiceInteractor);
  computeLaunchingTaskFlags();
  computeSourceStack();
  mIntent.setFlags(mLaunchFlags);
  ActivityRecord intentActivity=getReusableIntentActivity();
  if (intentActivity != null) {
    if (mSupervisor.isLockTaskModeViolation(intentActivity.task,(mLaunchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK))) {
      mSupervisor.showLockTaskToast();
      Slog.e(TAG,"String_Node_Str");
      return START_RETURN_LOCK_TASK_MODE_VIOLATION;
    }
    if (mStartActivity.task == null) {
      mStartActivity.task=intentActivity.task;
    }
    if (intentActivity.task.intent == null) {
      intentActivity.task.setIntent(mStartActivity);
    }
    if ((mLaunchFlags & FLAG_ACTIVITY_CLEAR_TOP) != 0 || mLaunchSingleInstance || mLaunchSingleTask) {
      final ActivityRecord top=intentActivity.task.performClearTaskForReuseLocked(mStartActivity,mLaunchFlags);
      if (top != null) {
        if (top.frontOfTask) {
          top.task.setIntent(mStartActivity);
        }
        ActivityStack.logStartActivity(AM_NEW_INTENT,mStartActivity,top.task);
        top.deliverNewIntentLocked(mCallingUid,mStartActivity.intent,mStartActivity.launchedFromPackage);
      }
    }
    intentActivity=setTargetStackAndMoveToFrontIfNeeded(intentActivity);
    if ((mStartFlags & START_FLAG_ONLY_IF_NEEDED) != 0) {
      resumeTargetStackIfNeeded();
      return START_RETURN_INTENT_TO_CALLER;
    }
    setTaskFromIntentActivity(intentActivity);
    if (!mAddingToTask && mReuseTask == null) {
      resumeTargetStackIfNeeded();
      return START_TASK_TO_FRONT;
    }
  }
  if (mStartActivity.packageName == null) {
    if (mStartActivity.resultTo != null && mStartActivity.resultTo.task.stack != null) {
      mStartActivity.resultTo.task.stack.sendActivityResultLocked(-1,mStartActivity.resultTo,mStartActivity.resultWho,mStartActivity.requestCode,RESULT_CANCELED,null);
    }
    ActivityOptions.abort(mOptions);
    return START_CLASS_NOT_FOUND;
  }
  final ActivityStack topStack=mSupervisor.mFocusedStack;
  final ActivityRecord top=topStack.topRunningNonDelayedActivityLocked(mNotTop);
  final boolean dontStart=top != null && mStartActivity.resultTo == null && top.realActivity.equals(mStartActivity.realActivity) && top.userId == mStartActivity.userId && top.app != null && top.app.thread != null && ((mLaunchFlags & FLAG_ACTIVITY_SINGLE_TOP) != 0 || mLaunchSingleTop || mLaunchSingleTask);
  if (dontStart) {
    ActivityStack.logStartActivity(AM_NEW_INTENT,top,top.task);
    topStack.mLastPausedActivity=null;
    if (mDoResume) {
      mSupervisor.resumeFocusedStackTopActivityLocked();
    }
    ActivityOptions.abort(mOptions);
    if ((mStartFlags & START_FLAG_ONLY_IF_NEEDED) != 0) {
      return START_RETURN_INTENT_TO_CALLER;
    }
    top.deliverNewIntentLocked(mCallingUid,mStartActivity.intent,mStartActivity.launchedFromPackage);
    return START_DELIVERED_TO_TOP;
  }
  boolean newTask=false;
  final TaskRecord taskToAffiliate=(mLaunchTaskBehind && mSourceRecord != null) ? mSourceRecord.task : null;
  if (mStartActivity.resultTo == null && mInTask == null && !mAddingToTask && (mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) {
    newTask=true;
    setTaskFromReuseOrCreateNewTask(taskToAffiliate);
    if (mSupervisor.isLockTaskModeViolation(mStartActivity.task)) {
      Slog.e(TAG,"String_Node_Str" + mStartActivity);
      return START_RETURN_LOCK_TASK_MODE_VIOLATION;
    }
    if (!mMovedHome) {
      updateTaskReturnToType(mStartActivity.task,mLaunchFlags,topStack);
    }
  }
 else   if (mSourceRecord != null) {
    if (mSupervisor.isLockTaskModeViolation(mSourceRecord.task)) {
      Slog.e(TAG,"String_Node_Str" + mStartActivity);
      return START_RETURN_LOCK_TASK_MODE_VIOLATION;
    }
    final int result=setTaskFromSourceRecord();
    if (result != START_SUCCESS) {
      return result;
    }
  }
 else   if (mInTask != null) {
    if (mSupervisor.isLockTaskModeViolation(mInTask)) {
      Slog.e(TAG,"String_Node_Str" + mStartActivity);
      return START_RETURN_LOCK_TASK_MODE_VIOLATION;
    }
    final int result=setTaskFromInTask();
    if (result != START_SUCCESS) {
      return result;
    }
  }
 else {
    setTaskToCurrentTopOrCreateNewTask();
  }
  mService.grantUriPermissionFromIntentLocked(mCallingUid,mStartActivity.packageName,mIntent,mStartActivity.getUriPermissionsLocked(),mStartActivity.userId);
  if (mSourceRecord != null && mSourceRecord.isRecentsActivity()) {
    mStartActivity.task.setTaskToReturnTo(RECENTS_ACTIVITY_TYPE);
  }
  if (newTask) {
    EventLog.writeEvent(EventLogTags.AM_CREATE_TASK,mStartActivity.userId,mStartActivity.task.taskId);
  }
  ActivityStack.logStartActivity(EventLogTags.AM_CREATE_ACTIVITY,mStartActivity,mStartActivity.task);
  mTargetStack.mLastPausedActivity=null;
  mTargetStack.startActivityLocked(mStartActivity,newTask,mKeepCurTransition,mOptions);
  if (mDoResume) {
    if (!mLaunchTaskBehind) {
      mService.setFocusedActivityLocked(mStartActivity,"String_Node_Str");
    }
    if (mTargetStack.isFocusable()) {
      mSupervisor.resumeFocusedStackTopActivityLocked(mTargetStack,mStartActivity,mOptions);
    }
 else {
      mTargetStack.ensureActivitiesVisibleLocked(null,0,!PRESERVE_WINDOWS);
    }
  }
 else {
    mTargetStack.addRecentActivityLocked(mStartActivity);
  }
  mSupervisor.updateUserStackLocked(mStartActivity.userId,mTargetStack);
  final int preferredLaunchStackId=(mOptions != null) ? mOptions.getLaunchStackId() : INVALID_STACK_ID;
  mSupervisor.showNonResizeableDockToastIfNeeded(mStartActivity.task,preferredLaunchStackId,mTargetStack.mStackId);
  return START_SUCCESS;
}

Fixed version (ground truth):
private int startActivityUnchecked(final ActivityRecord r,ActivityRecord sourceRecord,IVoiceInteractionSession voiceSession,IVoiceInteractor voiceInteractor,int startFlags,boolean doResume,ActivityOptions options,TaskRecord inTask){
  setInitialState(r,options,inTask,doResume,startFlags,sourceRecord,voiceSession,voiceInteractor);
  computeLaunchingTaskFlags();
  computeSourceStack();
  mIntent.setFlags(mLaunchFlags);
  ActivityRecord intentActivity=getReusableIntentActivity();
  if (intentActivity != null) {
    if (mSupervisor.isLockTaskModeViolation(intentActivity.task,(mLaunchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK))) {
      mSupervisor.showLockTaskToast();
      Slog.e(TAG,"String_Node_Str");
      return START_RETURN_LOCK_TASK_MODE_VIOLATION;
    }
    if (mStartActivity.task == null) {
      mStartActivity.task=intentActivity.task;
    }
    if (intentActivity.task.intent == null) {
      intentActivity.task.setIntent(mStartActivity);
    }
    if ((mLaunchFlags & FLAG_ACTIVITY_CLEAR_TOP) != 0 || mLaunchSingleInstance || mLaunchSingleTask) {
      final ActivityRecord top=intentActivity.task.performClearTaskForReuseLocked(mStartActivity,mLaunchFlags);
      if (top != null) {
        if (top.frontOfTask) {
          top.task.setIntent(mStartActivity);
        }
        ActivityStack.logStartActivity(AM_NEW_INTENT,mStartActivity,top.task);
        top.deliverNewIntentLocked(mCallingUid,mStartActivity.intent,mStartActivity.launchedFromPackage);
      }
    }
    intentActivity=setTargetStackAndMoveToFrontIfNeeded(intentActivity);
    if ((mStartFlags & START_FLAG_ONLY_IF_NEEDED) != 0) {
      resumeTargetStackIfNeeded();
      return START_RETURN_INTENT_TO_CALLER;
    }
    setTaskFromIntentActivity(intentActivity);
    if (!mAddingToTask && mReuseTask == null) {
      resumeTargetStackIfNeeded();
      return START_TASK_TO_FRONT;
    }
  }
  if (mStartActivity.packageName == null) {
    if (mStartActivity.resultTo != null && mStartActivity.resultTo.task.stack != null) {
      mStartActivity.resultTo.task.stack.sendActivityResultLocked(-1,mStartActivity.resultTo,mStartActivity.resultWho,mStartActivity.requestCode,RESULT_CANCELED,null);
    }
    ActivityOptions.abort(mOptions);
    return START_CLASS_NOT_FOUND;
  }
  final ActivityStack topStack=mSupervisor.mFocusedStack;
  final ActivityRecord top=topStack.topRunningNonDelayedActivityLocked(mNotTop);
  final boolean dontStart=top != null && mStartActivity.resultTo == null && top.realActivity.equals(mStartActivity.realActivity) && top.userId == mStartActivity.userId && top.app != null && top.app.thread != null && ((mLaunchFlags & FLAG_ACTIVITY_SINGLE_TOP) != 0 || mLaunchSingleTop || mLaunchSingleTask);
  if (dontStart) {
    ActivityStack.logStartActivity(AM_NEW_INTENT,top,top.task);
    topStack.mLastPausedActivity=null;
    if (mDoResume) {
      mSupervisor.resumeFocusedStackTopActivityLocked();
    }
    ActivityOptions.abort(mOptions);
    if ((mStartFlags & START_FLAG_ONLY_IF_NEEDED) != 0) {
      return START_RETURN_INTENT_TO_CALLER;
    }
    top.deliverNewIntentLocked(mCallingUid,mStartActivity.intent,mStartActivity.launchedFromPackage);
    return START_DELIVERED_TO_TOP;
  }
  boolean newTask=false;
  final TaskRecord taskToAffiliate=(mLaunchTaskBehind && mSourceRecord != null) ? mSourceRecord.task : null;
  if (mStartActivity.resultTo == null && mInTask == null && !mAddingToTask && (mLaunchFlags & FLAG_ACTIVITY_NEW_TASK) != 0) {
    newTask=true;
    setTaskFromReuseOrCreateNewTask(taskToAffiliate);
    if (mSupervisor.isLockTaskModeViolation(mStartActivity.task)) {
      Slog.e(TAG,"String_Node_Str" + mStartActivity);
      return START_RETURN_LOCK_TASK_MODE_VIOLATION;
    }
    if (!mMovedHome) {
      updateTaskReturnToType(mStartActivity.task,mLaunchFlags,topStack);
    }
  }
 else   if (mSourceRecord != null) {
    if (mSupervisor.isLockTaskModeViolation(mSourceRecord.task)) {
      Slog.e(TAG,"String_Node_Str" + mStartActivity);
      return START_RETURN_LOCK_TASK_MODE_VIOLATION;
    }
    final int result=setTaskFromSourceRecord();
    if (result != START_SUCCESS) {
      return result;
    }
  }
 else   if (mInTask != null) {
    if (mSupervisor.isLockTaskModeViolation(mInTask)) {
      Slog.e(TAG,"String_Node_Str" + mStartActivity);
      return START_RETURN_LOCK_TASK_MODE_VIOLATION;
    }
    final int result=setTaskFromInTask();
    if (result != START_SUCCESS) {
      return result;
    }
  }
 else {
    setTaskToCurrentTopOrCreateNewTask();
  }
  mService.grantUriPermissionFromIntentLocked(mCallingUid,mStartActivity.packageName,mIntent,mStartActivity.getUriPermissionsLocked(),mStartActivity.userId);
  if (mSourceRecord != null && mSourceRecord.isRecentsActivity()) {
    mStartActivity.task.setTaskToReturnTo(RECENTS_ACTIVITY_TYPE);
  }
  if (newTask) {
    EventLog.writeEvent(EventLogTags.AM_CREATE_TASK,mStartActivity.userId,mStartActivity.task.taskId);
  }
  ActivityStack.logStartActivity(EventLogTags.AM_CREATE_ACTIVITY,mStartActivity,mStartActivity.task);
  mTargetStack.mLastPausedActivity=null;
  mTargetStack.startActivityLocked(mStartActivity,newTask,mKeepCurTransition,mOptions);
  if (mDoResume) {
    if (!mLaunchTaskBehind) {
      mService.setFocusedActivityLocked(mStartActivity,"String_Node_Str");
    }
    if (mTargetStack.isFocusable()) {
      mSupervisor.resumeFocusedStackTopActivityLocked(mTargetStack,mStartActivity,mOptions);
    }
 else {
      mTargetStack.ensureActivitiesVisibleLocked(null,0,!PRESERVE_WINDOWS);
      mWindowManager.executeAppTransition();
    }
  }
 else {
    mTargetStack.addRecentActivityLocked(mStartActivity);
  }
  mSupervisor.updateUserStackLocked(mStartActivity.userId,mTargetStack);
  final int preferredLaunchStackId=(mOptions != null) ? mOptions.getLaunchStackId() : INVALID_STACK_ID;
  mSupervisor.showNonResizeableDockToastIfNeeded(mStartActivity.task,preferredLaunchStackId,mTargetStack.mStackId);
  return START_SUCCESS;
}