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"
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
38 namespace Tizen { namespace Telephony
42 _SimInfoImpl::_SimInfoImpl(void)
43 : __pTelephonyServiceProxy(null)
48 _SimInfoImpl::~_SimInfoImpl(void)
53 _SimInfoImpl::Construct(void)
55 SysTryReturnResult(NID_TEL, IsAvailable(), E_DEVICE_UNAVAILABLE, "The operation failed due to a missing SIM card.");
57 __pTelephonyServiceProxy = _TelephonyIpcProxy::GetInstance();
59 if (__pTelephonyServiceProxy == null)
61 SysLog(NID_TEL, "Creating an IPC instance to connect with the Connectivity service daemon has failed.");
69 _SimInfoImpl::GetMnc(void) const
73 SysTryReturn(NID_TEL, IsAvailable(), mnc, E_DEVICE_UNAVAILABLE,
74 "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
76 int err = SIM_ERROR_NONE;
79 err = sim_get_mnc(&pTemp);
81 SysLog(NID_TEL, "The return value of sim_get_mnc() is 0x%x and the mnc value is %s", err, pTemp);
82 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));
83 unique_ptr<char, _CharDeleter> pMnc(pTemp);
85 if(pMnc.get() != null)
87 mnc = atoi(pMnc.get());
93 _SimInfoImpl::GetMcc(void) const
97 SysTryReturn(NID_TEL, IsAvailable(), mcc, E_DEVICE_UNAVAILABLE,
98 "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
100 int err = SIM_ERROR_NONE;
103 err = sim_get_mcc(&pTemp);
105 SysLog(NID_TEL, "The return value of sim_get_mcc() is 0x%x,and the mcc value is %s", err, pTemp);
106 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));
107 unique_ptr<char, _CharDeleter> pMcc(pTemp);
109 if(pMcc.get() != null)
111 mcc = atoi(pMcc.get());
117 _SimInfoImpl::GetSpn(void) const
121 SysTryReturn(NID_TEL, IsAvailable(), spn, E_DEVICE_UNAVAILABLE,
122 "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
124 int err = SIM_ERROR_NONE;
128 err = sim_get_spn(&pTemp);
129 SysLog(NID_TEL, "The return value of sim_get_spn() is 0x%x and the spn value is %s", err, pTemp);
130 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));
131 unique_ptr<char, _CharDeleter> pSpn(pTemp);
133 if(pSpn.get() != null)
135 spn = String(pSpn.get());
141 _SimInfoImpl::GetIccId(void) const
145 SysTryReturn(NID_TEL, IsAvailable(), iccId, E_DEVICE_UNAVAILABLE,
146 "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
148 int err = SIM_ERROR_NONE;
151 err = sim_get_icc_id(&pTemp);
152 SysLog(NID_TEL, "The return value of sim_get_icc_id() is 0x%x and the iccid valuce is %s", err, pTemp);
153 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));
155 unique_ptr<char, _CharDeleter> pIccId(pTemp);
157 if (pIccId.get() != null)
159 iccId = String(pIccId.get());
166 _SimInfoImpl::GetOperatorName(void) const
170 SysTryReturn(NID_TEL, IsAvailable(), operatorName, E_DEVICE_UNAVAILABLE,
171 "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
173 int err = SIM_ERROR_NONE;
175 char* pTempFullName = null;
176 char* pTempShortName = null;
178 err = sim_get_cphs_operator_name(&pTempFullName, &pTempShortName);
180 SysLog(NID_TEL, "The return value of sim_get_cphs_operator_name() is 0x%x", err);
181 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));
183 unique_ptr<char, _CharDeleter> pFullName(pTempFullName);
184 unique_ptr<char, _CharDeleter> pShortName(pTempShortName);
186 operatorName = String((const char*) pFullName.get());
187 SysLog(NID_TEL, "The Operator Name is %ls", operatorName.GetPointer());
193 _SimInfoImpl::GetPhoneNumber(void) const
197 SysTryReturn(NID_TEL, IsAvailable(), phoneNumber, E_DEVICE_UNAVAILABLE,
198 "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
200 int err = SIM_ERROR_NONE;
203 err = sim_get_subscriber_number(&pTemp);
204 SysLog(NID_TEL, "The return value of sim_get_subscriber_number() is 0x%x and the phone number is %s", err, pTemp);
205 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));
207 unique_ptr<char, _CharDeleter> pPhoneNumber(pTemp);
208 if (pPhoneNumber.get() != null)
210 phoneNumber = String((const char*) pPhoneNumber.get());
216 _SimInfoImpl::GetImsi(void) const
218 result r = E_SUCCESS;
221 SysTryReturn(NID_TEL, IsAvailable(), imsi, E_DEVICE_UNAVAILABLE,
222 "[%s] The operation failed due to a missing SIM card.", GetErrorMessage(E_DEVICE_UNAVAILABLE));
224 SysTryReturn(NID_TEL, __pTelephonyServiceProxy != null, imsi, E_SYSTEM, "[%s] A system error has occured. IPC instance has not been constructed yet.", GetErrorMessage(E_SYSTEM));
226 r = __pTelephonyServiceProxy->GetImsi(imsi);
227 SysTryReturn(NID_TEL, r == E_SUCCESS, imsi, r, "[%s] Failed to get the imsi.", GetErrorMessage(r));
233 _SimInfoImpl::IsAvailable(void) const
235 bool isAvailable = false;
236 int err = SIM_ERROR_NONE;
237 sim_state_e simState = SIM_STATE_UNKNOWN;
239 err = sim_get_state(&simState);
240 SysLog(NID_TEL, "The return value of sim_get_state() is 0x%x and the simState is %d", err, simState);
242 if (err == SIM_ERROR_NONE && simState == SIM_STATE_AVAILABLE)
251 _SimInfoImpl::GetInstance(SimInfo& simInfo)
253 return simInfo.__pSimInfoImpl;
257 _SimInfoImpl::GetInstance(const SimInfo& simInfo)
259 return simInfo.__pSimInfoImpl;
262 }} // Tizen::Telephony