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.Threading.Tasks;
19 using System.Runtime.InteropServices;
20 using System.Collections.Generic;
25 /// A class which manages Supplementary Services of the SIM.
27 /// <since_tizen> 4 </since_tizen>
30 private IntPtr _handle = IntPtr.Zero;
31 private Dictionary<IntPtr, Interop.Tapi.TapiResponseCallback> _callbackMap = new Dictionary<IntPtr, Interop.Tapi.TapiResponseCallback>();
32 private int _requestId = 0;
38 /// A constructor to instantiate Ss class using the Tapi handle.
40 /// <since_tizen> 4 </since_tizen>
41 /// <param name="handle">An instance of TapiHandle obtained from InitTapi in TapiManager API.</param>
42 /// <exception cref="ArgumentNullException">Thrown when handle is passed as null.</exception>
43 public Ss(TapiHandle handle)
47 throw new ArgumentNullException("Handle is null");
50 _handle = handle._handle;
54 /// Sends a request to activate/deactivate call barring.
56 /// <since_tizen> 4 </since_tizen>
57 /// <param name="info">The information about call barring.</param>
58 /// <returns>A task containing an instance of SsBarringResponse which contains information about barring response.</returns>
59 /// <feature>http://tizen.org/feature/network.telephony</feature>
60 /// <privlevel>platform</privlevel>
61 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
62 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
63 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
64 /// <exception cref="ArgumentNullException">Thrown when barring info is passed as null.</exception>
65 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
66 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
67 public Task<SsBarringResponse> SsSetBarring(SsBarringInfo info)
69 TaskCompletionSource<SsBarringResponse> task = new TaskCompletionSource<SsBarringResponse>();
70 IntPtr id = (IntPtr)_requestId++;
71 _callbackMap[id] = (handle, result, data, key) =>
73 Task taskResult = new Task(() =>
75 if (result != (int)SsCause.Success)
77 Log.Error(TapiUtility.LogTag, "Error occurs during setting SS barring info: " + (SsCause)result);
78 task.SetException(new InvalidOperationException("Error occurs during setting SS barring info, " + (SsCause)result));
82 SsBarringResponseStruct response = Marshal.PtrToStructure<SsBarringResponseStruct>(data);
83 task.SetResult(SsStructConversions.ConvertBarringRspStruct(response));
87 _callbackMap.Remove(key);
92 throw new ArgumentNullException("Ss barring info is null");
95 SsBarringInfoStruct infoStruct = SsClassConversions.ConvertSsBarringInfo(info);
96 int ret = Interop.Tapi.Ss.SsSetBarring(_handle, ref infoStruct, _callbackMap[id], id);
97 if (ret != (int)TapiError.Success)
99 Log.Error(TapiUtility.LogTag, "Failed to set barring info, Error: " + (TapiError)ret);
100 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
107 /// Gets call barring status.
109 /// <since_tizen> 4 </since_tizen>
110 /// <param name="ssClass">The type of call.</param>
111 /// <param name="type">The barring type.</param>
112 /// <returns>A task containing information about barring response.</returns>
113 /// <feature>http://tizen.org/feature/network.telephony</feature>
114 /// <privilege>http://tizen.org/privilege/telephony</privilege>
115 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
116 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
117 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
118 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
119 public Task<SsBarringResponse> SsGetBarringStatus(SsClass ssClass, SsBarringType type)
121 TaskCompletionSource<SsBarringResponse> task = new TaskCompletionSource<SsBarringResponse>();
122 IntPtr id = (IntPtr)_requestId++;
123 _callbackMap[id] = (handle, result, data, key) =>
125 Task taskResult = new Task(() =>
127 if (result != (int)SsCause.Success)
129 Log.Error(TapiUtility.LogTag, "Error occurs in getting barring status: " + (SsCause)result);
130 task.SetException(new InvalidOperationException("Error occurs in getting barring status, " + (SsCause)result));
134 SsBarringResponseStruct response = Marshal.PtrToStructure<SsBarringResponseStruct>(data);
135 task.SetResult(SsStructConversions.ConvertBarringRspStruct(response));
139 _callbackMap.Remove(key);
142 int ret = Interop.Tapi.Ss.SsGetBarringStatus(_handle, ssClass, type, _callbackMap[id], id);
143 if (ret != (int)TapiError.Success)
145 Log.Error(TapiUtility.LogTag, "Failed to get barring status, Error: " + (TapiError)ret);
146 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
153 /// Allows changing of the barring password in the network.
155 /// <since_tizen> 4 </since_tizen>
156 /// <param name="oldPassword">The old password set for Barring in the Network.</param>
157 /// <param name="newPassword">The new password set for Barring in the Network.</param>
158 /// <param name="newPasswordAgain">The new password again.</param>
159 /// <returns>A task indicating whether the change of password is done or not.</returns>
160 /// <feature>http://tizen.org/feature/network.telephony</feature>
161 /// <privlevel>platform</privlevel>
162 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
163 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
164 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
165 /// <exception cref="ArgumentNullException">Thrown when any of the parameter is passed as null.</exception>
166 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
167 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
168 public Task<bool> SsChangeBarringPassword(string oldPassword, string newPassword, string newPasswordAgain)
170 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
171 IntPtr id = (IntPtr)_requestId++;
172 _callbackMap[id] = (handle, result, data, key) =>
174 Task taskResult = new Task(() =>
176 if (result != (int)SsCause.Success)
178 Log.Error(TapiUtility.LogTag, "Error occurs in changing barring password: " + (SsCause)result);
179 task.SetException(new InvalidOperationException("Error occurs in changing barring password, " + (SsCause)result));
183 task.SetResult(true);
187 _callbackMap.Remove(key);
190 if (oldPassword == null || newPassword == null || newPasswordAgain == null)
192 throw new ArgumentNullException("Old password/new password is null");
195 int ret = Interop.Tapi.Ss.SsChangeBarringPassword(_handle, oldPassword, newPassword, newPasswordAgain, _callbackMap[id], id);
196 if (ret != (int)TapiError.Success)
198 Log.Error(TapiUtility.LogTag, "Failed to change barring password, Error: " + (TapiError)ret);
199 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
206 /// Allows to set the (register/erase/activate/deactivate) call forwarding option at the network.
208 /// <since_tizen> 4 </since_tizen>
209 /// <param name="info">The Call forward information such as a forward mode, a forward type, and so on.</param>
210 /// <returns>A task containing information about SS forward response.</returns>
211 /// <feature>http://tizen.org/feature/network.telephony</feature>
212 /// <privlevel>platform</privlevel>
213 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
214 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
215 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
216 /// <exception cref="ArgumentNullException">Thrown when forward info is passed as null.</exception>
217 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
218 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
219 public Task<SsForwardResponse> SsSetForwardInfo(SsForwardInfo info)
221 TaskCompletionSource<SsForwardResponse> task = new TaskCompletionSource<SsForwardResponse>();
222 IntPtr id = (IntPtr)_requestId++;
223 _callbackMap[id] = (handle, result, data, key) =>
225 Task taskResult = new Task(() =>
227 if (result != (int)SsCause.Success)
229 Log.Error(TapiUtility.LogTag, "Error occurs in setting SS forward info: " + (SsCause)result);
230 task.SetException(new InvalidOperationException("Error occurs in setting SS forward info, " + (SsCause)result));
234 SsForwardResponseStruct response = Marshal.PtrToStructure<SsForwardResponseStruct>(data);
235 task.SetResult(SsStructConversions.ConvertForwardRspStruct(response));
239 _callbackMap.Remove(key);
244 throw new ArgumentNullException("Ss forward info is null");
247 SsForwardInfoStruct infoStruct = SsClassConversions.ConvertSsForwardInfo(info);
248 int ret = Interop.Tapi.Ss.SsSetForward(_handle, ref infoStruct, _callbackMap[id], id);
249 if (ret != (int)TapiError.Success)
251 Log.Error(TapiUtility.LogTag, "Failed to set forward info, Error: " + (TapiError)ret);
252 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
259 /// Provides an option to get the call forwarding status of different calls from the Network.
261 /// <since_tizen> 4 </since_tizen>
262 /// <param name="ssClass">The Forward call type.</param>
263 /// <param name="condition">The forward condition.</param>
264 /// <returns>A task containing SS forward response information.</returns>
265 /// <feature>http://tizen.org/feature/network.telephony</feature>
266 /// <privilege>http://tizen.org/privilege/telephony</privilege>
267 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
268 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
269 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
270 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
271 public Task<SsForwardResponse> SsGetForwardStatus(SsClass ssClass, SsForwardCondition condition)
273 TaskCompletionSource<SsForwardResponse> task = new TaskCompletionSource<SsForwardResponse>();
274 IntPtr id = (IntPtr)_requestId++;
275 _callbackMap[id] = (handle, result, data, key) =>
277 Task taskResult = new Task(() =>
279 if (result != (int)SsCause.Success)
281 Log.Error(TapiUtility.LogTag, "Error occurs in getting SS forward status: " + (SsCause)result);
282 task.SetException(new InvalidOperationException("Error occurs in getting SS forward status, " + (SsCause)result));
286 SsForwardResponseStruct response = Marshal.PtrToStructure<SsForwardResponseStruct>(data);
287 task.SetResult(SsStructConversions.ConvertForwardRspStruct(response));
291 _callbackMap.Remove(key);
294 int ret = Interop.Tapi.Ss.SsGetForwardStatus(_handle, ssClass, condition, _callbackMap[id], id);
295 if (ret != (int)TapiError.Success)
297 Log.Error(TapiUtility.LogTag, "Failed to get forward status, Error: " + (TapiError)ret);
298 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
305 /// Activates/deactivates the call waiting service.
307 /// <since_tizen> 4 </since_tizen>
308 /// <param name="info">The status of call-waiting service.</param>
309 /// <returns>A task containing SS waiting response information.</returns>
310 /// <feature>http://tizen.org/feature/network.telephony</feature>
311 /// <privlevel>platform</privlevel>
312 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
313 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
314 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
315 /// <exception cref="ArgumentNullException">Thrown when waiting info is passed as null.</exception>
316 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
317 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
318 public Task<SsWaitingResponse> SsSetWaitingInfo(SsWaitingInfo info)
320 TaskCompletionSource<SsWaitingResponse> task = new TaskCompletionSource<SsWaitingResponse>();
321 IntPtr id = (IntPtr)_requestId++;
322 _callbackMap[id] = (handle, result, data, key) =>
324 Task taskResult = new Task(() =>
326 if (result != (int)SsCause.Success)
328 Log.Error(TapiUtility.LogTag, "Error occurs in setting SS waiting info: " + (SsCause)result);
329 task.SetException(new InvalidOperationException("Error occurs in setting SS waiting info, " + (SsCause)result));
333 SsWaitingResponseStruct response = Marshal.PtrToStructure<SsWaitingResponseStruct>(data);
334 task.SetResult(SsStructConversions.ConvertWaitingRspStruct(response));
338 _callbackMap.Remove(key);
343 throw new ArgumentNullException("Ss waiting info is null");
346 SsWaitingInfoStruct infoStruct = SsClassConversions.ConvertSsWaitingInfo(info);
347 int ret = Interop.Tapi.Ss.SsSetWaiting(_handle, ref infoStruct, _callbackMap[id], id);
348 if (ret != (int)TapiError.Success)
350 Log.Error(TapiUtility.LogTag, "Failed to set waiting info, Error: " + (TapiError)ret);
351 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
358 /// Gets the status of the call waiting service.
360 /// <since_tizen> 4 </since_tizen>
361 /// <param name="ssClass">The call types.</param>
362 /// <returns>A task containing information about SS waiting response.</returns>
363 /// <feature>http://tizen.org/feature/network.telephony</feature>
364 /// <privilege>http://tizen.org/privilege/telephony</privilege>
365 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
366 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
367 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
368 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
369 public Task<SsWaitingResponse> SsGetWaitingInfo(SsClass ssClass)
371 TaskCompletionSource<SsWaitingResponse> task = new TaskCompletionSource<SsWaitingResponse>();
372 IntPtr id = (IntPtr)_requestId++;
373 _callbackMap[id] = (handle, result, data, key) =>
375 Task taskResult = new Task(() =>
377 if (result != (int)SsCause.Success)
379 Log.Error(TapiUtility.LogTag, "Error occurs in getting SS waiting info: " + (SsCause)result);
380 task.SetException(new InvalidOperationException("Error occurs in getting SS waiting info, " + (SsCause)result));
384 SsWaitingResponseStruct response = Marshal.PtrToStructure<SsWaitingResponseStruct>(data);
385 task.SetResult(SsStructConversions.ConvertWaitingRspStruct(response));
389 _callbackMap.Remove(key);
392 int ret = Interop.Tapi.Ss.SsGetWaitingStatus(_handle, ssClass, _callbackMap[id], id);
393 if (ret != (int)TapiError.Success)
395 Log.Error(TapiUtility.LogTag, "Failed to get waiting info, Error: " + (TapiError)ret);
396 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
403 /// Activates/deactivates the status of the calling line identity service.
405 /// <since_tizen> 4 </since_tizen>
406 /// <param name="type">The Cli service type.</param>
407 /// <param name="status">The Cli Status.</param>
408 /// <returns>A task indicating whether setting of CLI status is done or not.</returns>
409 /// <feature>http://tizen.org/feature/network.telephony</feature>
410 /// <privlevel>platform</privlevel>
411 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
412 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
413 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
414 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
415 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
416 public Task<bool> SsSetCliStatus(SsCliType type, SsCliStatus status)
418 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
419 IntPtr id = (IntPtr)_requestId++;
420 _callbackMap[id] = (handle, result, data, key) =>
422 Task taskResult = new Task(() =>
424 if (result != (int)SsCause.Success)
426 Log.Error(TapiUtility.LogTag, "Error occurs in setting SS CLI status: " + (SsCause)result);
427 task.SetException(new InvalidOperationException("Error occurs in setting SS CLI status, " + (SsCause)result));
431 task.SetResult(true);
435 _callbackMap.Remove(key);
438 int ret = Interop.Tapi.Ss.SsSetCliStatus(_handle, type, status, _callbackMap[id], id);
439 if (ret != (int)TapiError.Success)
441 Log.Error(TapiUtility.LogTag, "Failed to set SS CLI status, Error: " + (TapiError)ret);
442 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
449 /// Gets the status of the calling line identity service.
451 /// <since_tizen> 4 </since_tizen>
452 /// <param name="type">The Cli service type.</param>
453 /// <returns>A task containing SS CLI response information.</returns>
454 /// <feature>http://tizen.org/feature/network.telephony</feature>
455 /// <privilege>http://tizen.org/privilege/telephony</privilege>
456 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
457 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
458 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
459 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
460 public Task<SsCliResponse> SsGetCliStatus(SsCliType type)
462 TaskCompletionSource<SsCliResponse> task = new TaskCompletionSource<SsCliResponse>();
463 IntPtr id = (IntPtr)_requestId++;
464 _callbackMap[id] = (handle, result, data, key) =>
466 Task taskResult = new Task(() =>
468 if (result != (int)SsCause.Success)
470 Log.Error(TapiUtility.LogTag, "Error occurs in getting SS CLI status: " + (SsCause)result);
471 task.SetException(new InvalidOperationException("Error occurs in getting SS CLI status, " + (SsCause)result));
475 SsCliResponseStruct response = Marshal.PtrToStructure<SsCliResponseStruct>(data);
476 task.SetResult(SsStructConversions.ConvertSsCliResponseStruct(response));
480 _callbackMap.Remove(key);
483 int ret = Interop.Tapi.Ss.SsGetCliStatus(_handle, type, _callbackMap[id], id);
484 if (ret != (int)TapiError.Success)
486 Log.Error(TapiUtility.LogTag, "Failed to get CLI status, Error: " + (TapiError)ret);
487 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
494 /// Sends a USSD string or User response to the Network.
496 /// <since_tizen> 4 </since_tizen>
497 /// <param name="info">The data coding scheme used</param>
498 /// <returns>A task containing SS USSD response information.</returns>
499 /// <feature>http://tizen.org/feature/network.telephony</feature>
500 /// <privlevel>platform</privlevel>
501 /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
502 /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
503 /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
504 /// <exception cref="ArgumentNullException">Thrown when Ussd message info is passed as null.</exception>
505 /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
506 /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
507 public Task<SsUssdResponse> SsSendUssdRequest(SsUssdMsgInfo info)
509 TaskCompletionSource<SsUssdResponse> task = new TaskCompletionSource<SsUssdResponse>();
510 IntPtr id = (IntPtr)_requestId++;
511 _callbackMap[id] = (handle, result, data, key) =>
513 Task taskResult = new Task(() =>
515 if (result != (int)SsCause.Success)
517 Log.Error(TapiUtility.LogTag, "Error occurs in sending USSD request: " + (SsCause)result);
518 task.SetException(new InvalidOperationException("Error occurs in sending USSD request, " + (SsCause)result));
522 SsUssdResponseStruct response = Marshal.PtrToStructure<SsUssdResponseStruct>(data);
523 task.SetResult(SsStructConversions.ConvertSsUssdResponseStruct(response));
527 _callbackMap.Remove(key);
532 throw new ArgumentNullException("Ussd message info is null");
535 SsUssdMsgInfoStruct msgStruct = SsClassConversions.ConvertSsUssdMsgInfo(info);
536 int ret = Interop.Tapi.Ss.SsSendUssdRequest(_handle, ref msgStruct, _callbackMap[id], id);
537 if (ret != (int)TapiError.Success)
539 Log.Error(TapiUtility.LogTag, "Failed to send USSD request, Error: " + (TapiError)ret);
540 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");