nus-yam/ex-repair huggingface dataset:
Program: 2048
Project: 2048
Buggy source:
private View findNextFocusInRelativeDirection(ArrayList<View> focusables,ViewGroup root,View focused,Rect focusedRect,int direction){
  try {
    mSequentialFocusComparator.setRoot(root);
    Collections.sort(focusables,mSequentialFocusComparator);
  }
  finally {
    mSequentialFocusComparator.recycle();
  }
  final int count=focusables.size();
switch (direction) {
case View.FOCUS_FORWARD:
    return getForwardFocusable(root,focused,focusables,count);
case View.FOCUS_BACKWARD:
  return getBackwardFocusable(root,focused,focusables,count);
}
return focusables.get(count - 1);
}

Fixed version (ground truth):
private View findNextFocusInRelativeDirection(ArrayList<View> focusables,ViewGroup root,View focused,Rect focusedRect,int direction){
  try {
    mSequentialFocusComparator.setRoot(root);
    mSequentialFocusComparator.setIsLayoutRtl(root.isLayoutRtl());
    Collections.sort(focusables,mSequentialFocusComparator);
  }
  finally {
    mSequentialFocusComparator.recycle();
  }
  final int count=focusables.size();
switch (direction) {
case View.FOCUS_FORWARD:
    return getNextFocusable(focused,focusables,count);
case View.FOCUS_BACKWARD:
  return getPreviousFocusable(focused,focusables,count);
}
return focusables.get(count - 1);
}
Program: 2049
Project: 2049
Buggy source:
/** 
 * Replace existing canvas while ensuring that the swap has occurred before the previous native canvas is unreferenced.
 */
private void safeCanvasSwap(int nativeCanvas){
  final int oldCanvas=mNativeCanvas;
  mNativeCanvas=nativeCanvas;
  mFinalizer.mNativeCanvas=nativeCanvas;
  copyNativeCanvasState(oldCanvas,mNativeCanvas);
  finalizer(oldCanvas);
}

Fixed version (ground truth):
/** 
 * Replace existing canvas while ensuring that the swap has occurred before the previous native canvas is unreferenced.
 */
private void safeCanvasSwap(int nativeCanvas,boolean copyState){
  final int oldCanvas=mNativeCanvas;
  mNativeCanvas=nativeCanvas;
  mFinalizer.mNativeCanvas=nativeCanvas;
  if (copyState) {
    copyNativeCanvasState(oldCanvas,mNativeCanvas);
  }
  finalizer(oldCanvas);
}
Program: 2050
Project: 2050
Buggy source:
/** 
 * Specify a bitmap for the canvas to draw into. As a side-effect, the canvas' target density is updated to match that of the bitmap while all other state such as the layers, filters, matrix, and clip are reset.
 * @param bitmap Specifies a mutable bitmap for the canvas to draw into.
 * @see #setDensity(int)
 * @see #getDensity()
 */
public void setBitmap(Bitmap bitmap){
  if (isHardwareAccelerated()) {
    throw new RuntimeException("String_Node_Str");
  }
  if (bitmap == null) {
    safeCanvasSwap(initRaster(0));
    mDensity=Bitmap.DENSITY_NONE;
  }
 else {
    if (!bitmap.isMutable()) {
      throw new IllegalStateException();
    }
    throwIfRecycled(bitmap);
    safeCanvasSwap(initRaster(bitmap.ni()));
    mDensity=bitmap.mDensity;
  }
  mBitmap=bitmap;
}

Fixed version (ground truth):
/** 
 * Specify a bitmap for the canvas to draw into. All canvas state such as  layers, filters, and the save/restore stack are reset with the exception of the current matrix and clip stack. Additionally, as a side-effect the canvas' target density is updated to match that of the bitmap.
 * @param bitmap Specifies a mutable bitmap for the canvas to draw into.
 * @see #setDensity(int)
 * @see #getDensity()
 */
public void setBitmap(Bitmap bitmap){
  if (isHardwareAccelerated()) {
    throw new RuntimeException("String_Node_Str");
  }
  if (bitmap == null) {
    safeCanvasSwap(initRaster(0),false);
    mDensity=Bitmap.DENSITY_NONE;
  }
 else {
    if (!bitmap.isMutable()) {
      throw new IllegalStateException();
    }
    throwIfRecycled(bitmap);
    safeCanvasSwap(initRaster(bitmap.ni()),true);
    mDensity=bitmap.mDensity;
  }
  mBitmap=bitmap;
}
Program: 2051
Project: 2051
Buggy source:
public int compare(View first,View second){
  if (first == second) {
    return 0;
  }
  getRect(first,mFirstRect);
  getRect(second,mSecondRect);
  if (mFirstRect.top < mSecondRect.top) {
    return -1;
  }
 else   if (mFirstRect.top > mSecondRect.top) {
    return 1;
  }
 else   if (mFirstRect.left < mSecondRect.left) {
    return -1;
  }
 else   if (mFirstRect.left > mSecondRect.left) {
    return 1;
  }
 else   if (mFirstRect.bottom < mSecondRect.bottom) {
    return -1;
  }
 else   if (mFirstRect.bottom > mSecondRect.bottom) {
    return 1;
  }
 else   if (mFirstRect.right < mSecondRect.right) {
    return -1;
  }
 else   if (mFirstRect.right > mSecondRect.right) {
    return 1;
  }
 else {
    return 0;
  }
}

Fixed version (ground truth):
public int compare(View first,View second){
  if (first == second) {
    return 0;
  }
  getRect(first,mFirstRect);
  getRect(second,mSecondRect);
  if (mFirstRect.top < mSecondRect.top) {
    return -1;
  }
 else   if (mFirstRect.top > mSecondRect.top) {
    return 1;
  }
 else   if (mFirstRect.left < mSecondRect.left) {
    return mIsLayoutRtl ? 1 : -1;
  }
 else   if (mFirstRect.left > mSecondRect.left) {
    return mIsLayoutRtl ? -1 : 1;
  }
 else   if (mFirstRect.bottom < mSecondRect.bottom) {
    return -1;
  }
 else   if (mFirstRect.bottom > mSecondRect.bottom) {
    return 1;
  }
 else   if (mFirstRect.right < mSecondRect.right) {
    return mIsLayoutRtl ? 1 : -1;
  }
 else   if (mFirstRect.right > mSecondRect.right) {
    return mIsLayoutRtl ? -1 : 1;
  }
 else {
    return 0;
  }
}
Program: 2052
Project: 2052
Buggy source:
private View findNextFocusInRelativeDirection(ArrayList<View> focusables,ViewGroup root,View focused,Rect focusedRect,int direction){
  try {
    mSequentialFocusComparator.setRoot(root);
    Collections.sort(focusables,mSequentialFocusComparator);
  }
  finally {
    mSequentialFocusComparator.recycle();
  }
  final int count=focusables.size();
switch (direction) {
case View.FOCUS_FORWARD:
    return getForwardFocusable(root,focused,focusables,count);
case View.FOCUS_BACKWARD:
  return getBackwardFocusable(root,focused,focusables,count);
}
return focusables.get(count - 1);
}

