2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
21 using System.Runtime.InteropServices;
23 namespace Tizen.Network.Connection
26 /// This is the CellularProfile class. It provides functions to manage the cellular profile.
28 /// <since_tizen> 3 </since_tizen>
29 public class CellularProfile : ConnectionProfile
31 internal CellularProfile(IntPtr handle): base(handle)
35 private CellularAuthInformation _cellularAuthInfo = null;
38 /// Destroy the CellularProfile object
45 /// The APN (access point name).
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>
58 Log.Debug(Globals.LogTag, "Get Apn");
60 int ret = Interop.ConnectionCellularProfile.GetApn(ProfileHandle, out Value);
61 if ((ConnectionError)ret != ConnectionError.None)
63 Log.Error(Globals.LogTag, "It failed to get apn, " + (ConnectionError)ret);
65 string result = Marshal.PtrToStringAnsi(Value);
66 Interop.Glib.Free(Value);
72 Log.Debug(Globals.LogTag, "Set Apn");
76 int ret = Interop.ConnectionCellularProfile.SetApn(ProfileHandle, value);
77 if ((ConnectionError)ret != ConnectionError.None)
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);
88 throw new ArgumentNullException("Value of Apn is null");
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
107 Log.Debug(Globals.LogTag, "Get HomeUri");
109 int ret = Interop.ConnectionCellularProfile.GetHomeUrl(ProfileHandle, out Value);
110 if ((ConnectionError)ret != ConnectionError.None)
112 Log.Error(Globals.LogTag, "It failed to get home url, " + (ConnectionError)ret);
114 string result = Marshal.PtrToStringAnsi(Value);
115 Interop.Glib.Free(Value);
121 Log.Debug(Globals.LogTag, "Set HomeUri");
125 int ret = Interop.ConnectionCellularProfile.SetHomeUrl(ProfileHandle, value);
126 if ((ConnectionError)ret != ConnectionError.None)
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);
137 throw new ArgumentNullException("Value of HomeUri is null");
143 /// The service type.
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
155 Log.Debug(Globals.LogTag, "Get ServiceType");
157 int ret = Interop.ConnectionCellularProfile.GetServiceType(ProfileHandle, out value);
158 if ((ConnectionError)ret != ConnectionError.None)
160 Log.Error(Globals.LogTag, "It failed to get service type, " + (ConnectionError)ret);
162 return (CellularServiceType)value;
167 Log.Debug(Globals.LogTag, "Set ServiceType");
169 int ret = Interop.ConnectionCellularProfile.SetServiceType(ProfileHandle, (int)value);
170 if ((ConnectionError)ret != ConnectionError.None)
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);
181 /// The cellular pdn type.
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
193 Log.Debug(Globals.LogTag, "Get PdnType");
195 int ret = Interop.ConnectionCellularProfile.GetPdnType(ProfileHandle, out value);
196 if ((ConnectionError)ret != ConnectionError.None)
198 Log.Error(Globals.LogTag, "It failed to get pdn type, " + (ConnectionError)ret);
200 return (CellularPdnType)value;
205 Log.Debug(Globals.LogTag, "Set PdnType");
207 int ret = Interop.ConnectionCellularProfile.SetPdnType(ProfileHandle, (int)value);
208 if ((ConnectionError)ret != ConnectionError.None)
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);
219 /// The cellular roaming pdn type.
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
231 Log.Debug(Globals.LogTag, "Get RoamingPdnType");
233 int ret = Interop.ConnectionCellularProfile.GetRoamingPdnType(ProfileHandle, out value);
234 if ((ConnectionError)ret != ConnectionError.None)
236 Log.Error(Globals.LogTag, "It failed to get roam pdn type, " + (ConnectionError)ret);
238 return (CellularPdnType)value;
243 Log.Debug(Globals.LogTag, "Set RoamingPdnType");
245 int ret = Interop.ConnectionCellularProfile.SetRoamingPdnType(ProfileHandle, (int)value);
246 if ((ConnectionError)ret != ConnectionError.None)
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);
257 /// Checks whether the connection is in roaming state.
259 /// <since_tizen> 6 </since_tizen>
260 /// <value> True if the cellular profile is in roaming state, otherwise false.</value>
261 public bool IsRoaming
265 Log.Debug(Globals.LogTag, "Get IsRoaming");
267 int ret = Interop.ConnectionCellularProfile.IsRoaming(ProfileHandle, out value);
268 if ((ConnectionError)ret != ConnectionError.None)
270 Log.Error(Globals.LogTag, "It failed to get isRoaming, " + (ConnectionError)ret);
277 /// The cellular authentication information.
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
293 int ret = Interop.ConnectionCellularProfile.GetAuthInfo(ProfileHandle, out type, out name, out password);
294 if ((ConnectionError)ret != ConnectionError.None)
296 Log.Error(Globals.LogTag, "It failed to get cellular authentication information, " + (ConnectionError)ret);
300 if (_cellularAuthInfo == null)
301 _cellularAuthInfo = new CellularAuthInformation();
302 _cellularAuthInfo.AuthType = (CellularAuthType)type;
303 _cellularAuthInfo.UserName = name;
304 _cellularAuthInfo.Password = password;
305 return _cellularAuthInfo;
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)
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);
329 throw new ArgumentNullException("CellularAuthInformation value is null");
335 /// Checks whether the profile is hidden.
337 /// <since_tizen> 3 </since_tizen>
338 /// <value>True if the cellular profile is hidden, otherwise false.</value>
344 int ret = Interop.ConnectionCellularProfile.IsHidden(ProfileHandle, out value);
345 if ((ConnectionError)ret != ConnectionError.None)
347 Log.Error(Globals.LogTag, "It failed to get hidden value, " + (ConnectionError)ret);
354 /// Checks whether the profile is editable.
356 /// <since_tizen> 3 </since_tizen>
357 /// <value>True if the cellular profile is editable, otherwise false.</value>
363 int ret = Interop.ConnectionCellularProfile.IsEditable(ProfileHandle, out value);
364 if ((ConnectionError)ret != ConnectionError.None)
366 Log.Error(Globals.LogTag, "It failed to get editable value, " + (ConnectionError)ret);
373 /// Checks whether the profile is default.
375 /// <since_tizen> 3 </since_tizen>
376 /// <value>True if the cellular profile is default, otherwise false.</value>
377 public bool IsDefault
382 int ret = Interop.ConnectionCellularProfile.IsDefault(ProfileHandle, out value);
383 if ((ConnectionError)ret != ConnectionError.None)
385 Log.Error(Globals.LogTag, "It failed to get IsDefault value, " + (ConnectionError)ret);
393 /// This is the CellularAuthInformation class. It provides the properties to get and set the cellular authentication information.
395 /// <since_tizen> 3 </since_tizen>
396 public class CellularAuthInformation
399 /// Default constructor. Initializes an object of the CellularAuthInformation.
401 /// <since_tizen> 3 </since_tizen>
402 public CellularAuthInformation()
409 /// <since_tizen> 3 </since_tizen>
410 /// <value>Cellular user name.</value>
411 public string UserName { get; set;}
415 /// <since_tizen> 3 </since_tizen>
416 /// <value>Cellular password.</value>
417 public string Password { get; set; }
420 /// The authentication type.
422 /// <since_tizen> 3 </since_tizen>
423 /// <value>Cellular authentication type.</value>
424 public CellularAuthType AuthType { get; set; }