@@ -65,6 +65,8 @@ public class ConnectivityManagerTestActivity extends Activity {
6565 public static final long LONG_TIMEOUT = 50 * 1000 ;
6666 // 2 minutes timer between wifi stop and start
6767 public static final long WIFI_STOP_START_INTERVAL = 2 * 60 * 1000 ;
68+ // Set ping test timer to be 3 minutes
69+ public static final long PING_TIMER = 3 * 60 *1000 ;
6870 public static final int SUCCESS = 0 ; // for Wifi tethering state change
6971 public static final int FAILURE = 1 ;
7072 public static final int INIT = -1 ;
@@ -517,37 +519,36 @@ public void turnScreenOn() {
517519 * @return true if the ping test is successful, false otherwise.
518520 */
519521 public boolean pingTest (String [] pingServerList ) {
520- boolean result = false ;
521522 String [] hostList = {"www.google.com" , "www.yahoo.com" ,
522523 "www.bing.com" , "www.facebook.com" , "www.ask.com" };
523524 if (pingServerList != null ) {
524525 hostList = pingServerList ;
525526 }
526- try {
527- // assume the chance that all servers are down is very small
528- for ( int i = 0 ; i < hostList . length ; i ++ ) {
529- String host = hostList [ i ];
530- log ( "Start ping test, ping " + host );
531- Process p = Runtime . getRuntime (). exec ( "ping -c 10 -w 100 " + host );
532- int status = p . waitFor () ;
533- if ( status == 0 ) {
534- // if any of the ping test is successful, return true
535- result = true ;
536- break ;
537- } else {
538- result = false ;
539- log ( "ping " + host + " failed." );
527+
528+ long startTime = System . currentTimeMillis ();
529+ while (( System . currentTimeMillis () - startTime ) < PING_TIMER ) {
530+ try {
531+ // assume the chance that all servers are down is very small
532+ for ( int i = 0 ; i < hostList . length ; i ++ ) {
533+ String host = hostList [ i ] ;
534+ log ( "Start ping test, ping " + host );
535+ Process p = Runtime . getRuntime (). exec ( "ping -c 10 -w 100 " + host );
536+ int status = p . waitFor () ;
537+ if ( status == 0 ) {
538+ // if any of the ping test is successful, return true
539+ return true ;
540+ }
540541 }
542+ } catch (UnknownHostException e ) {
543+ log ("Ping test Fail: Unknown Host" );
544+ } catch (IOException e ) {
545+ log ("Ping test Fail: IOException" );
546+ } catch (InterruptedException e ) {
547+ log ("Ping test Fail: InterruptedException" );
541548 }
542- } catch (UnknownHostException e ) {
543- log ("Ping test Fail: Unknown Host" );
544- } catch (IOException e ) {
545- log ("Ping test Fail: IOException" );
546- } catch (InterruptedException e ) {
547- log ("Ping test Fail: InterruptedException" );
548549 }
549- log ( "return" );
550- return result ;
550+ // ping test timeout
551+ return false ;
551552 }
552553
553554 /**
0 commit comments