Program: 2455
Project: 2455
Buggy source:
final ActivityRecord activityIdleInternalLocked(IBinder token,boolean fromTimeout,Configuration config){
  if (localLOGV)   Slog.v(TAG,"String_Node_Str" + token);
  ActivityRecord res=null;
  ArrayList<ActivityRecord> stops=null;
  ArrayList<ActivityRecord> finishes=null;
  ArrayList<ActivityRecord> thumbnails=null;
  ArrayList<UserStartedState> startingUsers=null;
  int NS=0;
  int NF=0;
  int NT=0;
  IApplicationThread sendThumbnail=null;
  boolean booting=false;
  boolean enableScreen=false;
  boolean activityRemoved=false;
  ActivityRecord r=ActivityRecord.forToken(token);
  if (r != null) {
    mHandler.removeMessages(IDLE_TIMEOUT_MSG,r);
    r.finishLaunchTickingLocked();
  }
  if (isInStackLocked(token) != null) {
    res=r;
    if (fromTimeout) {
      reportActivityLaunchedLocked(fromTimeout,r,-1,-1);
    }
    if (config != null) {
      r.configuration=config;
    }
    if (mResumedActivity == r && mLaunchingActivity.isHeld()) {
      mHandler.removeMessages(LAUNCH_TIMEOUT_MSG);
      mLaunchingActivity.release();
    }
    r.idle=true;
    mService.scheduleAppGcsLocked();
    if (r.thumbnailNeeded && r.app != null && r.app.thread != null) {
      sendThumbnail=r.app.thread;
      r.thumbnailNeeded=false;
    }
    if (DEBUG_VISBILITY)     Slog.v(TAG,"String_Node_Str" + r);
    ensureActivitiesVisibleLocked(null,0);
    if (mStackSupervisor.isMainStack(this)) {
      if (!mService.mBooted) {
        mService.mBooted=true;
        enableScreen=true;
      }
    }
  }
 else   if (fromTimeout) {
    reportActivityLaunchedLocked(fromTimeout,null,-1,-1);
  }
  stops=processStoppingActivitiesLocked(true);
  NS=stops != null ? stops.size() : 0;
  if ((NF=mFinishingActivities.size()) > 0) {
    finishes=new ArrayList<ActivityRecord>(mFinishingActivities);
    mFinishingActivities.clear();
  }
  if ((NT=mCancelledThumbnails.size()) > 0) {
    thumbnails=new ArrayList<ActivityRecord>(mCancelledThumbnails);
    mCancelledThumbnails.clear();
  }
  if (mStackSupervisor.isMainStack(this)) {
    booting=mService.mBooting;
    mService.mBooting=false;
  }
  if (mStartingUsers.size() > 0) {
    startingUsers=new ArrayList<UserStartedState>(mStartingUsers);
    mStartingUsers.clear();
  }
  int i;
  if (sendThumbnail != null) {
    try {
      sendThumbnail.requestThumbnail(token);
    }
 catch (    Exception e) {
      Slog.w(TAG,"String_Node_Str",e);
      mService.sendPendingThumbnail(null,token,null,null,true);
    }
  }
  for (i=0; i < NS; i++) {
    r=stops.get(i);
synchronized (mService) {
      if (r.finishing) {
        finishCurrentActivityLocked(r,FINISH_IMMEDIATELY,false);
      }
 else {
        stopActivityLocked(r);
      }
    }
  }
  for (i=0; i < NF; i++) {
    r=finishes.get(i);
synchronized (mService) {
      activityRemoved=destroyActivityLocked(r,true,false,"String_Node_Str");
    }
  }
  for (i=0; i < NT; i++) {
    r=thumbnails.get(i);
    mService.sendPendingThumbnail(r,null,null,null,true);
  }
  if (booting) {
    mService.finishBooting();
  }
 else   if (startingUsers != null) {
    for (i=0; i < startingUsers.size(); i++) {
      mService.finishUserSwitch(startingUsers.get(i));
    }
  }
  mService.trimApplications();
  if (enableScreen) {
    mService.enableScreenAfterBoot();
  }
  if (activityRemoved) {
    resumeTopActivityLocked(null);
  }
  return res;
}

