Program: 22535
Project: 22535
Buggy source:
boolean computeNewConfigurationLocked(Configuration config){
  if (mDisplay == null) {
    return false;
  }
  mQueue.getInputConfiguration(config);
  final int dw=mDisplay.getWidth();
  final int dh=mDisplay.getHeight();
  int orientation=Configuration.ORIENTATION_SQUARE;
  if (dw < dh) {
    orientation=Configuration.ORIENTATION_PORTRAIT;
  }
 else   if (dw > dh) {
    orientation=Configuration.ORIENTATION_LANDSCAPE;
  }
  config.orientation=orientation;
  DisplayMetrics dm=new DisplayMetrics();
  mDisplay.getMetrics(dm);
  CompatibilityInfo.updateCompatibleScreenFrame(dm,orientation,mCompatibleScreenFrame);
  if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
    int longSize=dw;
    int shortSize=dh;
    if (longSize < shortSize) {
      int tmp=longSize;
      longSize=shortSize;
      shortSize=tmp;
    }
    longSize=(int)(longSize / dm.density);
    shortSize=(int)(shortSize / dm.density);
    if (longSize < 470) {
      mScreenLayout=Configuration.SCREENLAYOUT_SIZE_SMALL | Configuration.SCREENLAYOUT_LONG_NO;
    }
 else {
      if (longSize > 640 && shortSize >= 480) {
        mScreenLayout=Configuration.SCREENLAYOUT_SIZE_LARGE;
      }
 else {
        mScreenLayout=Configuration.SCREENLAYOUT_SIZE_NORMAL;
        if (shortSize > 321 || longSize > 570) {
          mScreenLayout|=Configuration.SCREENLAYOUT_COMPAT_NEEDED;
        }
      }
      if (((longSize * 3) / 5) >= (shortSize - 1)) {
        mScreenLayout|=Configuration.SCREENLAYOUT_LONG_YES;
      }
 else {
        mScreenLayout|=Configuration.SCREENLAYOUT_LONG_NO;
      }
    }
  }
  config.screenLayout=mScreenLayout;
  config.keyboardHidden=Configuration.KEYBOARDHIDDEN_NO;
  config.hardKeyboardHidden=Configuration.HARDKEYBOARDHIDDEN_NO;
  mPolicy.adjustConfigurationLw(config);
  return true;
}

Fixed version (ground truth):
boolean computeNewConfigurationLocked(Configuration config){
  if (mDisplay == null) {
    return false;
  }
  mQueue.getInputConfiguration(config);
  final boolean rotated=(mRotation == Surface.ROTATION_90 || mRotation == Surface.ROTATION_270);
  final int dw=rotated ? mInitialDisplayHeight : mInitialDisplayWidth;
  final int dh=rotated ? mInitialDisplayWidth : mInitialDisplayHeight;
  int orientation=Configuration.ORIENTATION_SQUARE;
  if (dw < dh) {
    orientation=Configuration.ORIENTATION_PORTRAIT;
  }
 else   if (dw > dh) {
    orientation=Configuration.ORIENTATION_LANDSCAPE;
  }
  config.orientation=orientation;
  DisplayMetrics dm=new DisplayMetrics();
  mDisplay.getMetrics(dm);
  CompatibilityInfo.updateCompatibleScreenFrame(dm,orientation,mCompatibleScreenFrame);
  if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
    int longSize=dw;
    int shortSize=dh;
    if (longSize < shortSize) {
      int tmp=longSize;
      longSize=shortSize;
      shortSize=tmp;
    }
    longSize=(int)(longSize / dm.density);
    shortSize=(int)(shortSize / dm.density);
    if (longSize < 470) {
      mScreenLayout=Configuration.SCREENLAYOUT_SIZE_SMALL | Configuration.SCREENLAYOUT_LONG_NO;
    }
 else {
      if (longSize > 640 && shortSize >= 480) {
        mScreenLayout=Configuration.SCREENLAYOUT_SIZE_LARGE;
      }
 else {
        mScreenLayout=Configuration.SCREENLAYOUT_SIZE_NORMAL;
        if (shortSize > 321 || longSize > 570) {
          mScreenLayout|=Configuration.SCREENLAYOUT_COMPAT_NEEDED;
        }
      }
      if (((longSize * 3) / 5) >= (shortSize - 1)) {
        mScreenLayout|=Configuration.SCREENLAYOUT_LONG_YES;
      }
 else {
        mScreenLayout|=Configuration.SCREENLAYOUT_LONG_NO;
      }
    }
  }
  config.screenLayout=mScreenLayout;
  config.keyboardHidden=Configuration.KEYBOARDHIDDEN_NO;
  config.hardKeyboardHidden=Configuration.HARDKEYBOARDHIDDEN_NO;
  mPolicy.adjustConfigurationLw(config);
  return true;
}