Fixed version (ground truth):
private View findNextFocusInRelativeDirection(ArrayList<View> focusables,ViewGroup root,View focused,Rect focusedRect,int direction){
  try {
    mSequentialFocusComparator.setRoot(root);
    mSequentialFocusComparator.setIsLayoutRtl(root.isLayoutRtl());
    Collections.sort(focusables,mSequentialFocusComparator);
  }
  finally {
    mSequentialFocusComparator.recycle();
  }
  final int count=focusables.size();
switch (direction) {
case View.FOCUS_FORWARD:
    return getNextFocusable(focused,focusables,count);
case View.FOCUS_BACKWARD:
  return getPreviousFocusable(focused,focusables,count);
}
return focusables.get(count - 1);
}
Program: 2054
Project: 2054
Buggy source:
private void animateInIconOfFirstTask(){
  if (mItemToAnimateInWhenWindowAnimationIsFinished != null && !mRecentTasksLoader.isFirstScreenful()) {
    int timeSinceWindowAnimation=(int)(System.currentTimeMillis() - mWindowAnimationStartTime);
    final int minStartDelay=125;
    final int startDelay=Math.max(0,Math.min(minStartDelay - timeSinceWindowAnimation,minStartDelay));
    final int duration=250;
    final ViewHolder holder=mItemToAnimateInWhenWindowAnimationIsFinished;
    final TimeInterpolator cubic=new DecelerateInterpolator(1.5f);
    FirstFrameAnimatorHelper.initializeDrawListener(holder.iconView);
    for (    View v : new View[]{holder.iconView,holder.labelView,holder.calloutLine}) {
      if (v != null) {
        ViewPropertyAnimator vpa=v.animate().translationX(0).translationY(0).alpha(1f).setStartDelay(startDelay).setDuration(duration).setInterpolator(cubic);
        FirstFrameAnimatorHelper h=new FirstFrameAnimatorHelper(vpa,v);
      }
    }
    mItemToAnimateInWhenWindowAnimationIsFinished=null;
    mAnimateIconOfFirstTask=false;
  }
}

Fixed version (ground truth):
private void animateInIconOfFirstTask(){
  if (mItemToAnimateInWhenWindowAnimationIsFinished != null && !mRecentTasksLoader.isFirstScreenful()) {
    int timeSinceWindowAnimation=(int)(System.currentTimeMillis() - mWindowAnimationStartTime);
    final int minStartDelay=150;
    final int startDelay=Math.max(0,Math.min(minStartDelay - timeSinceWindowAnimation,minStartDelay));
    final int duration=250;
    final ViewHolder holder=mItemToAnimateInWhenWindowAnimationIsFinished;
    final TimeInterpolator cubic=new DecelerateInterpolator(1.5f);
    FirstFrameAnimatorHelper.initializeDrawListener(holder.iconView);
    for (    View v : new View[]{holder.iconView,holder.labelView,holder.calloutLine}) {
      if (v != null) {
        ViewPropertyAnimator vpa=v.animate().translationX(0).translationY(0).alpha(1f).setStartDelay(startDelay).setDuration(duration).setInterpolator(cubic);
        FirstFrameAnimatorHelper h=new FirstFrameAnimatorHelper(vpa,v);
      }
    }
    mItemToAnimateInWhenWindowAnimationIsFinished=null;
    mAnimateIconOfFirstTask=false;
  }
}
Program: 2058
Project: 2058
Buggy source:
public int compare(View first,View second){
  if (first == second) {
    return 0;
  }
  getRect(first,mFirstRect);
  getRect(second,mSecondRect);
  if (mFirstRect.top < mSecondRect.top) {
    return -1;
  }
 else   if (mFirstRect.top > mSecondRect.top) {
    return 1;
  }
 else   if (mFirstRect.left < mSecondRect.left) {
    return -1;
  }
 else   if (mFirstRect.left > mSecondRect.left) {
    return 1;
  }
 else   if (mFirstRect.bottom < mSecondRect.bottom) {
    return -1;
  }
 else   if (mFirstRect.bottom > mSecondRect.bottom) {
    return 1;
  }
 else   if (mFirstRect.right < mSecondRect.right) {
    return -1;
  }
 else   if (mFirstRect.right > mSecondRect.right) {
    return 1;
  }
 else {
    return 0;
  }
}

Fixed version (ground truth):
public int compare(View first,View second){
  if (first == second) {
    return 0;
  }
  getRect(first,mFirstRect);
  getRect(second,mSecondRect);
  if (mFirstRect.top < mSecondRect.top) {
    return -1;
  }
 else   if (mFirstRect.top > mSecondRect.top) {
    return 1;
  }
 else   if (mFirstRect.left < mSecondRect.left) {
    return mIsLayoutRtl ? 1 : -1;
  }
 else   if (mFirstRect.left > mSecondRect.left) {
    return mIsLayoutRtl ? -1 : 1;
  }
 else   if (mFirstRect.bottom < mSecondRect.bottom) {
    return -1;
  }
 else   if (mFirstRect.bottom > mSecondRect.bottom) {
    return 1;
  }
 else   if (mFirstRect.right < mSecondRect.right) {
    return mIsLayoutRtl ? 1 : -1;
  }
 else   if (mFirstRect.right > mSecondRect.right) {
    return mIsLayoutRtl ? -1 : 1;
  }
 else {
    return 0;
  }
}
Program: 2059
Project: 2059
Buggy source:
private View findNextFocusInRelativeDirection(ArrayList<View> focusables,ViewGroup root,View focused,Rect focusedRect,int direction){
  try {
    mSequentialFocusComparator.setRoot(root);
    Collections.sort(focusables,mSequentialFocusComparator);
  }
  finally {
    mSequentialFocusComparator.recycle();
  }
  final int count=focusables.size();
switch (direction) {
case View.FOCUS_FORWARD:
    return getForwardFocusable(root,focused,focusables,count);
case View.FOCUS_BACKWARD:
  return getBackwardFocusable(root,focused,focusables,count);
}
return focusables.get(count - 1);
}

