Program: 191889
Project: 191889
Buggy source:
Bitmap screenshotApplicationsInner(IBinder appToken,int displayId,int width,int height,boolean includeFullDisplay,float frameScale,Bitmap.Config config){
  final DisplayContent displayContent;
synchronized (mWindowMap) {
    displayContent=getDisplayContentLocked(displayId);
    if (displayContent == null) {
      if (DEBUG_SCREENSHOT)       Slog.i(TAG_WM,"String_Node_Str" + appToken + "String_Node_Str"+ displayId);
      return null;
    }
  }
  final DisplayInfo displayInfo=displayContent.getDisplayInfo();
  int dw=displayInfo.logicalWidth;
  int dh=displayInfo.logicalHeight;
  if (dw == 0 || dh == 0) {
    if (DEBUG_SCREENSHOT)     Slog.i(TAG_WM,"String_Node_Str" + appToken + "String_Node_Str"+ dw+ "String_Node_Str"+ dh);
    return null;
  }
  Bitmap bm=null;
  int maxLayer=0;
  final Rect frame=new Rect();
  final Rect stackBounds=new Rect();
  boolean screenshotReady;
  int minLayer;
  if (appToken == null) {
    screenshotReady=true;
    minLayer=0;
  }
 else {
    screenshotReady=false;
    minLayer=Integer.MAX_VALUE;
  }
  WindowState appWin=null;
  boolean appIsImTarget;
synchronized (mWindowMap) {
    appIsImTarget=mInputMethodTarget != null && mInputMethodTarget.mAppToken != null && mInputMethodTarget.mAppToken.appToken != null && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
  }
  final int aboveAppLayer=(mPolicy.windowTypeToLayerLw(TYPE_APPLICATION) + 1) * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
synchronized (mWindowMap) {
    appWin=null;
    final WindowList windows=displayContent.getWindowList();
    for (int i=windows.size() - 1; i >= 0; i--) {
      WindowState ws=windows.get(i);
      if (!ws.mHasSurface) {
        continue;
      }
      if (ws.mLayer >= aboveAppLayer) {
        continue;
      }
      if (ws.mIsImWindow) {
        if (!appIsImTarget) {
          continue;
        }
      }
 else       if (ws.mIsWallpaper) {
        if (appWin == null) {
          continue;
        }
      }
 else       if (appToken != null) {
        if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
          continue;
        }
        appWin=ws;
      }
      final WindowStateAnimator winAnim=ws.mWinAnimator;
      int layer=winAnim.mSurfaceController.getLayer();
      if (maxLayer < layer) {
        maxLayer=layer;
      }
      if (minLayer > layer) {
        minLayer=layer;
      }
      if (!includeFullDisplay && !ws.mIsWallpaper) {
        final Rect wf=ws.mFrame;
        final Rect cr=ws.mContentInsets;
        int left=wf.left + cr.left;
        int top=wf.top + cr.top;
        int right=wf.right - cr.right;
        int bottom=wf.bottom - cr.bottom;
        frame.union(left,top,right,bottom);
        ws.getVisibleBounds(stackBounds);
        if (!Rect.intersects(frame,stackBounds)) {
          frame.setEmpty();
        }
      }
      if (ws.mAppToken != null && ws.mAppToken.token == appToken && ws.isDisplayedLw() && winAnim.getShown()) {
        screenshotReady=true;
      }
      if (ws.isObscuringFullscreen(displayInfo)) {
        break;
      }
    }
    if (appToken != null && appWin == null) {
      if (DEBUG_SCREENSHOT)       Slog.i(TAG_WM,"String_Node_Str" + appToken);
      return null;
    }
    if (!screenshotReady) {
      Slog.i(TAG_WM,"String_Node_Str" + appToken + "String_Node_Str"+ (appWin == null ? "String_Node_Str" : (appWin + "String_Node_Str" + appWin.mWinAnimator.mDrawState)));
      return null;
    }
    if (maxLayer == 0) {
      if (DEBUG_SCREENSHOT)       Slog.i(TAG_WM,"String_Node_Str" + appToken + "String_Node_Str"+ maxLayer);
      return null;
    }
    if (!includeFullDisplay) {
      if (!frame.intersect(0,0,dw,dh)) {
        frame.setEmpty();
      }
    }
 else {
      frame.set(0,0,dw,dh);
    }
    if (frame.isEmpty()) {
      return null;
    }
    if (width < 0) {
      width=(int)(frame.width() * frameScale);
    }
    if (height < 0) {
      height=(int)(frame.height() * frameScale);
    }
    Rect crop=new Rect(frame);
    if (width / (float)frame.width() < height / (float)frame.height()) {
      int cropWidth=(int)((float)width / (float)height * frame.height());
      crop.right=crop.left + cropWidth;
    }
 else {
      int cropHeight=(int)((float)height / (float)width * frame.width());
      crop.bottom=crop.top + cropHeight;
    }
    int rot=getDefaultDisplayContentLocked().getDisplay().getRotation();
    if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
      rot=(rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
    }
    convertCropForSurfaceFlinger(crop,rot,dw,dh);
    if (DEBUG_SCREENSHOT) {
      Slog.i(TAG_WM,"String_Node_Str" + dw + "String_Node_Str"+ dh+ "String_Node_Str"+ minLayer+ "String_Node_Str"+ maxLayer+ "String_Node_Str"+ appToken);
      for (int i=0; i < windows.size(); i++) {
        WindowState win=windows.get(i);
        Slog.i(TAG_WM,win + "String_Node_Str" + win.mLayer+ "String_Node_Str"+ win.mWinAnimator.mAnimLayer+ "String_Node_Str"+ win.mWinAnimator.mSurfaceController.getLayer());
      }
    }
    ScreenRotationAnimation screenRotationAnimation=mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY);
    final boolean inRotation=screenRotationAnimation != null && screenRotationAnimation.isAnimating();
    if (DEBUG_SCREENSHOT && inRotation)     Slog.v(TAG_WM,"String_Node_Str");
    bm=SurfaceControl.screenshot(crop,width,height,minLayer,maxLayer,inRotation,rot);
    if (bm == null) {
      Slog.w(TAG_WM,"String_Node_Str" + dw + "String_Node_Str"+ dh+ "String_Node_Str"+ maxLayer);
      return null;
    }
  }
  if (DEBUG_SCREENSHOT) {
    int[] buffer=new int[bm.getWidth() * bm.getHeight()];
    bm.getPixels(buffer,0,bm.getWidth(),0,0,bm.getWidth(),bm.getHeight());
    boolean allBlack=true;
    final int firstColor=buffer[0];
    for (int i=0; i < buffer.length; i++) {
      if (buffer[i] != firstColor) {
        allBlack=false;
        break;
      }
    }
    if (allBlack) {
      Slog.i(TAG_WM,"String_Node_Str" + appWin + "String_Node_Str"+ Integer.toHexString(firstColor)+ "String_Node_Str"+ (appWin != null ? appWin.mWinAnimator.mSurfaceController.getLayer() : "String_Node_Str")+ "String_Node_Str"+ minLayer+ "String_Node_Str"+ maxLayer);
    }
  }
  Bitmap ret=bm.createAshmemBitmap(config);
  bm.recycle();
  return ret;
}

