From 0beeb74bff3ba91267f4a301201d7e2fc2402d65 Mon Sep 17 00:00:00 2001 From: chleun-moon <32117100+chleun-moon@users.noreply.github.com> Date: Tue, 13 Mar 2018 17:40:20 +0900 Subject: [PATCH] [Connection][WiFi] Handling exception for event and async methods (#155) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * [MediaContent] Added "content.scanning.others" feature tags to related methods. (#15) Signed-off-by: coderhyme * [MediaCodec] Added feature tags. (#14) Signed-off-by: coderhyme * [MediaContent] Added NotSupportedException to be thrown when the feature is not supported. (#18) Signed-off-by: coderhyme * [MediaPlayer] Added feature tag on the ApplyAudioStreamPolicy method. (#16) Signed-off-by: coderhyme * [NUI] Fix sibling issue (#20) Signed-off-by: huiyu,eun * [NUI] DALi version 1.2.80 (#21) * [Tizen.NUI]Fix bug about Children property. (#23) Signed-off-by: huiyu,eun * [TtsEngine] Fix invalid marshalling (#25) Signed-off-by: Suyeon Hwang * Fixed issue where key event does not occur when focus is lost (#24) * NUI release 1.2.81 (#27) * [4.0] Fix auto tct widgetImpl dispose crash Signed-off-by: huiyu,eun * [NUI] DALi version 1.2.81 Signed-off-by: huiyu,eun * [TtsEngine/SttEngine] Fix invalid marshalling (#29) * [TtsEngine] Fix invalid marshalling Signed-off-by: Suyeon Hwang * [TtsEngine] Fix invalid marshalling Signed-off-by: Suyeon Hwang * [SttEngine] Fix invalid marshalling Signed-off-by: Suyeon Hwang * Restore converted key before calling a callback (#30) * [MediaPlayer] Added ErrorHandler registration methods for internal use. (#31) Signed-off-by: coderhyme * [Recorder] Change recorder feature (#32) * [SystemSettings] Changed event handler routine. (#22) Signed-off-by: jinwang.an * [ElmSharp] Changed Widget.SetFocus() internal routine (#35) * [ElmSharp] Changed Widget.SetFocus() internal routine * [ElmSharp] fix elm_object_focuse_clear() routine order * [ElmSharp] elm_object_focus_clear() code clean up * [NUI] Support for animated GIF (#34) * [NUI] Added playback (i.e. Play, Pause, Stop) support for the animated GIF Signed-off-by: huiyu,eun * [NUI] Loop count support for animated GIF Signed-off-by: huiyu,eun * [NUI] Modify property index Signed-off-by: huiyu,eun * [NUI] Fix SiblingOrder return value (#37) If parentChildren count is empty, return 0 Signed-off-by: huiyu,eun * [NUI] Fix svace issue (#41) * [NUI] Fix svace issue Value widget, which was created by as-operator, so can be null, is dereferenced in method call widget.GetIntPtr() Value value, which is result of method invocation with possible null return value, is dereferenced in method call value.Get() Signed-off-by: huiyu,eun * [NUI] Modify unassigned local variable 'str' Signed-off-by: huiyu,eun * change a property to a method for exception handling (#46) * [ElmSharp] Remove layout for Background (#28) Signed-off-by: Jeonghyun Yun * [ElmSharp] fix svace issue (#42) Add an optional extended description… * [NUI] Nui release 1.2.82 (#45) * [NUI] Added RefObjectPtr null check condition in Registry copy from gerrit : https://review.tizen.org/gerrit/#/c/167442/1 Signed-off-by: huiyu,eun * [NUI] C# binding for VERTICAL_LINE_ALIGNMENT property Signed-off-by: huiyu,eun * [NUI] NUI release 1.2.82 Signed-off-by: huiyu,eun * [NUI] Add SetProperty for VerticalLineAlignment (#48) Signed-off-by: huiyu,eun * [Device] add lock for global variable of led and battery (#49) * [Information] Fix delegate lifetime issue (#52) Signed-off-by: kichankwon * Fixed svace issue (#53) * [Notification] Fix handle leak (#57) * fix svace issues (#59) * [Tts/Stt/VoiceControl] Fix indent and lock issue (#61) Signed-off-by: Suyeon Hwang * [Calendar] Fix svace issue (#62) * [NUI] Add protected codes to avoid the crash when the IntPtr of key is 0 (#72) Signed-off-by: dongsug.song * [NUI]fix memory leak problem caused by wrong increased ref-cnt (#75) Signed-off-by: dongsug.song * [ElmSharp] Changed Background Color property internal implementation to Widget BackgroundColor property (#58) Signed-off-by: Jeonghyun Yun * [NUI] Apply sibling patch (#74) * Revert "[NUI] Fix SiblingOrder return value (#37)" This reverts commit 6591fa264a9316785a0601f0b25f2fd1994dad22. * Revert "[Tizen.NUI]Fix bug about Children property. (#23)" This reverts commit 6d306df109b452d8f03bc28180b56bf38fd4ed2d. * Revert "[NUI] Fix sibling issue (#20)" This reverts commit da9ec169dab93abd132247eaad37eaf559e99edf. * [NUI] Fix sibling issue This reverts commit ee09d11559d07c19d379e5cd6f81b953c5b179ef. * [Tizen.NUI]Fix bug about Children property. This reverts commit 5c4ef3415bdef7ea5d6ae8ee4c07c330a2458b16. * [NUI] Fix SiblingOrder return value This reverts commit 28e5a6c00537b60b1bcb3b4f01d2ef9b2f08f10e. * [NUI] NUI_1.2.83 version release (#77) * [NUI] remove this.Reset in Animation Dispose * [NUI] NUI_1.2.83 Version * [NUI]Revert sibling patch (#78) * Revert "[NUI] Fix SiblingOrder return value (#37)" This reverts commit 6591fa264a9316785a0601f0b25f2fd1994dad22. * Revert "[Tizen.NUI]Fix bug about Children property. (#23)" This reverts commit 6d306df109b452d8f03bc28180b56bf38fd4ed2d. * Revert "[NUI] Fix sibling issue (#20)" This reverts commit da9ec169dab93abd132247eaad37eaf559e99edf. * [NUI] Apply sibling patch (#79) * [NUI] Fix sibling issue This reverts commit c52e414d9473f1ec744bb30eeed0bed033eec2dc. * [NUI]Fix bug about Children property. This reverts commit 5f2fa0f0e7bc26eed46b38431f6b702cc396e52f. * [NUI] Fix SiblingOrder return value This reverts commit 83d9228a204bccef4f9cd7b8d5927c869d8e41b4. * [TEEC] Guard session close in destructor, follow 'Dispose Pattern' (#88) * [NUI] Add protected codes for SiblingOrder (#89) Signed-off-by: huiyu,eun * [Telephony] Fix call notification numbering (#91) * [Multimedia] Fixed wrong implementation of MediaBufferBase. (#94) Signed-off-by: coderhyme * [NUI] Fix memory leak problem (#95) Signed-off-by: huiyu,eun * Update README.md * [VoiceControl/VoiceControlWidget] Fix invalid null checking (#96) Signed-off-by: Suyeon Hwang * [NUI] Fix Parent crash error (#97) * [NUI] fix Parent property memory leak (#100) * Update CODEOWNERS * [NUI] memory leak issue, rollback changes except View and Layer (#104) * Fix xml documentation issues (#105) 3 cases of invalid xml structure added to list items 2 cases of < character - replaced with < * [NUI] IntPtr is not Null always, null should be IntPtr.Zero (#106) * [NUI] NUI_1.2.84 version release (#107) Signed-off-by: huiyu,eun * [NUI] Fix TCT Crash issue, Parent crash (#108) Signed-off-by: huiyu,eun * [Multimedia] Restored the GetException internal api of Player. (#109) Signed-off-by: coderhyme * [Multimedia] Fixed wrong implementation of GetException of MediaPlayer. (#110) Signed-off-by: coderhyme * [NUI] Fix memory leak (#111) * [NUI] Change Registry as concurrent collection for protection code (#113) * [NUI] NUI_1.2.85 version release (#115) Signed-off-by: huiyu,eun * [NUI] Delete NUI Log (#116) Signed-off-by: huiyu,eun * Update README.md * [NUI] Check NUI internal API version, Remove tizenfx build dependency from dali (#117) * [Build] Remove dali native version check from rpm spec (#118) * fixed delegator reference holding issue (#122) * [Multimedia] Modify MediaPlayer for product reuse (#124) * Revert "[Telephony] Fix call notification numbering (#91)" (#125) This reverts commit 613641d2906b3b9ca83e3e9abdedd4dee15e86a1. * Update CODEOWNERS * [Stt] Fix lock issue (#126) Signed-off-by: sungrae jo * [Tizen.Network.WiFi] Use lock on checking if instance is null (#131) * [WiFi][Connection] Apply CAPIs for thread handling (#134) * [Tizen.Network.WiFi] Use lock on checking if instance is null * [WiFi][Connection] Apply CAPIs for thread handling * [Tizen.Applications.MessagePort] Remove checking name of remoteport (#135) To get remote app id regardless of the remote-port name * [Tizen.Applications.DataControl] Fixed a bug for checking if IntPtr is null (#137) * [Notification] Save the hidetime, deletetime value (#140) - regardless of IsAutoRemove Signed-off-by: mk5004.lee * [Connection][WiFi]Apply TizenSynchronizationContext for event handling (#138) * [NUI] Fix parent get issue (#141) Signed-off-by: huiyu * [Connection][WiFi] Use TizenSynchronizationContext.Post for asynchronous methods (#147) * [Tizen.Network.WiFi] Use lock on checking if instance is null * [WiFi][Connection] Apply CAPIs for thread handling * [Connection][WiFi] Use TizenSynchronizationContext.Post for asynchronous methods * [Connection][WiFi] Use TizenSynchronizationContext.Post for asynchronous methods #2 Fixed build error * [Connection][WiFi] Handling exception for event and async methods --- .../ConnectionInternalManager.cs | 141 ++++++++++++++++----- .../Tizen.Network.WiFi/WiFiAP.cs | 131 +++++++++++-------- .../Tizen.Network.WiFi/WiFiConfiguration.cs | 7 +- .../Tizen.Network.WiFi/WiFiManagerImpl.cs | 80 +++++++++--- .../Tizen.Network.WiFi/WiFiNetworkChange.cs | 75 +++++++++-- 5 files changed, 321 insertions(+), 113 deletions(-) diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs index 91e9fe1..7f3718a 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs @@ -18,10 +18,10 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading; using System.Threading.Tasks; using System.Runtime.InteropServices; using System.Collections; +using System.Threading; using Tizen.Applications; namespace Tizen.Network.Connection @@ -34,7 +34,6 @@ namespace Tizen.Network.Connection public HandleHolder() { _tid = Thread.CurrentThread.ManagedThreadId; - Log.Info(Globals.LogTag, "PInvoke connection_create for Thread " + _tid); int ret = Interop.Connection.Create(_tid, out Handle); Log.Info(Globals.LogTag, "Handle: " + Handle); @@ -123,7 +122,15 @@ namespace Tizen.Network.Connection { if (_ConnectionTypeChanged == null) { - ConnectionTypeChangedStart(); + try + { + ConnectionTypeChangedStart(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on adding ConnectionTypeChanged\n" + e.ToString()); + return; + } } _ConnectionTypeChanged += value; }, null); @@ -135,7 +142,14 @@ namespace Tizen.Network.Connection _ConnectionTypeChanged -= value; if (_ConnectionTypeChanged == null) { - ConnectionTypeChangedStop(); + try + { + ConnectionTypeChangedStop(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on removing ConnectionTypeChanged\n" + e.ToString()); + } } }, null); } @@ -179,7 +193,15 @@ namespace Tizen.Network.Connection { if (_EthernetCableStateChanged == null) { - EthernetCableStateChangedStart(); + try + { + EthernetCableStateChangedStart(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on adding EthernetCableStateChanged\n" + e.ToString()); + return; + } } _EthernetCableStateChanged += value; }, null); @@ -191,7 +213,14 @@ namespace Tizen.Network.Connection _EthernetCableStateChanged -= value; if (_EthernetCableStateChanged == null) { - EthernetCableStateChangedStop(); + try + { + EthernetCableStateChangedStop(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on removing EthernetCableStateChanged\n" + e.ToString()); + } } }, null); } @@ -239,7 +268,15 @@ namespace Tizen.Network.Connection { if (_IPAddressChanged == null) { - IPAddressChangedStart(); + try + { + IPAddressChangedStart(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on adding IPAddressChanged\n" + e.ToString()); + return; + } } _IPAddressChanged += value; }, null); @@ -252,7 +289,14 @@ namespace Tizen.Network.Connection _IPAddressChanged -= value; if (_IPAddressChanged == null) { - IPAddressChangedStop(); + try + { + IPAddressChangedStop(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on removing IPAddressChanged\n" + e.ToString()); + } } }, null); } @@ -300,7 +344,15 @@ namespace Tizen.Network.Connection { if (_ProxyAddressChanged == null) { - ProxyAddressChangedStart(); + try + { + ProxyAddressChangedStart(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on adding ProxyAddressChanged\n" + e.ToString()); + return; + } } _ProxyAddressChanged += value; }, null); @@ -312,7 +364,14 @@ namespace Tizen.Network.Connection _ProxyAddressChanged -= value; if (_ProxyAddressChanged == null) { - ProxyAddressChangedStop(); + try + { + ProxyAddressChangedStop(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on removing ProxyAddressChanged\n" + e.ToString()); + } } }, null); } @@ -821,13 +880,21 @@ namespace Tizen.Network.Connection context.Post((x) => { Log.Info(Globals.LogTag, "Interop.Connection.SetDefaultCellularServiceProfileAsync " + profile.Name); - int ret = Interop.Connection.SetDefaultCellularServiceProfileAsync(GetHandle(), (int)type, profile.ProfileHandle, Callback, (IntPtr)0); - if ((ConnectionError)ret != ConnectionError.None) + try { - Log.Error(Globals.LogTag, "It failed to set default cellular profile, " + (ConnectionError)ret); - ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); - ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); - ConnectionErrorFactory.ThrowConnectionException(ret); + int ret = Interop.Connection.SetDefaultCellularServiceProfileAsync(GetHandle(), (int)type, profile.ProfileHandle, Callback, (IntPtr)0); + + if ((ConnectionError)ret != ConnectionError.None) + { + Log.Error(Globals.LogTag, "It failed to set default cellular profile, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); + } + } catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on SetDefaultCellularServiceProfileAsync\n" + e.ToString()); + task.SetException(e); } }, null); @@ -911,13 +978,21 @@ namespace Tizen.Network.Connection context.Post((x) => { Log.Info(Globals.LogTag, "Interop.Connection.OpenProfile " + profile.Name); - int ret = Interop.Connection.OpenProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero); - if ((ConnectionError)ret != ConnectionError.None) + try { - Log.Error(Globals.LogTag, "It failed to connect profile, " + (ConnectionError)ret); - ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth"); - ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); - ConnectionErrorFactory.ThrowConnectionException(ret); + int ret = Interop.Connection.OpenProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero); + if ((ConnectionError)ret != ConnectionError.None) + { + Log.Error(Globals.LogTag, "It failed to connect profile, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); + } + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on OpenProfile\n" + e.ToString()); + task.SetException(e); } }, null); @@ -954,14 +1029,22 @@ namespace Tizen.Network.Connection context.Post((x) => { Log.Info(Globals.LogTag, "Interop.Connection.CloseProfile " + profile.Name); - int ret = Interop.Connection.CloseProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero); - if ((ConnectionError)ret != ConnectionError.None) + try { - Log.Error(Globals.LogTag, "It failed to disconnect profile, " + (ConnectionError)ret); - ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth"); - ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.set)"); - ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); - ConnectionErrorFactory.ThrowConnectionException(ret); + int ret = Interop.Connection.CloseProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero); + if ((ConnectionError)ret != ConnectionError.None) + { + Log.Error(Globals.LogTag, "It failed to disconnect profile, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth"); + ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.set)"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); + } + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on CloseProfile\n" + e.ToString()); + task.SetException(e); } }, null); diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs index 24d8476..cc72ad6 100755 --- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs +++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs @@ -135,11 +135,8 @@ namespace Tizen.Network.WiFi if (_disposed) return; - if (disposing) - { - Interop.WiFi.AP.Destroy(_apHandle); - _apHandle = IntPtr.Zero; - } + Interop.WiFi.AP.Destroy(_apHandle); + _apHandle = IntPtr.Zero; _disposed = true; } @@ -249,11 +246,19 @@ namespace Tizen.Network.WiFi context.Post((x) => { Log.Info(Globals.LogTag, "Interop.WiFi.Connect"); - int ret = Interop.WiFi.Connect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id); - if (ret != (int)WiFiError.None) + try + { + int ret = Interop.WiFi.Connect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle); + } + } + catch (Exception e) { - Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret); - WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle); + Log.Error(Globals.LogTag, "Exception on ConnectAsync\n" + e.ToString()); + task.SetException(e); } }, null); @@ -310,33 +315,41 @@ namespace Tizen.Network.WiFi context.Post((x) => { - int ret = -1; - if (info.GetType() == typeof(WpsPbcInfo)) + try { - Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPb"); - ret = Interop.WiFi.ConnectByWpsPbc(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id); - } - else if (info.GetType() == typeof(WpsPinInfo)) - { - WpsPinInfo pinInfo = (WpsPinInfo)info; - if (pinInfo.GetWpsPin() == null) + int ret = -1; + if (info.GetType() == typeof(WpsPbcInfo)) { - throw new ArgumentNullException("Wps pin should not be null"); + Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPb"); + ret = Interop.WiFi.ConnectByWpsPbc(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id); } - - if (pinInfo.GetWpsPin().Length == 0 || pinInfo.GetWpsPin().Length > 8) + else if (info.GetType() == typeof(WpsPinInfo)) { - throw new ArgumentOutOfRangeException("Wps pin should not be empty or more than 7 characters"); + WpsPinInfo pinInfo = (WpsPinInfo)info; + if (pinInfo.GetWpsPin() == null) + { + throw new ArgumentNullException("Wps pin should not be null"); + } + + if (pinInfo.GetWpsPin().Length == 0 || pinInfo.GetWpsPin().Length > 8) + { + throw new ArgumentOutOfRangeException("Wps pin should not be empty or more than 7 characters"); + } + + Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPin"); + ret = Interop.WiFi.ConnectByWpsPin(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, pinInfo.GetWpsPin(), _callback_map[id], id); } - Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPin"); - ret = Interop.WiFi.ConnectByWpsPin(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, pinInfo.GetWpsPin(), _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle); + } } - - if (ret != (int)WiFiError.None) + catch (Exception e) { - Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret); - WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle); + Log.Error(Globals.LogTag, "Exception on ConnectWpsAsync\n" + e.ToString()); + task.SetException(e); } }, null); @@ -393,33 +406,41 @@ namespace Tizen.Network.WiFi s_context.Post((x) => { - int ret = -1; - if (info.GetType() == typeof(WpsPbcInfo)) - { - Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPbcWithoutSsid"); - ret = Interop.WiFi.ConnectByWpsPbcWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), s_callbackMap[id], id); - } - else if (info.GetType() == typeof(WpsPinInfo)) + try { - WpsPinInfo pinInfo = (WpsPinInfo)info; - if (pinInfo.GetWpsPin() == null) + int ret = -1; + if (info.GetType() == typeof(WpsPbcInfo)) { - throw new ArgumentNullException("Wps pin should not be null"); + Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPbcWithoutSsid"); + ret = Interop.WiFi.ConnectByWpsPbcWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), s_callbackMap[id], id); } - - if (pinInfo.GetWpsPin().Length != 4 && pinInfo.GetWpsPin().Length != 8) + else if (info.GetType() == typeof(WpsPinInfo)) { - throw new ArgumentOutOfRangeException("Wps pin should be of 4 or 8 characters long"); + WpsPinInfo pinInfo = (WpsPinInfo)info; + if (pinInfo.GetWpsPin() == null) + { + throw new ArgumentNullException("Wps pin should not be null"); + } + + if (pinInfo.GetWpsPin().Length != 4 && pinInfo.GetWpsPin().Length != 8) + { + throw new ArgumentOutOfRangeException("Wps pin should be of 4 or 8 characters long"); + } + + Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPinWithoutSsid"); + ret = Interop.WiFi.ConnectByWpsPinWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), pinInfo.GetWpsPin(), s_callbackMap[id], id); } - Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPinWithoutSsid"); - ret = Interop.WiFi.ConnectByWpsPinWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), pinInfo.GetWpsPin(), s_callbackMap[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle()); + } } - - if (ret != (int)WiFiError.None) + catch (Exception e) { - Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret); - WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle()); + Log.Error(Globals.LogTag, "Exception on ConnectWpsWithoutSsidAsync\n" + e.ToString()); + task.SetException(e); } }, null); @@ -474,11 +495,19 @@ namespace Tizen.Network.WiFi context.Post((x) => { Log.Info(Globals.LogTag, "Interop.WiFi.Disconnect"); - int ret = Interop.WiFi.Disconnect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id); - if (ret != (int)WiFiError.None) + try + { + int ret = Interop.WiFi.Disconnect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to disconnect wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle); + } + } + catch (Exception e) { - Log.Error(Globals.LogTag, "Failed to disconnect wifi, Error - " + (WiFiError)ret); - WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle); + Log.Error(Globals.LogTag, "Exception on Disconnect\n" + e.ToString()); + task.SetException(e); } }, null); diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs index ea34275..1fd57bc 100755 --- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs +++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs @@ -219,11 +219,8 @@ namespace Tizen.Network.WiFi if (_disposed) return; - if (disposing) - { - Interop.WiFi.Config.Destroy(_configHandle); - _configHandle = IntPtr.Zero; - } + Interop.WiFi.Config.Destroy(_configHandle); + _configHandle = IntPtr.Zero; _disposed = true; } diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs index 9ac1150..0578f01 100755 --- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs +++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs @@ -314,11 +314,19 @@ namespace Tizen.Network.WiFi context.Post((x) => { Log.Info(Globals.LogTag, "Interop.WiFi.ActivateAsync"); - int ret = Interop.WiFi.Activate(GetSafeHandle(), _callback_map[id], id); - if (ret != (int)WiFiError.None) + try + { + int ret = Interop.WiFi.Activate(GetSafeHandle(), _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to activate wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle()); + } + } + catch (Exception e) { - Log.Error(Globals.LogTag, "Failed to activate wifi, Error - " + (WiFiError)ret); - WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle()); + Log.Error(Globals.LogTag, "Exception on ActivateAsync\n" + e.ToString()); + task.SetException(e); } }, null); @@ -355,11 +363,19 @@ namespace Tizen.Network.WiFi context.Post((x) => { Log.Info(Globals.LogTag, "Interop.WiFi.ActivateWithWiFiPickerTestedAsync"); - int ret = Interop.WiFi.ActivateWithWiFiPickerTested(GetSafeHandle(), _callback_map[id], id); - if (ret != (int)WiFiError.None) + try { - Log.Error(Globals.LogTag, "Failed to activate wifi, Error - " + (WiFiError)ret); - WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle()); + int ret = Interop.WiFi.ActivateWithWiFiPickerTested(GetSafeHandle(), _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to activate wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle()); + } + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on ActivateWithWiFiPickerTestedAsync\n" + e.ToString()); + task.SetException(e); } }, null); @@ -396,11 +412,19 @@ namespace Tizen.Network.WiFi context.Post((x) => { Log.Info(Globals.LogTag, "Interop.WiFi.Deactivate"); - int ret = Interop.WiFi.Deactivate(GetSafeHandle(), _callback_map[id], id); - if (ret != (int)WiFiError.None) + try + { + int ret = Interop.WiFi.Deactivate(GetSafeHandle(), _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to deactivate wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle()); + } + } + catch (Exception e) { - Log.Error(Globals.LogTag, "Failed to deactivate wifi, Error - " + (WiFiError)ret); - WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle()); + Log.Error(Globals.LogTag, "Exception on Deactivate\n" + e.ToString()); + task.SetException(e); } }, null); @@ -437,11 +461,19 @@ namespace Tizen.Network.WiFi context.Post((x) => { Log.Info(Globals.LogTag, "Interop.WiFi.Scan"); - int ret = Interop.WiFi.Scan(GetSafeHandle(), _callback_map[id], id); - if (ret != (int)WiFiError.None) + try { - Log.Error(Globals.LogTag, "Failed to scan all AP, Error - " + (WiFiError)ret); - WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle()); + int ret = Interop.WiFi.Scan(GetSafeHandle(), _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to scan all AP, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle()); + } + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on Scan\n" + e.ToString()); + task.SetException(e); } }, null); @@ -478,11 +510,19 @@ namespace Tizen.Network.WiFi context.Post((x) => { Log.Info(Globals.LogTag, "Interop.WiFi.ScanSpecificAPAsync"); - int ret = Interop.WiFi.ScanSpecificAP(GetSafeHandle(), essid, _callback_map[id], id); - if (ret != (int)WiFiError.None) + try + { + int ret = Interop.WiFi.ScanSpecificAP(GetSafeHandle(), essid, _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to scan with specific AP, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle()); + } + } + catch (Exception e) { - Log.Error(Globals.LogTag, "Failed to scan with specific AP, Error - " + (WiFiError)ret); - WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle()); + Log.Error(Globals.LogTag, "Exception on ScanSpecificAPAsync\n" + e.ToString()); + task.SetException(e); } }, null); diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetworkChange.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetworkChange.cs index 122c905..4c39c98 100755 --- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetworkChange.cs +++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetworkChange.cs @@ -62,7 +62,14 @@ namespace Tizen.Network.WiFi { if (_deviceStateChanged == null) { - RegisterDeviceStateChangedEvent(); + try + { + RegisterDeviceStateChangedEvent(); + } catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on adding DeviceStateChanged\n" + e.ToString()); + return; + } } _deviceStateChanged += value; }, null); @@ -74,7 +81,14 @@ namespace Tizen.Network.WiFi _deviceStateChanged -= value; if (_deviceStateChanged == null) { - UnregisterDeviceStateChangedEvent(); + try + { + UnregisterDeviceStateChangedEvent(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on removing DeviceStateChanged\n" + e.ToString()); + } } }, null); } @@ -88,7 +102,15 @@ namespace Tizen.Network.WiFi { if (_connectionStateChanged == null) { - RegisterConnectionStateChangedEvent(); + try + { + RegisterConnectionStateChangedEvent(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on adding ConnectionStateChanged\n" + e.ToString()); + return; + } } _connectionStateChanged += value; }, null); @@ -100,7 +122,14 @@ namespace Tizen.Network.WiFi _connectionStateChanged -= value; if (_connectionStateChanged == null) { - UnregisterConnectionStateChangedEvent(); + try + { + UnregisterConnectionStateChangedEvent(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on removing ConnectionStateChanged\n" + e.ToString()); + } } }, null); } @@ -114,7 +143,15 @@ namespace Tizen.Network.WiFi { if (_rssiLevelChanged == null) { - RegisterRssiLevelChangedEvent(); + try + { + RegisterRssiLevelChangedEvent(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on adding RssiLevelChanged\n" + e.ToString()); + return; + } } _rssiLevelChanged += value; }, null); @@ -126,7 +163,14 @@ namespace Tizen.Network.WiFi _rssiLevelChanged -= value; if (_rssiLevelChanged == null) { - UnregisterRssiLevelChangedEvent(); + try + { + UnregisterRssiLevelChangedEvent(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on removing RssiLevelChanged\n" + e.ToString()); + } } }, null); } @@ -140,7 +184,15 @@ namespace Tizen.Network.WiFi { if (_backgroundScanFinished == null) { - RegisterBackgroundScanFinishedEvent(); + try + { + RegisterBackgroundScanFinishedEvent(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on adding BackgroundScanFinished\n" + e.ToString()); + return; + } } _backgroundScanFinished += value; }, null); @@ -152,7 +204,14 @@ namespace Tizen.Network.WiFi _backgroundScanFinished -= value; if (_backgroundScanFinished == null) { - UnregisterBackgroundScanFinishedEvent(); + try + { + UnregisterBackgroundScanFinishedEvent(); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on removing BackgroundScanFinished\n" + e.ToString()); + } } }, null); } -- 2.7.4