import android.util.Log;
import android.view.KeyEvent;
+import java.io.IOException;
import java.io.InputStream;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import android.widget.LinearLayout;
}
/**
+ * @param pingServerList a list of servers that can be used for ping test, can be null
+ * @return true if the ping test is successful, false otherwise.
+ */
+ public boolean pingTest(String[] pingServerList) {
+ boolean result = false;
+ String[] hostList = {"www.google.com", "www.yahoo.com",
+ "www.bing.com", "www.facebook.com", "www.ask.com"};
+ if (pingServerList != null) {
+ hostList = pingServerList;
+ }
+ try {
+ // assume the chance that all servers are down is very small
+ for (int i = 0; i < hostList.length; i++ ) {
+ String host = hostList[i];
+ log("Start ping test, ping " + host);
+ Process p = Runtime.getRuntime().exec("ping -c 10 -w 100 " + host);
+ int status = p.waitFor();
+ if (status == 0) {
+ // if any of the ping test is successful, return true
+ result = true;
+ break;
+ } else {
+ result = false;
+ log("ping " + host + " failed.");
+ }
+ }
+ } catch (UnknownHostException e) {
+ log("Ping test Fail: Unknown Host");
+ } catch (IOException e) {
+ log("Ping test Fail: IOException");
+ } catch (InterruptedException e) {
+ log("Ping test Fail: InterruptedException");
+ }
+ log("return");
+ return result;
+ }
+
+ /**
* Associate the device to given SSID
* If the device is already associated with a WiFi, disconnect and forget it,
* We don't verify whether the connection is successful or not, leave this to the test
} catch (Exception e) {
fail("thread in sleep is interrupted");
}
+ assertTrue("no uplink data connection after Wi-Fi tethering", mAct.pingTest(null));
+ // Wait for 5 minutes, and verify the data connection again.
+ // bug id: 3400027
+ try {
+ Thread.sleep(5 * 60 * 1000);
+ } catch (Exception e) {
+ fail("thread in sleep is interrupted");
+ }
+ // Verify the uplink data connection
+ assertTrue("no uplink data connection", mAct.pingTest(null));
+ // Disable soft AP
assertTrue(mAct.mWifiManager.setWifiApEnabled(config, false));
// Wait for 30 seconds until Wi-Fi tethering is stopped
try {
ConnectivityManagerTestActivity.SHORT_TIMEOUT));
assertTrue(mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ // Run ping test to verify the data connection
+ assertTrue("Wi-Fi is connected, but no data connection.", mAct.pingTest(null));
+
int i;
for (i = 0; i < mReconnectIterations; i++) {
// 1. Put device into sleep mode
mAct.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState());
assertEquals("Cellular connection is down", State.CONNECTED,
mAct.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState());
+
+ assertTrue("Mobile is connected, but no data connection.", mAct.pingTest(null));
+
// Turn screen on again
mAct.turnScreenOn();
assertTrue("Wait for Wi-Fi enable timeout after wake up",
assertTrue("Wait for Wi-Fi connection timeout after wake up",
mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
ConnectivityManagerTestActivity.LONG_TIMEOUT));
+ assertTrue("Reconnect to Wi-Fi network, but no data connection.", mAct.pingTest(null));
}
if (i == mReconnectIterations) {
writeOutput(String.format("iteration %d out of %d",