Change License under the Apache License.
[platform/core/csapi/telephony.git] / Tizen.Telephony / Tizen.Telephony / Modem.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     /// This Class provides API's to obtain information from the modem.
23     /// </summary>
24     public class Modem
25     {
26         internal IntPtr _handle;
27
28         /// <summary>
29         /// Modem 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 Modem(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 Modem Power Status.
49         /// </summary>
50         public enum PowerStatus
51         {
52             /// <summary>
53             /// Unknown
54             /// </summary>
55             Unknown = -1,
56             /// <summary>
57             /// Modem power ON
58             /// </summary>
59             On,
60             /// <summary>
61             /// Modem power OFF
62             /// </summary>
63             Off,
64             /// <summary>
65             /// Modem power RESET
66             /// </summary>
67             Reset,
68             /// <summary>
69             /// Modem power LOW
70             /// </summary>
71             Low
72         };
73
74         /// <summary>
75         /// Gets the IMEI (International Mobile Station Equipment Identity) of a mobile phone.
76         /// The IMEI number is used by a GSM network to identify valid devices and therefore can be used for stopping a stolen phone from accessing that network.
77         /// </summary>
78         /// <priviledge>
79         /// http://tizen.org/privilege/telephony
80         /// </priviledge>
81         /// <returns>
82         /// The International Mobile Station Equipment Identity
83         /// empty string if unable to complete the operation
84         /// </returns>
85         public string Imei
86         {
87             get
88             {
89                 string imei;
90                 TelephonyError error = Interop.Modem.GetImei(_handle, out imei);
91                 if (error != TelephonyError.None)
92                 {
93                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetImei Failed with error " + error);
94                     return "";
95                 }
96
97                 return imei;
98             }
99         }
100
101         /// <summary>
102         /// Gets the power status of the modem.
103         /// </summary>
104         /// <priviledge>
105         /// http://tizen.org/privilege/telephony
106         /// </priviledge>
107         /// <returns>
108         /// The Modem power status (0=on,1=off,2=reset,3=low)
109         /// </returns>
110         public PowerStatus CurrentPowerStatus
111         {
112             get
113             {
114                 PowerStatus status;
115                 TelephonyError error = Interop.Modem.GetPowerStatus(_handle, out status);
116                 if (error != TelephonyError.None)
117                 {
118                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetImei Failed with error " + error);
119                     return PowerStatus.Unknown;
120                 }
121
122                 return status;
123             }
124
125         }
126
127         /// <summary>
128         /// Gets the MEID (Mobile Equipment Identifier) of a mobile phone. (for CDMA)
129         /// </summary>
130         /// <priviledge>
131         /// http://tizen.org/privilege/telephony
132         /// </priviledge>
133         /// <returns>
134         /// The Mobile Equipment Identifier
135         /// empty string if unable to complete the operation
136         /// </returns>
137         public string Meid
138         {
139             get
140             {
141                 string meid;
142                 TelephonyError error = Interop.Modem.GetMeid(_handle, out meid);
143                 if (error != TelephonyError.None)
144                 {
145                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetMeid Failed with error " + error);
146                     return "";
147                 }
148
149                 return meid;
150             }
151
152         }
153     }
154 }