#include "FTel_TelephonyIpcProxy.h"
#include "FTel_TelephonyUtility.h"
+#include <ITapiSim.h>
+
+
using namespace std;
using namespace Tizen::App;
using namespace Tizen::Base;
_SimInfoImpl::_SimInfoImpl(void)
-: __pTelephonyServiceProxy(null)
+ : __mcc(-1)
+ , __mnc(-1)
+ , __simType(SIM_TYPE_UNKNOWN)
+ , __isAvailable(false)
+ , __isIccIdValid(false)
+ , __isMccValid(false)
+ , __isMncValid(false)
+ , __isOperatorNameValid(false)
+ , __isPhoneNumberValid(false)
+ , __isSpnValid(false)
+ , __isSimTypeValid(false)
{
+}
+_SimInfoImpl::_SimInfoImpl(const _SimInfoImpl& rhs)
+ : __mcc(rhs.__mcc)
+ , __mnc(rhs.__mnc)
+ , __iccId(rhs.__iccId)
+ , __imsi(rhs.__imsi)
+ , __operatorName(rhs.__operatorName)
+ , __phoneNumber(rhs.__phoneNumber)
+ , __spn(rhs.__spn)
+ , __simType(rhs.__simType)
+ , __isAvailable(rhs.__isAvailable)
+ , __isIccIdValid(rhs.__isIccIdValid)
+ , __isMccValid(rhs.__isMccValid)
+ , __isMncValid(rhs.__isMncValid)
+ , __isOperatorNameValid(rhs.__isOperatorNameValid)
+ , __isPhoneNumberValid(rhs.__isPhoneNumberValid)
+ , __isSpnValid(rhs.__isSpnValid)
+ , __isSimTypeValid(rhs.__isSimTypeValid)
+{
}
_SimInfoImpl::~_SimInfoImpl(void)
result
_SimInfoImpl::Construct(void)
{
- SysTryReturnResult(NID_TEL, IsAvailable(), E_DEVICE_UNAVAILABLE, "The operation failed due to a missing SIM card.");
-
- __pTelephonyServiceProxy = _TelephonyIpcProxy::GetInstance();
-
- if (__pTelephonyServiceProxy == null)
- {
- SysLog(NID_TEL, "Creating an IPC instance to connect with the Connectivity service daemon has failed.");
- }
-
- return E_SUCCESS;
-}
-
+ TapiHandle* pHandle = null;
+ int err = SIM_ERROR_NONE;
+ sim_state_e simState = SIM_STATE_UNAVAILABLE;
-int
-_SimInfoImpl::GetMnc(void) const
-{
int mnc = -1;
+ int mcc = -1;
- SysTryReturn(NID_TEL, IsAvailable(), mnc, E_DEVICE_UNAVAILABLE,
- "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
+ String spn;
+ String iccId;
+ String operatorName;
+ String phoneNumber;
- int err = SIM_ERROR_NONE;
char* pTemp = null;
+ char* pTempFullName = null;
+ char* pTempShortName = null;
- err = sim_get_mnc(&pTemp);
-
- SysLog(NID_TEL, "The return value of sim_get_mnc() is 0x%x and the mnc value is %s", err, pTemp);
- SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, mnc, E_SYSTEM, "[%s] A system error has occured. Failed to get the Mobile Network Code (MNC).", GetErrorMessage(E_SYSTEM));
- unique_ptr<char, _CharDeleter> pMnc(pTemp);
+ // Checking availability
+ err = sim_get_state(&simState);
+ SysLog(NID_TEL, "The return value of sim_get_state() is 0x%x and the simState is %d", err, simState);
- if(pMnc.get() != null)
+ if (err == SIM_ERROR_NONE && simState == SIM_STATE_AVAILABLE)
{
- mnc = atoi(pMnc.get());
+ __isAvailable = true;
}
- return mnc;
-}
+ SysTryReturnResult(NID_TEL, __isAvailable, E_DEVICE_UNAVAILABLE, "The operation failed due to a missing SIM card.");
-int
-_SimInfoImpl::GetMcc(void) const
-{
- int mcc = -1;
+ // Getting mnc
+ err = sim_get_mnc(&pTemp);
+ SysLog(NID_TEL, "The return value of sim_get_mnc() is 0x%x and the mnc value is %s", err, pTemp);
- SysTryReturn(NID_TEL, IsAvailable(), mcc, E_DEVICE_UNAVAILABLE,
- "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
+ if (err != SIM_ERROR_NONE)
+ {
+ SysLog(NID_TEL, "Failed to get the Mobile Network Code (MNC).");
+ __isMncValid = false;
+ }
+ else
+ {
+ unique_ptr<char, _CharDeleter> pMnc(pTemp);
- int err = SIM_ERROR_NONE;
- char* pTemp = null;
+ if(pMnc.get() != null)
+ {
+ mnc = atoi(pMnc.get());
+ }
+ __isMncValid = true;
+ }
+ __mnc = mnc;
+ // Getting mcc
err = sim_get_mcc(&pTemp);
-
SysLog(NID_TEL, "The return value of sim_get_mcc() is 0x%x,and the mcc value is %s", err, pTemp);
- SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, mcc, E_SYSTEM, "[%s] A system error has occured. Failed to get the Mobile Country Code (MCC).", GetErrorMessage(E_SYSTEM));
- unique_ptr<char, _CharDeleter> pMcc(pTemp);
- if(pMcc.get() != null)
+ if (err != SIM_ERROR_NONE)
{
- mcc = atoi(pMcc.get());
+ SysLog(NID_TEL, "Failed to get the Mobile Country Code (MCC).");
+ __isMccValid = false;
}
- return mcc;
-}
-
-String
-_SimInfoImpl::GetSpn(void) const
-{
- String spn;
-
- SysTryReturn(NID_TEL, IsAvailable(), spn, E_DEVICE_UNAVAILABLE,
- "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
+ else
+ {
+ unique_ptr<char, _CharDeleter> pMcc(pTemp);
- int err = SIM_ERROR_NONE;
-
- char* pTemp = null;
+ if(pMcc.get() != null)
+ {
+ mcc = atoi(pMcc.get());
+ }
+ __isMccValid = true;
+ }
+ __mcc = mcc;
+ // Getting spn
err = sim_get_spn(&pTemp);
SysLog(NID_TEL, "The return value of sim_get_spn() is 0x%x and the spn value is %s", err, pTemp);
- SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, spn, E_SYSTEM, "[%s] A system error has occured. Failed to get the Service Provider Name (SPN).", GetErrorMessage(E_SYSTEM));
- unique_ptr<char, _CharDeleter> pSpn(pTemp);
- if(pSpn.get() != null)
+ if (err != SIM_ERROR_NONE)
{
- spn = String(pSpn.get());
+ SysLog(NID_TEL, "Failed to get the Service Provider Name (SPN).");
+ __isSpnValid = false;
}
- return spn;
-}
-
-String
-_SimInfoImpl::GetIccId(void) const
-{
- String iccId;
+ else
+ {
+ unique_ptr<char, _CharDeleter> pSpn(pTemp);
- SysTryReturn(NID_TEL, IsAvailable(), iccId, E_DEVICE_UNAVAILABLE,
- "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
+ if(pSpn.get() != null)
+ {
+ spn = String(pSpn.get());
+ }
+ __isSpnValid = true;
+ }
- int err = SIM_ERROR_NONE;
- char* pTemp = null;
+ __spn = spn;
+ // Getting icc id
err = sim_get_icc_id(&pTemp);
- SysLog(NID_TEL, "The return value of sim_get_icc_id() is 0x%x and the iccid valuce is %s", err, pTemp);
- SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, iccId, E_SYSTEM, "[%s] A system error has occured. Failed to get the Integrated Circuit Card(ICC) ID.", GetErrorMessage(E_SYSTEM));
+ SysLog(NID_TEL, "The return value of sim_get_icc_id() is 0x%x and the iccid value is %s", err, pTemp);
- unique_ptr<char, _CharDeleter> pIccId(pTemp);
-
- if (pIccId.get() != null)
+ if (err != SIM_ERROR_NONE)
{
- iccId = String(pIccId.get());
+ SysLog(NID_TEL, "Failed to get the Integrated Circuit Card(ICC) ID.");
+ __isIccIdValid = false;
}
+ else
+ {
+ unique_ptr<char, _CharDeleter> pIccId(pTemp);
- return iccId;
-}
+ if (pIccId.get() != null)
+ {
+ iccId = String(pIccId.get());
+ }
+ __isIccIdValid = true;
+ }
+ __iccId = iccId;
-String
-_SimInfoImpl::GetOperatorName(void) const
-{
- String operatorName;
+ // Getting operator name
+ err = sim_get_cphs_operator_name(&pTempFullName, &pTempShortName);
- SysTryReturn(NID_TEL, IsAvailable(), operatorName, E_DEVICE_UNAVAILABLE,
- "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
+ SysLog(NID_TEL, "The return value of sim_get_cphs_operator_name() is 0x%x. full[%s] short[%s]", err, pTempFullName, pTempShortName);
+ if (err != SIM_ERROR_NONE)
+ {
+ SysLog(NID_TEL, "Failed to get the operator name.");
+ __isOperatorNameValid = false;
+ }
+ else
+ {
+ unique_ptr<char, _CharDeleter> pFullName(pTempFullName);
+ unique_ptr<char, _CharDeleter> pShortName(pTempShortName);
- int err = SIM_ERROR_NONE;
+ operatorName = String((const char*) pFullName.get());
+ SysLog(NID_TEL, "The Operator Name is [%ls]", operatorName.GetPointer());
+ __isOperatorNameValid = true;
+ }
+ __operatorName = operatorName;
- char* pTempFullName = null;
- char* pTempShortName = null;
+ // Getting phone number
+ err = sim_get_subscriber_number(&pTemp);
+ SysLog(NID_TEL, "The return value of sim_get_subscriber_number() is 0x%x and the phone number is [%s]", err, pTemp);
+ if (err != SIM_ERROR_NONE)
+ {
+ SysLog(NID_TEL, "Failed to get the phone number.");
+ __isPhoneNumberValid = false;
+ }
+ else
+ {
+ unique_ptr<char, _CharDeleter> pPhoneNumber(pTemp);
+ if (pPhoneNumber.get() != null)
+ {
+ phoneNumber = String((const char*) pPhoneNumber.get());
+ }
+ __isPhoneNumberValid = true;
+ }
+ __phoneNumber = phoneNumber;
- err = sim_get_cphs_operator_name(&pTempFullName, &pTempShortName);
+ // Getting SIM type
+ pHandle = tel_init(null);
+ SysTryReturnResult(NID_TEL, pHandle != null, E_SYSTEM,
+ "[%s] A system error has occurred. Failed to initialize TApi library.", GetErrorMessage(E_SYSTEM));
- SysLog(NID_TEL, "The return value of sim_get_cphs_operator_name() is 0x%x", err);
- SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, operatorName, E_SYSTEM, "[%s] A system error has occured. Failed to get the operator name.", GetErrorMessage(E_SYSTEM));
+ TelSimCardType_t simType = TAPI_SIM_CARD_TYPE_UNKNOWN;
+ err = tel_get_sim_type(pHandle, &simType);
+ SysLog(NID_TEL, "The return value of tel_get_sim_type() is 0x%x and the SIM type is %d", err, simType);
+ if (err != SIM_ERROR_NONE)
+ {
+ SysLog(NID_TEL, "Failed to get the SIM type.");
+ __isSimTypeValid = false;
+ }
+ else
+ {
+ __isSimTypeValid = true;
+ }
- unique_ptr<char, _CharDeleter> pFullName(pTempFullName);
- unique_ptr<char, _CharDeleter> pShortName(pTempShortName);
+ switch(simType)
+ {
+ case TAPI_SIM_CARD_TYPE_GSM:
+ __simType = SIM_TYPE_GSM;
+ break;
+ case TAPI_SIM_CARD_TYPE_USIM:
+ __simType = SIM_TYPE_USIM;
+ break;
+ case TAPI_SIM_CARD_TYPE_RUIM:
+ __simType = SIM_TYPE_RUIM;
+ break;
+ case TAPI_SIM_CARD_TYPE_IMS:
+ __simType = SIM_TYPE_ISIM;
+ break;
+ case TAPI_SIM_CARD_TYPE_UNKNOWN: // Fall through
+ default:
+ __simType = SIM_TYPE_UNKNOWN;
+ break;
+ }
- operatorName = String((const char*) pFullName.get());
- SysLog(NID_TEL, "The Operator Name is %ls", operatorName.GetPointer());
+ tel_deinit(pHandle);
- return operatorName;
+ return E_SUCCESS;
+}
+
+int
+_SimInfoImpl::GetMnc(void) const
+{
+ return __mnc;
+}
+
+int
+_SimInfoImpl::GetMcc(void) const
+{
+ return __mcc;
}
String
-_SimInfoImpl::GetPhoneNumber(void) const
+_SimInfoImpl::GetSpn(void) const
{
- String phoneNumber;
+ return __spn;
+}
- SysTryReturn(NID_TEL, IsAvailable(), phoneNumber, E_DEVICE_UNAVAILABLE,
- "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
+String
+_SimInfoImpl::GetIccId(void) const
+{
+ return __iccId;
+}
- int err = SIM_ERROR_NONE;
- char* pTemp = null;
+String
+_SimInfoImpl::GetOperatorName(void) const
+{
+ return __operatorName;
+}
- err = sim_get_subscriber_number(&pTemp);
- SysLog(NID_TEL, "The return value of sim_get_subscriber_number() is 0x%x and the phone number is %s", err, pTemp);
- SysTryReturn(NID_TEL, err == SIM_ERROR_NONE, phoneNumber, E_SYSTEM, "[%s] A system error has occured. Failed to get the phone number.", GetErrorMessage(E_SYSTEM));
-
- unique_ptr<char, _CharDeleter> pPhoneNumber(pTemp);
- if (pPhoneNumber.get() != null)
- {
- phoneNumber = String((const char*) pPhoneNumber.get());
- }
- return phoneNumber;
+String
+_SimInfoImpl::GetPhoneNumber(void) const
+{
+ return __phoneNumber;
}
String
result r = E_SUCCESS;
String imsi;
- SysTryReturn(NID_TEL, IsAvailable(), imsi, E_DEVICE_UNAVAILABLE,
+ SysTryReturn(NID_TEL, __isAvailable, imsi, E_DEVICE_UNAVAILABLE,
"[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
- SysTryReturn(NID_TEL, __pTelephonyServiceProxy != null, imsi, E_SYSTEM, "[%s] A system error has occured. IPC instance has not been constructed yet.", GetErrorMessage(E_SYSTEM));
+ _TelephonyIpcProxy* pTelephonyServiceProxy = _TelephonyIpcProxy::GetInstance();
+ SysTryReturn(NID_TEL, pTelephonyServiceProxy != null, imsi, E_SYSTEM, "[%s] A system error has occured. IPC instance has not been constructed yet.", GetErrorMessage(E_SYSTEM));
- r = __pTelephonyServiceProxy->GetImsi(imsi);
+ r = pTelephonyServiceProxy->GetImsi(imsi);
SysTryReturn(NID_TEL, r == E_SUCCESS, imsi, r, "[%s] Failed to get the imsi.", GetErrorMessage(r));
return imsi;
}
+SimType
+_SimInfoImpl::GetSimType(void) const
+{
+ return __simType;
+}
+
bool
_SimInfoImpl::IsAvailable(void) const
{
- bool isAvailable = false;
- int err = SIM_ERROR_NONE;
- sim_state_e simState = SIM_STATE_UNKNOWN;
+ return __isAvailable;
+}
- err = sim_get_state(&simState);
- SysLog(NID_TEL, "The return value of sim_get_state() is 0x%x and the simState is %d", err, simState);
+_SimInfoImpl&
+_SimInfoImpl::operator =(const _SimInfoImpl& rhs)
+{
+ if (this != &rhs)
+ {
+ __mcc = rhs.__mcc;
+ __mnc = rhs.__mnc;
+ __iccId = rhs.__iccId;
+ __imsi = rhs.__imsi;
+ __operatorName = rhs.__operatorName;
+ __phoneNumber = rhs.__phoneNumber;
+ __spn = rhs.__spn;
+ __simType = rhs.__simType;
+ __isAvailable = rhs.__isAvailable;
+ __isIccIdValid = rhs.__isIccIdValid;
+ __isMccValid = rhs.__isMccValid;
+ __isMncValid = rhs.__isMncValid;
+ __isOperatorNameValid = rhs.__isOperatorNameValid;
+ __isPhoneNumberValid = rhs.__isPhoneNumberValid;
+ __isSpnValid = rhs.__isSpnValid;
+ __isSimTypeValid = rhs.__isSimTypeValid;
+ }
- if (err == SIM_ERROR_NONE && simState == SIM_STATE_AVAILABLE)
+ return *this;
+}
+
+bool
+_SimInfoImpl::Equals(const Tizen::Base::Object& rhs) const
+{
+ const _SimInfoImpl* pRhs = dynamic_cast <const _SimInfoImpl*>(&rhs);
+
+ if (pRhs == null)
+ {
+ return false;
+ }
+
+ if (__mcc != pRhs->__mcc ||
+ __mnc != pRhs->__mnc ||
+ __iccId != pRhs->__iccId ||
+ __imsi != pRhs->__imsi ||
+ __operatorName != pRhs->__operatorName ||
+ __phoneNumber != pRhs->__phoneNumber ||
+ __spn != pRhs->__spn ||
+ __simType != pRhs->__simType ||
+ __isAvailable != pRhs->__isAvailable ||
+ __isIccIdValid != pRhs->__isIccIdValid ||
+ __isMccValid != pRhs->__isMccValid ||
+ __isMncValid != pRhs->__isMncValid ||
+ __isOperatorNameValid != pRhs->__isOperatorNameValid ||
+ __isPhoneNumberValid != pRhs->__isPhoneNumberValid ||
+ __isSpnValid != pRhs->__isSpnValid ||
+ __isSimTypeValid != pRhs->__isSimTypeValid)
{
- isAvailable = true;
+ return false;
}
- return isAvailable;
+ return true;
+}
+
+int
+_SimInfoImpl::GetHashCode(void) const
+{
+ int hashCode = _HASH_CODE_INITIAL_VALUE;
+
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __mcc;
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __mnc;
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __iccId.GetHashCode();
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __imsi.GetHashCode();
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __operatorName.GetHashCode();
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __phoneNumber.GetHashCode();
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __spn.GetHashCode();
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __simType;
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isAvailable ? 0 : 1);
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isIccIdValid ? 0 : 1);
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isMccValid ? 0 : 1);
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isMncValid ? 0 : 1);
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isOperatorNameValid ? 0 : 1);
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isPhoneNumberValid ? 0 : 1);
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isSpnValid ? 0 : 1);
+ hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isSimTypeValid ? 0 : 1);
+
+ return hashCode;
}
_SimInfoImpl*