Program: 181981
Project: 181981
Buggy source:
public int addWindow(Session session,IWindow client,WindowManager.LayoutParams attrs,int viewVisibility,Rect outContentInsets){
  int res=mPolicy.checkAddPermission(attrs);
  if (res != WindowManagerImpl.ADD_OKAY) {
    return res;
  }
  boolean reportNewConfig=false;
  WindowState attachedWindow=null;
  WindowState win=null;
synchronized (mWindowMap) {
    if (mDisplay == null) {
      WindowManager wm=(WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
      mDisplay=wm.getDefaultDisplay();
      mQueue.setDisplay(mDisplay);
      reportNewConfig=true;
    }
    if (mWindowMap.containsKey(client.asBinder())) {
      Slog.w(TAG,"String_Node_Str" + client + "String_Node_Str");
      return WindowManagerImpl.ADD_DUPLICATE_ADD;
    }
    if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
      attachedWindow=windowForClientLocked(null,attrs.token,false);
      if (attachedWindow == null) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
      }
      if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
      }
    }
    boolean addToken=false;
    WindowToken token=mTokenMap.get(attrs.token);
    if (token == null) {
      if (attrs.type >= FIRST_APPLICATION_WINDOW && attrs.type <= LAST_APPLICATION_WINDOW) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_APP_TOKEN;
      }
      if (attrs.type == TYPE_INPUT_METHOD) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_APP_TOKEN;
      }
      if (attrs.type == TYPE_WALLPAPER) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_APP_TOKEN;
      }
      token=new WindowToken(attrs.token,-1,false);
      addToken=true;
    }
 else     if (attrs.type >= FIRST_APPLICATION_WINDOW && attrs.type <= LAST_APPLICATION_WINDOW) {
      AppWindowToken atoken=token.appWindowToken;
      if (atoken == null) {
        Slog.w(TAG,"String_Node_Str" + token + "String_Node_Str");
        return WindowManagerImpl.ADD_NOT_APP_TOKEN;
      }
 else       if (atoken.removed) {
        Slog.w(TAG,"String_Node_Str" + token + "String_Node_Str");
        return WindowManagerImpl.ADD_APP_EXITING;
      }
      if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
        if (localLOGV)         Slog.v(TAG,"String_Node_Str" + attrs.getTitle());
        return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
      }
    }
 else     if (attrs.type == TYPE_INPUT_METHOD) {
      if (token.windowType != TYPE_INPUT_METHOD) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_APP_TOKEN;
      }
    }
 else     if (attrs.type == TYPE_WALLPAPER) {
      if (token.windowType != TYPE_WALLPAPER) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_APP_TOKEN;
      }
    }
    win=new WindowState(session,client,token,attachedWindow,attrs,viewVisibility);
    if (win.mDeathRecipient == null) {
      Slog.w(TAG,"String_Node_Str" + client.asBinder() + "String_Node_Str");
      return WindowManagerImpl.ADD_APP_EXITING;
    }
    mPolicy.adjustWindowParamsLw(win.mAttrs);
    res=mPolicy.prepareAddWindowLw(win,attrs);
    if (res != WindowManagerImpl.ADD_OKAY) {
      return res;
    }
    res=WindowManagerImpl.ADD_OKAY;
    final long origId=Binder.clearCallingIdentity();
    if (addToken) {
      mTokenMap.put(attrs.token,token);
      mTokenList.add(token);
    }
    win.attach();
    mWindowMap.put(client.asBinder(),win);
    if (attrs.type == TYPE_APPLICATION_STARTING && token.appWindowToken != null) {
      token.appWindowToken.startingWindow=win;
    }
    boolean imMayMove=true;
    if (attrs.type == TYPE_INPUT_METHOD) {
      mInputMethodWindow=win;
      addInputMethodWindowToListLocked(win);
      imMayMove=false;
    }
 else     if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
      mInputMethodDialogs.add(win);
      addWindowToListInOrderLocked(win,true);
      adjustInputMethodDialogsLocked();
      imMayMove=false;
    }
 else {
      addWindowToListInOrderLocked(win,true);
      if (attrs.type == TYPE_WALLPAPER) {
        mLastWallpaperTimeoutTime=0;
        adjustWallpaperWindowsLocked();
      }
 else       if ((attrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
        adjustWallpaperWindowsLocked();
      }
    }
    win.mEnterAnimationPending=true;
    mPolicy.getContentInsetHintLw(attrs,outContentInsets);
    if (mInTouchMode) {
      res|=WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
    }
    if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
      res|=WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
    }
    boolean focusChanged=false;
    if (win.canReceiveKeys()) {
      if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS)) == true) {
        imMayMove=false;
      }
    }
    if (imMayMove) {
      moveInputMethodWindowsIfNeededLocked(false);
    }
    assignLayersLocked();
    if (focusChanged) {
      if (mCurrentFocus != null) {
        mKeyWaiter.handleNewWindowLocked(mCurrentFocus);
      }
    }
    if (localLOGV)     Slog.v(TAG,"String_Node_Str" + client.asBinder() + "String_Node_Str"+ win);
    if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
      reportNewConfig=true;
    }
  }
  final long origId=Binder.clearCallingIdentity();
  if (reportNewConfig) {
    sendNewConfiguration();
  }
  Binder.restoreCallingIdentity(origId);
  return res;
}

