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)
63 _NetworkManagerImpl::~_NetworkManagerImpl(void)
65 if (__pNetworkManagerEvent != null)
67 network_info_unset_service_state_changed_cb();
68 network_info_unset_roaming_state_changed_cb();
69 connection_unset_type_changed_cb(__pConnectionHandle.get());
74 _NetworkManagerImpl::Construct(ITelephonyNetworkEventListener* pListener)
76 connection_h pConnHandle = null;
77 int err = connection_create(&pConnHandle);
78 SysLog(NID_TEL, "The return value of connection_create() is %d", err);
79 SysTryReturnResult(NID_TEL, err == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the connection handle.");
81 std::unique_ptr<void, _ConnectionDeleter> pConnectionHandle(pConnHandle);
83 if (pListener != null)
85 // Register data service state changed event
86 err = connection_set_type_changed_cb(pConnectionHandle.get(),(connection_type_changed_cb)_NetworkManagerImpl::OnDataServiceStateChangedCallback, this);
87 SysLog(NID_TEL, "The return value of connection_set_type_changed_cb() is 0x%x", err);
88 SysTryReturnResult(NID_TEL, err == 0, E_SYSTEM, "A system error has occurred. Failed to register the callback function to received the data service state changed event.");
90 // Register call service state changed event
91 err = network_info_set_service_state_changed_cb((network_info_service_state_changed_cb) _NetworkManagerImpl::OnCallServiceStateChangedCallback, this);
92 SysLog(NID_TEL, "The return value of network_info_set_service_state_changed_cb() is 0x%x", err);
93 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM,
94 "A system error has occurred. Failed to register the callback function to received the call service state changed event.");
96 // Register roaming state changed event
97 err = network_info_set_roaming_state_changed_cb((network_info_roaming_state_changed_cb)_NetworkManagerImpl::OnRoamingStateChangedCallback, this);
98 SysLog(NID_TEL, "The return value of network_info_set_roaming_state_changed_cb() is 0x%x", err);
99 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM,
100 "A system error has occurred. Failed to register the callback function to received the roaming state changed event.");
102 unique_ptr<_NetworkManagerEvent> pNetworkManagerEvent(new (std::nothrow) _NetworkManagerEvent);
103 SysTryReturnResult(NID_TEL, pNetworkManagerEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
105 result r = pNetworkManagerEvent->Construct();
106 SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
107 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to construct of the _NetworkManagerEvent.");
109 pNetworkManagerEvent->AddListener(*pListener, true);
111 __pNetworkManagerEvent = move(pNetworkManagerEvent);
115 __pTelephonyServiceProxy = _TelephonyIpcProxy::GetInstance();
117 if (__pTelephonyServiceProxy == null)
119 SysLog(NID_TEL, "Creating an IPC instance to connect with the Connectivity service daemon has failed.");
122 __pConnectionHandle = move(pConnectionHandle);
128 _NetworkManagerImpl::GetNetworkStatus(NetworkStatus& networkStatus) const
130 int err = NETWORK_INFO_ERROR_NONE;
131 bool isRoaming = false;
132 bool isDataServiceAvailable = false;
133 bool isCallServiceAvailable = false;
134 connection_cellular_state_e dataServiceState = CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
136 SysTryReturnResult(NID_TEL, IsNetworkAvailable(), E_NETWORK_UNAVAILABLE, "The operation has failed because the device is in the offline mode.");
139 err = network_info_is_roaming(&isRoaming);
140 SysLog(NID_TEL, "The return value of network_info_is_roaming() is 0x%x and the roming state is %s", err, isRoaming ? "True" : "False");
142 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.");
143 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the roaming status.")
145 // Get the isCallServiceAvailable
146 SysTryReturnResult(NID_TEL, IsServiceAvailable(), E_SERVICE_UNAVAILABLE, "The operation failed because the device is out of the coverage area or in the emergency mode.")
147 isCallServiceAvailable = true;
149 // Get the isDataServiceAvailable
150 err = connection_get_cellular_state(__pConnectionHandle.get(), &dataServiceState);
152 SysLog(NID_TEL, "The return value of connection_get_cellular_state() is 0x%x and the dataServiceState is %d", err, dataServiceState);
153 SysTryReturnResult(NID_TEL, err == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the data service status.");
155 if (dataServiceState == CONNECTION_CELLULAR_STATE_AVAILABLE || dataServiceState == CONNECTION_CELLULAR_STATE_CONNECTED)
157 isDataServiceAvailable = true;
160 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsRoaming(isRoaming);
161 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsCallServiceAvailable(isCallServiceAvailable);
162 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsDataServiceAvailable(isDataServiceAvailable);
169 _NetworkManagerImpl::GetNetworkInfo(NetworkInfo& networkInfo) const
171 result r = E_SUCCESS;
173 SysTryReturnResult(NID_TEL, IsNetworkAvailable(), E_NETWORK_UNAVAILABLE,
174 "The operation has failed because the device is in the offline mode.");
175 SysTryReturnResult(NID_TEL, IsServiceAvailable(), E_SERVICE_UNAVAILABLE,
176 "The operation failed because the device is out of the coverage area or in the emergency mode.");
178 int err = NETWORK_INFO_ERROR_NONE;
179 _ApiVersion apiVersion = _AppInfo::GetApiVersion();
183 err = network_info_get_cell_id(&cellId);
184 SysLog(NID_TEL, "The return value of network_info_get_cell_id() is %d and the cellId value is %d", err, cellId);
185 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the cell ID.");
189 err = network_info_get_lac(&lac);
190 SysLog(NID_TEL, "The return value of network_info_get_lac() is %d and the lac value is %d", err, lac);
191 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the lac.");
195 // Get the operator name
196 err = network_info_get_provider_name(&pTemp);
197 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the plmn.");
198 unique_ptr<char[],_CharDeleter> pOperatorName(pTemp);
200 r = (StringUtil::Utf8ToString(pOperatorName.get(), operatorName));
201 SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
202 SysLog(NID_TEL, "The operatorname is %ls", operatorName.GetPointer());
205 err = network_info_get_mcc(&pTemp);
206 SysLog(NID_TEL, "The return value of network_info_get_mcc() is %d and the mcc value is %s", err, pTemp);
207 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the mcc.");
208 unique_ptr<char[],_CharDeleter> pMcc(pTemp);
211 err = network_info_get_mnc(&pTemp);
212 SysLog(NID_TEL, "The return value of network_info_get_mnc() is %d and the mnc value is %s", err, pTemp);
213 SysTryReturnResult(NID_TEL, err == NETWORK_INFO_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to get the mnc.");
214 unique_ptr<char[],_CharDeleter> pMnc(pTemp);
217 r = plmn.Append(pMcc.get());
218 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to set plmn.");
220 r = plmn.Append(pMnc.get());
221 SysLog(NID_TEL, "The plmn value is %ls", plmn.GetPointer());
222 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to set plmn.");
224 _NetworkInfoImpl::GetInstance(networkInfo)->SetCellId(cellId);
225 _NetworkInfoImpl::GetInstance(networkInfo)->SetLac(lac);
226 _NetworkInfoImpl::GetInstance(networkInfo)->SetOperatorName(operatorName);
227 _NetworkInfoImpl::GetInstance(networkInfo)->SetMcc(atoi(pMcc.get()));
228 _NetworkInfoImpl::GetInstance(networkInfo)->SetMnc(atoi(pMnc.get()));
230 if (apiVersion == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
232 _NetworkInfoImpl::GetInstance(networkInfo)->SetPlmn(operatorName);
236 _NetworkInfoImpl::GetInstance(networkInfo)->SetPlmn(plmn);
243 _NetworkManagerImpl::SetNetworkSettingListener(ITelephonyNetworkSettingListener* pListener)
245 SysTryReturnResult(NID_TEL, __pTelephonyServiceProxy != null, E_SYSTEM, "A system error has occurred. IPC instance has not been constructed yet.");
247 result r = __pTelephonyServiceProxy->HasSystemPrivilege();
248 SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
250 if (__pSettingListener != null)
252 __pNetworkSettingEvent->RemoveListener(*__pSettingListener);
253 __pSettingListener = null;
256 // Creates event object
257 if (__pNetworkSettingEvent == null && pListener != null)
259 std::unique_ptr<_NetworkSettingEvent> pNetworkSettingEvent(new (std::nothrow) _NetworkSettingEvent());
261 SysTryReturnResult(NID_TEL, pNetworkSettingEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
263 r = pNetworkSettingEvent->Construct();
264 SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
266 __pNetworkSettingEvent = move(pNetworkSettingEvent);
270 if (pListener != null)
272 __pSettingListener = pListener;
273 r = __pNetworkSettingEvent->AddListener(*__pSettingListener, true);
278 __pNetworkSettingEvent.reset(null);
279 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
286 _NetworkManagerImpl::GetNetworkSelectionMode(void)
288 SysTryReturnResult(NID_TEL, __pTelephonyServiceProxy != null, E_SYSTEM, "A system error has occurred. IPC instance has not been constructed yet.");
290 result r = __pTelephonyServiceProxy->GetNetworkSelectionMode(this);
291 SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
292 SysTryReturnResult(NID_TEL, r != E_PRIVILEGE_DENIED, r, "Propagating.");
293 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_OPERATION_FAILED, "Failed to get selection mode.");
299 _NetworkManagerImpl::SelectNetwork(const NetworkInfo & networkInfo)
301 SysTryReturnResult(NID_TEL, __pTelephonyServiceProxy != null, E_SYSTEM, "IPC instance has not been constructed yet.");
303 const _NetworkInfoImpl* pNetworkInfoImpl = _NetworkInfoImpl::GetInstance(networkInfo);
304 TelNetworkSystemType_t networkSystemType = _TelephonyUtility::ConvertNetworkType(pNetworkInfoImpl->GetNetworkType());
306 result r = __pTelephonyServiceProxy->SelectNetwork(this, pNetworkInfoImpl->GetPlmn(), (int)networkSystemType);
307 SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
308 SysTryReturnResult(NID_TEL, r != E_PRIVILEGE_DENIED, r, "Propagating.");
309 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_OPERATION_FAILED, "Failed to select network manually.");
315 _NetworkManagerImpl::SelectNetwork(void)
317 SysTryReturnResult(NID_TEL, __pTelephonyServiceProxy != null, E_SYSTEM, "A system error has occurred. IPC instance has not been constructed yet.");
319 result r = __pTelephonyServiceProxy->SelectNetwork(this);
320 SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
321 SysTryReturnResult(NID_TEL, r != E_PRIVILEGE_DENIED, r, "Propagating.");
322 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_OPERATION_FAILED, "Failed to select network automatically.");
328 _NetworkManagerImpl::SearchNetwork(void)
330 SysTryReturnResult(NID_TEL, __pTelephonyServiceProxy != null, E_SYSTEM, "A system error has occurred. IPC instance has not been constructed yet.");
332 result r = __pTelephonyServiceProxy->SearchNetwork(this);
333 SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
334 SysTryReturnResult(NID_TEL, r != E_PRIVILEGE_DENIED, r, "Propagating.");
335 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_OPERATION_FAILED, "Failed to search network automatic.");
341 _NetworkManagerImpl::OnRoamingStateChangedCallback(bool isRoaming, void* pUserData)
343 SysLog(NID_TEL, "The callback has called and the roaming state is %s", isRoaming ? "True" : "False");
344 _NetworkManagerImpl* pNetworkManagerImpl = static_cast <_NetworkManagerImpl*>(pUserData);
346 pNetworkManagerImpl->OnTelephonyNetworkStatusChanged(_NETWORK_EVENT_ROAMING, isRoaming);
352 _NetworkManagerImpl::OnCallServiceStateChangedCallback(network_info_service_state_e serviceState, void* pUserData)
354 SysLog(NID_TEL, "The callback has called and the service state is %d", serviceState);
356 _NetworkManagerImpl* pNetworkManagerImpl = static_cast <_NetworkManagerImpl*>(pUserData);
358 bool isAvailable = false;
359 if (serviceState == NETWORK_INFO_SERVICE_STATE_IN_SERVICE)
364 pNetworkManagerImpl->OnTelephonyNetworkStatusChanged(_NETWORK_EVENT_CALL, isAvailable);
370 _NetworkManagerImpl::OnDataServiceStateChangedCallback(connection_type_e type, void* pUserData)
372 if (type != CONNECTION_TYPE_CELLULAR)
374 SysLog(NID_TEL, "The connection type %d can be ignored", type);
378 _NetworkManagerImpl* pNetworkManagerImpl = static_cast <_NetworkManagerImpl*>(pUserData);
379 bool isAvailable = false;
381 // Get the isDataServiceAvailable
382 connection_cellular_state_e dataServiceState = CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
383 int err = connection_get_cellular_state(pNetworkManagerImpl->__pConnectionHandle.get(), &dataServiceState);
384 SysLog(NID_TEL, "The return value of connection_get_cellular_state() is 0x%x", err);
385 SysTryReturnVoidResult(NID_TEL, err == CONNECTION_ERROR_NONE, E_SYSTEM, "[%s] A system error has occurred. Failed to get the data service status.", GetErrorMessage(E_SYSTEM));
387 if (dataServiceState == CONNECTION_CELLULAR_STATE_AVAILABLE || dataServiceState == CONNECTION_CELLULAR_STATE_CONNECTED)
392 pNetworkManagerImpl->OnTelephonyNetworkStatusChanged(_NETWORK_EVENT_DATA, isAvailable);
398 _NetworkManagerImpl::OnTelephonyNetworkStatusChanged(_NetworkEventType type, bool data)
400 SysLog(NID_TEL, "The listener has called with %s state", GetStringOfNetworkEventType(type));
402 result r = E_SUCCESS;
403 NetworkStatus networkStatus;
404 r = GetNetworkStatus(networkStatus);
405 SysTryReturnVoidResult(NID_TEL, r == E_SUCCESS, r, "[%s] Failed to get network status", GetErrorMessage(r));
409 case _NETWORK_EVENT_CALL:
410 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsCallServiceAvailable(data);
413 case _NETWORK_EVENT_DATA:
414 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsDataServiceAvailable(data);
417 case _NETWORK_EVENT_ROAMING:
418 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsRoaming(data);
426 _NetworkManagerEventArg* pEventArg = new (std::nothrow)_NetworkManagerEventArg(networkStatus);
427 SysTryReturnVoidResult(NID_TEL, pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
428 (void)__pNetworkManagerEvent->Fire(*pEventArg);
432 _NetworkManagerImpl::IsServiceAvailable(bool checkEmergency /* = false */)
434 bool isAvailable = false;
435 int err = NETWORK_INFO_ERROR_NONE;
436 network_info_service_state_e state;
438 err = network_info_get_service_state(&state);
439 SysLog(NID_TEL, "The return value of network_info_get_service_state() is 0x%x and the state is %d and checkEmergency is %s",
440 err, state, checkEmergency ? "True" : "False");
442 if (!checkEmergency && state == NETWORK_INFO_SERVICE_STATE_IN_SERVICE)
446 else if (checkEmergency && (state == NETWORK_INFO_SERVICE_STATE_IN_SERVICE ||
447 state == NETWORK_INFO_SERVICE_STATE_EMERGENCY_ONLY))
456 _NetworkManagerImpl::IsNetworkAvailable(void)
458 bool isFlightModeEnabled = false;
459 result r = SettingInfo::GetValue(L"http://tizen.org/setting/network.flight_mode", isFlightModeEnabled);
460 SysLog(NID_TEL, "isFlightModeEnabled is %s", isFlightModeEnabled ? "True":"False");
461 SysLog(NID_TEL, "The return value of SettingInfo::GetValue() is %s", GetErrorMessage(r));
468 return !isFlightModeEnabled;
472 _NetworkManagerImpl::GetStringOfNetworkEventType(_NetworkEventType type) const
474 static const char* pStateStr[] =
476 "CallServiceAvailable",
477 "DataServiceAvailable ",
480 return pStateStr[type];
484 _NetworkManagerImpl::GetInstance(NetworkManager& networkManager)
486 return networkManager.__pNetworkManagerImpl;
489 const _NetworkManagerImpl*
490 _NetworkManagerImpl::GetInstance(const NetworkManager& networkManager)
492 return networkManager.__pNetworkManagerImpl;
497 _NetworkManagerImpl::OnTelephonyNetworkSelectionModeReceived(bool isManual, result r)
499 SysLog(NID_TEL, "The mode is %s and the result is %s", isManual ? "Manual":"Automatic", GetErrorMessage(r));
501 if (__pNetworkSettingEvent != null)
503 _NetworkSettingEventArg* pEventArg = new (std::nothrow)_NetworkSettingEventArg(_NETWORK_EVENT_GET_SELECTION_MODE, isManual, r);
504 SysTryReturnVoidResult(NID_TEL, pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
505 (void)__pNetworkSettingEvent->Fire(*pEventArg);
510 _NetworkManagerImpl::OnTelephonyNetworkSelectionCompleted(result r)
512 SysLog(NID_TEL, "The listener has called with the result %s", GetErrorMessage(r));
514 if (__pNetworkSettingEvent != null)
516 _NetworkSettingEventArg* pEventArg = new (std::nothrow)_NetworkSettingEventArg(_NETWORK_EVENT_SELECT_NETWORK, r);
517 SysTryReturnVoidResult(NID_TEL, pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
518 (void)__pNetworkSettingEvent->Fire(*pEventArg);
523 _NetworkManagerImpl::OnTelephonyNetworkSearchCompleted(String message, result r)
525 SysLog(NID_TEL, "The listener has called with the result %s", GetErrorMessage(r));
527 if (__pNetworkSettingEvent != null)
529 IList* pNetworkInfoList = null;
533 pNetworkInfoList = ParsingMessageN(message);
535 if (pNetworkInfoList == null)
537 SysLog(NID_TEL, "ParsingMessageN() has failed ");
542 _NetworkSettingEventArg* pEventArg = new (std::nothrow)_NetworkSettingEventArg(_NETWORK_EVENT_SEARCH_COMPLETED, pNetworkInfoList, r);
543 SysTryReturnVoidResult(NID_TEL, pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
545 (void)__pNetworkSettingEvent->Fire(*pEventArg);
550 _NetworkManagerImpl::ParsingMessageN(const String& message)
552 result r = E_SUCCESS;
553 int currentIndex = 0;
556 NetworkInfo* pNetworkInfo = null;
558 int networkInfoCount = 0;
560 r = message.SubString(0, 1, temp);
561 SysTryReturn(NID_TEL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
565 r = Integer::Decode(temp, networkInfoCount);
566 SysTryReturn(NID_TEL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
568 ArrayList* pNetworkInfoList = null;
570 pNetworkInfoList = new (std::nothrow) ArrayList();
571 SysTryReturn(NID_TEL, pNetworkInfoList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
573 r = pNetworkInfoList->Construct(networkInfoCount);
574 SysTryReturn(NID_TEL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
576 for (int i = 0 ; i < networkInfoCount ; i++)
578 pNetworkInfo = GenerateNetworkInfoN(message, currentIndex);
580 pNetworkInfoList->Add(*pNetworkInfo);
583 return pNetworkInfoList;
588 _NetworkManagerImpl::GenerateNetworkInfoN(const String& message, int& currentIndex)
590 NetworkInfo* pNetworkInfo = null;
591 _NetworkInfoImpl* pNetworkInfoImpl = null;
596 pNetworkInfo = new (std::nothrow) NetworkInfo();
597 SysTryReturn(NID_TEL, pNetworkInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
599 pNetworkInfoImpl = _NetworkInfoImpl::GetInstance(*pNetworkInfo);
604 tempString = MessageWithLengthToString(message, currentIndex);
605 _TelephonyUtility::GetMccMncFromPlmn(tempString, mcc, mnc);
606 pNetworkInfoImpl->SetPlmn(tempString);
607 pNetworkInfoImpl->SetMcc(mcc);
608 pNetworkInfoImpl->SetMnc(mnc);
609 SysLog(NID_TEL, "The plmn value is %ls, the mcc value is %d and the mnc is %d",tempString.GetPointer(), mcc, mnc);
612 tempString = MessageWithLengthToString(message, currentIndex);
613 pNetworkInfoImpl->SetOperatorName(tempString);
614 SysLog(NID_TEL, "The Operator Name is %ls", tempString.GetPointer());
617 tempString = MessageToString(message, currentIndex);
618 Tizen::Base::Integer::Parse(tempString, temp);
620 _NetworkType networkType = _TelephonyUtility::ConvertNetworkType(static_cast<TelNetworkSystemType_t>(temp));
621 pNetworkInfoImpl->SetNetworkType(networkType);
622 SysLog(NID_TEL, "The NetworkType is %d", networkType);
629 _NetworkManagerImpl::MessageToString(const String& message, int& currentIndex)
633 result r = E_SUCCESS;
635 r = message.IndexOf(":", currentIndex, nextIndex);
639 SysLog(NID_TEL, "The result of message.IndexOf is %s", GetErrorMessage(r));
642 currentIndex = nextIndex + 1;
644 r = message.IndexOf(":", currentIndex, nextIndex);
648 SysLog(NID_TEL, "The result of message.IndexOf is %s", GetErrorMessage(r));
651 r = message.SubString(currentIndex, nextIndex-currentIndex, tempString);
655 SysLog(NID_TEL, "The result of message.SubString is %s", GetErrorMessage(r));
662 _NetworkManagerImpl::MessageWithLengthToString(const String& message, int& currentIndex)
664 // e.g. plmn or network name -> "05Olleh",
666 String tempString("");
667 result r = E_SUCCESS;
670 r = message.IndexOf(":", currentIndex, nextIndex);
674 SysLog(NID_TEL, "The result of message.IndexOf is %s", GetErrorMessage(r));
677 currentIndex = nextIndex + 1;
679 message.SubString(currentIndex, 2, tempString);
682 Tizen::Base::Integer::Decode(tempString, static_cast<int&>(len));
690 r = message.SubString(currentIndex, len, tempString);
694 SysLog(NID_TEL, "The result of message.IndexOf is %s", GetErrorMessage(r));
703 }} // Tizen::Telephony