/
ConnectionProfileManager.cs
executable file
·276 lines (263 loc) · 16.7 KB
/
ConnectionProfileManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
* Copyright (c) 2018 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.Threading.Tasks;
using System.Collections;
namespace Tizen.Network.Connection
{
/// <summary>
/// This is the ConnectionProfileManager class. It provides functions to add, get, connect, or modify the connection profile.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public static class ConnectionProfileManager
{
/// <summary>
/// Adds a new profile.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="profile">The cellular profile object.</param>
/// <privilege>http://tizen.org/privilege/network.profile</privilege>
/// <privilege>http://tizen.org/privilege/network.get</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 connection or profile instance is invalid or when a method fails due to an invalid operation.</exception>
public static void AddCellularProfile(CellularProfile profile)
{
Log.Debug(Globals.LogTag, "AddCellularProfile");
ConnectionInternalManager.Instance.AddCellularProfile(profile);
}
/// <summary>
/// Gets the list of the profile with the profile list type.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="type">The type of profile.</param>
/// <returns>List of connection profile objects.</returns>
/// <privilege>http://tizen.org/privilege/network.get</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.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
/// <exception cref="System.InvalidOperationException">Thrown when a connection instance has been disposed.</exception>
public static Task<IEnumerable<ConnectionProfile>> GetProfileListAsync(ProfileListType type)
{
Log.Debug(Globals.LogTag, "GetProfileListAsync");
return ConnectionInternalManager.Instance.GetProfileListAsync(type);
}
/// <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>
/// <remarks>
/// This method must be called from MainThread.
/// </remarks>
/// <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);
}
/// <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>
/// <remarks>
/// This method must be called from MainThread.
/// </remarks>
/// <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);
}
/// <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);
}
/// <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);
}
/// <summary>
/// Gets the name of the default profile.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <returns>Connection profile object.</returns>
/// <privilege>http://tizen.org/privilege/network.get</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.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
/// <exception cref="System.InvalidOperationException">Thrown when a connection instance is invalid or when a method fails due to an invalid operation.</exception>
public static ConnectionProfile GetCurrentProfile()
{
Log.Debug(Globals.LogTag, "GetCurrentProfile");
return ConnectionInternalManager.Instance.GetCurrentProfile();
}
/// <summary>
/// Gets the default profile, which provides the given cellular service.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <param name="type">The cellular service type.</param>
/// <returns>Connection profile object.</returns>
/// <privilege>http://tizen.org/privilege/network.get</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.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
/// <exception cref="System.InvalidOperationException">Thrown when a connection instance is invalid or when a method fails due to an invalid operation.</exception>
public static ConnectionProfile GetDefaultCellularProfile(CellularServiceType type)
{
Log.Debug(Globals.LogTag, "GetDefaultCurrentProfile");
return ConnectionInternalManager.Instance.GetDefaultCellularProfile(type);
}
/// <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>
/// <remarks>
/// This method must be called from MainThread.
/// </remarks>
/// <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);
}
}
/// <summary>
/// An extended EventArgs class, which contains the state of changed connection profile.
/// </summary>
/// <since_tizen> 3 </since_tizen>
public class ConnectionProfileStateEventArgs : EventArgs
{
private ConnectionProfileState State;
internal ConnectionProfileStateEventArgs(ConnectionProfileState state)
{
State = state;
}
/// <summary>
/// The connection profile state.
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <value>State of the connection profile.</value>
public ConnectionProfileState ConnectionProfileState
{
get
{
return State;
}
}
}
}