Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e355e75a authored by Xia Wang's avatar Xia Wang Committed by Android (Google) Code Review
Browse files

Merge "Add ping test to verify data connection."

parents ffae14aa 6bffe14c
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -30,7 +30,9 @@ import android.provider.Settings;
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;
@@ -484,6 +486,44 @@ public class ConnectivityManagerTestActivity extends Activity {
        }
    }

    /**
     * @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,
+11 −0
Original line number Diff line number Diff line
@@ -107,6 +107,17 @@ public class WifiApStress
            } 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 {
+7 −0
Original line number Diff line number Diff line
@@ -243,6 +243,9 @@ public class WifiStressTest
                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
@@ -271,6 +274,9 @@ public class WifiStressTest
                    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",
@@ -279,6 +285,7 @@ public class WifiStressTest
            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",