Fixed version (ground truth):
private View findNextFocusInRelativeDirection(ArrayList<View> focusables,ViewGroup root,View focused,Rect focusedRect,int direction){
  try {
    mSequentialFocusComparator.setRoot(root);
    mSequentialFocusComparator.setIsLayoutRtl(root.isLayoutRtl());
    Collections.sort(focusables,mSequentialFocusComparator);
  }
  finally {
    mSequentialFocusComparator.recycle();
  }
  final int count=focusables.size();
switch (direction) {
case View.FOCUS_FORWARD:
    return getNextFocusable(focused,focusables,count);
case View.FOCUS_BACKWARD:
  return getPreviousFocusable(focused,focusables,count);
}
return focusables.get(count - 1);
}
Program: 2060
Project: 2060
Buggy source:
private void cancelLoadingThumbnailsAndIcons(){
  if (mTaskLoader != null) {
    mTaskLoader.cancel(false);
    mTaskLoader=null;
  }
  if (mThumbnailLoader != null) {
    mThumbnailLoader.cancel(false);
    mThumbnailLoader=null;
  }
  mLoadedTasks=null;
  if (mRecentsPanel != null) {
    mRecentsPanel.onTaskLoadingCancelled();
  }
  mFirstScreenful=false;
  mState=State.CANCELLED;
}

Fixed version (ground truth):
private void cancelLoadingThumbnailsAndIcons(){
  if (mRecentsPanel != null && mRecentsPanel.isShowing()) {
    return;
  }
  if (mTaskLoader != null) {
    mTaskLoader.cancel(false);
    mTaskLoader=null;
  }
  if (mThumbnailLoader != null) {
    mThumbnailLoader.cancel(false);
    mThumbnailLoader=null;
  }
  mLoadedTasks=null;
  if (mRecentsPanel != null) {
    mRecentsPanel.onTaskLoadingCancelled();
  }
  mFirstScreenful=false;
  mState=State.CANCELLED;
}
Program: 2061
Project: 2061
Buggy source:
@Override public void onStart(){
  if (forceOpaqueBackground(this)) {
    updateWallpaperVisibility(false);
  }
 else {
    updateWallpaperVisibility(true);
  }
  mShowing=true;
  if (mRecentsPanel != null) {
    mRecentsPanel.refreshViews();
  }
  super.onStart();
}

Fixed version (ground truth):
@Override public void onStart(){
  if (forceOpaqueBackground(this)) {
    updateWallpaperVisibility(false);
  }
 else {
    updateWallpaperVisibility(true);
  }
  mShowing=true;
  if (mRecentsPanel != null) {
    mRecentsPanel.refreshRecentTasksList();
    mRecentsPanel.refreshViews();
  }
  super.onStart();
}
Program: 2065
Project: 2065
Buggy source:
private void cancelLoadingThumbnailsAndIcons(){
  if (mTaskLoader != null) {
    mTaskLoader.cancel(false);
    mTaskLoader=null;
  }
  if (mThumbnailLoader != null) {
    mThumbnailLoader.cancel(false);
    mThumbnailLoader=null;
  }
  mLoadedTasks=null;
  if (mRecentsPanel != null) {
    mRecentsPanel.onTaskLoadingCancelled();
  }
  mFirstScreenful=false;
  mState=State.CANCELLED;
}

Fixed version (ground truth):
private void cancelLoadingThumbnailsAndIcons(){
  if (mRecentsPanel != null && mRecentsPanel.isShowing()) {
    return;
  }
  if (mTaskLoader != null) {
    mTaskLoader.cancel(false);
    mTaskLoader=null;
  }
  if (mThumbnailLoader != null) {
    mThumbnailLoader.cancel(false);
    mThumbnailLoader=null;
  }
  mLoadedTasks=null;
  if (mRecentsPanel != null) {
    mRecentsPanel.onTaskLoadingCancelled();
  }
  mFirstScreenful=false;
  mState=State.CANCELLED;
}
Program: 2066
Project: 2066
Buggy source:
@Override public void onStart(){
  if (forceOpaqueBackground(this)) {
    updateWallpaperVisibility(false);
  }
 else {
    updateWallpaperVisibility(true);
  }
  mShowing=true;
  if (mRecentsPanel != null) {
    mRecentsPanel.refreshViews();
  }
  super.onStart();
}

Fixed version (ground truth):
@Override public void onStart(){
  if (forceOpaqueBackground(this)) {
    updateWallpaperVisibility(false);
  }
 else {
    updateWallpaperVisibility(true);
  }
  mShowing=true;
  if (mRecentsPanel != null) {
    mRecentsPanel.refreshRecentTasksList();
    mRecentsPanel.refreshViews();
  }
  super.onStart();
}
Program: 2067
Project: 2067
Buggy source:
private void cancelLoadingThumbnailsAndIcons(){
  if (mTaskLoader != null) {
    mTaskLoader.cancel(false);
    mTaskLoader=null;
  }
  if (mThumbnailLoader != null) {
    mThumbnailLoader.cancel(false);
    mThumbnailLoader=null;
  }
  mLoadedTasks=null;
  if (mRecentsPanel != null) {
    mRecentsPanel.onTaskLoadingCancelled();
  }
  mFirstScreenful=false;
  mState=State.CANCELLED;
}

Fixed version (ground truth):
private void cancelLoadingThumbnailsAndIcons(){
  if (mRecentsPanel != null && mRecentsPanel.isShowing()) {
    return;
  }
  if (mTaskLoader != null) {
    mTaskLoader.cancel(false);
    mTaskLoader=null;
  }
  if (mThumbnailLoader != null) {
    mThumbnailLoader.cancel(false);
    mThumbnailLoader=null;
  }
  mLoadedTasks=null;
  if (mRecentsPanel != null) {
    mRecentsPanel.onTaskLoadingCancelled();
  }
  mFirstScreenful=false;
  mState=State.CANCELLED;
}
Program: 2068
Project: 2068
Buggy source:
@Override public void onStart(){
  if (forceOpaqueBackground(this)) {
    updateWallpaperVisibility(false);
  }
 else {
    updateWallpaperVisibility(true);
  }
  mShowing=true;
  if (mRecentsPanel != null) {
    mRecentsPanel.refreshViews();
  }
  super.onStart();
}

Fixed version (ground truth):
@Override public void onStart(){
  if (forceOpaqueBackground(this)) {
    updateWallpaperVisibility(false);
  }
 else {
    updateWallpaperVisibility(true);
  }
  mShowing=true;
  if (mRecentsPanel != null) {
    mRecentsPanel.refreshRecentTasksList();
    mRecentsPanel.refreshViews();
  }
  super.onStart();
}
Program: 2071
Project: 2071
Buggy source:
@Override public void setRequestedOrientation(IBinder token,int requestedOrientation){
synchronized (this) {
    ActivityRecord r=ActivityRecord.isInStackLocked(token);
    if (r == null) {
      return;
    }
    final long origId=Binder.clearCallingIdentity();
    mWindowManager.setAppOrientation(r.appToken,requestedOrientation);
    Configuration config=mWindowManager.updateOrientationFromAppTokens(mConfiguration,r.mayFreezeScreenLocked(r.app) ? r.appToken : null);
    if (config != null) {
      r.frozenBeforeDestroy=true;
      if (!updateConfigurationLocked(config,r,false,false)) {
        r.task.stack.resumeTopActivityLocked(null);
      }
    }
    Binder.restoreCallingIdentity(origId);
  }
}

