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