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 Class is CellularProfile. 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;
42 /// The APN (access point name).
44 /// <since_tizen> 3 </since_tizen>
45 /// <value>Cellular access point name.</value>
46 /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
47 /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
48 /// <exception cref="System.ArgumentNullException">Thrown during set when value is null.</exception>
49 /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
50 /// <exception cref="System.ObjectDisposedException">Thrown when operation is performed on a disposed object.</exception>
55 Log.Debug(Globals.LogTag, "Get Apn");
57 int ret = Interop.ConnectionCellularProfile.GetApn(ProfileHandle, out Value);
58 if ((ConnectionError)ret != ConnectionError.None)
60 Log.Error(Globals.LogTag, "It failed to get apn, " + (ConnectionError)ret);
62 string result = Marshal.PtrToStringAnsi(Value);
63 Interop.Libc.Free(Value);
69 Log.Debug(Globals.LogTag, "Set Apn");
73 int ret = Interop.ConnectionCellularProfile.SetApn(ProfileHandle, value);
74 if ((ConnectionError)ret != ConnectionError.None)
76 Log.Error(Globals.LogTag, "It failed to set apn, " + (ConnectionError)ret);
77 ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
78 ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
79 ConnectionErrorFactory.ThrowConnectionException(ret);
85 throw new ArgumentNullException("Value of Apn is null");
93 /// <since_tizen> 3 </since_tizen>
94 /// <value>Cellular home URL.</value>
95 /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
96 /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
97 /// <exception cref="System.ArgumentNullException">Thrown during set when value is null.</exception>
98 /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
99 /// <exception cref="System.ObjectDisposedException">Thrown when operation is performed on a disposed object.</exception>
100 public string HomeUri
104 Log.Debug(Globals.LogTag, "Get HomeUri");
106 int ret = Interop.ConnectionCellularProfile.GetHomeUrl(ProfileHandle, out Value);
107 if ((ConnectionError)ret != ConnectionError.None)
109 Log.Error(Globals.LogTag, "It failed to get home url, " + (ConnectionError)ret);
111 string result = Marshal.PtrToStringAnsi(Value);
112 Interop.Libc.Free(Value);
118 Log.Debug(Globals.LogTag, "Set HomeUri");
122 int ret = Interop.ConnectionCellularProfile.SetHomeUrl(ProfileHandle, value);
123 if ((ConnectionError)ret != ConnectionError.None)
125 Log.Error(Globals.LogTag, "It failed to set home url, " + (ConnectionError)ret);
126 ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
127 ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
128 ConnectionErrorFactory.ThrowConnectionException(ret);
134 throw new ArgumentNullException("Value of HomeUri is null");
140 /// The service type.
142 /// <since_tizen> 3 </since_tizen>
143 /// <value>Cellular service type.</value>
144 /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
145 /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
146 /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
147 /// <exception cref="System.ObjectDisposedException">Thrown when operation is performed on a disposed object.</exception>
148 public CellularServiceType ServiceType
152 Log.Debug(Globals.LogTag, "Get ServiceType");
154 int ret = Interop.ConnectionCellularProfile.GetServiceType(ProfileHandle, out value);
155 if ((ConnectionError)ret != ConnectionError.None)
157 Log.Error(Globals.LogTag, "It failed to get service type, " + (ConnectionError)ret);
159 return (CellularServiceType)value;
164 Log.Debug(Globals.LogTag, "Set ServiceType");
166 int ret = Interop.ConnectionCellularProfile.SetServiceType(ProfileHandle, (int)value);
167 if ((ConnectionError)ret != ConnectionError.None)
169 Log.Error(Globals.LogTag, "It failed to set service type, " + (ConnectionError)ret);
170 ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
171 ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
172 ConnectionErrorFactory.ThrowConnectionException(ret);
178 /// The cellular pdn type.
180 /// <since_tizen> 3 </since_tizen>
181 /// <value>Cellular pdn type.</value>
182 /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
183 /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
184 /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
185 /// <exception cref="System.ObjectDisposedException">Thrown when operation is performed on a disposed object.</exception>
186 public CellularPdnType PdnType
190 Log.Debug(Globals.LogTag, "Get PdnType");
192 int ret = Interop.ConnectionCellularProfile.GetPdnType(ProfileHandle, out value);
193 if ((ConnectionError)ret != ConnectionError.None)
195 Log.Error(Globals.LogTag, "It failed to get pdn type, " + (ConnectionError)ret);
197 return (CellularPdnType)value;
202 Log.Debug(Globals.LogTag, "Set PdnType");
204 int ret = Interop.ConnectionCellularProfile.SetPdnType(ProfileHandle, (int)value);
205 if ((ConnectionError)ret != ConnectionError.None)
207 Log.Error(Globals.LogTag, "It failed to set pdn type, " + (ConnectionError)ret);
208 ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
209 ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
210 ConnectionErrorFactory.ThrowConnectionException(ret);
216 /// The cellular roaming pdn type.
218 /// <since_tizen> 3 </since_tizen>
219 /// <value>Cellular roaming pdn type.</value>
220 /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
221 /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
222 /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
223 /// <exception cref="System.ObjectDisposedException">Thrown when operation is performed on a disposed object.</exception>
224 public CellularPdnType RoamingPdnType
228 Log.Debug(Globals.LogTag, "Get RoamingPdnType");
230 int ret = Interop.ConnectionCellularProfile.GetRoamingPdnType(ProfileHandle, out value);
231 if ((ConnectionError)ret != ConnectionError.None)
233 Log.Error(Globals.LogTag, "It failed to get roam pdn type, " + (ConnectionError)ret);
235 return (CellularPdnType)value;
240 Log.Debug(Globals.LogTag, "Set RoamingPdnType");
242 int ret = Interop.ConnectionCellularProfile.SetRoamingPdnType(ProfileHandle, (int)value);
243 if ((ConnectionError)ret != ConnectionError.None)
245 Log.Error(Globals.LogTag, "It failed to set roam pdn type, " + (ConnectionError)ret);
246 ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
247 ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
248 ConnectionErrorFactory.ThrowConnectionException(ret);
254 /// Cellular Authentication Information.
256 /// <since_tizen> 3 </since_tizen>
257 /// <value>Instance of CellularAuthInformation.</value>
258 /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
259 /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
260 /// <exception cref="System.ArgumentNullException">Thrown during set when value is null.</exception>
261 /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
262 /// <exception cref="System.ObjectDisposedException">Thrown when operation is performed on a disposed object.</exception>
263 public CellularAuthInformation CellularAuthInfo
270 int ret = Interop.ConnectionCellularProfile.GetAuthInfo(ProfileHandle, out type, out name, out password);
271 if ((ConnectionError)ret != ConnectionError.None)
273 Log.Error(Globals.LogTag, "It failed to get cellular authentication information, " + (ConnectionError)ret);
277 if (_cellularAuthInfo == null)
278 _cellularAuthInfo = new CellularAuthInformation();
279 _cellularAuthInfo.AuthType = (CellularAuthType)type;
280 _cellularAuthInfo.UserName = name;
281 _cellularAuthInfo.Password = password;
282 return _cellularAuthInfo;
290 _cellularAuthInfo = value;
291 int type = (int)_cellularAuthInfo.AuthType;
292 string name = _cellularAuthInfo.UserName;
293 string password = _cellularAuthInfo.Password;
294 int ret = Interop.ConnectionCellularProfile.SetAuthInfo(ProfileHandle, type, name, password);
295 if ((ConnectionError)ret != ConnectionError.None)
297 Log.Error(Globals.LogTag, "It failed to set auth information, " + (ConnectionError)ret);
298 ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
299 ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
300 ConnectionErrorFactory.ThrowConnectionException(ret);
306 throw new ArgumentNullException("CellularAuthInformation value is null");
312 /// Checks whether the profile is hidden.
314 /// <since_tizen> 3 </since_tizen>
315 /// <value>True if the cellular profile is hidden, otherwise false.</value>
321 int ret = Interop.ConnectionCellularProfile.IsHidden(ProfileHandle, out value);
322 if ((ConnectionError)ret != ConnectionError.None)
324 Log.Error(Globals.LogTag, "It failed to get hidden value, " + (ConnectionError)ret);
331 /// Checks whether the profile is editable.
333 /// <since_tizen> 3 </since_tizen>
334 /// <value>True if the cellular profile is editable, otherwise false.</value>
340 int ret = Interop.ConnectionCellularProfile.IsEditable(ProfileHandle, out value);
341 if ((ConnectionError)ret != ConnectionError.None)
343 Log.Error(Globals.LogTag, "It failed to get editable value, " + (ConnectionError)ret);
350 /// Checks whether the profile is default.
352 /// <since_tizen> 3 </since_tizen>
353 /// <value>True if the cellular profile is default, otherwise false.</value>
354 public bool IsDefault
359 int ret = Interop.ConnectionCellularProfile.IsDefault(ProfileHandle, out value);
360 if ((ConnectionError)ret != ConnectionError.None)
362 Log.Error(Globals.LogTag, "It failed to get IsDefault value, " + (ConnectionError)ret);
370 /// This Class is CellularAuthInformation. It provides the properties to get and set the cellular authentication information.
372 /// <since_tizen> 3 </since_tizen>
373 public class CellularAuthInformation
376 /// Default Constructor.Initializes an object of CellularAuthInformation.
378 public CellularAuthInformation()
384 /// <since_tizen> 3 </since_tizen>
386 /// <value>Cellular user name.</value>
387 public string UserName { get; set;}
391 /// <since_tizen> 3 </since_tizen>
392 /// <value>Cellular password.</value>
393 public string Password { get; set; }
396 /// The authentication type
398 /// <since_tizen> 3 </since_tizen>
399 /// <value>Cellular authentication type.</value>
400 public CellularAuthType AuthType { get; set; }