Fixed version (ground truth):
@Override public void setRequestedOrientation(IBinder token,int requestedOrientation){
synchronized (this) {
    ActivityRecord r=ActivityRecord.isInStackLocked(token);
    if (r == null) {
      return;
    }
    final long origId=Binder.clearCallingIdentity();
    mWindowManager.setAppOrientation(r.appToken,requestedOrientation);
    Configuration config=mWindowManager.updateOrientationFromAppTokens(mConfiguration,r.mayFreezeScreenLocked(r.app) ? r.appToken : null);
    if (config != null) {
      r.frozenBeforeDestroy=true;
      if (!updateConfigurationLocked(config,r,false,false)) {
        mStackSupervisor.resumeTopActivitiesLocked();
      }
    }
    Binder.restoreCallingIdentity(origId);
  }
}
Program: 2072
Project: 2072
Buggy source:
final void activityStoppedLocked(ActivityRecord r,Bundle icicle,Bitmap thumbnail,CharSequence description){
  if (r.state != ActivityState.STOPPING) {
    Slog.i(TAG,"String_Node_Str" + r);
    mHandler.removeMessages(STOP_TIMEOUT_MSG,r);
    return;
  }
  if (DEBUG_SAVED_STATE)   Slog.i(TAG,"String_Node_Str" + r + "String_Node_Str"+ icicle);
  if (icicle != null) {
    r.icicle=icicle;
    r.haveState=true;
    r.launchCount=0;
    r.updateThumbnail(thumbnail,description);
  }
  if (!r.stopped) {
    if (DEBUG_STATES)     Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str");
    mHandler.removeMessages(STOP_TIMEOUT_MSG,r);
    r.stopped=true;
    r.state=ActivityState.STOPPED;
    if (r.finishing) {
      r.clearOptionsLocked();
    }
 else {
      if (r.configDestroy) {
        destroyActivityLocked(r,true,false,"String_Node_Str");
        mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
      }
 else {
        ProcessRecord fgApp=null;
        if (mResumedActivity != null) {
          fgApp=mResumedActivity.app;
        }
 else         if (mPausingActivity != null) {
          fgApp=mPausingActivity.app;
        }
        if (r.app != null && fgApp != null && r.app != fgApp && r.lastVisibleTime > mService.mPreviousProcessVisibleTime && r.app != mService.mHomeProcess) {
          mService.mPreviousProcess=r.app;
          mService.mPreviousProcessVisibleTime=r.lastVisibleTime;
        }
      }
    }
  }
}

Fixed version (ground truth):
final void activityStoppedLocked(ActivityRecord r,Bundle icicle,Bitmap thumbnail,CharSequence description){
  if (r.state != ActivityState.STOPPING) {
    Slog.i(TAG,"String_Node_Str" + r);
    mHandler.removeMessages(STOP_TIMEOUT_MSG,r);
    return;
  }
  if (DEBUG_SAVED_STATE)   Slog.i(TAG,"String_Node_Str" + r + "String_Node_Str"+ icicle);
  if (icicle != null) {
    r.icicle=icicle;
    r.haveState=true;
    r.launchCount=0;
    r.updateThumbnail(thumbnail,description);
  }
  if (!r.stopped) {
    if (DEBUG_STATES)     Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str");
    mHandler.removeMessages(STOP_TIMEOUT_MSG,r);
    r.stopped=true;
    r.state=ActivityState.STOPPED;
    if (r.finishing) {
      r.clearOptionsLocked();
    }
 else {
      if (r.configDestroy) {
        destroyActivityLocked(r,true,false,"String_Node_Str");
        mStackSupervisor.resumeTopActivitiesLocked();
      }
 else {
        ProcessRecord fgApp=null;
        if (mResumedActivity != null) {
          fgApp=mResumedActivity.app;
        }
 else         if (mPausingActivity != null) {
          fgApp=mPausingActivity.app;
        }
        if (r.app != null && fgApp != null && r.app != fgApp && r.lastVisibleTime > mService.mPreviousProcessVisibleTime && r.app != mService.mHomeProcess) {
          mService.mPreviousProcess=r.app;
          mService.mPreviousProcessVisibleTime=r.lastVisibleTime;
        }
      }
    }
  }
}
Program: 2073
Project: 2073
Buggy source:
final void destroyActivitiesLocked(ProcessRecord owner,boolean oomAdj,String reason){
  boolean lastIsOpaque=false;
  boolean activityRemoved=false;
  for (int taskNdx=mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
    final ArrayList<ActivityRecord> activities=mTaskHistory.get(taskNdx).mActivities;
    for (int activityNdx=activities.size() - 1; activityNdx >= 0; --activityNdx) {
      final ActivityRecord r=activities.get(activityNdx);
      if (r.finishing) {
        continue;
      }
      if (r.fullscreen) {
        lastIsOpaque=true;
      }
      if (owner != null && r.app != owner) {
        continue;
      }
      if (!lastIsOpaque) {
        continue;
      }
      if (r.app != null && r != mResumedActivity && r != mPausingActivity && r.haveState && !r.visible && r.stopped && r.state != ActivityState.DESTROYING && r.state != ActivityState.DESTROYED) {
        if (DEBUG_SWITCH)         Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.state+ "String_Node_Str"+ mResumedActivity+ "String_Node_Str"+ mPausingActivity);
        if (destroyActivityLocked(r,true,oomAdj,reason)) {
          activityRemoved=true;
        }
      }
    }
  }
  if (activityRemoved) {
    mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
  }
}

