Add '-D_SECURE_LOG'
[platform/framework/native/telephony.git] / src / FTelSimInfo.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        FTelSimInfo.cpp
19  * @brief       This is the implementation file for SimInfo class.
20  */
21
22 #include <FTelSimInfo.h>
23 #include <FBaseSysLog.h>
24 #include <FSec_AccessController.h>
25 #include <FSys_SystemInfoImpl.h>
26 #include "FTel_SimInfoImpl.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Security;
30 using namespace Tizen::System;
31
32 namespace Tizen { namespace Telephony
33 {
34 SimInfo::SimInfo(void)
35         : __pSimInfoImpl(null)
36 {
37 }
38
39 SimInfo::SimInfo(const SimInfo& rhs)
40         : __pSimInfoImpl(null)
41 {
42         __pSimInfoImpl = new (std::nothrow)_SimInfoImpl(*rhs.__pSimInfoImpl);
43         SysTryReturnVoidResult(NID_TEL, __pSimInfoImpl, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
44 }
45
46 SimInfo::~SimInfo(void)
47 {
48         delete __pSimInfoImpl;
49 }
50
51
52 result
53 SimInfo::Construct(void)
54 {
55         static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
56
57         SysAssertf(__pSimInfoImpl == null,
58                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
59
60         result r = E_SUCCESS;
61         bool isTelephonySupported = false;
62
63     r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
64     SysTryReturnResult(NID_TEL, r == E_SUCCESS && isTelephonySupported, E_UNSUPPORTED_OPERATION, "Telephony is not supported.");
65
66         __pSimInfoImpl = new (std::nothrow)_SimInfoImpl();
67         SysTryReturnResult(NID_TEL, __pSimInfoImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed");
68
69         r = __pSimInfoImpl->Construct();
70
71         if (r != E_SUCCESS)
72         {
73                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
74                 delete __pSimInfoImpl;
75                 __pSimInfoImpl = null;
76         }
77
78         return r;
79 }
80
81 int
82 SimInfo::GetMnc(void) const
83 {
84         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
85
86         ClearLastResult();
87
88         int mnc = -1;
89         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
90
91         SysTryReturn(NID_TEL, r == E_SUCCESS, mnc, E_PRIVILEGE_DENIED,
92                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
93
94         mnc = __pSimInfoImpl->GetMnc();
95
96         r = GetLastResult();
97
98         SysTryReturn(NID_TEL, r == E_SUCCESS, mnc, r, "[%s] Propagating.", GetErrorMessage(r));
99
100         return mnc;
101 }
102
103 int
104 SimInfo::GetMcc(void) const
105 {
106         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
107
108         ClearLastResult();
109
110         int mcc = -1;
111         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
112
113         SysTryReturn(NID_TEL, r == E_SUCCESS, mcc, E_PRIVILEGE_DENIED,
114                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
115
116         mcc = __pSimInfoImpl->GetMcc();
117
118         r = GetLastResult();
119
120         SysTryReturn(NID_TEL, r == E_SUCCESS, mcc, r, "[%s] Propagating.", GetErrorMessage(r));
121
122         return mcc;
123 }
124
125 String
126 SimInfo::GetSpn(void) const
127 {
128         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
129
130         ClearLastResult();
131
132         String spn;
133         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
134
135         SysTryReturn(NID_TEL, r == E_SUCCESS, spn, E_PRIVILEGE_DENIED,
136                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
137
138         spn = __pSimInfoImpl->GetSpn();
139
140         r = GetLastResult();
141
142         SysTryReturn(NID_TEL, r == E_SUCCESS, spn, r, "[%s] Propagating.", GetErrorMessage(r));
143
144         return spn;
145 }
146
147 String
148 SimInfo::GetIccId(void) const
149 {
150         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
151
152         ClearLastResult();
153
154         String iccId;
155         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
156
157         SysTryReturn(NID_TEL, r == E_SUCCESS, iccId, E_PRIVILEGE_DENIED,
158                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
159
160         iccId = __pSimInfoImpl->GetIccId();
161
162         r = GetLastResult();
163
164         SysTryReturn(NID_TEL, r == E_SUCCESS, iccId, r, "[%s] Propagating.", GetErrorMessage(r));
165
166         return iccId;
167 }
168
169 String
170 SimInfo::GetOperatorName(void) const
171 {
172         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
173
174         ClearLastResult();
175
176         String operatorName;
177         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
178
179         SysTryReturn(NID_TEL, r == E_SUCCESS, operatorName, E_PRIVILEGE_DENIED,
180                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
181
182         operatorName = __pSimInfoImpl->GetOperatorName();
183
184         r = GetLastResult();
185
186         SysTryReturn(NID_TEL, r == E_SUCCESS, operatorName, r, "[%s] Propagating.", GetErrorMessage(r));
187
188         return operatorName;
189 }
190
191 String
192 SimInfo::GetPhoneNumber(void) const
193 {
194         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
195
196         ClearLastResult();
197
198         String phoneNumber;
199         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
200
201         SysTryReturn(NID_TEL, r == E_SUCCESS, phoneNumber, E_PRIVILEGE_DENIED,
202                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
203
204         phoneNumber = __pSimInfoImpl->GetPhoneNumber();
205
206         r = GetLastResult();
207
208         SysTryReturn(NID_TEL, r == E_SUCCESS, phoneNumber, r, "[%s] Propagating.", GetErrorMessage(r));
209
210         return phoneNumber;
211 }
212
213 String
214 SimInfo::GetImsi(void) const
215 {
216         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
217
218         ClearLastResult();
219
220         String imsi;
221
222         imsi = __pSimInfoImpl->GetImsi();
223
224         result r = GetLastResult();
225
226         if (r == E_PRIVILEGE_DENIED)
227         {
228                 SysLogException(NID_TEL, E_PRIVILEGE_DENIED,"[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
229         }
230         else if(r != E_SUCCESS)
231         {
232                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
233         }
234
235         return imsi;
236 }
237
238 SimType
239 SimInfo::GetSimType(void) const
240 {
241         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
242
243         ClearLastResult();
244
245         result r = _AccessController::CheckUserPrivilege(_PRV_TELEPHONY);
246         SysTryReturn(NID_TEL, r == E_SUCCESS, SIM_TYPE_UNKNOWN, E_PRIVILEGE_DENIED,
247                         "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
248
249         return __pSimInfoImpl->GetSimType();
250 }
251
252 bool
253 SimInfo::IsAvailable(void) const
254 {
255         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
256
257         ClearLastResult();
258
259         bool isAvailable = false;
260         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
261
262         SysTryReturn(NID_TEL, r == E_SUCCESS, isAvailable, E_PRIVILEGE_DENIED,
263                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
264
265         isAvailable = __pSimInfoImpl->IsAvailable();
266
267         return isAvailable;
268 }
269
270 SimInfo&
271 SimInfo::operator =(const SimInfo& rhs)
272 {
273     if (this != &rhs)
274     {
275         if (rhs.__pSimInfoImpl != null)
276         {
277                 if (__pSimInfoImpl != null)
278                 {
279                                 *__pSimInfoImpl = *rhs.__pSimInfoImpl;
280                 }
281                 else
282                 {
283                         __pSimInfoImpl = new (std::nothrow) _SimInfoImpl(*rhs.__pSimInfoImpl);
284                 }
285         }
286         else
287         {
288                 delete __pSimInfoImpl;
289                 __pSimInfoImpl = null;
290         }
291     }
292
293     return *this;
294 }
295
296 bool
297 SimInfo::Equals(const Object& rhs) const
298 {
299         const SimInfo* pRhs = dynamic_cast<const SimInfo*>(&rhs);
300
301         if (pRhs == null)
302         {
303                 return false;
304         }
305
306         const _SimInfoImpl* pRhsImpl = _SimInfoImpl::GetInstance(*pRhs);
307
308         if (pRhsImpl == null)
309         {
310                 return false;
311         }
312
313         return __pSimInfoImpl->Equals(*pRhsImpl);
314 }
315
316 int
317 SimInfo::GetHashCode(void) const
318 {
319         return __pSimInfoImpl->GetHashCode();
320 }
321
322 } } // Tizen::Telephony