[TCSACR-203][WiFi] Add new Exceptions (#588)
authorchleun-moon <32117100+chleun-moon@users.noreply.github.com>
Fri, 7 Dec 2018 04:31:23 +0000 (13:31 +0900)
committerjeik01 <35021126+jeik01@users.noreply.github.com>
Fri, 7 Dec 2018 04:31:23 +0000 (13:31 +0900)
* [WiFi] Add new Exceptions

* [WiFi] Fix year as 2018 in Copyrights comment

src/Tizen.Network.WiFi/Tizen.Network.WiFi/InvalidKeyException.cs [new file with mode: 0755]
src/Tizen.Network.WiFi/Tizen.Network.WiFi/NowInProgressException.cs [new file with mode: 0755]
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiErrorFactory.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs

diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/InvalidKeyException.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/InvalidKeyException.cs
new file mode 100755 (executable)
index 0000000..724d7eb
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Network.WiFi
+{
+    /// <summary>
+    /// The class that represents the exception which will be thrown when an operation is in progress
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    public class InvalidKeyException : InvalidOperationException
+    {
+        /// <summary>
+        /// Constructor
+        /// </summary>
+        /// <param name="message">The localized error message string</param>
+        /// <since_tizen> 6 </since_tizen>
+        public InvalidKeyException(string message) : base(message)
+        {
+        }
+    }
+}
diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/NowInProgressException.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/NowInProgressException.cs
new file mode 100755 (executable)
index 0000000..12de934
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Network.WiFi
+{
+    /// <summary>
+    /// The class that represents the exception which will be thrown when an operation is in progress
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    public class NowInProgressException : InvalidOperationException
+    {
+        /// <summary>
+        /// Constructor
+        /// </summary>
+        /// <param name="message">The localized error message string</param>
+        /// <since_tizen> 6 </since_tizen>
+        public NowInProgressException(string message) : base(message)
+        {
+        }
+    }
+}
index 935d26b..40b23c1 100644 (file)
@@ -218,10 +218,12 @@ namespace Tizen.Network.WiFi
         /// <privilege>http://tizen.org/privilege/network.set</privilege>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
+        /// <exception cref="NowInProgressException">Thrown when the Wi-Fi connection is now in progress.</exception>
         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
         /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception>
         /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
+        /// <exception cref="InvalidKeyException">Thrown when the key is wrong.</exception>
         public Task ConnectAsync()
         {
             Log.Info(Globals.LogTag, "ConnectAsync HashCode: " + _apHandle.GetHashCode());
@@ -240,7 +242,7 @@ namespace Tizen.Network.WiFi
                     if (error != (int)WiFiError.None)
                     {
                         Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error);
-                        task.SetException(new InvalidOperationException("Error occurs during WiFi connecting, " + (WiFiError)error));
+                        task.SetException(WiFiErrorFactory.GetException(error, "Error occurs during WiFi connecting"));
                     }
                     else
                     {
@@ -299,6 +301,8 @@ namespace Tizen.Network.WiFi
         /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
         /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
+        /// <exception cref="NowInProgressException">Thrown when the Wi-Fi connection is now in progress.</exception>
+        /// <exception cref="TimeoutException">Thrown when the timeout of WPS connection is expired.</exception>
         public Task ConnectWpsAsync(WpsInfo info)
         {
             Log.Info(Globals.LogTag, "ConnectWpsAsync");
@@ -320,7 +324,7 @@ namespace Tizen.Network.WiFi
                     if (error != (int)WiFiError.None)
                     {
                         Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error);
-                        wpsTask.SetException(new InvalidOperationException("Error occurs during WiFi connecting, " + (WiFiError)error));
+                        wpsTask.SetException(WiFiErrorFactory.GetException(error, "Error occurs during WiFi connecting"));
                         Log.Info(Globals.LogTag, "Remove task for ConnectWpsAsync");
                         _wpsTaskMap.Remove(_apHandle);
                     }
@@ -403,6 +407,8 @@ namespace Tizen.Network.WiFi
         /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
         /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
+        /// <exception cref="NowInProgressException">Thrown when the Wi-Fi connection is now in progress.</exception>
+        /// <exception cref="TimeoutException">Thrown when the timeout of WPS connection is expired.</exception>
         public static Task<WiFiAP> ConnectWpsWithoutSsidAsync(WpsInfo info)
         {
             Log.Info(Globals.LogTag, "ConnectWpsWithoutSsidAsync");
@@ -417,7 +423,7 @@ namespace Tizen.Network.WiFi
                     if (error != (int)WiFiError.None)
                     {
                         Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error);
-                        wpsWithoutSsidTask.SetException(new InvalidOperationException("Error occurs during WiFi connecting, " + (WiFiError)error));
+                        wpsWithoutSsidTask.SetException(WiFiErrorFactory.GetException(error, "Error occurs during WiFi connecting"));
                         wpsWithoutSsidTask = null;
                         Log.Info(Globals.LogTag, "task is null");
                     }
index b65ebaf..ef16428 100755 (executable)
@@ -40,6 +40,7 @@ namespace Tizen.Network.WiFi
         InvalidKeyError = WiFiErrorValue.Base | 0x06,
         NoReplyError = WiFiErrorValue.Base | 0x07,
         SecurityRestrictedError = WiFiErrorValue.Base | 0x08,
+        WpsTimeoutError = WiFiErrorValue.Base | 0x10,
         PermissionDeniedError = ErrorCode.PermissionDenied,
         NotSupportedError = ErrorCode.NotSupported
     }
@@ -71,35 +72,51 @@ namespace Tizen.Network.WiFi
             ThrowException(e, (handle1 == IntPtr.Zero), (handle2 == IntPtr.Zero), message);
         }
 
