[Network][Non-ACR] Try to connect to Wi-Fi again 70/179870/1
authorchleun.moon <chleun.moon@samsung.com>
Wed, 23 May 2018 06:05:05 +0000 (15:05 +0900)
committerchleun.moon <chleun.moon@samsung.com>
Wed, 23 May 2018 06:05:15 +0000 (15:05 +0900)
Change-Id: I8cf14aa75d2f8cf0a338c4267caa535e11edc607
Signed-off-by: Cheoleun Moon <chleun.moon@samsung.com>
tct-suite-vs/Tizen.Network.Tests/testcase/support/networkSetup.cs

index 7824d94..b07c390 100644 (file)
@@ -16,7 +16,8 @@ namespace networkUtils
     public class networkSetup
     {
         public static networkSetup mInstance = new networkSetup();
-        private static int MAX_TRY = 12;
+        private static int MAX_SCAN_TRY = 12;
+        private static int MAX_CONNECT_TRY = 3;
 
         private networkSetup()
         {
@@ -89,7 +90,8 @@ namespace networkUtils
                     ap = WiFiManager.GetConnectedAP();
                 }
 
-                for (int i = 0; i < MAX_TRY; i++) {
+                int connectTry = 0;
+                for (int i = 0; i < MAX_SCAN_TRY; i++) {
                     var list = WiFiManager.GetFoundAPs();
                     Tizen.Log.Info(Globals.LogTag, "Get Scan List. Try: " + i);
 
@@ -103,9 +105,32 @@ namespace networkUtils
                                 Tizen.Log.Info(Globals.LogTag, "Set passphrase");
                                 item.SecurityInformation.SetPassphrase(WiFiPass);
                             }
-                            await item.ConnectAsync();
-                            Tizen.Log.Info(Globals.LogTag, "Connected");
-                            return;
+                            try
+                            {
+                                await item.ConnectAsync();
+                                Tizen.Log.Info(Globals.LogTag, "Connected");
+                                return;
+                            }
+                            catch (System.Exception e)
+                            {
+                                /*
+                                 * It is possible that ConnectAsync is failed due to some network environment issue.
+                                 * In this case, we will try to connect the AP again.
+                                 */
+                                if (connectTry == MAX_CONNECT_TRY)
+                                {
+                                    Tizen.Log.Info(Globals.LogTag, "Failed to connect");
+                                    throw e;
+                                }
+                                else
+                                {
+                                    connectTry++;
+                                    Tizen.Log.Info(Globals.LogTag, "Failed to connect --> try again after 3 seconds");
+                                    await Task.Delay(3000);
+                                    break;
+                                }
+
+                            }
                         }
                     }
                     if (i == 3)
@@ -114,7 +139,7 @@ namespace networkUtils
                         await WiFiManager.ScanAsync();
                     }
                     await Task.Delay(10000);
-                } // for (int i = 0; i < MAX_TRY; i++) {
+                } // for (int i = 0; i < MAX_SCAN_TRY; i++) {
            } // if (ap != null && ap.NetworkInformation.Essid != WiFiName)
         } // WiFiActivate()
     }