9194a20a03a676eeac27a02114e62ed91bad3314
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.WiFi / Tizen.Network.WiFi / WiFiAP.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Threading.Tasks;
19 using System.Collections.Generic;
20 using Tizen.Applications;
21
22 namespace Tizen.Network.WiFi
23 {
24     /// <summary>
25     /// A class for managing the network information of the access point (AP).
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     public class WiFiAP : IDisposable
29     {
30         private IntPtr _apHandle = IntPtr.Zero;
31         private Dictionary<IntPtr, Interop.WiFi.VoidCallback> _callback_map = new Dictionary<IntPtr, Interop.WiFi.VoidCallback>();
32         private static Dictionary<IntPtr, Interop.WiFi.VoidCallback> s_callbackMap = new Dictionary<IntPtr, Interop.WiFi.VoidCallback>();
33         private int _requestId = 0;
34         private static int s_requestId = 0;
35         private WiFiNetwork _network;
36         private WiFiSecurity _security;
37         private bool _disposed = false;
38
39         private TizenSynchronizationContext context = new TizenSynchronizationContext();
40         private static TizenSynchronizationContext s_context = new TizenSynchronizationContext();
41
42         /// <summary>
43         /// The network information of the access point (AP).
44         /// </summary>
45         /// <since_tizen> 3 </since_tizen>
46         /// <value>The WiFiNetwork instance containing the network information of the AP.</value>
47         public WiFiNetwork NetworkInformation
48         {
49             get
50             {
51                 return _network;
52             }
53         }
54
55         /// <summary>
56         /// The security information of the access point (AP).
57         /// </summary>
58         /// <since_tizen> 3 </since_tizen>
59         /// <value>The WiFiSecurity instance containing security information of the AP.</value>
60         public WiFiSecurity SecurityInformation
61         {
62             get
63             {
64                 return _security;
65             }
66         }
67
68         internal WiFiAP(IntPtr handle)
69         {
70             Log.Debug(Globals.LogTag, "New WiFiAP. Handle: " + handle);
71             _apHandle = handle;
72             Initialize();
73         }
74
75         /// <summary>
76         /// Creates an object for the access point.
77         /// </summary>
78         /// <since_tizen> 3 </since_tizen>
79         /// <param name="essid">The Extended Service Set Identifier of the access point.</param>
80         /// <feature>http://tizen.org/feature/network.wifi</feature>
81         /// <privilege>http://tizen.org/privilege/network.get</privilege>
82         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
83         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
84         /// <exception cref="ArgumentNullException">Thrown when the ESSID is passed as null.</exception>
85         /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
86         /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
87         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
88         public WiFiAP(string essid)
89         {
90             Log.Debug(Globals.LogTag, "New WiFiAP. Essid: " + essid);
91             createHandle(essid, true);
92             Initialize();
93         }
94
95         /// <summary>
96         /// Creates an object for the hidden access point.
97         /// </summary>
98         /// <since_tizen> 3 </since_tizen>
99         /// <param name="essid">The Extended Service Set Identifier of the access point.</param>
100         /// <param name="hidden">The value to set a hidden AP.</param>
101         /// <feature>http://tizen.org/feature/network.wifi</feature>
102         /// <privilege>http://tizen.org/privilege/network.get</privilege>
103         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
104         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
105         /// <exception cref="ArgumentNullException">Thrown when the ESSID is passed as null.</exception>
106         /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
107         /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
108         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
109         public WiFiAP(string essid, bool hidden)
110         {
111             createHandle(essid, hidden);
112             Initialize();
113         }
114
115         /// <summary>
116         /// Destroy the WiFiAP object
117         /// </summary>
118         ~WiFiAP()
119         {
120             Dispose(false);
121         }
122
123         /// <summary>
124         /// A method to destroy the managed WiFiAP objects.
125         /// </summary>
126         /// <since_tizen> 3 </since_tizen>
127         public void Dispose()
128         {
129             Dispose(true);
130             GC.SuppressFinalize(this);
131         }
132
133         private void Dispose(bool disposing)
134         {
135             if (_disposed)
136                 return;
137
138             Interop.WiFi.AP.Destroy(_apHandle);
139             _apHandle = IntPtr.Zero;
140             _disposed = true;
141         }
142
143         private void createHandle(string id, bool hidden)
144         {
145             int ret = -1;
146             if (id == null)
147             {
148                 throw new ArgumentNullException("Essid is null");
149             }
150
151             if (hidden)
152             {
153                 ret = Interop.WiFi.AP.CreateHiddenAP(WiFiManagerImpl.Instance.GetSafeHandle(), id, out _apHandle);
154             }
155
156             else
157             {
158                 ret = Interop.WiFi.AP.Create(WiFiManagerImpl.Instance.GetSafeHandle(), id, out _apHandle);
159             }
160
161             if (ret != (int)WiFiError.None)
162             {
163                 Log.Error(Globals.LogTag, "Failed to create handle, Error - " + (WiFiError)ret);
164                 WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle());
165             }
166         }
167
168         private void Initialize()
169         {
170             Interop.WiFi.SafeWiFiAPHandle apHandle = new Interop.WiFi.SafeWiFiAPHandle(_apHandle);
171             _network = new WiFiNetwork(apHandle);
172             _security = new WiFiSecurity(apHandle);
173         }
174
175         /// <summary>
176         /// Refreshes the access point information.
177         /// </summary>
178         /// <since_tizen> 3 </since_tizen>
179         /// <feature>http://tizen.org/feature/network.wifi</feature>
180         /// <privilege>http://tizen.org/privilege/network.get</privilege>
181         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
182         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
183         /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception>
184         /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
185         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
186         public void Refresh()
187         {
188             Log.Debug(Globals.LogTag, "Refresh");
189             if (_disposed)
190             {
191                 throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)");
192             }
193             int ret = Interop.WiFi.AP.Refresh(_apHandle);
194             if (ret != (int)WiFiError.None)
195             {
196                 Log.Error(Globals.LogTag, "Failed to refresh ap handle, Error - " + (WiFiError)ret);
197                 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle, "http://tizen.org/privilege/network.get");
198             }
199         }
200
201         /// <summary>
202         /// Connects the access point asynchronously.
203         /// </summary>
204         /// <since_tizen> 3 </since_tizen>
205         /// <returns> A task indicating whether the connect method is done or not.</returns>
206         /// <remarks>
207         /// This method must be called from MainThread.
208         /// </remarks>
209         /// <feature>http://tizen.org/feature/network.wifi</feature>
210         /// <privilege>http://tizen.org/privilege/network.set</privilege>
211         /// <privilege>http://tizen.org/privilege/network.get</privilege>
212         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
213         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
214         /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception>
215         /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
216         /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
217         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
218         public Task ConnectAsync()
219         {
220             Log.Info(Globals.LogTag, "ConnectAsync");
221             if (_disposed)
222             {
223                 throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)");
224             }
225             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
226             IntPtr id;
227             lock (_callback_map)
228             {
229                 id = (IntPtr)_requestId++;
230                 _callback_map[id] = (error, key) =>
231                 {
232                     Log.Info(Globals.LogTag, "ConnectAsync done " + (WiFiError)error);
233                     if (error != (int)WiFiError.None)
234                     {
235                         Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error);
236                         task.SetException(new InvalidOperationException("Error occurs during WiFi connecting, " + (WiFiError)error));
237                     }
238                     else
239                     {
240                         task.SetResult(true);
241                     }
242                     lock (_callback_map)
243                     {
244                         _callback_map.Remove(key);
245                     }
246                 };
247             }
248
249             context.Post((x) =>
250             {
251                 Log.Info(Globals.LogTag, "Interop.WiFi.Connect");
252                 try
253                 {
254                     int ret = Interop.WiFi.Connect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
255                     if (ret != (int)WiFiError.None)
256                     {
257                         Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
258                         WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
259                     }
260                 }
261                 catch (Exception e)
262                 {
263                     Log.Error(Globals.LogTag, "Exception on ConnectAsync\n" + e.ToString());
264                     task.SetException(e);
265                 }
266             }, null);
267
268             return task.Task;
269         }
270
271         /// <summary>
272         /// Connects the access point with the WPS asynchronously.
273         /// </summary>
274         /// <since_tizen> 3 </since_tizen>
275         /// <param name="info">A WpsInfo instance which is type of WpsPbcInfo or WpsPinInfo.</param>
276         /// <returns>A task indicating whether the ConnectWps method is done or not.</returns>
277         /// <remarks>
278         /// This method must be called from MainThread.
279         /// </remarks>
280         /// <feature>http://tizen.org/feature/network.wifi</feature>
281         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
282         /// <privilege>http://tizen.org/privilege/network.get</privilege>
283         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
284         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
285         /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception>
286         /// <exception cref="ArgumentNullException">Thrown when the WpsPinInfo object is constructed with a null pin.</exception>
287         /// <exception cref="ArgumentOutOfRangeException">Thrown when the WpsPinInfo object is constructed with a pin which is an empty string or more than 7 characters.</exception>
288         /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
289         /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
290         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
291         public Task ConnectWpsAsync(WpsInfo info)
292         {
293             Log.Info(Globals.LogTag, "ConnectWpsAsync");
294             if (_disposed)
295             {
296                 throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)");
297             }
298             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
299             IntPtr id;
300             lock (_callback_map)
301             {
302                 id = (IntPtr)_requestId++;
303                 _callback_map[id] = (error, key) =>
304                 {
305                     Log.Info(Globals.LogTag, "ConnectWpsAsync done");
306                     if (error != (int)WiFiError.None)
307                     {
308                         Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error);
309                         task.SetException(new InvalidOperationException("Error occurs during WiFi connecting, " + (WiFiError)error));
310                     }
311                     else
312                     {
313                         task.SetResult(true);
314                     }
315                     lock (_callback_map)
316                     {
317                         _callback_map.Remove(key);
318                     }
319                 };
320             }
321
322             context.Post((x) =>
323             {
324                 try
325                 {
326                     int ret = -1;
327                     if (info.GetType() == typeof(WpsPbcInfo))
328                     {
329                         Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPb");
330                         ret = Interop.WiFi.ConnectByWpsPbc(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
331                     }
332                     else if (info.GetType() == typeof(WpsPinInfo))
333                     {
334                         WpsPinInfo pinInfo = (WpsPinInfo)info;
335                         if (pinInfo.GetWpsPin() == null)
336                         {
337                             throw new ArgumentNullException("Wps pin should not be null");
338                         }
339
340                         if (pinInfo.GetWpsPin().Length == 0 || pinInfo.GetWpsPin().Length > 8)
341                         {
342                             throw new ArgumentOutOfRangeException("Wps pin should not be empty or more than 7 characters");
343                         }
344
345                         Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPin");
346                         ret = Interop.WiFi.ConnectByWpsPin(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, pinInfo.GetWpsPin(), _callback_map[id], id);
347                     }
348
349                     if (ret != (int)WiFiError.None)
350                     {
351                         Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
352                         WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
353                     }
354                 }
355                 catch (Exception e)
356                 {
357                     Log.Error(Globals.LogTag, "Exception on ConnectWpsAsync\n" + e.ToString());
358                     task.SetException(e);
359                 }
360             }, null);
361
362             return task.Task;
363         }
364
365         /// <summary>
366         /// Connects the access point with WPS without SSID asynchronously.
367         /// </summary>
368         /// <since_tizen> 3 </since_tizen>
369         /// <param name="info">A WpsInfo instance which is of type WpsPbcInfo or WpsPinInfo.</param>
370         /// <returns>A task which contains Connected access point information.</returns>
371         /// <remarks>
372         /// If WpsPinInfo is used, its object has to be constructed with a pin which must be 4 or 8 characters long. \n
373         /// This method must be called from MainThread.
374         /// </remarks>
375         /// <feature>http://tizen.org/feature/network.wifi</feature>
376         /// <privilege>http://tizen.org/privilege/network.set</privilege>
377         /// <privilege>http://tizen.org/privilege/network.get</privilege>
378         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
379         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
380         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
381         /// <exception cref="ArgumentNullException">Thrown when the WpsPinInfo object is constructed with a null pin.</exception>
382         /// <exception cref="ArgumentOutOfRangeException">Thrown when the WpsPinInfo object is constructed with a pin which is not of 4 or 8 characters long.</exception>
383         /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
384         /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
385         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
386         public static Task<WiFiAP> ConnectWpsWithoutSsidAsync(WpsInfo info)
387         {
388             Log.Info(Globals.LogTag, "ConnectWpsWithoutSsidAsync");
389             TaskCompletionSource<WiFiAP> task = new TaskCompletionSource<WiFiAP>();
390             IntPtr id;
391             lock (s_callbackMap)
392             {
393                 id = (IntPtr)s_requestId++;
394                 s_callbackMap[id] = (error, key) =>
395                 {
396                     Log.Info(Globals.LogTag, "ConnectWpsWithoutSsidAsync done");
397                     if (error != (int)WiFiError.None)
398                     {
399                         Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error);
400                         task.SetException(new InvalidOperationException("Error occurs during WiFi connecting, " + (WiFiError)error));
401                     }
402                     else
403                     {
404                         WiFiAP ap = WiFiManagerImpl.Instance.GetConnectedAP();
405                         task.SetResult(ap);
406                     }
407                     lock (s_callbackMap)
408                     {
409                         s_callbackMap.Remove(key);
410                     }
411                 };
412             }
413
414             s_context.Post((x) =>
415             {
416                 try
417                 {
418                     int ret = -1;
419                     if (info.GetType() == typeof(WpsPbcInfo))
420                     {
421                         Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPbcWithoutSsid");
422                         ret = Interop.WiFi.ConnectByWpsPbcWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), s_callbackMap[id], id);
423                     }
424                     else if (info.GetType() == typeof(WpsPinInfo))
425                     {
426                         WpsPinInfo pinInfo = (WpsPinInfo)info;
427                         if (pinInfo.GetWpsPin() == null)
428                         {
429                             throw new ArgumentNullException("Wps pin should not be null");
430                         }
431
432                         if (pinInfo.GetWpsPin().Length != 4 && pinInfo.GetWpsPin().Length != 8)
433                         {
434                             throw new ArgumentOutOfRangeException("Wps pin should be of 4 or 8 characters long");
435                         }
436
437                         Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPinWithoutSsid");
438                         ret = Interop.WiFi.ConnectByWpsPinWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), pinInfo.GetWpsPin(), s_callbackMap[id], id);
439                     }
440
441                     if (ret != (int)WiFiError.None)
442                     {
443                         Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
444                         WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle());
445                     }
446                 }
447                 catch (Exception e)
448                 {
449                     Log.Error(Globals.LogTag, "Exception on ConnectWpsWithoutSsidAsync\n" + e.ToString());
450                     task.SetException(e);
451                 }
452             }, null);
453
454             return task.Task;
455         }
456
457         /// <summary>
458         /// Disconnects the access point asynchronously.
459         /// </summary>
460         /// <since_tizen> 3 </since_tizen>
461         /// <returns> A task indicating whether the disconnect method is done or not.</returns>
462         /// <remarks>
463         /// This method must be called from MainThread.
464         /// </remarks>
465         /// <feature>http://tizen.org/feature/network.wifi</feature>
466         /// <privilege>http://tizen.org/privilege/network.set</privilege>
467         /// <privilege>http://tizen.org/privilege/network.get</privilege>
468         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
469         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
470         /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception>
471         /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
472         /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
473         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
474         public Task DisconnectAsync()
475         {
476             Log.Debug(Globals.LogTag, "DisconnectAsync");
477             if (_disposed)
478             {
479                 throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)");
480             }
481             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
482             IntPtr id;
483             lock (_callback_map)
484             {
485                 id = (IntPtr)_requestId++;
486                 _callback_map[id] = (error, key) =>
487                 {
488                     Log.Info(Globals.LogTag, "DisconnectAsync done");
489                     if (error != (int)WiFiError.None)
490                     {
491                         Log.Error(Globals.LogTag, "Error occurs during WiFi disconnecting, " + (WiFiError)error);
492                         task.SetException(new InvalidOperationException("Error occurs during WiFi disconnecting, " + (WiFiError)error));
493                     }
494                     else
495                     {
496                         task.SetResult(true);
497                     }
498                     lock (_callback_map)
499                     {
500                         _callback_map.Remove(key);
501                     }
502                 };
503             }
504
505             context.Post((x) =>
506             {
507                 Log.Info(Globals.LogTag, "Interop.WiFi.Disconnect");
508                 try
509                 {
510                     int ret = Interop.WiFi.Disconnect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
511                     if (ret != (int)WiFiError.None)
512                     {
513                         Log.Error(Globals.LogTag, "Failed to disconnect wifi, Error - " + (WiFiError)ret);
514                         WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
515                     }
516                 }
517                 catch (Exception e)
518                 {
519                     Log.Error(Globals.LogTag, "Exception on Disconnect\n" + e.ToString());
520                     task.SetException(e);
521                 }
522             }, null);
523
524             return task.Task;
525         }
526
527         /// <summary>
528         /// Deletes the information of a stored access point and disconnects it when the AP is connected.
529         /// If an AP is connected, then the connection information will be stored. This information is used when a connection to that AP is established automatically.
530         /// </summary>
531         /// <since_tizen> 3 </since_tizen>
532         /// <feature>http://tizen.org/feature/network.wifi</feature>
533         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
534         /// <privilege>http://tizen.org/privilege/network.get</privilege>
535         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
536         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
537         /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception>
538         /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
539         /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
540         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
541         public void ForgetAP()
542         {
543             Log.Debug(Globals.LogTag, "ForgetAP");
544             if (_disposed)
545             {
546                 throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)");
547             }
548             int ret = Interop.WiFi.RemoveAP(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle);
549             if (ret != (int)WiFiError.None)
550             {
551                 Log.Error(Globals.LogTag, "Failed to forget AP, Error - " + (WiFiError)ret);
552                 WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
553             }
554         }
555
556         /// <summary>
557         /// Update the information of a stored access point.
558         /// When a AP information is changed, the change will not be applied until this method is called.
559         /// </summary>
560         /// <since_tizen> 5 </since_tizen>
561         /// <feature>http://tizen.org/feature/network.wifi</feature>
562         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
563         /// <privilege>http://tizen.org/privilege/network.get</privilege>
564         /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
565         /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
566         /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception>
567         /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
568         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
569         public void Update()
570         {
571             Log.Debug(Globals.LogTag, "Update");
572             if (_disposed)
573             {
574                 throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)");
575             }
576             int ret = Interop.WiFi.UpdateAP(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle);
577             if (ret != (int)WiFiError.None)
578             {
579                 Log.Error(Globals.LogTag, "Failed to update AP, Error - " + (WiFiError)ret);
580                 WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
581             }
582         }
583    }
584
585     /// <summary>
586     /// An abstract class which is used to represent the WPS information of the access point.
587     /// </summary>
588     /// <since_tizen> 3 </since_tizen>
589     public abstract class WpsInfo
590     {
591     }
592
593     /// <summary>
594     /// A class which is used to represent WPS PBC information of the access point.
595     /// </summary>
596     /// <since_tizen> 3 </since_tizen>
597     public class WpsPbcInfo : WpsInfo
598     {
599     }
600
601     /// <summary>
602     /// A class which is used to represent WPS PIN information of the access point.
603     /// </summary>
604     /// <since_tizen> 3 </since_tizen>
605     public class WpsPinInfo : WpsInfo
606     {
607         private string _pin;
608
609         private WpsPinInfo()
610         {
611         }
612
613         /// <summary>
614         /// A public constructor which instantiates WpsPinInfo class with the given pin.
615         /// </summary>
616         /// <since_tizen> 3 </since_tizen>
617         /// <param name="pin">WPS Pin of the access point.</param>
618         /// <remarks>
619         /// Pin should not be null or empty. It should be of less than 8 characters.
620         /// </remarks>
621         public WpsPinInfo(string pin)
622         {
623             _pin = pin;
624         }
625
626         internal string GetWpsPin()
627         {
628             return _pin;
629         }
630     }
631 }