internal ConnectionProfile GetCurrentProfile()
        {
            Log.Info(Globals.LogTag, "GetCurrentProfile");
            IntPtr ProfileHandle;
            int    ret = Interop.Connection.GetCurrentProfile(GetHandle(), out ProfileHandle);

            if ((ConnectionError)ret != ConnectionError.None)
            {
                if ((ConnectionError)ret == ConnectionError.NoConnection)
                {
                    Log.Error(Globals.LogTag, "No connection " + (ConnectionError)ret);
                    return(null);
                }
                else
                {
                    Log.Error(Globals.LogTag, "It failed to get current profile, " + (ConnectionError)ret);
                    ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet");
                    ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)");
                    ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released");
                    ConnectionErrorFactory.ThrowConnectionException(ret);
                }
            }

            ConnectionProfile Profile = new ConnectionProfile(ProfileHandle);

            return(Profile);
        }
示例#2
0
        internal Task CloseProfileAsync(ConnectionProfile profile)
        {
            Log.Info(Globals.LogTag, "CloseProfileAsync");
            if (profile != null)
            {
                Log.Info(Globals.LogTag, "CloseProfileAsync " + profile.Name);
                TaskCompletionSource <bool> task = new TaskCompletionSource <bool>();
                IntPtr id;
                lock (_callback_map)
                {
                    id = (IntPtr)_requestId++;
                    _callback_map[id] = (error, key) =>
                    {
                        Log.Info(Globals.LogTag, "CloseProfileAsync done " + profile.Name);
                        if (error != ConnectionError.None)
                        {
                            Log.Error(Globals.LogTag, "Error occurs during disconnecting profile, " + error);
                            task.SetException(new InvalidOperationException("Error occurs during disconnecting profile, " + error));
                        }
                        else
                        {
                            task.SetResult(true);
                        }
                        lock (_callback_map)
                        {
                            _callback_map.Remove(key);
                        }
                    };
                }

                context.Post((x) =>
                {
                    Log.Info(Globals.LogTag, "Interop.Connection.CloseProfile " + profile.Name);
                    try
                    {
                        int ret = Interop.Connection.CloseProfile(GetHandle(), profile.ProfileHandle, _callback_map[id], id);
                        if ((ConnectionError)ret != ConnectionError.None)
                        {
                            Log.Error(Globals.LogTag, "It failed to disconnect profile, " + (ConnectionError)ret);
                            ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth");
                            ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.set)");
                            ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released");
                            ConnectionErrorFactory.ThrowConnectionException(ret);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error(Globals.LogTag, "Exception on CloseProfile\n" + e.ToString());
                        task.SetException(e);
                    }
                }, null);

                return(task.Task);
            }

            else
            {
                throw new ArgumentNullException("Profile is null");
            }
        }
