FileDocCategorySizeDatePackage
WifiApStress.javaAPI DocAndroid 5.1 API4980Thu Mar 12 22:22:12 GMT 2015com.android.connectivitymanagertest.stress

WifiApStress

public class WifiApStress extends com.android.connectivitymanagertest.ConnectivityManagerTestBase
Stress test setting up device as wifi hotspot

Fields Summary
private static String
NETWORK_ID
private static String
PASSWD
private static final String
OUTPUT_FILE
private int
mTotalIterations
private BufferedWriter
mOutputWriter
private int
mLastIteration
private boolean
mWifiOnlyFlag
Constructors Summary
public WifiApStress()


      
        super(WifiApStress.class.getSimpleName());
    
Methods Summary
protected voidsetUp()

        super.setUp();
        ConnectivityManagerStressTestRunner mRunner =
            (ConnectivityManagerStressTestRunner)getInstrumentation();
        mTotalIterations = mRunner.getSoftApInterations();
        mWifiOnlyFlag = mRunner.isWifiOnly();
        turnScreenOn();
    
protected voidtearDown()

        // write the total number of iterations into output file
        mOutputWriter = new BufferedWriter(new FileWriter(new File(
                Environment.getExternalStorageDirectory(), OUTPUT_FILE)));
        mOutputWriter.write(String.format("iteration %d out of %d\n",
                mLastIteration + 1, mTotalIterations));
        mOutputWriter.flush();
        mOutputWriter.close();
        super.tearDown();
    
public voidtestWifiHotSpot()

        if (mWifiOnlyFlag) {
            logv(getName() + " is excluded for wi-fi only test");
            return;
        }
        WifiConfiguration config = new WifiConfiguration();
        config.SSID = NETWORK_ID;
        config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
        config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
        config.preSharedKey = PASSWD;

        // if wifiap enabled, disable it
        assertTrue("failed to disable wifi hotspot",
                mWifiManager.setWifiApEnabled(config, false));
        assertTrue("wifi hotspot not enabled", waitForWifiApState(
                WifiManager.WIFI_AP_STATE_DISABLED, 2 * LONG_TIMEOUT));

        // if Wifi is enabled, disable it
        if (mWifiManager.isWifiEnabled()) {
            assertTrue("failed to disable wifi", disableWifi());
            // wait for the wifi state to be DISABLED
            assertTrue("wifi state not disabled", waitForWifiState(
                    WifiManager.WIFI_STATE_DISABLED, LONG_TIMEOUT));
        }
        int i;
        for (i = 0; i < mTotalIterations; i++) {
            logv("iteration: " + i);
            mLastIteration = i;
            // enable Wifi tethering
            assertTrue("failed to enable wifi hotspot",
                    mWifiManager.setWifiApEnabled(config, true));
            // wait for wifi ap state to be ENABLED
            assertTrue("wifi hotspot not enabled", waitForWifiApState(
                    WifiManager.WIFI_AP_STATE_ENABLED, 2 * LONG_TIMEOUT));
            // wait for wifi tethering result
            assertTrue("tether state not changed", waitForTetherStateChange(LONG_TIMEOUT));
            // allow the wifi tethering to be enabled for 10 seconds
            try {
                Thread.sleep(2 * SHORT_TIMEOUT);
            } catch (Exception e) {
                // ignore
            }
            assertTrue("no uplink data connection after Wi-Fi tethering", pingTest());
            // disable wifi hotspot
            assertTrue("failed to disable wifi hotspot",
                    mWifiManager.setWifiApEnabled(config, false));
            assertTrue("wifi hotspot not enabled", waitForWifiApState(
                    WifiManager.WIFI_AP_STATE_DISABLED, 2 * LONG_TIMEOUT));
            assertFalse("wifi hotspot still enabled", mWifiManager.isWifiApEnabled());
        }