Program: 196693
Project: 196693
Buggy source:
final ActivityRecord activityIdleInternalLocked(final IBinder token,boolean fromTimeout,Configuration config){
  if (localLOGV)   Slog.v(TAG,"String_Node_Str" + token);
  ArrayList<ActivityRecord> stops=null;
  ArrayList<ActivityRecord> finishes=null;
  ArrayList<UserStartedState> startingUsers=null;
  int NS=0;
  int NF=0;
  boolean booting=false;
  boolean enableScreen=false;
  boolean activityRemoved=false;
  ActivityRecord r=ActivityRecord.forToken(token);
  if (r != null) {
    if (DEBUG_IDLE)     Slog.d(TAG,"String_Node_Str" + Debug.getCallers(4));
    mHandler.removeMessages(IDLE_TIMEOUT_MSG,r);
    r.finishLaunchTickingLocked();
    if (fromTimeout) {
      reportActivityLaunchedLocked(fromTimeout,r,-1,-1);
    }
    if (config != null) {
      r.configuration=config;
    }
    r.idle=true;
    if (!mService.mBooted && isFrontStack(r.task.stack)) {
      mService.mBooted=true;
      enableScreen=true;
    }
  }
  if (allResumedActivitiesIdle()) {
    if (r != null) {
      mService.scheduleAppGcsLocked();
    }
    if (mLaunchingActivity.isHeld()) {
      mHandler.removeMessages(LAUNCH_TIMEOUT_MSG);
      if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) {
        throw new IllegalStateException("String_Node_Str");
      }
      mLaunchingActivity.release();
    }
    ensureActivitiesVisibleLocked(null,0);
  }
  stops=processStoppingActivitiesLocked(true);
  NS=stops != null ? stops.size() : 0;
  if ((NF=mFinishingActivities.size()) > 0) {
    finishes=new ArrayList<ActivityRecord>(mFinishingActivities);
    mFinishingActivities.clear();
  }
  booting=mService.mBooting;
  mService.mBooting=false;
  if (mStartingUsers.size() > 0) {
    startingUsers=new ArrayList<UserStartedState>(mStartingUsers);
    mStartingUsers.clear();
  }
  for (int i=0; i < NS; i++) {
    r=stops.get(i);
    final ActivityStack stack=r.task.stack;
    if (r.finishing) {
      stack.finishCurrentActivityLocked(r,ActivityStack.FINISH_IMMEDIATELY,false);
    }
 else {
      stack.stopActivityLocked(r);
    }
  }
  for (int i=0; i < NF; i++) {
    r=finishes.get(i);
    activityRemoved|=r.task.stack.destroyActivityLocked(r,true,"String_Node_Str");
  }
  if (!booting) {
    if (startingUsers != null) {
      for (int i=0; i < startingUsers.size(); i++) {
        mService.finishUserSwitch(startingUsers.get(i));
      }
    }
    if (mStartingBackgroundUsers.size() > 0) {
      startingUsers=new ArrayList<UserStartedState>(mStartingBackgroundUsers);
      mStartingBackgroundUsers.clear();
      for (int i=0; i < startingUsers.size(); i++) {
        mService.finishUserBoot(startingUsers.get(i));
      }
    }
  }
  mService.trimApplications();
  if (booting || enableScreen) {
    mService.postFinishBooting(booting,enableScreen);
  }
  if (activityRemoved) {
    resumeTopActivitiesLocked();
  }
  return r;
}

Fixed version (ground truth):
final ActivityRecord activityIdleInternalLocked(final IBinder token,boolean fromTimeout,Configuration config){
  if (localLOGV)   Slog.v(TAG,"String_Node_Str" + token);
  ArrayList<ActivityRecord> stops=null;
  ArrayList<ActivityRecord> finishes=null;
  ArrayList<UserStartedState> startingUsers=null;
  int NS=0;
  int NF=0;
  boolean booting=false;
  boolean enableScreen=false;
  boolean activityRemoved=false;
  ActivityRecord r=ActivityRecord.forToken(token);
  if (r != null) {
    if (DEBUG_IDLE)     Slog.d(TAG,"String_Node_Str" + Debug.getCallers(4));
    mHandler.removeMessages(IDLE_TIMEOUT_MSG,r);
    r.finishLaunchTickingLocked();
    if (fromTimeout) {
      reportActivityLaunchedLocked(fromTimeout,r,-1,-1);
    }
    if (config != null) {
      r.configuration=config;
    }
    r.idle=true;
    if (isFrontStack(r.task.stack) || fromTimeout) {
      booting=mService.mBooting;
      mService.mBooting=false;
      if (!mService.mBooted) {
        mService.mBooted=true;
        enableScreen=true;
      }
    }
  }
  if (allResumedActivitiesIdle()) {
    if (r != null) {
      mService.scheduleAppGcsLocked();
    }
    if (mLaunchingActivity.isHeld()) {
      mHandler.removeMessages(LAUNCH_TIMEOUT_MSG);
      if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) {
        throw new IllegalStateException("String_Node_Str");
      }
      mLaunchingActivity.release();
    }
    ensureActivitiesVisibleLocked(null,0);
  }
  stops=processStoppingActivitiesLocked(true);
  NS=stops != null ? stops.size() : 0;
  if ((NF=mFinishingActivities.size()) > 0) {
    finishes=new ArrayList<ActivityRecord>(mFinishingActivities);
    mFinishingActivities.clear();
  }
  if (mStartingUsers.size() > 0) {
    startingUsers=new ArrayList<UserStartedState>(mStartingUsers);
    mStartingUsers.clear();
  }
  for (int i=0; i < NS; i++) {
    r=stops.get(i);
    final ActivityStack stack=r.task.stack;
    if (r.finishing) {
      stack.finishCurrentActivityLocked(r,ActivityStack.FINISH_IMMEDIATELY,false);
    }
 else {
      stack.stopActivityLocked(r);
    }
  }
  for (int i=0; i < NF; i++) {
    r=finishes.get(i);
    activityRemoved|=r.task.stack.destroyActivityLocked(r,true,"String_Node_Str");
  }
  if (!booting) {
    if (startingUsers != null) {
      for (int i=0; i < startingUsers.size(); i++) {
        mService.finishUserSwitch(startingUsers.get(i));
      }
    }
    if (mStartingBackgroundUsers.size() > 0) {
      startingUsers=new ArrayList<UserStartedState>(mStartingBackgroundUsers);
      mStartingBackgroundUsers.clear();
      for (int i=0; i < startingUsers.size(); i++) {
        mService.finishUserBoot(startingUsers.get(i));
      }
    }
  }
  mService.trimApplications();
  if (booting || enableScreen) {
    mService.postFinishBooting(booting,enableScreen);
  }
  if (activityRemoved) {
    resumeTopActivitiesLocked();
  }
  return r;
}