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 FTel_SimInfoImpl.cpp
19 * @brief This is the implementation file for _SimInfoImpl class.
25 #include <FBaseString.h>
26 #include <FBaseResult.h>
27 #include <unique_ptr.h>
28 #include <FTelSimInfo.h>
29 #include <FBaseSysLog.h>
30 #include "FTel_SimInfoImpl.h"
31 #include "FTel_TelephonyIpcProxy.h"
32 #include "FTel_TelephonyUtility.h"
38 using namespace Tizen::App;
39 using namespace Tizen::Base;
41 namespace Tizen { namespace Telephony
45 _SimInfoImpl::_SimInfoImpl(void)
46 : __isAvailable(false)
50 _SimInfoImpl::_SimInfoImpl(const _SimInfoImpl& rhs)
51 : __isAvailable(rhs.__isAvailable)
55 _SimInfoImpl::~_SimInfoImpl(void)
60 _SimInfoImpl::Construct(void)
62 int err = SIM_ERROR_NONE;
63 sim_state_e simState = SIM_STATE_UNAVAILABLE;
65 err = sim_get_state(&simState);
66 SysLog(NID_TEL, "The return value of sim_get_state() is [0x%x] and the simState is [%d]", err, simState);
68 if (err == SIM_ERROR_NONE && simState == SIM_STATE_AVAILABLE)
73 SysTryReturnResult(NID_TEL, __isAvailable, E_DEVICE_UNAVAILABLE, "The operation failed because the SIM card is not ready.");
79 _SimInfoImpl::GetMnc(void) const
81 int err = SIM_ERROR_NONE;
85 SysTryReturn(NID_TEL, __isAvailable, mnc, E_DEVICE_UNAVAILABLE,
86 "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
88 err = sim_get_mnc(&pMnc);
89 SysLog(NID_TEL, "The return value of sim_get_mnc() is [0x%x] and the mnc value is [%s]", err, pMnc);
90 SysTryReturn(NID_TEL, err == SIM_ERROR_NONE && pMnc != null, mnc, E_DEVICE_UNAVAILABLE,
91 "[%s] The operation failed.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
100 _SimInfoImpl::GetMcc(void) const
102 int err = SIM_ERROR_NONE;
106 SysTryReturn(NID_TEL, __isAvailable, mcc, E_DEVICE_UNAVAILABLE,
107 "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
109 err = sim_get_mcc(&pMcc);
110 SysLog(NID_TEL, "The return value of sim_get_mcc() is [0x%x] and the mcc value is [%s]", err, pMcc);
111 SysTryReturn(NID_TEL, err == SIM_ERROR_NONE && pMcc != null, mcc, E_DEVICE_UNAVAILABLE,
112 "[%s] The operation failed.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
121 _SimInfoImpl::GetSpn(void) const
123 int err = SIM_ERROR_NONE;
127 SysTryReturn(NID_TEL, __isAvailable, spn, E_DEVICE_UNAVAILABLE,
128 "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
130 err = sim_get_spn(&pSpn);
131 SysLog(NID_TEL, "The return value of sim_get_spn() is [0x%x] and the spn value is [%s]", err, pSpn);
132 SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, spn, E_DEVICE_UNAVAILABLE,
133 "[%s] The operation failed.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
146 _SimInfoImpl::GetIccId(void) const
148 int err = SIM_ERROR_NONE;
152 SysTryReturn(NID_TEL, __isAvailable, iccId, E_DEVICE_UNAVAILABLE,
153 "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
155 err = sim_get_icc_id(&pIccId);
156 SysLog(NID_TEL, "The return value of sim_get_icc_id() is [0x%x] and the iccid value is [%s]", err, pIccId);
157 SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, iccId, E_DEVICE_UNAVAILABLE,
158 "[%s] The operation failed.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
160 iccId = String(pIccId);
171 _SimInfoImpl::GetOperatorName(void) const
173 int err = SIM_ERROR_NONE;
174 char* pFullName = null;
175 char* pShortName = null;
178 SysTryReturn(NID_TEL, __isAvailable, operatorName, E_DEVICE_UNAVAILABLE,
179 "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
181 err = sim_get_cphs_operator_name(&pFullName, &pShortName);
182 SysLog(NID_TEL, "The return value of sim_get_cphs_operator_name() is [0x%x]. full[%s] short[%s]", err, pFullName, pShortName);
183 SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, operatorName, E_DEVICE_UNAVAILABLE,
184 "[%s] The operation failed.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
186 if ((pFullName != null) && (strlen(pFullName) > 0))
188 operatorName = String(pFullName);
190 else if ((pShortName != null) && (strlen(pShortName) > 0))
192 operatorName = String(pShortName);
195 if (pFullName != null)
199 if (pShortName != null)
208 _SimInfoImpl::GetPhoneNumber(void) const
210 int err = SIM_ERROR_NONE;
211 char* pPhoneNumber = null;
214 SysTryReturn(NID_TEL, __isAvailable, phoneNumber, E_DEVICE_UNAVAILABLE,
215 "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
217 err = sim_get_subscriber_number(&pPhoneNumber);
218 SysLog(NID_TEL, "The return value of sim_get_subscriber_number() is [0x%x] and the phone number is [%s]", err, pPhoneNumber);
219 SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, phoneNumber, E_DEVICE_UNAVAILABLE,
220 "[%s] The operation failed.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
222 phoneNumber = String(pPhoneNumber);
224 if (pPhoneNumber != null)
233 _SimInfoImpl::GetImsi(void) const
235 result r = E_SUCCESS;
238 SysTryReturn(NID_TEL, __isAvailable, imsi, E_DEVICE_UNAVAILABLE,
239 "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
241 _TelephonyIpcProxy* pTelephonyServiceProxy = _TelephonyIpcProxy::GetInstance();
242 SysTryReturn(NID_TEL, pTelephonyServiceProxy != null, imsi, E_SYSTEM, "[%s] A system error has occured. IPC instance has not been constructed yet.", GetErrorMessage(E_SYSTEM));
244 r = pTelephonyServiceProxy->GetImsi(imsi);
245 SysTryReturn(NID_TEL, r == E_SUCCESS, imsi, r, "[%s] Failed to get the imsi.", GetErrorMessage(r));
251 _SimInfoImpl::GetSimType(void) const
253 TapiHandle* pHandle = null;
254 int err = SIM_ERROR_NONE;
255 TelSimCardType_t simCardType = TAPI_SIM_CARD_TYPE_UNKNOWN;
256 SimType simType = SIM_TYPE_UNKNOWN;
258 SysTryReturn(NID_TEL, __isAvailable, SIM_TYPE_UNKNOWN, E_DEVICE_UNAVAILABLE,
259 "[%s] The operation failed because the SIM card is not ready.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
261 pHandle = tel_init(null);
262 SysTryReturn(NID_TEL, pHandle != null, SIM_TYPE_UNKNOWN, E_SYSTEM,
263 "[%s] A system error has occurred. Failed to initialize TAPI library.", GetErrorMessage(E_SYSTEM));
265 err = tel_get_sim_type(pHandle, &simCardType);
266 SysLog(NID_TEL, "The return value of tel_get_sim_type() is [0x%x] and the SIM type is [%d]", err, simCardType);
270 case TAPI_SIM_CARD_TYPE_GSM:
271 simType = SIM_TYPE_GSM;
273 case TAPI_SIM_CARD_TYPE_USIM:
274 simType = SIM_TYPE_USIM;
276 case TAPI_SIM_CARD_TYPE_RUIM:
277 simType = SIM_TYPE_RUIM;
279 case TAPI_SIM_CARD_TYPE_IMS:
280 simType = SIM_TYPE_ISIM;
282 case TAPI_SIM_CARD_TYPE_UNKNOWN: // Fall through
284 simType = SIM_TYPE_UNKNOWN;
294 _SimInfoImpl::IsAvailable(void) const
296 return __isAvailable;
300 _SimInfoImpl::operator =(const _SimInfoImpl& rhs)
304 __isAvailable = rhs.__isAvailable;
311 _SimInfoImpl::Equals(const Tizen::Base::Object& rhs) const
313 const _SimInfoImpl* pRhs = dynamic_cast <const _SimInfoImpl*>(&rhs);
320 if (__isAvailable != pRhs->__isAvailable)
329 _SimInfoImpl::GetHashCode(void) const
331 int hashCode = _HASH_CODE_INITIAL_VALUE;
333 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isAvailable ? 0 : 1);
339 _SimInfoImpl::GetInstance(SimInfo& simInfo)
341 return simInfo.__pSimInfoImpl;
345 _SimInfoImpl::GetInstance(const SimInfo& simInfo)
347 return simInfo.__pSimInfoImpl;
350 }} // Tizen::Telephony