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 <FSys_SystemInfoImpl.h>
26 #include "FTel_SimInfoImpl.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Security;
30 using namespace Tizen::System;
32 namespace Tizen { namespace Telephony
34 SimInfo::SimInfo(void)
35 : __pSimInfoImpl(null)
39 SimInfo::SimInfo(const SimInfo& rhs)
40 : __pSimInfoImpl(null)
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));
46 SimInfo::~SimInfo(void)
48 delete __pSimInfoImpl;
53 SimInfo::Construct(void)
55 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
57 SysAssertf(__pSimInfoImpl == null,
58 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
61 bool isTelephonySupported = false;
63 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
64 SysTryReturnResult(NID_TEL, r == E_SUCCESS && isTelephonySupported, E_UNSUPPORTED_OPERATION, "Telephony is not supported.");
66 __pSimInfoImpl = new (std::nothrow)_SimInfoImpl();
67 SysTryReturnResult(NID_TEL, __pSimInfoImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed");
69 r = __pSimInfoImpl->Construct();
73 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
74 delete __pSimInfoImpl;
75 __pSimInfoImpl = null;
82 SimInfo::GetMnc(void) const
84 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
89 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
94 mnc = __pSimInfoImpl->GetMnc();
98 SysTryReturn(NID_TEL, r == E_SUCCESS, mnc, r, "[%s] Propagating.", GetErrorMessage(r));
104 SimInfo::GetMcc(void) const
106 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
111 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
116 mcc = __pSimInfoImpl->GetMcc();
120 SysTryReturn(NID_TEL, r == E_SUCCESS, mcc, r, "[%s] Propagating.", GetErrorMessage(r));
126 SimInfo::GetSpn(void) const
128 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
133 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
138 spn = __pSimInfoImpl->GetSpn();
142 SysTryReturn(NID_TEL, r == E_SUCCESS, spn, r, "[%s] Propagating.", GetErrorMessage(r));
148 SimInfo::GetIccId(void) const
150 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
155 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
160 iccId = __pSimInfoImpl->GetIccId();
164 SysTryReturn(NID_TEL, r == E_SUCCESS, iccId, r, "[%s] Propagating.", GetErrorMessage(r));
170 SimInfo::GetOperatorName(void) const
172 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
177 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
182 operatorName = __pSimInfoImpl->GetOperatorName();
186 SysTryReturn(NID_TEL, r == E_SUCCESS, operatorName, r, "[%s] Propagating.", GetErrorMessage(r));
192 SimInfo::GetPhoneNumber(void) const
194 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
199 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
204 phoneNumber = __pSimInfoImpl->GetPhoneNumber();
208 SysTryReturn(NID_TEL, r == E_SUCCESS, phoneNumber, r, "[%s] Propagating.", GetErrorMessage(r));
214 SimInfo::GetImsi(void) const
216 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
222 imsi = __pSimInfoImpl->GetImsi();
224 result r = GetLastResult();
226 if (r == E_PRIVILEGE_DENIED)
228 SysLogException(NID_TEL, E_PRIVILEGE_DENIED,"[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
230 else if(r != E_SUCCESS)
232 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
239 SimInfo::GetSimType(void) const
241 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
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));
249 return __pSimInfoImpl->GetSimType();
253 SimInfo::IsAvailable(void) const
255 SysAssertf(__pSimInfoImpl != null, "Not yet constructed. Construct() should be called before use.");
259 bool isAvailable = false;
260 result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
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));
265 isAvailable = __pSimInfoImpl->IsAvailable();
271 SimInfo::operator =(const SimInfo& rhs)
275 if (rhs.__pSimInfoImpl != null)
277 if (__pSimInfoImpl != null)
279 *__pSimInfoImpl = *rhs.__pSimInfoImpl;
283 __pSimInfoImpl = new (std::nothrow) _SimInfoImpl(*rhs.__pSimInfoImpl);
288 delete __pSimInfoImpl;
289 __pSimInfoImpl = null;
297 SimInfo::Equals(const Object& rhs) const
299 const SimInfo* pRhs = dynamic_cast<const SimInfo*>(&rhs);
306 const _SimInfoImpl* pRhsImpl = _SimInfoImpl::GetInstance(*pRhs);
308 if (pRhsImpl == null)
313 return __pSimInfoImpl->Equals(*pRhsImpl);
317 SimInfo::GetHashCode(void) const
319 return __pSimInfoImpl->GetHashCode();
322 } } // Tizen::Telephony