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.Threading.Tasks;
22 using System.Collections;
24 namespace Tizen.Network.Connection
27 /// This is the ConnectionProfileManager class. It provides functions to add, get, connect, or modify the connection profile.
29 /// <since_tizen> 3 </since_tizen>
30 public static class ConnectionProfileManager
33 /// Adds a new profile.
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)
51 Log.Debug(Globals.LogTag, "AddCellularProfile");
52 ConnectionInternalManager.Instance.AddCellularProfile(profile);
56 /// Gets the list of the profile with the profile list type.
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)
73 Log.Debug(Globals.LogTag, "GetProfileListAsync");
74 return ConnectionInternalManager.Instance.GetProfileListAsync(type);
78 /// Opens a connection of profile asynchronously.
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>
84 /// This method must be called from MainThread.
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)
100 Log.Debug(Globals.LogTag, "ConnectProfile");
101 return ConnectionInternalManager.Instance.OpenProfileAsync(profile);
105 /// Closes a connection of profile.
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>
111 /// This method must be called from MainThread.
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)
127 Log.Debug(Globals.LogTag, "DisconnectProfileAsync");
128 return ConnectionInternalManager.Instance.CloseProfileAsync(profile);
132 /// Removes an existing profile.
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)
150 Log.Debug(Globals.LogTag, "RemoveProfile. Id: " + profile.Id + ", Name: " + profile.Name + ", Type: " + profile.Type);
151 ConnectionInternalManager.Instance.RemoveProfile(profile);
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.
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)
175 Log.Debug(Globals.LogTag, "UpdateProfile");
176 ConnectionInternalManager.Instance.UpdateProfile(profile);
180 /// Gets the name of the default profile.
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()
196 Log.Debug(Globals.LogTag, "GetCurrentProfile");
197 return ConnectionInternalManager.Instance.GetCurrentProfile();
201 /// Gets the default profile, which provides the given cellular service.
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)
218 Log.Debug(Globals.LogTag, "GetDefaultCurrentProfile");
219 return ConnectionInternalManager.Instance.GetDefaultCellularProfile(type);
223 /// Sets the default profile, which provides the given cellular service.
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>
230 /// This method must be called from MainThread.
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)
246 Log.Debug(Globals.LogTag, "SetDefaultCellularProfile");
247 return ConnectionInternalManager.Instance.SetDefaultCellularProfile(type, profile);
252 /// An extended EventArgs class, which contains the state of changed connection profile.
254 /// <since_tizen> 3 </since_tizen>
255 public class ConnectionProfileStateEventArgs : EventArgs
257 private ConnectionProfileState State;
259 internal ConnectionProfileStateEventArgs(ConnectionProfileState state)
265 /// The connection profile state.
267 /// <since_tizen> 3 </since_tizen>
268 /// <value>State of the connection profile.</value>
269 public ConnectionProfileState ConnectionProfileState