Program: 22966
Project: 22966
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;
  boolean configChanged;
  long origId=Binder.clearCallingIdentity();
synchronized (mWindowMap) {
    WindowState win=windowForClientLocked(session,client,false);
    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 (DEBUG_LAYOUT)     Slog.v(TAG,"String_Node_Str" + win + "String_Node_Str"+ win.mAttrs);
    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;
    }
 else {
      win.mHScale=win.mVScale=1;
    }
    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 && mPolicy.isScreenOn()) {
        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)           Slog.i(TAG,"String_Node_Str" + outSurface + "String_Node_Str");
        }
 else {
          outSurface.release();
        }
      }
 catch (      Exception e) {
        Slog.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;
      }
      if (win.mAttrs.type == TYPE_BASE_APPLICATION && win.mAppToken != null && win.mAppToken.startingWindow != null) {
        final int mask=WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
        WindowManager.LayoutParams sa=win.mAppToken.startingWindow.mAttrs;
        sa.flags=(sa.flags & ~mask) | (win.mAttrs.flags & mask);
      }
    }
 else {
      win.mEnterAnimationPending=false;
      if (win.mSurface != null) {
        if (DEBUG_VISIBILITY)         Slog.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)         Slog.i(TAG,"String_Node_Str" + win);
      }
 else       if (win.mSurface != null) {
        if (DEBUG_VISIBILITY)         Slog.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();
    }
    configChanged=updateOrientationFromAppTokensLocked();
    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)     Slog.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)     Slog.v(TAG,"String_Node_Str" + win + "String_Node_Str"+ focusMayChange);
    inTouchMode=mInTouchMode;
  }
  if (configChanged) {
    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;
  boolean configChanged;
  long origId=Binder.clearCallingIdentity();
synchronized (mWindowMap) {
    WindowState win=windowForClientLocked(session,client,false);
    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 (DEBUG_LAYOUT)     Slog.v(TAG,"String_Node_Str" + win + "String_Node_Str"+ win.mAttrs);
    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;
    }
 else {
      win.mHScale=win.mVScale=1;
    }
    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 && mPolicy.isScreenOn()) {
        applyEnterAnimationLocked(win);
      }
      if (displayed && (win.mAttrs.flags & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
        if (DEBUG_VISIBILITY)         Slog.v(TAG,"String_Node_Str" + win);
        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)           Slog.i(TAG,"String_Node_Str" + outSurface + "String_Node_Str");
        }
 else {
          outSurface.release();
        }
      }
 catch (      Exception e) {
        Slog.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;
      }
      if (win.mAttrs.type == TYPE_BASE_APPLICATION && win.mAppToken != null && win.mAppToken.startingWindow != null) {
        final int mask=WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
        WindowManager.LayoutParams sa=win.mAppToken.startingWindow.mAttrs;
        sa.flags=(sa.flags & ~mask) | (win.mAttrs.flags & mask);
      }
    }
 else {
      win.mEnterAnimationPending=false;
      if (win.mSurface != null) {
        if (DEBUG_VISIBILITY)         Slog.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)         Slog.i(TAG,"String_Node_Str" + win);
      }
 else       if (win.mSurface != null) {
        if (DEBUG_VISIBILITY)         Slog.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();
    }
    configChanged=updateOrientationFromAppTokensLocked();
    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)     Slog.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)     Slog.v(TAG,"String_Node_Str" + win + "String_Node_Str"+ focusMayChange);
    inTouchMode=mInTouchMode;
  }
  if (configChanged) {
    sendNewConfiguration();
  }
  Binder.restoreCallingIdentity(origId);
  return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0);
}