示例#3
0
        internal Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
        {
            Log.Info(Globals.LogTag, "SetDefaultCellularProfile");
            if (profile != null)
            {
                TaskCompletionSource <bool> task = new TaskCompletionSource <bool>();
                IntPtr id;
                lock (_callback_map)
                {
                    id = (IntPtr)_requestId++;
                    _callback_map[id] = (error, key) =>
                    {
                        Log.Info(Globals.LogTag, "SetDefaultCellularProfile done " + profile.Name);
                        if (error != ConnectionError.None)
                        {
                            Log.Error(Globals.LogTag, "Error occurs during set default cellular profile, " + error);
                            task.SetException(new InvalidOperationException("Error occurs during set default cellular profile, " + error));
                        }
                        else
                        {
                            task.SetResult(true);
                        }
                        lock (_callback_map)
                        {
                            _callback_map.Remove(key);
                        }
                    };
                }

                context.Post((x) =>
                {
                    Log.Info(Globals.LogTag, "Interop.Connection.SetDefaultCellularServiceProfileAsync " + profile.Name);
                    try
                    {
                        int ret = Interop.Connection.SetDefaultCellularServiceProfileAsync(GetHandle(), (int)type, profile.ProfileHandle, _callback_map[id], id);

                        if ((ConnectionError)ret != ConnectionError.None)
                        {
                            Log.Error(Globals.LogTag, "It failed to set default cellular profile, " + (ConnectionError)ret);
                            ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
                            ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released");
                            ConnectionErrorFactory.ThrowConnectionException(ret);
                        }
                    } catch (Exception e)
                    {
                        Log.Error(Globals.LogTag, "Exception on SetDefaultCellularServiceProfileAsync\n" + e.ToString());
                        task.SetException(e);
                    }
                }, null);

                return(task.Task);
            }
            else
            {
                throw new ArgumentNullException("Profile is null");
            }
        }
        internal Task OpenProfileAsync(ConnectionProfile profile)
        {
            Log.Info(Globals.LogTag, "OpenProfileAsync");
            if (profile != null)
            {
                Log.Debug(Globals.LogTag, "OpenProfileAsync " + profile.Name);
                TaskCompletionSource <bool>           task     = new TaskCompletionSource <bool>();
                Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) =>
                {
                    Log.Info(Globals.LogTag, "OpenProfileAsync done " + profile.Name);
                    if (Result != ConnectionError.None)
                    {
                        Log.Error(Globals.LogTag, "Error occurs during connecting profile, " + Result);
                        task.SetException(new InvalidOperationException("Error occurs during connecting profile, " + Result));
                    }
                    else
                    {
                        task.SetResult(true);
                    }
                };

                context.Post((x) =>
                {
                    Log.Info(Globals.LogTag, "Interop.Connection.OpenProfile " + profile.Name);
                    try
                    {
                        int ret = Interop.Connection.OpenProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero);
                        if ((ConnectionError)ret != ConnectionError.None)
                        {
                            Log.Error(Globals.LogTag, "It failed to connect profile, " + (ConnectionError)ret);
                            ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth");
                            ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released");
                            ConnectionErrorFactory.ThrowConnectionException(ret);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error(Globals.LogTag, "Exception on OpenProfile\n" + e.ToString());
                        task.SetException(e);
                    }
                }, null);

                return(task.Task);
            }

            else
            {
                throw new ArgumentNullException("Profile is null");
            }
        }
示例#5
0
        internal Task <IEnumerable <ConnectionProfile> > GetProfileListAsync(ProfileListType type)
        {
            Log.Debug(Globals.LogTag, "GetProfileListAsync");
            var task = new TaskCompletionSource <IEnumerable <ConnectionProfile> >();

            List <ConnectionProfile> Result = new List <ConnectionProfile>();
            IntPtr iterator;
            int    ret = Interop.Connection.GetProfileIterator(GetHandle(), (int)type, out iterator);

            if ((ConnectionError)ret != ConnectionError.None)
            {
                Log.Error(Globals.LogTag, "It failed to get profile iterator, " + (ConnectionError)ret);
                ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet");
                ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)");
                ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released");
                ConnectionErrorFactory.ThrowConnectionException(ret);
            }

            while (Interop.Connection.HasNextProfileIterator(iterator))
            {
                IntPtr nextH;
                IntPtr profileH;
                Interop.Connection.GetNextProfileIterator(iterator, out nextH);
                Interop.ConnectionProfile.Clone(out profileH, nextH);

                int profileType;
                Interop.ConnectionProfile.GetType(profileH, out profileType);

                if ((ConnectionProfileType)profileType == ConnectionProfileType.WiFi)
                {
                    WiFiProfile cur = new WiFiProfile(profileH);
                    Result.Add(cur);
                }
                else if ((ConnectionProfileType)profileType == ConnectionProfileType.Cellular)
                {
                    CellularProfile cur = new CellularProfile(profileH);
                    Result.Add(cur);
                }
                else
                {
                    ConnectionProfile cur = new ConnectionProfile(profileH);
                    Result.Add(cur);
                }
            }
            Interop.Connection.DestroyProfileIterator(iterator);
            task.SetResult(Result);
            return(task.Task);
        }
示例#6
0
        internal void UpdateProfile(ConnectionProfile profile)
        {
            Log.Info(Globals.LogTag, "UpdateProfile");
            if (profile != null)
            {
                int ret = Interop.Connection.UpdateProfile(GetHandle(), profile.ProfileHandle);
                if ((ConnectionError)ret != ConnectionError.None)
                {
                    Log.Error(Globals.LogTag, "It failed to update profile, " + (ConnectionError)ret);
                    ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.ethernet");
                    ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released");
                    ConnectionErrorFactory.ThrowConnectionException(ret);
                }
            }

            else
            {
                throw new ArgumentNullException("Profile is null");
            }
        }
