[Connection][Non-ACR][Add exception handling codes for precondition] 64/219664/1
authorSeonah Moon <seonah1.moon@samsung.com>
Mon, 9 Dec 2019 05:30:11 +0000 (14:30 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Mon, 9 Dec 2019 05:34:20 +0000 (14:34 +0900)
Change-Id: I69688558f8588e42a26272c050b7436766079375

tct-suite-vs/Tizen.Connection.Tests/testcase/support/networkSetup.cs

index 152a351..026aab4 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");
@@ -130,16 +158,31 @@ namespace networkUtils
                 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()
     }
 }