Loading core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java +24 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,10 @@ import android.content.BroadcastReceiver; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.os.IPowerManager; import android.os.PowerManager; import android.os.ServiceManager; import android.os.SystemClock; import android.provider.Settings; import android.util.Log; import android.view.KeyEvent; Loading Loading @@ -460,6 +464,26 @@ public class ConnectivityManagerTestActivity extends Activity { return mWifiManager.setWifiEnabled(true); } // Turn screen off public void turnScreenOff() { log("Turn screen off"); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); pm.goToSleep(SystemClock.uptimeMillis() + 100); } // Turn screen on public void turnScreenOn() { log("Turn screen on"); IPowerManager mPowerManagerService = IPowerManager.Stub.asInterface( ServiceManager.getService("power"));; try { mPowerManagerService.userActivityWithForce(SystemClock.uptimeMillis(), false, true); } catch (Exception e) { log(e.toString()); } } /** * Associate the device to given SSID * If the device is already associated with a WiFi, disconnect and forget it, Loading core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java +4 −8 Original line number Diff line number Diff line Loading @@ -26,7 +26,10 @@ import android.net.wifi.WifiConfiguration.KeyMgmt; import android.net.wifi.WifiConfiguration.AuthAlgorithm; import android.net.wifi.WifiManager; import android.os.Environment; import android.os.IPowerManager; import android.os.PowerManager; import android.os.ServiceManager; import android.os.SystemClock; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; Loading @@ -46,7 +49,6 @@ public class WifiApStress private final static String OUTPUT_FILE = "WifiStressTestOutput.txt"; private ConnectivityManagerTestActivity mAct; private int iterations; private PowerManager.WakeLock mWakelock = null; private BufferedWriter mOutputWriter = null; private int mLastIteration = 0; Loading @@ -61,17 +63,11 @@ public class WifiApStress ConnectivityManagerStressTestRunner mRunner = (ConnectivityManagerStressTestRunner)getInstrumentation(); iterations = mRunner.mSoftapIterations; PowerManager pm = (PowerManager)mRunner.getContext().getSystemService(Context.POWER_SERVICE); mWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "wifiApStress"); mWakelock.acquire(); mAct.turnScreenOn(); } @Override public void tearDown() throws Exception { if (mWakelock != null) { mWakelock.release(); } // write the total number of iterations into output file mOutputWriter = new BufferedWriter(new FileWriter(new File( Environment.getExternalStorageDirectory(), OUTPUT_FILE))); Loading core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java +20 −34 Original line number Diff line number Diff line Loading @@ -30,7 +30,9 @@ import android.net.wifi.WifiConfiguration.ProxySettings; import android.net.wifi.WifiManager; import android.os.Environment; import android.os.PowerManager; import android.os.IPowerManager; import android.os.SystemClock; import android.os.ServiceManager; import android.provider.Settings; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.LargeTest; Loading @@ -57,7 +59,7 @@ public class WifiStressTest /** * Wi-Fi idle time for default sleep policy */ private final static long WIFI_IDLE_MS = 5 * 1000; private final static long WIFI_IDLE_MS = 60 * 1000; /** * The delay for Wi-Fi to get into idle, after screen off + WIFI_IDEL_MS + WIFI_IDLE_DELAY Loading @@ -73,7 +75,6 @@ public class WifiStressTest private String mSsid; private String mPassword; private ConnectivityManagerStressTestRunner mRunner; private PowerManager.WakeLock wl = null; private BufferedWriter mOutputWriter = null; public WifiStressTest() { Loading @@ -90,10 +91,11 @@ public class WifiStressTest mPassword = mRunner.mReconnectPassword; mScanIterations = mRunner.mScanIterations; mWifiSleepTime = mRunner.mSleepTime; wl = null; mOutputWriter = new BufferedWriter(new FileWriter(new File( Environment.getExternalStorageDirectory(), OUTPUT_FILE), true)); mAct.turnScreenOn(); if (!mAct.mWifiManager.isWifiEnabled()) { log("Enable wi-fi before stress tests."); if (!mAct.enableWifi()) { tearDown(); fail("enable wifi failed."); Loading @@ -106,9 +108,6 @@ public class WifiStressTest @Override public void tearDown() throws Exception { log("tearDown()"); if ((wl != null) && wl.isHeld()) { wl.release(); } if (mOutputWriter != null) { mOutputWriter.close(); } Loading @@ -129,26 +128,6 @@ public class WifiStressTest } } private void turnScreenOff() { log("Turn screen off"); if (wl != null) { log("release wake lock"); wl.release(); } PowerManager pm = (PowerManager) mRunner.getContext().getSystemService(Context.POWER_SERVICE); pm.goToSleep(SystemClock.uptimeMillis() + 50); } private void turnScreenOn() { log("Turn screen on"); PowerManager pm = (PowerManager)mRunner.getContext().getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "wifiStressTest"); wl.acquire(); } public void log(String message) { Log.v(TAG, message); } Loading Loading @@ -247,7 +226,6 @@ public class WifiStressTest Settings.Secure.WIFI_IDLE_MS, WIFI_IDLE_MS); // Connect to a Wi-Fi network turnScreenOn(); WifiConfiguration config = new WifiConfiguration(); config.SSID = mSsid; config.allowedKeyManagement.set(KeyMgmt.WPA_PSK); Loading @@ -267,26 +245,34 @@ public class WifiStressTest ConnectivityManagerTestActivity.LONG_TIMEOUT)); int i; for (i = 0; i < mReconnectIterations; i++) { // 1. Put device into sleep // 2. Wait for the device to sleep for sometime, very 3G is connected // 3. Wake up the device // 1. Put device into sleep mode // 2. Wait for the device to sleep for sometime, verify wi-fi is off and mobile is on. // 3. Maintain the sleep mode for some time, // 4. Verify the Wi-Fi is still off, and data is on // 5. Wake up the device, verify Wi-Fi is enabled and connected. writeOutput(String.format("iteration %d out of %d", i, mReconnectIterations)); log("iteration: " + i); turnScreenOff(); mAct.turnScreenOff(); PowerManager pm = (PowerManager)mRunner.getContext().getSystemService(Context.POWER_SERVICE); assertFalse(pm.isScreenOn()); sleep(WIFI_IDLE_MS + WIFI_IDLE_DELAY, "Interruped while wait for wifi to be idle"); sleep(WIFI_IDLE_MS, "Interruped while wait for wifi to be idle"); assertTrue("Wait for Wi-Fi to idle timeout", mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.DISCONNECTED, ConnectivityManagerTestActivity.SHORT_TIMEOUT)); 6 * ConnectivityManagerTestActivity.SHORT_TIMEOUT)); // use long timeout as the pppd startup may take several retries. assertTrue("Wait for cellular connection timeout", mAct.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.CONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT)); sleep(mWifiSleepTime + WIFI_IDLE_DELAY, "Interrupted while device is in sleep mode"); // Verify the wi-fi is still off and data connection is on assertEquals("Wi-Fi is reconnected", State.DISCONNECTED, mAct.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState()); assertEquals("Cellular connection is down", State.CONNECTED, mAct.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState()); // Turn screen on again turnScreenOn(); mAct.turnScreenOn(); assertTrue("Wait for Wi-Fi enable timeout after wake up", mAct.waitForWifiState(WifiManager.WIFI_STATE_ENABLED, ConnectivityManagerTestActivity.SHORT_TIMEOUT)); Loading Loading
core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java +24 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,10 @@ import android.content.BroadcastReceiver; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.os.IPowerManager; import android.os.PowerManager; import android.os.ServiceManager; import android.os.SystemClock; import android.provider.Settings; import android.util.Log; import android.view.KeyEvent; Loading Loading @@ -460,6 +464,26 @@ public class ConnectivityManagerTestActivity extends Activity { return mWifiManager.setWifiEnabled(true); } // Turn screen off public void turnScreenOff() { log("Turn screen off"); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); pm.goToSleep(SystemClock.uptimeMillis() + 100); } // Turn screen on public void turnScreenOn() { log("Turn screen on"); IPowerManager mPowerManagerService = IPowerManager.Stub.asInterface( ServiceManager.getService("power"));; try { mPowerManagerService.userActivityWithForce(SystemClock.uptimeMillis(), false, true); } catch (Exception e) { log(e.toString()); } } /** * Associate the device to given SSID * If the device is already associated with a WiFi, disconnect and forget it, Loading
core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java +4 −8 Original line number Diff line number Diff line Loading @@ -26,7 +26,10 @@ import android.net.wifi.WifiConfiguration.KeyMgmt; import android.net.wifi.WifiConfiguration.AuthAlgorithm; import android.net.wifi.WifiManager; import android.os.Environment; import android.os.IPowerManager; import android.os.PowerManager; import android.os.ServiceManager; import android.os.SystemClock; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; Loading @@ -46,7 +49,6 @@ public class WifiApStress private final static String OUTPUT_FILE = "WifiStressTestOutput.txt"; private ConnectivityManagerTestActivity mAct; private int iterations; private PowerManager.WakeLock mWakelock = null; private BufferedWriter mOutputWriter = null; private int mLastIteration = 0; Loading @@ -61,17 +63,11 @@ public class WifiApStress ConnectivityManagerStressTestRunner mRunner = (ConnectivityManagerStressTestRunner)getInstrumentation(); iterations = mRunner.mSoftapIterations; PowerManager pm = (PowerManager)mRunner.getContext().getSystemService(Context.POWER_SERVICE); mWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "wifiApStress"); mWakelock.acquire(); mAct.turnScreenOn(); } @Override public void tearDown() throws Exception { if (mWakelock != null) { mWakelock.release(); } // write the total number of iterations into output file mOutputWriter = new BufferedWriter(new FileWriter(new File( Environment.getExternalStorageDirectory(), OUTPUT_FILE))); Loading
core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java +20 −34 Original line number Diff line number Diff line Loading @@ -30,7 +30,9 @@ import android.net.wifi.WifiConfiguration.ProxySettings; import android.net.wifi.WifiManager; import android.os.Environment; import android.os.PowerManager; import android.os.IPowerManager; import android.os.SystemClock; import android.os.ServiceManager; import android.provider.Settings; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.LargeTest; Loading @@ -57,7 +59,7 @@ public class WifiStressTest /** * Wi-Fi idle time for default sleep policy */ private final static long WIFI_IDLE_MS = 5 * 1000; private final static long WIFI_IDLE_MS = 60 * 1000; /** * The delay for Wi-Fi to get into idle, after screen off + WIFI_IDEL_MS + WIFI_IDLE_DELAY Loading @@ -73,7 +75,6 @@ public class WifiStressTest private String mSsid; private String mPassword; private ConnectivityManagerStressTestRunner mRunner; private PowerManager.WakeLock wl = null; private BufferedWriter mOutputWriter = null; public WifiStressTest() { Loading @@ -90,10 +91,11 @@ public class WifiStressTest mPassword = mRunner.mReconnectPassword; mScanIterations = mRunner.mScanIterations; mWifiSleepTime = mRunner.mSleepTime; wl = null; mOutputWriter = new BufferedWriter(new FileWriter(new File( Environment.getExternalStorageDirectory(), OUTPUT_FILE), true)); mAct.turnScreenOn(); if (!mAct.mWifiManager.isWifiEnabled()) { log("Enable wi-fi before stress tests."); if (!mAct.enableWifi()) { tearDown(); fail("enable wifi failed."); Loading @@ -106,9 +108,6 @@ public class WifiStressTest @Override public void tearDown() throws Exception { log("tearDown()"); if ((wl != null) && wl.isHeld()) { wl.release(); } if (mOutputWriter != null) { mOutputWriter.close(); } Loading @@ -129,26 +128,6 @@ public class WifiStressTest } } private void turnScreenOff() { log("Turn screen off"); if (wl != null) { log("release wake lock"); wl.release(); } PowerManager pm = (PowerManager) mRunner.getContext().getSystemService(Context.POWER_SERVICE); pm.goToSleep(SystemClock.uptimeMillis() + 50); } private void turnScreenOn() { log("Turn screen on"); PowerManager pm = (PowerManager)mRunner.getContext().getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "wifiStressTest"); wl.acquire(); } public void log(String message) { Log.v(TAG, message); } Loading Loading @@ -247,7 +226,6 @@ public class WifiStressTest Settings.Secure.WIFI_IDLE_MS, WIFI_IDLE_MS); // Connect to a Wi-Fi network turnScreenOn(); WifiConfiguration config = new WifiConfiguration(); config.SSID = mSsid; config.allowedKeyManagement.set(KeyMgmt.WPA_PSK); Loading @@ -267,26 +245,34 @@ public class WifiStressTest ConnectivityManagerTestActivity.LONG_TIMEOUT)); int i; for (i = 0; i < mReconnectIterations; i++) { // 1. Put device into sleep // 2. Wait for the device to sleep for sometime, very 3G is connected // 3. Wake up the device // 1. Put device into sleep mode // 2. Wait for the device to sleep for sometime, verify wi-fi is off and mobile is on. // 3. Maintain the sleep mode for some time, // 4. Verify the Wi-Fi is still off, and data is on // 5. Wake up the device, verify Wi-Fi is enabled and connected. writeOutput(String.format("iteration %d out of %d", i, mReconnectIterations)); log("iteration: " + i); turnScreenOff(); mAct.turnScreenOff(); PowerManager pm = (PowerManager)mRunner.getContext().getSystemService(Context.POWER_SERVICE); assertFalse(pm.isScreenOn()); sleep(WIFI_IDLE_MS + WIFI_IDLE_DELAY, "Interruped while wait for wifi to be idle"); sleep(WIFI_IDLE_MS, "Interruped while wait for wifi to be idle"); assertTrue("Wait for Wi-Fi to idle timeout", mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.DISCONNECTED, ConnectivityManagerTestActivity.SHORT_TIMEOUT)); 6 * ConnectivityManagerTestActivity.SHORT_TIMEOUT)); // use long timeout as the pppd startup may take several retries. assertTrue("Wait for cellular connection timeout", mAct.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.CONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT)); sleep(mWifiSleepTime + WIFI_IDLE_DELAY, "Interrupted while device is in sleep mode"); // Verify the wi-fi is still off and data connection is on assertEquals("Wi-Fi is reconnected", State.DISCONNECTED, mAct.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState()); assertEquals("Cellular connection is down", State.CONNECTED, mAct.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState()); // Turn screen on again turnScreenOn(); mAct.turnScreenOn(); assertTrue("Wait for Wi-Fi enable timeout after wake up", mAct.waitForWifiState(WifiManager.WIFI_STATE_ENABLED, ConnectivityManagerTestActivity.SHORT_TIMEOUT)); Loading