From: chleun-moon <32117100+chleun-moon@users.noreply.github.com>
Date: Fri, 7 Dec 2018 04:31:23 +0000 (+0900)
Subject: [TCSACR-203][WiFi] Add new Exceptions (#588)
X-Git-Tag: 5.5_M2~382
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1f219a2ae44adac134c8da8625779c128112ac4a;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git
[TCSACR-203][WiFi] Add new Exceptions (#588)
* [WiFi] Add new Exceptions
* [WiFi] Fix year as 2018 in Copyrights comment
---
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
index 0000000..724d7eb
--- /dev/null
+++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/InvalidKeyException.cs
@@ -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
+{
+ ///
+ /// The class that represents the exception which will be thrown when an operation is in progress
+ ///
+ /// 6
+ public class InvalidKeyException : InvalidOperationException
+ {
+ ///
+ /// Constructor
+ ///
+ /// The localized error message string
+ /// 6
+ 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
index 0000000..12de934
--- /dev/null
+++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/NowInProgressException.cs
@@ -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
+{
+ ///
+ /// The class that represents the exception which will be thrown when an operation is in progress
+ ///
+ /// 6
+ public class NowInProgressException : InvalidOperationException
+ {
+ ///
+ /// Constructor
+ ///
+ /// The localized error message string
+ /// 6
+ public NowInProgressException(string message) : base(message)
+ {
+ }
+ }
+}
diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs
index 935d26b..40b23c1 100644
--- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs
+++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs
@@ -218,10 +218,12 @@ namespace Tizen.Network.WiFi
/// http://tizen.org/privilege/network.set
/// http://tizen.org/privilege/network.get
/// Thrown when the Wi-Fi is not supported.
+ /// Thrown when the Wi-Fi connection is now in progress.
/// Thrown when permission is denied.
/// Thrown when the object instance is disposed or released.
/// Thrown when the system is out of memory.
/// Thrown when the method failed due to an invalid operation.
+ /// Thrown when the key is wrong.
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
/// Thrown when the system is out of memory.
/// Thrown when the method failed due to an invalid parameter.
/// Thrown when the method failed due to an invalid operation.
+ /// Thrown when the Wi-Fi connection is now in progress.
+ /// Thrown when the timeout of WPS connection is expired.
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
/// Thrown when the system is out of memory.
/// Thrown when the method failed due to an invalid parameter.
/// Thrown when the method failed due to an invalid operation.
+ /// Thrown when the Wi-Fi connection is now in progress.
+ /// Thrown when the timeout of WPS connection is expired.
public static Task 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");
}
diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiErrorFactory.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiErrorFactory.cs
index b65ebaf..ef16428 100755
--- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiErrorFactory.cs
+++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiErrorFactory.cs
@@ -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());
}
}
}
diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs
index 4eb5636..9e53676 100755
--- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs
+++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs
@@ -351,6 +351,7 @@ namespace Tizen.Network.WiFi
/// http://tizen.org/privilege/network.set
/// http://tizen.org/privilege/network.get
/// Thrown when the Wi-Fi is not supported.
+ /// Thrown when the Wi-Fi activation is now in progress.
/// Thrown when the permission is denied.
/// Thrown when the method failed due to an invalid operation.
static public Task ActivateAsync()
@@ -367,6 +368,7 @@ namespace Tizen.Network.WiFi
/// http://tizen.org/privilege/network.set
/// http://tizen.org/privilege/network.get
/// Thrown when the Wi-Fi is not supported.
+ /// Thrown when the Wi-Fi activation is now in progress.
/// Thrown when the permission is denied.
/// Thrown when the method failed due to an invalid operation.
static public Task ActivateWithPickerAsync()
@@ -383,6 +385,7 @@ namespace Tizen.Network.WiFi
/// http://tizen.org/privilege/network.set
/// http://tizen.org/privilege/network.get
/// Thrown when the Wi-Fi is not supported.
+ /// Thrown when the Wi-Fi deactivation is now in progress.
/// Thrown when the permission is denied.
/// Thrown when the method failed due to an invalid operation.
static public Task DeactivateAsync()
diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs
index a5cb7aa..ff008e1 100644
--- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs
+++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs
@@ -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
{