+        // Used for return value of native API
         static private void ThrowException(int e, bool isHandle1Null, bool isHandle2Null, string message)
         {
             WiFiError err = (WiFiError)e;
-            if (err == WiFiError.NotSupportedError)
+            switch (err)
             {
-                throw new NotSupportedException("Unsupported feature http://tizen.org/feature/network.wifi");
-            }
-
-            if (err == WiFiError.PermissionDeniedError)
-            {
-                throw new UnauthorizedAccessException("Permission denied " + message);
-            }
-
-            if (err == WiFiError.OutOfMemoryError)
-            {
-                throw new OutOfMemoryException("Out of memory");
+                case WiFiError.NotSupportedError:
+                    throw new NotSupportedException("Unsupported feature http://tizen.org/feature/network.wifi");
+                case WiFiError.PermissionDeniedError:
+                    throw new UnauthorizedAccessException("Permission denied " + message);
+                case WiFiError.SecurityRestrictedError:
+                    throw new UnauthorizedAccessException("Disabled by the device policy");
+                case WiFiError.OutOfMemoryError:
+                    throw new OutOfMemoryException("Out of memory");
+                case WiFiError.InvalidParameterError:
+                    if (isHandle1Null || isHandle2Null)
+                        throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
+                    throw new ArgumentException("Invalid parameter");
+                case WiFiError.InvalidKeyError:
+                    if (isHandle1Null || isHandle2Null)
+                        throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
+                    throw new InvalidKeyException(message);
+                case WiFiError.NowInProgressError:
+                    throw new NowInProgressException(message);
+                default:
+                    throw new InvalidOperationException(err.ToString());
             }
+        }
 
-            if (err == WiFiError.InvalidParameterError || err == WiFiError.InvalidKeyError)
+        // Used in callback
+        static internal Exception GetException(int e, string message)
+        {
+            WiFiError err = (WiFiError)e;
+            switch (err)
             {
-                if (isHandle1Null || isHandle2Null)
-                {
-                    throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
-                }
-
-                throw new ArgumentException("Invalid parameter");
+                case WiFiError.NowInProgressError:
+                    return new NowInProgressException(message);
+                case WiFiError.InvalidKeyError:
+                    return new InvalidKeyException(message);
+                case WiFiError.SecurityRestrictedError:
+                    return new UnauthorizedAccessException("Disabled by the device policy");
+                case WiFiError.WpsTimeoutError:
+                    return new TimeoutException("WPS connection is timed out");
             }
-
-            throw new InvalidOperationException(err.ToString());
+            return new InvalidOperationException(message + " " + err.ToString());
         }
     }
 }
index 4eb5636..9e53676 100755 (executable)
@@ -351,6 +351,7 @@ namespace Tizen.Network.WiFi
         /// <privilege>http://tizen.org/privilege/network.set</privilege>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
+        /// <exception cref="NowInProgressException">Thrown when the Wi-Fi activation is now in progress.</exception>
         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         static public Task ActivateAsync()
@@ -367,6 +368,7 @@ namespace Tizen.Network.WiFi
         /// <privilege>http://tizen.org/privilege/network.set</privilege>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
+        /// <exception cref="NowInProgressException">Thrown when the Wi-Fi activation is now in progress.</exception>
         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         static public Task ActivateWithPickerAsync()
@@ -383,6 +385,7 @@ namespace Tizen.Network.WiFi
         /// <privilege>http://tizen.org/privilege/network.set</privilege>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
+        /// <exception cref="NowInProgressException">Thrown when the Wi-Fi deactivation is now in progress.</exception>
         /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         static public Task DeactivateAsync()
index a5cb7aa..ff008e1 100644 (file)
@@ -316,7 +316,7 @@ namespace Tizen.Network.WiFi
                     if (error != (int)WiFiError.None)
                     {
                         Log.Error(Globals.LogTag, "Error occurs during WiFi activating, " + (WiFiError)error);
-                        task.SetException(new InvalidOperationException("Error occurs during WiFi activating, " + (WiFiError)error));
+                        task.SetException(WiFiErrorFactory.GetException(error, "Error occurs during WiFi activating"));
                     }
                     else
                     {
@@ -361,7 +361,7 @@ namespace Tizen.Network.WiFi
                     if (error != (int)WiFiError.None)
                     {
                         Log.Error(Globals.LogTag, "Error occurs during WiFi activating, " + (WiFiError)error);
-                        task.SetException(new InvalidOperationException("Error occurs during WiFi activating, " + (WiFiError)error));
+                        task.SetException(WiFiErrorFactory.GetException(error, "Error occurs during WiFi activating"));
                     }
                     else
                     {
@@ -406,7 +406,7 @@ namespace Tizen.Network.WiFi
                     if (error != (int)WiFiError.None)
                     {
                         Log.Error(Globals.LogTag, "Error occurs during WiFi deactivating, " + (WiFiError)error);
-                        task.SetException(new InvalidOperationException("Error occurs during WiFi deactivating, " + (WiFiError)error));
+                        task.SetException(WiFiErrorFactory.GetException(error, "Error occurs during WiFi deactivating"));
                     }
                     else
                     {