Program: 193938
Project: 193938
Buggy source:
SurfaceControl createSurfaceLocked(){
  final WindowState w=mWin;
  if (mSurfaceControl == null) {
    if (DEBUG_ANIM || DEBUG_ORIENTATION)     Slog.i(TAG,"String_Node_Str" + this + "String_Node_Str");
    mDrawState=DRAW_PENDING;
    if (w.mAppToken != null) {
      if (w.mAppToken.mAppAnimator.animation == null) {
        w.mAppToken.allDrawn=false;
        w.mAppToken.deferClearAllDrawn=false;
      }
 else {
        w.mAppToken.deferClearAllDrawn=true;
      }
    }
    mService.makeWindowFreezingScreenIfNeededLocked(w);
    int flags=SurfaceControl.HIDDEN;
    final WindowManager.LayoutParams attrs=w.mAttrs;
    if ((attrs.flags & WindowManager.LayoutParams.FLAG_SECURE) != 0) {
      flags|=SurfaceControl.SECURE;
    }
    if (mService.isScreenCaptureDisabledLocked(UserHandle.getUserId(mWin.mOwnerUid))) {
      flags|=SurfaceControl.SECURE;
    }
    int width;
    int height;
    if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) {
      width=w.mRequestedWidth;
      height=w.mRequestedHeight;
    }
 else {
      width=w.mCompatFrame.width();
      height=w.mCompatFrame.height();
    }
    if (width <= 0) {
      width=1;
    }
    if (height <= 0) {
      height=1;
    }
    float left=w.mFrame.left + w.mXOffset;
    float top=w.mFrame.top + w.mYOffset;
    width+=attrs.surfaceInsets.left + attrs.surfaceInsets.right;
    height+=attrs.surfaceInsets.top + attrs.surfaceInsets.bottom;
    left-=attrs.surfaceInsets.left;
    top-=attrs.surfaceInsets.top;
    if (DEBUG_VISIBILITY) {
      Slog.v(TAG,"String_Node_Str" + mSession.mSurfaceSession + "String_Node_Str"+ this+ "String_Node_Str"+ width+ "String_Node_Str"+ height+ "String_Node_Str"+ left+ "String_Node_Str"+ top+ "String_Node_Str"+ attrs.format+ "String_Node_Str"+ flags);
    }
    mSurfaceShown=false;
    mSurfaceLayer=0;
    mSurfaceAlpha=0;
    mSurfaceX=0;
    mSurfaceY=0;
    w.mLastSystemDecorRect.set(0,0,0,0);
    mLastClipRect.set(0,0,0,0);
    try {
      mSurfaceW=width;
      mSurfaceH=height;
      final boolean isHwAccelerated=(attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
      final int format=isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
      if (!PixelFormat.formatHasAlpha(attrs.format) && attrs.surfaceInsets.left == 0 && attrs.surfaceInsets.top == 0 && attrs.surfaceInsets.right == 0 && attrs.surfaceInsets.bottom == 0) {
        flags|=SurfaceControl.OPAQUE;
      }
      mSurfaceFormat=format;
      if (DEBUG_SURFACE_TRACE) {
        mSurfaceControl=new SurfaceTrace(mSession.mSurfaceSession,attrs.getTitle().toString(),width,height,format,flags);
      }
 else {
        mSurfaceControl=new SurfaceControl(mSession.mSurfaceSession,attrs.getTitle().toString(),width,height,format,flags);
      }
      w.mHasSurface=true;
      if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
        Slog.i(TAG,"String_Node_Str" + mSurfaceControl + "String_Node_Str"+ mSession.mSurfaceSession+ "String_Node_Str"+ mSession.mPid+ "String_Node_Str"+ attrs.format+ "String_Node_Str"+ Integer.toHexString(flags)+ "String_Node_Str"+ this);
      }
    }
 catch (    OutOfResourcesException e) {
      w.mHasSurface=false;
      Slog.w(TAG,"String_Node_Str");
      mService.reclaimSomeSurfaceMemoryLocked(this,"String_Node_Str",true);
      mDrawState=NO_SURFACE;
      return null;
    }
catch (    Exception e) {
      w.mHasSurface=false;
      Slog.e(TAG,"String_Node_Str",e);
      mDrawState=NO_SURFACE;
      return null;
    }
    if (WindowManagerService.localLOGV) {
      Slog.v(TAG,"String_Node_Str" + mSurfaceControl + "String_Node_Str"+ w.mFrame.left+ "String_Node_Str"+ w.mFrame.top+ "String_Node_Str"+ mAnimLayer);
    }
    if (SHOW_LIGHT_TRANSACTIONS) {
      Slog.i(TAG,"String_Node_Str");
      WindowManagerService.logSurface(w,"String_Node_Str" + w.mFrame.left + "String_Node_Str"+ w.mFrame.top+ "String_Node_Str"+ w.mCompatFrame.width()+ "String_Node_Str"+ w.mCompatFrame.height()+ "String_Node_Str"+ mAnimLayer+ "String_Node_Str",null);
    }
    SurfaceControl.openTransaction();
    try {
      mSurfaceX=left;
      mSurfaceY=top;
      try {
        mSurfaceControl.setPosition(left,top);
        mSurfaceLayer=mAnimLayer;
        final DisplayContent displayContent=w.getDisplayContent();
        if (displayContent != null) {
          mSurfaceControl.setLayerStack(displayContent.getDisplay().getLayerStack());
        }
        mSurfaceControl.setLayer(mAnimLayer);
        mSurfaceControl.setAlpha(0);
        mSurfaceShown=false;
      }
 catch (      RuntimeException e) {
        Slog.w(TAG,"String_Node_Str" + w,e);
        mService.reclaimSomeSurfaceMemoryLocked(this,"String_Node_Str",true);
      }
      mLastHidden=true;
    }
  finally {
      SurfaceControl.closeTransaction();
      if (SHOW_LIGHT_TRANSACTIONS)       Slog.i(TAG,"String_Node_Str");
    }
    if (WindowManagerService.localLOGV)     Slog.v(TAG,"String_Node_Str" + this);
  }
  return mSurfaceControl;
}

