Release 5.0.0.14403
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Connection / Tizen.Network.Connection / ConnectionProfileManager.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.Threading.Tasks;
22 using System.Collections;
23
24 namespace Tizen.Network.Connection
25 {
26     /// <summary>
27     /// This is the ConnectionProfileManager class. It provides functions to add, get, connect, or modify the connection profile.
28     /// </summary>
29     /// <since_tizen> 3 </since_tizen>
30     public static class ConnectionProfileManager
31     {
32         /// <summary>
33         /// Adds a new profile.
34         /// </summary>
35         /// <since_tizen> 3 </since_tizen>
36         /// <param name="profile">The cellular profile object.</param>
37         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
38         /// <privilege>http://tizen.org/privilege/network.get</privilege>
39         /// <feature>http://tizen.org/feature/network.telephony</feature>
40         /// <feature>http://tizen.org/feature/network.wifi</feature>
41         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
42         /// <feature>http://tizen.org/feature/network.ethernet</feature>
43         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
44         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
45         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
46         /// <exception cref="System.ArgumentNullException">Thrown when a value is null.</exception>
47         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
48         /// <exception cref="System.InvalidOperationException">Thrown when connection or profile instance is invalid or when a method fails due to an invalid operation.</exception>
49         public static void AddCellularProfile(CellularProfile profile)
50         {
51             Log.Debug(Globals.LogTag, "AddCellularProfile");
52             ConnectionInternalManager.Instance.AddCellularProfile(profile);
53         }
54
55         /// <summary>
56         /// Gets the list of the profile with the profile list type.
57         /// </summary>
58         /// <since_tizen> 3 </since_tizen>
59         /// <param name="type">The type of profile.</param>
60         /// <returns>List of connection profile objects.</returns>
61         /// <privilege>http://tizen.org/privilege/network.get</privilege>
62         /// <feature>http://tizen.org/feature/network.telephony</feature>
63         /// <feature>http://tizen.org/feature/network.wifi</feature>
64         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
65         /// <feature>http://tizen.org/feature/network.ethernet</feature>
66         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
67         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
68         /// <exception cref="System.ArgumentException">Thrown when value is an invalid parameter.</exception>
69         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
70         /// <exception cref="System.InvalidOperationException">Thrown when a connection instance has been disposed.</exception>
71         public static Task<IEnumerable<ConnectionProfile>> GetProfileListAsync(ProfileListType type)
72         {
73             Log.Debug(Globals.LogTag, "GetProfileListAsync");
74             return ConnectionInternalManager.Instance.GetProfileListAsync(type);
75         }
76
77         /// <summary>
78         /// Opens a connection of profile asynchronously.
79         /// </summary>
80         /// <since_tizen> 3 </since_tizen>
81         /// <param name="profile">The connection profile object.</param>
82         /// <returns>A task indicates whether the ConnectProfileAsync method is done successfully or not.</returns>
83         /// <remarks>
84         /// This method must be called from MainThread.
85         /// </remarks>
86         /// <privilege>http://tizen.org/privilege/network.get</privilege>
87         /// <privilege>http://tizen.org/privilege/network.set</privilege>
88         /// <feature>http://tizen.org/feature/network.telephony</feature>
89         /// <feature>http://tizen.org/feature/network.wifi</feature>
90         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
91         /// <feature>http://tizen.org/feature/network.ethernet</feature>
92         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
93         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
94         /// <exception cref="System.ArgumentException">Thrown when value is an invalid parameter.</exception>
95         /// <exception cref="System.ArgumentNullException">Thrown when a value is null.</exception>
96         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
97         /// <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>
98         public static Task ConnectProfileAsync(ConnectionProfile profile)
99         {
100             Log.Debug(Globals.LogTag, "ConnectProfile");
101             return ConnectionInternalManager.Instance.OpenProfileAsync(profile);
102         }
103
104         /// <summary>
105         /// Closes a connection of profile.
106         /// </summary>
107         /// <since_tizen> 3 </since_tizen>
108         /// <param name="profile">The connection profile object.</param>
109         /// <returns>A task indicates whether the DisconnectProfileAsync method is done successfully or not.</returns>
110         /// <remarks>
111         /// This method must be called from MainThread.
112         /// </remarks>
113         /// <privilege>http://tizen.org/privilege/network.get</privilege>
114         /// <privilege>http://tizen.org/privilege/network.set</privilege>
115         /// <feature>http://tizen.org/feature/network.telephony</feature>
116         /// <feature>http://tizen.org/feature/network.wifi</feature>
117         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
118         /// <feature>http://tizen.org/feature/network.ethernet</feature>
119         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
120         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
121         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
122         /// <exception cref="System.ArgumentNullException">Thrown when a value is null.</exception>
123         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
124         /// <exception cref="System.InvalidOperationException">Thrown when a connection or a profile instance is invalid or when a method fails due to invalid operation.</exception>
125         public static Task DisconnectProfileAsync(ConnectionProfile profile)
126         {
127             Log.Debug(Globals.LogTag, "DisconnectProfileAsync");
128             return ConnectionInternalManager.Instance.CloseProfileAsync(profile);
129         }
130
131         /// <summary>
132         /// Removes an existing profile.
133         /// </summary>
134         /// <since_tizen> 3 </since_tizen>
135         /// <param name="profile">The connection profile object.</param>
136         /// <privilege>http://tizen.org/privilege/network.get</privilege>
137         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
138         /// <feature>http://tizen.org/feature/network.telephony</feature>
139         /// <feature>http://tizen.org/feature/network.wifi</feature>
140         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
141         /// <feature>http://tizen.org/feature/network.ethernet</feature>
142         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
143         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
144         /// <exception cref="System.ArgumentException">Thrown when value is an invalid parameter.</exception>
145         /// <exception cref="System.ArgumentNullException">Thrown when a value is null.</exception>
146         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
147         /// <exception cref="System.InvalidOperationException">Thrown when a connection or a profile instance is invalid or when a method fails due to invalid operation.</exception>
148         public static void RemoveProfile(ConnectionProfile profile)
149         {
150             Log.Debug(Globals.LogTag, "RemoveProfile. Id: " + profile.Id + ", Name: " + profile.Name + ", Type: " + profile.Type);
151             ConnectionInternalManager.Instance.RemoveProfile(profile);
152         }
153
154         /// <summary>
155         /// Updates an existing profile.
156         /// When a profile is changed, these changes will be not applied to the ConnectionProfileManager immediately.
157         /// When you call this function, your changes affect the ConnectionProfileManager and the existing profile is updated.
158         /// </summary>
159         /// <since_tizen> 3 </since_tizen>
160         /// <param name="profile">The connection profile object.</param>
161         /// <privilege>http://tizen.org/privilege/network.get</privilege>
162         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
163         /// <feature>http://tizen.org/feature/network.telephony</feature>
164         /// <feature>http://tizen.org/feature/network.wifi</feature>
165         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
166         /// <feature>http://tizen.org/feature/network.ethernet</feature>
167         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
168         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
169         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
170         /// <exception cref="System.ArgumentNullException">Thrown when a value is null.</exception>
171         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
172         /// <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>
173         public static void UpdateProfile(ConnectionProfile profile)
174         {
175             Log.Debug(Globals.LogTag, "UpdateProfile");
176             ConnectionInternalManager.Instance.UpdateProfile(profile);
177         }
178
179         /// <summary>
180         /// Gets the name of the default profile.
181         /// </summary>
182         /// <since_tizen> 3 </since_tizen>
183         /// <returns>Connection profile object.</returns>
184         /// <privilege>http://tizen.org/privilege/network.get</privilege>
185         /// <feature>http://tizen.org/feature/network.telephony</feature>
186         /// <feature>http://tizen.org/feature/network.wifi</feature>
187         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
188         /// <feature>http://tizen.org/feature/network.ethernet</feature>
189         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
190         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
191         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
192         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
193         /// <exception cref="System.InvalidOperationException">Thrown when a connection instance is invalid or when a method fails due to an invalid operation.</exception>
194         public static ConnectionProfile GetCurrentProfile()
195         {
196             Log.Debug(Globals.LogTag, "GetCurrentProfile");
197             return ConnectionInternalManager.Instance.GetCurrentProfile();
198         }
199
200         /// <summary>
201         /// Gets the default profile, which provides the given cellular service.
202         /// </summary>
203         /// <since_tizen> 3 </since_tizen>
204         /// <param name="type">The cellular service type.</param>
205         /// <returns>Connection profile object.</returns>
206         /// <privilege>http://tizen.org/privilege/network.get</privilege>
207         /// <feature>http://tizen.org/feature/network.telephony</feature>
208         /// <feature>http://tizen.org/feature/network.wifi</feature>
209         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
210         /// <feature>http://tizen.org/feature/network.ethernet</feature>
211         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
212         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
213         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
214         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
215         /// <exception cref="System.InvalidOperationException">Thrown when a connection instance is invalid or when a method fails due to an invalid operation.</exception>
216         public static ConnectionProfile GetDefaultCellularProfile(CellularServiceType type)
217         {
218             Log.Debug(Globals.LogTag, "GetDefaultCurrentProfile");
219             return ConnectionInternalManager.Instance.GetDefaultCellularProfile(type);
220         }
221
222         /// <summary>
223         /// Sets the default profile, which provides the given cellular service.
224         /// </summary>
225         /// <since_tizen> 3 </since_tizen>
226         /// <param name="type">The cellular service type.</param>
227         /// <param name="profile">The connection profile object.</param>
228         /// <returns>A task indicates whether the SetDefaultCellularProfile method is done successfully or not.</returns>
229         /// <remarks>
230         /// This method must be called from MainThread.
231         /// </remarks>
232         /// <privilege>http://tizen.org/privilege/network.get</privilege>
233         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
234         /// <feature>http://tizen.org/feature/network.telephony</feature>
235         /// <feature>http://tizen.org/feature/network.wifi</feature>
236         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
237         /// <feature>http://tizen.org/feature/network.ethernet</feature>
238         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
239         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
240         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
241         /// <exception cref="System.ArgumentNullException">Thrown when a value is null.</exception>
242         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
243         /// <exception cref="System.InvalidOperationException">Thrown when a connection or a profile instance is invalid or when a method fails due to invalid operation.</exception>
244         public static Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
245         {
246             Log.Debug(Globals.LogTag, "SetDefaultCellularProfile");
247             return ConnectionInternalManager.Instance.SetDefaultCellularProfile(type, profile);
248         }
249     }
250
251     /// <summary>
252     /// An extended EventArgs class, which contains the state of changed connection profile.
253     /// </summary>
254     /// <since_tizen> 3 </since_tizen>
255     public class ConnectionProfileStateEventArgs : EventArgs
256     {
257         private  ConnectionProfileState State;
258
259         internal ConnectionProfileStateEventArgs(ConnectionProfileState state)
260         {
261             State = state;
262         }
263
264         /// <summary>
265         /// The connection profile state.
266         /// </summary>
267         /// <since_tizen> 3 </since_tizen>
268         /// <value>State of the connection profile.</value>
269         public ConnectionProfileState ConnectionProfileState
270         {
271             get
272             {
273                 return State;
274             }
275         }
276     }
277 }