Program: 42786
Project: 42786
Buggy source:
public int relayoutWindow(Session session,IWindow client,WindowManager.LayoutParams attrs,int requestedWidth,int requestedHeight,int viewVisibility,boolean insetsPending,Rect outFrame,Rect outContentInsets,Rect outVisibleInsets,Surface outSurface){
  boolean displayed=false;
  boolean inTouchMode;
  Configuration newConfig=null;
  long origId=Binder.clearCallingIdentity();
synchronized (mWindowMap) {
    WindowState win=windowForClientLocked(session,client);
    if (win == null) {
      return 0;
    }
    win.mRequestedWidth=requestedWidth;
    win.mRequestedHeight=requestedHeight;
    if (attrs != null) {
      mPolicy.adjustWindowParamsLw(attrs);
    }
    int attrChanges=0;
    int flagChanges=0;
    if (attrs != null) {
      flagChanges=win.mAttrs.flags^=attrs.flags;
      attrChanges=win.mAttrs.copyFrom(attrs);
    }
    if (localLOGV)     Log.v(TAG,"String_Node_Str" + client.asBinder() + "String_Node_Str"+ win.mAttrs.getTitle()+ "String_Node_Str");
    if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
      win.mAlpha=attrs.alpha;
    }
    final boolean scaledWindow=((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
    if (scaledWindow) {
      win.mHScale=(attrs.width != requestedWidth) ? (attrs.width / (float)requestedWidth) : 1.0f;
      win.mVScale=(attrs.height != requestedHeight) ? (attrs.height / (float)requestedHeight) : 1.0f;
    }
    boolean imMayMove=(flagChanges & (WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
    boolean focusMayChange=win.mViewVisibility != viewVisibility || ((flagChanges & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) || (!win.mRelayoutCalled);
    boolean wallpaperMayMove=win.mViewVisibility != viewVisibility && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
    win.mRelayoutCalled=true;
    final int oldVisibility=win.mViewVisibility;
    win.mViewVisibility=viewVisibility;
    if (viewVisibility == View.VISIBLE && (win.mAppToken == null || !win.mAppToken.clientHidden)) {
      displayed=!win.isVisibleLw();
      if (win.mExiting) {
        win.mExiting=false;
        win.mAnimation=null;
      }
      if (win.mDestroying) {
        win.mDestroying=false;
        mDestroySurface.remove(win);
      }
      if (oldVisibility == View.GONE) {
        win.mEnterAnimationPending=true;
      }
      if (displayed && win.mSurface != null && !win.mDrawPending && !win.mCommitDrawPending && !mDisplayFrozen) {
        applyEnterAnimationLocked(win);
      }
      if (displayed && (win.mAttrs.flags & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
        win.mTurnOnScreen=true;
      }
      if ((attrChanges & WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
        win.destroySurfaceLocked();
        displayed=true;
      }
      try {
        Surface surface=win.createSurfaceLocked();
        if (surface != null) {
          outSurface.copyFrom(surface);
          win.mReportDestroySurface=false;
          win.mSurfacePendingDestroy=false;
          if (SHOW_TRANSACTIONS)           Log.i(TAG,"String_Node_Str" + outSurface + "String_Node_Str");
        }
 else {
          outSurface.release();
        }
      }
 catch (      Exception e) {
        Log.w(TAG,"String_Node_Str" + client + "String_Node_Str"+ win.mAttrs.getTitle()+ "String_Node_Str",e);
        Binder.restoreCallingIdentity(origId);
        return 0;
      }
      if (displayed) {
        focusMayChange=true;
      }
      if (win.mAttrs.type == TYPE_INPUT_METHOD && mInputMethodWindow == null) {
        mInputMethodWindow=win;
        imMayMove=true;
      }
    }
 else {
      win.mEnterAnimationPending=false;
      if (win.mSurface != null) {
        if (DEBUG_VISIBILITY)         Log.i(TAG,"String_Node_Str" + win + "String_Node_Str"+ win.mExiting+ "String_Node_Str"+ win.mSurfacePendingDestroy);
        if (!win.mExiting || win.mSurfacePendingDestroy) {
          int transit=WindowManagerPolicy.TRANSIT_EXIT;
          if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
            transit=WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
          }
          if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && applyAnimationLocked(win,transit,false)) {
            focusMayChange=true;
            win.mExiting=true;
            mKeyWaiter.finishedKey(session,client,true,KeyWaiter.RETURN_NOTHING);
          }
 else           if (win.isAnimating()) {
            win.mExiting=true;
          }
 else           if (win == mWallpaperTarget) {
            win.mExiting=true;
            win.mAnimating=true;
          }
 else {
            if (mInputMethodWindow == win) {
              mInputMethodWindow=null;
            }
            win.destroySurfaceLocked();
          }
        }
      }
      if (win.mSurface == null || (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 || win.mSurfacePendingDestroy) {
        win.mSurfacePendingDestroy=false;
        outSurface.release();
        if (DEBUG_VISIBILITY)         Log.i(TAG,"String_Node_Str" + win);
      }
 else       if (win.mSurface != null) {
        if (DEBUG_VISIBILITY)         Log.i(TAG,"String_Node_Str" + win);
        win.mReportDestroySurface=true;
        outSurface.copyFrom(win.mSurface);
      }
    }
    if (focusMayChange) {
      if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
        imMayMove=false;
      }
    }
    boolean assignLayers=false;
    if (imMayMove) {
      if (moveInputMethodWindowsIfNeededLocked(false)) {
        assignLayers=true;
      }
    }
    if (wallpaperMayMove) {
      if ((adjustWallpaperWindowsLocked() & ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
        assignLayers=true;
      }
    }
    mLayoutNeeded=true;
    win.mGivenInsetsPending=insetsPending;
    if (assignLayers) {
      assignLayersLocked();
    }
    newConfig=updateOrientationFromAppTokensLocked(null,null);
    performLayoutAndPlaceSurfacesLocked();
    if (displayed && win.mIsWallpaper) {
      updateWallpaperOffsetLocked(win,mDisplay.getWidth(),mDisplay.getHeight(),false);
    }
    if (win.mAppToken != null) {
      win.mAppToken.updateReportedVisibilityLocked();
    }
    outFrame.set(win.mFrame);
    outContentInsets.set(win.mContentInsets);
    outVisibleInsets.set(win.mVisibleInsets);
    if (localLOGV)     Log.v(TAG,"String_Node_Str" + client.asBinder() + "String_Node_Str"+ requestedWidth+ "String_Node_Str"+ requestedHeight+ "String_Node_Str"+ viewVisibility+ "String_Node_Str"+ outFrame+ "String_Node_Str"+ outSurface);
    if (localLOGV || DEBUG_FOCUS)     Log.v(TAG,"String_Node_Str" + win + "String_Node_Str"+ focusMayChange);
    inTouchMode=mInTouchMode;
  }
  if (newConfig != null) {
    sendNewConfiguration();
  }
  Binder.restoreCallingIdentity(origId);
  return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
}

Fixed version (ground truth):
public int relayoutWindow(Session session,IWindow client,WindowManager.LayoutParams attrs,int requestedWidth,int requestedHeight,int viewVisibility,boolean insetsPending,Rect outFrame,Rect outContentInsets,Rect outVisibleInsets,Surface outSurface){
  boolean displayed=false;
  boolean inTouchMode;
  Configuration newConfig=null;
  long origId=Binder.clearCallingIdentity();
synchronized (mWindowMap) {
    WindowState win=windowForClientLocked(session,client);
    if (win == null) {
      return 0;
    }
    win.mRequestedWidth=requestedWidth;
    win.mRequestedHeight=requestedHeight;
    if (attrs != null) {
      mPolicy.adjustWindowParamsLw(attrs);
    }
    int attrChanges=0;
    int flagChanges=0;
    if (attrs != null) {
      flagChanges=win.mAttrs.flags^=attrs.flags;
      attrChanges=win.mAttrs.copyFrom(attrs);
    }
    if (localLOGV)     Log.v(TAG,"String_Node_Str" + client.asBinder() + "String_Node_Str"+ win.mAttrs.getTitle()+ "String_Node_Str");
    if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
      win.mAlpha=attrs.alpha;
    }
    final boolean scaledWindow=((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
    if (scaledWindow) {
      win.mHScale=(attrs.width != requestedWidth) ? (attrs.width / (float)requestedWidth) : 1.0f;
      win.mVScale=(attrs.height != requestedHeight) ? (attrs.height / (float)requestedHeight) : 1.0f;
    }
    boolean imMayMove=(flagChanges & (WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0;
    boolean focusMayChange=win.mViewVisibility != viewVisibility || ((flagChanges & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) || (!win.mRelayoutCalled);
    boolean wallpaperMayMove=win.mViewVisibility != viewVisibility && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
    win.mRelayoutCalled=true;
    final int oldVisibility=win.mViewVisibility;
    win.mViewVisibility=viewVisibility;
    if (viewVisibility == View.VISIBLE && (win.mAppToken == null || !win.mAppToken.clientHidden)) {
      displayed=!win.isVisibleLw();
      if (win.mExiting) {
        win.mExiting=false;
        win.mAnimation=null;
      }
      if (win.mDestroying) {
        win.mDestroying=false;
        mDestroySurface.remove(win);
      }
      if (oldVisibility == View.GONE) {
        win.mEnterAnimationPending=true;
      }
      if (displayed && win.mSurface != null && !win.mDrawPending && !win.mCommitDrawPending && !mDisplayFrozen) {
        applyEnterAnimationLocked(win);
      }
      if (displayed && (win.mAttrs.flags & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
        win.mTurnOnScreen=true;
      }
      if ((attrChanges & WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
        win.destroySurfaceLocked();
        displayed=true;
      }
      try {
        Surface surface=win.createSurfaceLocked();
        if (surface != null) {
          outSurface.copyFrom(surface);
          win.mReportDestroySurface=false;
          win.mSurfacePendingDestroy=false;
          if (SHOW_TRANSACTIONS)           Log.i(TAG,"String_Node_Str" + outSurface + "String_Node_Str");
        }
 else {
          outSurface.release();
        }
      }
 catch (      Exception e) {
        Log.w(TAG,"String_Node_Str" + client + "String_Node_Str"+ win.mAttrs.getTitle()+ "String_Node_Str",e);
        Binder.restoreCallingIdentity(origId);
        return 0;
      }
      if (displayed) {
        focusMayChange=true;
      }
      if (win.mAttrs.type == TYPE_INPUT_METHOD && mInputMethodWindow == null) {
        mInputMethodWindow=win;
        imMayMove=true;
      }
    }
 else {
      win.mEnterAnimationPending=false;
      if (win.mSurface != null) {
        if (DEBUG_VISIBILITY)         Log.i(TAG,"String_Node_Str" + win + "String_Node_Str"+ win.mExiting+ "String_Node_Str"+ win.mSurfacePendingDestroy);
        if (!win.mExiting || win.mSurfacePendingDestroy) {
          int transit=WindowManagerPolicy.TRANSIT_EXIT;
          if (win.getAttrs().type == TYPE_APPLICATION_STARTING) {
            transit=WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
          }
          if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && applyAnimationLocked(win,transit,false)) {
            focusMayChange=true;
            win.mExiting=true;
            mKeyWaiter.finishedKey(session,client,true,KeyWaiter.RETURN_NOTHING);
          }
 else           if (win.isAnimating()) {
            win.mExiting=true;
          }
 else           if (win == mWallpaperTarget) {
            win.mExiting=true;
            win.mAnimating=true;
          }
 else {
            if (mInputMethodWindow == win) {
              mInputMethodWindow=null;
            }
            win.destroySurfaceLocked();
          }
        }
      }
      if (win.mSurface == null || (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 || win.mSurfacePendingDestroy) {
        win.mSurfacePendingDestroy=false;
        outSurface.release();
        if (DEBUG_VISIBILITY)         Log.i(TAG,"String_Node_Str" + win);
      }
 else       if (win.mSurface != null) {
        if (DEBUG_VISIBILITY)         Log.i(TAG,"String_Node_Str" + win);
        win.mReportDestroySurface=true;
        outSurface.copyFrom(win.mSurface);
      }
    }
    if (focusMayChange) {
      if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) {
        imMayMove=false;
      }
    }
    boolean assignLayers=false;
    if (imMayMove) {
      if (moveInputMethodWindowsIfNeededLocked(false) || displayed) {
        assignLayers=true;
      }
    }
    if (wallpaperMayMove) {
      if ((adjustWallpaperWindowsLocked() & ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
        assignLayers=true;
      }
    }
    mLayoutNeeded=true;
    win.mGivenInsetsPending=insetsPending;
    if (assignLayers) {
      assignLayersLocked();
    }
    newConfig=updateOrientationFromAppTokensLocked(null,null);
    performLayoutAndPlaceSurfacesLocked();
    if (displayed && win.mIsWallpaper) {
      updateWallpaperOffsetLocked(win,mDisplay.getWidth(),mDisplay.getHeight(),false);
    }
    if (win.mAppToken != null) {
      win.mAppToken.updateReportedVisibilityLocked();
    }
    outFrame.set(win.mFrame);
    outContentInsets.set(win.mContentInsets);
    outVisibleInsets.set(win.mVisibleInsets);
    if (localLOGV)     Log.v(TAG,"String_Node_Str" + client.asBinder() + "String_Node_Str"+ requestedWidth+ "String_Node_Str"+ requestedHeight+ "String_Node_Str"+ viewVisibility+ "String_Node_Str"+ outFrame+ "String_Node_Str"+ outSurface);
    if (localLOGV || DEBUG_FOCUS)     Log.v(TAG,"String_Node_Str" + win + "String_Node_Str"+ focusMayChange);
    inTouchMode=mInTouchMode;
  }
  if (newConfig != null) {
    sendNewConfiguration();
  }
  Binder.restoreCallingIdentity(origId);
  return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
}