Program: 2004
Project: 2004
Buggy source:
int adjustWallpaperWindowsLocked(){
  mInnerFields.mWallpaperMayChange=false;
  boolean targetChanged=false;
  final DisplayInfo displayInfo=getDefaultDisplayContentLocked().getDisplayInfo();
  final int dw=displayInfo.appWidth;
  final int dh=displayInfo.appHeight;
  final WindowList windows=getDefaultWindowListLocked();
  int N=windows.size();
  WindowState w=null;
  WindowState foundW=null;
  int foundI=0;
  WindowState topCurW=null;
  int topCurI=0;
  int windowDetachedI=-1;
  int i=N;
  while (i > 0) {
    i--;
    w=windows.get(i);
    if ((w.mAttrs.type == TYPE_WALLPAPER)) {
      if (topCurW == null) {
        topCurW=w;
        topCurI=i;
      }
      continue;
    }
    topCurW=null;
    if (w != mAnimator.mWindowDetachedWallpaper && w.mAppToken != null) {
      if (w.mAppToken.hidden && w.mAppToken.mAppAnimator.animation == null) {
        if (DEBUG_WALLPAPER)         Slog.v(TAG,"String_Node_Str" + w);
        continue;
      }
    }
    if (DEBUG_WALLPAPER)     Slog.v(TAG,"String_Node_Str" + i + "String_Node_Str"+ w+ "String_Node_Str"+ w.isOnScreen()+ "String_Node_Str"+ w.mWinAnimator.mDrawState);
    if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0 && w.isOnScreen() && (mWallpaperTarget == w || w.isDrawFinishedLw())) {
      if (DEBUG_WALLPAPER)       Slog.v(TAG,"String_Node_Str" + i + "String_Node_Str"+ w);
      foundW=w;
      foundI=i;
      if (w == mWallpaperTarget && w.mWinAnimator.isAnimating()) {
        if (DEBUG_WALLPAPER)         Slog.v(TAG,"String_Node_Str" + w + "String_Node_Str");
        continue;
      }
      break;
    }
 else     if (w == mAnimator.mWindowDetachedWallpaper) {
      windowDetachedI=i;
    }
  }
  if (foundW == null && windowDetachedI >= 0) {
    if (DEBUG_WALLPAPER_LIGHT)     Slog.v(TAG,"String_Node_Str" + i + "String_Node_Str"+ w);
    foundW=w;
    foundI=windowDetachedI;
  }
  if (mWallpaperTarget != foundW && (mLowerWallpaperTarget == null || mLowerWallpaperTarget != foundW)) {
    if (DEBUG_WALLPAPER_LIGHT) {
      Slog.v(TAG,"String_Node_Str" + foundW + "String_Node_Str"+ mWallpaperTarget);
    }
    mLowerWallpaperTarget=null;
    mUpperWallpaperTarget=null;
    WindowState oldW=mWallpaperTarget;
    mWallpaperTarget=foundW;
    targetChanged=true;
    if (foundW != null && oldW != null) {
      boolean oldAnim=oldW.isAnimatingLw();
      boolean foundAnim=foundW.isAnimatingLw();
      if (DEBUG_WALLPAPER_LIGHT) {
        Slog.v(TAG,"String_Node_Str" + foundAnim + "String_Node_Str"+ oldAnim);
      }
      if (foundAnim && oldAnim) {
        int oldI=windows.indexOf(oldW);
        if (DEBUG_WALLPAPER_LIGHT) {
          Slog.v(TAG,"String_Node_Str" + foundI + "String_Node_Str"+ oldI);
        }
        if (oldI >= 0) {
          if (DEBUG_WALLPAPER_LIGHT) {
            Slog.v(TAG,"String_Node_Str" + oldI + "String_Node_Str"+ oldW+ "String_Node_Str"+ foundI+ "String_Node_Str"+ foundW);
          }
          if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
            if (DEBUG_WALLPAPER_LIGHT) {
              Slog.v(TAG,"String_Node_Str");
            }
            mWallpaperTarget=oldW;
            foundW=oldW;
            foundI=oldI;
          }
 else           if (foundI > oldI) {
            if (DEBUG_WALLPAPER_LIGHT) {
              Slog.v(TAG,"String_Node_Str");
            }
            mUpperWallpaperTarget=foundW;
            mLowerWallpaperTarget=oldW;
            foundW=oldW;
            foundI=oldI;
          }
 else {
            if (DEBUG_WALLPAPER_LIGHT) {
              Slog.v(TAG,"String_Node_Str");
            }
            mUpperWallpaperTarget=oldW;
            mLowerWallpaperTarget=foundW;
          }
        }
      }
    }
  }
 else   if (mLowerWallpaperTarget != null) {
    if (!mLowerWallpaperTarget.isAnimatingLw() || !mUpperWallpaperTarget.isAnimatingLw()) {
      if (DEBUG_WALLPAPER_LIGHT) {
        Slog.v(TAG,"String_Node_Str");
      }
      mLowerWallpaperTarget=null;
      mUpperWallpaperTarget=null;
      mWallpaperTarget=foundW;
      targetChanged=true;
    }
  }
  boolean visible=foundW != null;
  if (visible) {
    visible=isWallpaperVisible(foundW);
    if (DEBUG_WALLPAPER)     Slog.v(TAG,"String_Node_Str" + visible);
    mWallpaperAnimLayerAdjustment=(mLowerWallpaperTarget == null && foundW.mAppToken != null) ? foundW.mAppToken.mAppAnimator.animLayerAdjustment : 0;
    final int maxLayer=mPolicy.getMaxWallpaperLayer() * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
    while (foundI > 0) {
      WindowState wb=windows.get(foundI - 1);
      if (wb.mBaseLayer < maxLayer && wb.mAttachedWindow != foundW && (foundW.mAttachedWindow == null || wb.mAttachedWindow != foundW.mAttachedWindow) && (wb.mAttrs.type != TYPE_APPLICATION_STARTING || foundW.mToken == null || wb.mToken != foundW.mToken)) {
        break;
      }
      foundW=wb;
      foundI--;
    }
  }
 else {
    if (DEBUG_WALLPAPER)     Slog.v(TAG,"String_Node_Str");
  }
  if (foundW == null && topCurW != null) {
    foundW=topCurW;
    foundI=topCurI + 1;
  }
 else {
    foundW=foundI > 0 ? windows.get(foundI - 1) : null;
  }
  if (visible) {
    if (mWallpaperTarget.mWallpaperX >= 0) {
      mLastWallpaperX=mWallpaperTarget.mWallpaperX;
      mLastWallpaperXStep=mWallpaperTarget.mWallpaperXStep;
    }
    if (mWallpaperTarget.mWallpaperY >= 0) {
      mLastWallpaperY=mWallpaperTarget.mWallpaperY;
      mLastWallpaperYStep=mWallpaperTarget.mWallpaperYStep;
    }
  }
  int changed=0;
  int curTokenIndex=mWallpaperTokens.size();
  while (curTokenIndex > 0) {
    curTokenIndex--;
    WindowToken token=mWallpaperTokens.get(curTokenIndex);
    if (token.hidden == visible) {
      if (DEBUG_WALLPAPER_LIGHT)       Slog.d(TAG,"String_Node_Str" + token + "String_Node_Str"+ !visible);
      changed|=ADJUST_WALLPAPER_VISIBILITY_CHANGED;
      token.hidden=!visible;
      getDefaultDisplayContentLocked().layoutNeeded=true;
    }
    int curWallpaperIndex=token.windows.size();
    while (curWallpaperIndex > 0) {
      curWallpaperIndex--;
      WindowState wallpaper=token.windows.get(curWallpaperIndex);
      if (visible) {
        updateWallpaperOffsetLocked(wallpaper,dw,dh,false);
      }
      dispatchWallpaperVisibility(wallpaper,visible);
      wallpaper.mWinAnimator.mAnimLayer=wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
      if (DEBUG_LAYERS || DEBUG_WALLPAPER_LIGHT)       Slog.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ wallpaper.mWinAnimator.mAnimLayer);
      if (wallpaper == foundW) {
        foundI--;
        foundW=foundI > 0 ? windows.get(foundI - 1) : null;
        continue;
      }
      int oldIndex=windows.indexOf(wallpaper);
      if (oldIndex >= 0) {
        if (DEBUG_WINDOW_MOVEMENT)         Slog.v(TAG,"String_Node_Str" + oldIndex + "String_Node_Str"+ wallpaper);
        windows.remove(oldIndex);
        mWindowsChanged=true;
        if (oldIndex < foundI) {
          foundI--;
        }
      }
      if (DEBUG_WALLPAPER_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
        Slog.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ oldIndex+ "String_Node_Str"+ foundI);
      }
      windows.add(foundI,wallpaper);
      mWindowsChanged=true;
      changed|=ADJUST_WALLPAPER_LAYERS_CHANGED;
    }
  }
  final TaskStack targetStack=mWallpaperTarget == null ? null : mWallpaperTarget.getStack();
  if ((changed & ADJUST_WALLPAPER_LAYERS_CHANGED) != 0 && targetStack != null && !targetStack.isHomeStack()) {
    for (i=foundI - 1; i >= 0; --i) {
      WindowState win=windows.get(i);
      if (!win.isVisibleLw()) {
        continue;
      }
      final TaskStack winStack=win.getStack();
      if (winStack != null && !winStack.isHomeStack() && winStack != targetStack) {
        windows.remove(i);
        windows.add(foundI + 1,win);
      }
    }
  }
  if (targetChanged && DEBUG_WALLPAPER_LIGHT) {
    Slog.d(TAG,"String_Node_Str" + mWallpaperTarget + "String_Node_Str"+ mLowerWallpaperTarget+ "String_Node_Str"+ mUpperWallpaperTarget);
  }
  return changed;
}