Fixed version (ground truth):
final void destroyActivitiesLocked(ProcessRecord owner,boolean oomAdj,String reason){
  boolean lastIsOpaque=false;
  boolean activityRemoved=false;
  for (int taskNdx=mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
    final ArrayList<ActivityRecord> activities=mTaskHistory.get(taskNdx).mActivities;
    for (int activityNdx=activities.size() - 1; activityNdx >= 0; --activityNdx) {
      final ActivityRecord r=activities.get(activityNdx);
      if (r.finishing) {
        continue;
      }
      if (r.fullscreen) {
        lastIsOpaque=true;
      }
      if (owner != null && r.app != owner) {
        continue;
      }
      if (!lastIsOpaque) {
        continue;
      }
      if (r.app != null && r != mResumedActivity && r != mPausingActivity && r.haveState && !r.visible && r.stopped && r.state != ActivityState.DESTROYING && r.state != ActivityState.DESTROYED) {
        if (DEBUG_SWITCH)         Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.state+ "String_Node_Str"+ mResumedActivity+ "String_Node_Str"+ mPausingActivity);
        if (destroyActivityLocked(r,true,oomAdj,reason)) {
          activityRemoved=true;
        }
      }
    }
  }
  if (activityRemoved) {
    mStackSupervisor.resumeTopActivitiesLocked();
  }
}
Program: 2074
Project: 2074
Buggy source:
final ActivityRecord finishCurrentActivityLocked(ActivityRecord r,int mode,boolean oomAdj){
  if (mode == FINISH_AFTER_VISIBLE && r.nowVisible) {
    if (!mStackSupervisor.mStoppingActivities.contains(r)) {
      mStackSupervisor.mStoppingActivities.add(r);
      if (mStackSupervisor.mStoppingActivities.size() > 3 || r.frontOfTask && mTaskHistory.size() <= 1) {
        mStackSupervisor.scheduleIdleLocked();
      }
 else {
        checkReadyForSleepLocked();
      }
    }
    if (DEBUG_STATES)     Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str");
    r.state=ActivityState.STOPPING;
    if (oomAdj) {
      mService.updateOomAdjLocked();
    }
    return r;
  }
  mStackSupervisor.mStoppingActivities.remove(r);
  mGoingToSleepActivities.remove(r);
  mStackSupervisor.mWaitingVisibleActivities.remove(r);
  if (mResumedActivity == r) {
    mResumedActivity=null;
  }
  final ActivityState prevState=r.state;
  if (DEBUG_STATES)   Slog.v(TAG,"String_Node_Str" + r);
  r.state=ActivityState.FINISHING;
  if (mode == FINISH_IMMEDIATELY || prevState == ActivityState.STOPPED || prevState == ActivityState.INITIALIZING) {
    boolean activityRemoved=destroyActivityLocked(r,true,oomAdj,"String_Node_Str");
    if (activityRemoved) {
      mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
    }
    return activityRemoved ? null : r;
  }
  if (localLOGV)   Slog.v(TAG,"String_Node_Str" + r);
  mStackSupervisor.mFinishingActivities.add(r);
  mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
  return r;
}

Fixed version (ground truth):
final ActivityRecord finishCurrentActivityLocked(ActivityRecord r,int mode,boolean oomAdj){
  if (mode == FINISH_AFTER_VISIBLE && r.nowVisible) {
    if (!mStackSupervisor.mStoppingActivities.contains(r)) {
      mStackSupervisor.mStoppingActivities.add(r);
      if (mStackSupervisor.mStoppingActivities.size() > 3 || r.frontOfTask && mTaskHistory.size() <= 1) {
        mStackSupervisor.scheduleIdleLocked();
      }
 else {
        checkReadyForSleepLocked();
      }
    }
    if (DEBUG_STATES)     Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str");
    r.state=ActivityState.STOPPING;
    if (oomAdj) {
      mService.updateOomAdjLocked();
    }
    return r;
  }
  mStackSupervisor.mStoppingActivities.remove(r);
  mGoingToSleepActivities.remove(r);
  mStackSupervisor.mWaitingVisibleActivities.remove(r);
  if (mResumedActivity == r) {
    mResumedActivity=null;
  }
  final ActivityState prevState=r.state;
  if (DEBUG_STATES)   Slog.v(TAG,"String_Node_Str" + r);
  r.state=ActivityState.FINISHING;
  if (mode == FINISH_IMMEDIATELY || prevState == ActivityState.STOPPED || prevState == ActivityState.INITIALIZING) {
    boolean activityRemoved=destroyActivityLocked(r,true,oomAdj,"String_Node_Str");
    if (activityRemoved) {
      mStackSupervisor.resumeTopActivitiesLocked();
    }
    return activityRemoved ? null : r;
  }
  if (localLOGV)   Slog.v(TAG,"String_Node_Str" + r);
  mStackSupervisor.mFinishingActivities.add(r);
  mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
  return r;
}
Program: 2075
Project: 2075
Buggy source:
final void activityDestroyedLocked(IBinder token){
  final long origId=Binder.clearCallingIdentity();
  try {
    ActivityRecord r=ActivityRecord.forToken(token);
    if (r != null) {
      mHandler.removeMessages(DESTROY_TIMEOUT_MSG,r);
    }
    if (isInStackLocked(token) != null) {
      if (r.state == ActivityState.DESTROYING) {
        cleanUpActivityLocked(r,true,false);
        removeActivityFromHistoryLocked(r);
      }
    }
    mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
  }
  finally {
    Binder.restoreCallingIdentity(origId);
  }
}

Fixed version (ground truth):
final void activityDestroyedLocked(IBinder token){
  final long origId=Binder.clearCallingIdentity();
  try {
    ActivityRecord r=ActivityRecord.forToken(token);
    if (r != null) {
      mHandler.removeMessages(DESTROY_TIMEOUT_MSG,r);
    }
    if (isInStackLocked(token) != null) {
      if (r.state == ActivityState.DESTROYING) {
        cleanUpActivityLocked(r,true,false);
        removeActivityFromHistoryLocked(r);
      }
    }
    mStackSupervisor.resumeTopActivitiesLocked();
  }
  finally {
    Binder.restoreCallingIdentity(origId);
  }
}
Program: 2076
Project: 2076
Buggy source:
void handleAppDiedLocked(ProcessRecord app,boolean restarting){
  if (!containsApp(app)) {
    return;
  }
  if (mPausingActivity != null && mPausingActivity.app == app) {
    if (DEBUG_PAUSE || DEBUG_CLEANUP)     Slog.v(TAG,"String_Node_Str" + mPausingActivity);
    mPausingActivity=null;
  }
  if (mLastPausedActivity != null && mLastPausedActivity.app == app) {
    mLastPausedActivity=null;
  }
  boolean hasVisibleActivities=removeHistoryRecordsForAppLocked(app);
  if (!restarting) {
    ActivityStack stack=mStackSupervisor.getFocusedStack();
    if (stack == null) {
      mStackSupervisor.resumeHomeActivity(null);
    }
 else     if (!stack.resumeTopActivityLocked(null)) {
      if (hasVisibleActivities) {
        ensureActivitiesVisibleLocked(null,0);
      }
    }
  }
}

Fixed version (ground truth):
void handleAppDiedLocked(ProcessRecord app,boolean restarting){
  if (!containsApp(app)) {
    return;
  }
  if (mPausingActivity != null && mPausingActivity.app == app) {
    if (DEBUG_PAUSE || DEBUG_CLEANUP)     Slog.v(TAG,"String_Node_Str" + mPausingActivity);
    mPausingActivity=null;
  }
  if (mLastPausedActivity != null && mLastPausedActivity.app == app) {
    mLastPausedActivity=null;
  }
  boolean hasVisibleActivities=removeHistoryRecordsForAppLocked(app);
  if (!restarting) {
    ActivityStack stack=mStackSupervisor.getFocusedStack();
    if (stack == null) {
      mStackSupervisor.resumeHomeActivity(null);
    }
 else     if (!mStackSupervisor.resumeTopActivitiesLocked(stack,null,null)) {
      if (hasVisibleActivities) {
        ensureActivitiesVisibleLocked(null,0);
      }
    }
  }
}
Program: 2079
Project: 2079
Buggy source:
final void moveTaskToFrontLocked(TaskRecord tr,ActivityRecord reason,Bundle options){
  if (DEBUG_SWITCH)   Slog.v(TAG,"String_Node_Str" + tr);
  final int numTasks=mTaskHistory.size();
  final int index=mTaskHistory.indexOf(tr);
  if (numTasks == 0 || index < 0 || index == numTasks - 1) {
    if (reason != null && (reason.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
      ActivityOptions.abort(options);
    }
 else {
      updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT,options);
    }
    return;
  }
  mTaskHistory.remove(tr);
  mTaskHistory.add(tr);
  if (DEBUG_TRANSITION)   Slog.v(TAG,"String_Node_Str" + tr);
  if (reason != null && (reason.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
    mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE,false);
    ActivityRecord r=topRunningActivityLocked(null);
    if (r != null) {
      mNoAnimActivities.add(r);
    }
    ActivityOptions.abort(options);
  }
 else {
    updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT,options);
  }
  mWindowManager.moveTaskToTop(tr.taskId);
  mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
  EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT,tr.userId,tr.taskId);
  if (VALIDATE_TOKENS) {
    validateAppTokensLocked();
  }
}

