Program: 43080
Project: 43080
Buggy source:
int adjustWallpaperWindowsLocked(){
  int changed=0;
  final int dw=mDisplay.getWidth();
  final int dh=mDisplay.getHeight();
  final ArrayList localmWindows=mWindows;
  int N=localmWindows.size();
  WindowState w=null;
  WindowState foundW=null;
  int foundI=0;
  WindowState topCurW=null;
  int topCurI=0;
  int i=N;
  while (i > 0) {
    i--;
    w=(WindowState)localmWindows.get(i);
    if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
      if (topCurW == null) {
        topCurW=w;
        topCurI=i;
      }
      continue;
    }
    topCurW=null;
    if (w.mAppToken != null) {
      if (w.mAppToken.hidden && w.mAppToken.animation == null) {
        if (DEBUG_WALLPAPER)         Log.v(TAG,"String_Node_Str" + w);
        topCurW=null;
        continue;
      }
    }
    if (DEBUG_WALLPAPER)     Log.v(TAG,"String_Node_Str" + w + "String_Node_Str"+ w.isReadyForDisplay()+ "String_Node_Str"+ w.mDrawPending+ "String_Node_Str"+ w.mCommitDrawPending);
    if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() && (mWallpaperTarget == w || (!w.mDrawPending && !w.mCommitDrawPending))) {
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str" + i + "String_Node_Str"+ w);
      foundW=w;
      foundI=i;
      if (w == mWallpaperTarget && ((w.mAppToken != null && w.mAppToken.animation != null) || w.mAnimation != null)) {
        if (DEBUG_WALLPAPER)         Log.v(TAG,"String_Node_Str" + w + "String_Node_Str");
        continue;
      }
      break;
    }
  }
  if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
    if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str");
      return 0;
    }
    if (foundW != null && foundW.mAppToken != null) {
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str");
      return 0;
    }
  }
  if (mWallpaperTarget != foundW) {
    if (DEBUG_WALLPAPER) {
      Log.v(TAG,"String_Node_Str" + foundW + "String_Node_Str"+ mWallpaperTarget);
    }
    mLowerWallpaperTarget=null;
    mUpperWallpaperTarget=null;
    WindowState oldW=mWallpaperTarget;
    mWallpaperTarget=foundW;
    if (foundW != null && oldW != null) {
      boolean oldAnim=oldW.mAnimation != null || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
      boolean foundAnim=foundW.mAnimation != null || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
      if (DEBUG_WALLPAPER) {
        Log.v(TAG,"String_Node_Str" + foundAnim + "String_Node_Str"+ oldAnim);
      }
      if (foundAnim && oldAnim) {
        int oldI=localmWindows.indexOf(oldW);
        if (DEBUG_WALLPAPER) {
          Log.v(TAG,"String_Node_Str" + foundI + "String_Node_Str"+ oldI);
        }
        if (oldI >= 0) {
          if (DEBUG_WALLPAPER) {
            Log.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) {
              Log.v(TAG,"String_Node_Str");
            }
            mWallpaperTarget=oldW;
          }
          if (foundI > oldI) {
            if (DEBUG_WALLPAPER) {
              Log.v(TAG,"String_Node_Str");
            }
            mUpperWallpaperTarget=foundW;
            mLowerWallpaperTarget=oldW;
            foundW=oldW;
            foundI=oldI;
          }
 else {
            if (DEBUG_WALLPAPER) {
              Log.v(TAG,"String_Node_Str");
            }
            mUpperWallpaperTarget=oldW;
            mLowerWallpaperTarget=foundW;
          }
        }
      }
    }
  }
 else {
    if (mLowerWallpaperTarget == null || mLowerWallpaperTarget.mAppToken.animation == null || mUpperWallpaperTarget == null || mUpperWallpaperTarget.mAppToken.animation == null) {
      if (DEBUG_WALLPAPER) {
        Log.v(TAG,"String_Node_Str");
      }
      mLowerWallpaperTarget=null;
      mUpperWallpaperTarget=null;
    }
  }
  boolean visible=foundW != null;
  if (visible) {
    visible=isWallpaperVisible(foundW);
    if (DEBUG_WALLPAPER)     Log.v(TAG,"String_Node_Str" + visible);
    mWallpaperAnimLayerAdjustment=(mLowerWallpaperTarget == null && foundW.mAppToken != null) ? foundW.mAppToken.animLayerAdjustment : 0;
    final int maxLayer=mPolicy.getMaxWallpaperLayer() * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
    while (foundI > 0) {
      WindowState wb=(WindowState)localmWindows.get(foundI - 1);
      if (wb.mBaseLayer < maxLayer && wb.mAttachedWindow != foundW && (wb.mAttrs.type != TYPE_APPLICATION_STARTING || wb.mToken != foundW.mToken)) {
        break;
      }
      foundW=wb;
      foundI--;
    }
  }
 else {
    if (DEBUG_WALLPAPER)     Log.v(TAG,"String_Node_Str");
  }
  if (foundW == null && topCurW != null) {
    foundW=topCurW;
    foundI=topCurI + 1;
  }
 else {
    foundW=foundI > 0 ? (WindowState)localmWindows.get(foundI - 1) : null;
  }
  if (visible) {
    mLastWallpaperX=mWallpaperTarget.mWallpaperX;
    mLastWallpaperY=mWallpaperTarget.mWallpaperY;
  }
  int curTokenIndex=mWallpaperTokens.size();
  while (curTokenIndex > 0) {
    curTokenIndex--;
    WindowToken token=mWallpaperTokens.get(curTokenIndex);
    if (token.hidden == visible) {
      changed|=ADJUST_WALLPAPER_VISIBILITY_CHANGED;
      token.hidden=!visible;
      mLayoutNeeded=true;
    }
    int curWallpaperIndex=token.windows.size();
    while (curWallpaperIndex > 0) {
      curWallpaperIndex--;
      WindowState wallpaper=token.windows.get(curWallpaperIndex);
      if (visible) {
        updateWallpaperOffsetLocked(wallpaper,dw,dh,false);
      }
      if (wallpaper.mWallpaperVisible != visible) {
        wallpaper.mWallpaperVisible=visible;
        try {
          if (DEBUG_VISIBILITY || DEBUG_WALLPAPER)           Log.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ visible);
          wallpaper.mClient.dispatchAppVisibility(visible);
        }
 catch (        RemoteException e) {
        }
      }
      wallpaper.mAnimLayer=wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
      if (DEBUG_LAYERS || DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ wallpaper.mAnimLayer);
      if (wallpaper == foundW) {
        foundI--;
        foundW=foundI > 0 ? (WindowState)localmWindows.get(foundI - 1) : null;
        continue;
      }
      int oldIndex=localmWindows.indexOf(wallpaper);
      if (oldIndex >= 0) {
        if (DEBUG_WINDOW_MOVEMENT)         Log.v(TAG,"String_Node_Str" + oldIndex + "String_Node_Str"+ wallpaper);
        localmWindows.remove(oldIndex);
        if (oldIndex < foundI) {
          foundI--;
        }
      }
      if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT)       Log.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ oldIndex+ "String_Node_Str"+ foundI);
      localmWindows.add(foundI,wallpaper);
      changed|=ADJUST_WALLPAPER_LAYERS_CHANGED;
    }
  }
  return changed;
}

