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_NetworkManagerImpl.cpp
19 * @brief This is the implementation file for _NetworkManagerImpl class.
23 #include <telephony_network.h>
24 #include <FTelITelephonyNetworkEventListener.h>
25 #include <FTelITelephonyNetworkSettingListener.h>
26 #include <FTelNetworkInfo.h>
27 #include <FTelNetworkStatus.h>
28 #include <FTelNetworkManager.h>
29 #include <FSysSettingInfo.h>
30 #include <FBaseUtilStringUtil.h>
31 #include <FBaseSysLog.h>
32 #include "FApp_AppInfo.h"
33 #include "FTel_NetworkManagerImpl.h"
34 #include "FTel_NetworkStatusImpl.h"
35 #include "FTel_NetworkInfoImpl.h"
36 #include "FTel_NetworkManagerEvent.h"
37 #include "FTel_NetworkManagerEventArg.h"
38 #include "FTel_NetworkSettingEvent.h"
39 #include "FTel_NetworkSettingEventArg.h"
40 #include "FTel_TelephonyUtility.h"
41 #include "FTel_TelephonyIpcProxy.h"
44 using namespace Tizen::System;
45 using namespace Tizen::App;
46 using namespace Tizen::Base;
47 using namespace Tizen::Base::Utility;
48 using namespace Tizen::Base::Collection;
51 namespace Tizen { namespace Telephony
54 _NetworkManagerImpl::_NetworkManagerImpl(void)
55 : __pConnectionHandle(null)
56 , __pNetworkManagerEvent(null)
57 , __pNetworkSettingEvent(null)
58 , __pTelephonyServiceProxy(null)
59 , __pSettingListener(null)
60 , __isCallServiceAvailable(false)
61 , __isDataServiceAvailable(false)
66 _NetworkManagerImpl::~_NetworkManagerImpl(void)
68 if (__pNetworkManagerEvent != null)
70 network_info_unset_service_state_changed_cb();
71 network_info_unset_roaming_state_changed_cb();
72 connection_unset_type_changed_cb(__pConnectionHandle.get());
77 _NetworkManagerImpl::Construct(ITelephonyNetworkEventListener* pListener)
79 connection_h pConnHandle = null;
80 int err = connection_create(&pConnHandle);
81 SysLog(NID_TEL, "The return value of connection_create() is %d", err);
82 SysTryReturnResult(NID_TEL, err == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the connection handle.");
84 std::unique_ptr<void, _ConnectionDeleter> pConnectionHandle(pConnHandle);
86 if (pListener != null)
88 unique_ptr<_NetworkManagerEvent> pNetworkManagerEvent(new (std::nothrow) _NetworkManagerEvent);
89 SysTryReturnResult(NID_TEL, pNetworkManagerEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
91 result r = pNetworkManagerEvent->Construct();
92 SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
93 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to construct of the _NetworkManagerEvent.");
95 // Register data service state changed event
96 err = connection_set_type_changed_cb(pConnectionHandle.get(),(connection_type_changed_cb)_NetworkManagerImpl::OnDataServiceStateChangedCallback, this);
97 SysLog(NID_TEL, "The return value of connection_set_type_changed_cb() is 0x%x", err);
98 SysTryReturnResult(NID_TEL, err == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to register the callback function to received the data service state changed event.");
100 // Register call service state changed event
101 err = network_info_set_service_state_changed_cb((network_info_service_state_changed_cb) _NetworkManagerImpl::OnCallServiceStateChangedCallback, this);
102 SysLog(NID_TEL, "The return value of network_info_set_service_state_changed_cb() is 0x%x", err);
103 if (err != NETWORK_INFO_ERROR_NONE)
105 SysLogException(NID_TEL, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to register the callback function to received the call service state changed event.");
106 connection_unset_type_changed_cb(pConnectionHandle.get());
111 // Register roaming state changed event
112 err = network_info_set_roaming_state_changed_cb((network_info_roaming_state_changed_cb)_NetworkManagerImpl::OnRoamingStateChangedCallback, this);
113 SysLog(NID_TEL, "The return value of network_info_set_roaming_state_changed_cb() is 0x%x", err);
114 if (err != NETWORK_INFO_ERROR_NONE)
116 SysLogException(NID_TEL, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to register the callback function to received the roaming state changed event.");
117 connection_unset_type_changed_cb(pConnectionHandle.get());
118 network_info_unset_service_state_changed_cb();
123 pNetworkManagerEvent->AddListener(*pListener, true);
125 __pNetworkManagerEvent = move(pNetworkManagerEvent);
129 __pTelephonyServiceProxy = _TelephonyIpcProxy::GetInstance();
131 if (__pTelephonyServiceProxy == null)
133 SysLog(NID_TEL, "Creating an IPC instance to connect with the Connectivity service daemon has failed.");
136 __pConnectionHandle = move(pConnectionHandle);
138 __isCallServiceAvailable = IsServiceAvailable();
139 __isDataServiceAvailable = IsDataAvailable();
140 __isRoaming = IsRoaming();
146 _NetworkManagerImpl::GetNetworkStatus(NetworkStatus& networkStatus) const
148 int err = NETWORK_INFO_ERROR_NONE;
149 bool isRoaming = false;
150 bool isDataServiceAvailable = false;
151 bool isCallServiceAvailable = false;
152 connection_cellular_state_e dataServiceState = CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
154 SysTryReturnResult(NID_TEL, IsNetworkAvailable(), E_NETWORK_UNAVAILABLE, "The operation has failed because the device is in the offline mode.");
157 err = network_info_is_roaming(&isRoaming);
158 SysLog(NID_TEL, "The return value of network_info_is_roaming() is 0x%x and the roming state is %s", err, isRoaming ? "True" : "False");
160 SysTryReturnResult(NID_TEL, err != NETWORK_INFO_ERROR_OUT_OF_SERVICE, E_SERVICE_UNAVAILABLE, "The operation failed because the device is out of the coverage area or in the emergency mode.");
161 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the roaming status.")
163 // Get the isCallServiceAvailable
164 SysTryReturnResult(NID_TEL, IsServiceAvailable(), E_SERVICE_UNAVAILABLE, "The operation failed because the device is out of the coverage area or in the emergency mode.")
165 isCallServiceAvailable = true;
167 // Get the isDataServiceAvailable
168 err = connection_get_cellular_state(__pConnectionHandle.get(), &dataServiceState);
170 SysLog(NID_TEL, "The return value of connection_get_cellular_state() is 0x%x and the dataServiceState is %d", err, dataServiceState);
171 SysTryReturnResult(NID_TEL, err == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the data service status.");
173 if (dataServiceState == CONNECTION_CELLULAR_STATE_AVAILABLE || dataServiceState == CONNECTION_CELLULAR_STATE_CONNECTED)
175 isDataServiceAvailable = true;
178 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsRoaming(isRoaming);
179 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsCallServiceAvailable(isCallServiceAvailable);
180 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsDataServiceAvailable(isDataServiceAvailable);
187 _NetworkManagerImpl::GetNetworkInfo(NetworkInfo& networkInfo) const
189 result r = E_SUCCESS;
191 SysTryReturnResult(NID_TEL, IsNetworkAvailable(), E_NETWORK_UNAVAILABLE,
192 "The operation has failed because the device is in the offline mode.");
193 SysTryReturnResult(NID_TEL, IsServiceAvailable(), E_SERVICE_UNAVAILABLE,
194 "The operation failed because the device is out of the coverage area or in the emergency mode.");
196 int err = NETWORK_INFO_ERROR_NONE;
197 _ApiVersion apiVersion = _AppInfo::GetApiVersion();
201 err = network_info_get_cell_id(&cellId);
202 SysLog(NID_TEL, "The return value of network_info_get_cell_id() is %d and the cellId value is %d", err, cellId);
203 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the cell ID.");
207 err = network_info_get_lac(&lac);
208 SysLog(NID_TEL, "The return value of network_info_get_lac() is %d and the lac value is %d", err, lac);
209 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the lac.");
213 // Get the operator name
214 err = network_info_get_provider_name(&pTemp);
215 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the plmn.");
216 unique_ptr<char[],_CharDeleter> pOperatorName(pTemp);
218 r = (StringUtil::Utf8ToString(pOperatorName.get(), operatorName));
219 SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
220 SysLog(NID_TEL, "The operatorname is %ls", operatorName.GetPointer());
223 err = network_info_get_mcc(&pTemp);
224 SysLog(NID_TEL, "The return value of network_info_get_mcc() is %d and the mcc value is %s", err, pTemp);
225 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the mcc.");
226 unique_ptr<char[],_CharDeleter> pMcc(pTemp);
229 err = network_info_get_mnc(&pTemp);
230 SysLog(NID_TEL, "The return value of network_info_get_mnc() is %d and the mnc value is %s", err, pTemp);
231 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the mnc.");
232 unique_ptr<char[],_CharDeleter> pMnc(pTemp);
235 r = plmn.Append(pMcc.get());
236 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to set plmn.");
238 r = plmn.Append(pMnc.get());
239 SysLog(NID_TEL, "The plmn value is %ls", plmn.GetPointer());
240 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to set plmn.");
242 _NetworkInfoImpl::GetInstance(networkInfo)->SetCellId(cellId);
243 _NetworkInfoImpl::GetInstance(networkInfo)->SetLac(lac);
244 _NetworkInfoImpl::GetInstance(networkInfo)->SetOperatorName(operatorName);
245 _NetworkInfoImpl::GetInstance(networkInfo)->SetMcc(atoi(pMcc.get()));
246 _NetworkInfoImpl::GetInstance(networkInfo)->SetMnc(atoi(pMnc.get()));
248 if (apiVersion == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
250 _NetworkInfoImpl::GetInstance(networkInfo)->SetPlmn(operatorName);
254 _NetworkInfoImpl::GetInstance(networkInfo)->SetPlmn(plmn);
261 _NetworkManagerImpl::SetNetworkSettingListener(ITelephonyNetworkSettingListener* pListener)
263 SysTryReturnResult(NID_TEL, __pTelephonyServiceProxy != null, E_SYSTEM, "A system error has occurred. IPC instance has not been constructed yet.");
265 result r = __pTelephonyServiceProxy->HasSystemPrivilege();
266 SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
268 if (__pSettingListener != null)
270 __pNetworkSettingEvent->RemoveListener(*__pSettingListener);
271 __pSettingListener = null;
274 // Creates event object
275 if (__pNetworkSettingEvent == null && pListener != null)
277 std::unique_ptr<_NetworkSettingEvent> pNetworkSettingEvent(new (std::nothrow) _NetworkSettingEvent());
279 SysTryReturnResult(NID_TEL, pNetworkSettingEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
281 r = pNetworkSettingEvent->Construct();
282 SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
284 __pNetworkSettingEvent = move(pNetworkSettingEvent);
288 if (pListener != null)
290 __pSettingListener = pListener;
291 r = __pNetworkSettingEvent->AddListener(*__pSettingListener, true);
296 __pNetworkSettingEvent.reset(null);
297 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
304 _NetworkManagerImpl::GetNetworkSelectionMode(void)
306 SysTryReturnResult(NID_TEL, __pTelephonyServiceProxy != null, E_SYSTEM, "A system error has occurred. IPC instance has not been constructed yet.");
308 result r = __pTelephonyServiceProxy->GetNetworkSelectionMode(this);
309 SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
310 SysTryReturnResult(NID_TEL, r != E_PRIVILEGE_DENIED, r, "Propagating.");
311 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_OPERATION_FAILED, "Failed to get selection mode.");
317 _NetworkManagerImpl::SelectNetwork(const NetworkInfo & networkInfo)
319 SysTryReturnResult(NID_TEL, __pTelephonyServiceProxy != null, E_SYSTEM, "IPC instance has not been constructed yet.");
321 const _NetworkInfoImpl* pNetworkInfoImpl = _NetworkInfoImpl::GetInstance(networkInfo);
322 TelNetworkSystemType_t networkSystemType = _TelephonyUtility::ConvertNetworkType(pNetworkInfoImpl->GetNetworkType());
324 result r = __pTelephonyServiceProxy->SelectNetwork(this, pNetworkInfoImpl->GetPlmn(), (int)networkSystemType);
325 SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
326 SysTryReturnResult(NID_TEL, r != E_PRIVILEGE_DENIED, r, "Propagating.");
327 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_OPERATION_FAILED, "Failed to select network manually.");
333 _NetworkManagerImpl::SelectNetwork(void)
335 SysTryReturnResult(NID_TEL, __pTelephonyServiceProxy != null, E_SYSTEM, "A system error has occurred. IPC instance has not been constructed yet.");
337 result r = __pTelephonyServiceProxy->SelectNetwork(this);
338 SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
339 SysTryReturnResult(NID_TEL, r != E_PRIVILEGE_DENIED, r, "Propagating.");
340 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_OPERATION_FAILED, "Failed to select network automatically.");
346 _NetworkManagerImpl::SearchNetwork(void)
348 SysTryReturnResult(NID_TEL, __pTelephonyServiceProxy != null, E_SYSTEM, "A system error has occurred. IPC instance has not been constructed yet.");
350 result r = __pTelephonyServiceProxy->SearchNetwork(this);
351 SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
352 SysTryReturnResult(NID_TEL, r != E_PRIVILEGE_DENIED, r, "Propagating.");
353 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_OPERATION_FAILED, "Failed to search network automatic.");
359 _NetworkManagerImpl::OnRoamingStateChangedCallback(bool isRoaming, void* pUserData)
361 SysLog(NID_TEL, "The callback has called and the roaming state is %s", isRoaming ? "True" : "False");
362 _NetworkManagerImpl* pNetworkManagerImpl = static_cast <_NetworkManagerImpl*>(pUserData);
364 pNetworkManagerImpl->OnTelephonyNetworkStatusChanged();
370 _NetworkManagerImpl::OnCallServiceStateChangedCallback(network_info_service_state_e serviceState, void* pUserData)
372 SysLog(NID_TEL, "The callback has called and the service state is %d", serviceState);
374 _NetworkManagerImpl* pNetworkManagerImpl = static_cast <_NetworkManagerImpl*>(pUserData);
376 pNetworkManagerImpl->OnTelephonyNetworkStatusChanged();
382 _NetworkManagerImpl::OnDataServiceStateChangedCallback(connection_type_e type, void* pUserData)
384 SysLog(NID_TEL, "The callback has called and the connection state is %d", type);
386 _NetworkManagerImpl* pNetworkManagerImpl = static_cast <_NetworkManagerImpl*>(pUserData);
388 pNetworkManagerImpl->OnTelephonyNetworkStatusChanged();
394 _NetworkManagerImpl::OnTelephonyNetworkStatusChanged(void)
396 bool isCallServiceAvailable = false;
397 bool isDataServiceAvailable = false;
398 bool isRoaming = false;
400 NetworkStatus networkStatus;
402 isCallServiceAvailable = IsServiceAvailable();
403 if (isCallServiceAvailable)
405 isDataServiceAvailable = IsDataAvailable();
409 isDataServiceAvailable = false;
411 isRoaming = IsRoaming();
413 SysLog(NID_TEL, "The network status Call[%d]->[%d] Data[%d]->[%d] Roaming[%d]->[%d]",
414 __isCallServiceAvailable, isCallServiceAvailable, __isDataServiceAvailable,
415 isDataServiceAvailable, __isRoaming, isRoaming);
417 if ((__isCallServiceAvailable == isCallServiceAvailable) &&
418 (__isDataServiceAvailable == isDataServiceAvailable) &&
419 (__isRoaming == isRoaming))
424 __isCallServiceAvailable = isCallServiceAvailable;
425 __isDataServiceAvailable = isDataServiceAvailable;
426 __isRoaming = isRoaming;
428 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsCallServiceAvailable(isCallServiceAvailable);
429 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsDataServiceAvailable(isDataServiceAvailable);
430 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsRoaming(isRoaming);
432 _NetworkManagerEventArg* pEventArg = new (std::nothrow)_NetworkManagerEventArg(networkStatus);
433 SysTryReturnVoidResult(NID_TEL, pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
434 (void)__pNetworkManagerEvent->Fire(*pEventArg);
438 _NetworkManagerImpl::IsDataAvailable(void)
440 int err = NETWORK_INFO_ERROR_NONE;
441 connection_cellular_state_e dataServiceState = CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
442 bool isDataAvailable = false;
444 err = connection_get_cellular_state(__pConnectionHandle.get(), &dataServiceState);
446 SysLog(NID_TEL, "The return value of connection_get_cellular_state() is 0x%x and the dataServiceState is %d", err, dataServiceState);
448 if (dataServiceState == CONNECTION_CELLULAR_STATE_AVAILABLE || dataServiceState == CONNECTION_CELLULAR_STATE_CONNECTED)
450 isDataAvailable = true;
454 isDataAvailable = false;
457 return isDataAvailable;
461 _NetworkManagerImpl::IsRoaming(void)
463 int err = NETWORK_INFO_ERROR_NONE;
464 bool isRoaming = false;
466 err = network_info_is_roaming(&isRoaming);
467 SysLog(NID_TEL, "The return value of network_info_is_roaming() is 0x%x and the roming state is %s", err, isRoaming ? "True" : "False");
473 _NetworkManagerImpl::IsServiceAvailable(bool checkEmergency /* = false */)
475 bool isAvailable = false;
476 int err = NETWORK_INFO_ERROR_NONE;
477 network_info_service_state_e state;
479 err = network_info_get_service_state(&state);
480 SysLog(NID_TEL, "The return value of network_info_get_service_state() is 0x%x and the state is %d and checkEmergency is %s",
481 err, state, checkEmergency ? "True" : "False");
483 if (!checkEmergency && state == NETWORK_INFO_SERVICE_STATE_IN_SERVICE)
487 else if (checkEmergency && (state == NETWORK_INFO_SERVICE_STATE_IN_SERVICE ||
488 state == NETWORK_INFO_SERVICE_STATE_EMERGENCY_ONLY))
497 _NetworkManagerImpl::IsNetworkAvailable(void)
499 bool isFlightModeEnabled = false;
500 result r = SettingInfo::GetValue(L"http://tizen.org/setting/network.flight_mode", isFlightModeEnabled);
501 SysLog(NID_TEL, "isFlightModeEnabled is %s", isFlightModeEnabled ? "True":"False");
502 SysLog(NID_TEL, "The return value of SettingInfo::GetValue() is %s", GetErrorMessage(r));
509 return !isFlightModeEnabled;
513 //_NetworkManagerImpl::GetStringOfNetworkEventType(_NetworkEventType type) const
515 // static const char* pStateStr[] =
517 // "CallServiceAvailable",
518 // "DataServiceAvailable ",
521 // return pStateStr[type];
525 _NetworkManagerImpl::GetInstance(NetworkManager& networkManager)
527 return networkManager.__pNetworkManagerImpl;
530 const _NetworkManagerImpl*
531 _NetworkManagerImpl::GetInstance(const NetworkManager& networkManager)
533 return networkManager.__pNetworkManagerImpl;
538 _NetworkManagerImpl::OnTelephonyNetworkSelectionModeReceived(bool isManual, result r)
540 SysLog(NID_TEL, "The mode is %s and the result is %s", isManual ? "Manual":"Automatic", GetErrorMessage(r));
542 if (__pNetworkSettingEvent != null)
544 _NetworkSettingEventArg* pEventArg = new (std::nothrow)_NetworkSettingEventArg(_NETWORK_EVENT_GET_SELECTION_MODE, isManual, r);
545 SysTryReturnVoidResult(NID_TEL, pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
546 (void)__pNetworkSettingEvent->Fire(*pEventArg);
551 _NetworkManagerImpl::OnTelephonyNetworkSelectionCompleted(result r)
553 SysLog(NID_TEL, "The listener has called with the result %s", GetErrorMessage(r));
555 if (__pNetworkSettingEvent != null)
557 _NetworkSettingEventArg* pEventArg = new (std::nothrow)_NetworkSettingEventArg(_NETWORK_EVENT_SELECT_NETWORK, r);
558 SysTryReturnVoidResult(NID_TEL, pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
559 (void)__pNetworkSettingEvent->Fire(*pEventArg);
564 _NetworkManagerImpl::OnTelephonyNetworkSearchCompleted(String message, result r)
566 SysLog(NID_TEL, "The listener has called with the result %s", GetErrorMessage(r));
568 if (__pNetworkSettingEvent != null)
570 IList* pNetworkInfoList = null;
574 pNetworkInfoList = ParsingMessageN(message);
576 if (pNetworkInfoList == null)
578 SysLog(NID_TEL, "ParsingMessageN() has failed ");
583 _NetworkSettingEventArg* pEventArg = new (std::nothrow)_NetworkSettingEventArg(_NETWORK_EVENT_SEARCH_COMPLETED, pNetworkInfoList, r);
584 SysTryReturnVoidResult(NID_TEL, pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
586 (void)__pNetworkSettingEvent->Fire(*pEventArg);
591 _NetworkManagerImpl::ParsingMessageN(const String& message)
593 result r = E_SUCCESS;
594 int currentIndex = 0;
597 NetworkInfo* pNetworkInfo = null;
599 int networkInfoCount = 0;
601 r = message.SubString(0, 1, temp);
602 SysTryReturn(NID_TEL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
606 r = Integer::Decode(temp, networkInfoCount);
607 SysTryReturn(NID_TEL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
609 ArrayList* pNetworkInfoList = null;
611 pNetworkInfoList = new (std::nothrow) ArrayList();
612 SysTryReturn(NID_TEL, pNetworkInfoList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
614 r = pNetworkInfoList->Construct(networkInfoCount);
615 SysTryReturn(NID_TEL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
617 for (int i = 0 ; i < networkInfoCount ; i++)
619 pNetworkInfo = GenerateNetworkInfoN(message, currentIndex);
621 pNetworkInfoList->Add(*pNetworkInfo);
624 return pNetworkInfoList;
629 _NetworkManagerImpl::GenerateNetworkInfoN(const String& message, int& currentIndex)
631 NetworkInfo* pNetworkInfo = null;
632 _NetworkInfoImpl* pNetworkInfoImpl = null;
637 pNetworkInfo = new (std::nothrow) NetworkInfo();
638 SysTryReturn(NID_TEL, pNetworkInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
640 pNetworkInfoImpl = _NetworkInfoImpl::GetInstance(*pNetworkInfo);
645 tempString = MessageWithLengthToString(message, currentIndex);
646 _TelephonyUtility::GetMccMncFromPlmn(tempString, mcc, mnc);
647 pNetworkInfoImpl->SetPlmn(tempString);
648 pNetworkInfoImpl->SetMcc(mcc);
649 pNetworkInfoImpl->SetMnc(mnc);
650 SysLog(NID_TEL, "The plmn value is %ls, the mcc value is %d and the mnc is %d",tempString.GetPointer(), mcc, mnc);
653 tempString = MessageWithLengthToString(message, currentIndex);
654 pNetworkInfoImpl->SetOperatorName(tempString);
655 SysLog(NID_TEL, "The Operator Name is %ls", tempString.GetPointer());
658 tempString = MessageToString(message, currentIndex);
659 Tizen::Base::Integer::Parse(tempString, temp);
661 _NetworkType networkType = _TelephonyUtility::ConvertNetworkType(static_cast<TelNetworkSystemType_t>(temp));
662 pNetworkInfoImpl->SetNetworkType(networkType);
663 SysLog(NID_TEL, "The NetworkType is %d", networkType);
670 _NetworkManagerImpl::MessageToString(const String& message, int& currentIndex)
674 result r = E_SUCCESS;
676 r = message.IndexOf(":", currentIndex, nextIndex);
680 SysLog(NID_TEL, "The result of message.IndexOf is %s", GetErrorMessage(r));
683 currentIndex = nextIndex + 1;
685 r = message.IndexOf(":", currentIndex, nextIndex);
689 SysLog(NID_TEL, "The result of message.IndexOf is %s", GetErrorMessage(r));
692 r = message.SubString(currentIndex, nextIndex-currentIndex, tempString);
696 SysLog(NID_TEL, "The result of message.SubString is %s", GetErrorMessage(r));
703 _NetworkManagerImpl::MessageWithLengthToString(const String& message, int& currentIndex)
705 // e.g. plmn or network name -> "05Olleh",
707 String tempString("");
708 result r = E_SUCCESS;
711 r = message.IndexOf(":", currentIndex, nextIndex);
715 SysLog(NID_TEL, "The result of message.IndexOf is %s", GetErrorMessage(r));
718 currentIndex = nextIndex + 1;
720 message.SubString(currentIndex, 2, tempString);
723 Tizen::Base::Integer::Decode(tempString, static_cast<int&>(len));
731 r = message.SubString(currentIndex, len, tempString);
735 SysLog(NID_TEL, "The result of message.IndexOf is %s", GetErrorMessage(r));
744 }} // Tizen::Telephony