Fixed version (ground truth):
Bitmap screenshotApplicationsInner(IBinder appToken,int displayId,int width,int height,boolean includeFullDisplay,float frameScale,Bitmap.Config config){
  final DisplayContent displayContent;
synchronized (mWindowMap) {
    displayContent=getDisplayContentLocked(displayId);
    if (displayContent == null) {
      if (DEBUG_SCREENSHOT)       Slog.i(TAG_WM,"String_Node_Str" + appToken + "String_Node_Str"+ displayId);
      return null;
    }
  }
  final DisplayInfo displayInfo=displayContent.getDisplayInfo();
  int dw=displayInfo.logicalWidth;
  int dh=displayInfo.logicalHeight;
  if (dw == 0 || dh == 0) {
    if (DEBUG_SCREENSHOT)     Slog.i(TAG_WM,"String_Node_Str" + appToken + "String_Node_Str"+ dw+ "String_Node_Str"+ dh);
    return null;
  }
  Bitmap bm=null;
  int maxLayer=0;
  final Rect frame=new Rect();
  final Rect stackBounds=new Rect();
  boolean screenshotReady;
  int minLayer;
  if (appToken == null) {
    screenshotReady=true;
    minLayer=0;
  }
 else {
    screenshotReady=false;
    minLayer=Integer.MAX_VALUE;
  }
  WindowState appWin=null;
  boolean appIsImTarget;
synchronized (mWindowMap) {
    appIsImTarget=mInputMethodTarget != null && mInputMethodTarget.mAppToken != null && mInputMethodTarget.mAppToken.appToken != null && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
  }
  final int aboveAppLayer=(mPolicy.windowTypeToLayerLw(TYPE_APPLICATION) + 1) * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
synchronized (mWindowMap) {
    appWin=null;
    final WindowList windows=displayContent.getWindowList();
    for (int i=windows.size() - 1; i >= 0; i--) {
      WindowState ws=windows.get(i);
      if (!ws.mHasSurface) {
        continue;
      }
      if (ws.mLayer >= aboveAppLayer) {
        continue;
      }
      if (ws.mIsImWindow) {
        if (!appIsImTarget) {
          continue;
        }
      }
 else       if (ws.mIsWallpaper) {
        if (appWin == null) {
          continue;
        }
      }
 else       if (appToken != null) {
        if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
          continue;
        }
        appWin=ws;
      }
      final WindowStateAnimator winAnim=ws.mWinAnimator;
      int layer=winAnim.mSurfaceController.getLayer();
      if (maxLayer < layer) {
        maxLayer=layer;
      }
      if (minLayer > layer) {
        minLayer=layer;
      }
      if (!includeFullDisplay && !ws.mIsWallpaper) {
        final Rect wf=ws.mFrame;
        final Rect cr=ws.mContentInsets;
        int left=wf.left + cr.left;
        int top=wf.top + cr.top;
        int right=wf.right - cr.right;
        int bottom=wf.bottom - cr.bottom;
        frame.union(left,top,right,bottom);
        ws.getVisibleBounds(stackBounds);
        if (!Rect.intersects(frame,stackBounds)) {
          frame.setEmpty();
        }
      }
      if (ws.mAppToken != null && ws.mAppToken.token == appToken && ws.isDisplayedLw() && winAnim.getShown()) {
        screenshotReady=true;
      }
      if (ws.isObscuringFullscreen(displayInfo)) {
        break;
      }
    }
    if (appToken != null && appWin == null) {
      if (DEBUG_SCREENSHOT)       Slog.i(TAG_WM,"String_Node_Str" + appToken);
      return null;
    }
    if (!screenshotReady) {
      Slog.i(TAG_WM,"String_Node_Str" + appToken + "String_Node_Str"+ (appWin == null ? "String_Node_Str" : (appWin + "String_Node_Str" + appWin.mWinAnimator.mDrawState)));
      return null;
    }
    if (maxLayer == 0) {
      if (DEBUG_SCREENSHOT)       Slog.i(TAG_WM,"String_Node_Str" + appToken + "String_Node_Str"+ maxLayer);
      return null;
    }
    if (!includeFullDisplay) {
      if (!frame.intersect(0,0,dw,dh)) {
        frame.setEmpty();
      }
    }
 else {
      frame.set(0,0,dw,dh);
    }
    if (frame.isEmpty()) {
      return null;
    }
    if (width < 0) {
      width=(int)(frame.width() * frameScale);
    }
    if (height < 0) {
      height=(int)(frame.height() * frameScale);
    }
    Rect crop=new Rect(frame);
    if (width / (float)frame.width() < height / (float)frame.height()) {
      int cropWidth=(int)((float)width / (float)height * frame.height());
      crop.right=crop.left + cropWidth;
    }
 else {
      int cropHeight=(int)((float)height / (float)width * frame.width());
      crop.bottom=crop.top + cropHeight;
    }
    int rot=getDefaultDisplayContentLocked().getDisplay().getRotation();
    if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
      rot=(rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
    }
    convertCropForSurfaceFlinger(crop,rot,dw,dh);
    if (DEBUG_SCREENSHOT) {
      Slog.i(TAG_WM,"String_Node_Str" + dw + "String_Node_Str"+ dh+ "String_Node_Str"+ minLayer+ "String_Node_Str"+ maxLayer+ "String_Node_Str"+ appToken);
      for (int i=0; i < windows.size(); i++) {
        WindowState win=windows.get(i);
        WindowSurfaceController controller=win.mWinAnimator.mSurfaceController;
        Slog.i(TAG_WM,win + "String_Node_Str" + win.mLayer+ "String_Node_Str"+ win.mWinAnimator.mAnimLayer+ "String_Node_Str"+ ((controller == null) ? "String_Node_Str" : controller.getLayer()));
      }
    }
    ScreenRotationAnimation screenRotationAnimation=mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY);
    final boolean inRotation=screenRotationAnimation != null && screenRotationAnimation.isAnimating();
    if (DEBUG_SCREENSHOT && inRotation)     Slog.v(TAG_WM,"String_Node_Str");
    bm=SurfaceControl.screenshot(crop,width,height,minLayer,maxLayer,inRotation,rot);
    if (bm == null) {
      Slog.w(TAG_WM,"String_Node_Str" + dw + "String_Node_Str"+ dh+ "String_Node_Str"+ maxLayer);
      return null;
    }
  }
  if (DEBUG_SCREENSHOT) {
    int[] buffer=new int[bm.getWidth() * bm.getHeight()];
    bm.getPixels(buffer,0,bm.getWidth(),0,0,bm.getWidth(),bm.getHeight());
    boolean allBlack=true;
    final int firstColor=buffer[0];
    for (int i=0; i < buffer.length; i++) {
      if (buffer[i] != firstColor) {
        allBlack=false;
        break;
      }
    }
    if (allBlack) {
      Slog.i(TAG_WM,"String_Node_Str" + appWin + "String_Node_Str"+ Integer.toHexString(firstColor)+ "String_Node_Str"+ (appWin != null ? appWin.mWinAnimator.mSurfaceController.getLayer() : "String_Node_Str")+ "String_Node_Str"+ minLayer+ "String_Node_Str"+ maxLayer);
    }
  }
  Bitmap ret=bm.createAshmemBitmap(config);
  bm.recycle();
  return ret;
}