Program: 45449
Project: 45449
Buggy source:
@Override public boolean onKeyDown(int keyCode,KeyEvent event){
  boolean handled=false;
  if (!isVisible()) {
    return false;
  }
  final int iconCount=mRollo.mState.iconCount;
  if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
    if (mArrowNavigation) {
      if (mLastSelection == SELECTION_HOME) {
        reallyPlaySoundEffect(SoundEffectConstants.CLICK);
        mLauncher.closeAllApps(true);
      }
 else {
        int whichApp=mRollo.mState.selectedIconIndex;
        if (whichApp >= 0) {
          ApplicationInfo app=mAllAppsList.get(whichApp);
          mLauncher.startActivitySafely(app.intent);
          handled=true;
        }
      }
    }
  }
  if (iconCount > 0) {
    mArrowNavigation=true;
    int currentSelection=mRollo.mState.selectedIconIndex;
    int currentTopRow=Math.round(mPosX);
    final int currentPageCol=currentSelection % mColumnsPerPage;
    final int currentPageRow=(currentSelection - (currentTopRow * mColumnsPerPage)) / mRowsPerPage;
    int newSelection=currentSelection;
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
      if (mLastSelection == SELECTION_HOME) {
        mRollo.setHomeSelected(SELECTED_NONE);
        int lastRowCount=iconCount % mColumnsPerPage;
        if (lastRowCount == 0) {
          lastRowCount=mColumnsPerPage;
        }
        newSelection=iconCount - lastRowCount + (mColumnsPerPage / 2);
        if (newSelection >= iconCount) {
          newSelection=iconCount - 1;
        }
        int target=(newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
        if (target < 0) {
          target=0;
        }
        if (currentTopRow != target) {
          mRollo.moveTo(target);
        }
      }
 else {
        if (currentPageRow > 0) {
          newSelection=currentSelection - mColumnsPerPage;
        }
 else         if (currentTopRow > 0) {
          newSelection=currentSelection - mColumnsPerPage;
          mRollo.moveTo(newSelection / mColumnsPerPage);
        }
 else         if (currentPageRow != 0) {
          newSelection=currentTopRow * mRowsPerPage;
        }
      }
    handled=true;
  break;
case KeyEvent.KEYCODE_DPAD_DOWN:
{
  final int rowCount=iconCount / mColumnsPerPage + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
  final int currentRow=currentSelection / mColumnsPerPage;
  if (mLastSelection != SELECTION_HOME) {
    if (currentRow < rowCount - 1) {
      mRollo.setHomeSelected(SELECTED_NONE);
      if (currentSelection < 0) {
        newSelection=0;
      }
 else {
        newSelection=currentSelection + mColumnsPerPage;
      }
      if (newSelection >= iconCount) {
        newSelection=iconCount - 1;
      }
      if (currentPageRow >= mRowsPerPage - 1) {
        mRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
      }
    }
 else {
      newSelection=-1;
      mRollo.setHomeSelected(SELECTED_FOCUSED);
    }
  }
  handled=true;
  break;
}
case KeyEvent.KEYCODE_DPAD_LEFT:
if (mLastSelection != SELECTION_HOME) {
if (currentPageCol > 0) {
  newSelection=currentSelection - 1;
}
}
handled=true;
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (mLastSelection != SELECTION_HOME) {
if ((currentPageCol < mColumnsPerPage - 1) && (currentSelection < iconCount - 1)) {
newSelection=currentSelection + 1;
}
}
handled=true;
break;
}
if (newSelection != currentSelection) {
mRollo.selectIcon(newSelection,SELECTED_FOCUSED);
mRollo.mState.save();
}
}
return handled;
}

