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