/* * Copyright (c) 2016 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; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace Tizen.Network.Connection { /// /// This is the CellularProfile class. It provides functions to manage the cellular profile. /// /// 3 public class CellularProfile : ConnectionProfile { internal CellularProfile(IntPtr handle): base(handle) { } private CellularAuthInformation _cellularAuthInfo = null; /// /// Destroy the CellularProfile object /// ~CellularProfile() { } /// /// The APN (access point name). /// /// 3 /// Cellular access point name. /// Thrown during set when a feature is not supported. /// Thrown during set when a value is an invalid parameter. /// Thrown during set when a value is null. /// Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation. /// Thrown when an operation is performed on a disposed object. public string Apn { get { Log.Debug(Globals.LogTag, "Get Apn"); IntPtr Value; int ret = Interop.ConnectionCellularProfile.GetApn(ProfileHandle, out Value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get apn, " + (ConnectionError)ret); } string result = Marshal.PtrToStringAnsi(Value); Interop.Libc.Free(Value); return result; } set { Log.Debug(Globals.LogTag, "Set Apn"); CheckDisposed(); if (value != null) { int ret = Interop.ConnectionCellularProfile.SetApn(ProfileHandle, value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set apn, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } else { throw new ArgumentNullException("Value of Apn is null"); } } } /// /// The home URL. /// /// 3 /// Cellular home URL. /// Thrown during set when a feature is not supported. /// Thrown during set when a value is an invalid parameter. /// Thrown during set when a value is null. /// Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation. /// Thrown when an operation is performed on a disposed object. public string HomeUri { get { Log.Debug(Globals.LogTag, "Get HomeUri"); IntPtr Value; int ret = Interop.ConnectionCellularProfile.GetHomeUrl(ProfileHandle, out Value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get home url, " + (ConnectionError)ret); } string result = Marshal.PtrToStringAnsi(Value); Interop.Libc.Free(Value); return result; } set { Log.Debug(Globals.LogTag, "Set HomeUri"); CheckDisposed(); if (value != null) { int ret = Interop.ConnectionCellularProfile.SetHomeUrl(ProfileHandle, value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set home url, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } else { throw new ArgumentNullException("Value of HomeUri is null"); } } } /// /// The service type. /// /// 3 /// Cellular service type. /// Thrown during set when a feature is not supported. /// Thrown during set when a value is an invalid parameter. /// Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation. /// Thrown when an operation is performed on a disposed object. public CellularServiceType ServiceType { get { Log.Debug(Globals.LogTag, "Get ServiceType"); int value; int ret = Interop.ConnectionCellularProfile.GetServiceType(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get service type, " + (ConnectionError)ret); } return (CellularServiceType)value; } set { Log.Debug(Globals.LogTag, "Set ServiceType"); CheckDisposed(); int ret = Interop.ConnectionCellularProfile.SetServiceType(ProfileHandle, (int)value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set service type, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } } /// /// The cellular pdn type. /// /// 3 /// Cellular pdn type. /// Thrown during set when a feature is not supported. /// Thrown during set when a value is an invalid parameter. /// Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation. /// Thrown when an operation is performed on a disposed object. public CellularPdnType PdnType { get { Log.Debug(Globals.LogTag, "Get PdnType"); int value; int ret = Interop.ConnectionCellularProfile.GetPdnType(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get pdn type, " + (ConnectionError)ret); } return (CellularPdnType)value; } set { Log.Debug(Globals.LogTag, "Set PdnType"); CheckDisposed(); int ret = Interop.ConnectionCellularProfile.SetPdnType(ProfileHandle, (int)value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set pdn type, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } } /// /// The cellular roaming pdn type. /// /// 3 /// Cellular roaming pdn type. /// Thrown during set when a feature is not supported. /// Thrown during set when a value is an invalid parameter. /// Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation. /// Thrown when a operation is performed on a disposed object. public CellularPdnType RoamingPdnType { get { Log.Debug(Globals.LogTag, "Get RoamingPdnType"); int value; int ret = Interop.ConnectionCellularProfile.GetRoamingPdnType(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get roam pdn type, " + (ConnectionError)ret); } return (CellularPdnType)value; } set { Log.Debug(Globals.LogTag, "Set RoamingPdnType"); CheckDisposed(); int ret = Interop.ConnectionCellularProfile.SetRoamingPdnType(ProfileHandle, (int)value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set roam pdn type, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } } /// /// Checks whether the connection is in roaming state. /// /// 6 /// True if the cellular profile is in roaming state, otherwise false. public bool IsRoaming { get { Log.Debug(Globals.LogTag, "Get IsRoaming"); bool value = false; int ret = Interop.ConnectionCellularProfile.IsRoaming(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get isRoaming, " + (ConnectionError)ret); } return value; } } /// /// The cellular authentication information. /// /// 3 /// Instance of CellularAuthInformation. /// Thrown during set when a feature is not supported. /// Thrown during set when a value is an invalid parameter. /// Thrown during set when a value is null. /// Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation. /// Thrown when an operation is performed on a disposed object. public CellularAuthInformation CellularAuthInfo { get { int type; string name; string password; int ret = Interop.ConnectionCellularProfile.GetAuthInfo(ProfileHandle, out type, out name, out password); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get cellular authentication information, " + (ConnectionError)ret); return null; } if (_cellularAuthInfo == null) _cellularAuthInfo = new CellularAuthInformation(); _cellularAuthInfo.AuthType = (CellularAuthType)type; _cellularAuthInfo.UserName = name; _cellularAuthInfo.Password = password; return _cellularAuthInfo; } set { CheckDisposed(); if (value != null) { _cellularAuthInfo = value; int type = (int)_cellularAuthInfo.AuthType; string name = _cellularAuthInfo.UserName; string password = _cellularAuthInfo.Password; int ret = Interop.ConnectionCellularProfile.SetAuthInfo(ProfileHandle, type, name, password); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set auth information, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } else { throw new ArgumentNullException("CellularAuthInformation value is null"); } } } /// /// Checks whether the profile is hidden. /// /// 3 /// True if the cellular profile is hidden, otherwise false. public bool Hidden { get { bool value; int ret = Interop.ConnectionCellularProfile.IsHidden(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get hidden value, " + (ConnectionError)ret); } return value; } } /// /// Checks whether the profile is editable. /// /// 3 /// True if the cellular profile is editable, otherwise false. public bool Editable { get { bool value; int ret = Interop.ConnectionCellularProfile.IsEditable(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get editable value, " + (ConnectionError)ret); } return value; } } /// /// Checks whether the profile is default. /// /// 3 /// True if the cellular profile is default, otherwise false. public bool IsDefault { get { bool value; int ret = Interop.ConnectionCellularProfile.IsDefault(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get IsDefault value, " + (ConnectionError)ret); } return value; } } } /// /// This is the CellularAuthInformation class. It provides the properties to get and set the cellular authentication information. /// /// 3 public class CellularAuthInformation { /// /// Default constructor. Initializes an object of the CellularAuthInformation. /// /// 3 public CellularAuthInformation() { } /// /// The user name. /// /// 3 /// Cellular user name. public string UserName { get; set;} /// /// The password. /// /// 3 /// Cellular password. public string Password { get; set; } /// /// The authentication type. /// /// 3 /// Cellular authentication type. public CellularAuthType AuthType { get; set; } } }