Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Tapi / Tizen.Tapi / Sim.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 using System.Text;
22
23 namespace Tizen.Tapi
24 {
25     /// <summary>
26     /// A class which manages SIM card services.
27     /// </summary>
28     public class Sim
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 Sim()
34         {
35         }
36
37         /// <summary>
38         /// A constructor to instantiate Sim class using the Tapi handle.
39         /// </summary>
40         /// <param name="handle">An instance of TapiHandle obtained from InitTapi in TapiManager API.</param>
41         /// <exception cref="ArgumentNullException">Thrown when handle is passed as null.</exception>
42         public Sim(TapiHandle handle)
43         {
44             if (handle == null)
45             {
46                 throw new ArgumentNullException("Handle is null");
47             }
48
49             _handle = handle._handle;
50         }
51
52         /// <summary>
53         /// Gets SIM card initialization status and SIM card identification.
54         /// </summary>
55         /// <value>An instance of SimInitInfo class in case of success. Null in case of failure.</value>
56         public SimInitInfo InitInfo
57         {
58             get
59             {
60                 SimCardStatus status;
61                 int isCardChanged;
62                 int ret = Interop.Tapi.Sim.SimGetInitInfo(_handle, out status, out isCardChanged);
63                 if (ret != (int)TapiError.Success)
64                 {
65                     Log.Error(TapiUtility.LogTag, "Failed to get SIM init info, Error: " + (TapiError)ret);
66                     return null;
67                 }
68
69                 SimInitInfo initInfo = new SimInitInfo();
70                 initInfo.SimStatus = status;
71                 if (isCardChanged == 1)
72                 {
73                     initInfo.IsChanged = true;
74                 }
75
76                 else if (isCardChanged == 0)
77                 {
78                     initInfo.IsChanged = false;
79                 }
80
81                 return initInfo;
82             }
83         }
84
85         /// <summary>
86         /// Gets the card type (SIM/USIM).
87         /// </summary>
88         public SimCardType SimType
89         {
90             get
91             {
92                 SimCardType type;
93                 int ret = Interop.Tapi.Sim.SimGetType(_handle, out type);
94                 if (ret != (int)TapiError.Success)
95                 {
96                     Log.Error(TapiUtility.LogTag, "Failed to get SIM card type, Error: " + (TapiError)ret);
97                     return default(SimCardType);
98                 }
99
100                 return type;
101             }
102         }
103
104         /// <summary>
105         /// Gets SIM IMSI information.
106         /// </summary>
107         public SimImsiInfo Imsi
108         {
109             get
110             {
111                 SimImsiInfoStruct imsi;
112                 int ret = Interop.Tapi.Sim.SimGetImsi(_handle, out imsi);
113                 if (ret != (int)TapiError.Success)
114                 {
115                     Log.Error(TapiUtility.LogTag, "Failed to get SIM IMSI info, Error: " + (TapiError)ret);
116                     return null;
117                 }
118
119                 return SimStructConversions.ConvertSimImsiInfoStruct(imsi);
120             }
121         }
122
123         /// <summary>
124         /// Gets ECC(SIM) or UECC(USIM) data.
125         /// </summary>
126         public SimEccInfoList Ecc
127         {
128             get
129             {
130                 SimEccInfoListStruct eccInfo;
131                 int ret = Interop.Tapi.Sim.SimGetEcc(_handle, out eccInfo);
132                 if (ret != (int)TapiError.Success)
133                 {
134                     Log.Error(TapiUtility.LogTag, "Failed to get SIM ECC info, Error: " + (TapiError)ret);
135                     return null;
136                 }
137
138                 return SimStructConversions.ConvertSimEccInfoListStruct(eccInfo);
139             }
140         }
141
142         /// <summary>
143         /// Gets the list of application on UICC.
144         /// </summary>
145         /// <returns>A byte containing the masking value for SimAppType.</returns>
146         /// <feature>http://tizen.org/feature/network.telephony</feature>
147         /// <privilege>http://tizen.org/privilege/telephony</privilege>
148         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
149         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
150         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
151         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
152         public byte SimGetApplicationList()
153         {
154             byte appList;
155             int ret = Interop.Tapi.Sim.SimGetApplicationList(_handle, out appList);
156             if (ret != (int)TapiError.Success)
157             {
158                 Log.Error(TapiUtility.LogTag, "Failed to get list of applications, Error: " + (TapiError)ret);
159                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
160             }
161
162             return appList;
163         }
164
165         /// <summary>
166         /// Gets the unique identification number of the (U)ICC.
167         /// </summary>
168         /// <returns>A task containing ICCID information.</returns>
169         /// <feature>http://tizen.org/feature/network.telephony</feature>
170         /// <privilege>http://tizen.org/privilege/telephony</privilege>
171         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
172         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
173         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
174         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
175         public Task<SimIccIdInfo> SimGetIccId()
176         {
177             TaskCompletionSource<SimIccIdInfo> task = new TaskCompletionSource<SimIccIdInfo>();
178             IntPtr id = (IntPtr)_requestId++;
179             _callbackMap[id] = (handle, result, data, key) =>
180             {
181                 Task taskResult = new Task(() =>
182                 {
183                     if (result != (int)SimAccessResult.Success)
184                     {
185                         Log.Error(TapiUtility.LogTag, "Error occurs in getting ICCID info: " + (SimAccessResult)result);
186                         task.SetException(new InvalidOperationException("Error occurs in getting ICCID info, " + (SimAccessResult)result));
187                         return;
188                     }
189
190                     SimIccIdInfoStruct info = Marshal.PtrToStructure<SimIccIdInfoStruct>(data);
191                     task.SetResult(SimStructConversions.ConvertSimIccIdInfoStruct(info));
192                 });
193                 taskResult.Start();
194                 taskResult.Wait();
195                 _callbackMap.Remove(key);
196             };
197
198             int ret = Interop.Tapi.Sim.SimGetIccId(_handle, _callbackMap[id], id);
199             if (ret != (int)TapiError.Success)
200             {
201                 Log.Error(TapiUtility.LogTag, "Failed to get SIM ICCID info, Error: " + (TapiError)ret);
202                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
203             }
204
205             return task.Task;
206         }
207
208         /// <summary>
209         /// Gets language preference(indication) information.
210         /// </summary>
211         /// <returns>A task containing information about SIM language preference.</returns>
212         /// <feature>http://tizen.org/feature/network.telephony</feature>
213         /// <privilege>http://tizen.org/privilege/telephony</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="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
217         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
218         public Task<SimLanguagePreference> SimGetLanguagePreference()
219         {
220             TaskCompletionSource<SimLanguagePreference> task = new TaskCompletionSource<SimLanguagePreference>();
221             IntPtr id = (IntPtr)_requestId++;
222             _callbackMap[id] = (handle, result, data, key) =>
223             {
224                 Task taskResult = new Task(() =>
225                 {
226                     if (result != (int)SimAccessResult.Success)
227                     {
228                         Log.Error(TapiUtility.LogTag, "Error occurs in getting language preference: " + (SimAccessResult)result);
229                         task.SetException(new InvalidOperationException("Error occurs in getting language preference, " + (SimAccessResult)result));
230                         return;
231                     }
232
233                     task.SetResult((SimLanguagePreference)Marshal.ReadInt32(data));
234                 });
235                 taskResult.Start();
236                 taskResult.Wait();
237                 _callbackMap.Remove(key);
238             };
239
240             int ret = Interop.Tapi.Sim.SimGetLanguage(_handle, _callbackMap[id], id);
241             if (ret != (int)TapiError.Success)
242             {
243                 Log.Error(TapiUtility.LogTag, "Failed to get SIM language preference, Error: " + (TapiError)ret);
244                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
245             }
246
247             return task.Task;
248         }
249
250         /// <summary>
251         /// Updates language preference information to the SIM card.
252         /// </summary>
253         /// <param name="language">The language preference information.</param>
254         /// <returns>A task indicating whether setting of language preference is done or not.</returns>
255         /// <feature>http://tizen.org/feature/network.telephony</feature>
256         /// <privlevel>platform</privlevel>
257         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
258         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
259         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
260         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
261         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
262         public Task<bool> SimSetLanguagePreference(SimLanguagePreference language)
263         {
264             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
265             IntPtr id = (IntPtr)_requestId++;
266             _callbackMap[id] = (handle, result, data, key) =>
267             {
268                 Task taskResult = new Task(() =>
269                 {
270                     if (result != (int)SimAccessResult.Success)
271                     {
272                         Log.Error(TapiUtility.LogTag, "Error occurs in setting language preference: " + (SimAccessResult)result);
273                         task.SetException(new InvalidOperationException("Error occurs in setting language preference, " + (SimAccessResult)result));
274                         return;
275                     }
276
277                     task.SetResult(true);
278                 });
279                 taskResult.Start();
280                 taskResult.Wait();
281                 _callbackMap.Remove(key);
282             };
283
284             int ret = Interop.Tapi.Sim.SimSetLanguage(_handle, language, _callbackMap[id], id);
285             if (ret != (int)TapiError.Success)
286             {
287                 Log.Error(TapiUtility.LogTag, "Failed to set SIM language preference, Error: " + (TapiError)ret);
288                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
289             }
290
291             return task.Task;
292         }
293
294         /// <summary>
295         /// Gets SIM call forwarding indication related data(EF-CFIS and CPHS case).
296         /// </summary>
297         /// <returns>A task containing call forward response information.</returns>
298         /// <feature>http://tizen.org/feature/network.telephony</feature>
299         /// <privilege>http://tizen.org/privilege/telephony</privilege>
300         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
301         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
302         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
303         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
304         public Task<SimCallForwardResponse> SimGetCallForwardInfo()
305         {
306             TaskCompletionSource<SimCallForwardResponse> task = new TaskCompletionSource<SimCallForwardResponse>();
307             IntPtr id = (IntPtr)_requestId++;
308             _callbackMap[id] = (handle, result, data, key) =>
309             {
310                 Task taskResult = new Task(() =>
311                 {
312                     if (result != (int)SimAccessResult.Success)
313                     {
314                         Log.Error(TapiUtility.LogTag, "Error occurs in getting call forward info: " + (SimAccessResult)result);
315                         task.SetException(new InvalidOperationException("Error occurs in getting call forward info, " + (SimAccessResult)result));
316                         return;
317                     }
318
319                     SimCallForwardResponseStruct info = Marshal.PtrToStructure<SimCallForwardResponseStruct>(data);
320                     task.SetResult(SimStructConversions.ConvertSimCallForwardResponseStruct(info));
321                 });
322                 taskResult.Start();
323                 taskResult.Wait();
324                 _callbackMap.Remove(key);
325             };
326
327             int ret = Interop.Tapi.Sim.SimGetCallForwardingInfo(_handle, _callbackMap[id], id);
328             if (ret != (int)TapiError.Success)
329             {
330                 Log.Error(TapiUtility.LogTag, "Failed to get SIM call forward info, Error: " + (TapiError)ret);
331                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
332             }
333
334             return task.Task;
335         }
336
337         /// <summary>
338         /// Sets SIM call forwarding indication related data(EF-CFIS and CPHS case).
339         /// </summary>
340         /// <param name="request">The data requesting for call forwarding.</param>
341         /// <returns>A task indicating whether setting call forward info is done or not.</returns>
342         /// <feature>http://tizen.org/feature/network.telephony</feature>
343         /// <privlevel>platform</privlevel>
344         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
345         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
346         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
347         /// <exception cref="ArgumentNullException">Thrown when call forward request is passed as null.</exception>
348         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
349         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
350         public Task<bool> SimSetCallForwardInfo(SimCallForwardRequest request)
351         {
352             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
353             IntPtr id = (IntPtr)_requestId++;
354             _callbackMap[id] = (handle, result, data, key) =>
355             {
356                 Task taskResult = new Task(() =>
357                 {
358                     if (result != (int)SimAccessResult.Success)
359                     {
360                         Log.Error(TapiUtility.LogTag, "Error occurs in setting call forward info: " + (SimAccessResult)result);
361                         task.SetException(new InvalidOperationException("Error occurs in setting call forward info, " + (SimAccessResult)result));
362                         return;
363                     }
364
365                     task.SetResult(true);
366                 });
367                 taskResult.Start();
368                 taskResult.Wait();
369                 _callbackMap.Remove(key);
370             };
371
372             if (request == null)
373             {
374                 throw new ArgumentNullException("SIM call forward request is null");
375             }
376
377             SimCallForwardRequestStruct requestStruct = SimClassConversions.ConvertSimCallForwardRequest(request);
378             int ret = Interop.Tapi.Sim.SimSetCallForwardingInfo(_handle, ref requestStruct, _callbackMap[id], id);
379             if (ret != (int)TapiError.Success)
380             {
381                 Log.Error(TapiUtility.LogTag, "Failed to set SIM call forward info, Error: " + (TapiError)ret);
382                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
383             }
384
385             return task.Task;
386         }
387
388         /// <summary>
389         /// Gets SIM message waiting indication related data(EF-MWIS and CPHS case).
390         /// </summary>
391         /// <returns>A task containing message waiting response information.</returns>
392         /// <feature>http://tizen.org/feature/network.telephony</feature>
393         /// <privilege>http://tizen.org/privilege/telephony</privilege>
394         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
395         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
396         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
397         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
398         public Task<SimMessageWaitingResponse> SimGetMessageWaitingInfo()
399         {
400             TaskCompletionSource<SimMessageWaitingResponse> task = new TaskCompletionSource<SimMessageWaitingResponse>();
401             IntPtr id = (IntPtr)_requestId++;
402             _callbackMap[id] = (handle, result, data, key) =>
403             {
404                 Task taskResult = new Task(() =>
405                 {
406                     if (result != (int)SimAccessResult.Success)
407                     {
408                         Log.Error(TapiUtility.LogTag, "Error occurs in getting message waiting info: " + (SimAccessResult)result);
409                         task.SetException(new InvalidOperationException("Error occurs in getting message waiting info, " + (SimAccessResult)result));
410                         return;
411                     }
412
413                     SimMessageWaitingResponseStruct info = Marshal.PtrToStructure<SimMessageWaitingResponseStruct>(data);
414                     task.SetResult(SimStructConversions.ConvertSimMessageWaitingRespStruct(info));
415                 });
416                 taskResult.Start();
417                 taskResult.Wait();
418                 _callbackMap.Remove(key);
419             };
420
421             int ret = Interop.Tapi.Sim.SimGetMessageWaitingInfo(_handle, _callbackMap[id], id);
422             if (ret != (int)TapiError.Success)
423             {
424                 Log.Error(TapiUtility.LogTag, "Failed to get SIM message waiting info, Error: " + (TapiError)ret);
425                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
426             }
427
428             return task.Task;
429         }
430
431         /// <summary>
432         /// Sets SIM message waiting indication related data(EF-MWIS and CPHS case).
433         /// </summary>
434         /// <param name="request">The data requesting for message waiting.</param>
435         /// <returns>A task indicating whether setting message waiting info is done or not.</returns>
436         /// <feature>http://tizen.org/feature/network.telephony</feature>
437         /// <privlevel>platform</privlevel>
438         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
439         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
440         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
441         /// <exception cref="ArgumentNullException">Thrown when message waiting request is passed as null.</exception>
442         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
443         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
444         public Task<bool> SimSetMessageWaitingInfo(SimMessageWaitingRequest request)
445         {
446             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
447             IntPtr id = (IntPtr)_requestId++;
448             _callbackMap[id] = (handle, result, data, key) =>
449             {
450                 Task taskResult = new Task(() =>
451                 {
452                     if (result != (int)SimAccessResult.Success)
453                     {
454                         Log.Error(TapiUtility.LogTag, "Error occurs in setting message waiting info: " + (SimAccessResult)result);
455                         task.SetException(new InvalidOperationException("Error occurs in setting message waiting info, " + (SimAccessResult)result));
456                         return;
457                     }
458
459                     task.SetResult(true);
460                 });
461                 taskResult.Start();
462                 taskResult.Wait();
463                 _callbackMap.Remove(key);
464             };
465
466             if (request == null)
467             {
468                 throw new ArgumentNullException("SIM message waiting request is null");
469             }
470
471             SimMessageWaitingRequestStruct requestStruct = SimClassConversions.ConvertSimMessageWaitingRequest(request);
472             int ret = Interop.Tapi.Sim.SimSetMessageWaitingInfo(_handle, ref requestStruct, _callbackMap[id], id);
473             if (ret != (int)TapiError.Success)
474             {
475                 Log.Error(TapiUtility.LogTag, "Failed to set SIM message waiting info, Error: " + (TapiError)ret);
476                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
477             }
478
479             return task.Task;
480         }
481
482         /// <summary>
483         /// Gets SIM mailbox related data(EF-MBDN, MBDI, and CPHS case).
484         /// </summary>
485         /// <returns>A task containing SimMailboxList information.</returns>
486         /// <feature>http://tizen.org/feature/network.telephony</feature>
487         /// <privilege>http://tizen.org/privilege/telephony</privilege>
488         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
489         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
490         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
491         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
492         public Task<SimMailboxList> SimGetMailboxInfo()
493         {
494             TaskCompletionSource<SimMailboxList> task = new TaskCompletionSource<SimMailboxList>();
495             IntPtr id = (IntPtr)_requestId++;
496             _callbackMap[id] = (handle, result, data, key) =>
497             {
498                 Task taskResult = new Task(() =>
499                 {
500                     if (result != (int)SimAccessResult.Success)
501                     {
502                         Log.Error(TapiUtility.LogTag, "Error occurs in getting mailbox info: " + (SimAccessResult)result);
503                         task.SetException(new InvalidOperationException("Error occurs in getting mailbox info, " + (SimAccessResult)result));
504                         return;
505                     }
506
507                     SimMailboxListStruct info = Marshal.PtrToStructure<SimMailboxListStruct>(data);
508                     task.SetResult(SimStructConversions.ConvertSimMailboxListStruct(info));
509                 });
510                 taskResult.Start();
511                 taskResult.Wait();
512                 _callbackMap.Remove(key);
513             };
514
515             int ret = Interop.Tapi.Sim.SimGetMailboxInfo(_handle, _callbackMap[id], id);
516             if (ret != (int)TapiError.Success)
517             {
518                 Log.Error(TapiUtility.LogTag, "Failed to get SIM mailbox info, Error: " + (TapiError)ret);
519                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
520             }
521
522             return task.Task;
523         }
524
525         /// <summary>
526         /// Sets SIM mailbox related data(EF-MBDN, MBDI and CPHS case).
527         /// </summary>
528         /// <param name="mailboxNumber">The data requesting for mailbox info.</param>
529         /// <returns>A task indicating whether setting mailbox info is done or not.</returns>
530         /// <feature>http://tizen.org/feature/network.telephony</feature>
531         /// <privlevel>platform</privlevel>
532         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
533         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
534         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
535         /// <exception cref="ArgumentNullException">Thrown when mailbox number is passed as null.</exception>
536         /// <exception cref="OutOfMemoryException">Thrown when the system runs out of memory.</exception>
537         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
538         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
539         public Task<bool> SimSetMailboxInfo(SimMailboxNumber mailboxNumber)
540         {
541             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
542             IntPtr id = (IntPtr)_requestId++;
543             _callbackMap[id] = (handle, result, data, key) =>
544             {
545                 Task taskResult = new Task(() =>
546                 {
547                     if (result != (int)SimAccessResult.Success)
548                     {
549                         Log.Error(TapiUtility.LogTag, "Error occurs in setting mailbox info: " + (SimAccessResult)result);
550                         task.SetException(new InvalidOperationException("Error occurs in setting mailbox info, " + (SimAccessResult)result));
551                         return;
552                     }
553
554                     task.SetResult(true);
555                 });
556                 taskResult.Start();
557                 taskResult.Wait();
558                 _callbackMap.Remove(key);
559             };
560
561             if (mailboxNumber == null)
562             {
563                 throw new ArgumentNullException("SIM mailbox number is null");
564             }
565
566             SimMailboxNumberStruct mbStruct = SimClassConversions.ConvertSimMailboxNumber(mailboxNumber);
567             int ret = Interop.Tapi.Sim.SimSetMailboxInfo(_handle, ref mbStruct, _callbackMap[id], id);
568             if (ret != (int)TapiError.Success)
569             {
570                 Log.Error(TapiUtility.LogTag, "Failed to set SIM mailbox info, Error: " + (TapiError)ret);
571                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
572             }
573
574             return task.Task;
575         }
576
577         /// <summary>
578         /// Gets SIM CPHS specific data.
579         /// </summary>
580         /// <returns>A task containing SimCphs information.</returns>
581         /// <feature>http://tizen.org/feature/network.telephony</feature>
582         /// <privilege>http://tizen.org/privilege/telephony</privilege>
583         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
584         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
585         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
586         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
587         public Task<SimCphsInfo> SimGetCphsInfo()
588         {
589             TaskCompletionSource<SimCphsInfo> task = new TaskCompletionSource<SimCphsInfo>();
590             IntPtr id = (IntPtr)_requestId++;
591             _callbackMap[id] = (handle, result, data, key) =>
592             {
593                 Task taskResult = new Task(() =>
594                 {
595                     if (result != (int)SimAccessResult.Success)
596                     {
597                         Log.Error(TapiUtility.LogTag, "Error occurs in getting CPHS info: " + (SimAccessResult)result);
598                         task.SetException(new InvalidOperationException("Error occurs in getting CPHS info, " + (SimAccessResult)result));
599                         return;
600                     }
601
602                     SimCphsInfoStruct info = Marshal.PtrToStructure<SimCphsInfoStruct>(data);
603                     task.SetResult(SimStructConversions.ConvertSimCphsInfoStruct(info));
604                 });
605                 taskResult.Start();
606                 taskResult.Wait();
607                 _callbackMap.Remove(key);
608             };
609
610             int ret = Interop.Tapi.Sim.SimGetCphsInfo(_handle, _callbackMap[id], id);
611             if (ret != (int)TapiError.Success)
612             {
613                 Log.Error(TapiUtility.LogTag, "Failed to get SIM CPHS info, Error: " + (TapiError)ret);
614                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
615             }
616
617             return task.Task;
618         }
619
620         /// <summary>
621         /// Gets the SIM Service Table.
622         /// </summary>
623         /// <returns>A task containing SIM service table information.</returns>
624         /// <feature>http://tizen.org/feature/network.telephony</feature>
625         /// <privilege>http://tizen.org/privilege/telephony</privilege>
626         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
627         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
628         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
629         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
630         public Task<SimServiceTable> SimGetServiceTable()
631         {
632             TaskCompletionSource<SimServiceTable> task = new TaskCompletionSource<SimServiceTable>();
633             IntPtr id = (IntPtr)_requestId++;
634             _callbackMap[id] = (handle, result, data, key) =>
635             {
636                 Task taskResult = new Task(() =>
637                 {
638                     if (result != (int)SimAccessResult.Success)
639                     {
640                         Log.Error(TapiUtility.LogTag, "Error occurs in getting service table: " + (SimAccessResult)result);
641                         task.SetException(new InvalidOperationException("Error occurs in getting service table, " + (SimAccessResult)result));
642                         return;
643                     }
644
645                     SimServiceTableStruct info = Marshal.PtrToStructure<SimServiceTableStruct>(data);
646                     task.SetResult(SimStructConversions.ConvertSimServiceTableStruct(info));
647                 });
648                 taskResult.Start();
649                 taskResult.Wait();
650                 _callbackMap.Remove(key);
651             };
652
653             int ret = Interop.Tapi.Sim.SimGetServiceTable(_handle, _callbackMap[id], id);
654             if (ret != (int)TapiError.Success)
655             {
656                 Log.Error(TapiUtility.LogTag, "Failed to get SIM service table, Error: " + (TapiError)ret);
657                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
658             }
659
660             return task.Task;
661         }
662
663         /// <summary>
664         /// Gets SIM MSISDN data.
665         /// </summary>
666         /// <returns>A task containing SimMsisdnList information.</returns>
667         /// <feature>http://tizen.org/feature/network.telephony</feature>
668         /// <privilege>http://tizen.org/privilege/telephony</privilege>
669         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
670         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
671         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
672         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
673         public Task<SimMsisdnList> SimGetMsisdn()
674         {
675             TaskCompletionSource<SimMsisdnList> task = new TaskCompletionSource<SimMsisdnList>();
676             IntPtr id = (IntPtr)_requestId++;
677             _callbackMap[id] = (handle, result, data, key) =>
678             {
679                 Task taskResult = new Task(() =>
680                 {
681                     if (result != (int)SimAccessResult.Success)
682                     {
683                         Log.Error(TapiUtility.LogTag, "Error occurs in getting MSISDN info: " + (SimAccessResult)result);
684                         task.SetException(new InvalidOperationException("Error occurs in getting MSISDN info, " + (SimAccessResult)result));
685                         return;
686                     }
687
688                     SimMsisdnListStruct info = Marshal.PtrToStructure<SimMsisdnListStruct>(data);
689                     task.SetResult(SimStructConversions.ConvertSimMsisdnListStruct(info));
690                 });
691                 taskResult.Start();
692                 taskResult.Wait();
693                 _callbackMap.Remove(key);
694             };
695
696             int ret = Interop.Tapi.Sim.SimGetMsisdn(_handle, _callbackMap[id], id);
697             if (ret != (int)TapiError.Success)
698             {
699                 Log.Error(TapiUtility.LogTag, "Failed to get SIM MSISDN data, Error: " + (TapiError)ret);
700                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
701             }
702
703             return task.Task;
704         }
705
706         /// <summary>
707         /// Gets SIM OPLMNWACT(Operator controlled PLMN Selector with Access Technology) data.
708         /// </summary>
709         /// <returns>A task containing SimOplmnwactList information.</returns>
710         /// <feature>http://tizen.org/feature/network.telephony</feature>
711         /// <privilege>http://tizen.org/privilege/telephony</privilege>
712         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
713         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
714         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
715         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
716         public Task<SimOplmnwactList> SimGetOplmnwact()
717         {
718             TaskCompletionSource<SimOplmnwactList> task = new TaskCompletionSource<SimOplmnwactList>();
719             IntPtr id = (IntPtr)_requestId++;
720             _callbackMap[id] = (handle, result, data, key) =>
721             {
722                 Task taskResult = new Task(() =>
723                 {
724                     if (result != (int)SimAccessResult.Success)
725                     {
726                         Log.Error(TapiUtility.LogTag, "Error occurs in getting OPLMNWACT info: " + (SimAccessResult)result);
727                         task.SetException(new InvalidOperationException("Error occurs in getting OPLMNWACT info, " + (SimAccessResult)result));
728                         return;
729                     }
730
731                     SimOplmnwactListStruct info = Marshal.PtrToStructure<SimOplmnwactListStruct>(data);
732                     task.SetResult(SimStructConversions.ConvertSimOplmnwactListStruct(info));
733                 });
734                 taskResult.Start();
735                 taskResult.Wait();
736                 _callbackMap.Remove(key);
737             };
738
739             int ret = Interop.Tapi.Sim.SimGetOplmnwact(_handle, _callbackMap[id], id);
740             if (ret != (int)TapiError.Success)
741             {
742                 Log.Error(TapiUtility.LogTag, "Failed to get SIM OPLMNWACT info, Error: " + (TapiError)ret);
743                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
744             }
745
746             return task.Task;
747         }
748
749         /// <summary>
750         /// Gets SIM SPN data.
751         /// </summary>
752         /// <returns>A task containing SimSpn information.</returns>
753         /// <feature>http://tizen.org/feature/network.telephony</feature>
754         /// <privilege>http://tizen.org/privilege/telephony</privilege>
755         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
756         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
757         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
758         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
759         public Task<SimSpn> SimGetSpn()
760         {
761             TaskCompletionSource<SimSpn> task = new TaskCompletionSource<SimSpn>();
762             IntPtr id = (IntPtr)_requestId++;
763             _callbackMap[id] = (handle, result, data, key) =>
764             {
765                 Task taskResult = new Task(() =>
766                 {
767                     if (result != (int)SimAccessResult.Success)
768                     {
769                         Log.Error(TapiUtility.LogTag, "Error occurs in getting SPN info: " + (SimAccessResult)result);
770                         task.SetException(new InvalidOperationException("Error occurs in getting SPN info, " + (SimAccessResult)result));
771                         return;
772                     }
773
774                     SimSpnStruct info = Marshal.PtrToStructure<SimSpnStruct>(data);
775                     task.SetResult(SimStructConversions.ConvertSimSpnStruct(info));
776                 });
777                 taskResult.Start();
778                 taskResult.Wait();
779                 _callbackMap.Remove(key);
780             };
781
782             int ret = Interop.Tapi.Sim.SimGetSpn(_handle, _callbackMap[id], id);
783             if (ret != (int)TapiError.Success)
784             {
785                 Log.Error(TapiUtility.LogTag, "Failed to get SIM SPN info, Error: " + (TapiError)ret);
786                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
787             }
788
789             return task.Task;
790         }
791
792         /// <summary>
793         /// Gets SIM CPHS NETNAME data.
794         /// </summary>
795         /// <returns>A task containing SimCphsNetName information.</returns>
796         /// <feature>http://tizen.org/feature/network.telephony</feature>
797         /// <privilege>http://tizen.org/privilege/telephony</privilege>
798         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
799         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
800         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
801         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
802         public Task<SimCphsNetName> SimGetCphsNetName()
803         {
804             TaskCompletionSource<SimCphsNetName> task = new TaskCompletionSource<SimCphsNetName>();
805             IntPtr id = (IntPtr)_requestId++;
806             _callbackMap[id] = (handle, result, data, key) =>
807             {
808                 Task taskResult = new Task(() =>
809                 {
810                     if (result != (int)SimAccessResult.Success)
811                     {
812                         Log.Error(TapiUtility.LogTag, "Error occurs in getting CPHS netname info: " + (SimAccessResult)result);
813                         task.SetException(new InvalidOperationException("Error occurs in getting CPHS netname info, " + (SimAccessResult)result));
814                         return;
815                     }
816
817                     SimCphsNetNameStruct info = Marshal.PtrToStructure<SimCphsNetNameStruct>(data);
818                     task.SetResult(SimStructConversions.ConvertSimCphsNetNameStruct(info));
819                 });
820                 taskResult.Start();
821                 taskResult.Wait();
822                 _callbackMap.Remove(key);
823             };
824
825             int ret = Interop.Tapi.Sim.SimGetCphsNetName(_handle, _callbackMap[id], id);
826             if (ret != (int)TapiError.Success)
827             {
828                 Log.Error(TapiUtility.LogTag, "Failed to get SIM CPHS netname info, Error: " + (TapiError)ret);
829                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
830             }
831
832             return task.Task;
833         }
834
835         /// <summary>
836         /// Executes an authentication procedure by using SIM.
837         /// </summary>
838         /// <param name="authenticationData">The authentication code to be validated by the ISIM, 3G, and GSM application in the SIM card.</param>
839         /// <returns>A task containing SimAuthenticationResponse information.</returns>
840         /// <feature>http://tizen.org/feature/network.telephony</feature>
841         /// <privlevel>platform</privlevel>
842         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
843         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
844         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
845         /// <exception cref="ArgumentNullException">Thrown when authentication data is passed as null.</exception>
846         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
847         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
848         public Task<SimAuthenticationResponse> SimExecuteAuthentication(SimAuthenticationData authenticationData)
849         {
850             TaskCompletionSource<SimAuthenticationResponse> task = new TaskCompletionSource<SimAuthenticationResponse>();
851             IntPtr id = (IntPtr)_requestId++;
852             _callbackMap[id] = (handle, result, data, key) =>
853             {
854                 Task taskResult = new Task(() =>
855                 {
856                     if (result != (int)SimAccessResult.Success)
857                     {
858                         Log.Error(TapiUtility.LogTag, "Error occurs in executing authentication procedure: " + (SimAccessResult)result);
859                         task.SetException(new InvalidOperationException("Error occurs in executing authentication procedure, " + (SimAccessResult)result));
860                         return;
861                     }
862
863                     SimAuthenticationResponseStruct info = Marshal.PtrToStructure<SimAuthenticationResponseStruct>(data);
864                     task.SetResult(SimStructConversions.ConvertSimAuthenticationResponseStruct(info));
865                 });
866                 taskResult.Start();
867                 taskResult.Wait();
868                 _callbackMap.Remove(key);
869             };
870
871             if (authenticationData == null)
872             {
873                 throw new ArgumentNullException("SIM authentication data is null");
874             }
875
876             SimAuthenticationDataStruct authStruct = SimClassConversions.ConvertSimAuthenticationDataStruct(authenticationData);
877             int ret = Interop.Tapi.Sim.SimExecuteAuthentication(_handle, ref authStruct, _callbackMap[id], id);
878             if (ret != (int)TapiError.Success)
879             {
880                 Log.Error(TapiUtility.LogTag, "Failed to execute authentication procedure, Error: " + (TapiError)ret);
881                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
882             }
883
884             return task.Task;
885         }
886
887         /// <summary>
888         /// Performs PIN1/PIN2/SIM LOCK verification.
889         /// </summary>
890         /// <param name="pinData">The PIN code.</param>
891         /// <returns>A task containing SimPinResult information.</returns>
892         /// <feature>http://tizen.org/feature/network.telephony</feature>
893         /// <privlevel>platform</privlevel>
894         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
895         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
896         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
897         /// <exception cref="ArgumentNullException">Thrown when pin data is passed as null.</exception>
898         /// <exception cref="OutOfMemoryException">Thrown when the system runs out of memory.</exception>
899         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
900         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
901         public Task<SimPinResult> SimVerifyPins(SimPinData pinData)
902         {
903             TaskCompletionSource<SimPinResult> task = new TaskCompletionSource<SimPinResult>();
904             IntPtr id = (IntPtr)_requestId++;
905             _callbackMap[id] = (handle, result, data, key) =>
906             {
907                 Task taskResult = new Task(() =>
908                 {
909                     if (result != (int)SimAccessResult.Success)
910                     {
911                         Log.Error(TapiUtility.LogTag, "Error occurs in verifying SIM pins: " + (SimAccessResult)result);
912                         task.SetException(new InvalidOperationException("Error occurs in verifying SIM pins, " + (SimAccessResult)result));
913                         return;
914                     }
915
916                     SimPinResultStruct info = Marshal.PtrToStructure<SimPinResultStruct>(data);
917                     task.SetResult(SimStructConversions.ConvertSimPinResultStruct(info));
918                 });
919                 taskResult.Start();
920                 taskResult.Wait();
921                 _callbackMap.Remove(key);
922             };
923
924             if (pinData == null)
925             {
926                 throw new ArgumentNullException("SIM PIN data is null");
927             }
928
929             SimPinDataStruct pinStruct = SimClassConversions.ConvertSimPinData(pinData);
930             int ret = Interop.Tapi.Sim.SimVerifyPins(_handle, ref pinStruct, _callbackMap[id], id);
931             if (ret != (int)TapiError.Success)
932             {
933                 Log.Error(TapiUtility.LogTag, "Failed to verify SIM PIN, Error: " + (TapiError)ret);
934                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
935             }
936
937             return task.Task;
938         }
939
940         /// <summary>
941         /// Performs PIN1/PIN2 unblocking operation based on PUK information.
942         /// </summary>
943         /// <param name="pukData">The unblocking PIN password.</param>
944         /// <param name="newPinData">The PIN password to use after the unblocking operation.</param>
945         /// <returns>A task containing SimPinResult information.</returns>
946         /// <feature>http://tizen.org/feature/network.telephony</feature>
947         /// <privlevel>platform</privlevel>
948         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
949         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
950         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
951         /// <exception cref="ArgumentNullException">Thrown when either of pukData or newPinData is passed as null.</exception>
952         /// <exception cref="OutOfMemoryException">Thrown when the system runs out of memory.</exception>
953         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
954         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
955         public Task<SimPinResult> SimVerifyPuks(SimPinData pukData, SimPinData newPinData)
956         {
957             TaskCompletionSource<SimPinResult> task = new TaskCompletionSource<SimPinResult>();
958             IntPtr id = (IntPtr)_requestId++;
959             _callbackMap[id] = (handle, result, data, key) =>
960             {
961                 Task taskResult = new Task(() =>
962                 {
963                     if (result != (int)SimAccessResult.Success)
964                     {
965                         Log.Error(TapiUtility.LogTag, "Error occurs in verifying SIM puks: " + (SimAccessResult)result);
966                         task.SetException(new InvalidOperationException("Error occurs in verifying SIM puks, " + (SimAccessResult)result));
967                         return;
968                     }
969
970                     SimPinResultStruct info = Marshal.PtrToStructure<SimPinResultStruct>(data);
971                     task.SetResult(SimStructConversions.ConvertSimPinResultStruct(info));
972                 });
973                 taskResult.Start();
974                 taskResult.Wait();
975                 _callbackMap.Remove(key);
976             };
977
978             if (pukData == null || newPinData == null)
979             {
980                 throw new ArgumentNullException("SIM PIN/PUK data is null");
981             }
982
983             SimPinDataStruct pukStruct = SimClassConversions.ConvertSimPinData(pukData);
984             SimPinDataStruct pinStruct = SimClassConversions.ConvertSimPinData(newPinData);
985             int ret = Interop.Tapi.Sim.SimVerifyPuks(_handle, ref pukStruct, ref pinStruct, _callbackMap[id], id);
986             if (ret != (int)TapiError.Success)
987             {
988                 Log.Error(TapiUtility.LogTag, "Failed to verify SIM puks, Error: " + (TapiError)ret);
989                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
990             }
991
992             return task.Task;
993         }
994
995         /// <summary>
996         /// Changes the PIN1/PIN2 code based on the PIN type passed along with old PIN data and new PIN data.
997         /// </summary>
998         /// <param name="oldPin">The old PIN code entered by the user.</param>
999         /// <param name="newPin">The new PIN code entered by the user.</param>
1000         /// <returns>A task containing SimPinResult information.</returns>
1001         /// <feature>http://tizen.org/feature/network.telephony</feature>
1002         /// <privlevel>platform</privlevel>
1003         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
1004         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
1005         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1006         /// <exception cref="ArgumentNullException">Thrown when either of oldPin or newPin is passed as null.</exception>
1007         /// <exception cref="OutOfMemoryException">Thrown when the system runs out of memory.</exception>
1008         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
1009         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
1010         public Task<SimPinResult> SimChangePins(SimPinData oldPin, SimPinData newPin)
1011         {
1012             TaskCompletionSource<SimPinResult> task = new TaskCompletionSource<SimPinResult>();
1013             IntPtr id = (IntPtr)_requestId++;
1014             _callbackMap[id] = (handle, result, data, key) =>
1015             {
1016                 Task taskResult = new Task(() =>
1017                 {
1018                     if (result != (int)SimAccessResult.Success)
1019                     {
1020                         Log.Error(TapiUtility.LogTag, "Error occurs in changing SIM pins: " + (SimAccessResult)result);
1021                         task.SetException(new InvalidOperationException("Error occurs in changing SIM pins, " + (SimAccessResult)result));
1022                         return;
1023                     }
1024
1025                     SimPinResultStruct info = Marshal.PtrToStructure<SimPinResultStruct>(data);
1026                     task.SetResult(SimStructConversions.ConvertSimPinResultStruct(info));
1027                 });
1028                 taskResult.Start();
1029                 taskResult.Wait();
1030                 _callbackMap.Remove(key);
1031             };
1032
1033             if (oldPin == null || newPin == null)
1034             {
1035                 throw new ArgumentNullException("Old/new PIN data is null");
1036             }
1037
1038             SimPinDataStruct oldPinStruct = SimClassConversions.ConvertSimPinData(oldPin);
1039             SimPinDataStruct newPinStruct = SimClassConversions.ConvertSimPinData(newPin);
1040             int ret = Interop.Tapi.Sim.SimChangePins(_handle, ref oldPinStruct, ref newPinStruct, _callbackMap[id], id);
1041             if (ret != (int)TapiError.Success)
1042             {
1043                 Log.Error(TapiUtility.LogTag, "Failed to change SIM pins, Error: " + (TapiError)ret);
1044                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
1045             }
1046
1047             return task.Task;
1048         }
1049
1050         /// <summary>
1051         /// Disables the SIM facility.
1052         /// </summary>
1053         /// <param name="facility">An object which contains the facility type and password.</param>
1054         /// <returns>A task containing SIM facility result information.</returns>
1055         /// <feature>http://tizen.org/feature/network.telephony</feature>
1056         /// <privlevel>platform</privlevel>
1057         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
1058         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
1059         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1060         /// <exception cref="ArgumentNullException">Thrown when SIM facility info is passed as null.</exception>
1061         /// <exception cref="OutOfMemoryException">Thrown when the system runs out of memory.</exception>
1062         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
1063         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
1064         public Task<SimFacilityResult> SimDisableFacility(SimFacility facility)
1065         {
1066             TaskCompletionSource<SimFacilityResult> task = new TaskCompletionSource<SimFacilityResult>();
1067             IntPtr id = (IntPtr)_requestId++;
1068             _callbackMap[id] = (handle, result, data, key) =>
1069             {
1070                 Task taskResult = new Task(() =>
1071                 {
1072                     if (result != (int)SimAccessResult.Success)
1073                     {
1074                         Log.Error(TapiUtility.LogTag, "Error occurs in disabling SIM facility: " + (SimAccessResult)result);
1075                         task.SetException(new InvalidOperationException("Error occurs in disabling SIM facility, " + (SimAccessResult)result));
1076                         return;
1077                     }
1078
1079                     SimFacilityResultStruct info = Marshal.PtrToStructure<SimFacilityResultStruct>(data);
1080                     task.SetResult(SimStructConversions.ConvertSimFacilityResultStruct(info));
1081                 });
1082                 taskResult.Start();
1083                 taskResult.Wait();
1084                 _callbackMap.Remove(key);
1085             };
1086
1087             if (facility == null)
1088             {
1089                 throw new ArgumentNullException("SIM facility info is null");
1090             }
1091
1092             SimFacilityStruct facilityStruct = SimClassConversions.ConvertSimFacility(facility);
1093             int ret = Interop.Tapi.Sim.SimDisableFacility(_handle, ref facilityStruct, _callbackMap[id], id);
1094             if (ret != (int)TapiError.Success)
1095             {
1096                 Log.Error(TapiUtility.LogTag, "Failed to disable SIM facility, Error: " + (TapiError)ret);
1097                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
1098             }
1099
1100             return task.Task;
1101         }
1102
1103         /// <summary>
1104         /// Enables the SIM facility.
1105         /// </summary>
1106         /// <param name="facility">An object which contains the facility type and password.</param>
1107         /// <returns>A task containing SIM facility result information.</returns>
1108         /// <feature>http://tizen.org/feature/network.telephony</feature>
1109         /// <privlevel>platform</privlevel>
1110         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
1111         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
1112         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1113         /// <exception cref="ArgumentNullException">Thrown when SIM facility info is passed as null.</exception>
1114         /// <exception cref="OutOfMemoryException">Thrown when the system runs out of memory.</exception>
1115         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
1116         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
1117         public Task<SimFacilityResult> SimEnableFacility(SimFacility facility)
1118         {
1119             TaskCompletionSource<SimFacilityResult> task = new TaskCompletionSource<SimFacilityResult>();
1120             IntPtr id = (IntPtr)_requestId++;
1121             _callbackMap[id] = (handle, result, data, key) =>
1122             {
1123                 Task taskResult = new Task(() =>
1124                 {
1125                     if (result != (int)SimAccessResult.Success)
1126                     {
1127                         Log.Error(TapiUtility.LogTag, "Error occurs in enabling SIM facility: " + (SimAccessResult)result);
1128                         task.SetException(new InvalidOperationException("Error occurs in enabling SIM facility, " + (SimAccessResult)result));
1129                         return;
1130                     }
1131
1132                     SimFacilityResultStruct info = Marshal.PtrToStructure<SimFacilityResultStruct>(data);
1133                     task.SetResult(SimStructConversions.ConvertSimFacilityResultStruct(info));
1134                 });
1135                 taskResult.Start();
1136                 taskResult.Wait();
1137                 _callbackMap.Remove(key);
1138             };
1139
1140             if (facility == null)
1141             {
1142                 throw new ArgumentNullException("SIM facility info is null");
1143             }
1144
1145             SimFacilityStruct facilityStruct = SimClassConversions.ConvertSimFacility(facility);
1146             int ret = Interop.Tapi.Sim.SimEnableFacility(_handle, ref facilityStruct, _callbackMap[id], id);
1147             if (ret != (int)TapiError.Success)
1148             {
1149                 Log.Error(TapiUtility.LogTag, "Failed to enable SIM facility, Error: " + (TapiError)ret);
1150                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
1151             }
1152
1153             return task.Task;
1154         }
1155
1156         /// <summary>
1157         /// Gets the SIM facility.
1158         /// </summary>
1159         /// <param name="lockType">The type of security lock.</param>
1160         /// <returns>A task containing SIM facility information.</returns>
1161         /// <feature>http://tizen.org/feature/network.telephony</feature>
1162         /// <privilege>http://tizen.org/privilege/telephony</privilege>
1163         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
1164         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1165         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
1166         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
1167         public Task<SimFacilityInfo> SimGetFacility(SimLockType lockType)
1168         {
1169             TaskCompletionSource<SimFacilityInfo> task = new TaskCompletionSource<SimFacilityInfo>();
1170             IntPtr id = (IntPtr)_requestId++;
1171             _callbackMap[id] = (handle, result, data, key) =>
1172             {
1173                 Task taskResult = new Task(() =>
1174                 {
1175                     if (result != (int)SimAccessResult.Success)
1176                     {
1177                         Log.Error(TapiUtility.LogTag, "Error occurs in getting SIM facility: " + (SimAccessResult)result);
1178                         task.SetException(new InvalidOperationException("Error occurs in getting SIM facility, " + (SimAccessResult)result));
1179                         return;
1180                     }
1181
1182                     SimFacilityInfoStruct info = Marshal.PtrToStructure<SimFacilityInfoStruct>(data);
1183                     task.SetResult(SimStructConversions.ConvertSimFacilityInfoStruct(info));
1184                 });
1185                 taskResult.Start();
1186                 taskResult.Wait();
1187                 _callbackMap.Remove(key);
1188             };
1189
1190             int ret = Interop.Tapi.Sim.SimGetFacility(_handle, lockType, _callbackMap[id], id);
1191             if (ret != (int)TapiError.Success)
1192             {
1193                 Log.Error(TapiUtility.LogTag, "Failed to get SIM facility, Error: " + (TapiError)ret);
1194                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
1195             }
1196
1197             return task.Task;
1198         }
1199
1200         /// <summary>
1201         /// Gets SIM lock type info.
1202         /// </summary>
1203         /// <param name="lockType">The type of security lock.</param>
1204         /// <returns>A task containing SIM lock information.</returns>
1205         /// <feature>http://tizen.org/feature/network.telephony</feature>
1206         /// <privilege>http://tizen.org/privilege/telephony</privilege>
1207         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
1208         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1209         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
1210         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
1211         public Task<SimLockInfo> SimGetLockInfo(SimLockType lockType)
1212         {
1213             TaskCompletionSource<SimLockInfo> task = new TaskCompletionSource<SimLockInfo>();
1214             IntPtr id = (IntPtr)_requestId++;
1215             _callbackMap[id] = (handle, result, data, key) =>
1216             {
1217                 Task taskResult = new Task(() =>
1218                 {
1219                     if (result != (int)SimAccessResult.Success)
1220                     {
1221                         Log.Error(TapiUtility.LogTag, "Error occurs in getting SIM lock info: " + (SimAccessResult)result);
1222                         task.SetException(new InvalidOperationException("Error occurs in getting SIM lock info, " + (SimAccessResult)result));
1223                         return;
1224                     }
1225
1226                     SimLockInfoStruct info = Marshal.PtrToStructure<SimLockInfoStruct>(data);
1227                     task.SetResult(SimStructConversions.ConvertSimLockInfoStruct(info));
1228                 });
1229                 taskResult.Start();
1230                 taskResult.Wait();
1231                 _callbackMap.Remove(key);
1232             };
1233
1234             int ret = Interop.Tapi.Sim.SimGetLockInfo(_handle, lockType, _callbackMap[id], id);
1235             if (ret != (int)TapiError.Success)
1236             {
1237                 Log.Error(TapiUtility.LogTag, "Failed to get SIM lock info, Error: " + (TapiError)ret);
1238                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
1239             }
1240
1241             return task.Task;
1242         }
1243
1244         /// <summary>
1245         /// Sets the SIM power state.
1246         /// </summary>
1247         /// <param name="state">The state of SIM to be set.</param>
1248         /// <returns>A task indicating whether setting SIM power state is done or not.</returns>
1249         /// <feature>http://tizen.org/feature/network.telephony</feature>
1250         /// <privlevel>platform</privlevel>
1251         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
1252         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
1253         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1254         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
1255         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
1256         public Task<bool> SimSetPowerState(SimPowerState state)
1257         {
1258             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
1259             IntPtr id = (IntPtr)_requestId++;
1260             _callbackMap[id] = (handle, result, data, key) =>
1261             {
1262                 Task taskResult = new Task(() =>
1263                 {
1264                     if (result != (int)SimPowerSetResult.Success)
1265                     {
1266                         Log.Error(TapiUtility.LogTag, "Error occurs in setting SIM power state: " + (SimPowerSetResult)result);
1267                         task.SetException(new InvalidOperationException("Error occurs in setting SIM power state, " + (SimPowerSetResult)result));
1268                         return;
1269                     }
1270
1271                     task.SetResult(true);
1272                 });
1273                 taskResult.Start();
1274                 taskResult.Wait();
1275                 _callbackMap.Remove(key);
1276             };
1277
1278             int ret = Interop.Tapi.Sim.SimSetPowerState(_handle, state, _callbackMap[id], id);
1279             if (ret != (int)TapiError.Success)
1280             {
1281                 Log.Error(TapiUtility.LogTag, "Failed to set SIM power state, Error: " + (TapiError)ret);
1282                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
1283             }
1284
1285             return task.Task;
1286         }
1287
1288         /// <summary>
1289         /// Provides a common interface for accessing SIM data.
1290         /// </summary>
1291         /// <param name="apdu">The APDU data.</param>
1292         /// <returns>A task containing SIM APDU response information.</returns>
1293         /// <feature>http://tizen.org/feature/network.telephony</feature>
1294         /// <privlevel>platform</privlevel>
1295         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
1296         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
1297         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1298         /// <exception cref="ArgumentNullException">Thrown when SIM APDU is passed as null.</exception>
1299         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
1300         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
1301         public Task<SimApduResponse> SimRequestApdu(SimApdu apdu)
1302         {
1303             TaskCompletionSource<SimApduResponse> task = new TaskCompletionSource<SimApduResponse>();
1304             IntPtr id = (IntPtr)_requestId++;
1305             _callbackMap[id] = (handle, result, data, key) =>
1306             {
1307                 Task taskResult = new Task(() =>
1308                 {
1309                     if (result != (int)SimAccessResult.Success)
1310                     {
1311                         Log.Error(TapiUtility.LogTag, "Error occurs in requesting SIM APDU: " + (SimAccessResult)result);
1312                         task.SetException(new InvalidOperationException("Error occurs in requesting SIM APDU, " + (SimAccessResult)result));
1313                         return;
1314                     }
1315
1316                     SimApduResponseStruct info = Marshal.PtrToStructure<SimApduResponseStruct>(data);
1317                     task.SetResult(SimStructConversions.ConvertSimApduResponseStruct(info));
1318                 });
1319                 taskResult.Start();
1320                 taskResult.Wait();
1321                 _callbackMap.Remove(key);
1322             };
1323
1324             if (apdu == null)
1325             {
1326                 throw new ArgumentNullException("SIM APDU is null");
1327             }
1328
1329             SimApduStruct apduStruct = SimClassConversions.ConvertSimApdu(apdu);
1330             int ret = Interop.Tapi.Sim.SimRequestApdu(_handle, ref apduStruct, _callbackMap[id], id);
1331             if (ret != (int)TapiError.Success)
1332             {
1333                 Log.Error(TapiUtility.LogTag, "Failed to request SIM APDU, Error: " + (TapiError)ret);
1334                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
1335             }
1336
1337             return task.Task;
1338         }
1339
1340         /// <summary>
1341         /// Provides a common interface to get the SIM ATR(Answer To Reset) value.
1342         /// </summary>
1343         /// <returns>A task containing SIM ATR response information.</returns>
1344         /// <feature>http://tizen.org/feature/network.telephony</feature>
1345         /// <privilege>http://tizen.org/privilege/telephony</privilege>
1346         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
1347         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1348         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
1349         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
1350         public Task<SimAtrResponse> SimRequestAtr()
1351         {
1352             TaskCompletionSource<SimAtrResponse> task = new TaskCompletionSource<SimAtrResponse>();
1353             IntPtr id = (IntPtr)_requestId++;
1354             _callbackMap[id] = (handle, result, data, key) =>
1355             {
1356                 Task taskResult = new Task(() =>
1357                 {
1358                     if (result != (int)SimAccessResult.Success)
1359                     {
1360                         Log.Error(TapiUtility.LogTag, "Error occurs in requesting SIM ATR: " + (SimAccessResult)result);
1361                         task.SetException(new InvalidOperationException("Error occurs in requesting SIM ATR, " + (SimAccessResult)result));
1362                         return;
1363                     }
1364
1365                     SimAtrResponseStruct info = Marshal.PtrToStructure<SimAtrResponseStruct>(data);
1366                     task.SetResult(SimStructConversions.ConvertSimAtrResponseStruct(info));
1367                 });
1368                 taskResult.Start();
1369                 taskResult.Wait();
1370                 _callbackMap.Remove(key);
1371             };
1372
1373             int ret = Interop.Tapi.Sim.SimRequestAtr(_handle, _callbackMap[id], id);
1374             if (ret != (int)TapiError.Success)
1375             {
1376                 Log.Error(TapiUtility.LogTag, "Failed to request SIM ATR, Error: " + (TapiError)ret);
1377                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
1378             }
1379
1380             return task.Task;
1381         }
1382
1383         /// <summary>
1384         /// Gets the IMPI(IMS private user identity). (ISIM only).
1385         /// </summary>
1386         /// <returns>A task containing IMPI string.</returns>
1387         /// <feature>http://tizen.org/feature/network.telephony</feature>
1388         /// <privilege>http://tizen.org/privilege/telephony</privilege>
1389         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
1390         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1391         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
1392         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
1393         public Task<string> SimGetImpi()
1394         {
1395             TaskCompletionSource<string> task = new TaskCompletionSource<string>();
1396             IntPtr id = (IntPtr)_requestId++;
1397             _callbackMap[id] = (handle, result, data, key) =>
1398             {
1399                 Task taskResult = new Task(() =>
1400                 {
1401                     if (result != (int)SimAccessResult.Success)
1402                     {
1403                         Log.Error(TapiUtility.LogTag, "Error occurs in getting SIM IMPI: " + (SimAccessResult)result);
1404                         task.SetException(new InvalidOperationException("Error occurs in getting SIM IMPI, " + (SimAccessResult)result));
1405                         return;
1406                     }
1407
1408                     task.SetResult(Marshal.PtrToStringAnsi(data));
1409                 });
1410                 taskResult.Start();
1411                 taskResult.Wait();
1412                 _callbackMap.Remove(key);
1413             };
1414
1415             int ret = Interop.Tapi.Sim.SimGetImpi(_handle, _callbackMap[id], id);
1416             if (ret != (int)TapiError.Success)
1417             {
1418                 Log.Error(TapiUtility.LogTag, "Failed to get SIM IMPI, Error: " + (TapiError)ret);
1419                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
1420             }
1421
1422             return task.Task;
1423         }
1424
1425         /// <summary>
1426         /// Gets the IMPU(IMS public user identity). (ISIM only).
1427         /// </summary>
1428         /// <returns>A task containing SIM IMPU list information.</returns>
1429         /// <feature>http://tizen.org/feature/network.telephony</feature>
1430         /// <privilege>http://tizen.org/privilege/telephony</privilege>
1431         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
1432         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1433         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
1434         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
1435         public Task<SimImpuList> SimGetImpu()
1436         {
1437             TaskCompletionSource<SimImpuList> task = new TaskCompletionSource<SimImpuList>();
1438             IntPtr id = (IntPtr)_requestId++;
1439             _callbackMap[id] = (handle, result, data, key) =>
1440             {
1441                 Task taskResult = new Task(() =>
1442                 {
1443                     if (result != (int)SimAccessResult.Success)
1444                     {
1445                         Log.Error(TapiUtility.LogTag, "Error occurs in getting SIM IMPU: " + (SimAccessResult)result);
1446                         task.SetException(new InvalidOperationException("Error occurs in getting SIM IMPU, " + (SimAccessResult)result));
1447                         return;
1448                     }
1449
1450                     SimImpuListStruct info = Marshal.PtrToStructure<SimImpuListStruct>(data);
1451                     task.SetResult(SimStructConversions.ConvertSimImpuListStruct(info));
1452                 });
1453                 taskResult.Start();
1454                 taskResult.Wait();
1455                 _callbackMap.Remove(key);
1456             };
1457
1458             int ret = Interop.Tapi.Sim.SimGetImpu(_handle, _callbackMap[id], id);
1459             if (ret != (int)TapiError.Success)
1460             {
1461                 Log.Error(TapiUtility.LogTag, "Failed to get SIM IMPU, Error: " + (TapiError)ret);
1462                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
1463             }
1464
1465             return task.Task;
1466         }
1467
1468         /// <summary>
1469         /// Gets the Domain(Home Network Domain Name). (ISIM only)
1470         /// </summary>
1471         /// <returns>A task containing domain string.</returns>
1472         /// <feature>http://tizen.org/feature/network.telephony</feature>
1473         /// <privilege>http://tizen.org/privilege/telephony</privilege>
1474         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
1475         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1476         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
1477         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
1478         public Task<string> SimGetDomain()
1479         {
1480             TaskCompletionSource<string> task = new TaskCompletionSource<string>();
1481             IntPtr id = (IntPtr)_requestId++;
1482             _callbackMap[id] = (handle, result, data, key) =>
1483             {
1484                 Task taskResult = new Task(() =>
1485                 {
1486                     if (result != (int)SimAccessResult.Success)
1487                     {
1488                         Log.Error(TapiUtility.LogTag, "Error occurs in getting SIM domain: " + (SimAccessResult)result);
1489                         task.SetException(new InvalidOperationException("Error occurs in getting SIM domain, " + (SimAccessResult)result));
1490                         return;
1491                     }
1492
1493                     task.SetResult(Marshal.PtrToStringAnsi(data));
1494                 });
1495                 taskResult.Start();
1496                 taskResult.Wait();
1497                 _callbackMap.Remove(key);
1498             };
1499
1500             int ret = Interop.Tapi.Sim.SimGetDomain(_handle, _callbackMap[id], id);
1501             if (ret != (int)TapiError.Success)
1502             {
1503                 Log.Error(TapiUtility.LogTag, "Failed to get SIM domain, Error: " + (TapiError)ret);
1504                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
1505             }
1506
1507             return task.Task;
1508         }
1509
1510         /// <summary>
1511         /// Gets the P-CSCF(Proxy Call Session Control Function). (ISIM only)
1512         /// </summary>
1513         /// <returns>A task containing SIM PCSCF list information.</returns>
1514         /// <feature>http://tizen.org/feature/network.telephony</feature>
1515         /// <privilege>http://tizen.org/privilege/telephony</privilege>
1516         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
1517         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1518         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
1519         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
1520         public Task<SimPcscfList> SimGetPcscf()
1521         {
1522             TaskCompletionSource<SimPcscfList> task = new TaskCompletionSource<SimPcscfList>();
1523             IntPtr id = (IntPtr)_requestId++;
1524             _callbackMap[id] = (handle, result, data, key) =>
1525             {
1526                 Task taskResult = new Task(() =>
1527                 {
1528                     if (result != (int)SimAccessResult.Success)
1529                     {
1530                         Log.Error(TapiUtility.LogTag, "Error occurs in getting SIM PCSCF: " + (SimAccessResult)result);
1531                         task.SetException(new InvalidOperationException("Error occurs in getting SIM PCSCF, " + (SimAccessResult)result));
1532                         return;
1533                     }
1534
1535                     SimPcscfListStruct info = Marshal.PtrToStructure<SimPcscfListStruct>(data);
1536                     task.SetResult(SimStructConversions.ConvertSimPcscfListStruct(info));
1537                 });
1538                 taskResult.Start();
1539                 taskResult.Wait();
1540                 _callbackMap.Remove(key);
1541             };
1542
1543             int ret = Interop.Tapi.Sim.SimGetPcscf(_handle, _callbackMap[id], id);
1544             if (ret != (int)TapiError.Success)
1545             {
1546                 Log.Error(TapiUtility.LogTag, "Failed to get SIM PCSCF, Error: " + (TapiError)ret);
1547                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
1548             }
1549
1550             return task.Task;
1551         }
1552
1553         /// <summary>
1554         /// Gets the ISIM service table. (ISIM only).
1555         /// </summary>
1556         /// <returns>A task containing a byte array in which mask value of SimIsimService enum will be stored.</returns>
1557         /// <feature>http://tizen.org/feature/network.telephony</feature>
1558         /// <privilege>http://tizen.org/privilege/telephony</privilege>
1559         /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
1560         /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
1561         /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
1562         /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
1563         public Task<byte[]> SimGetIsimServiceTable()
1564         {
1565             TaskCompletionSource<byte[]> task = new TaskCompletionSource<byte[]>();
1566             IntPtr id = (IntPtr)_requestId++;
1567             _callbackMap[id] = (handle, result, data, key) =>
1568             {
1569                 Task taskResult = new Task(() =>
1570                 {
1571                     if (result != (int)SimAccessResult.Success)
1572                     {
1573                         Log.Error(TapiUtility.LogTag, "Error occurs in getting ISIM service table: " + (SimAccessResult)result);
1574                         task.SetException(new InvalidOperationException("Error occurs in getting ISIM service table, " + (SimAccessResult)result));
1575                         return;
1576                     }
1577
1578                     task.SetResult(Encoding.ASCII.GetBytes(Marshal.PtrToStringAnsi(data)));
1579                 });
1580                 taskResult.Start();
1581                 taskResult.Wait();
1582                 _callbackMap.Remove(key);
1583             };
1584
1585             int ret = Interop.Tapi.Sim.SimGetIsimServiceTable(_handle, _callbackMap[id], id);
1586             if (ret != (int)TapiError.Success)
1587             {
1588                 Log.Error(TapiUtility.LogTag, "Failed to get ISIM service table, Error: " + (TapiError)ret);
1589                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
1590             }
1591
1592             return task.Task;
1593         }
1594     }
1595 }