示例#7
0
        internal Task CloseProfileAsync(ConnectionProfile profile)
        {
            Log.Debug(Globals.LogTag, "CloseProfileAsync");
            if (profile != null)
            {
                Log.Debug(Globals.LogTag, "CloseProfileAsync " + profile.Name);
                TaskCompletionSource <bool>           task     = new TaskCompletionSource <bool>();
                Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) =>
                {
                    if (Result != ConnectionError.None)
                    {
                        Log.Error(Globals.LogTag, "Error occurs during disconnecting profile, " + Result);
                        task.SetException(new InvalidOperationException("Error occurs during disconnecting profile, " + Result));
                    }
                    else
                    {
                        task.SetResult(true);
                    }
                };

                int ret = Interop.Connection.CloseProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero);
                if ((ConnectionError)ret != ConnectionError.None)
                {
                    Log.Error(Globals.LogTag, "It failed to disconnect profile, " + (ConnectionError)ret);
                    ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth");
                    ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.set)");
                    ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released");
                    ConnectionErrorFactory.ThrowConnectionException(ret);
                }

                return(task.Task);
            }

            else
            {
                throw new ArgumentNullException("Profile is null");
            }
        }
示例#8
0
        internal Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
        {
            Log.Debug(Globals.LogTag, "SetDefaultCellularProfile");
            if (profile != null)
            {
                TaskCompletionSource <bool>           task     = new TaskCompletionSource <bool>();
                Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) =>
                {
                    if (Result != ConnectionError.None)
                    {
                        Log.Error(Globals.LogTag, "Error occurs during set default cellular profile, " + Result);
                        task.SetException(new InvalidOperationException("Error occurs during set default cellular profile, " + Result));
                    }
                    else
                    {
                        task.SetResult(true);
                    }
                };

                int ret = Interop.Connection.SetDefaultCellularServiceProfileAsync(GetHandle(), (int)type, profile.ProfileHandle, Callback, (IntPtr)0);
                if ((ConnectionError)ret != ConnectionError.None)
                {
                    Log.Error(Globals.LogTag, "It failed to set default cellular profile, " + (ConnectionError)ret);
                    ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
                    ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released");
                    ConnectionErrorFactory.ThrowConnectionException(ret);
                }

                return(task.Task);
            }

            else
            {
                throw new ArgumentNullException("Profile is null");
            }
        }
示例#9
0
 /// <summary>
 /// Opens a connection of profile asynchronously.
 /// </summary>
 /// <since_tizen> 3 </since_tizen>
 /// <param name="profile">The connection profile object.</param>
 /// <returns>A task indicates whether the ConnectProfileAsync method is done successfully or not.</returns>
 /// <privilege>http://tizen.org/privilege/network.get</privilege>
 /// <privilege>http://tizen.org/privilege/network.set</privilege>
 /// <feature>http://tizen.org/feature/network.telephony</feature>
 /// <feature>http://tizen.org/feature/network.wifi</feature>
 /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
 /// <feature>http://tizen.org/feature/network.ethernet</feature>
 /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
 /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
 /// <exception cref="System.ArgumentException">Thrown when value is an invalid parameter.</exception>
 /// <exception cref="System.ArgumentNullException">Thrown when a value is null.</exception>
 /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
 /// <exception cref="System.InvalidOperationException">Thrown when a connection or a profile instance is invalid or when a method fails due to an invalid operation.</exception>
 public static Task ConnectProfileAsync(ConnectionProfile profile)
 {
     Log.Debug(Globals.LogTag, "ConnectProfile");
     return(ConnectionInternalManager.Instance.OpenProfileAsync(profile));
 }
