Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Telephony / Tizen.Telephony / 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 static Interop.Telephony;
19
20 namespace Tizen.Telephony
21 {
22     /// <summary>
23     /// This Class provides API's that allows you to extract information stored on a SIM card
24     /// </summary>
25     public class Sim
26     {
27         internal IntPtr _handle;
28
29         /// <summary>
30         /// Sim Class Constructor
31         /// </summary>
32         /// <since_tizen> 3 </since_tizen>
33         /// <param name="handle">
34         /// SlotHandle received in the Manager.Init API
35         /// </param>
36         /// <feature>http://tizen.org/feature/network.telephony</feature>
37         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
38         /// <exception cref="ArgumentNullException">
39         /// This exception occurs if handle provided is null
40         /// </exception>
41         public Sim(SlotHandle handle)
42         {
43             if (handle == null)
44             {
45                 throw new ArgumentNullException();
46             }
47
48             _handle = handle._handle;
49         }
50
51         /// <summary>
52         /// Enumeration for the state of SIM card.
53         /// </summary>
54         public enum State
55         {
56             /// <summary>
57             /// SIM is not available on this device
58             /// </summary>
59             Unavailable,
60             /// <summary>
61             /// SIM is locked
62             /// </summary>
63             Locked,
64             /// <summary>
65             /// SIM is available on this device (SIM is not locked)
66             /// </summary>
67             Available,
68             /// <summary>
69             /// SIM is in transition between states
70             /// </summary>
71             Unknown
72         }
73
74         /// <summary>
75         /// Enumeration for the lock state of SIM card.
76         /// </summary>
77         public enum LockState
78         {
79             /// <summary>
80             /// SIM is not in lock
81             /// </summary>
82             Unknown,
83             /// <summary>
84             /// SIM is PIN(Personal Identification Number) locked
85             /// </summary>
86             PinRequired,
87             /// <summary>
88             /// SIM is PUK(Personal Unblocking Code) locked
89             /// </summary>
90             PukRequired,
91             /// <summary>
92             /// SIM is permanently blocked(All the attempts for PIN/PUK failed)
93             /// </summary>
94             PermLocked,
95             /// <summary>
96             /// SIM is NCK(Network Control Key) locked
97             /// </summary>
98             NckRequired
99         }
100
101         /// <summary>
102         /// Enumeration for the type of SIM card.
103         /// </summary>
104         public enum ApplicationType
105         {
106             /// <summary>
107             /// SIM(GSM) Application
108             /// </summary>
109             Sim = 0x01,
110             /// <summary>
111             /// USIM Application
112             /// </summary>
113             Usim = 0x02,
114             /// <summary>
115             /// CDMA Application
116             /// </summary>
117             Csim = 0x04,
118             /// <summary>
119             /// ISIM Application
120             /// </summary>
121             Isim = 0x08
122         }
123
124         /// <summary>
125         /// Gets the Integrated Circuit Card IDentification (ICC-ID).
126         /// The Integrated Circuit Card Identification number internationally identifies SIM cards.
127         /// </summary>
128         /// <since_tizen> 3 </since_tizen>
129         /// <privilege>http://tizen.org/privilege/telephony</privilege>
130         /// <value>
131         /// The Integrated Circuit Card Identification
132         /// empty string if unable to complete the operation
133         /// </value>
134         /// <precondition>
135         /// The SIM state must be Available
136         /// </precondition>
137         public string IccId
138         {
139             get
140             {
141                 string iccId;
142                 TelephonyError error = Interop.Sim.GetIccId(_handle, out iccId);
143                 if (error != TelephonyError.None)
144                 {
145                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetIccId Failed with error " + error);
146                     return "";
147                 }
148
149                 return iccId;
150             }
151         }
152
153         /// <summary>
154         /// Gets the SIM Operator (MCC [3 digits] + MNC [2~3 digits]).
155         /// The Operator is embedded in the SIM card.
156         /// </summary>
157         /// <since_tizen> 3 </since_tizen>
158         /// <privilege>http://tizen.org/privilege/telephony</privilege>
159         /// <value>
160         /// The SIM Operator
161         /// empty string if unable to complete the operation
162         /// </value>
163         /// <precondition>
164         /// The SIM state must be Available
165         /// </precondition>
166         public string Operator
167         {
168             get
169             {
170                 string simOperator;
171                 TelephonyError error = Interop.Sim.GetOperator(_handle, out simOperator);
172                 if (error != TelephonyError.None)
173                 {
174                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetOperator Failed with error " + error);
175                     return "";
176                 }
177
178                 return simOperator;
179             }
180         }
181
182         /// <summary>
183         /// Gets the Mobile Subscription Identification Number (MSIN [9~10 digits]) of the SIM provider.
184         /// </summary>
185         /// <since_tizen> 3 </since_tizen>
186         /// <privilege>http://tizen.org/privilege/telephony</privilege>
187         /// <value>
188         /// The Mobile Subscription Identification Number
189         /// empty string if unable to complete the operation
190         /// </value>
191         /// <precondition>
192         /// The SIM state must be Available
193         /// </precondition>
194         public string Msin
195         {
196             get
197             {
198                 string msin;
199                 TelephonyError error = Interop.Sim.GetMsin(_handle, out msin);
200                 if (error != TelephonyError.None)
201                 {
202                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetMsin Failed with error " + error);
203                     return "";
204                 }
205
206                 return msin;
207             }
208         }
209
210         /// <summary>
211         /// Gets the Service Provider Name (SPN) of the SIM card.
212         /// Gets Service Provider Name embedded in the SIM card.If this value is not stored in SIM card, empty string will be returned.
213         /// </summary>
214         /// <since_tizen> 3 </since_tizen>
215         /// <privilege>http://tizen.org/privilege/telephony</privilege>
216         /// <value>
217         /// The Service Provider Name
218         /// empty string if unable to complete the operation
219         /// </value>
220         /// <precondition>
221         /// The SIM state must be Available
222         /// </precondition>
223         public string Spn
224         {
225             get
226             {
227                 string spn;
228                 TelephonyError error = Interop.Sim.GetSpn(_handle, out spn);
229                 if (error != TelephonyError.None)
230                 {
231                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetSpn Failed with error " + error);
232                     return "";
233                 }
234
235                 return spn;
236             }
237         }
238
239         /// <summary>
240         /// Checks whether the current SIM card is different from the previous SIM card.
241         /// </summary>
242         /// <since_tizen> 3 </since_tizen>
243         /// <privilege>http://tizen.org/privilege/telephony</privilege>
244         /// <value>
245         /// true if the current SIM card is different from the previous SIM card, otherwise false if the SIM card is not changed
246         /// </value>
247         /// <precondition>
248         /// The SIM state must be Available
249         /// </precondition>
250         public bool IsChanged
251         {
252             get
253             {
254                 int ischanged;
255                 bool isChanged = false; ;
256                 TelephonyError error = Interop.Sim.IsChanged(_handle, out ischanged);
257                 if (error != TelephonyError.None)
258                 {
259                     Tizen.Log.Error(Interop.Telephony.LogTag, "IsChanged Failed with error " + error);
260                     return false;
261                 }
262
263                 if (ischanged > 0)
264                 {
265                     isChanged = true;
266                 }
267
268                 return isChanged;
269             }
270         }
271
272         /// <summary>
273         /// Gets the state of the SIM.
274         /// </summary>
275         /// <since_tizen> 3 </since_tizen>
276         /// <privilege>http://tizen.org/privilege/telephony</privilege>
277         /// <value>
278         /// The current state of the SIM
279         /// </value>
280         public State CurrentState
281         {
282             get
283             {
284                 State currentState;
285                 TelephonyError error = Interop.Sim.GetState(_handle, out currentState);
286                 if (error != TelephonyError.None)
287                 {
288                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetState Failed with error " + error);
289                     return State.Unavailable;
290                 }
291
292                 return currentState;
293             }
294         }
295
296         /// <summary>
297         /// Gets the count of application on UICC.
298         /// </summary>
299         /// <since_tizen> 3 </since_tizen>
300         /// <privilege>http://tizen.org/privilege/telephony</privilege>
301         /// <value>
302         /// The masking value for below values are provided by the enum ApplicationType
303         /// 0 if unable to complete the operation
304         /// </value>
305         /// <precondition>
306         /// The SIM state must be Available
307         /// </precondition>
308         public uint ApplicationList
309         {
310             get
311             {
312                 uint appList;
313                 TelephonyError error = Interop.Sim.GetApplicationList(_handle, out appList);
314                 if (error != TelephonyError.None)
315                 {
316                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetApplicationList Failed with error " + error);
317                     return 0;
318                 }
319
320                 return appList;
321             }
322         }
323
324         /// <summary>
325         /// Gets subscriber number embedded in the SIM card. This value contains MSISDN related to the subscriber.
326         /// If this value is not stored in SIM card, empty string will be returned.
327         /// </summary>
328         /// <since_tizen> 3 </since_tizen>
329         /// <privilege>http://tizen.org/privilege/telephony</privilege>
330         /// <value>
331         /// The subscriber number in the SIM
332         /// empty string if unable to complete the operation
333         /// </value>
334         /// <precondition>
335         /// The SIM state must be Available
336         /// </precondition>
337         public string SubscriberNumber
338         {
339             get
340             {
341                 string subscriberNumber;
342                 TelephonyError error = Interop.Sim.GetSubscriberNumber(_handle, out subscriberNumber);
343                 if (error != TelephonyError.None)
344                 {
345                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetSubscriberNumber Failed with error " + error);
346                     return "";
347                 }
348
349                 return subscriberNumber;
350             }
351         }
352
353         /// <summary>
354         /// Gets the Subscriber ID.
355         /// </summary>
356         /// <since_tizen> 3 </since_tizen>
357         /// <privilege>http://tizen.org/privilege/telephony</privilege>
358         /// <value>
359         /// The subscriber ID
360         /// empty string if unable to complete the operation
361         /// </value>
362         /// <precondition>
363         /// The SIM state must be Available
364         /// </precondition>
365         public string SubscriberId
366         {
367             get
368             {
369                 string subscriberId;
370                 TelephonyError error = Interop.Sim.GetSubscriberId(_handle, out subscriberId);
371                 if (error != TelephonyError.None)
372                 {
373                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetSubscriberId Failed with error " + error);
374                     return "";
375                 }
376
377                 return subscriberId;
378             }
379         }
380
381         /// <summary>
382         /// Gets the lock state of the SIM.
383         /// </summary>
384         /// <since_tizen> 3 </since_tizen>
385         /// <privilege>http://tizen.org/privilege/telephony</privilege>
386         /// <value>
387         /// The current lock state of the SIM
388         /// </value>
389         /// <precondition>
390         /// The SIM state must be Available
391         /// </precondition>
392         public LockState CurrentLockState
393         {
394             get
395             {
396                 LockState currentLockState;
397                 TelephonyError error = Interop.Sim.GetLockState(_handle, out currentLockState);
398                 if (error != TelephonyError.None)
399                 {
400                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetLockState Failed with error " + error);
401                     return LockState.Unknown;
402                 }
403
404                 return currentLockState;
405             }
406         }
407
408         /// <summary>
409         /// Gets the GID1 (Group Identifier Level 1).
410         /// Gets Group Identifier Level 1(GID1) embedded in the SIM card.If this value is not stored in SIM card, empty string will be returned.
411         /// </summary>
412         /// <since_tizen> 3 </since_tizen>
413         /// <privilege>http://tizen.org/privilege/telephony</privilege>
414         /// <value>
415         /// The GID1 (Group Identifier Level 1)
416         /// empty string if unable to complete the operation
417         /// </value>
418         /// <precondition>
419         /// The SIM state must be Available
420         /// </precondition>
421         public string GroupId1
422         {
423             get
424             {
425                 string groupId1;
426                 TelephonyError error = Interop.Sim.GetGroupId1(_handle, out groupId1);
427                 if (error != TelephonyError.None)
428                 {
429                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetGroupId1 Failed with error " + error);
430                     return "";
431                 }
432
433                 return groupId1;
434             }
435         }
436
437         /// <summary>
438         /// Gets the call forwarding indicator state of the SIM.
439         /// If the state is true, incoming call will be forwarded to the selected number.state indicates the CFU(Call Forwarding Unconditional) indicator status - Voice. (3GPP TS 31.102 4.2.64 EF CFIS)
440         /// </summary>
441         /// <since_tizen> 3 </since_tizen>
442         /// <privilege>http://tizen.org/privilege/telephony</privilege>
443         /// <value>
444         /// The value whether incoming call will be forwarded or not. (true: forwarded, false: not forwarded)
445         /// </value>
446         /// <precondition>
447         /// The SIM state must be Available
448         /// </precondition>
449         public bool CallForwardingIndicatorState
450         {
451             get
452             {
453                 bool callForwardingIndicatorState;
454                 TelephonyError error = Interop.Sim.GetCallForwardingIndicatorState(_handle, out callForwardingIndicatorState);
455                 if (error != TelephonyError.None)
456                 {
457                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetCallForwardingIndicatorState Failed with error " + error);
458                     return false;
459                 }
460
461                 return callForwardingIndicatorState;
462             }
463         }
464     }
465 }