Change License under the Apache License.
[platform/core/csapi/telephony.git] / Tizen.Telephony / Tizen.Telephony / Network.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 namespace Tizen.Telephony
20 {
21     /// <summary>
22     /// The Network class provides API's to obtain information about the current telephony service network.
23     /// </summary>
24     public class Network
25     {
26         internal IntPtr _handle;
27
28         /// <summary>
29         /// Network Class Constructor
30         /// </summary>
31         /// <param name="handle">
32         /// SlotHandle received in the Manager.Init API
33         /// </param>
34         /// <exception cref="ArgumentNullException">
35         /// This exception occurs if handle provided is null
36         /// </exception>
37         public Network(SlotHandle handle)
38         {
39             if (handle == null)
40             {
41                 throw new ArgumentNullException();
42             }
43
44             _handle = handle._handle;
45         }
46
47         /// <summary>
48         /// Enumeration for RSSI (Receive Signal Strength Indicator).
49         /// Rssi6 indicates the highest strength.
50         /// </summary>
51         public enum Rssi
52         {
53             /// <summary>
54             /// Strength 0
55             /// </summary>
56             Rssi0,
57             /// <summary>
58             /// Strength 1
59             /// </summary>
60             Rssi1,
61             /// <summary>
62             /// Strength 2
63             /// </summary>
64             Rssi2,
65             /// <summary>
66             /// Strength 3
67             /// </summary>
68             Rssi3,
69             /// <summary>
70             /// Strength 4
71             /// </summary>
72             Rssi4,
73             /// <summary>
74             /// Strength 5
75             /// </summary>
76             Rssi5,
77             /// <summary>
78             /// Strength 6
79             /// </summary>
80             Rssi6,
81             /// <summary>
82             /// Unavailable
83             /// </summary>
84             Unavailable
85         }
86
87         /// <summary>
88         /// Enumeration for Network Type.
89         /// </summary>
90         public enum Type
91         {
92             /// <summary>
93             /// Unknown
94             /// </summary>
95             Unknown,
96             /// <summary>
97             /// 2G GSM network type
98             /// </summary>
99             Gsm,
100             /// <summary>
101             /// 2.5G GPRS network type
102             /// </summary>
103             Gprs,
104             /// <summary>
105             /// 2.5G EDGE network type
106             /// </summary>
107             Edge,
108             /// <summary>
109             /// 3G UMTS network type
110             /// </summary>
111             Umts,
112             /// <summary>
113             /// HSDPA network type
114             /// </summary>
115             Hsdpa,
116             /// <summary>
117             /// LTE network type
118             /// </summary>
119             Lte,
120             /// <summary>
121             /// IS95A network type
122             /// </summary>
123             Is95a,
124             /// <summary>
125             /// IS95B network type
126             /// </summary>
127             Is95b,
128             /// <summary>
129             /// CDMA 1x network type
130             /// </summary>
131             Cdma1X,
132             /// <summary>
133             /// EVDO revision 0 network type
134             /// </summary>
135             EvdoRev0,
136             /// <summary>
137             /// EVDO revision A network type
138             /// </summary>
139             EvdoRevA,
140             /// <summary>
141             /// EVDO revision B network type
142             /// </summary>
143             EvdoRevB,
144             /// <summary>
145             /// EVDV network type
146             /// </summary>
147             Evdv,
148             /// <summary>
149             /// EHRPD network type
150             /// </summary>
151             Ehrpd
152         }
153
154         /// <summary>
155         /// Enumeration for PS Type.
156         /// </summary>
157         public enum PsType
158         {
159             /// <summary>
160             /// Unknown
161             /// </summary>
162             Unknown,
163             /// <summary>
164             /// HSDPA ps type
165             /// </summary>
166             Hsdpa,
167             /// <summary>
168             /// HSUPA ps type
169             /// </summary>
170             Hsupa,
171             /// <summary>
172             /// HSPA ps type
173             /// </summary>
174             Hspa,
175             /// <summary>
176             /// HSPAP ps type
177             /// </summary>
178             Hspap
179         }
180
181         /// <summary>
182         /// Enumeration for Network Service State.
183         /// </summary>
184         public enum ServiceState
185         {
186             /// <summary>
187             /// In service
188             /// </summary>
189             InService,
190             /// <summary>
191             /// Out of service
192             /// </summary>
193             OutOfService,
194             /// <summary>
195             /// Only emergency call is allowed
196             /// </summary>
197             EmergencyOnly,
198             /// <summary>
199             /// Unavailable
200             /// </summary>
201             Unavailable
202         }
203
204         /// <summary>
205         /// Enumeration for Network Name Priority.
206         /// </summary>
207         public enum NameOption
208         {
209             /// <summary>
210             /// Unknown
211             /// </summary>
212             Unknown,
213             /// <summary>
214             /// Network name displayed by SPN
215             /// </summary>
216             Spn,
217             /// <summary>
218             /// Network name displayed by Network
219             /// </summary>
220             Network,
221             /// <summary>
222             /// Network name displayed by SPN or Network
223             /// </summary>
224             Any
225         }
226
227         /// <summary>
228         /// Enumeration for the possible 'default' Data Subscriptions for Packet Switched(PS).
229         /// </summary>
230         public enum DefaultDataSubscription
231         {
232             /// <summary>
233             /// Unknown status
234             /// </summary>
235             Unknown = -1,
236             /// <summary>
237             /// SIM 1
238             /// </summary>
239             Sim1,
240             /// <summary>
241             /// SIM 2
242             /// </summary>
243             Sim2
244         }
245
246         /// <summary>
247         /// Enumeration defines possible 'default' Subscriptions for Circuit Switched(CS).
248         /// </summary>
249         public enum DefaultSubscription
250         {
251             /// <summary>
252             /// Unknown status
253             /// </summary>
254             Unknown = -1,
255             /// <summary>
256             /// SIM 1 network
257             /// </summary>
258             Sim1,
259             /// <summary>
260             /// SIM 2 network
261             /// </summary>
262             Sim2
263         }
264
265         /// <summary>
266         /// Enumeration for network selection mode.
267         /// </summary>
268         public enum SelectionMode
269         {
270             /// <summary>
271             /// Automatic mode
272             /// </summary>
273             Automatic,
274             /// <summary>
275             /// Manual mode
276             /// </summary>
277             Manual,
278             /// <summary>
279             /// Unavailable
280             /// </summary>
281             Unavailable
282         }
283
284         /// <summary>
285         /// Gets the LAC (Location Area Code) of the current location.
286         /// </summary>
287         /// <priviledge>
288         /// http://tizen.org/privilege/location.coarse
289         /// </priviledge>
290         /// <remarks>
291         /// This API can be used in GSM / WCDMA network.
292         /// </remarks>
293         /// <returns>
294         /// The Location Area Code, -1 if unknown
295         /// </returns>
296         public int Lac
297         {
298             get
299             {
300                 int lac;
301                 TelephonyError error = Interop.Network.GetLac(_handle, out lac);
302                 if (error != TelephonyError.None)
303                 {
304                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetLac Failed with error " + error);
305                     return -1;
306                 }
307
308                 Log.Info(Interop.Telephony.LogTag, "Lac Value " + lac);
309                 return lac;
310             }
311
312         }
313
314         /// <summary>
315         /// Gets the cell ID of the current location.
316         /// </summary>
317         /// <priviledge>
318         /// http://tizen.org/privilege/location.coarse
319         /// </priviledge>
320         /// <remarks>
321         /// This API can be used in GSM / WCDMA / LTE network.
322         /// </remarks>
323         /// <returns>
324         /// The cell identification number, -1 if unknown
325         /// </returns>
326         public int CellId
327         {
328             get
329             {
330                 int cellId;
331                 TelephonyError error = Interop.Network.GetCellId(_handle, out cellId);
332                 if (error != TelephonyError.None)
333                 {
334                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetCellId Failed with error " + error);
335                     return -1;
336                 }
337
338                 Log.Info(Interop.Telephony.LogTag, "CellId Value " + cellId);
339                 return cellId;
340             }
341         }
342
343         /// <summary>
344         /// Gets the RSSI (Received Signal Strength Indicator).
345         /// </summary>
346         /// <priviledge>
347         /// http://tizen.org/privilege/telephony
348         /// </priviledge>
349         /// <returns>
350         /// The Received Signal Strength Indicator
351         /// Higher the received number, the stronger the signal strength.
352         /// </returns>
353         public Rssi CurrentRssi
354         {
355             get
356             {
357                 Rssi currentRssi;
358                 TelephonyError error = Interop.Network.GetRssi(_handle, out currentRssi);
359                 if (error != TelephonyError.None)
360                 {
361                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetRssi Failed with error " + error);
362                     return Rssi.Unavailable;
363                 }
364
365                 Log.Info(Interop.Telephony.LogTag, "CurrentRssi Value " + currentRssi);
366                 return currentRssi;
367             }
368         }
369
370         /// <summary>
371         /// Gets the roaming state of the current registered network.
372         /// </summary>
373         /// <priviledge>
374         /// http://tizen.org/privilege/telephony
375         /// </priviledge>
376         /// <returns>
377         /// true if roaming, otherwise false if not roaming
378         /// </returns>
379         public bool RoamingStatus
380         {
381             get
382             {
383                 bool roamingStatus;
384                 TelephonyError error = Interop.Network.GetRoamingStatus(_handle, out roamingStatus);
385                 if (error != TelephonyError.None)
386                 {
387                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetRoamingStatus Failed with error " + error);
388                     return false;
389                 }
390
391                 return roamingStatus;
392             }
393         }
394
395         /// <summary>
396         /// Gets the MCC (Mobile Country Code) of the current registered network.
397         /// </summary>
398         /// <priviledge>
399         /// http://tizen.org/privilege/telephony
400         /// </priviledge>
401         /// <remarks>
402         /// This API can be used in GSM / WCDMA / LTE network.
403         /// </remarks>
404         /// <returns>
405         /// The Mobile Country Code (three digits) Mobile Country Code (MCC) identifies the country where the cell is being used.
406         /// empty string if unknown.
407         /// </returns>
408         public string Mcc
409         {
410             get
411             {
412                 string mcc;
413                 TelephonyError error = Interop.Network.GetMcc(_handle, out mcc);
414                 if (error != TelephonyError.None)
415                 {
416                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetMcc Failed with error " + error);
417                     return "";
418                 }
419
420                 return mcc;
421             }
422         }
423
424         /// <summary>
425         /// Gets the MNC (Mobile Network Code) of the current registered network.
426         /// </summary>
427         /// <priviledge>
428         /// http://tizen.org/privilege/telephony
429         /// </priviledge>
430         /// <remarks>
431         /// This API can be used in GSM / WCDMA / LTE network.
432         /// </remarks>
433         /// <returns>
434         /// The Mobile Network Code (three digits) The Mobile Network Code (MNC) identifies the mobile phone operator and network provider.
435         /// empty string if unknown.
436         /// </returns>
437         public string Mnc
438         {
439             get
440             {
441                 string mnc;
442                 TelephonyError error = Interop.Network.GetMnc(_handle, out mnc);
443                 if (error != TelephonyError.None)
444                 {
445                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetMnc Failed with error " + error);
446                     return "";
447                 }
448
449                 return mnc;
450             }
451         }
452
453         /// <summary>
454         /// Gets the name of the current registered network.
455         /// </summary>
456         /// <priviledge>
457         /// http://tizen.org/privilege/telephony
458         /// </priviledge>
459         /// <remarks>
460         /// This API can be used in GSM / WCDMA / LTE network.
461         /// </remarks>
462         /// <returns>
463         /// The name of the current registered network
464         /// empty string if unknown.
465         /// </returns>
466         public string NetworkName
467         {
468             get
469             {
470                 string networkName;
471                 TelephonyError error = Interop.Network.GetNetworkName(_handle, out networkName);
472                 if (error != TelephonyError.None)
473                 {
474                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetNetworkName Failed with error " + error);
475                     return "";
476                 }
477
478                 return networkName;
479             }
480         }
481
482         /// <summary>
483         /// Gets the network service type of the current registered network.
484         /// </summary>
485         /// <priviledge>
486         /// http://tizen.org/privilege/telephony
487         /// </priviledge>
488         /// <remarks>
489         /// This API can be used in case network is in service.
490         /// </remarks>
491         /// <returns>
492         /// The network service type
493         /// </returns>
494         public Type NetworkType
495         {
496             get
497             {
498                 Type networkType;
499                 TelephonyError error = Interop.Network.GetType(_handle, out networkType);
500                 if (error != TelephonyError.None)
501                 {
502                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetType Failed with error " + error);
503                     return Type.Unknown;
504                 }
505
506                 return networkType;
507             }
508         }
509
510         /// <summary>
511         /// Gets the packet service type of the current registered network.
512         /// </summary>
513         /// <priviledge>
514         /// http://tizen.org/privilege/telephony
515         /// </priviledge>
516         /// <remarks>
517         /// This API can be used in HSDPA network.
518         /// </remarks>
519         /// <returns>
520         /// The type of packet service
521         /// </returns>
522         public PsType NetworkPsType
523         {
524             get
525             {
526                 PsType networkPsType;
527                 TelephonyError error = Interop.Network.GetPsType(_handle, out networkPsType);
528                 if (error != TelephonyError.None)
529                 {
530                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetPsType Failed with error " + error);
531                     return PsType.Unknown;
532                 }
533
534                 return networkPsType;
535             }
536
537         }
538
539         /// <summary>
540         /// Gets the network name option of the current registered network.
541         /// </summary>
542         /// <priviledge>
543         /// http://tizen.org/privilege/telephony
544         /// </priviledge>
545         /// <returns>
546         /// The network name display option
547         /// </returns>
548         public NameOption NetworkNameOption
549         {
550             get
551             {
552                 NameOption networkNameOption;
553                 TelephonyError error = Interop.Network.GetNetworkNameOption(_handle, out networkNameOption);
554                 if (error != TelephonyError.None)
555                 {
556                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetNetworkNameOption Failed with error " + error);
557                     return NameOption.Unknown;
558                 }
559
560                 return networkNameOption;
561             }
562
563         }
564
565         /// <summary>
566         /// Gets the current network state of the telephony service.
567         /// </summary>
568         /// <priviledge>
569         /// http://tizen.org/privilege/telephony
570         /// </priviledge>
571         /// <returns>
572         /// The current network state
573         /// </returns>
574         public ServiceState NetworkServiceState
575         {
576             get
577             {
578                 ServiceState networkServiceState;
579                 TelephonyError error = Interop.Network.GetServiceState(_handle, out networkServiceState);
580                 if (error != TelephonyError.None)
581                 {
582                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetServiceState Failed with error " + error);
583                     return ServiceState.Unavailable;
584                 }
585
586                 return networkServiceState;
587             }
588
589         }
590
591         /// <summary>
592         /// Gets the current default subscription for data service (Packet Switched).
593         /// </summary>
594         /// <priviledge>
595         /// http://tizen.org/privilege/telephony
596         /// </priviledge>
597         /// <returnns>
598         /// The current default data subscription
599         /// </returnns>
600         public DefaultDataSubscription NetworkDefaultDataSubscription
601         {
602             get
603             {
604                 DefaultDataSubscription networkDefaultDataSubs;
605                 TelephonyError error = Interop.Network.GetDefaultDataSubscription(_handle, out networkDefaultDataSubs);
606                 if (error != TelephonyError.None)
607                 {
608                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetDefaultDataSubscription Failed with error " + error);
609                     return DefaultDataSubscription.Unknown;
610                 }
611
612                 return networkDefaultDataSubs;
613             }
614
615         }
616
617         /// <summary>
618         /// Gets the current default subscription for voice service (Circuit Switched).
619         /// </summary>
620         /// <priviledge>
621         /// http://tizen.org/privilege/telephony
622         /// </priviledge>
623         /// <returnns>
624         /// The current default voice subscription
625         /// </returnns>
626         public DefaultSubscription NetworkDefaultSubscription
627         {
628             get
629             {
630                 DefaultSubscription networkDefaultSubscription;
631                 TelephonyError error = Interop.Network.GetDefaultSubscription(_handle, out networkDefaultSubscription);
632                 if (error != TelephonyError.None)
633                 {
634                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetDefaultSubscription Failed with error " + error);
635                     return DefaultSubscription.Unknown;
636                 }
637
638                 return networkDefaultSubscription;
639             }
640
641         }
642
643         /// <summary>
644         /// Gets the network selection mode.
645         /// </summary>
646         /// <priviledge>
647         /// http://tizen.org/privilege/telephony
648         /// </priviledge>
649         /// <returns>
650         /// The network selection mode.
651         /// </returns>
652         public SelectionMode NetworkSelectionMode
653         {
654             get
655             {
656                 SelectionMode networkSelectionMode;
657                 TelephonyError error = Interop.Network.GetSelectionMode(_handle, out networkSelectionMode);
658                 if (error != TelephonyError.None)
659                 {
660                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetSelectionMode Failed with error " + error);
661                     return SelectionMode.Unavailable;
662                 }
663
664                 return networkSelectionMode;
665             }
666
667         }
668
669         /// <summary>
670         /// Gets the TAC (Tracking Area Code) of the current location.
671         /// </summary>
672         /// <priviledge>
673         /// http://tizen.org/privilege/telephony
674         /// </priviledge>
675         /// <remarks>
676         /// This API can be used in LTE network.
677         /// </remarks>
678         /// <returns>
679         /// The Tracking Area Code
680         /// -1 if unknown
681         /// </returns>
682         public int Tac
683         {
684             get
685             {
686                 int tac;
687                 TelephonyError error = Interop.Network.GetTac(_handle, out tac);
688                 if (error != TelephonyError.None)
689                 {
690                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetTac Failed with error " + error);
691                     return -1;
692                 }
693
694                 return tac;
695             }
696
697         }
698
699         /// <summary>
700         /// Gets the system ID of the current location.
701         /// </summary>
702         /// <priviledge>
703         /// http://tizen.org/privilege/telephony
704         /// </priviledge>
705         /// <remarks>
706         /// This API can be used in CDMA network.
707         /// </remarks>
708         /// <returns>
709         /// The system ID
710         /// -1 if unknown
711         /// </returns>
712         public int SystemId
713         {
714             get
715             {
716                 int systemId;
717                 TelephonyError error = Interop.Network.GetSystemId(_handle, out systemId);
718                 if (error != TelephonyError.None)
719                 {
720                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetSystemId Failed with error " + error);
721                     return -1;
722                 }
723
724                 return systemId;
725             }
726
727         }
728
729         /// <summary>
730         /// Gets the network ID of the current location.
731         /// </summary>
732         /// <priviledge>
733         /// http://tizen.org/privilege/location.coarse
734         /// </priviledge>
735         /// <remarks>
736         /// This API can be used in CDMA network.
737         /// </remarks>
738         /// <returns>
739         /// The network ID
740         /// -1 if unknown
741         /// </returns>
742         public int NetworkId
743         {
744             get
745             {
746                 int networkId;
747                 TelephonyError error = Interop.Network.GetNetworkId(_handle, out networkId);
748                 if (error != TelephonyError.None)
749                 {
750                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetNetworkId Failed with error " + error);
751                     return -1;
752                 }
753
754                 return networkId;
755             }
756
757         }
758
759         /// <summary>
760         /// Gets the base station ID of the current location.
761         /// </summary>
762         /// <priviledge>
763         /// http://tizen.org/privilege/location.coarse
764         /// </priviledge>
765         /// <remarks>
766         /// This API can be used in CDMA network.
767         /// </remarks>
768         /// <returns>
769         /// The base station ID
770         /// -1 if unknown
771         /// </returns>
772
773         public int BaseStationId
774         {
775             get
776             {
777                 int baseStationId;
778                 TelephonyError error = Interop.Network.GetBaseStationId(_handle, out baseStationId);
779                 if (error != TelephonyError.None)
780                 {
781                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetBaseStationId Failed with error " + error);
782                     return -1;
783                 }
784
785                 return baseStationId;
786             }
787
788         }
789
790         /// <summary>
791         /// Gets the base station latitude of the current location.
792         /// </summary>
793         /// <priviledge>
794         /// http://tizen.org/privilege/location.coarse
795         /// </priviledge>
796         /// <remarks>
797         /// This API can be used in CDMA network.
798         /// </remarks>
799         /// <returns>
800         /// The base station latitude
801         /// 0x7FFFFFFF if unknown
802         /// </returns>
803         public int BaseStationLatitude
804         {
805             get
806             {
807                 int baseStationLatitude;
808                 TelephonyError error = Interop.Network.GetBaseStationLatitude(_handle, out baseStationLatitude);
809                 if (error != TelephonyError.None)
810                 {
811                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetBaseStationLatitude Failed with error " + error);
812                     return 0x7FFFFFFF;
813                 }
814
815                 return baseStationLatitude;
816             }
817         }
818
819         /// <summary>
820         /// Gets the base station longitude of the current location.
821         /// </summary>
822         /// <priviledge>
823         /// http://tizen.org/privilege/location.coarse
824         /// </priviledge>
825         /// <remarks>
826         /// This API can be used in CDMA network.
827         /// </remarks>
828         /// <returns>
829         /// The base station latitude
830         /// 0x7FFFFFFF if unknown
831         /// </returns>
832         public int BaseStationLongitude
833         {
834             get
835             {
836                 int baseStationLongitude;
837                 TelephonyError error = Interop.Network.GetBaseStationLongitude(_handle, out baseStationLongitude);
838                 if (error != TelephonyError.None)
839                 {
840                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetBaseStationLongitude Failed with error " + error);
841                     return 0x7FFFFFFF;
842                 }
843
844                 return baseStationLongitude;
845             }
846         }
847     }
848 }