Fixed version (ground truth):
SurfaceControl createSurfaceLocked(){
  final WindowState w=mWin;
  if (mSurfaceControl == null) {
    if (DEBUG_ANIM || DEBUG_ORIENTATION)     Slog.i(TAG,"String_Node_Str" + this + "String_Node_Str");
    mDrawState=DRAW_PENDING;
    if (w.mAppToken != null) {
      if (w.mAppToken.mAppAnimator.animation == null) {
        w.mAppToken.allDrawn=false;
        w.mAppToken.deferClearAllDrawn=false;
      }
 else {
        w.mAppToken.deferClearAllDrawn=true;
      }
    }
    mService.makeWindowFreezingScreenIfNeededLocked(w);
    int flags=SurfaceControl.HIDDEN;
    final WindowManager.LayoutParams attrs=w.mAttrs;
    if (mService.isSecureLocked(w)) {
      flags|=SurfaceControl.SECURE;
    }
    int width;
    int height;
    if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) {
      width=w.mRequestedWidth;
      height=w.mRequestedHeight;
    }
 else {
      width=w.mCompatFrame.width();
      height=w.mCompatFrame.height();
    }
    if (width <= 0) {
      width=1;
    }
    if (height <= 0) {
      height=1;
    }
    float left=w.mFrame.left + w.mXOffset;
    float top=w.mFrame.top + w.mYOffset;
    width+=attrs.surfaceInsets.left + attrs.surfaceInsets.right;
    height+=attrs.surfaceInsets.top + attrs.surfaceInsets.bottom;
    left-=attrs.surfaceInsets.left;
    top-=attrs.surfaceInsets.top;
    if (DEBUG_VISIBILITY) {
      Slog.v(TAG,"String_Node_Str" + mSession.mSurfaceSession + "String_Node_Str"+ this+ "String_Node_Str"+ width+ "String_Node_Str"+ height+ "String_Node_Str"+ left+ "String_Node_Str"+ top+ "String_Node_Str"+ attrs.format+ "String_Node_Str"+ flags);
    }
    mSurfaceShown=false;
    mSurfaceLayer=0;
    mSurfaceAlpha=0;
    mSurfaceX=0;
    mSurfaceY=0;
    w.mLastSystemDecorRect.set(0,0,0,0);
    mLastClipRect.set(0,0,0,0);
    try {
      mSurfaceW=width;
      mSurfaceH=height;
      final boolean isHwAccelerated=(attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
      final int format=isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
      if (!PixelFormat.formatHasAlpha(attrs.format) && attrs.surfaceInsets.left == 0 && attrs.surfaceInsets.top == 0 && attrs.surfaceInsets.right == 0 && attrs.surfaceInsets.bottom == 0) {
        flags|=SurfaceControl.OPAQUE;
      }
      mSurfaceFormat=format;
      if (DEBUG_SURFACE_TRACE) {
        mSurfaceControl=new SurfaceTrace(mSession.mSurfaceSession,attrs.getTitle().toString(),width,height,format,flags);
      }
 else {
        mSurfaceControl=new SurfaceControl(mSession.mSurfaceSession,attrs.getTitle().toString(),width,height,format,flags);
      }
      w.mHasSurface=true;
      if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
        Slog.i(TAG,"String_Node_Str" + mSurfaceControl + "String_Node_Str"+ mSession.mSurfaceSession+ "String_Node_Str"+ mSession.mPid+ "String_Node_Str"+ attrs.format+ "String_Node_Str"+ Integer.toHexString(flags)+ "String_Node_Str"+ this);
      }
    }
 catch (    OutOfResourcesException e) {
      w.mHasSurface=false;
      Slog.w(TAG,"String_Node_Str");
      mService.reclaimSomeSurfaceMemoryLocked(this,"String_Node_Str",true);
      mDrawState=NO_SURFACE;
      return null;
    }
catch (    Exception e) {
      w.mHasSurface=false;
      Slog.e(TAG,"String_Node_Str",e);
      mDrawState=NO_SURFACE;
      return null;
    }
    if (WindowManagerService.localLOGV) {
      Slog.v(TAG,"String_Node_Str" + mSurfaceControl + "String_Node_Str"+ w.mFrame.left+ "String_Node_Str"+ w.mFrame.top+ "String_Node_Str"+ mAnimLayer);
    }
    if (SHOW_LIGHT_TRANSACTIONS) {
      Slog.i(TAG,"String_Node_Str");
      WindowManagerService.logSurface(w,"String_Node_Str" + w.mFrame.left + "String_Node_Str"+ w.mFrame.top+ "String_Node_Str"+ w.mCompatFrame.width()+ "String_Node_Str"+ w.mCompatFrame.height()+ "String_Node_Str"+ mAnimLayer+ "String_Node_Str",null);
    }
    SurfaceControl.openTransaction();
    try {
      mSurfaceX=left;
      mSurfaceY=top;
      try {
        mSurfaceControl.setPosition(left,top);
        mSurfaceLayer=mAnimLayer;
        final DisplayContent displayContent=w.getDisplayContent();
        if (displayContent != null) {
          mSurfaceControl.setLayerStack(displayContent.getDisplay().getLayerStack());
        }
        mSurfaceControl.setLayer(mAnimLayer);
        mSurfaceControl.setAlpha(0);
        mSurfaceShown=false;
      }
 catch (      RuntimeException e) {
        Slog.w(TAG,"String_Node_Str" + w,e);
        mService.reclaimSomeSurfaceMemoryLocked(this,"String_Node_Str",true);
      }
      mLastHidden=true;
    }
  finally {
      SurfaceControl.closeTransaction();
      if (SHOW_LIGHT_TRANSACTIONS)       Slog.i(TAG,"String_Node_Str");
    }
    if (WindowManagerService.localLOGV)     Slog.v(TAG,"String_Node_Str" + this);
  }
  return mSurfaceControl;
}