Program: 192909
Project: 192909
Buggy source:
/** 
 * Dig through the WindowStates and find the one that the Input Method will target.
 * @param willMove
 * @return The index+1 in mWindows of the discovered target.
 */
int findDesiredInputMethodWindowIndexLocked(boolean willMove){
  WindowList windows=getDefaultWindowListLocked();
  WindowState w=null;
  int i;
  for (i=windows.size() - 1; i >= 0; --i) {
    WindowState win=windows.get(i);
    if (DEBUG_INPUT_METHOD && willMove)     Slog.i(TAG_WM,"String_Node_Str" + i + "String_Node_Str"+ win+ "String_Node_Str"+ Integer.toHexString(win.mAttrs.flags));
    if (canBeImeTarget(win)) {
      w=win;
      if (!willMove && w.mAttrs.type == TYPE_APPLICATION_STARTING && i > 0) {
        WindowState wb=windows.get(i - 1);
        if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
          i--;
          w=wb;
        }
      }
      break;
    }
  }
  if (DEBUG_INPUT_METHOD && willMove)   Slog.v(TAG_WM,"String_Node_Str" + w);
  final WindowState curTarget=mInputMethodTarget;
  if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing() && (w == null || curTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer)) {
    if (DEBUG_INPUT_METHOD)     Slog.v(TAG_WM,"String_Node_Str");
    return windows.indexOf(curTarget) + 1;
  }
  if (DEBUG_INPUT_METHOD)   Slog.v(TAG_WM,"String_Node_Str" + w + "String_Node_Str"+ willMove);
  if (willMove && w != null) {
    AppWindowToken token=curTarget == null ? null : curTarget.mAppToken;
    if (token != null) {
      WindowState highestTarget=null;
      int highestPos=0;
      if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) {
        WindowList curWindows=curTarget.getWindowList();
        int pos=curWindows.indexOf(curTarget);
        while (pos >= 0) {
          WindowState win=curWindows.get(pos);
          if (win.mAppToken != token) {
            break;
          }
          if (!win.mRemoved) {
            if (highestTarget == null || win.mWinAnimator.mAnimLayer > highestTarget.mWinAnimator.mAnimLayer) {
              highestTarget=win;
              highestPos=pos;
            }
          }
          pos--;
        }
      }
      if (highestTarget != null) {
        if (DEBUG_INPUT_METHOD)         Slog.v(TAG_WM,mAppTransition + "String_Node_Str" + highestTarget+ "String_Node_Str"+ highestTarget.mWinAnimator.isAnimating()+ "String_Node_Str"+ highestTarget.mWinAnimator.mAnimLayer+ "String_Node_Str"+ w.mWinAnimator.mAnimLayer);
        if (mAppTransition.isTransitionSet()) {
          mInputMethodTargetWaitingAnim=true;
          mInputMethodTarget=highestTarget;
          return highestPos + 1;
        }
 else         if (highestTarget.mWinAnimator.isAnimating() && highestTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) {
          mInputMethodTargetWaitingAnim=true;
          mInputMethodTarget=highestTarget;
          return highestPos + 1;
        }
      }
    }
  }
  if (w != null) {
    if (willMove) {
      if (DEBUG_INPUT_METHOD)       Slog.w(TAG_WM,"String_Node_Str" + curTarget + "String_Node_Str"+ w+ (HIDE_STACK_CRAWLS ? "String_Node_Str" : "String_Node_Str" + Debug.getCallers(4)));
      mInputMethodTarget=w;
      mInputMethodTargetWaitingAnim=false;
      if (w.mAppToken != null) {
        mLayersController.setInputMethodAnimLayerAdjustment(w.mAppToken.mAppAnimator.animLayerAdjustment);
      }
 else {
        mLayersController.setInputMethodAnimLayerAdjustment(0);
      }
    }
    return i + 1;
  }
  if (willMove) {
    if (DEBUG_INPUT_METHOD)     Slog.w(TAG_WM,"String_Node_Str" + curTarget + "String_Node_Str"+ (HIDE_STACK_CRAWLS ? "String_Node_Str" : "String_Node_Str" + Debug.getCallers(4)));
    mInputMethodTarget=null;
    mLayersController.setInputMethodAnimLayerAdjustment(0);
  }
  return -1;
}

