Binding KeyboardGrab and KeyboardUnGrab
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Connection / Tizen.Network.Connection / CellularProfile.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.Collections.Generic;
19 using System.Linq;
20 using System.Text;
21 using System.Runtime.InteropServices;
22
23 namespace Tizen.Network.Connection
24 {
25     /// <summary>
26     /// This is the CellularProfile class. It provides functions to manage the cellular profile.
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     public class CellularProfile : ConnectionProfile
30     {
31         internal CellularProfile(IntPtr handle): base(handle)
32         {
33         }
34
35         private CellularAuthInformation _cellularAuthInfo = null;
36
37         /// <summary>
38         /// Destroy the CellularProfile object
39         /// </summary>
40         ~CellularProfile()
41         {
42         }
43
44         /// <summary>
45         /// The APN (access point name).
46         /// </summary>
47         /// <since_tizen> 3 </since_tizen>
48         /// <value>Cellular access point name.</value>
49         /// <exception cref="System.NotSupportedException">Thrown during set when a feature is not supported.</exception>
50         /// <exception cref="System.ArgumentException">Thrown during set when a value is an invalid parameter.</exception>
51         /// <exception cref="System.ArgumentNullException">Thrown during set when a value is null.</exception>
52         /// <exception cref="System.InvalidOperationException">Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation.</exception>
53         /// <exception cref="System.ObjectDisposedException">Thrown when an operation is performed on a disposed object.</exception>
54         public string Apn
55         {
56             get
57             {
58                 Log.Debug(Globals.LogTag, "Get Apn");
59                 IntPtr Value;
60                 int ret = Interop.ConnectionCellularProfile.GetApn(ProfileHandle, out Value);
61                 if ((ConnectionError)ret != ConnectionError.None)
62                 {
63                     Log.Error(Globals.LogTag, "It failed to get apn, " + (ConnectionError)ret);
64                 }
65                 string result = Marshal.PtrToStringAnsi(Value);
66                 Interop.Libc.Free(Value);
67                 return result;
68             }
69
70             set
71             {
72                 Log.Debug(Globals.LogTag, "Set Apn");
73                 CheckDisposed();
74                 if (value != null)
75                 {
76                     int ret = Interop.ConnectionCellularProfile.SetApn(ProfileHandle, value);
77                     if ((ConnectionError)ret != ConnectionError.None)
78                     {
79                         Log.Error(Globals.LogTag, "It failed to set apn, " + (ConnectionError)ret);
80                         ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
81                         ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
82                         ConnectionErrorFactory.ThrowConnectionException(ret);
83                     }
84                 }
85
86                 else
87                 {
88                     throw new ArgumentNullException("Value of Apn is null");
89                 }
90             }
91         }
92
93         /// <summary>
94         /// The home URL.
95         /// </summary>
96         /// <since_tizen> 3 </since_tizen>
97         /// <value>Cellular home URL.</value>
98         /// <exception cref="System.NotSupportedException">Thrown during set when a feature is not supported.</exception>
99         /// <exception cref="System.ArgumentException">Thrown during set when a value is an invalid parameter.</exception>
100         /// <exception cref="System.ArgumentNullException">Thrown during set when a value is null.</exception>
101         /// <exception cref="System.InvalidOperationException">Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation.</exception>
102         /// <exception cref="System.ObjectDisposedException">Thrown when an operation is performed on a disposed object.</exception>
103         public string HomeUri
104         {
105             get
106             {
107                 Log.Debug(Globals.LogTag, "Get HomeUri");
108                 IntPtr Value;
109                 int ret = Interop.ConnectionCellularProfile.GetHomeUrl(ProfileHandle, out Value);
110                 if ((ConnectionError)ret != ConnectionError.None)
111                 {
112                     Log.Error(Globals.LogTag, "It failed to get home url, " + (ConnectionError)ret);
113                 }
114                 string result = Marshal.PtrToStringAnsi(Value);
115                 Interop.Libc.Free(Value);
116                 return result;
117             }
118
119             set
120             {
121                 Log.Debug(Globals.LogTag, "Set HomeUri");
122                 CheckDisposed();
123                 if (value != null)
124                 {
125                     int ret = Interop.ConnectionCellularProfile.SetHomeUrl(ProfileHandle, value);
126                     if ((ConnectionError)ret != ConnectionError.None)
127                     {
128                         Log.Error(Globals.LogTag, "It failed to set home url, " + (ConnectionError)ret);
129                         ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
130                         ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
131                         ConnectionErrorFactory.ThrowConnectionException(ret);
132                     }
133                 }
134
135                 else
136                 {
137                     throw new ArgumentNullException("Value of HomeUri is null");
138                 }
139             }
140         }
141
142         /// <summary>
143         /// The service type.
144         /// </summary>
145         /// <since_tizen> 3 </since_tizen>
146         /// <value>Cellular service type.</value>
147         /// <exception cref="System.NotSupportedException">Thrown during set when a feature is not supported.</exception>
148         /// <exception cref="System.ArgumentException">Thrown during set when a value is an invalid parameter.</exception>
149         /// <exception cref="System.InvalidOperationException">Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation.</exception>
150         /// <exception cref="System.ObjectDisposedException">Thrown when an operation is performed on a disposed object.</exception>
151         public CellularServiceType ServiceType
152         {
153             get
154             {
155                 Log.Debug(Globals.LogTag, "Get ServiceType");
156                 int value;
157                 int ret = Interop.ConnectionCellularProfile.GetServiceType(ProfileHandle, out value);
158                 if ((ConnectionError)ret != ConnectionError.None)
159                 {
160                     Log.Error(Globals.LogTag, "It failed to get service type, " + (ConnectionError)ret);
161                 }
162                 return (CellularServiceType)value;
163             }
164
165             set
166             {
167                 Log.Debug(Globals.LogTag, "Set ServiceType");
168                 CheckDisposed();
169                 int ret = Interop.ConnectionCellularProfile.SetServiceType(ProfileHandle, (int)value);
170                 if ((ConnectionError)ret != ConnectionError.None)
171                 {
172                     Log.Error(Globals.LogTag, "It failed to set service type, " + (ConnectionError)ret);
173                     ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
174                     ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
175                     ConnectionErrorFactory.ThrowConnectionException(ret);
176                 }
177             }
178         }
179
180         /// <summary>
181         /// The cellular pdn type.
182         /// </summary>
183         /// <since_tizen> 3 </since_tizen>
184         /// <value>Cellular pdn type.</value>
185         /// <exception cref="System.NotSupportedException">Thrown during set when a feature is not supported.</exception>
186         /// <exception cref="System.ArgumentException">Thrown during set when a value is an invalid parameter.</exception>
187         /// <exception cref="System.InvalidOperationException">Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation.</exception>
188         /// <exception cref="System.ObjectDisposedException">Thrown when an operation is performed on a disposed object.</exception>
189         public CellularPdnType PdnType
190         {
191             get
192             {
193                 Log.Debug(Globals.LogTag, "Get PdnType");
194                 int value;
195                 int ret = Interop.ConnectionCellularProfile.GetPdnType(ProfileHandle, out value);
196                 if ((ConnectionError)ret != ConnectionError.None)
197                 {
198                     Log.Error(Globals.LogTag, "It failed to get pdn type, " + (ConnectionError)ret);
199                 }
200                 return (CellularPdnType)value;
201             }
202
203             set
204             {
205                 Log.Debug(Globals.LogTag, "Set PdnType");
206                 CheckDisposed();
207                 int ret = Interop.ConnectionCellularProfile.SetPdnType(ProfileHandle, (int)value);
208                 if ((ConnectionError)ret != ConnectionError.None)
209                 {
210                     Log.Error(Globals.LogTag, "It failed to set pdn type, " + (ConnectionError)ret);
211                     ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
212                     ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
213                     ConnectionErrorFactory.ThrowConnectionException(ret);
214                 }
215             }
216         }
217
218         /// <summary>
219         /// The cellular roaming pdn type.
220         /// </summary>
221         /// <since_tizen> 3 </since_tizen>
222         /// <value>Cellular roaming pdn type.</value>
223         /// <exception cref="System.NotSupportedException">Thrown during set when a feature is not supported.</exception>
224         /// <exception cref="System.ArgumentException">Thrown during set when a value is an invalid parameter.</exception>
225         /// <exception cref="System.InvalidOperationException">Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation.</exception>
226         /// <exception cref="System.ObjectDisposedException">Thrown when a operation is performed on a disposed object.</exception>
227         public CellularPdnType RoamingPdnType
228         {
229             get
230             {
231                 Log.Debug(Globals.LogTag, "Get RoamingPdnType");
232                 int value;
233                 int ret = Interop.ConnectionCellularProfile.GetRoamingPdnType(ProfileHandle, out value);
234                 if ((ConnectionError)ret != ConnectionError.None)
235                 {
236                     Log.Error(Globals.LogTag, "It failed to get roam pdn type, " + (ConnectionError)ret);
237                 }
238                 return (CellularPdnType)value;
239             }
240
241             set
242             {
243                 Log.Debug(Globals.LogTag, "Set RoamingPdnType");
244                 CheckDisposed();
245                 int ret = Interop.ConnectionCellularProfile.SetRoamingPdnType(ProfileHandle, (int)value);
246                 if ((ConnectionError)ret != ConnectionError.None)
247                 {
248                     Log.Error(Globals.LogTag, "It failed to set roam pdn type, " + (ConnectionError)ret);
249                     ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
250                     ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
251                     ConnectionErrorFactory.ThrowConnectionException(ret);
252                 }
253             }
254         }
255
256         /// <summary>
257         /// Checks whether the connection is in roaming state.
258         /// </summary>
259         /// <since_tizen> 6 </since_tizen>
260         /// <value> True if the cellular profile is in roaming state, otherwise false.</value>
261         public bool IsRoaming
262         {
263             get
264             {
265                 Log.Debug(Globals.LogTag, "Get IsRoaming");
266                 bool value = false;
267                 int ret = Interop.ConnectionCellularProfile.IsRoaming(ProfileHandle, out value);
268                 if ((ConnectionError)ret != ConnectionError.None)
269                 {
270                     Log.Error(Globals.LogTag, "It failed to get isRoaming, " + (ConnectionError)ret);
271                 }
272                 return value;
273             }
274         }
275
276         /// <summary>
277         /// The cellular authentication information.
278         /// </summary>
279         /// <since_tizen> 3 </since_tizen>
280         /// <value>Instance of CellularAuthInformation.</value>
281         /// <exception cref="System.NotSupportedException">Thrown during set when a feature is not supported.</exception>
282         /// <exception cref="System.ArgumentException">Thrown during set when a value is an invalid parameter.</exception>
283         /// <exception cref="System.ArgumentNullException">Thrown during set when a value is null.</exception>
284         /// <exception cref="System.InvalidOperationException">Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation.</exception>
285         /// <exception cref="System.ObjectDisposedException">Thrown when an operation is performed on a disposed object.</exception>
286         public CellularAuthInformation CellularAuthInfo
287         {
288             get
289             {
290                 int type;
291                 string name;
292                 string password;
293                 int ret = Interop.ConnectionCellularProfile.GetAuthInfo(ProfileHandle, out type, out name, out password);
294                 if ((ConnectionError)ret != ConnectionError.None)
295                 {
296                     Log.Error(Globals.LogTag, "It failed to get cellular authentication information, " + (ConnectionError)ret);
297                     return null;
298                 }
299
300                 if (_cellularAuthInfo == null)
301                     _cellularAuthInfo = new CellularAuthInformation();
302                 _cellularAuthInfo.AuthType = (CellularAuthType)type;
303                 _cellularAuthInfo.UserName = name;
304                 _cellularAuthInfo.Password = password;
305                 return _cellularAuthInfo;
306             }
307
308             set
309             {
310                 CheckDisposed();
311                 if (value != null)
312                 {
313                     _cellularAuthInfo = value;
314                     int type = (int)_cellularAuthInfo.AuthType;
315                     string name = _cellularAuthInfo.UserName;
316                     string password = _cellularAuthInfo.Password;
317                     int ret = Interop.ConnectionCellularProfile.SetAuthInfo(ProfileHandle, type, name, password);
318                     if ((ConnectionError)ret != ConnectionError.None)
319                     {
320                         Log.Error(Globals.LogTag, "It failed to set auth information, " + (ConnectionError)ret);
321                         ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
322                         ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
323                         ConnectionErrorFactory.ThrowConnectionException(ret);
324                     }
325                 }
326
327                 else
328                 {
329                     throw new ArgumentNullException("CellularAuthInformation value is null");
330                 }
331             }
332         }
333
334         /// <summary>
335         /// Checks whether the profile is hidden.
336         /// </summary>
337         /// <since_tizen> 3 </since_tizen>
338         /// <value>True if the cellular profile is hidden, otherwise false.</value>
339         public bool Hidden
340         {
341             get
342             {
343                 bool value;
344                 int ret = Interop.ConnectionCellularProfile.IsHidden(ProfileHandle, out value);
345                 if ((ConnectionError)ret != ConnectionError.None)
346                 {
347                     Log.Error(Globals.LogTag, "It failed to get hidden value, " + (ConnectionError)ret);
348                 }
349                 return value;
350             }
351         }
352
353         /// <summary>
354         /// Checks whether the profile is editable.
355         /// </summary>
356         /// <since_tizen> 3 </since_tizen>
357         /// <value>True if the cellular profile is editable, otherwise false.</value>
358         public bool Editable
359         {
360             get
361             {
362                 bool value;
363                 int ret = Interop.ConnectionCellularProfile.IsEditable(ProfileHandle, out value);
364                 if ((ConnectionError)ret != ConnectionError.None)
365                 {
366                     Log.Error(Globals.LogTag, "It failed to get editable value, " + (ConnectionError)ret);
367                 }
368                 return value;
369             }
370         }
371
372         /// <summary>
373         /// Checks whether the profile is default.
374         /// </summary>
375         /// <since_tizen> 3 </since_tizen>
376         /// <value>True if the cellular profile is default, otherwise false.</value>
377         public bool IsDefault
378         {
379             get
380             {
381                 bool value;
382                 int ret = Interop.ConnectionCellularProfile.IsDefault(ProfileHandle, out value);
383                 if ((ConnectionError)ret != ConnectionError.None)
384                 {
385                     Log.Error(Globals.LogTag, "It failed to get IsDefault value, " + (ConnectionError)ret);
386                 }
387                 return value;
388             }
389         }
390     }
391
392     /// <summary>
393     /// This is the CellularAuthInformation class. It provides the properties to get and set the cellular authentication information.
394     /// </summary>
395     /// <since_tizen> 3 </since_tizen>
396     public class CellularAuthInformation
397     {
398         /// <summary>
399         /// Default constructor. Initializes an object of the CellularAuthInformation.
400         /// </summary>
401         /// <since_tizen> 3 </since_tizen>
402         public CellularAuthInformation()
403         {
404         }
405
406         /// <summary>
407         /// The user name.
408         /// </summary>
409         /// <since_tizen> 3 </since_tizen>
410         /// <value>Cellular user name.</value>
411         public string UserName { get; set;}
412         /// <summary>
413         /// The password.
414         /// </summary>
415         /// <since_tizen> 3 </since_tizen>
416         /// <value>Cellular password.</value>
417         public string Password { get; set; }
418
419         /// <summary>
420         /// The authentication type.
421         /// </summary>
422         /// <since_tizen> 3 </since_tizen>
423         /// <value>Cellular authentication type.</value>
424         public CellularAuthType AuthType { get; set; }
425     }
426 }