Program: 2025
Project: 2025
Buggy source:
static void updateWifiDisplayStatus(WifiDisplayStatus newStatus){
  final WifiDisplayStatus oldStatus=sStatic.mLastKnownWifiDisplayStatus;
  boolean wantScan=false;
  boolean blockScan=false;
  WifiDisplay[] oldDisplays=oldStatus != null ? oldStatus.getRememberedDisplays() : WifiDisplay.EMPTY_ARRAY;
  WifiDisplay[] newDisplays;
  WifiDisplay[] availableDisplays;
  WifiDisplay activeDisplay;
  if (newStatus.getFeatureState() == WifiDisplayStatus.FEATURE_STATE_ON) {
    newDisplays=newStatus.getRememberedDisplays();
    availableDisplays=newStatus.getAvailableDisplays();
    activeDisplay=newStatus.getActiveDisplay();
  }
 else {
    newDisplays=availableDisplays=WifiDisplay.EMPTY_ARRAY;
    activeDisplay=null;
  }
  for (int i=0; i < newDisplays.length; i++) {
    final WifiDisplay d=newDisplays[i];
    final WifiDisplay oldRemembered=findMatchingDisplay(d,oldDisplays);
    if (oldRemembered == null) {
      addRouteStatic(makeWifiDisplayRoute(d,findMatchingDisplay(d,availableDisplays) != null));
      wantScan=true;
    }
 else {
      final boolean available=findMatchingDisplay(d,availableDisplays) != null;
      final RouteInfo route=findWifiDisplayRoute(d);
      updateWifiDisplayRoute(route,d,available,newStatus);
    }
    if (d.equals(activeDisplay)) {
      final RouteInfo activeRoute=findWifiDisplayRoute(d);
      if (activeRoute != null) {
        selectRouteStatic(activeRoute.getSupportedTypes(),activeRoute);
        blockScan=true;
      }
    }
  }
  for (int i=0; i < oldDisplays.length; i++) {
    final WifiDisplay d=oldDisplays[i];
    final WifiDisplay newDisplay=findMatchingDisplay(d,newDisplays);
    if (newDisplay == null) {
      removeRoute(findWifiDisplayRoute(d));
    }
  }
  if (wantScan && !blockScan) {
    sStatic.mDisplayService.scanWifiDisplays();
  }
  sStatic.mLastKnownWifiDisplayStatus=newStatus;
}

Fixed version (ground truth):
static void updateWifiDisplayStatus(WifiDisplayStatus newStatus){
  final WifiDisplayStatus oldStatus=sStatic.mLastKnownWifiDisplayStatus;
  boolean wantScan=false;
  boolean blockScan=false;
  WifiDisplay[] oldDisplays=oldStatus != null ? oldStatus.getRememberedDisplays() : WifiDisplay.EMPTY_ARRAY;
  WifiDisplay[] newDisplays;
  WifiDisplay[] availableDisplays;
  WifiDisplay activeDisplay;
  if (newStatus.getFeatureState() == WifiDisplayStatus.FEATURE_STATE_ON) {
    newDisplays=newStatus.getRememberedDisplays();
    availableDisplays=newStatus.getAvailableDisplays();
    activeDisplay=newStatus.getActiveDisplay();
  }
 else {
    newDisplays=availableDisplays=WifiDisplay.EMPTY_ARRAY;
    activeDisplay=null;
  }
  for (int i=0; i < newDisplays.length; i++) {
    final WifiDisplay d=newDisplays[i];
    final boolean available=findMatchingDisplay(d,availableDisplays) != null;
    RouteInfo route=findWifiDisplayRoute(d);
    if (route == null) {
      route=makeWifiDisplayRoute(d,available);
      addRouteStatic(route);
      wantScan=true;
    }
 else {
      updateWifiDisplayRoute(route,d,available,newStatus);
    }
    if (d.equals(activeDisplay)) {
      selectRouteStatic(route.getSupportedTypes(),route);
      blockScan=true;
    }
  }
  for (int i=0; i < oldDisplays.length; i++) {
    final WifiDisplay d=oldDisplays[i];
    final WifiDisplay newDisplay=findMatchingDisplay(d,newDisplays);
    if (newDisplay == null) {
      removeRoute(findWifiDisplayRoute(d));
    }
  }
  if (wantScan && !blockScan) {
    sStatic.mDisplayService.scanWifiDisplays();
  }
  sStatic.mLastKnownWifiDisplayStatus=newStatus;
}