[WiFi][Non-ACR][Add exception handling codes for precondition] 75/224675/2
authorCheoleun Moon <chleun.moon@samsung.com>
Wed, 12 Feb 2020 07:47:00 +0000 (16:47 +0900)
committerCheoleun Moon <chleun.moon@samsung.com>
Wed, 12 Feb 2020 08:14:55 +0000 (17:14 +0900)
Change-Id: I2ff45b4eb74fe825f765709cad02706699cb41fa
Signed-off-by: Cheoleun Moon <chleun.moon@samsung.com>
tct-suite-vs/Tizen.WiFi.Tests/testcase/support/networkSetup.cs

index 83edad3..03c79ed 100755 (executable)
@@ -16,11 +16,39 @@ namespace networkUtils
     public class networkSetup
     {
         private static int MAX_SCAN_TRY = 3;
+        private static WiFiConnectionState connectionState = WiFiConnectionState.Disconnected;
 
         private networkSetup()
         {
         }
 
+        private static void EventHandlerConnectionStateChangedCBState(object sender, ConnectionStateChangedEventArgs e)
+        {
+            connectionState = e.State;
+            Tizen.Log.Info(Globals.LogTag, "ConnectionState is changed: " + connectionState.ToString());
+        }
+
+        private static async Task waitConnecting()
+        {
+            int count = 0;
+            while (true)
+            {
+                await Task.Delay(1000);
+                count++;
+                if (connectionState == WiFiConnectionState.Connected)
+                {
+                    Tizen.Log.Info(Globals.LogTag, "Connected");
+                    break;
+                }
+
+                if (count == 30)
+                {
+                    Tizen.Log.Info(Globals.LogTag, "connecting timeout is reached");
+                    break;
+                }
+            }
+        }
+
         public static async Task ForgetCurrentAP()
         {
             Tizen.Log.Info(Globals.LogTag, "networkSetup.ForgetCurrentAP");
@@ -127,16 +155,31 @@ namespace networkUtils
             Tizen.Log.Info(Globals.LogTag, "Set passphrase " + WiFiPass);
             ap.SecurityInformation.SetPassphrase(WiFiPass);
 
+            WiFiManager.ConnectionStateChanged += EventHandlerConnectionStateChangedCBState;
+
             try
             {
                 await ap.ConnectAsync();
                 Tizen.Log.Info(Globals.LogTag, "Connected");
             }
+            catch (NowInProgressException)
+            {
+                Tizen.Log.Info(Globals.LogTag, "Connecting..");
+                await waitConnecting();
+            }
             catch (System.Exception e)
             {
-                Tizen.Log.Info(Globals.LogTag, "Exception during Wi-Fi Association: " + e);
-                await ap.ConnectAsync();
+                if (WiFiManager.ConnectionState == WiFiConnectionState.Connected)
+                {
+                  Tizen.Log.Info(Globals.LogTag, "Already connected");
+                }
+                else
+                {
+                    Tizen.Log.Info(Globals.LogTag, "Exception during Wi-Fi Association: " + e);
+                    await ap.ConnectAsync();
+                }
             }
+            WiFiManager.ConnectionStateChanged -= EventHandlerConnectionStateChangedCBState;
         } // ConnectWiFi()
     }
 }