2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FTelSimInfo.cpp
19 * @brief This is the implementation file for SimInfo class.
22 #include <FTelSimInfo.h>
23 #include <FBaseSysLog.h>
24 #include <FSec_AccessController.h>
25 #include "FTel_SimInfoImpl.h"
27 using namespace Tizen::Base;
28 using namespace Tizen::Security;
30 namespace Tizen { namespace Telephony
32 SimInfo::SimInfo(void)
33 : __pSimInfoImpl(null)
37 SimInfo::SimInfo(const SimInfo& rhs)
38 : __pSimInfoImpl(null)
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));
44 SimInfo::~SimInfo(void)
46 delete __pSimInfoImpl;
51 SimInfo::Construct(void)
53 SysAssertf(__pSimInfoImpl == null,
54 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
58 __pSimInfoImpl = new (std::nothrow)_SimInfoImpl();
59 SysTryReturnResult(NID_TEL, __pSimInfoImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed");
61 r = __pSimInfoImpl->Construct();
65 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
66 delete __pSimInfoImpl;
67 __pSimInfoImpl = null;
74 SimInfo::GetMnc(void) const
76 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
81 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
86 mnc = __pSimInfoImpl->GetMnc();
90 SysTryReturn(NID_TEL, r == E_SUCCESS, mnc, r, "[%s] Propagating.", GetErrorMessage(r));
96 SimInfo::GetMcc(void) const
98 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
103 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
108 mcc = __pSimInfoImpl->GetMcc();
112 SysTryReturn(NID_TEL, r == E_SUCCESS, mcc, r, "[%s] Propagating.", GetErrorMessage(r));
118 SimInfo::GetSpn(void) const
120 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
125 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
130 spn = __pSimInfoImpl->GetSpn();
134 SysTryReturn(NID_TEL, r == E_SUCCESS, spn, r, "[%s] Propagating.", GetErrorMessage(r));
140 SimInfo::GetIccId(void) const
142 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
147 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
152 iccId = __pSimInfoImpl->GetIccId();
156 SysTryReturn(NID_TEL, r == E_SUCCESS, iccId, r, "[%s] Propagating.", GetErrorMessage(r));
162 SimInfo::GetOperatorName(void) const
164 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
169 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
174 operatorName = __pSimInfoImpl->GetOperatorName();
178 SysTryReturn(NID_TEL, r == E_SUCCESS, operatorName, r, "[%s] Propagating.", GetErrorMessage(r));
184 SimInfo::GetPhoneNumber(void) const
186 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
191 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
196 phoneNumber = __pSimInfoImpl->GetPhoneNumber();
200 SysTryReturn(NID_TEL, r == E_SUCCESS, phoneNumber, r, "[%s] Propagating.", GetErrorMessage(r));
206 SimInfo::GetImsi(void) const
208 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
214 imsi = __pSimInfoImpl->GetImsi();
216 result r = GetLastResult();
218 if (r == E_PRIVILEGE_DENIED)
220 SysLogException(NID_TEL, E_PRIVILEGE_DENIED,"[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
222 else if(r != E_SUCCESS)
224 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
231 SimInfo::GetSimType(void) const
233 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
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));
241 return __pSimInfoImpl->GetSimType();
245 SimInfo::IsAvailable(void) const
247 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
251 bool isAvailable = false;
252 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
257 isAvailable = __pSimInfoImpl->IsAvailable();
263 SimInfo::operator =(const SimInfo& rhs)
267 *__pSimInfoImpl = *rhs.__pSimInfoImpl;
274 SimInfo::Equals(const Object& rhs) const
276 const SimInfo* pRhs = dynamic_cast<const SimInfo*>(&rhs);
283 const _SimInfoImpl* pRhsImpl = _SimInfoImpl::GetInstance(*pRhs);
285 if (pRhsImpl == null)
290 return __pSimInfoImpl->Equals(*pRhsImpl);
294 SimInfo::GetHashCode(void) const
296 return __pSimInfoImpl->GetHashCode();
299 } } // Tizen::Telephony