Fixed version (ground truth):
/** 
 * Dig through the WindowStates and find the one that the Input Method will target.
 * @param willMove
 * @return The index+1 in mWindows of the discovered target.
 */
int findDesiredInputMethodWindowIndexLocked(boolean willMove){
  WindowList windows=getDefaultWindowListLocked();
  WindowState w=null;
  int i;
  for (i=windows.size() - 1; i >= 0; --i) {
    WindowState win=windows.get(i);
    if (DEBUG_INPUT_METHOD && willMove)     Slog.i(TAG_WM,"String_Node_Str" + i + "String_Node_Str"+ win+ "String_Node_Str"+ Integer.toHexString(win.mAttrs.flags));
    if (canBeImeTarget(win)) {
      w=win;
      if (!willMove && w.mAttrs.type == TYPE_APPLICATION_STARTING && i > 0) {
        WindowState wb=windows.get(i - 1);
        if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
          i--;
          w=wb;
        }
      }
      break;
    }
  }
  if (DEBUG_INPUT_METHOD && willMove)   Slog.v(TAG_WM,"String_Node_Str" + w);
  final WindowState curTarget=mInputMethodTarget;
  if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing() && (w == null || curTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer)) {
    if (DEBUG_INPUT_METHOD)     Slog.v(TAG_WM,"String_Node_Str");
    return windows.indexOf(curTarget) + 1;
  }
  if (DEBUG_INPUT_METHOD)   Slog.v(TAG_WM,"String_Node_Str" + w + "String_Node_Str"+ willMove);
  if (willMove && w != null) {
    AppWindowToken token=curTarget == null ? null : curTarget.mAppToken;
    if (token != null) {
      WindowState highestTarget=null;
      int highestPos=0;
      if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) {
        WindowList curWindows=curTarget.getWindowList();
        int pos=curWindows.indexOf(curTarget);
        while (pos >= 0) {
          WindowState win=curWindows.get(pos);
          if (win.mAppToken != token) {
            break;
          }
          if (!win.mRemoved) {
            if (highestTarget == null || win.mWinAnimator.mAnimLayer > highestTarget.mWinAnimator.mAnimLayer) {
              highestTarget=win;
              highestPos=pos;
            }
          }
          pos--;
        }
      }
      if (highestTarget != null) {
        if (DEBUG_INPUT_METHOD)         Slog.v(TAG_WM,mAppTransition + "String_Node_Str" + highestTarget+ "String_Node_Str"+ highestTarget.mWinAnimator.isAnimating()+ "String_Node_Str"+ highestTarget.mWinAnimator.mAnimLayer+ "String_Node_Str"+ w.mWinAnimator.mAnimLayer);
        if (mAppTransition.isTransitionSet()) {
          mInputMethodTargetWaitingAnim=true;
          mInputMethodTarget=highestTarget;
          return highestPos + 1;
        }
 else         if (highestTarget.mWinAnimator.isAnimating() && highestTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) {
          mInputMethodTargetWaitingAnim=true;
          mInputMethodTarget=highestTarget;
          return highestPos + 1;
        }
      }
    }
  }
  if (w != null) {
    if (willMove) {
      if (DEBUG_INPUT_METHOD)       Slog.w(TAG_WM,"String_Node_Str" + curTarget + "String_Node_Str"+ w+ (SHOW_STACK_CRAWLS ? "String_Node_Str" + Debug.getCallers(4) : "String_Node_Str"));
      mInputMethodTarget=w;
      mInputMethodTargetWaitingAnim=false;
      if (w.mAppToken != null) {
        mLayersController.setInputMethodAnimLayerAdjustment(w.mAppToken.mAppAnimator.animLayerAdjustment);
      }
 else {
        mLayersController.setInputMethodAnimLayerAdjustment(0);
      }
    }
    return i + 1;
  }
  if (willMove) {
    if (DEBUG_INPUT_METHOD)     Slog.w(TAG_WM,"String_Node_Str" + curTarget + "String_Node_Str"+ (SHOW_STACK_CRAWLS ? "String_Node_Str" + Debug.getCallers(4) : "String_Node_Str"));
    mInputMethodTarget=null;
    mLayersController.setInputMethodAnimLayerAdjustment(0);
  }
  return -1;
}