Fixed version (ground truth):
int adjustWallpaperWindowsLocked(){
  mInnerFields.mWallpaperMayChange=false;
  boolean targetChanged=false;
  final DisplayInfo displayInfo=getDefaultDisplayContentLocked().getDisplayInfo();
  final int dw=displayInfo.appWidth;
  final int dh=displayInfo.appHeight;
  final WindowList windows=getDefaultWindowListLocked();
  int N=windows.size();
  WindowState w=null;
  WindowState foundW=null;
  int foundI=0;
  WindowState topCurW=null;
  int topCurI=0;
  int windowDetachedI=-1;
  int i=N;
  while (i > 0) {
    i--;
    w=windows.get(i);
    if ((w.mAttrs.type == TYPE_WALLPAPER)) {
      if (topCurW == null) {
        topCurW=w;
        topCurI=i;
      }
      continue;
    }
    topCurW=null;
    if (w != mAnimator.mWindowDetachedWallpaper && w.mAppToken != null) {
      if (w.mAppToken.hidden && w.mAppToken.mAppAnimator.animation == null) {
        if (DEBUG_WALLPAPER)         Slog.v(TAG,"String_Node_Str" + w);
        continue;
      }
    }
    if (DEBUG_WALLPAPER)     Slog.v(TAG,"String_Node_Str" + i + "String_Node_Str"+ w+ "String_Node_Str"+ w.isOnScreen()+ "String_Node_Str"+ w.mWinAnimator.mDrawState);
    if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0 && w.isOnScreen() && (mWallpaperTarget == w || w.isDrawFinishedLw())) {
      if (DEBUG_WALLPAPER)       Slog.v(TAG,"String_Node_Str" + i + "String_Node_Str"+ w);
      foundW=w;
      foundI=i;
      if (w == mWallpaperTarget && w.mWinAnimator.isAnimating()) {
        if (DEBUG_WALLPAPER)         Slog.v(TAG,"String_Node_Str" + w + "String_Node_Str");
        continue;
      }
      break;
    }
 else     if (w == mAnimator.mWindowDetachedWallpaper) {
      windowDetachedI=i;
    }
  }
  if (foundW == null && windowDetachedI >= 0) {
    if (DEBUG_WALLPAPER_LIGHT)     Slog.v(TAG,"String_Node_Str" + i + "String_Node_Str"+ w);
    foundW=w;
    foundI=windowDetachedI;
  }
  if (mWallpaperTarget != foundW && (mLowerWallpaperTarget == null || mLowerWallpaperTarget != foundW)) {
    if (DEBUG_WALLPAPER_LIGHT) {
      Slog.v(TAG,"String_Node_Str" + foundW + "String_Node_Str"+ mWallpaperTarget);
    }
    mLowerWallpaperTarget=null;
    mUpperWallpaperTarget=null;
    WindowState oldW=mWallpaperTarget;
    mWallpaperTarget=foundW;
    targetChanged=true;
    if (foundW != null && oldW != null) {
      boolean oldAnim=oldW.isAnimatingLw();
      boolean foundAnim=foundW.isAnimatingLw();
      if (DEBUG_WALLPAPER_LIGHT) {
        Slog.v(TAG,"String_Node_Str" + foundAnim + "String_Node_Str"+ oldAnim);
      }
      if (foundAnim && oldAnim) {
        int oldI=windows.indexOf(oldW);
        if (DEBUG_WALLPAPER_LIGHT) {
          Slog.v(TAG,"String_Node_Str" + foundI + "String_Node_Str"+ oldI);
        }
        if (oldI >= 0) {
          if (DEBUG_WALLPAPER_LIGHT) {
            Slog.v(TAG,"String_Node_Str" + oldI + "String_Node_Str"+ oldW+ "String_Node_Str"+ foundI+ "String_Node_Str"+ foundW);
          }
          if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
            if (DEBUG_WALLPAPER_LIGHT) {
              Slog.v(TAG,"String_Node_Str");
            }
            mWallpaperTarget=oldW;
            foundW=oldW;
            foundI=oldI;
          }
 else           if (foundI > oldI) {
            if (DEBUG_WALLPAPER_LIGHT) {
              Slog.v(TAG,"String_Node_Str");
            }
            mUpperWallpaperTarget=foundW;
            mLowerWallpaperTarget=oldW;
            foundW=oldW;
            foundI=oldI;
          }
 else {
            if (DEBUG_WALLPAPER_LIGHT) {
              Slog.v(TAG,"String_Node_Str");
            }
            mUpperWallpaperTarget=oldW;
            mLowerWallpaperTarget=foundW;
          }
        }
      }
    }
  }
 else   if (mLowerWallpaperTarget != null) {
    if (!mLowerWallpaperTarget.isAnimatingLw() || !mUpperWallpaperTarget.isAnimatingLw()) {
      if (DEBUG_WALLPAPER_LIGHT) {
        Slog.v(TAG,"String_Node_Str");
      }
      mLowerWallpaperTarget=null;
      mUpperWallpaperTarget=null;
      mWallpaperTarget=foundW;
      targetChanged=true;
    }
  }
  boolean visible=foundW != null;
  if (visible) {
    visible=isWallpaperVisible(foundW);
    if (DEBUG_WALLPAPER)     Slog.v(TAG,"String_Node_Str" + visible);
    mWallpaperAnimLayerAdjustment=(mLowerWallpaperTarget == null && foundW.mAppToken != null) ? foundW.mAppToken.mAppAnimator.animLayerAdjustment : 0;
    final int maxLayer=mPolicy.getMaxWallpaperLayer() * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
    while (foundI > 0) {
      WindowState wb=windows.get(foundI - 1);
      if (wb.mBaseLayer < maxLayer && wb.mAttachedWindow != foundW && (foundW.mAttachedWindow == null || wb.mAttachedWindow != foundW.mAttachedWindow) && (wb.mAttrs.type != TYPE_APPLICATION_STARTING || foundW.mToken == null || wb.mToken != foundW.mToken)) {
        break;
      }
      foundW=wb;
      foundI--;
    }
  }
 else {
    if (DEBUG_WALLPAPER)     Slog.v(TAG,"String_Node_Str");
  }
  if (foundW == null && topCurW != null) {
    foundW=topCurW;
    foundI=topCurI + 1;
  }
 else {
    foundW=foundI > 0 ? windows.get(foundI - 1) : null;
  }
  if (visible) {
    if (mWallpaperTarget.mWallpaperX >= 0) {
      mLastWallpaperX=mWallpaperTarget.mWallpaperX;
      mLastWallpaperXStep=mWallpaperTarget.mWallpaperXStep;
    }
    if (mWallpaperTarget.mWallpaperY >= 0) {
      mLastWallpaperY=mWallpaperTarget.mWallpaperY;
      mLastWallpaperYStep=mWallpaperTarget.mWallpaperYStep;
    }
  }
  int changed=0;
  int curTokenIndex=mWallpaperTokens.size();
  while (curTokenIndex > 0) {
    curTokenIndex--;
    WindowToken token=mWallpaperTokens.get(curTokenIndex);
    if (token.hidden == visible) {
      if (DEBUG_WALLPAPER_LIGHT)       Slog.d(TAG,"String_Node_Str" + token + "String_Node_Str"+ !visible);
      changed|=ADJUST_WALLPAPER_VISIBILITY_CHANGED;
      token.hidden=!visible;
      getDefaultDisplayContentLocked().layoutNeeded=true;
    }
    int curWallpaperIndex=token.windows.size();
    while (curWallpaperIndex > 0) {
      curWallpaperIndex--;
      WindowState wallpaper=token.windows.get(curWallpaperIndex);
      if (visible) {
        updateWallpaperOffsetLocked(wallpaper,dw,dh,false);
      }
      dispatchWallpaperVisibility(wallpaper,visible);
      wallpaper.mWinAnimator.mAnimLayer=wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
      if (DEBUG_LAYERS || DEBUG_WALLPAPER_LIGHT)       Slog.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ wallpaper.mWinAnimator.mAnimLayer);
      if (wallpaper == foundW) {
        foundI--;
        foundW=foundI > 0 ? windows.get(foundI - 1) : null;
        continue;
      }
      int oldIndex=windows.indexOf(wallpaper);
      if (oldIndex >= 0) {
        if (DEBUG_WINDOW_MOVEMENT)         Slog.v(TAG,"String_Node_Str" + oldIndex + "String_Node_Str"+ wallpaper);
        windows.remove(oldIndex);
        mWindowsChanged=true;
        if (oldIndex < foundI) {
          foundI--;
        }
      }
      if (DEBUG_WALLPAPER_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
        Slog.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ oldIndex+ "String_Node_Str"+ 0);
      }
      windows.add(0,wallpaper);
      mWindowsChanged=true;
      changed|=ADJUST_WALLPAPER_LAYERS_CHANGED;
    }
  }
  if (targetChanged && DEBUG_WALLPAPER_LIGHT) {
    Slog.d(TAG,"String_Node_Str" + mWallpaperTarget + "String_Node_Str"+ mLowerWallpaperTarget+ "String_Node_Str"+ mUpperWallpaperTarget);
  }
  return changed;
}