From: Cheoleun Moon Date: Wed, 12 Feb 2020 07:47:00 +0000 (+0900) Subject: [WiFi][Non-ACR][Add exception handling codes for precondition] X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F75%2F224675%2F2;p=test%2Ftct%2Fcsharp%2Fapi.git [WiFi][Non-ACR][Add exception handling codes for precondition] Change-Id: I2ff45b4eb74fe825f765709cad02706699cb41fa Signed-off-by: Cheoleun Moon --- diff --git a/tct-suite-vs/Tizen.WiFi.Tests/testcase/support/networkSetup.cs b/tct-suite-vs/Tizen.WiFi.Tests/testcase/support/networkSetup.cs index 83edad3..03c79ed 100755 --- a/tct-suite-vs/Tizen.WiFi.Tests/testcase/support/networkSetup.cs +++ b/tct-suite-vs/Tizen.WiFi.Tests/testcase/support/networkSetup.cs @@ -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() } }