Program: 807
Project: 807
Buggy source:
public int relayoutWindow(Session session,IWindow client,int seq,WindowManager.LayoutParams attrs,int requestedWidth,int requestedHeight,int viewVisibility,int flags,Rect outFrame,Rect outOverscanInsets,Rect outContentInsets,Rect outVisibleInsets,Configuration outConfig,Surface outSurface){
  boolean toBeDisplayed=false;
  boolean inTouchMode;
  boolean configChanged;
  boolean surfaceChanged=false;
  boolean animating;
  int systemUiVisibility=0;
  if (attrs != null) {
    systemUiVisibility=(attrs.systemUiVisibility | attrs.subtreeSystemUiVisibility);
    if ((systemUiVisibility & StatusBarManager.DISABLE_MASK) != 0) {
      if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR) != PackageManager.PERMISSION_GRANTED) {
        systemUiVisibility&=~StatusBarManager.DISABLE_MASK;
      }
    }
  }
  long origId=Binder.clearCallingIdentity();
synchronized (mWindowMap) {
    WindowState win=windowForClientLocked(session,client,false);
    if (win == null) {
      return 0;
    }
    WindowStateAnimator winAnimator=win.mWinAnimator;
    if (win.mRequestedWidth != requestedWidth || win.mRequestedHeight != requestedHeight) {
      win.mLayoutNeeded=true;
      win.mRequestedWidth=requestedWidth;
      win.mRequestedHeight=requestedHeight;
    }
    if (attrs != null && seq == win.mSeq) {
      win.mSystemUiVisibility=systemUiVisibility;
    }
    if (attrs != null) {
      mPolicy.adjustWindowParamsLw(attrs);
    }
    winAnimator.mSurfaceDestroyDeferred=(flags & WindowManagerGlobal.RELAYOUT_DEFER_SURFACE_DESTROY) != 0;
    int attrChanges=0;
    int flagChanges=0;
    if (attrs != null) {
      if (win.mAttrs.type != attrs.type) {
        throw new IllegalArgumentException("String_Node_Str");
      }
      flagChanges=win.mAttrs.flags^=attrs.flags;
      attrChanges=win.mAttrs.copyFrom(attrs);
      if ((attrChanges & (WindowManager.LayoutParams.LAYOUT_CHANGED | WindowManager.LayoutParams.SYSTEM_UI_VISIBILITY_CHANGED)) != 0) {
        win.mLayoutNeeded=true;
      }
    }
    if (DEBUG_LAYOUT)     Slog.v(TAG,"String_Node_Str" + win + "String_Node_Str"+ viewVisibility+ "String_Node_Str"+ requestedWidth+ "String_Node_Str"+ requestedHeight+ "String_Node_Str"+ win.mAttrs);
    win.mEnforceSizeCompat=(win.mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
    if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
      winAnimator.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 & (FLAG_ALT_FOCUSABLE_IM | FLAG_NOT_FOCUSABLE)) != 0;
    final boolean isDefaultDisplay=win.isDefaultDisplay();
    boolean focusMayChange=isDefaultDisplay && (win.mViewVisibility != viewVisibility || ((flagChanges & FLAG_NOT_FOCUSABLE) != 0) || (!win.mRelayoutCalled));
    boolean wallpaperMayMove=win.mViewVisibility != viewVisibility && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
    wallpaperMayMove|=(flagChanges & FLAG_SHOW_WALLPAPER) != 0;
    win.mRelayoutCalled=true;
    final int oldVisibility=win.mViewVisibility;
    win.mViewVisibility=viewVisibility;
    if (DEBUG_SCREEN_ON) {
      RuntimeException stack=new RuntimeException();
      stack.fillInStackTrace();
      Slog.i(TAG,"String_Node_Str" + win + "String_Node_Str"+ oldVisibility+ "String_Node_Str"+ viewVisibility,stack);
    }
    if (viewVisibility == View.VISIBLE && (win.mAppToken == null || !win.mAppToken.clientHidden)) {
      toBeDisplayed=!win.isVisibleLw();
      if (win.mExiting) {
        winAnimator.cancelExitAnimationForNextAnimationLocked();
        win.mExiting=false;
      }
      if (win.mDestroying) {
        win.mDestroying=false;
        mDestroySurface.remove(win);
      }
      if (oldVisibility == View.GONE) {
        winAnimator.mEnterAnimationPending=true;
      }
      if (toBeDisplayed) {
        if (win.isDrawnLw() && okToDisplay()) {
          winAnimator.applyEnterAnimationLocked();
        }
        if ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
          if (DEBUG_VISIBILITY)           Slog.v(TAG,"String_Node_Str" + win);
          win.mTurnOnScreen=true;
        }
        if (win.isConfigChanged()) {
          if (DEBUG_CONFIGURATION)           Slog.i(TAG,"String_Node_Str" + win + "String_Node_Str"+ mCurConfiguration);
          outConfig.setTo(mCurConfiguration);
        }
      }
      if ((attrChanges & WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
        winAnimator.destroySurfaceLocked();
        toBeDisplayed=true;
        surfaceChanged=true;
      }
      try {
        if (!win.mHasSurface) {
          surfaceChanged=true;
        }
        SurfaceControl surfaceControl=winAnimator.createSurfaceLocked();
        if (surfaceControl != null) {
          outSurface.copyFrom(surfaceControl);
          if (SHOW_TRANSACTIONS)           Slog.i(TAG,"String_Node_Str" + outSurface + "String_Node_Str");
        }
 else {
          outSurface.release();
        }
      }
 catch (      Exception e) {
        mInputMonitor.updateInputWindowsLw(true);
        Slog.w(TAG,"String_Node_Str" + client + "String_Node_Str"+ win.mAttrs.getTitle()+ "String_Node_Str",e);
        Binder.restoreCallingIdentity(origId);
        return 0;
      }
      if (toBeDisplayed) {
        focusMayChange=isDefaultDisplay;
      }
      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 {
      winAnimator.mEnterAnimationPending=false;
      if (winAnimator.mSurfaceControl != null) {
        if (DEBUG_VISIBILITY)         Slog.i(TAG,"String_Node_Str" + win + "String_Node_Str"+ win.mExiting);
        if (!win.mExiting) {
          surfaceChanged=true;
          int transit=WindowManagerPolicy.TRANSIT_EXIT;
          if (win.mAttrs.type == TYPE_APPLICATION_STARTING) {
            transit=WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
          }
          if (win.isWinVisibleLw() && winAnimator.applyAnimationLocked(transit,false)) {
            focusMayChange=isDefaultDisplay;
            win.mExiting=true;
          }
 else           if (win.mWinAnimator.isAnimating()) {
            win.mExiting=true;
          }
 else           if (win == mWallpaperTarget) {
            win.mExiting=true;
            win.mWinAnimator.mAnimating=true;
          }
 else {
            if (mInputMethodWindow == win) {
              mInputMethodWindow=null;
            }
            winAnimator.destroySurfaceLocked();
          }
          if (mDisplayMagnifier != null && win.getDisplayId() == Display.DEFAULT_DISPLAY) {
            mDisplayMagnifier.onWindowTransitionLocked(win,transit);
          }
        }
      }
      outSurface.release();
      if (DEBUG_VISIBILITY)       Slog.i(TAG,"String_Node_Str" + win);
    }
    if (focusMayChange) {
      if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,false)) {
        imMayMove=false;
      }
    }
    if (imMayMove && (moveInputMethodWindowsIfNeededLocked(false) || toBeDisplayed)) {
      assignLayersLocked(win.getWindowList());
    }
    if (wallpaperMayMove) {
      getDefaultDisplayContentLocked().pendingLayoutChanges|=WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
    }
    win.mDisplayContent.layoutNeeded=true;
    win.mGivenInsetsPending=(flags & WindowManagerGlobal.RELAYOUT_INSETS_PENDING) != 0;
    configChanged=updateOrientationFromAppTokensLocked(false);
    performLayoutAndPlaceSurfacesLocked();
    if (toBeDisplayed && win.mIsWallpaper) {
      DisplayInfo displayInfo=getDefaultDisplayInfoLocked();
      updateWallpaperOffsetLocked(win,displayInfo.logicalWidth,displayInfo.logicalHeight,false);
    }
    if (win.mAppToken != null) {
      win.mAppToken.updateReportedVisibilityLocked();
    }
    outFrame.set(win.mCompatFrame);
    outOverscanInsets.set(win.mOverscanInsets);
    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;
    animating=mAnimator.mAnimating;
    if (animating && !mRelayoutWhileAnimating.contains(win)) {
      mRelayoutWhileAnimating.add(win);
    }
    mInputMonitor.updateInputWindowsLw(true);
    if (DEBUG_LAYOUT) {
      Slog.v(TAG,"String_Node_Str" + win + "String_Node_Str"+ outFrame.toShortString());
    }
  }
  if (configChanged) {
    sendNewConfiguration();
  }
  Binder.restoreCallingIdentity(origId);
  return (inTouchMode ? WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE : 0) | (toBeDisplayed ? WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME : 0) | (surfaceChanged ? WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED : 0)| (animating ? WindowManagerGlobal.RELAYOUT_RES_ANIMATING : 0);
}

