Program: 183599
Project: 183599
Buggy source:
final void activityIdleInternal(IBinder token,boolean fromTimeout){
  if (localLOGV)   Log.v(TAG,"String_Node_Str" + token);
  ArrayList<HistoryRecord> stops=null;
  ArrayList<HistoryRecord> finishes=null;
  ArrayList<HistoryRecord> thumbnails=null;
  int NS=0;
  int NF=0;
  int NT=0;
  IApplicationThread sendThumbnail=null;
  boolean booting=false;
  boolean enableScreen=false;
synchronized (this) {
    if (token != null) {
      mHandler.removeMessages(IDLE_TIMEOUT_MSG,token);
    }
    int index=indexOfTokenLocked(token,false);
    if (index >= 0) {
      HistoryRecord r=(HistoryRecord)mHistory.get(index);
      if (mResumedActivity == r && mLaunchingActivity.isHeld()) {
        mHandler.removeMessages(LAUNCH_TIMEOUT_MSG);
        mLaunchingActivity.release();
      }
      r.idle=true;
      scheduleAppGcsLocked();
      if (r.thumbnailNeeded && r.app != null && r.app.thread != null) {
        sendThumbnail=r.app.thread;
        r.thumbnailNeeded=false;
      }
      if (DEBUG_VISBILITY)       Log.v(TAG,"String_Node_Str" + r);
      ensureActivitiesVisibleLocked(null,0);
      if (!mBooted && !fromTimeout) {
        mBooted=true;
        enableScreen=true;
      }
    }
    stops=processStoppingActivitiesLocked(true);
    NS=stops != null ? stops.size() : 0;
    if ((NF=mFinishingActivities.size()) > 0) {
      finishes=new ArrayList<HistoryRecord>(mFinishingActivities);
      mFinishingActivities.clear();
    }
    if ((NT=mCancelledThumbnails.size()) > 0) {
      thumbnails=new ArrayList<HistoryRecord>(mCancelledThumbnails);
      mCancelledThumbnails.clear();
    }
    booting=mBooting;
    mBooting=false;
  }
  int i;
  if (sendThumbnail != null) {
    try {
      sendThumbnail.requestThumbnail(token);
    }
 catch (    Exception e) {
      Log.w(TAG,"String_Node_Str",e);
      sendPendingThumbnail(null,token,null,null,true);
    }
  }
  for (i=0; i < NS; i++) {
    HistoryRecord r=(HistoryRecord)stops.get(i);
synchronized (this) {
      if (r.finishing) {
        finishCurrentActivityLocked(r,FINISH_IMMEDIATELY);
      }
 else {
        stopActivityLocked(r);
      }
    }
  }
  for (i=0; i < NF; i++) {
    HistoryRecord r=(HistoryRecord)finishes.get(i);
synchronized (this) {
      destroyActivityLocked(r,true);
    }
  }
  for (i=0; i < NT; i++) {
    HistoryRecord r=(HistoryRecord)thumbnails.get(i);
    sendPendingThumbnail(r,null,null,null,true);
  }
  if (booting) {
    final int NP=mProcessesOnHold.size();
    if (NP > 0) {
      ArrayList<ProcessRecord> procs=new ArrayList<ProcessRecord>(mProcessesOnHold);
      for (int ip=0; ip < NP; ip++) {
        this.startProcessLocked(procs.get(ip),"String_Node_Str",null);
      }
    }
    if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
synchronized (this) {
        broadcastIntentLocked(null,null,new Intent(Intent.ACTION_BOOT_COMPLETED,null),null,null,0,null,null,android.Manifest.permission.RECEIVE_BOOT_COMPLETED,false,false,MY_PID,Process.SYSTEM_UID);
      }
    }
  }
  trimApplications();
  if (enableScreen) {
    EventLog.writeEvent(LOG_BOOT_PROGRESS_ENABLE_SCREEN,SystemClock.uptimeMillis());
    enableScreenAfterBoot();
  }
}

