Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / 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     public class Ss
28     {
29         private IntPtr _handle = IntPtr.Zero;
30         private Dictionary<IntPtr, Interop.Tapi.TapiResponseCallback> _callbackMap = new Dictionary<IntPtr, Interop.Tapi.TapiResponseCallback>();
31         private int _requestId = 0;
32         private Ss()
33         {
34         }
35
36         /// <summary>
37         /// A constructor to instantiate Ss class using the Tapi handle.
38         /// </summary>
39         /// <param name="handle">An instance of TapiHandle obtained from InitTapi in TapiManager API.</param>
40         /// <exception cref="ArgumentNullException">Thrown when handle is passed as null.</exception>
41         public Ss(TapiHandle handle)
42         {
43             if (handle == null)
44             {
45                 throw new ArgumentNullException("Handle is null");
46             }
47
48             _handle = handle._handle;
49         }
50
51         /// <summary>
52         /// Sends a request to activate/deactivate call barring.
53         /// </summary>
54         /// <param name="info">The information about call barring.</param>
55         /// <returns>A task containing an instance of SsBarringResponse which contains information about barring response.</returns>
56         /// <feature>http://tizen.org/feature/network.telephony</feature>
57         /// <privlevel>platform</privlevel>
58         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
59         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
60         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
61         /// <exception cref="ArgumentNullException">Thrown when barring info is passed as null.</exception>
62         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
63         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
64         public Task<SsBarringResponse> SsSetBarring(SsBarringInfo info)
65         {
66             TaskCompletionSource<SsBarringResponse> task = new TaskCompletionSource<SsBarringResponse>();
67             IntPtr id = (IntPtr)_requestId++;
68             _callbackMap[id] = (handle, result, data, key) =>
69             {
70                 Task taskResult = new Task(() =>
71                 {
72                     if (result != (int)SsCause.Success)
73                     {
74                         Log.Error(TapiUtility.LogTag, "Error occurs during setting SS barring info: " + (SsCause)result);
75                         task.SetException(new InvalidOperationException("Error occurs during setting SS barring info, " + (SsCause)result));
76                         return;
77                     }
78
79                     SsBarringResponseStruct response = Marshal.PtrToStructure<SsBarringResponseStruct>(data);
80                     task.SetResult(SsStructConversions.ConvertBarringRspStruct(response));
81                 });
82                 taskResult.Start();
83                 taskResult.Wait();
84                 _callbackMap.Remove(key);
85             };
86
87             if (info == null)
88             {
89                 throw new ArgumentNullException("Ss barring info is null");
90             }
91
92             SsBarringInfoStruct infoStruct = SsClassConversions.ConvertSsBarringInfo(info);
93             int ret = Interop.Tapi.Ss.SsSetBarring(_handle, ref infoStruct, _callbackMap[id], id);
94             if (ret != (int)TapiError.Success)
95             {
96                 Log.Error(TapiUtility.LogTag, "Failed to set barring info, Error: " + (TapiError)ret);
97                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
98             }
99
100             return task.Task;
101         }
102
103         /// <summary>
104         /// Gets call barring status.
105         /// </summary>
106         /// <param name="ssClass">The type of call.</param>
107         /// <param name="type">The barring type.</param>
108         /// <returns>A task containing information about barring response.</returns>
109         /// <feature>http://tizen.org/feature/network.telephony</feature>
110         /// <privilege>http://tizen.org/privilege/telephony</privilege>
111         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
112         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
113         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
114         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
115         public Task<SsBarringResponse> SsGetBarringStatus(SsClass ssClass, SsBarringType type)
116         {
117             TaskCompletionSource<SsBarringResponse> task = new TaskCompletionSource<SsBarringResponse>();
118             IntPtr id = (IntPtr)_requestId++;
119             _callbackMap[id] = (handle, result, data, key) =>
120             {
121                 Task taskResult = new Task(() =>
122                 {
123                     if (result != (int)SsCause.Success)
124                     {
125                         Log.Error(TapiUtility.LogTag, "Error occurs in getting barring status: " + (SsCause)result);
126                         task.SetException(new InvalidOperationException("Error occurs in getting barring status, " + (SsCause)result));
127                         return;
128                     }
129
130                     SsBarringResponseStruct response = Marshal.PtrToStructure<SsBarringResponseStruct>(data);
131                     task.SetResult(SsStructConversions.ConvertBarringRspStruct(response));
132                 });
133                 taskResult.Start();
134                 taskResult.Wait();
135                 _callbackMap.Remove(key);
136             };
137
138             int ret = Interop.Tapi.Ss.SsGetBarringStatus(_handle, ssClass, type, _callbackMap[id], id);
139             if (ret != (int)TapiError.Success)
140             {
141                 Log.Error(TapiUtility.LogTag, "Failed to get barring status, Error: " + (TapiError)ret);
142                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
143             }
144
145             return task.Task;
146         }
147
148         /// <summary>
149         /// Allows changing of the barring password in the network.
150         /// </summary>
151         /// <param name="oldPassword">The old password set for Barring in the Network.</param>
152         /// <param name="newPassword">The new password set for Barring in the Network.</param>
153         /// <param name="newPasswordAgain">The new password again.</param>
154         /// <returns>A task indicating whether the change of password is done or not.</returns>
155         /// <feature>http://tizen.org/feature/network.telephony</feature>
156         /// <privlevel>platform</privlevel>
157         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
158         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
159         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
160         /// <exception cref="ArgumentNullException">Thrown when any of the parameter is passed as null.</exception>
161         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
162         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
163         public Task<bool> SsChangeBarringPassword(string oldPassword, string newPassword, string newPasswordAgain)
164         {
165             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
166             IntPtr id = (IntPtr)_requestId++;
167             _callbackMap[id] = (handle, result, data, key) =>
168             {
169                 Task taskResult = new Task(() =>
170                 {
171                     if (result != (int)SsCause.Success)
172                     {
173                         Log.Error(TapiUtility.LogTag, "Error occurs in changing barring password: " + (SsCause)result);
174                         task.SetException(new InvalidOperationException("Error occurs in changing barring password, " + (SsCause)result));
175                         return;
176                     }
177
178                     task.SetResult(true);
179                 });
180                 taskResult.Start();
181                 taskResult.Wait();
182                 _callbackMap.Remove(key);
183             };
184
185             if (oldPassword == null || newPassword == null || newPasswordAgain == null)
186             {
187                 throw new ArgumentNullException("Old password/new password is null");
188             }
189
190             int ret = Interop.Tapi.Ss.SsChangeBarringPassword(_handle, oldPassword, newPassword, newPasswordAgain, _callbackMap[id], id);
191             if (ret != (int)TapiError.Success)
192             {
193                 Log.Error(TapiUtility.LogTag, "Failed to change barring password, Error: " + (TapiError)ret);
194                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
195             }
196
197             return task.Task;
198         }
199
200         /// <summary>
201         /// Allows to set the (register/erase/activate/deactivate) call forwarding option at the network.
202         /// </summary>
203         /// <param name="info">The Call forward information such as a forward mode, a forward type, and so on.</param>
204         /// <returns>A task containing information about SS forward response.</returns>
205         /// <feature>http://tizen.org/feature/network.telephony</feature>
206         /// <privlevel>platform</privlevel>
207         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
208         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
209         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
210         /// <exception cref="ArgumentNullException">Thrown when forward info is passed as null.</exception>
211         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
212         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
213         public Task<SsForwardResponse> SsSetForwardInfo(SsForwardInfo info)
214         {
215             TaskCompletionSource<SsForwardResponse> task = new TaskCompletionSource<SsForwardResponse>();
216             IntPtr id = (IntPtr)_requestId++;
217             _callbackMap[id] = (handle, result, data, key) =>
218             {
219                 Task taskResult = new Task(() =>
220                 {
221                     if (result != (int)SsCause.Success)
222                     {
223                         Log.Error(TapiUtility.LogTag, "Error occurs in setting SS forward info: " + (SsCause)result);
224                         task.SetException(new InvalidOperationException("Error occurs in setting SS forward info, " + (SsCause)result));
225                         return;
226                     }
227
228                     SsForwardResponseStruct response = Marshal.PtrToStructure<SsForwardResponseStruct>(data);
229                     task.SetResult(SsStructConversions.ConvertForwardRspStruct(response));
230                 });
231                 taskResult.Start();
232                 taskResult.Wait();
233                 _callbackMap.Remove(key);
234             };
235
236             if (info == null)
237             {
238                 throw new ArgumentNullException("Ss forward info is null");
239             }
240
241             SsForwardInfoStruct infoStruct = SsClassConversions.ConvertSsForwardInfo(info);
242             int ret = Interop.Tapi.Ss.SsSetForward(_handle, ref infoStruct, _callbackMap[id], id);
243             if (ret != (int)TapiError.Success)
244             {
245                 Log.Error(TapiUtility.LogTag, "Failed to set forward info, Error: " + (TapiError)ret);
246                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
247             }
248
249             return task.Task;
250         }
251
252         /// <summary>
253         /// Provides an option to get the call forwarding status of different calls from the Network.
254         /// </summary>
255         /// <param name="ssClass">The Forward call type.</param>
256         /// <param name="condition">The forward condition.</param>
257         /// <returns>A task containing SS forward response information.</returns>
258         /// <feature>http://tizen.org/feature/network.telephony</feature>
259         /// <privilege>http://tizen.org/privilege/telephony</privilege>
260         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
261         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
262         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
263         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
264         public Task<SsForwardResponse> SsGetForwardStatus(SsClass ssClass, SsForwardCondition condition)
265         {
266             TaskCompletionSource<SsForwardResponse> task = new TaskCompletionSource<SsForwardResponse>();
267             IntPtr id = (IntPtr)_requestId++;
268             _callbackMap[id] = (handle, result, data, key) =>
269             {
270                 Task taskResult = new Task(() =>
271                 {
272                     if (result != (int)SsCause.Success)
273                     {
274                         Log.Error(TapiUtility.LogTag, "Error occurs in getting SS forward status: " + (SsCause)result);
275                         task.SetException(new InvalidOperationException("Error occurs in getting SS forward status, " + (SsCause)result));
276                         return;
277                     }
278
279                     SsForwardResponseStruct response = Marshal.PtrToStructure<SsForwardResponseStruct>(data);
280                     task.SetResult(SsStructConversions.ConvertForwardRspStruct(response));
281                 });
282                 taskResult.Start();
283                 taskResult.Wait();
284                 _callbackMap.Remove(key);
285             };
286
287             int ret = Interop.Tapi.Ss.SsGetForwardStatus(_handle, ssClass, condition, _callbackMap[id], id);
288             if (ret != (int)TapiError.Success)
289             {
290                 Log.Error(TapiUtility.LogTag, "Failed to get forward status, Error: " + (TapiError)ret);
291                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
292             }
293
294             return task.Task;
295         }
296
297         /// <summary>
298         /// Activates/deactivates the call waiting service.
299         /// </summary>
300         /// <param name="info">The status of call-waiting service.</param>
301         /// <returns>A task containing SS waiting response information.</returns>
302         /// <feature>http://tizen.org/feature/network.telephony</feature>
303         /// <privlevel>platform</privlevel>
304         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
305         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
306         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
307         /// <exception cref="ArgumentNullException">Thrown when waiting info is passed as null.</exception>
308         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
309         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
310         public Task<SsWaitingResponse> SsSetWaitingInfo(SsWaitingInfo info)
311         {
312             TaskCompletionSource<SsWaitingResponse> task = new TaskCompletionSource<SsWaitingResponse>();
313             IntPtr id = (IntPtr)_requestId++;
314             _callbackMap[id] = (handle, result, data, key) =>
315             {
316                 Task taskResult = new Task(() =>
317                 {
318                     if (result != (int)SsCause.Success)
319                     {
320                         Log.Error(TapiUtility.LogTag, "Error occurs in setting SS waiting info: " + (SsCause)result);
321                         task.SetException(new InvalidOperationException("Error occurs in setting SS waiting info, " + (SsCause)result));
322                         return;
323                     }
324
325                     SsWaitingResponseStruct response = Marshal.PtrToStructure<SsWaitingResponseStruct>(data);
326                     task.SetResult(SsStructConversions.ConvertWaitingRspStruct(response));
327                 });
328                 taskResult.Start();
329                 taskResult.Wait();
330                 _callbackMap.Remove(key);
331             };
332
333             if (info == null)
334             {
335                 throw new ArgumentNullException("Ss waiting info is null");
336             }
337
338             SsWaitingInfoStruct infoStruct = SsClassConversions.ConvertSsWaitingInfo(info);
339             int ret = Interop.Tapi.Ss.SsSetWaiting(_handle, ref infoStruct, _callbackMap[id], id);
340             if (ret != (int)TapiError.Success)
341             {
342                 Log.Error(TapiUtility.LogTag, "Failed to set waiting info, Error: " + (TapiError)ret);
343                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
344             }
345
346             return task.Task;
347         }
348
349         /// <summary>
350         /// Gets the status of the call waiting service.
351         /// </summary>
352         /// <param name="ssClass">The call types.</param>
353         /// <returns>A task containing information about SS waiting response.</returns>
354         /// <feature>http://tizen.org/feature/network.telephony</feature>
355         /// <privilege>http://tizen.org/privilege/telephony</privilege>
356         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
357         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
358         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
359         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
360         public Task<SsWaitingResponse> SsGetWaitingInfo(SsClass ssClass)
361         {
362             TaskCompletionSource<SsWaitingResponse> task = new TaskCompletionSource<SsWaitingResponse>();
363             IntPtr id = (IntPtr)_requestId++;
364             _callbackMap[id] = (handle, result, data, key) =>
365             {
366                 Task taskResult = new Task(() =>
367                 {
368                     if (result != (int)SsCause.Success)
369                     {
370                         Log.Error(TapiUtility.LogTag, "Error occurs in getting SS waiting info: " + (SsCause)result);
371                         task.SetException(new InvalidOperationException("Error occurs in getting SS waiting info, " + (SsCause)result));
372                         return;
373                     }
374
375                     SsWaitingResponseStruct response = Marshal.PtrToStructure<SsWaitingResponseStruct>(data);
376                     task.SetResult(SsStructConversions.ConvertWaitingRspStruct(response));
377                 });
378                 taskResult.Start();
379                 taskResult.Wait();
380                 _callbackMap.Remove(key);
381             };
382
383             int ret = Interop.Tapi.Ss.SsGetWaitingStatus(_handle, ssClass, _callbackMap[id], id);
384             if (ret != (int)TapiError.Success)
385             {
386                 Log.Error(TapiUtility.LogTag, "Failed to get waiting info, Error: " + (TapiError)ret);
387                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
388             }
389
390             return task.Task;
391         }
392
393         /// <summary>
394         /// Activates/deactivates the status of the calling line identity service.
395         /// </summary>
396         /// <param name="type">The Cli service type.</param>
397         /// <param name="status">The Cli Status.</param>
398         /// <returns>A task indicating whether setting of CLI status is done or not.</returns>
399         /// <feature>http://tizen.org/feature/network.telephony</feature>
400         /// <privlevel>platform</privlevel>
401         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
402         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
403         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
404         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
405         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
406         public Task<bool> SsSetCliStatus(SsCliType type, SsCliStatus status)
407         {
408             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
409             IntPtr id = (IntPtr)_requestId++;
410             _callbackMap[id] = (handle, result, data, key) =>
411             {
412                 Task taskResult = new Task(() =>
413                 {
414                     if (result != (int)SsCause.Success)
415                     {
416                         Log.Error(TapiUtility.LogTag, "Error occurs in setting SS CLI status: " + (SsCause)result);
417                         task.SetException(new InvalidOperationException("Error occurs in setting SS CLI status, " + (SsCause)result));
418                         return;
419                     }
420
421                     task.SetResult(true);
422                 });
423                 taskResult.Start();
424                 taskResult.Wait();
425                 _callbackMap.Remove(key);
426             };
427
428             int ret = Interop.Tapi.Ss.SsSetCliStatus(_handle, type, status, _callbackMap[id], id);
429             if (ret != (int)TapiError.Success)
430             {
431                 Log.Error(TapiUtility.LogTag, "Failed to set SS CLI status, Error: " + (TapiError)ret);
432                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
433             }
434
435             return task.Task;
436         }
437
438         /// <summary>
439         /// Gets the status of the calling line identity service.
440         /// </summary>
441         /// <param name="type">The Cli service type.</param>
442         /// <returns>A task containing SS CLI response information.</returns>
443         /// <feature>http://tizen.org/feature/network.telephony</feature>
444         /// <privilege>http://tizen.org/privilege/telephony</privilege>
445         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
446         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
447         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
448         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
449         public Task<SsCliResponse> SsGetCliStatus(SsCliType type)
450         {
451             TaskCompletionSource<SsCliResponse> task = new TaskCompletionSource<SsCliResponse>();
452             IntPtr id = (IntPtr)_requestId++;
453             _callbackMap[id] = (handle, result, data, key) =>
454             {
455                 Task taskResult = new Task(() =>
456                 {
457                     if (result != (int)SsCause.Success)
458                     {
459                         Log.Error(TapiUtility.LogTag, "Error occurs in getting SS CLI status: " + (SsCause)result);
460                         task.SetException(new InvalidOperationException("Error occurs in getting SS CLI status, " + (SsCause)result));
461                         return;
462                     }
463
464                     SsCliResponseStruct response = Marshal.PtrToStructure<SsCliResponseStruct>(data);
465                     task.SetResult(SsStructConversions.ConvertSsCliResponseStruct(response));
466                 });
467                 taskResult.Start();
468                 taskResult.Wait();
469                 _callbackMap.Remove(key);
470             };
471
472             int ret = Interop.Tapi.Ss.SsGetCliStatus(_handle, type, _callbackMap[id], id);
473             if (ret != (int)TapiError.Success)
474             {
475                 Log.Error(TapiUtility.LogTag, "Failed to get CLI status, Error: " + (TapiError)ret);
476                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
477             }
478
479             return task.Task;
480         }
481
482         /// <summary>
483         /// Sends a USSD string or User response to the Network.
484         /// </summary>
485         /// <param name="info">The data coding scheme used</param>
486         /// <returns>A task containing SS USSD response information.</returns>
487         /// <feature>http://tizen.org/feature/network.telephony</feature>
488         /// <privlevel>platform</privlevel>
489         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
490         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
491         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
492         /// <exception cref="ArgumentNullException">Thrown when Ussd message info is passed as null.</exception>
493         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
494         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
495         public Task<SsUssdResponse> SsSendUssdRequest(SsUssdMsgInfo info)
496         {
497             TaskCompletionSource<SsUssdResponse> task = new TaskCompletionSource<SsUssdResponse>();
498             IntPtr id = (IntPtr)_requestId++;
499             _callbackMap[id] = (handle, result, data, key) =>
500             {
501                 Task taskResult = new Task(() =>
502                 {
503                     if (result != (int)SsCause.Success)
504                     {
505                         Log.Error(TapiUtility.LogTag, "Error occurs in sending USSD request: " + (SsCause)result);
506                         task.SetException(new InvalidOperationException("Error occurs in sending USSD request, " + (SsCause)result));
507                         return;
508                     }
509
510                     SsUssdResponseStruct response = Marshal.PtrToStructure<SsUssdResponseStruct>(data);
511                     task.SetResult(SsStructConversions.ConvertSsUssdResponseStruct(response));
512                 });
513                 taskResult.Start();
514                 taskResult.Wait();
515                 _callbackMap.Remove(key);
516             };
517
518             if (info == null)
519             {
520                 throw new ArgumentNullException("Ussd message info is null");
521             }
522
523             SsUssdMsgInfoStruct msgStruct = SsClassConversions.ConvertSsUssdMsgInfo(info);
524             int ret = Interop.Tapi.Ss.SsSendUssdRequest(_handle, ref msgStruct, _callbackMap[id], id);
525             if (ret != (int)TapiError.Success)
526             {
527                 Log.Error(TapiUtility.LogTag, "Failed to send USSD request, Error: " + (TapiError)ret);
528                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
529             }
530
531             return task.Task;
532         }
533     }
534 }