示例#10
0
 /// <summary>
 /// Sets the default profile, which provides the given cellular service.
 /// </summary>
 /// <since_tizen> 3 </since_tizen>
 /// <param name="type">The cellular service type.</param>
 /// <param name="profile">The connection profile object.</param>
 /// <returns>A task indicates whether the SetDefaultCellularProfile method is done successfully or not.</returns>
 /// <privilege>http://tizen.org/privilege/network.get</privilege>
 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
 /// <feature>http://tizen.org/feature/network.telephony</feature>
 /// <feature>http://tizen.org/feature/network.wifi</feature>
 /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
 /// <feature>http://tizen.org/feature/network.ethernet</feature>
 /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
 /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
 /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
 /// <exception cref="System.ArgumentNullException">Thrown when a value is null.</exception>
 /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
 /// <exception cref="System.InvalidOperationException">Thrown when a connection or a profile instance is invalid or when a method fails due to invalid operation.</exception>
 public static Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
 {
     Log.Debug(Globals.LogTag, "SetDefaultCellularProfile");
     return(ConnectionInternalManager.Instance.SetDefaultCellularProfile(type, profile));
 }
示例#11
0
 /// <summary>
 /// Updates an existing profile.
 /// When a profile is changed, these changes will be not applied to the ConnectionProfileManager immediately.
 /// When you call this function, your changes affect the ConnectionProfileManager and the existing profile is updated.
 /// </summary>
 /// <since_tizen> 3 </since_tizen>
 /// <param name="profile">The connection profile object.</param>
 /// <privilege>http://tizen.org/privilege/network.get</privilege>
 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
 /// <feature>http://tizen.org/feature/network.telephony</feature>
 /// <feature>http://tizen.org/feature/network.wifi</feature>
 /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
 /// <feature>http://tizen.org/feature/network.ethernet</feature>
 /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
 /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
 /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
 /// <exception cref="System.ArgumentNullException">Thrown when a value is null.</exception>
 /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
 /// <exception cref="System.InvalidOperationException">Thrown when a connection or a profile instance is invalid or when a method fails due to an invalid operation.</exception>
 public static void UpdateProfile(ConnectionProfile profile)
 {
     Log.Debug(Globals.LogTag, "UpdateProfile");
     ConnectionInternalManager.Instance.UpdateProfile(profile);
 }
示例#12
0
 /// <summary>
 /// Removes an existing profile.
 /// </summary>
 /// <since_tizen> 3 </since_tizen>
 /// <param name="profile">The connection profile object.</param>
 /// <privilege>http://tizen.org/privilege/network.get</privilege>
 /// <privilege>http://tizen.org/privilege/network.profile</privilege>
 /// <feature>http://tizen.org/feature/network.telephony</feature>
 /// <feature>http://tizen.org/feature/network.wifi</feature>
 /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
 /// <feature>http://tizen.org/feature/network.ethernet</feature>
 /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
 /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
 /// <exception cref="System.ArgumentException">Thrown when value is an invalid parameter.</exception>
 /// <exception cref="System.ArgumentNullException">Thrown when a value is null.</exception>
 /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
 /// <exception cref="System.InvalidOperationException">Thrown when a connection or a profile instance is invalid or when a method fails due to invalid operation.</exception>
 public static void RemoveProfile(ConnectionProfile profile)
 {
     Log.Debug(Globals.LogTag, "RemoveProfile. Id: " + profile.Id + ", Name: " + profile.Name + ", Type: " + profile.Type);
     ConnectionInternalManager.Instance.RemoveProfile(profile);
 }
示例#13
0
 /// <summary>
 /// Closes a connection of profile.
 /// </summary>
 /// <since_tizen> 3 </since_tizen>
 /// <param name="profile">The connection profile object.</param>
 /// <returns>A task indicates whether the DisconnectProfileAsync method is done successfully or not.</returns>
 /// <privilege>http://tizen.org/privilege/network.get</privilege>
 /// <privilege>http://tizen.org/privilege/network.set</privilege>
 /// <feature>http://tizen.org/feature/network.telephony</feature>
 /// <feature>http://tizen.org/feature/network.wifi</feature>
 /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
 /// <feature>http://tizen.org/feature/network.ethernet</feature>
 /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
 /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
 /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
 /// <exception cref="System.ArgumentNullException">Thrown when a value is null.</exception>
 /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
 /// <exception cref="System.InvalidOperationException">Thrown when a connection or a profile instance is invalid or when a method fails due to invalid operation.</exception>
 public static Task DisconnectProfileAsync(ConnectionProfile profile)
 {
     Log.Debug(Globals.LogTag, "DisconnectProfileAsync");
     return(ConnectionInternalManager.Instance.CloseProfileAsync(profile));
 }