Fixed version (ground truth):
final void activityIdleInternal(IBinder token,boolean fromTimeout){
  if (localLOGV)   Log.v(TAG,"String_Node_Str" + token);
  ArrayList<HistoryRecord> stops=null;
  ArrayList<HistoryRecord> finishes=null;
  ArrayList<HistoryRecord> thumbnails=null;
  int NS=0;
  int NF=0;
  int NT=0;
  IApplicationThread sendThumbnail=null;
  boolean booting=false;
  boolean enableScreen=false;
synchronized (this) {
    if (token != null) {
      mHandler.removeMessages(IDLE_TIMEOUT_MSG,token);
    }
    int index=indexOfTokenLocked(token);
    if (index >= 0) {
      HistoryRecord r=(HistoryRecord)mHistory.get(index);
      if (mResumedActivity == r && mLaunchingActivity.isHeld()) {
        mHandler.removeMessages(LAUNCH_TIMEOUT_MSG);
        mLaunchingActivity.release();
      }
      r.idle=true;
      scheduleAppGcsLocked();
      if (r.thumbnailNeeded && r.app != null && r.app.thread != null) {
        sendThumbnail=r.app.thread;
        r.thumbnailNeeded=false;
      }
      if (DEBUG_VISBILITY)       Log.v(TAG,"String_Node_Str" + r);
      ensureActivitiesVisibleLocked(null,0);
      if (!mBooted && !fromTimeout) {
        mBooted=true;
        enableScreen=true;
      }
    }
    stops=processStoppingActivitiesLocked(true);
    NS=stops != null ? stops.size() : 0;
    if ((NF=mFinishingActivities.size()) > 0) {
      finishes=new ArrayList<HistoryRecord>(mFinishingActivities);
      mFinishingActivities.clear();
    }
    if ((NT=mCancelledThumbnails.size()) > 0) {
      thumbnails=new ArrayList<HistoryRecord>(mCancelledThumbnails);
      mCancelledThumbnails.clear();
    }
    booting=mBooting;
    mBooting=false;
  }
  int i;
  if (sendThumbnail != null) {
    try {
      sendThumbnail.requestThumbnail(token);
    }
 catch (    Exception e) {
      Log.w(TAG,"String_Node_Str",e);
      sendPendingThumbnail(null,token,null,null,true);
    }
  }
  for (i=0; i < NS; i++) {
    HistoryRecord r=(HistoryRecord)stops.get(i);
synchronized (this) {
      if (r.finishing) {
        finishCurrentActivityLocked(r,FINISH_IMMEDIATELY);
      }
 else {
        stopActivityLocked(r);
      }
    }
  }
  for (i=0; i < NF; i++) {
    HistoryRecord r=(HistoryRecord)finishes.get(i);
synchronized (this) {
      destroyActivityLocked(r,true);
    }
  }
  for (i=0; i < NT; i++) {
    HistoryRecord r=(HistoryRecord)thumbnails.get(i);
    sendPendingThumbnail(r,null,null,null,true);
  }
  if (booting) {
    final int NP=mProcessesOnHold.size();
    if (NP > 0) {
      ArrayList<ProcessRecord> procs=new ArrayList<ProcessRecord>(mProcessesOnHold);
      for (int ip=0; ip < NP; ip++) {
        this.startProcessLocked(procs.get(ip),"String_Node_Str",null);
      }
    }
    if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
synchronized (this) {
        broadcastIntentLocked(null,null,new Intent(Intent.ACTION_BOOT_COMPLETED,null),null,null,0,null,null,android.Manifest.permission.RECEIVE_BOOT_COMPLETED,false,false,MY_PID,Process.SYSTEM_UID);
      }
    }
  }
  trimApplications();
  if (enableScreen) {
    EventLog.writeEvent(LOG_BOOT_PROGRESS_ENABLE_SCREEN,SystemClock.uptimeMillis());
    enableScreenAfterBoot();
  }
}