Program: 199517
Project: 199517
Buggy source:
protected void cropImageAndSetWallpaper(Uri uri,OnBitmapCroppedHandler onBitmapCroppedHandler,final boolean finishActivityWhenDone){
  boolean centerCrop=getResources().getBoolean(R.bool.center_crop);
  boolean ltr=mCropView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
  Display d=getWindowManager().getDefaultDisplay();
  Point displaySize=new Point();
  d.getSize(displaySize);
  boolean isPortrait=displaySize.x < displaySize.y;
  Point defaultWallpaperSize=getDefaultWallpaperSize(getResources(),getWindowManager());
  RectF cropRect=mCropView.getCrop();
  cropRect.left=Math.max(0,cropRect.left);
  cropRect.right=Math.min(mCropView.getWidth(),cropRect.right);
  cropRect.top=Math.max(0,cropRect.top);
  cropRect.bottom=Math.min(mCropView.getHeight(),cropRect.bottom);
  int cropRotation=mCropView.getImageRotation();
  float cropScale=mCropView.getWidth() / (float)cropRect.width();
  Point inSize=mCropView.getSourceDimensions();
  Matrix rotateMatrix=new Matrix();
  rotateMatrix.setRotate(cropRotation);
  float[] rotatedInSize=new float[]{inSize.x,inSize.y};
  rotateMatrix.mapPoints(rotatedInSize);
  rotatedInSize[0]=Math.abs(rotatedInSize[0]);
  rotatedInSize[1]=Math.abs(rotatedInSize[1]);
  float extraSpace;
  if (centerCrop) {
    extraSpace=2f * Math.min(rotatedInSize[0] - cropRect.right,cropRect.left);
  }
 else {
    extraSpace=ltr ? rotatedInSize[0] - cropRect.right : cropRect.left;
  }
  float maxExtraSpace=defaultWallpaperSize.x / cropScale - cropRect.width();
  extraSpace=Math.min(extraSpace,maxExtraSpace);
  if (centerCrop) {
    cropRect.left-=extraSpace / 2f;
    cropRect.right+=extraSpace / 2f;
  }
 else {
    if (ltr) {
      cropRect.right+=extraSpace;
    }
 else {
      cropRect.left-=extraSpace;
    }
  }
  if (isPortrait) {
    cropRect.bottom=cropRect.top + defaultWallpaperSize.y / cropScale;
  }
 else {
    float extraPortraitHeight=defaultWallpaperSize.y / cropScale - cropRect.height();
    float expandHeight=Math.min(Math.min(rotatedInSize[1] - cropRect.bottom,cropRect.top),extraPortraitHeight / 2);
    cropRect.top-=expandHeight;
    cropRect.bottom+=expandHeight;
  }
  final int outWidth=(int)Math.round(cropRect.width() * cropScale);
  final int outHeight=(int)Math.round(cropRect.height() * cropScale);
  Runnable onEndCrop=new Runnable(){
    public void run(){
      updateWallpaperDimensions(outWidth,outHeight);
      if (finishActivityWhenDone) {
        setResult(Activity.RESULT_OK);
        finish();
      }
    }
  }
;
  BitmapCropTask cropTask=new BitmapCropTask(this,uri,cropRect,cropRotation,outWidth,outHeight,true,false,onEndCrop);
  if (onBitmapCroppedHandler != null) {
    cropTask.setOnBitmapCropped(onBitmapCroppedHandler);
  }
  cropTask.execute();
}

Fixed version (ground truth):
protected void cropImageAndSetWallpaper(Uri uri,OnBitmapCroppedHandler onBitmapCroppedHandler,final boolean finishActivityWhenDone){
  boolean centerCrop=getResources().getBoolean(R.bool.center_crop);
  boolean ltr=mCropView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
  Display d=getWindowManager().getDefaultDisplay();
  Point displaySize=new Point();
  d.getSize(displaySize);
  boolean isPortrait=displaySize.x < displaySize.y;
  Point defaultWallpaperSize=getDefaultWallpaperSize(getResources(),getWindowManager());
  RectF cropRect=mCropView.getCrop();
  Point inSize=mCropView.getSourceDimensions();
  cropRect.left=Math.max(0,cropRect.left);
  cropRect.right=Math.min(inSize.x,cropRect.right);
  cropRect.top=Math.max(0,cropRect.top);
  cropRect.bottom=Math.min(inSize.y,cropRect.bottom);
  int cropRotation=mCropView.getImageRotation();
  float cropScale=mCropView.getWidth() / (float)cropRect.width();
  Matrix rotateMatrix=new Matrix();
  rotateMatrix.setRotate(cropRotation);
  float[] rotatedInSize=new float[]{inSize.x,inSize.y};
  rotateMatrix.mapPoints(rotatedInSize);
  rotatedInSize[0]=Math.abs(rotatedInSize[0]);
  rotatedInSize[1]=Math.abs(rotatedInSize[1]);
  float extraSpace;
  if (centerCrop) {
    extraSpace=2f * Math.min(rotatedInSize[0] - cropRect.right,cropRect.left);
  }
 else {
    extraSpace=ltr ? rotatedInSize[0] - cropRect.right : cropRect.left;
  }
  float maxExtraSpace=defaultWallpaperSize.x / cropScale - cropRect.width();
  extraSpace=Math.min(extraSpace,maxExtraSpace);
  if (centerCrop) {
    cropRect.left-=extraSpace / 2f;
    cropRect.right+=extraSpace / 2f;
  }
 else {
    if (ltr) {
      cropRect.right+=extraSpace;
    }
 else {
      cropRect.left-=extraSpace;
    }
  }
  if (isPortrait) {
    cropRect.bottom=cropRect.top + defaultWallpaperSize.y / cropScale;
  }
 else {
    float extraPortraitHeight=defaultWallpaperSize.y / cropScale - cropRect.height();
    float expandHeight=Math.min(Math.min(rotatedInSize[1] - cropRect.bottom,cropRect.top),extraPortraitHeight / 2);
    cropRect.top-=expandHeight;
    cropRect.bottom+=expandHeight;
  }
  final int outWidth=(int)Math.round(cropRect.width() * cropScale);
  final int outHeight=(int)Math.round(cropRect.height() * cropScale);
  Runnable onEndCrop=new Runnable(){
    public void run(){
      updateWallpaperDimensions(outWidth,outHeight);
      if (finishActivityWhenDone) {
        setResult(Activity.RESULT_OK);
        finish();
      }
    }
  }
;
  BitmapCropTask cropTask=new BitmapCropTask(this,uri,cropRect,cropRotation,outWidth,outHeight,true,false,onEndCrop);
  if (onBitmapCroppedHandler != null) {
    cropTask.setOnBitmapCropped(onBitmapCroppedHandler);
  }
  cropTask.execute();
}