ca24fc10082afa53bbd2aa67b032d0aae89e7bf4
[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 "FTel_SimInfoImpl.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Security;
29
30 namespace Tizen { namespace Telephony
31 {
32 SimInfo::SimInfo(void)
33         : __pSimInfoImpl(null)
34 {
35 }
36
37 SimInfo::SimInfo(const SimInfo& rhs)
38         : __pSimInfoImpl(null)
39 {
40         __pSimInfoImpl = new (std::nothrow)_SimInfoImpl(*rhs.__pSimInfoImpl);
41         SysTryReturnVoidResult(NID_TEL, __pSimInfoImpl, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
42 }
43
44 SimInfo::~SimInfo(void)
45 {
46         delete __pSimInfoImpl;
47 }
48
49
50 result
51 SimInfo::Construct(void)
52 {
53         SysAssertf(__pSimInfoImpl == null,
54                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
55
56         result r = E_SUCCESS;
57
58         __pSimInfoImpl = new (std::nothrow)_SimInfoImpl();
59         SysTryReturnResult(NID_TEL, __pSimInfoImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed");
60
61         r = __pSimInfoImpl->Construct();
62
63         if (r != E_SUCCESS)
64         {
65                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
66                 delete __pSimInfoImpl;
67                 __pSimInfoImpl = null;
68         }
69
70         return r;
71 }
72
73 int
74 SimInfo::GetMnc(void) const
75 {
76         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
77
78         ClearLastResult();
79
80         int mnc = -1;
81         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
82
83         SysTryReturn(NID_TEL, r == E_SUCCESS, mnc, E_PRIVILEGE_DENIED,
84                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
85
86         mnc = __pSimInfoImpl->GetMnc();
87
88         r = GetLastResult();
89
90         SysTryReturn(NID_TEL, r == E_SUCCESS, mnc, r, "[%s] Propagating.", GetErrorMessage(r));
91
92         return mnc;
93 }
94
95 int
96 SimInfo::GetMcc(void) const
97 {
98         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
99
100         ClearLastResult();
101
102         int mcc = -1;
103         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
104
105         SysTryReturn(NID_TEL, r == E_SUCCESS, mcc, E_PRIVILEGE_DENIED,
106                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
107
108         mcc = __pSimInfoImpl->GetMcc();
109
110         r = GetLastResult();
111
112         SysTryReturn(NID_TEL, r == E_SUCCESS, mcc, r, "[%s] Propagating.", GetErrorMessage(r));
113
114         return mcc;
115 }
116
117 String
118 SimInfo::GetSpn(void) const
119 {
120         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
121
122         ClearLastResult();
123
124         String spn;
125         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
126
127         SysTryReturn(NID_TEL, r == E_SUCCESS, spn, E_PRIVILEGE_DENIED,
128                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
129
130         spn = __pSimInfoImpl->GetSpn();
131
132         r = GetLastResult();
133
134         SysTryReturn(NID_TEL, r == E_SUCCESS, spn, r, "[%s] Propagating.", GetErrorMessage(r));
135
136         return spn;
137 }
138
139 String
140 SimInfo::GetIccId(void) const
141 {
142         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
143
144         ClearLastResult();
145
146         String iccId;
147         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
148
149         SysTryReturn(NID_TEL, r == E_SUCCESS, iccId, E_PRIVILEGE_DENIED,
150                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
151
152         iccId = __pSimInfoImpl->GetIccId();
153
154         r = GetLastResult();
155
156         SysTryReturn(NID_TEL, r == E_SUCCESS, iccId, r, "[%s] Propagating.", GetErrorMessage(r));
157
158         return iccId;
159 }
160
161 String
162 SimInfo::GetOperatorName(void) const
163 {
164         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
165
166         ClearLastResult();
167
168         String operatorName;
169         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
170
171         SysTryReturn(NID_TEL, r == E_SUCCESS, operatorName, E_PRIVILEGE_DENIED,
172                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
173
174         operatorName = __pSimInfoImpl->GetOperatorName();
175
176         r = GetLastResult();
177
178         SysTryReturn(NID_TEL, r == E_SUCCESS, operatorName, r, "[%s] Propagating.", GetErrorMessage(r));
179
180         return operatorName;
181 }
182
183 String
184 SimInfo::GetPhoneNumber(void) const
185 {
186         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
187
188         ClearLastResult();
189
190         String phoneNumber;
191         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
192
193         SysTryReturn(NID_TEL, r == E_SUCCESS, phoneNumber, E_PRIVILEGE_DENIED,
194                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
195
196         phoneNumber = __pSimInfoImpl->GetPhoneNumber();
197
198         r = GetLastResult();
199
200         SysTryReturn(NID_TEL, r == E_SUCCESS, phoneNumber, r, "[%s] Propagating.", GetErrorMessage(r));
201
202         return phoneNumber;
203 }
204
205 String
206 SimInfo::GetImsi(void) const
207 {
208         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
209
210         ClearLastResult();
211
212         String imsi;
213
214         imsi = __pSimInfoImpl->GetImsi();
215
216         result r = GetLastResult();
217
218         if (r == E_PRIVILEGE_DENIED)
219         {
220                 SysLogException(NID_TEL, E_PRIVILEGE_DENIED,"[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
221         }
222         else if(r != E_SUCCESS)
223         {
224                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
225         }
226
227         return imsi;
228 }
229
230 SimType
231 SimInfo::GetSimType(void) const
232 {
233         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
234
235         ClearLastResult();
236
237         result r = _AccessController::CheckUserPrivilege(_PRV_TELEPHONY);
238         SysTryReturn(NID_TEL, r == E_SUCCESS, SIM_TYPE_UNKNOWN, E_PRIVILEGE_DENIED,
239                         "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
240
241         return __pSimInfoImpl->GetSimType();
242 }
243
244 bool
245 SimInfo::IsAvailable(void) const
246 {
247         SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
248
249         ClearLastResult();
250
251         bool isAvailable = false;
252         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
253
254         SysTryReturn(NID_TEL, r == E_SUCCESS, isAvailable, E_PRIVILEGE_DENIED,
255                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
256
257         isAvailable = __pSimInfoImpl->IsAvailable();
258
259         return isAvailable;
260 }
261
262 SimInfo&
263 SimInfo::operator =(const SimInfo& rhs)
264 {
265     if (this != &rhs)
266     {
267         *__pSimInfoImpl = *rhs.__pSimInfoImpl;
268     }
269
270     return *this;
271 }
272
273 bool
274 SimInfo::Equals(const Object& rhs) const
275 {
276         const SimInfo* pRhs = dynamic_cast<const SimInfo*>(&rhs);
277
278         if (pRhs == null)
279         {
280                 return false;
281         }
282
283         const _SimInfoImpl* pRhsImpl = _SimInfoImpl::GetInstance(*pRhs);
284
285         if (pRhsImpl == null)
286         {
287                 return false;
288         }
289
290         return __pSimInfoImpl->Equals(*pRhsImpl);
291 }
292
293 int
294 SimInfo::GetHashCode(void) const
295 {
296         return __pSimInfoImpl->GetHashCode();
297 }
298
299 } } // Tizen::Telephony