Fixed version (ground truth):
@Override public boolean onKeyDown(int keyCode,KeyEvent event){
  boolean handled=false;
  if (!isVisible()) {
    return false;
  }
  final int iconCount=mRollo.mState.iconCount;
  if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
    if (mArrowNavigation) {
      if (mLastSelection == SELECTION_HOME) {
        reallyPlaySoundEffect(SoundEffectConstants.CLICK);
        mLauncher.closeAllApps(true);
      }
 else {
        int whichApp=mRollo.mState.selectedIconIndex;
        if (whichApp >= 0) {
          ApplicationInfo app=mAllAppsList.get(whichApp);
          mLauncher.startActivitySafely(app.intent);
          handled=true;
        }
      }
    }
  }
  if (iconCount > 0) {
    final boolean isPortrait=getWidth() < getHeight();
    mArrowNavigation=true;
    int currentSelection=mRollo.mState.selectedIconIndex;
    int currentTopRow=Math.round(mRollo.mScrollPos);
    final int currentPageCol=currentSelection % mColumnsPerPage;
    final int currentPageRow=(currentSelection - (currentTopRow * mColumnsPerPage)) / mRowsPerPage;
    int newSelection=currentSelection;
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
      if (mLastSelection == SELECTION_HOME) {
        if (isPortrait) {
          mRollo.setHomeSelected(SELECTED_NONE);
          int lastRowCount=iconCount % mColumnsPerPage;
          if (lastRowCount == 0) {
            lastRowCount=mColumnsPerPage;
          }
          newSelection=iconCount - lastRowCount + (mColumnsPerPage / 2);
          if (newSelection >= iconCount) {
            newSelection=iconCount - 1;
          }
          int target=(newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
          if (target < 0) {
            target=0;
          }
          if (currentTopRow != target) {
            mRollo.moveTo(target);
          }
        }
      }
 else {
        if (currentPageRow > 0) {
          newSelection=currentSelection - mColumnsPerPage;
          if (currentTopRow > newSelection / mColumnsPerPage) {
            mRollo.moveTo(newSelection / mColumnsPerPage);
          }
        }
 else         if (currentTopRow > 0) {
          newSelection=currentSelection - mColumnsPerPage;
          mRollo.moveTo(newSelection / mColumnsPerPage);
        }
 else         if (currentPageRow != 0) {
          newSelection=currentTopRow * mRowsPerPage;
        }
      }
    handled=true;
  break;
case KeyEvent.KEYCODE_DPAD_DOWN:
{
  final int rowCount=iconCount / mColumnsPerPage + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
  final int currentRow=currentSelection / mColumnsPerPage;
  if (mLastSelection != SELECTION_HOME) {
    if (currentRow < rowCount - 1) {
      mRollo.setHomeSelected(SELECTED_NONE);
      if (currentSelection < 0) {
        newSelection=0;
      }
 else {
        newSelection=currentSelection + mColumnsPerPage;
      }
      if (newSelection >= iconCount) {
        newSelection=iconCount - 1;
      }
      if (currentPageRow >= mRowsPerPage - 1) {
        mRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
      }
    }
 else     if (isPortrait) {
      newSelection=-1;
      mRollo.setHomeSelected(SELECTED_FOCUSED);
    }
  }
  handled=true;
  break;
}
case KeyEvent.KEYCODE_DPAD_LEFT:
if (mLastSelection != SELECTION_HOME) {
if (currentPageCol > 0) {
  newSelection=currentSelection - 1;
}
}
 else if (!isPortrait) {
newSelection=((int)(mRollo.mScrollPos) * mColumnsPerPage) + (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
mRollo.setHomeSelected(SELECTED_NONE);
}
handled=true;
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (mLastSelection != SELECTION_HOME) {
if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 || currentSelection == iconCount - 1)) {
newSelection=-1;
mRollo.setHomeSelected(SELECTED_FOCUSED);
}
 else if ((currentPageCol < mColumnsPerPage - 1) && (currentSelection < iconCount - 1)) {
newSelection=currentSelection + 1;
}
}
handled=true;
break;
}
if (newSelection != currentSelection) {
mRollo.selectIcon(newSelection,SELECTED_FOCUSED);
mRollo.mState.save();
}
}
return handled;
}