Fixed version (ground truth):
int adjustWallpaperWindowsLocked(){
  int changed=0;
  final int dw=mDisplay.getWidth();
  final int dh=mDisplay.getHeight();
  final ArrayList localmWindows=mWindows;
  int N=localmWindows.size();
  WindowState w=null;
  WindowState foundW=null;
  int foundI=0;
  WindowState topCurW=null;
  int topCurI=0;
  int i=N;
  while (i > 0) {
    i--;
    w=(WindowState)localmWindows.get(i);
    if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) {
      if (topCurW == null) {
        topCurW=w;
        topCurI=i;
      }
      continue;
    }
    topCurW=null;
    if (w.mAppToken != null) {
      if (w.mAppToken.hidden && w.mAppToken.animation == null) {
        if (DEBUG_WALLPAPER)         Log.v(TAG,"String_Node_Str" + w);
        topCurW=null;
        continue;
      }
    }
    if (DEBUG_WALLPAPER)     Log.v(TAG,"String_Node_Str" + w + "String_Node_Str"+ w.isReadyForDisplay()+ "String_Node_Str"+ w.mDrawPending+ "String_Node_Str"+ w.mCommitDrawPending);
    if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() && (mWallpaperTarget == w || (!w.mDrawPending && !w.mCommitDrawPending))) {
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str" + i + "String_Node_Str"+ w);
      foundW=w;
      foundI=i;
      if (w == mWallpaperTarget && ((w.mAppToken != null && w.mAppToken.animation != null) || w.mAnimation != null)) {
        if (DEBUG_WALLPAPER)         Log.v(TAG,"String_Node_Str" + w + "String_Node_Str");
        continue;
      }
      break;
    }
  }
  if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
    if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str");
      return 0;
    }
    if (foundW != null && foundW.mAppToken != null) {
      if (DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str");
      return 0;
    }
  }
  if (mWallpaperTarget != foundW) {
    if (DEBUG_WALLPAPER) {
      Log.v(TAG,"String_Node_Str" + foundW + "String_Node_Str"+ mWallpaperTarget);
    }
    mLowerWallpaperTarget=null;
    mUpperWallpaperTarget=null;
    WindowState oldW=mWallpaperTarget;
    mWallpaperTarget=foundW;
    if (foundW != null && oldW != null) {
      boolean oldAnim=oldW.mAnimation != null || (oldW.mAppToken != null && oldW.mAppToken.animation != null);
      boolean foundAnim=foundW.mAnimation != null || (foundW.mAppToken != null && foundW.mAppToken.animation != null);
      if (DEBUG_WALLPAPER) {
        Log.v(TAG,"String_Node_Str" + foundAnim + "String_Node_Str"+ oldAnim);
      }
      if (foundAnim && oldAnim) {
        int oldI=localmWindows.indexOf(oldW);
        if (DEBUG_WALLPAPER) {
          Log.v(TAG,"String_Node_Str" + foundI + "String_Node_Str"+ oldI);
        }
        if (oldI >= 0) {
          if (DEBUG_WALLPAPER) {
            Log.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) {
              Log.v(TAG,"String_Node_Str");
            }
            mWallpaperTarget=oldW;
          }
          if (foundI > oldI) {
            if (DEBUG_WALLPAPER) {
              Log.v(TAG,"String_Node_Str");
            }
            mUpperWallpaperTarget=foundW;
            mLowerWallpaperTarget=oldW;
            foundW=oldW;
            foundI=oldI;
          }
 else {
            if (DEBUG_WALLPAPER) {
              Log.v(TAG,"String_Node_Str");
            }
            mUpperWallpaperTarget=oldW;
            mLowerWallpaperTarget=foundW;
          }
        }
      }
    }
  }
 else   if (mLowerWallpaperTarget != null) {
    boolean lowerAnimating=mLowerWallpaperTarget.mAnimation != null || (mLowerWallpaperTarget.mAppToken != null && mLowerWallpaperTarget.mAppToken.animation != null);
    boolean upperAnimating=mUpperWallpaperTarget.mAnimation != null || (mUpperWallpaperTarget.mAppToken != null && mUpperWallpaperTarget.mAppToken.animation != null);
    if (!lowerAnimating || !upperAnimating) {
      if (DEBUG_WALLPAPER) {
        Log.v(TAG,"String_Node_Str");
      }
      mLowerWallpaperTarget=null;
      mUpperWallpaperTarget=null;
    }
  }
  boolean visible=foundW != null;
  if (visible) {
    visible=isWallpaperVisible(foundW);
    if (DEBUG_WALLPAPER)     Log.v(TAG,"String_Node_Str" + visible);
    mWallpaperAnimLayerAdjustment=(mLowerWallpaperTarget == null && foundW.mAppToken != null) ? foundW.mAppToken.animLayerAdjustment : 0;
    final int maxLayer=mPolicy.getMaxWallpaperLayer() * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
    while (foundI > 0) {
      WindowState wb=(WindowState)localmWindows.get(foundI - 1);
      if (wb.mBaseLayer < maxLayer && wb.mAttachedWindow != foundW && (wb.mAttrs.type != TYPE_APPLICATION_STARTING || wb.mToken != foundW.mToken)) {
        break;
      }
      foundW=wb;
      foundI--;
    }
  }
 else {
    if (DEBUG_WALLPAPER)     Log.v(TAG,"String_Node_Str");
  }
  if (foundW == null && topCurW != null) {
    foundW=topCurW;
    foundI=topCurI + 1;
  }
 else {
    foundW=foundI > 0 ? (WindowState)localmWindows.get(foundI - 1) : null;
  }
  if (visible) {
    mLastWallpaperX=mWallpaperTarget.mWallpaperX;
    mLastWallpaperY=mWallpaperTarget.mWallpaperY;
  }
  int curTokenIndex=mWallpaperTokens.size();
  while (curTokenIndex > 0) {
    curTokenIndex--;
    WindowToken token=mWallpaperTokens.get(curTokenIndex);
    if (token.hidden == visible) {
      changed|=ADJUST_WALLPAPER_VISIBILITY_CHANGED;
      token.hidden=!visible;
      mLayoutNeeded=true;
    }
    int curWallpaperIndex=token.windows.size();
    while (curWallpaperIndex > 0) {
      curWallpaperIndex--;
      WindowState wallpaper=token.windows.get(curWallpaperIndex);
      if (visible) {
        updateWallpaperOffsetLocked(wallpaper,dw,dh,false);
      }
      if (wallpaper.mWallpaperVisible != visible) {
        wallpaper.mWallpaperVisible=visible;
        try {
          if (DEBUG_VISIBILITY || DEBUG_WALLPAPER)           Log.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ visible);
          wallpaper.mClient.dispatchAppVisibility(visible);
        }
 catch (        RemoteException e) {
        }
      }
      wallpaper.mAnimLayer=wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
      if (DEBUG_LAYERS || DEBUG_WALLPAPER)       Log.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ wallpaper.mAnimLayer);
      if (wallpaper == foundW) {
        foundI--;
        foundW=foundI > 0 ? (WindowState)localmWindows.get(foundI - 1) : null;
        continue;
      }
      int oldIndex=localmWindows.indexOf(wallpaper);
      if (oldIndex >= 0) {
        if (DEBUG_WINDOW_MOVEMENT)         Log.v(TAG,"String_Node_Str" + oldIndex + "String_Node_Str"+ wallpaper);
        localmWindows.remove(oldIndex);
        if (oldIndex < foundI) {
          foundI--;
        }
      }
      if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT)       Log.v(TAG,"String_Node_Str" + wallpaper + "String_Node_Str"+ oldIndex+ "String_Node_Str"+ foundI);
      localmWindows.add(foundI,wallpaper);
      changed|=ADJUST_WALLPAPER_LAYERS_CHANGED;
    }
  }
  return changed;
}