Fixed version (ground truth):
final void moveTaskToFrontLocked(TaskRecord tr,ActivityRecord reason,Bundle options){
  if (DEBUG_SWITCH)   Slog.v(TAG,"String_Node_Str" + tr);
  final int numTasks=mTaskHistory.size();
  final int index=mTaskHistory.indexOf(tr);
  if (numTasks == 0 || index < 0 || index == numTasks - 1) {
    if (reason != null && (reason.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
      ActivityOptions.abort(options);
    }
 else {
      updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT,options);
    }
    return;
  }
  mTaskHistory.remove(tr);
  mTaskHistory.add(tr);
  if (DEBUG_TRANSITION)   Slog.v(TAG,"String_Node_Str" + tr);
  if (reason != null && (reason.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
    mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE,false);
    ActivityRecord r=topRunningActivityLocked(null);
    if (r != null) {
      mNoAnimActivities.add(r);
    }
    ActivityOptions.abort(options);
  }
 else {
    updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT,options);
  }
  mWindowManager.moveTaskToTop(tr.taskId);
  mStackSupervisor.resumeTopActivitiesLocked();
  EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT,tr.userId,tr.taskId);
  if (VALIDATE_TOKENS) {
    validateAppTokensLocked();
  }
}
Program: 2084
Project: 2084
Buggy source:
boolean resumeHomeActivity(ActivityRecord prev){
  moveHomeStack(true);
  if (prev != null) {
    prev.mLaunchHomeTaskNext=false;
  }
  if (mHomeStack.topRunningActivityLocked(null) != null) {
    return mHomeStack.resumeTopActivityLocked(prev);
  }
  return mService.startHomeActivityLocked(mCurrentUser);
}

Fixed version (ground truth):
boolean resumeHomeActivity(ActivityRecord prev){
  moveHomeStack(true);
  if (prev != null) {
    prev.mLaunchHomeTaskNext=false;
  }
  if (mHomeStack.topRunningActivityLocked(null) != null) {
    return resumeTopActivitiesLocked(mHomeStack,prev,null);
  }
  return mService.startHomeActivityLocked(mCurrentUser);
}
Program: 2085
Project: 2085
Buggy source:
void comeOutOfSleepIfNeededLocked(){
  for (int stackNdx=mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
    final ActivityStack stack=mStacks.get(stackNdx);
    stack.awakeFromSleepingLocked();
    if (isFrontStack(stack)) {
      stack.resumeTopActivityLocked(null);
    }
  }
}

Fixed version (ground truth):
void comeOutOfSleepIfNeededLocked(){
  for (int stackNdx=mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
    final ActivityStack stack=mStacks.get(stackNdx);
    stack.awakeFromSleepingLocked();
    if (isFrontStack(stack)) {
      resumeTopActivitiesLocked();
    }
  }
}
Program: 2087
Project: 2087
Buggy source:
void resumeTopActivitiesLocked(){
  for (int stackNdx=mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
    final ActivityStack stack=mStacks.get(stackNdx);
    if (isFrontStack(stack)) {
      stack.resumeTopActivityLocked(null);
    }
  }
}

Fixed version (ground truth):
boolean resumeTopActivitiesLocked(ActivityStack targetStack,ActivityRecord target,Bundle targetOptions){
  if (targetStack == null) {
    targetStack=getFocusedStack();
  }
  boolean result=false;
  for (int stackNdx=mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
    final ActivityStack stack=mStacks.get(stackNdx);
    if (isFrontStack(stack)) {
      if (stack == targetStack) {
        result=stack.resumeTopActivityLocked(target,targetOptions);
      }
 else {
        stack.resumeTopActivityLocked(null);
      }
    }
  }
  return result;
}
Program: 2088
Project: 2088
Buggy source:
final void scheduleIdleLocked(){
  mHandler.obtainMessage(IDLE_NOW_MSG).sendToTarget();
}

Fixed version (ground truth):
final void scheduleIdleLocked(){
  mHandler.sendEmptyMessage(IDLE_NOW_MSG);
}
Program: 2089
Project: 2089
Buggy source:
@Override public void handleMessage(Message msg){
switch (msg.what) {
case IDLE_TIMEOUT_MSG:
{
      if (mService.mDidDexOpt) {
        mService.mDidDexOpt=false;
        Message nmsg=mHandler.obtainMessage(IDLE_TIMEOUT_MSG);
        nmsg.obj=msg.obj;
        mHandler.sendMessageDelayed(nmsg,IDLE_TIMEOUT);
        return;
      }
      activityIdleInternal((ActivityRecord)msg.obj);
    }
  break;
case IDLE_NOW_MSG:
{
  activityIdleInternal((ActivityRecord)msg.obj);
}
break;
}
}

Fixed version (ground truth):
@Override public void handleMessage(Message msg){
switch (msg.what) {
case IDLE_TIMEOUT_MSG:
{
      if (mService.mDidDexOpt) {
        mService.mDidDexOpt=false;
        Message nmsg=mHandler.obtainMessage(IDLE_TIMEOUT_MSG);
        nmsg.obj=msg.obj;
        mHandler.sendMessageDelayed(nmsg,IDLE_TIMEOUT);
        return;
      }
      activityIdleInternal((ActivityRecord)msg.obj);
    }
  break;
case IDLE_NOW_MSG:
{
  activityIdleInternal((ActivityRecord)msg.obj);
}
break;
case RESUME_TOP_ACTIVITY_MSG:
{
synchronized (mService) {
resumeTopActivitiesLocked();
}
}
break;
}
}
Program: 2090
Project: 2090
Buggy source:
void moveTaskToStack(int taskId,int stackId,boolean toTop){
  final ActivityStack stack=getStack(stackId);
  if (stack == null) {
    Slog.w(TAG,"String_Node_Str" + stackId);
    return;
  }
  stack.moveTask(taskId,toTop);
  stack.resumeTopActivityLocked(null);
}

