Program: 195252
Project: 195252
Buggy source:
@LargeTest public void testWifiReconnectionAfterSleep(){
  Settings.Global.putInt(mRunner.getContext().getContentResolver(),Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE,0);
  Settings.Global.putInt(mRunner.getContext().getContentResolver(),Settings.Global.WIFI_SLEEP_POLICY,Settings.Global.WIFI_SLEEP_POLICY_DEFAULT);
  Settings.Global.putLong(mRunner.getContext().getContentResolver(),Settings.Global.WIFI_IDLE_MS,WIFI_IDLE_MS);
  WifiConfiguration config;
  if (mPassword == null) {
    config=WifiConfigurationHelper.createOpenConfig(mSsid);
  }
 else {
    config=WifiConfigurationHelper.createPskConfig(mSsid,mPassword);
  }
  assertTrue("String_Node_Str" + mSsid,connectToWifiWithConfiguration(config));
  assertTrue("String_Node_Str",waitForNetworkState(ConnectivityManager.TYPE_WIFI,State.CONNECTED,WIFI_CONNECTION_TIMEOUT));
  assertTrue("String_Node_Str",pingTest());
  long i, sum=0, avgReconnectTime=0;
  for (i=1; i <= mReconnectIterations; i++) {
    writeOutput(String.format("String_Node_Str",i,mReconnectIterations));
    logv("String_Node_Str" + i);
    turnScreenOff();
    long start=SystemClock.uptimeMillis();
    PowerManager pm=(PowerManager)mRunner.getContext().getSystemService(Context.POWER_SERVICE);
    while (pm.isInteractive() && ((SystemClock.uptimeMillis() - start) < SCREEN_OFF_TIMER)) {
      SystemClock.sleep(100);
    }
    assertFalse("String_Node_Str",pm.isInteractive());
    SystemClock.sleep(WIFI_IDLE_MS + WIFI_SHUTDOWN_DELAY);
    if (mWifiOnlyFlag) {
      assertTrue("String_Node_Str",waitUntilNoActiveNetworkConnection(2 * LONG_TIMEOUT));
    }
 else {
      assertTrue("String_Node_Str",waitForNetworkState(ConnectivityManager.TYPE_MOBILE,State.CONNECTED,2 * LONG_TIMEOUT));
    }
    SystemClock.sleep(mWifiSleepTime);
    if (mWifiOnlyFlag) {
      NetworkInfo ni=mCm.getActiveNetworkInfo();
      if (ni != null) {
        Log.e(mLogTag,"String_Node_Str" + ni.toString());
        fail("String_Node_Str");
      }
    }
 else {
      assertEquals("String_Node_Str",State.CONNECTED,mCm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState());
      assertTrue("String_Node_Str",pingTest());
    }
    turnScreenOn();
    long startTime=SystemClock.uptimeMillis();
    assertTrue("String_Node_Str",waitForWifiState(WifiManager.WIFI_STATE_ENABLED,SHORT_TIMEOUT));
    assertTrue("String_Node_Str",waitForNetworkState(ConnectivityManager.TYPE_WIFI,State.CONNECTED,LONG_TIMEOUT));
    long connectionTime=SystemClock.uptimeMillis() - startTime;
    sum+=connectionTime;
    avgReconnectTime=sum / i;
    logv("String_Node_Str" + avgReconnectTime);
    assertTrue("String_Node_Str",pingTest());
  }
  Bundle result=new Bundle();
  result.putLong("String_Node_Str",i - 1);
  result.putLong("String_Node_Str",avgReconnectTime);
  getInstrumentation().sendStatus(Activity.RESULT_FIRST_USER,result);
  if (i == mReconnectIterations + 1) {
    writeOutput(String.format("String_Node_Str",i,mReconnectIterations));
  }
}

Fixed version (ground truth):
@LargeTest public void testWifiReconnectionAfterSleep(){
  Settings.Global.putInt(mRunner.getContext().getContentResolver(),Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE,0);
  Settings.Global.putInt(mRunner.getContext().getContentResolver(),Settings.Global.WIFI_SLEEP_POLICY,Settings.Global.WIFI_SLEEP_POLICY_DEFAULT);
  Settings.Global.putLong(mRunner.getContext().getContentResolver(),Settings.Global.WIFI_IDLE_MS,WIFI_IDLE_MS);
  WifiConfiguration config;
  if (mPassword == null) {
    config=WifiConfigurationHelper.createOpenConfig(mSsid);
  }
 else {
    config=WifiConfigurationHelper.createPskConfig(mSsid,mPassword);
  }
  assertTrue("String_Node_Str" + mSsid,connectToWifiWithConfiguration(config));
  assertTrue("String_Node_Str",waitForNetworkState(ConnectivityManager.TYPE_WIFI,State.CONNECTED,WIFI_CONNECTION_TIMEOUT));
  assertTrue("String_Node_Str",pingTest());
  long i, sum=0, avgReconnectTime=0;
  for (i=1; i <= mReconnectIterations; i++) {
    writeOutput(String.format("String_Node_Str",i,mReconnectIterations));
    logv("String_Node_Str" + i);
    turnScreenOff();
    long start=SystemClock.uptimeMillis();
    PowerManager pm=(PowerManager)mRunner.getContext().getSystemService(Context.POWER_SERVICE);
    while (pm.isInteractive() && ((SystemClock.uptimeMillis() - start) < SCREEN_OFF_TIMER)) {
      SystemClock.sleep(100);
    }
    assertFalse("String_Node_Str",pm.isInteractive());
    SystemClock.sleep(WIFI_IDLE_MS + WIFI_SHUTDOWN_DELAY);
    if (mWifiOnlyFlag) {
      assertTrue("String_Node_Str",waitUntilNoActiveNetworkConnection(2 * LONG_TIMEOUT));
    }
 else {
      assertTrue("String_Node_Str",waitForNetworkState(ConnectivityManager.TYPE_MOBILE,State.CONNECTED,2 * LONG_TIMEOUT));
    }
    SystemClock.sleep(mWifiSleepTime);
    if (mWifiOnlyFlag) {
      NetworkInfo ni=mCm.getActiveNetworkInfo();
      if (ni != null) {
        Log.e(mLogTag,"String_Node_Str" + ni.toString());
        fail("String_Node_Str");
      }
    }
 else {
      assertEquals("String_Node_Str",State.CONNECTED,mCm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState());
      assertTrue("String_Node_Str",pingTest());
    }
    turnScreenOn();
    long startTime=SystemClock.uptimeMillis();
    assertTrue("String_Node_Str",waitForWifiState(WifiManager.WIFI_STATE_ENABLED,SHORT_TIMEOUT));
    assertTrue("String_Node_Str",waitForNetworkState(ConnectivityManager.TYPE_WIFI,State.CONNECTED,LONG_TIMEOUT));
    long connectionTime=SystemClock.uptimeMillis() - startTime;
    sum+=connectionTime;
    avgReconnectTime=sum / i;
    logv("String_Node_Str" + avgReconnectTime);
    assertTrue("String_Node_Str",pingTest());
  }
  Bundle result=new Bundle();
  result.putLong("String_Node_Str",i - 1);
  result.putLong("String_Node_Str",avgReconnectTime);
  getInstrumentation().sendStatus(Activity.RESULT_FIRST_USER,result);
  if (i == mReconnectIterations + 1) {
    writeOutput(String.format("String_Node_Str",i - 1,mReconnectIterations));
  }
}