--- /dev/null
+/*
+ * 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)
+ {
+ }
+ }
+}
--- /dev/null
+/*
+ * 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)
+ {
+ }
+ }
+}
/// <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());
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
{
/// <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");
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);
}
/// <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");
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");
}
InvalidKeyError = WiFiErrorValue.Base | 0x06,
NoReplyError = WiFiErrorValue.Base | 0x07,
SecurityRestrictedError = WiFiErrorValue.Base | 0x08,
+ WpsTimeoutError = WiFiErrorValue.Base | 0x10,
PermissionDeniedError = ErrorCode.PermissionDenied,
NotSupportedError = ErrorCode.NotSupported
}
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());
}
}
}
/// <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()
/// <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()
/// <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()
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
{
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
{
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
{