Fixed version (ground truth):
void moveTaskToStack(int taskId,int stackId,boolean toTop){
  final ActivityStack stack=getStack(stackId);
  if (stack == null) {
    Slog.w(TAG,"String_Node_Str" + stackId);
    return;
  }
  stack.moveTask(taskId,toTop);
  resumeTopActivitiesLocked();
}
Program: 2091
Project: 2091
Buggy source:
/** 
 * Begin an animation to a new dim value. NOTE: Must be called with Surface transaction open.
 * @param layer The layer to set the surface to.
 * @param alpha The dim value to end at.
 * @param duration How long to take to get there in milliseconds.
 */
void show(int layer,float alpha,long duration){
  if (DEBUG)   Slog.v(TAG,"String_Node_Str" + layer + "String_Node_Str"+ alpha+ "String_Node_Str"+ duration);
  if (mDimSurface == null) {
    Slog.e(TAG,"String_Node_Str");
    mTargetAlpha=mAlpha=0;
    return;
  }
  final DisplayInfo info=mDisplayContent.getDisplayInfo();
  final int dw=(int)(info.logicalWidth * 1.5);
  final int dh=(int)(info.logicalHeight * 1.5);
  final float xPos=-1 * dw / 6;
  final float yPos=-1 * dh / 6;
  if (mLastDimWidth != dw || mLastDimHeight != dh || mLayer != layer) {
    try {
      mDimSurface.setPosition(xPos,yPos);
      mDimSurface.setSize(dw,dh);
      mDimSurface.setLayer(layer);
    }
 catch (    RuntimeException e) {
      Slog.w(TAG,"String_Node_Str",e);
    }
    mLastDimWidth=dw;
    mLastDimHeight=dh;
    mLayer=layer;
  }
  long curTime=SystemClock.uptimeMillis();
  final boolean animating=isAnimating();
  if ((animating && (mTargetAlpha != alpha || durationEndsEarlier(duration))) || (!animating && mAlpha != alpha)) {
    if (duration <= 0) {
      setAlpha(alpha);
    }
 else {
      mStartAlpha=mAlpha;
      mStartTime=curTime;
      mDuration=duration;
    }
  }
  if (DEBUG)   Slog.v(TAG,"String_Node_Str" + mStartAlpha + "String_Node_Str"+ mStartTime);
  mTargetAlpha=alpha;
}

Fixed version (ground truth):
/** 
 * Begin an animation to a new dim value. NOTE: Must be called with Surface transaction open.
 * @param layer The layer to set the surface to.
 * @param alpha The dim value to end at.
 * @param duration How long to take to get there in milliseconds.
 */
void show(int layer,float alpha,long duration){
  if (DEBUG)   Slog.v(TAG,"String_Node_Str" + layer + "String_Node_Str"+ alpha+ "String_Node_Str"+ duration);
  if (mDimSurface == null) {
    Slog.e(TAG,"String_Node_Str");
    mTargetAlpha=mAlpha=0;
    return;
  }
  if (!mLastBounds.equals(mBounds) || mLayer != layer) {
    try {
      mDimSurface.setPosition(mBounds.left,mBounds.top);
      mDimSurface.setSize(mBounds.width(),mBounds.height());
      mDimSurface.setLayer(layer);
    }
 catch (    RuntimeException e) {
      Slog.w(TAG,"String_Node_Str",e);
    }
    mLastBounds.set(mBounds);
    mLayer=layer;
  }
  long curTime=SystemClock.uptimeMillis();
  final boolean animating=isAnimating();
  if ((animating && (mTargetAlpha != alpha || durationEndsEarlier(duration))) || (!animating && mAlpha != alpha)) {
    if (duration <= 0) {
      setAlpha(alpha);
    }
 else {
      mStartAlpha=mAlpha;
      mStartTime=curTime;
      mDuration=duration;
    }
  }
  if (DEBUG)   Slog.v(TAG,"String_Node_Str" + mStartAlpha + "String_Node_Str"+ mStartTime);
  mTargetAlpha=alpha;
}
Program: 2092
Project: 2092
Buggy source:
public void printTo(String prefix,PrintWriter pw){
  pw.print(prefix);
  pw.print("String_Node_Str");
  pw.print(mDimSurface);
  pw.print("String_Node_Str");
  pw.print(mLayer);
  pw.print("String_Node_Str");
  pw.println(mAlpha);
  pw.print(prefix);
  pw.print("String_Node_Str");
  pw.print(mLastDimWidth);
  pw.print("String_Node_Str");
  pw.println(mLastDimHeight);
  pw.print(prefix);
  pw.print("String_Node_Str");
  pw.print("String_Node_Str");
  pw.print(mDuration);
  pw.print("String_Node_Str");
  pw.print(mStartTime);
  pw.print("String_Node_Str");
  pw.println(SystemClock.uptimeMillis());
  pw.print(prefix);
  pw.print("String_Node_Str");
  pw.print(mStartAlpha);
  pw.print("String_Node_Str");
  pw.println(mTargetAlpha);
}

Fixed version (ground truth):
public void printTo(String prefix,PrintWriter pw){
  pw.print(prefix);
  pw.print("String_Node_Str");
  pw.print(mDimSurface);
  pw.print("String_Node_Str");
  pw.print(mLayer);
  pw.print("String_Node_Str");
  pw.println(mAlpha);
  pw.print(prefix);
  pw.print("String_Node_Str");
  pw.print(mLastBounds.toShortString());
  pw.print("String_Node_Str");
  pw.println(mBounds.toShortString());
  pw.print(prefix);
  pw.print("String_Node_Str");
  pw.print("String_Node_Str");
  pw.print(mDuration);
  pw.print("String_Node_Str");
  pw.print(mStartTime);
  pw.print("String_Node_Str");
  pw.println(SystemClock.uptimeMillis());
  pw.print(prefix);
  pw.print("String_Node_Str");
  pw.print(mStartAlpha);
  pw.print("String_Node_Str");
  pw.println(mTargetAlpha);
}
Program: 2096
Project: 2096
Buggy source:
@Override public void setRequestedOrientation(IBinder token,int requestedOrientation){
synchronized (this) {
    ActivityRecord r=ActivityRecord.isInStackLocked(token);
    if (r == null) {
      return;
    }
    final long origId=Binder.clearCallingIdentity();
    mWindowManager.setAppOrientation(r.appToken,requestedOrientation);
    Configuration config=mWindowManager.updateOrientationFromAppTokens(mConfiguration,r.mayFreezeScreenLocked(r.app) ? r.appToken : null);
    if (config != null) {
      r.frozenBeforeDestroy=true;
      if (!updateConfigurationLocked(config,r,false,false)) {
        r.task.stack.resumeTopActivityLocked(null);
      }
    }
    Binder.restoreCallingIdentity(origId);
  }
}

