Release 4.0.0-preview1-00051
[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 class is ConnectionProfileManager. 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 feature is not supported.</exception>
44         /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
45         /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
46         /// <exception cref="System.ArgumentNullException">Thrown when 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 method failed due to 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 profile with 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 feature is not supported.</exception>
67         /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
68         /// <exception cref="System.ArgumentException">Thrown when value is 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 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         /// <privilege>http://tizen.org/privilege/network.get</privilege>
84         /// <privilege>http://tizen.org/privilege/network.set</privilege>
85         /// <feature>http://tizen.org/feature/network.telephony</feature>
86         /// <feature>http://tizen.org/feature/network.wifi</feature>
87         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
88         /// <feature>http://tizen.org/feature/network.ethernet</feature>
89         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
90         /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
91         /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
92         /// <exception cref="System.ArgumentNullException">Thrown when value is null.</exception>
93         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
94         /// <exception cref="System.InvalidOperationException">Thrown when connection or profile instance is invalid or when method failed due to invalid operation</exception>
95         public static Task ConnectProfileAsync(ConnectionProfile profile)
96         {
97             Log.Debug(Globals.LogTag, "ConnectProfile");
98             return ConnectionInternalManager.Instance.OpenProfileAsync(profile);
99         }
100
101         /// <summary>
102         /// Closes a connection of profile.
103         /// </summary>
104         /// <since_tizen> 3 </since_tizen>
105         /// <param name="profile">The connection profile object</param>
106         /// <returns>A task indicates whether the DisconnectProfileAsync method is done successfully or not.</returns>
107         /// <privilege>http://tizen.org/privilege/network.get</privilege>
108         /// <privilege>http://tizen.org/privilege/network.set</privilege>
109         /// <feature>http://tizen.org/feature/network.telephony</feature>
110         /// <feature>http://tizen.org/feature/network.wifi</feature>
111         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
112         /// <feature>http://tizen.org/feature/network.ethernet</feature>
113         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
114         /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
115         /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
116         /// <exception cref="System.ArgumentNullException">Thrown when value is null.</exception>
117         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
118         /// <exception cref="System.InvalidOperationException">Thrown when connection or profile instance is invalid or when method failed due to invalid operation</exception>
119         public static Task DisconnectProfileAsync(ConnectionProfile profile)
120         {
121             Log.Debug(Globals.LogTag, "DisconnectProfileAsync");
122             return ConnectionInternalManager.Instance.CloseProfileAsync(profile);
123         }
124
125         /// <summary>
126         /// Removes an existing profile.
127         /// </summary>
128         /// <since_tizen> 3 </since_tizen>
129         /// <param name="profile">The connection profile object</param>
130         /// <privilege>http://tizen.org/privilege/network.get</privilege>
131         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
132         /// <feature>http://tizen.org/feature/network.telephony</feature>
133         /// <feature>http://tizen.org/feature/network.wifi</feature>
134         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
135         /// <feature>http://tizen.org/feature/network.ethernet</feature>
136         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
137         /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
138         /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
139         /// <exception cref="System.ArgumentNullException">Thrown when value is null.</exception>
140         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
141         /// <exception cref="System.InvalidOperationException">Thrown when connection or profile instance is invalid or when method failed due to invalid operation</exception>
142         public static void RemoveProfile(ConnectionProfile profile)
143         {
144             Log.Debug(Globals.LogTag, "RemoveProfile. Id: " + profile.Id + ", Name: " + profile.Name + ", Type: " + profile.Type);
145             ConnectionInternalManager.Instance.RemoveProfile(profile);
146         }
147
148         /// <summary>
149         /// Updates an existing profile.
150         /// When a profile is changed, these changes will be not applied to the ConnectionProfileManager immediately.
151         /// When you call this function, your changes affect the ConnectionProfileManager and the existing profile is updated.
152         /// </summary>
153         /// <since_tizen> 3 </since_tizen>
154         /// <param name="profile">The connection profile object</param>
155         /// <privilege>http://tizen.org/privilege/network.get</privilege>
156         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
157         /// <feature>http://tizen.org/feature/network.telephony</feature>
158         /// <feature>http://tizen.org/feature/network.wifi</feature>
159         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
160         /// <feature>http://tizen.org/feature/network.ethernet</feature>
161         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
162         /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
163         /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
164         /// <exception cref="System.ArgumentNullException">Thrown when value is null.</exception>
165         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
166         /// <exception cref="System.InvalidOperationException">Thrown when connection or profile instance is invalid or when method failed due to invalid operation</exception>
167         public static void UpdateProfile(ConnectionProfile profile)
168         {
169             Log.Debug(Globals.LogTag, "UpdateProfile");
170             ConnectionInternalManager.Instance.UpdateProfile(profile);
171         }
172
173         /// <summary>
174         /// Gets the name of the default profile.
175         /// </summary>
176         /// <since_tizen> 3 </since_tizen>
177         /// <returns>Connection profile object.</returns>
178         /// <privilege>http://tizen.org/privilege/network.get</privilege>
179         /// <feature>http://tizen.org/feature/network.telephony</feature>
180         /// <feature>http://tizen.org/feature/network.wifi</feature>
181         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
182         /// <feature>http://tizen.org/feature/network.ethernet</feature>
183         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
184         /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
185         /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
186         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
187         /// <exception cref="System.InvalidOperationException">Thrown when connection instance is invalid or when method failed due to invalid operation</exception>
188         public static ConnectionProfile GetCurrentProfile()
189         {
190             Log.Debug(Globals.LogTag, "GetCurrentProfile");
191             return ConnectionInternalManager.Instance.GetCurrentProfile();
192         }
193
194         /// <summary>
195         /// Gets the default profile which provides the given cellular service.
196         /// </summary>
197         /// <since_tizen> 3 </since_tizen>
198         /// <param name="type">The cellular service type</param>
199         /// <returns>Connection profile object.</returns>
200         /// <privilege>http://tizen.org/privilege/network.get</privilege>
201         /// <feature>http://tizen.org/feature/network.telephony</feature>
202         /// <feature>http://tizen.org/feature/network.wifi</feature>
203         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
204         /// <feature>http://tizen.org/feature/network.ethernet</feature>
205         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
206         /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
207         /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
208         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
209         /// <exception cref="System.InvalidOperationException">Thrown when connection instance is invalid or when method failed due to invalid operation</exception>
210         public static ConnectionProfile GetDefaultCellularProfile(CellularServiceType type)
211         {
212             Log.Debug(Globals.LogTag, "GetDefaultCurrentProfile");
213             return ConnectionInternalManager.Instance.GetDefaultCellularProfile(type);
214         }
215
216         /// <summary>
217         /// Sets the default profile which provides the given cellular service.
218         /// </summary>
219         /// <since_tizen> 3 </since_tizen>
220         /// <param name="type">The cellular service type</param>
221         /// <param name="profile">The connection profile object</param>
222         /// <returns>A task indicates whether the SetDefaultCellularProfile method is done successfully or not.</returns>
223         /// <privilege>http://tizen.org/privilege/network.get</privilege>
224         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
225         /// <feature>http://tizen.org/feature/network.telephony</feature>
226         /// <feature>http://tizen.org/feature/network.wifi</feature>
227         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
228         /// <feature>http://tizen.org/feature/network.ethernet</feature>
229         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
230         /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
231         /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
232         /// <exception cref="System.ArgumentNullException">Thrown when value is null.</exception>
233         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
234         /// <exception cref="System.InvalidOperationException">Thrown when connection or profile instance is invalid or when method failed due to invalid operation</exception>
235         public static Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
236         {
237             Log.Debug(Globals.LogTag, "SetDefaultCellularProfile");
238             return ConnectionInternalManager.Instance.SetDefaultCellularProfile(type, profile);
239         }
240     }
241
242     /// <summary>
243     /// An extended EventArgs class which contains the state of changed connection profile.
244     /// </summary>
245     /// <since_tizen> 3 </since_tizen>
246     public class ConnectionProfileStateEventArgs : EventArgs
247     {
248         private  ConnectionProfileState State;
249
250         internal ConnectionProfileStateEventArgs(ConnectionProfileState state)
251         {
252             State = state;
253         }
254
255         /// <summary>
256         /// The connection profile state.
257         /// </summary>
258         /// <since_tizen> 3 </since_tizen>
259         /// <value>State of the connection profile.</value>
260         public ConnectionProfileState ConnectionProfileState
261         {
262             get
263             {
264                 return State;
265             }
266         }
267     }
268 }