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)
48 , __simType(SIM_TYPE_UNKNOWN)
49 , __isAvailable(false)
50 , __isIccIdValid(false)
53 , __isOperatorNameValid(false)
54 , __isPhoneNumberValid(false)
56 , __isSimTypeValid(false)
60 _SimInfoImpl::_SimInfoImpl(const _SimInfoImpl& rhs)
63 , __iccId(rhs.__iccId)
65 , __operatorName(rhs.__operatorName)
66 , __phoneNumber(rhs.__phoneNumber)
68 , __simType(rhs.__simType)
69 , __isAvailable(rhs.__isAvailable)
70 , __isIccIdValid(rhs.__isIccIdValid)
71 , __isMccValid(rhs.__isMccValid)
72 , __isMncValid(rhs.__isMncValid)
73 , __isOperatorNameValid(rhs.__isOperatorNameValid)
74 , __isPhoneNumberValid(rhs.__isPhoneNumberValid)
75 , __isSpnValid(rhs.__isSpnValid)
76 , __isSimTypeValid(rhs.__isSimTypeValid)
80 _SimInfoImpl::~_SimInfoImpl(void)
85 _SimInfoImpl::Construct(void)
87 TapiHandle* pHandle = null;
88 int err = SIM_ERROR_NONE;
89 sim_state_e simState = SIM_STATE_UNAVAILABLE;
100 char* pTempFullName = null;
101 char* pTempShortName = null;
103 // Checking availability
104 err = sim_get_state(&simState);
105 SysLog(NID_TEL, "The return value of sim_get_state() is 0x%x and the simState is %d", err, simState);
107 if (err == SIM_ERROR_NONE && simState == SIM_STATE_AVAILABLE)
109 __isAvailable = true;
111 SysTryReturnResult(NID_TEL, __isAvailable, E_DEVICE_UNAVAILABLE, "The operation failed due to a missing SIM card.");
114 err = sim_get_mnc(&pTemp);
115 SysLog(NID_TEL, "The return value of sim_get_mnc() is 0x%x and the mnc value is %s", err, pTemp);
117 if (err != SIM_ERROR_NONE)
119 SysLog(NID_TEL, "Failed to get the Mobile Network Code (MNC).");
120 __isMncValid = false;
124 unique_ptr<char, _CharDeleter> pMnc(pTemp);
126 if(pMnc.get() != null)
128 mnc = atoi(pMnc.get());
135 err = sim_get_mcc(&pTemp);
136 SysLog(NID_TEL, "The return value of sim_get_mcc() is 0x%x,and the mcc value is %s", err, pTemp);
138 if (err != SIM_ERROR_NONE)
140 SysLog(NID_TEL, "Failed to get the Mobile Country Code (MCC).");
141 __isMccValid = false;
145 unique_ptr<char, _CharDeleter> pMcc(pTemp);
147 if(pMcc.get() != null)
149 mcc = atoi(pMcc.get());
156 err = sim_get_spn(&pTemp);
157 SysLog(NID_TEL, "The return value of sim_get_spn() is 0x%x and the spn value is %s", err, pTemp);
159 if (err != SIM_ERROR_NONE)
161 SysLog(NID_TEL, "Failed to get the Service Provider Name (SPN).");
162 __isSpnValid = false;
166 unique_ptr<char, _CharDeleter> pSpn(pTemp);
168 if(pSpn.get() != null)
170 spn = String(pSpn.get());
178 err = sim_get_icc_id(&pTemp);
179 SysLog(NID_TEL, "The return value of sim_get_icc_id() is 0x%x and the iccid value is %s", err, pTemp);
181 if (err != SIM_ERROR_NONE)
183 SysLog(NID_TEL, "Failed to get the Integrated Circuit Card(ICC) ID.");
184 __isIccIdValid = false;
188 unique_ptr<char, _CharDeleter> pIccId(pTemp);
190 if (pIccId.get() != null)
192 iccId = String(pIccId.get());
194 __isIccIdValid = true;
198 // Getting operator name
199 err = sim_get_cphs_operator_name(&pTempFullName, &pTempShortName);
201 SysLog(NID_TEL, "The return value of sim_get_cphs_operator_name() is 0x%x. full[%s] short[%s]", err, pTempFullName, pTempShortName);
202 if (err != SIM_ERROR_NONE)
204 SysLog(NID_TEL, "Failed to get the operator name.");
205 __isOperatorNameValid = false;
209 unique_ptr<char, _CharDeleter> pFullName(pTempFullName);
210 unique_ptr<char, _CharDeleter> pShortName(pTempShortName);
212 operatorName = String((const char*) pFullName.get());
213 SysLog(NID_TEL, "The Operator Name is [%ls]", operatorName.GetPointer());
214 __isOperatorNameValid = true;
216 __operatorName = operatorName;
218 // Getting phone number
219 err = sim_get_subscriber_number(&pTemp);
220 SysLog(NID_TEL, "The return value of sim_get_subscriber_number() is 0x%x and the phone number is [%s]", err, pTemp);
221 if (err != SIM_ERROR_NONE)
223 SysLog(NID_TEL, "Failed to get the phone number.");
224 __isPhoneNumberValid = false;
228 unique_ptr<char, _CharDeleter> pPhoneNumber(pTemp);
229 if (pPhoneNumber.get() != null)
231 phoneNumber = String((const char*) pPhoneNumber.get());
233 __isPhoneNumberValid = true;
235 __phoneNumber = phoneNumber;
238 pHandle = tel_init(null);
239 SysTryReturnResult(NID_TEL, pHandle != null, E_SYSTEM,
240 "[%s] A system error has occurred. Failed to initialize TApi library.", GetErrorMessage(E_SYSTEM));
242 TelSimCardType_t simType = TAPI_SIM_CARD_TYPE_UNKNOWN;
243 err = tel_get_sim_type(pHandle, &simType);
244 SysLog(NID_TEL, "The return value of tel_get_sim_type() is 0x%x and the SIM type is %d", err, simType);
245 if (err != SIM_ERROR_NONE)
247 SysLog(NID_TEL, "Failed to get the SIM type.");
248 __isSimTypeValid = false;
252 __isSimTypeValid = true;
257 case TAPI_SIM_CARD_TYPE_GSM:
258 __simType = SIM_TYPE_GSM;
260 case TAPI_SIM_CARD_TYPE_USIM:
261 __simType = SIM_TYPE_USIM;
263 case TAPI_SIM_CARD_TYPE_RUIM:
264 __simType = SIM_TYPE_RUIM;
266 case TAPI_SIM_CARD_TYPE_IMS:
267 __simType = SIM_TYPE_ISIM;
269 case TAPI_SIM_CARD_TYPE_UNKNOWN: // Fall through
271 __simType = SIM_TYPE_UNKNOWN;
281 _SimInfoImpl::GetMnc(void) const
287 _SimInfoImpl::GetMcc(void) const
293 _SimInfoImpl::GetSpn(void) const
299 _SimInfoImpl::GetIccId(void) const
305 _SimInfoImpl::GetOperatorName(void) const
307 return __operatorName;
311 _SimInfoImpl::GetPhoneNumber(void) const
313 return __phoneNumber;
317 _SimInfoImpl::GetImsi(void) const
319 result r = E_SUCCESS;
322 SysTryReturn(NID_TEL, __isAvailable, imsi, E_DEVICE_UNAVAILABLE,
323 "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
325 _TelephonyIpcProxy* pTelephonyServiceProxy = _TelephonyIpcProxy::GetInstance();
326 SysTryReturn(NID_TEL, pTelephonyServiceProxy != null, imsi, E_SYSTEM, "[%s] A system error has occured. IPC instance has not been constructed yet.", GetErrorMessage(E_SYSTEM));
328 r = pTelephonyServiceProxy->GetImsi(imsi);
329 SysTryReturn(NID_TEL, r == E_SUCCESS, imsi, r, "[%s] Failed to get the imsi.", GetErrorMessage(r));
335 _SimInfoImpl::GetSimType(void) const
341 _SimInfoImpl::IsAvailable(void) const
343 return __isAvailable;
347 _SimInfoImpl::operator =(const _SimInfoImpl& rhs)
353 __iccId = rhs.__iccId;
355 __operatorName = rhs.__operatorName;
356 __phoneNumber = rhs.__phoneNumber;
358 __simType = rhs.__simType;
359 __isAvailable = rhs.__isAvailable;
360 __isIccIdValid = rhs.__isIccIdValid;
361 __isMccValid = rhs.__isMccValid;
362 __isMncValid = rhs.__isMncValid;
363 __isOperatorNameValid = rhs.__isOperatorNameValid;
364 __isPhoneNumberValid = rhs.__isPhoneNumberValid;
365 __isSpnValid = rhs.__isSpnValid;
366 __isSimTypeValid = rhs.__isSimTypeValid;
373 _SimInfoImpl::Equals(const Tizen::Base::Object& rhs) const
375 const _SimInfoImpl* pRhs = dynamic_cast <const _SimInfoImpl*>(&rhs);
382 if (__mcc != pRhs->__mcc ||
383 __mnc != pRhs->__mnc ||
384 __iccId != pRhs->__iccId ||
385 __imsi != pRhs->__imsi ||
386 __operatorName != pRhs->__operatorName ||
387 __phoneNumber != pRhs->__phoneNumber ||
388 __spn != pRhs->__spn ||
389 __simType != pRhs->__simType ||
390 __isAvailable != pRhs->__isAvailable ||
391 __isIccIdValid != pRhs->__isIccIdValid ||
392 __isMccValid != pRhs->__isMccValid ||
393 __isMncValid != pRhs->__isMncValid ||
394 __isOperatorNameValid != pRhs->__isOperatorNameValid ||
395 __isPhoneNumberValid != pRhs->__isPhoneNumberValid ||
396 __isSpnValid != pRhs->__isSpnValid ||
397 __isSimTypeValid != pRhs->__isSimTypeValid)
406 _SimInfoImpl::GetHashCode(void) const
408 int hashCode = _HASH_CODE_INITIAL_VALUE;
410 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __mcc;
411 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __mnc;
412 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __iccId.GetHashCode();
413 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __imsi.GetHashCode();
414 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __operatorName.GetHashCode();
415 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __phoneNumber.GetHashCode();
416 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __spn.GetHashCode();
417 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __simType;
418 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isAvailable ? 0 : 1);
419 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isIccIdValid ? 0 : 1);
420 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isMccValid ? 0 : 1);
421 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isMncValid ? 0 : 1);
422 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isOperatorNameValid ? 0 : 1);
423 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isPhoneNumberValid ? 0 : 1);
424 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isSpnValid ? 0 : 1);
425 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isSimTypeValid ? 0 : 1);
431 _SimInfoImpl::GetInstance(SimInfo& simInfo)
433 return simInfo.__pSimInfoImpl;
437 _SimInfoImpl::GetInstance(const SimInfo& simInfo)
439 return simInfo.__pSimInfoImpl;
442 }} // Tizen::Telephony