Fixed version (ground truth):
final ActivityRecord activityIdleInternalLocked(final IBinder token,boolean fromTimeout,Configuration config){
  if (localLOGV)   Slog.v(TAG,"String_Node_Str" + token);
  ActivityRecord res=null;
  ArrayList<ActivityRecord> stops=null;
  ArrayList<ActivityRecord> finishes=null;
  ArrayList<UserStartedState> startingUsers=null;
  int NS=0;
  int NF=0;
  IApplicationThread sendThumbnail=null;
  boolean booting=false;
  boolean enableScreen=false;
  boolean activityRemoved=false;
  ActivityRecord r=ActivityRecord.forToken(token);
  if (r != null) {
    mHandler.removeMessages(IDLE_TIMEOUT_MSG,r);
    r.finishLaunchTickingLocked();
  }
  if (isInStackLocked(token) != null) {
    res=r;
    if (fromTimeout) {
      reportActivityLaunchedLocked(fromTimeout,r,-1,-1);
    }
    if (config != null) {
      r.configuration=config;
    }
    if (mResumedActivity == r && mLaunchingActivity.isHeld()) {
      mHandler.removeMessages(LAUNCH_TIMEOUT_MSG);
      mLaunchingActivity.release();
    }
    r.idle=true;
    if (mStackSupervisor.allResumedActivitiesIdle()) {
      mService.scheduleAppGcsLocked();
    }
    if (r.thumbnailNeeded && r.app != null && r.app.thread != null) {
      sendThumbnail=r.app.thread;
      r.thumbnailNeeded=false;
    }
    if (DEBUG_VISBILITY)     Slog.v(TAG,"String_Node_Str" + r);
    ensureActivitiesVisibleLocked(null,0);
    if (!mService.mBooted && mStackSupervisor.isMainStack(this)) {
      mService.mBooted=true;
      enableScreen=true;
    }
  }
 else   if (fromTimeout) {
    reportActivityLaunchedLocked(fromTimeout,null,-1,-1);
  }
  stops=processStoppingActivitiesLocked(true);
  NS=stops != null ? stops.size() : 0;
  if ((NF=mFinishingActivities.size()) > 0) {
    finishes=new ArrayList<ActivityRecord>(mFinishingActivities);
    mFinishingActivities.clear();
  }
  final ArrayList<ActivityRecord> thumbnails;
  final int NT=mCancelledThumbnails.size();
  if (NT > 0) {
    thumbnails=new ArrayList<ActivityRecord>(mCancelledThumbnails);
    mCancelledThumbnails.clear();
  }
 else {
    thumbnails=null;
  }
  if (mStackSupervisor.isMainStack(this)) {
    booting=mService.mBooting;
    mService.mBooting=false;
  }
  if (mStartingUsers.size() > 0) {
    startingUsers=new ArrayList<UserStartedState>(mStartingUsers);
    mStartingUsers.clear();
  }
  final IApplicationThread thumbnailThread=sendThumbnail;
  mHandler.post(new Runnable(){
    @Override public void run(){
      if (thumbnailThread != null) {
        try {
          thumbnailThread.requestThumbnail(token);
        }
 catch (        Exception e) {
          Slog.w(TAG,"String_Node_Str",e);
          mService.sendPendingThumbnail(null,token,null,null,true);
        }
      }
      for (int i=0; i < NT; i++) {
        ActivityRecord r=thumbnails.get(i);
        mService.sendPendingThumbnail(r,null,null,null,true);
      }
    }
  }
);
  for (int i=0; i < NS; i++) {
    r=stops.get(i);
    if (r.finishing) {
      finishCurrentActivityLocked(r,FINISH_IMMEDIATELY,false);
    }
 else {
      stopActivityLocked(r);
    }
  }
  for (int i=0; i < NF; i++) {
    r=finishes.get(i);
    activityRemoved|=destroyActivityLocked(r,true,false,"String_Node_Str");
  }
  if (booting) {
    mService.finishBooting();
  }
 else   if (startingUsers != null) {
    for (int i=0; i < startingUsers.size(); i++) {
      mService.finishUserSwitch(startingUsers.get(i));
    }
  }
  mService.trimApplications();
  if (enableScreen) {
    mService.enableScreenAfterBoot();
  }
  if (activityRemoved) {
    resumeTopActivityLocked(null);
  }
  return res;
}