Fixed version (ground truth):
public int addWindow(Session session,IWindow client,WindowManager.LayoutParams attrs,int viewVisibility,Rect outContentInsets){
  int res=mPolicy.checkAddPermission(attrs);
  if (res != WindowManagerImpl.ADD_OKAY) {
    return res;
  }
  boolean reportNewConfig=false;
  WindowState attachedWindow=null;
  WindowState win=null;
synchronized (mWindowMap) {
    if (mDisplay == null) {
      WindowManager wm=(WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
      mDisplay=wm.getDefaultDisplay();
      mInitialDisplayWidth=mDisplay.getWidth();
      mInitialDisplayHeight=mDisplay.getHeight();
      mQueue.setDisplay(mDisplay);
      reportNewConfig=true;
    }
    if (mWindowMap.containsKey(client.asBinder())) {
      Slog.w(TAG,"String_Node_Str" + client + "String_Node_Str");
      return WindowManagerImpl.ADD_DUPLICATE_ADD;
    }
    if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) {
      attachedWindow=windowForClientLocked(null,attrs.token,false);
      if (attachedWindow == null) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
      }
      if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN;
      }
    }
    boolean addToken=false;
    WindowToken token=mTokenMap.get(attrs.token);
    if (token == null) {
      if (attrs.type >= FIRST_APPLICATION_WINDOW && attrs.type <= LAST_APPLICATION_WINDOW) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_APP_TOKEN;
      }
      if (attrs.type == TYPE_INPUT_METHOD) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_APP_TOKEN;
      }
      if (attrs.type == TYPE_WALLPAPER) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_APP_TOKEN;
      }
      token=new WindowToken(attrs.token,-1,false);
      addToken=true;
    }
 else     if (attrs.type >= FIRST_APPLICATION_WINDOW && attrs.type <= LAST_APPLICATION_WINDOW) {
      AppWindowToken atoken=token.appWindowToken;
      if (atoken == null) {
        Slog.w(TAG,"String_Node_Str" + token + "String_Node_Str");
        return WindowManagerImpl.ADD_NOT_APP_TOKEN;
      }
 else       if (atoken.removed) {
        Slog.w(TAG,"String_Node_Str" + token + "String_Node_Str");
        return WindowManagerImpl.ADD_APP_EXITING;
      }
      if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
        if (localLOGV)         Slog.v(TAG,"String_Node_Str" + attrs.getTitle());
        return WindowManagerImpl.ADD_STARTING_NOT_NEEDED;
      }
    }
 else     if (attrs.type == TYPE_INPUT_METHOD) {
      if (token.windowType != TYPE_INPUT_METHOD) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_APP_TOKEN;
      }
    }
 else     if (attrs.type == TYPE_WALLPAPER) {
      if (token.windowType != TYPE_WALLPAPER) {
        Slog.w(TAG,"String_Node_Str" + attrs.token + "String_Node_Str");
        return WindowManagerImpl.ADD_BAD_APP_TOKEN;
      }
    }
    win=new WindowState(session,client,token,attachedWindow,attrs,viewVisibility);
    if (win.mDeathRecipient == null) {
      Slog.w(TAG,"String_Node_Str" + client.asBinder() + "String_Node_Str");
      return WindowManagerImpl.ADD_APP_EXITING;
    }
    mPolicy.adjustWindowParamsLw(win.mAttrs);
    res=mPolicy.prepareAddWindowLw(win,attrs);
    if (res != WindowManagerImpl.ADD_OKAY) {
      return res;
    }
    res=WindowManagerImpl.ADD_OKAY;
    final long origId=Binder.clearCallingIdentity();
    if (addToken) {
      mTokenMap.put(attrs.token,token);
      mTokenList.add(token);
    }
    win.attach();
    mWindowMap.put(client.asBinder(),win);
    if (attrs.type == TYPE_APPLICATION_STARTING && token.appWindowToken != null) {
      token.appWindowToken.startingWindow=win;
    }
    boolean imMayMove=true;
    if (attrs.type == TYPE_INPUT_METHOD) {
      mInputMethodWindow=win;
      addInputMethodWindowToListLocked(win);
      imMayMove=false;
    }
 else     if (attrs.type == TYPE_INPUT_METHOD_DIALOG) {
      mInputMethodDialogs.add(win);
      addWindowToListInOrderLocked(win,true);
      adjustInputMethodDialogsLocked();
      imMayMove=false;
    }
 else {
      addWindowToListInOrderLocked(win,true);
      if (attrs.type == TYPE_WALLPAPER) {
        mLastWallpaperTimeoutTime=0;
        adjustWallpaperWindowsLocked();
      }
 else       if ((attrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
        adjustWallpaperWindowsLocked();
      }
    }
    win.mEnterAnimationPending=true;
    mPolicy.getContentInsetHintLw(attrs,outContentInsets);
    if (mInTouchMode) {
      res|=WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE;
    }
    if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) {
      res|=WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
    }
    boolean focusChanged=false;
    if (win.canReceiveKeys()) {
      if ((focusChanged=updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS)) == true) {
        imMayMove=false;
      }
    }
    if (imMayMove) {
      moveInputMethodWindowsIfNeededLocked(false);
    }
    assignLayersLocked();
    if (focusChanged) {
      if (mCurrentFocus != null) {
        mKeyWaiter.handleNewWindowLocked(mCurrentFocus);
      }
    }
    if (localLOGV)     Slog.v(TAG,"String_Node_Str" + client.asBinder() + "String_Node_Str"+ win);
    if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) {
      reportNewConfig=true;
    }
  }
  final long origId=Binder.clearCallingIdentity();
  if (reportNewConfig) {
    sendNewConfiguration();
  }
  Binder.restoreCallingIdentity(origId);
  return res;
}