Fixed version (ground truth):
public int relayoutWindow(Session session,IWindow client,int seq,WindowManager.LayoutParams attrs,int requestedWidth,int requestedHeight,int viewVisibility,int flags,Rect outFrame,Rect outOverscanInsets,Rect outContentInsets,Rect outVisibleInsets,Configuration outConfig,Surface outSurface){
  boolean toBeDisplayed=false;
  boolean inTouchMode;
  boolean configChanged;
  boolean surfaceChanged=false;
  boolean animating;
  int systemUiVisibility=0;
  if (attrs != null) {
    systemUiVisibility=(attrs.systemUiVisibility | attrs.subtreeSystemUiVisibility);
    if ((systemUiVisibility & StatusBarManager.DISABLE_MASK) != 0) {
      if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR) != PackageManager.PERMISSION_GRANTED) {
        systemUiVisibility&=~StatusBarManager.DISABLE_MASK;
      }
    }
  }
  long origId=Binder.clearCallingIdentity();
synchronized (mWindowMap) {
    WindowState win=windowForClientLocked(session,client,false);
    if (win == null) {
      return 0;
    }
    WindowStateAnimator winAnimator=win.mWinAnimator;
    if (win.mRequestedWidth != requestedWidth || win.mRequestedHeight != requestedHeight) {
      win.mLayoutNeeded=true;
      win.mRequestedWidth=requestedWidth;
      win.mRequestedHeight=requestedHeight;
    }
    if (attrs != null && seq == win.mSeq) {
      win.mSystemUiVisibility=systemUiVisibility;
    }
    if (attrs != null) {
      mPolicy.adjustWindowParamsLw(attrs);
    }
    winAnimator.mSurfaceDestroyDeferred=(flags & WindowManagerGlobal.RELAYOUT_DEFER_SURFACE_DESTROY) != 0;
    int attrChanges=0;
    int flagChanges=0;
    if (attrs != null) {
      if (win.mAttrs.type != attrs.type) {
        throw new IllegalArgumentException("String_Node_Str");
      }
      flagChanges=win.mAttrs.flags^=attrs.flags;
      attrChanges=win.mAttrs.copyFrom(attrs);
      if ((attrChanges & (WindowManager.LayoutParams.LAYOUT_CHANGED | WindowManager.LayoutParams.SYSTEM_UI_VISIBILITY_CHANGED)) != 0) {
        win.mLayoutNeeded=true;
      }
    }
    if (DEBUG_LAYOUT)     Slog.v(TAG,"String_Node_Str" + win + "String_Node_Str"+ viewVisibility+ "String_Node_Str"+ requestedWidth+ "String_Node_Str"+ requestedHeight+ "String_Node_Str"+ win.mAttrs);
    win.mEnforceSizeCompat=(win.mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
    if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
      winAnimator.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 & (FLAG_ALT_FOCUSABLE_IM | FLAG_NOT_FOCUSABLE)) != 0;
    final boolean isDefaultDisplay=win.isDefaultDisplay();
    boolean focusMayChange=isDefaultDisplay && (win.mViewVisibility != viewVisibility || ((flagChanges & FLAG_NOT_FOCUSABLE) != 0) || (!win.mRelayoutCalled));
    boolean wallpaperMayMove=win.mViewVisibility != viewVisibility && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
    wallpaperMayMove|=(flagChanges & FLAG_SHOW_WALLPAPER) != 0;
    win.mRelayoutCalled=true;
    final int oldVisibility=win.mViewVisibility;
    win.mViewVisibility=viewVisibility;
    if (DEBUG_SCREEN_ON) {
      RuntimeException stack=new RuntimeException();
      stack.fillInStackTrace();
      Slog.i(TAG,"String_Node_Str" + win + "String_Node_Str"+ oldVisibility+ "String_Node_Str"+ viewVisibility,stack);
    }
    if (viewVisibility == View.VISIBLE && (win.mAppToken == null || !win.mAppToken.clientHidden)) {
      toBeDisplayed=!win.isVisibleLw();
      if (win.mExiting) {
        winAnimator.cancelExitAnimationForNextAnimationLocked();
        win.mExiting=false;
      }
      if (win.mDestroying) {
        win.mDestroying=false;
        mDestroySurface.remove(win);
      }
      if (oldVisibility == View.GONE) {
        winAnimator.mEnterAnimationPending=true;
      }
      if (toBeDisplayed) {
        if (win.isDrawnLw() && okToDisplay()) {
          winAnimator.applyEnterAnimationLocked();
        }
        if ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
          if (DEBUG_VISIBILITY)           Slog.v(TAG,"String_Node_Str" + win);
          win.mTurnOnScreen=true;
        }
        if (win.isConfigChanged()) {
          if (DEBUG_CONFIGURATION)           Slog.i(TAG,"String_Node_Str" + win + "String_Node_Str"+ mCurConfiguration);
          outConfig.setTo(mCurConfiguration);
        }
      }
      if ((attrChanges & WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
        winAnimator.destroySurfaceLocked();
        toBeDisplayed=true;
        surfaceChanged=true;
      }
      try {
        if (!win.mHasSurface) {
          surfaceChanged=true;
        }
        SurfaceControl surfaceControl=winAnimator.createSurfaceLocked();
        if (surfaceControl != null) {
          outSurface.copyFrom(surfaceControl);
          if (SHOW_TRANSACTIONS)           Slog.i(TAG,"String_Node_Str" + outSurface + "String_Node_Str");
        }
 else {
          outSurface.release();
        }
      }
 catch (      Exception e) {
        mInputMonitor.updateInputWindowsLw(true);
        Slog.w(TAG,"String_Node_Str" + client + "String_Node_Str"+ win.mAttrs.getTitle()+ "String_Node_Str",e);
        Binder.restoreCallingIdentity(origId);
        return 0;
      }
      if (toBeDisplayed) {
        focusMayChange=isDefaultDisplay;
      }
      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 {
      winAnimator.mEnterAnimationPending=false;
      if (winAnimator.mSurfaceControl != null) {
        if (DEBUG_VISIBILITY)         Slog.i(TAG,"String_Node_Str" + win + "String_Node_Str"+ win.mExiting);
        if (!win.mExiting) {
          surfaceChanged=true;
          int transit=WindowManagerPolicy.TRANSIT_EXIT;
          if (win.mAttrs.type == TYPE_APPLICATION_STARTING) {
            transit=WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
          }
          if (win.isWinVisibleLw() && winAnimator.applyAnimationLocked(transit,false)) {
            focusMayChange=isDefaultDisplay;
            win.mExiting=true;
          }
 else           if (win.mWinAnimator.isAnimating()) {
            win.mExiting=true;
          }
 else           if (win == mWallpaperTarget) {
            win.mExiting=true;
            win.mWinAnimator.mAnimating=true;
          }
 else {
            if (mInputMethodWindow == win) {
              mInputMethodWindow=null;
            }
            winAnimator.destroySurfaceLocked();
          }
          if (mDisplayMagnifier != null && win.getDisplayId() == Display.DEFAULT_DISPLAY) {
            mDisplayMagnifier.onWindowTransitionLocked(win,transit);
          }
        }
      }
      outSurface.release();
      if (DEBUG_VISIBILITY)       Slog.i(TAG,"String_Node_Str" + win);
    }
    if (focusMayChange) {
      if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,false)) {
        imMayMove=false;
      }
    }
    if (imMayMove && (moveInputMethodWindowsIfNeededLocked(false) || toBeDisplayed)) {
      assignLayersLocked(win.getWindowList());
    }
    if (wallpaperMayMove) {
      getDefaultDisplayContentLocked().pendingLayoutChanges|=WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
    }
    win.mDisplayContent.layoutNeeded=true;
    win.mGivenInsetsPending=(flags & WindowManagerGlobal.RELAYOUT_INSETS_PENDING) != 0;
    configChanged=updateOrientationFromAppTokensLocked(false);
    performLayoutAndPlaceSurfacesLocked();
    if (toBeDisplayed && win.mIsWallpaper) {
      DisplayInfo displayInfo=getDefaultDisplayInfoLocked();
      updateWallpaperOffsetLocked(win,displayInfo.logicalWidth,displayInfo.logicalHeight,false);
    }
    if (win.mAppToken != null) {
      win.mAppToken.updateReportedVisibilityLocked();
    }
    outFrame.set(win.mCompatFrame);
    outOverscanInsets.set(win.mOverscanInsets);
    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;
    animating=mAnimator.mAnimating && win.mWinAnimator.isAnimating();
    if (animating && !mRelayoutWhileAnimating.contains(win)) {
      mRelayoutWhileAnimating.add(win);
    }
    mInputMonitor.updateInputWindowsLw(true);
    if (DEBUG_LAYOUT) {
      Slog.v(TAG,"String_Node_Str" + win + "String_Node_Str"+ outFrame.toShortString());
    }
  }
  if (configChanged) {
    sendNewConfiguration();
  }
  Binder.restoreCallingIdentity(origId);
  return (inTouchMode ? WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE : 0) | (toBeDisplayed ? WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME : 0) | (surfaceChanged ? WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED : 0)| (animating ? WindowManagerGlobal.RELAYOUT_RES_ANIMATING : 0);
}