[Tapi] Mark API Level as 4
[platform/core/csapi/tizenfx.git] / internal / src / Tizen.Tapi / Tizen.Tapi / Ss.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.Threading.Tasks;
19 using System.Runtime.InteropServices;
20 using System.Collections.Generic;
21
22 namespace Tizen.Tapi
23 {
24     /// <summary>
25     /// A class which manages Supplementary Services of the SIM.
26     /// </summary>
27     /// <since_tizen> 4 </since_tizen>
28     public class Ss
29     {
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;
33         private Ss()
34         {
35         }
36
37         /// <summary>
38         /// A constructor to instantiate Ss class using the Tapi handle.
39         /// </summary>
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)
44         {
45             if (handle == null)
46             {
47                 throw new ArgumentNullException("Handle is null");
48             }
49
50             _handle = handle._handle;
51         }
52
53         /// <summary>
54         /// Sends a request to activate/deactivate call barring.
55         /// </summary>
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)
68         {
69             TaskCompletionSource<SsBarringResponse> task = new TaskCompletionSource<SsBarringResponse>();
70             IntPtr id = (IntPtr)_requestId++;
71             _callbackMap[id] = (handle, result, data, key) =>
72             {
73                 Task taskResult = new Task(() =>
74                 {
75                     if (result != (int)SsCause.Success)
76                     {
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));
79                         return;
80                     }
81
82                     SsBarringResponseStruct response = Marshal.PtrToStructure<SsBarringResponseStruct>(data);
83                     task.SetResult(SsStructConversions.ConvertBarringRspStruct(response));
84                 });
85                 taskResult.Start();
86                 taskResult.Wait();
87                 _callbackMap.Remove(key);
88             };
89
90             if (info == null)
91             {
92                 throw new ArgumentNullException("Ss barring info is null");
93             }
94
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)
98             {
99                 Log.Error(TapiUtility.LogTag, "Failed to set barring info, Error: " + (TapiError)ret);
100                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
101             }
102
103             return task.Task;
104         }
105
106         /// <summary>
107         /// Gets call barring status.
108         /// </summary>
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)
120         {
121             TaskCompletionSource<SsBarringResponse> task = new TaskCompletionSource<SsBarringResponse>();
122             IntPtr id = (IntPtr)_requestId++;
123             _callbackMap[id] = (handle, result, data, key) =>
124             {
125                 Task taskResult = new Task(() =>
126                 {
127                     if (result != (int)SsCause.Success)
128                     {
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));
131                         return;
132                     }
133
134                     SsBarringResponseStruct response = Marshal.PtrToStructure<SsBarringResponseStruct>(data);
135                     task.SetResult(SsStructConversions.ConvertBarringRspStruct(response));
136                 });
137                 taskResult.Start();
138                 taskResult.Wait();
139                 _callbackMap.Remove(key);
140             };
141
142             int ret = Interop.Tapi.Ss.SsGetBarringStatus(_handle, ssClass, type, _callbackMap[id], id);
143             if (ret != (int)TapiError.Success)
144             {
145                 Log.Error(TapiUtility.LogTag, "Failed to get barring status, Error: " + (TapiError)ret);
146                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
147             }
148
149             return task.Task;
150         }
151
152         /// <summary>
153         /// Allows changing of the barring password in the network.
154         /// </summary>
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)
169         {
170             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
171             IntPtr id = (IntPtr)_requestId++;
172             _callbackMap[id] = (handle, result, data, key) =>
173             {
174                 Task taskResult = new Task(() =>
175                 {
176                     if (result != (int)SsCause.Success)
177                     {
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));
180                         return;
181                     }
182
183                     task.SetResult(true);
184                 });
185                 taskResult.Start();
186                 taskResult.Wait();
187                 _callbackMap.Remove(key);
188             };
189
190             if (oldPassword == null || newPassword == null || newPasswordAgain == null)
191             {
192                 throw new ArgumentNullException("Old password/new password is null");
193             }
194
195             int ret = Interop.Tapi.Ss.SsChangeBarringPassword(_handle, oldPassword, newPassword, newPasswordAgain, _callbackMap[id], id);
196             if (ret != (int)TapiError.Success)
197             {
198                 Log.Error(TapiUtility.LogTag, "Failed to change barring password, Error: " + (TapiError)ret);
199                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
200             }
201
202             return task.Task;
203         }
204
205         /// <summary>
206         /// Allows to set the (register/erase/activate/deactivate) call forwarding option at the network.
207         /// </summary>
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)
220         {
221             TaskCompletionSource<SsForwardResponse> task = new TaskCompletionSource<SsForwardResponse>();
222             IntPtr id = (IntPtr)_requestId++;
223             _callbackMap[id] = (handle, result, data, key) =>
224             {
225                 Task taskResult = new Task(() =>
226                 {
227                     if (result != (int)SsCause.Success)
228                     {
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));
231                         return;
232                     }
233
234                     SsForwardResponseStruct response = Marshal.PtrToStructure<SsForwardResponseStruct>(data);
235                     task.SetResult(SsStructConversions.ConvertForwardRspStruct(response));
236                 });
237                 taskResult.Start();
238                 taskResult.Wait();
239                 _callbackMap.Remove(key);
240             };
241
242             if (info == null)
243             {
244                 throw new ArgumentNullException("Ss forward info is null");
245             }
246
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)
250             {
251                 Log.Error(TapiUtility.LogTag, "Failed to set forward info, Error: " + (TapiError)ret);
252                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
253             }
254
255             return task.Task;
256         }
257
258         /// <summary>
259         /// Provides an option to get the call forwarding status of different calls from the Network.
260         /// </summary>
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)
272         {
273             TaskCompletionSource<SsForwardResponse> task = new TaskCompletionSource<SsForwardResponse>();
274             IntPtr id = (IntPtr)_requestId++;
275             _callbackMap[id] = (handle, result, data, key) =>
276             {
277                 Task taskResult = new Task(() =>
278                 {
279                     if (result != (int)SsCause.Success)
280                     {
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));
283                         return;
284                     }
285
286                     SsForwardResponseStruct response = Marshal.PtrToStructure<SsForwardResponseStruct>(data);
287                     task.SetResult(SsStructConversions.ConvertForwardRspStruct(response));
288                 });
289                 taskResult.Start();
290                 taskResult.Wait();
291                 _callbackMap.Remove(key);
292             };
293
294             int ret = Interop.Tapi.Ss.SsGetForwardStatus(_handle, ssClass, condition, _callbackMap[id], id);
295             if (ret != (int)TapiError.Success)
296             {
297                 Log.Error(TapiUtility.LogTag, "Failed to get forward status, Error: " + (TapiError)ret);
298                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
299             }
300
301             return task.Task;
302         }
303
304         /// <summary>
305         /// Activates/deactivates the call waiting service.
306         /// </summary>
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)
319         {
320             TaskCompletionSource<SsWaitingResponse> task = new TaskCompletionSource<SsWaitingResponse>();
321             IntPtr id = (IntPtr)_requestId++;
322             _callbackMap[id] = (handle, result, data, key) =>
323             {
324                 Task taskResult = new Task(() =>
325                 {
326                     if (result != (int)SsCause.Success)
327                     {
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));
330                         return;
331                     }
332
333                     SsWaitingResponseStruct response = Marshal.PtrToStructure<SsWaitingResponseStruct>(data);
334                     task.SetResult(SsStructConversions.ConvertWaitingRspStruct(response));
335                 });
336                 taskResult.Start();
337                 taskResult.Wait();
338                 _callbackMap.Remove(key);
339             };
340
341             if (info == null)
342             {
343                 throw new ArgumentNullException("Ss waiting info is null");
344             }
345
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)
349             {
350                 Log.Error(TapiUtility.LogTag, "Failed to set waiting info, Error: " + (TapiError)ret);
351                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
352             }
353
354             return task.Task;
355         }
356
357         /// <summary>
358         /// Gets the status of the call waiting service.
359         /// </summary>
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)
370         {
371             TaskCompletionSource<SsWaitingResponse> task = new TaskCompletionSource<SsWaitingResponse>();
372             IntPtr id = (IntPtr)_requestId++;
373             _callbackMap[id] = (handle, result, data, key) =>
374             {
375                 Task taskResult = new Task(() =>
376                 {
377                     if (result != (int)SsCause.Success)
378                     {
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));
381                         return;
382                     }
383
384                     SsWaitingResponseStruct response = Marshal.PtrToStructure<SsWaitingResponseStruct>(data);
385                     task.SetResult(SsStructConversions.ConvertWaitingRspStruct(response));
386                 });
387                 taskResult.Start();
388                 taskResult.Wait();
389                 _callbackMap.Remove(key);
390             };
391
392             int ret = Interop.Tapi.Ss.SsGetWaitingStatus(_handle, ssClass, _callbackMap[id], id);
393             if (ret != (int)TapiError.Success)
394             {
395                 Log.Error(TapiUtility.LogTag, "Failed to get waiting info, Error: " + (TapiError)ret);
396                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
397             }
398
399             return task.Task;
400         }
401
402         /// <summary>
403         /// Activates/deactivates the status of the calling line identity service.
404         /// </summary>
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)
417         {
418             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
419             IntPtr id = (IntPtr)_requestId++;
420             _callbackMap[id] = (handle, result, data, key) =>
421             {
422                 Task taskResult = new Task(() =>
423                 {
424                     if (result != (int)SsCause.Success)
425                     {
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));
428                         return;
429                     }
430
431                     task.SetResult(true);
432                 });
433                 taskResult.Start();
434                 taskResult.Wait();
435                 _callbackMap.Remove(key);
436             };
437
438             int ret = Interop.Tapi.Ss.SsSetCliStatus(_handle, type, status, _callbackMap[id], id);
439             if (ret != (int)TapiError.Success)
440             {
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");
443             }
444
445             return task.Task;
446         }
447
448         /// <summary>
449         /// Gets the status of the calling line identity service.
450         /// </summary>
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)
461         {
462             TaskCompletionSource<SsCliResponse> task = new TaskCompletionSource<SsCliResponse>();
463             IntPtr id = (IntPtr)_requestId++;
464             _callbackMap[id] = (handle, result, data, key) =>
465             {
466                 Task taskResult = new Task(() =>
467                 {
468                     if (result != (int)SsCause.Success)
469                     {
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));
472                         return;
473                     }
474
475                     SsCliResponseStruct response = Marshal.PtrToStructure<SsCliResponseStruct>(data);
476                     task.SetResult(SsStructConversions.ConvertSsCliResponseStruct(response));
477                 });
478                 taskResult.Start();
479                 taskResult.Wait();
480                 _callbackMap.Remove(key);
481             };
482
483             int ret = Interop.Tapi.Ss.SsGetCliStatus(_handle, type, _callbackMap[id], id);
484             if (ret != (int)TapiError.Success)
485             {
486                 Log.Error(TapiUtility.LogTag, "Failed to get CLI status, Error: " + (TapiError)ret);
487                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
488             }
489
490             return task.Task;
491         }
492
493         /// <summary>
494         /// Sends a USSD string or User response to the Network.
495         /// </summary>
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)
508         {
509             TaskCompletionSource<SsUssdResponse> task = new TaskCompletionSource<SsUssdResponse>();
510             IntPtr id = (IntPtr)_requestId++;
511             _callbackMap[id] = (handle, result, data, key) =>
512             {
513                 Task taskResult = new Task(() =>
514                 {
515                     if (result != (int)SsCause.Success)
516                     {
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));
519                         return;
520                     }
521
522                     SsUssdResponseStruct response = Marshal.PtrToStructure<SsUssdResponseStruct>(data);
523                     task.SetResult(SsStructConversions.ConvertSsUssdResponseStruct(response));
524                 });
525                 taskResult.Start();
526                 taskResult.Wait();
527                 _callbackMap.Remove(key);
528             };
529
530             if (info == null)
531             {
532                 throw new ArgumentNullException("Ussd message info is null");
533             }
534
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)
538             {
539                 Log.Error(TapiUtility.LogTag, "Failed to send USSD request, Error: " + (TapiError)ret);
540                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
541             }
542
543             return task.Task;
544         }
545     }
546 }