Fixed version (ground truth):
@Override public void setRequestedOrientation(IBinder token,int requestedOrientation){
synchronized (this) {
    ActivityRecord r=ActivityRecord.isInStackLocked(token);
    if (r == null) {
      return;
    }
    final long origId=Binder.clearCallingIdentity();
    mWindowManager.setAppOrientation(r.appToken,requestedOrientation);
    Configuration config=mWindowManager.updateOrientationFromAppTokens(mConfiguration,r.mayFreezeScreenLocked(r.app) ? r.appToken : null);
    if (config != null) {
      r.frozenBeforeDestroy=true;
      if (!updateConfigurationLocked(config,r,false,false)) {
        mStackSupervisor.resumeTopActivitiesLocked();
      }
    }
    Binder.restoreCallingIdentity(origId);
  }
}
Program: 2097
Project: 2097
Buggy source:
final void activityStoppedLocked(ActivityRecord r,Bundle icicle,Bitmap thumbnail,CharSequence description){
  if (r.state != ActivityState.STOPPING) {
    Slog.i(TAG,"String_Node_Str" + r);
    mHandler.removeMessages(STOP_TIMEOUT_MSG,r);
    return;
  }
  if (DEBUG_SAVED_STATE)   Slog.i(TAG,"String_Node_Str" + r + "String_Node_Str"+ icicle);
  if (icicle != null) {
    r.icicle=icicle;
    r.haveState=true;
    r.launchCount=0;
    r.updateThumbnail(thumbnail,description);
  }
  if (!r.stopped) {
    if (DEBUG_STATES)     Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str");
    mHandler.removeMessages(STOP_TIMEOUT_MSG,r);
    r.stopped=true;
    r.state=ActivityState.STOPPED;
    if (r.finishing) {
      r.clearOptionsLocked();
    }
 else {
      if (r.configDestroy) {
        destroyActivityLocked(r,true,false,"String_Node_Str");
        mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
      }
 else {
        ProcessRecord fgApp=null;
        if (mResumedActivity != null) {
          fgApp=mResumedActivity.app;
        }
 else         if (mPausingActivity != null) {
          fgApp=mPausingActivity.app;
        }
        if (r.app != null && fgApp != null && r.app != fgApp && r.lastVisibleTime > mService.mPreviousProcessVisibleTime && r.app != mService.mHomeProcess) {
          mService.mPreviousProcess=r.app;
          mService.mPreviousProcessVisibleTime=r.lastVisibleTime;
        }
      }
    }
  }
}

Fixed version (ground truth):
final void activityStoppedLocked(ActivityRecord r,Bundle icicle,Bitmap thumbnail,CharSequence description){
  if (r.state != ActivityState.STOPPING) {
    Slog.i(TAG,"String_Node_Str" + r);
    mHandler.removeMessages(STOP_TIMEOUT_MSG,r);
    return;
  }
  if (DEBUG_SAVED_STATE)   Slog.i(TAG,"String_Node_Str" + r + "String_Node_Str"+ icicle);
  if (icicle != null) {
    r.icicle=icicle;
    r.haveState=true;
    r.launchCount=0;
    r.updateThumbnail(thumbnail,description);
  }
  if (!r.stopped) {
    if (DEBUG_STATES)     Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str");
    mHandler.removeMessages(STOP_TIMEOUT_MSG,r);
    r.stopped=true;
    r.state=ActivityState.STOPPED;
    if (r.finishing) {
      r.clearOptionsLocked();
    }
 else {
      if (r.configDestroy) {
        destroyActivityLocked(r,true,false,"String_Node_Str");
        mStackSupervisor.resumeTopActivitiesLocked();
      }
 else {
        ProcessRecord fgApp=null;
        if (mResumedActivity != null) {
          fgApp=mResumedActivity.app;
        }
 else         if (mPausingActivity != null) {
          fgApp=mPausingActivity.app;
        }
        if (r.app != null && fgApp != null && r.app != fgApp && r.lastVisibleTime > mService.mPreviousProcessVisibleTime && r.app != mService.mHomeProcess) {
          mService.mPreviousProcess=r.app;
          mService.mPreviousProcessVisibleTime=r.lastVisibleTime;
        }
      }
    }
  }
}
Program: 2098
Project: 2098
Buggy source:
final void destroyActivitiesLocked(ProcessRecord owner,boolean oomAdj,String reason){
  boolean lastIsOpaque=false;
  boolean activityRemoved=false;
  for (int taskNdx=mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
    final ArrayList<ActivityRecord> activities=mTaskHistory.get(taskNdx).mActivities;
    for (int activityNdx=activities.size() - 1; activityNdx >= 0; --activityNdx) {
      final ActivityRecord r=activities.get(activityNdx);
      if (r.finishing) {
        continue;
      }
      if (r.fullscreen) {
        lastIsOpaque=true;
      }
      if (owner != null && r.app != owner) {
        continue;
      }
      if (!lastIsOpaque) {
        continue;
      }
      if (r.app != null && r != mResumedActivity && r != mPausingActivity && r.haveState && !r.visible && r.stopped && r.state != ActivityState.DESTROYING && r.state != ActivityState.DESTROYED) {
        if (DEBUG_SWITCH)         Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.state+ "String_Node_Str"+ mResumedActivity+ "String_Node_Str"+ mPausingActivity);
        if (destroyActivityLocked(r,true,oomAdj,reason)) {
          activityRemoved=true;
        }
      }
    }
  }
  if (activityRemoved) {
    mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
  }
}

Fixed version (ground truth):
final void destroyActivitiesLocked(ProcessRecord owner,boolean oomAdj,String reason){
  boolean lastIsOpaque=false;
  boolean activityRemoved=false;
  for (int taskNdx=mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
    final ArrayList<ActivityRecord> activities=mTaskHistory.get(taskNdx).mActivities;
    for (int activityNdx=activities.size() - 1; activityNdx >= 0; --activityNdx) {
      final ActivityRecord r=activities.get(activityNdx);
      if (r.finishing) {
        continue;
      }
      if (r.fullscreen) {
        lastIsOpaque=true;
      }
      if (owner != null && r.app != owner) {
        continue;
      }
      if (!lastIsOpaque) {
        continue;
      }
      if (r.app != null && r != mResumedActivity && r != mPausingActivity && r.haveState && !r.visible && r.stopped && r.state != ActivityState.DESTROYING && r.state != ActivityState.DESTROYED) {
        if (DEBUG_SWITCH)         Slog.v(TAG,"String_Node_Str" + r + "String_Node_Str"+ r.state+ "String_Node_Str"+ mResumedActivity+ "String_Node_Str"+ mPausingActivity);
        if (destroyActivityLocked(r,true,oomAdj,reason)) {
          activityRemoved=true;
        }
      }
    }
  }
  if (activityRemoved) {
    mStackSupervisor.resumeTopActivitiesLocked();
  }
}