Modify SMACK manifest according three domain model
[platform/framework/native/connectivity-service.git] / src / NetService.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file    NetService.cpp
20  * @brief   This is the implementation file for the %NetService class.
21  */
22
23 #include <net_connection.h>
24 #include <FBaseSysLog.h>
25 #include <FBaseString.h>
26 #include <FNetNetAccountManager.h>
27 #include <FNetNetConnectionInfo.h>
28 #include <FApp_AppManagerImpl.h>
29 #include <FBase_StringConverter.h>
30 #include <FNet_NetTypes.h>
31 #include <FNet_NetAccountInfoImpl.h>
32 #include "ConnectivityUtility.h"
33 #include "NetService.h"
34 #include "NetAccountDatabase.h"
35
36 using namespace std;
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::Net;
40
41
42 NetService* NetService::__pNetService = null;
43
44
45 NetService*
46 NetService::GetInstance(void)
47 {
48     result r = E_SUCCESS;
49
50     if (__pNetService == null)
51         {
52                 unique_ptr<NetService> pInstance(new (std::nothrow) NetService());
53                 SysTryReturn(NID_NET, pInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
54
55                 r = pInstance->Construct();
56                 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
57
58                 __pNetService = pInstance.release();
59         }
60
61         return __pNetService;
62 }
63
64
65 NetService::NetService(void)
66         : __pConnectionHandle(null)
67         , __internetAccountId(INVALID_HANDLE)
68         , __mmsAccountId(INVALID_HANDLE)
69 {
70         __internetProfileName.Clear();
71         __mmsProfileName.Clear();
72 }
73
74 NetService::~NetService(void)
75 {
76         if (__pConnectionHandle != null)
77         {
78                 connection_destroy(__pConnectionHandle);
79                 __pConnectionHandle = null;
80         }
81 }
82
83 result
84 NetService::Construct(void)
85 {
86         result r = E_SUCCESS;
87         int ret = CONNECTION_ERROR_NONE;
88
89         r = NetAccountDatabase::InitializeRepository();
90     SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
91
92     UpdateNetAccountDb();
93
94         ret = connection_create(&__pConnectionHandle);
95     SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to create a connection handle.[%d]", ret);
96
97     return E_SUCCESS;
98 }
99
100 result
101 NetService::GetAppNetAccountId(const String& profileName, int& netAccountId)
102 {
103         result r = E_SUCCESS;
104
105         if (profileName.Equals(L"Internet", false))
106         {
107                 netAccountId = GetInternetAccountId();
108         }
109         else if (profileName.Equals(L"Mms", false))
110         {
111                 netAccountId = GetMmsAccountId();
112         }
113         else
114         {
115                 netAccountId = INVALID_HANDLE;
116                 r = E_INVALID_ARG;
117         }
118
119         return r;
120 }
121
122 result
123 NetService::SetNetAccountId(int netAccountId, int& netAccountId2)
124 {
125         result r = E_SUCCESS;
126
127         netAccountId2 = netAccountId;
128
129         return r;
130 }
131
132 result
133 NetService::UpdateSystemNetAccount(const NetAccountInfo& netAccountInfo)
134 {
135         result r = E_SUCCESS;
136
137         int ret = CONNECTION_ERROR_NONE;
138         connection_h connectionHandle = null;
139         connection_profile_h profileHandle = null;
140
141         String profileName;
142
143         r = NetAccountDatabase::GetProfileName(netAccountInfo.GetAccountId(), profileName);
144         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
145
146         ret = connection_create(&connectionHandle);
147         SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
148                         "A system error has been occurred. The return value from connection_create() is %d", ret);
149
150         profileHandle = ConnectivityUtility::GetPsProfileHandleN(profileName);
151         SysTryReturnResult(NID_NET, profileHandle != null, E_INVALID_ACCOUNT,
152                         "Invalid network account. The current value of account id is %d", netAccountInfo.GetAccountId());
153
154         r = ConnectivityUtility::UpdateProfileInfo(&netAccountInfo, profileHandle, false);
155         if (IsFailed(r))
156         {
157                 SysLogException(NID_NET, r, "[%s] Propagating.", GetErrorMessage(r));
158
159                 connection_profile_destroy(profileHandle);
160                 connection_destroy(connectionHandle);
161
162                 return r;
163         }
164
165         ret = connection_update_profile((void*)connectionHandle, profileHandle);
166
167         connection_profile_destroy(profileHandle);
168         connection_destroy(connectionHandle);
169
170         SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
171                         "A system error has been occurred. The return value from connection_update_profile() is %d", ret);
172
173         r = NetAccountDatabase::UpdateAccountName(netAccountInfo.GetAccountId(), netAccountInfo.GetAccountName());
174         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
175
176         return r;
177 }
178
179 result
180 NetService::ResetNetStatistics(int bearerType, int statType)
181 {
182         int err = CONNECTION_ERROR_NONE;
183
184         SysTryReturnResult(NID_NET, (bearerType == NET_BEARER_WIFI || bearerType == NET_BEARER_PS),
185                         E_INVALID_ARG, "Invalid bearer type. [%d]", bearerType);
186
187         //Reset net statistics info based on type
188         switch (statType)
189         {
190         //supported cases
191         case NET_STAT_RCVD_SIZE:
192                 if (bearerType == NET_BEARER_PS)
193                 {
194                         err = connection_reset_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
195                 }
196                 else
197                 {
198                         err = connection_reset_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
199                 }
200
201                 break;
202
203         case NET_STAT_SENT_SIZE:
204                 if (bearerType == NET_BEARER_PS)
205                 {
206                         err = connection_reset_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
207                 }
208                 else
209                 {
210                         err = connection_reset_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
211                 }
212
213                 break;
214
215         case NET_STAT_TOTAL_RCVD_SIZE:
216                 if (bearerType == NET_BEARER_PS)
217                 {
218                         err = connection_reset_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
219                 }
220                 else
221                 {
222                         err = connection_reset_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
223                 }
224
225                 break;
226
227         case NET_STAT_TOTAL_SENT_SIZE:
228                 if (bearerType == NET_BEARER_PS)
229                 {
230                         err = connection_reset_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
231                 }
232                 else
233                 {
234                         err = connection_reset_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
235                 }
236
237                 break;
238
239         default:
240                 SysTryReturnResult(NID_NET, false, E_INVALID_ARG, "Invalid argument is used.");
241
242                 break;
243         }
244
245         SysTryReturnResult(NID_NET, err == CONNECTION_ERROR_NONE, E_SYSTEM,     "A system error has been occurred. Operation failed. [err:%d]", err);
246
247         return E_SUCCESS;
248 }
249
250 result
251 NetService::ResetAllNetStatistics(int bearerType)
252 {
253         int err = CONNECTION_ERROR_NONE;
254
255         SysTryReturnResult(NID_NET, (bearerType == NET_BEARER_WIFI || bearerType == NET_BEARER_PS),
256                         E_INVALID_ARG, "Invalid bearer type. [%d]", bearerType);
257
258         //we support only PS and WIFI
259         if (bearerType == NET_BEARER_PS)
260         {
261                 err = connection_reset_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
262                 SysTryReturnResult(NID_NET, err == CONNECTION_ERROR_NONE, E_SYSTEM,     "A system error has been occurred. Operation failed. [err:%d]", err);
263
264                 err = connection_reset_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
265                 SysTryReturnResult(NID_NET, err == CONNECTION_ERROR_NONE, E_SYSTEM,     "A system error has been occurred. Operation failed. [err:%d]", err);
266
267                 err = connection_reset_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
268                 SysTryReturnResult(NID_NET, err == CONNECTION_ERROR_NONE, E_SYSTEM,     "A system error has been occurred. Operation failed. [err:%d]", err);
269
270                 err = connection_reset_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
271                 SysTryReturnResult(NID_NET, err == CONNECTION_ERROR_NONE, E_SYSTEM,     "A system error has been occurred. Operation failed. [err:%d]", err);
272
273         }
274         else
275         {
276                 err = connection_reset_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
277                 SysTryReturnResult(NID_NET, err == CONNECTION_ERROR_NONE, E_SYSTEM,     "A system error has been occurred. Operation failed. [err:%d]", err);
278
279                 err = connection_reset_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
280                 SysTryReturnResult(NID_NET, err == CONNECTION_ERROR_NONE, E_SYSTEM,     "A system error has been occurred. Operation failed. [err:%d]", err);
281
282                 err = connection_reset_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
283                 SysTryReturnResult(NID_NET, err == CONNECTION_ERROR_NONE, E_SYSTEM,     "A system error has been occurred. Operation failed. [err:%d]", err);
284
285                 err = connection_reset_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
286                 SysTryReturnResult(NID_NET, err == CONNECTION_ERROR_NONE, E_SYSTEM,     "A system error has been occurred. Operation failed. [err:%d]", err);
287         }
288
289         return E_SUCCESS;
290 }
291
292 result
293 NetService::GetNetConnectionInfo(int netAccountId, NetConnectionInfo* pConnectionInfo)
294 {
295         result r = E_SUCCESS;
296     String profileName;
297         connection_profile_h profileHandle = null;
298
299         r = NetAccountDatabase::GetProfileName(netAccountId, profileName);
300         SysTryReturnResult(NID_NET, r == E_SUCCESS, E_INVALID_ACCOUNT, "Invalid network account. accountId:%d", netAccountId);
301
302         profileHandle = ConnectivityUtility::GetPsProfileHandleN(profileName);
303         SysTryReturnResult(NID_NET, profileHandle != null, E_INVALID_ACCOUNT, "Invalid network account. accountId:%d", netAccountId);
304
305         ConnectivityUtility::UpdateNetConnectionInfo(pConnectionInfo, profileHandle, false);
306         connection_profile_destroy(profileHandle);
307
308         return E_SUCCESS;
309 }
310
311 result
312 NetService::GetAllNetConnectionInfo(ArrayList* pList)
313 {
314         NetConnectionInfo* pInfo = null;
315         int ret = CONNECTION_ERROR_NONE;
316         connection_profile_iterator_h iterator = null;
317         connection_profile_h profileHandle = null;
318
319         ret = connection_get_profile_iterator(__pConnectionHandle, CONNECTION_ITERATOR_TYPE_CONNECTED, &iterator);
320         SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
321                         "A system error has been occurred. The return value from connection_get_profile_iterator() is %d", ret);
322         unique_ptr<void, _ProfileIteratorDeleter> pIterator(iterator);
323
324         ret = connection_profile_iterator_next(iterator, &profileHandle);
325         while ((ret == CONNECTION_ERROR_NONE) && (profileHandle != null))
326         {
327                 pInfo = new (std::nothrow) NetConnectionInfo();
328                 SysTryReturnResult(NID_NET, pInfo != null, E_OUT_OF_MEMORY, "Insufficient memory.");
329
330                 ConnectivityUtility::UpdateNetConnectionInfo(pInfo, profileHandle, false);
331                 pList->Add(pInfo);
332
333                 profileHandle = null;
334                 ret = connection_profile_iterator_next(iterator, &profileHandle);
335         }
336
337         SysLog(NID_NET, "GetAllNetConnectionInfo() has been succeeded with count:%d", pList->GetCount());
338
339         return E_SUCCESS;
340 }
341
342 NetAccountId
343 NetService::CreateNetAccount(const String& packageId, const NetAccountInfo& netAccountInfo)
344 {
345         result r = E_SUCCESS;
346         NetAccountId accountId = INVALID_HANDLE;
347         String profileName;
348         bool isCreated = false;
349         int ret = CONNECTION_ERROR_NONE;
350         connection_h connectionHandle = __pConnectionHandle;
351         connection_profile_h profileHandle = null;
352
353         SysTryReturn(NID_NET, !netAccountInfo.GetAccountName().IsEmpty(),
354                         INVALID_HANDLE, E_INVALID_ARG,
355                         "[%s] Invalid argument is used. accountName is an empty string.", GetErrorMessage(E_INVALID_ARG));
356
357         unique_ptr<IList, AllElementsDeleter> pProfileNamesBefore(NetService::GetAppProfileNamesN());
358         SysTryReturn(NID_NET, pProfileNamesBefore != null, INVALID_HANDLE, E_OUT_OF_MEMORY,
359                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
360
361         unique_ptr<char[]> pAccountName(_StringConverter::CopyToCharArrayN(netAccountInfo.GetAccountName()));
362         SysTryReturn(NID_NET, pAccountName != null, INVALID_HANDLE, E_OUT_OF_MEMORY,
363                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
364
365         ret = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, pAccountName.get(), &profileHandle);
366         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE,     E_SYSTEM,
367                         "[%s] A system error has been occurred. The return value from connection_profile_create() is %d",
368                         GetErrorMessage(E_SYSTEM), ret);
369
370         unique_ptr<void, _ProfileDeleter> pProfileHandle(profileHandle);
371         r = ConnectivityUtility::UpdateProfileInfo(&netAccountInfo, profileHandle, true);
372         SysTryReturn(NID_NET, r == E_SUCCESS, INVALID_HANDLE, r, "[%s] Propagating.", GetErrorMessage(r));
373
374         ret = connection_add_profile(connectionHandle, profileHandle);
375         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
376                         "[%s] A system error has been occurred. The return value from connection_add_profile() is %d",
377                         GetErrorMessage(E_SYSTEM), ret);
378
379         unique_ptr<IList, AllElementsDeleter> pProfileNamesAfter(NetService::GetAppProfileNamesN());
380         SysTryReturn(NID_NET, pProfileNamesAfter != null, INVALID_HANDLE, E_OUT_OF_MEMORY,
381                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
382
383         unique_ptr<IEnumerator> pEnum(pProfileNamesAfter->GetEnumeratorN());
384         SysTryReturn(NID_NET, pEnum != null, INVALID_HANDLE, E_OUT_OF_MEMORY,
385                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
386
387         while (pEnum->MoveNext() == E_SUCCESS)
388         {
389                 String* pProfileName = null;
390
391                 pProfileName = dynamic_cast<String*>(pEnum->GetCurrent());
392                 if ((pProfileName != null) && (!pProfileName->IsEmpty()))
393                 {
394                         if (!pProfileNamesBefore->Contains(*pProfileName))
395                         {
396                                 SysLog(NID_NET, "ProfileName[%ls] is not found before, so it is a new profile name.", pProfileName->GetPointer());
397                                 isCreated = true;
398                                 profileName = *pProfileName;
399
400                                 break;
401                         }
402                 }
403         }
404
405         SysTryReturn(NID_NET, isCreated, INVALID_HANDLE, E_SYSTEM,
406                         "[%s] A system error has been occurred. New account is not found.", GetErrorMessage(E_SYSTEM));
407         SysTryReturn(NID_NET, !profileName.IsEmpty(), INVALID_HANDLE, E_SYSTEM,
408                         "[%s] A system error has been occurred. The profileName of new account is an empty string.", GetErrorMessage(E_SYSTEM));
409
410         r = NetAccountDatabase::AddAccount(netAccountInfo.GetAccountName(), profileName, packageId, accountId);
411         SysTryReturn(NID_NET, r == E_SUCCESS, INVALID_HANDLE, r, "[%s] Propagating.", GetErrorMessage(r));
412
413         ClearLastResult();
414
415         SysSecureLog( NID_NET, "CreateNetAccount() has been succeeded with accountId:%d, accountName:%ls, profileName:%ls",
416                         netAccountInfo.GetAccountId(), netAccountInfo.GetAccountName().GetPointer(), profileName.GetPointer());
417
418         return accountId;
419 }
420
421 result
422 NetService::DeleteNetAccount(const String& packageId, NetAccountId netAccountId)
423 {
424         result r = E_SUCCESS;
425         String profileName;
426         bool isReadOnly = true;
427         int ret = CONNECTION_ERROR_NONE;
428         connection_h connectionHandle = __pConnectionHandle;
429
430         SysLog(NID_NET, "DeleteNetAccount() has been called with accountId:%d", netAccountId);
431
432         SysTryReturnResult(NID_NET, netAccountId > 0, E_INVALID_ACCOUNT,
433                         "Invalid network account. accountId=%d", netAccountId);
434
435         isReadOnly = NetAccountDatabase::IsReadOnly(packageId, netAccountId);
436         r = GetLastResult();
437         SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
438         SysTryReturnResult(NID_NET, !isReadOnly, E_INVALID_OPERATION, "Not allowed on the specified network account.");
439
440         r = NetAccountDatabase::GetProfileName(netAccountId, profileName);
441         SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
442         SysTryReturnResult(NID_NET, r == E_SUCCESS, E_INVALID_ACCOUNT, "Invalid network account. accountId=%d", netAccountId);
443
444         unique_ptr<void, _ProfileDeleter> pProfileHandle(ConnectivityUtility::GetPsProfileHandleN(profileName));
445         SysTryReturnResult(NID_NET, pProfileHandle != null, E_INVALID_ACCOUNT,
446                         "Invalid network account. accountId=%d", netAccountId);
447
448         ret = connection_remove_profile(connectionHandle, pProfileHandle.get());
449         SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
450                         "A system error has been occurred. The return value from connection_remove_profile() is %d", ret);
451
452         r = NetAccountDatabase::RemoveAccountByAccountId(netAccountId);
453         SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
454         SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM,
455                         "A system error has been occurred. Failed to remove the account.");
456
457         return r;
458 }
459
460 result
461 NetService::UpdateNetAccount(const String& packageId, const NetAccountInfo& netAccountInfo)
462 {
463         result r = E_SUCCESS;
464         String profileName;
465         bool isReadOnly = true;
466         const _NetAccountInfoImpl* pInfoImpl = _NetAccountInfoImpl::GetInstance(netAccountInfo);
467         int ret = CONNECTION_ERROR_NONE;
468         connection_h connectionHandle = __pConnectionHandle;
469
470         SysTryReturnResult(NID_NET, pInfoImpl != null, E_INVALID_ARG,
471                         "Invalid argument is used. Network account info is invalid.");
472         SysTryReturnResult(NID_NET, netAccountInfo.GetAccountId() > 0, E_INVALID_ARG,
473                         "Invalid argument is used. accountId=%d", netAccountInfo.GetAccountId());
474         SysTryReturnResult(NID_NET, !netAccountInfo.GetAccountName().IsEmpty(), E_INVALID_ARG,
475                         "Invalid argument is used. accountName is an empty string.");
476
477         isReadOnly = NetAccountDatabase::IsReadOnly(packageId, netAccountInfo.GetAccountId());
478         r = GetLastResult();
479         SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
480         SysTryReturnResult(NID_NET, !isReadOnly, E_INVALID_OPERATION,
481                         "Not allowed on the specified network account.");
482
483         r = NetAccountDatabase::GetProfileName(netAccountInfo.GetAccountId(), profileName);
484         SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
485         SysTryReturnResult(NID_NET, r == E_SUCCESS, E_INVALID_ARG,
486                         "Invalid argument is used. accountId=%d.", netAccountInfo.GetAccountId());
487
488         unique_ptr<void, _ProfileDeleter> pProfileHandle(ConnectivityUtility::GetPsProfileHandleN(profileName));
489         SysTryReturnResult(NID_NET, pProfileHandle != null, E_INVALID_ACCOUNT,
490                         "Invalid network account. accountId=%d", netAccountInfo.GetAccountId());
491
492         r = ConnectivityUtility::UpdateProfileInfo(&netAccountInfo, pProfileHandle.get(), true);
493         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
494
495         ret = connection_update_profile(connectionHandle, pProfileHandle.get());
496         SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
497                         "A system error has been occurred. The return value from connection_update_profile() is %d",
498                         GetErrorMessage(E_SYSTEM), ret);
499
500         r = NetAccountDatabase::UpdateAccountName(netAccountInfo.GetAccountId(), netAccountInfo.GetAccountName());
501         SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
502         SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM,
503                         "A system error has been occurred. Failed to update accountName.");
504
505         return r;
506 }
507
508 result
509 NetService::GetNetAccountInfo(const String& packageId, NetAccountId netAccountId, NetAccountInfo* pNetAccountInfo) const
510 {
511         result r = E_SUCCESS;
512         connection_profile_h profileHandle = null;
513         unique_ptr<void, _ProfileDeleter> pProfileHandle;
514
515         SysTryReturnResult(NID_NET, netAccountId > 0, E_INVALID_ACCOUNT, "Invalid network account. accountId=%d.", netAccountId);
516         SysTryReturnResult(NID_NET, netAccountId != _DEFAULT_WIFI_DIRECT_ACCOUNT_ID, E_INVALID_ACCOUNT, "Wifi direct account information is not found.");
517         SysTryReturnResult(NID_NET, netAccountId != _DEFAULT_USB_ACCOUNT_ID, E_INVALID_ACCOUNT, "USB account information is not found.");
518
519         _NetAccountInfoImpl* pImpl = _NetAccountInfoImpl::GetInstance(*pNetAccountInfo);
520         if (pImpl == null)
521         {
522                 r = pNetAccountInfo->Construct();
523                 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
524
525                 pImpl = _NetAccountInfoImpl::GetInstance(*pNetAccountInfo);
526                 SysTryReturnResult(NID_NET, pImpl != null, E_SYSTEM, "Failed to construct NetAccountInfo.");
527         }
528
529         String profileName;
530
531         r = NetAccountDatabase::GetProfileName(netAccountId, profileName);
532         SysTryReturnResult(NID_NET, r == E_SUCCESS, E_INVALID_ACCOUNT, "Ps account is NOT found for accountId[%d].", netAccountId);
533
534         profileHandle = ConnectivityUtility::GetPsProfileHandleN(profileName);
535         SysTryReturnResult(NID_NET, profileHandle != null, E_INVALID_ACCOUNT, "Ps account is NOT found for accountId[%d].", netAccountId);
536         pProfileHandle.reset(profileHandle);
537
538         pImpl->SetReadOnly(NetAccountDatabase::IsReadOnly(packageId, netAccountId));
539
540         r = ConnectivityUtility::UpdateNetAccountInfo(pNetAccountInfo, profileHandle);
541
542         return r;
543 }
544
545 result
546 NetService::GetNetAccountIds(ArrayListT<NetAccountId>* pList)
547 {
548         UpdateNetAccountDb();
549
550         ClearLastResult();
551
552         return NetAccountDatabase::GetAccountIds(pList);
553 }
554
555 result
556 NetService::GetNetAccountNames(ArrayList* pList)
557 {
558         UpdateNetAccountDb();
559
560         ClearLastResult();
561
562         return NetAccountDatabase::GetAccountNames(pList);
563 }
564
565 NetAccountId
566 NetService::GetNetAccountId(const String& netAccountName)
567 {
568         ClearLastResult();
569
570         result r = E_SUCCESS;
571         NetAccountId accountId = INVALID_HANDLE;
572
573         r = NetAccountDatabase::GetAccountIdByAccountName(netAccountName, accountId);
574         SysTryReturn(NID_NET, r == E_SUCCESS, INVALID_HANDLE, E_INVALID_ARG,
575                         "[%s] Invalid argument is used. AccountName[%ls] is not found.",
576                         GetErrorMessage(E_INVALID_ARG), netAccountName.GetPointer());
577
578         SysSecureLog(NID_NET, "GetNetAccountId() has been succeeded with accountId:%d", accountId);
579
580         return accountId;
581 }
582
583 NetAccountId
584 NetService::GetNetAccountId(NetBearerType netBearerType)
585 {
586         ClearLastResult();
587
588         NetAccountId accountId = INVALID_HANDLE;
589
590         if (netBearerType == NET_BEARER_PS)
591         {
592                 accountId = GetInternetAccountId();
593         }
594         else if (netBearerType == NET_BEARER_MMS)
595         {
596                 accountId = GetMmsAccountId();
597         }
598         else if (netBearerType == NET_BEARER_WIFI)
599         {
600                 accountId = _DEFAULT_WIFI_ACCOUNT_ID;
601         }
602         else if (netBearerType == NET_BEARER_WIFI_DIRECT)
603         {
604                 accountId = _DEFAULT_WIFI_DIRECT_ACCOUNT_ID;
605         }
606         else if (netBearerType == NET_BEARER_USB)
607         {
608                 accountId = _DEFAULT_USB_ACCOUNT_ID;
609         }
610         else
611         {
612                 SysLogException(NID_NET, E_INVALID_ARG,
613                                 "[%s] Invalid argument is used. bearerType=%d", GetErrorMessage(E_INVALID_ARG), netBearerType);
614         }
615
616         return accountId;
617 }
618
619 IList*
620 NetService::GetAppProfileNamesN(void)
621 {
622         ClearLastResult();
623
624         result r = E_SUCCESS;
625         int ret = CONNECTION_ERROR_NONE;
626         connection_h connectionHandle = null;
627         connection_profile_iterator_h iterator = null;
628         connection_profile_h profileHandle = null;
629         connection_profile_type_e profileType = CONNECTION_PROFILE_TYPE_WIFI;
630
631         ret = connection_create(&connectionHandle);
632         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
633                         "[%s] A system error has been occurred. The return value from connection_create() is %d",
634                         GetErrorMessage(E_SYSTEM), ret);
635         unique_ptr<void, _ConnectionDeleter> pConnectionHandle(connectionHandle);
636
637         unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
638         SysTryReturn(NID_NET, pList != null, null, E_OUT_OF_MEMORY,
639                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
640
641         r = pList->Construct();
642         SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
643
644         ret = connection_get_profile_iterator(connectionHandle, CONNECTION_ITERATOR_TYPE_REGISTERED, &iterator);
645         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
646                         "[%s] A system error has been occurred. The return value from connection_get_profile_iterator() is %d",
647                         GetErrorMessage(E_SYSTEM), ret);
648         unique_ptr<void, _ProfileIteratorDeleter> pIterator(iterator);
649
650         ret = connection_profile_iterator_next(iterator, &profileHandle);
651         while ((ret == CONNECTION_ERROR_NONE) && (profileHandle != null))
652         {
653                 char* pProfileName = null;
654
655                 ret = connection_profile_get_type(profileHandle, &profileType);
656                 SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
657                                 "[%s] A system error has been occurred. The return value from connection_profile_get_type() is %d",
658                         GetErrorMessage(E_SYSTEM), ret);
659
660                 if (profileType == CONNECTION_PROFILE_TYPE_CELLULAR)
661                 {
662                         connection_cellular_service_type_e serviceType = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
663
664                         ret = connection_profile_get_cellular_service_type(profileHandle, &serviceType);
665                         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
666                                         "[%s] A system error has been occurred. The return value from connection_profile_get_cellular_service_type() is %d",
667                                         GetErrorMessage(E_SYSTEM), ret);
668
669                         if (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION)
670                         {
671                                 ret = connection_profile_get_id(profileHandle, &pProfileName);
672                                 SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
673                                                 "[%s] A system error has been occurred. The return value from connection_profile_get_id() is %d",
674                                                 GetErrorMessage(E_SYSTEM), ret);
675
676                                 unique_ptr<String> pProfileNameString(new (std::nothrow) String(pProfileName));
677                                 free(pProfileName);
678                                 SysTryReturn(NID_NET, pProfileNameString != null, null, E_OUT_OF_MEMORY,
679                                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
680
681                                 r = pList->Add(*pProfileNameString);
682                                 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
683                                 pProfileNameString.release();
684                         }
685 //                      else
686 //                      {
687 //                              SysLog(NID_NET, "Ignore non-app profile.");
688 //                      }
689                 }
690 //              else
691 //              {
692 //                      SysLog(NID_NET, "Ignore non-cellular profile.");
693 //              }
694
695                 profileHandle = null;
696                 ret = connection_profile_iterator_next(iterator, &profileHandle);
697         }
698
699         SysLog(NID_NET, "GetAppProfileNamesN() has been succeeded with profiles count:%d", pList->GetCount());
700
701         return pList.release();
702 }
703
704 IList*
705 NetService::GetAllProfileNamesN(void)
706 {
707         ClearLastResult();
708
709         result r = E_SUCCESS;
710         int ret = CONNECTION_ERROR_NONE;
711         connection_h connectionHandle = null;
712         connection_profile_iterator_h iterator = null;
713         connection_profile_h profileHandle = null;
714         connection_profile_type_e profileType = CONNECTION_PROFILE_TYPE_WIFI;
715
716         ret = connection_create(&connectionHandle);
717         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
718                         "[%s] A system error has been occurred. The return value from connection_create() is %d",
719                         GetErrorMessage(E_SYSTEM), ret);
720         unique_ptr<void, _ConnectionDeleter> pConnectionHandle(connectionHandle);
721
722         unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
723         SysTryReturn(NID_NET, pList != null, null, E_OUT_OF_MEMORY,
724                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
725
726         r = pList->Construct();
727         SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
728
729         ret = connection_get_profile_iterator(connectionHandle, CONNECTION_ITERATOR_TYPE_REGISTERED, &iterator);
730         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
731                         "[%s] A system error has been occurred. The return value from connection_get_profile_iterator() is %d",
732                         GetErrorMessage(E_SYSTEM), ret);
733         unique_ptr<void, _ProfileIteratorDeleter> pIterator(iterator);
734
735         ret = connection_profile_iterator_next(iterator, &profileHandle);
736         while ((ret == CONNECTION_ERROR_NONE) && (profileHandle != null))
737         {
738                 ret = connection_profile_get_type(profileHandle, &profileType);
739                 SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
740                                 "[%s] A system error has been occurred. The return value from connection_profile_get_type() is %d",
741                         GetErrorMessage(E_SYSTEM), ret);
742
743                 if (profileType == CONNECTION_PROFILE_TYPE_CELLULAR)
744                 {
745                         connection_cellular_service_type_e serviceType = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
746
747                         ret = connection_profile_get_cellular_service_type(profileHandle, &serviceType);
748                         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
749                                         "[%s] A system error has been occurred. The return value from connection_profile_get_cellular_service_type() is %d",
750                                         GetErrorMessage(E_SYSTEM), ret);
751
752                         if ((serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET)
753                                         || (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
754                                         || (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_MMS)
755                                         || (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS)
756                                         || (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION))
757                         {
758                                 char* pProfileName = null;
759                                 char* pProfileDisplayName = null;
760                                 String profileName;
761                                 String profileDisplayName;
762
763                                 ret = connection_profile_get_id(profileHandle, &pProfileName);
764                                 SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
765                                                 "[%s] A system error has been occurred. The return value from connection_profile_get_id() is %d",
766                                                 GetErrorMessage(E_SYSTEM), ret);
767                                 profileName = String(pProfileName);
768                                 free(pProfileName);
769
770                                 ret = connection_profile_get_name(profileHandle, &pProfileDisplayName);
771                                 SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
772                                                 "[%s] A system error has been occurred. The return value from connection_profile_get_name() is %d",
773                                                 GetErrorMessage(E_SYSTEM), ret);
774                                 profileDisplayName = String(pProfileDisplayName);
775                                 free(pProfileDisplayName);
776
777                                 unique_ptr<String> pNetProfileName(new (std::nothrow) String(profileName));
778
779                                 SysLog(NID_NET, "Cellular profile is found: [%d][%ls][%ls].", serviceType, profileDisplayName.GetPointer(), profileName.GetPointer());
780
781                                 r = pList->Add(*pNetProfileName);
782                                 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
783                                 pNetProfileName.release();
784                         }
785 //                      else
786 //                      {
787 //                              SysLog(NID_NET, "Ignore unknown profile.");
788 //                      }
789                 }
790 //              else
791 //              {
792 //                      SysLog(NID_NET, "Ignore non-cellular profile.");
793 //              }
794
795                 profileHandle = null;
796                 ret = connection_profile_iterator_next(iterator, &profileHandle);
797         }
798
799         SysLog(NID_NET, "GetAllProfileNamesN() has been succeeded with profiles count:%d", pList->GetCount());
800
801         return pList.release();
802 }
803
804 NetAccountId
805 NetService::GetInternetAccountId(void)
806 {
807         result r = E_SUCCESS;
808         NetAccountId accountId = INVALID_HANDLE;
809
810         int ret = CONNECTION_ERROR_NONE;
811         connection_h connectionHandle = null;
812         connection_profile_h profileHandle = null;
813
814         ret = connection_create(&connectionHandle);
815         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
816                         "[%s] A system error has been occurred. The return value from connection_create() is %d",
817                         GetErrorMessage(E_SYSTEM), ret);
818         unique_ptr<void, _ConnectionDeleter> pConnectionHandle(connectionHandle);
819
820         ret = connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, &profileHandle);
821         if ((ret != CONNECTION_ERROR_NONE) || (profileHandle == null))
822         {
823                 SysLog(NID_NET, "Internet profile is not found, so search a prepaid-Internet profile.");
824
825                 ret = connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET, &profileHandle);
826         }
827         SysTryReturn(NID_NET, profileHandle != null, INVALID_HANDLE, E_INVALID_ACCOUNT,
828                         "[%s] Internet(incl. prepaid) profile is not found.", GetErrorMessage(E_INVALID_ACCOUNT));
829         unique_ptr<void, _ProfileDeleter> pProfileHandle(profileHandle);
830
831         char* pProfileName = null;
832         char* pProfileDisplayName = null;
833         String profileName;
834         String profileDisplayName;
835
836         ret = connection_profile_get_id(profileHandle, &pProfileName);
837         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
838                         "[%s] A system error has been occurred. The return value from connection_profile_get_id() is %d",
839                         GetErrorMessage(E_SYSTEM), ret);
840
841         profileName = String(pProfileName);
842         free(pProfileName);
843
844         ret = connection_profile_get_name(profileHandle, &pProfileDisplayName);
845         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
846                         "[%s] A system error has been occurred. The return value from connection_profile_get_name() is %d",
847                         GetErrorMessage(E_SYSTEM), ret);
848
849         profileDisplayName = String(pProfileDisplayName);
850         free(pProfileDisplayName);
851
852         SysLog(NID_NET, "Internet profile is found. [%ls][%ls]", profileDisplayName.GetPointer(), profileName.GetPointer());
853
854         if (!__internetProfileName.IsEmpty())
855         {
856                 if (!profileName.Equals(__internetProfileName, false))
857                 {
858                         // Internet profile is changed.
859                         SysLog(NID_NET, "Internet profile is changed. [%ls]->[%ls]", __internetProfileName.GetPointer(), profileName.GetPointer());
860
861                         UpdateNetAccountDb();
862                         r = NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
863
864                         __internetProfileName = profileName;
865                         __internetAccountId = accountId;
866                 }
867                 else
868                 {
869                         accountId = __internetAccountId;
870                 }
871         }
872         else
873         {
874                 SysLog(NID_NET, "Initialize Internet profile.");
875
876                 UpdateNetAccountDb();
877                 r = NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
878
879                 __internetProfileName = profileName;
880                 __internetAccountId = accountId;
881         }
882
883         ClearLastResult();
884
885         return accountId;
886 }
887
888 NetAccountId
889 NetService::GetMmsAccountId(void)
890 {
891         result r = E_SUCCESS;
892         NetAccountId accountId = INVALID_HANDLE;
893
894         int ret = CONNECTION_ERROR_NONE;
895         connection_h connectionHandle = null;
896         connection_profile_h profileHandle = null;
897
898         ret = connection_create(&connectionHandle);
899         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
900                         "[%s] A system error has been occurred. The return value from connection_create() is %d",
901                         GetErrorMessage(E_SYSTEM), ret);
902         unique_ptr<void, _ConnectionDeleter> pConnectionHandle(connectionHandle);
903
904         ret = connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profileHandle);
905         if ((ret != CONNECTION_ERROR_NONE) || (profileHandle == null))
906         {
907                 SysLog(NID_NET, "MMS profile is not found, so search a prepaid-MMS profile.");
908
909                 ret = connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS, &profileHandle);
910         }
911         SysTryReturn(NID_NET, profileHandle != null, INVALID_HANDLE, E_INVALID_ACCOUNT,
912                         "[%s] MMS(incl. prepaid) profile is not found.", GetErrorMessage(E_INVALID_ACCOUNT));
913         unique_ptr<void, _ProfileDeleter> pProfileHandle(profileHandle);
914
915         char* pProfileName = null;
916         char* pProfileDisplayName = null;
917         String profileName;
918         String profileDisplayName;
919
920         ret = connection_profile_get_id(profileHandle, &pProfileName);
921         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
922                         "[%s] A system error has been occurred. The return value from connection_profile_get_id() is %d",
923                         GetErrorMessage(E_SYSTEM), ret);
924
925         profileName = String(pProfileName);
926         free(pProfileName);
927
928         ret = connection_profile_get_name(profileHandle, &pProfileDisplayName);
929         SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
930                         "[%s] A system error has been occurred. The return value from connection_profile_get_name() is %d",
931                         GetErrorMessage(E_SYSTEM), ret);
932
933         profileDisplayName = String(pProfileDisplayName);
934         free(pProfileDisplayName);
935
936         SysLog(NID_NET, "MMS profile is found. [%ls][%ls]", profileDisplayName.GetPointer(), profileName.GetPointer());
937
938         if (!__mmsProfileName.IsEmpty())
939         {
940                 if (!profileName.Equals(__mmsProfileName, false))
941                 {
942                         // MMS profile is changed.
943                         SysLog(NID_NET, "MMS profile is changed. [%ls]->[%ls]", __mmsProfileName.GetPointer(), profileName.GetPointer());
944
945                         UpdateNetAccountDb();
946                         r = NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
947
948                         __mmsProfileName = profileName;
949                         __mmsAccountId = accountId;
950                 }
951                 else
952                 {
953                         accountId = __mmsAccountId;
954                 }
955         }
956         else
957         {
958                 SysLog(NID_NET, "Initialize MMS profile.");
959
960                 UpdateNetAccountDb();
961                 r = NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
962
963                 __mmsProfileName = profileName;
964                 __mmsAccountId = accountId;
965         }
966
967         ClearLastResult();
968
969         return accountId;
970 }
971
972 void
973 NetService::UpdateNetAccountDb(void)
974 {
975         result r = E_SUCCESS;
976         NetAccountId accountId = INVALID_HANDLE;
977         unique_ptr<IList, AllElementsDeleter> pAccountList(NetAccountDatabase::GetProfileNamesN());
978         unique_ptr<IList, AllElementsDeleter> pProfileList(NetService::GetAllProfileNamesN());
979
980         if (pProfileList != null)
981         {
982                 if (pProfileList->GetCount() > 0)
983                 {
984                         SysLog(NID_NET, "[%d] profiles are found.", pProfileList->GetCount());
985
986                         unique_ptr<IEnumerator> pEnum(pProfileList->GetEnumeratorN());
987                         if (pEnum != null)
988                         {
989                                 String* pProfileName = null;
990                                 while (pEnum->MoveNext() == E_SUCCESS)
991                                 {
992                                         pProfileName = dynamic_cast<String*>(pEnum->GetCurrent());
993                                         if (pProfileName != null)
994                                         {
995                                                 if (pAccountList->Contains(*pProfileName))
996                                                 {
997                                                         SysLog(NID_NET, "ProfileName[%ls] is already on DB.", pProfileName->GetPointer());
998                                                         pAccountList->Remove(*pProfileName, true);
999                                                 }
1000                                                 else
1001                                                 {
1002                                                         SysLog(NID_NET, "ProfileName[%ls] is not found on DB, so add it.", pProfileName->GetPointer());
1003                                                         r = NetAccountDatabase::AddAccount(*pProfileName, *pProfileName, String(SYSTEM_PACKAGE_NAME), accountId);
1004                                                 }
1005                                         }
1006                                 }
1007                         }
1008                 }
1009         }
1010
1011         if (pAccountList != null)
1012         {
1013                 if (pAccountList->GetCount() > 0)
1014                 {
1015                         SysLog(NID_NET, "[%d] zombie accounts are on DB.", pAccountList->GetCount());
1016
1017                         unique_ptr<IEnumerator> pEnum(pAccountList->GetEnumeratorN());
1018                         if (pEnum != null)
1019                         {
1020                                 String* pProfileName = null;
1021                                 while (pEnum->MoveNext() == E_SUCCESS)
1022                                 {
1023                                         pProfileName = dynamic_cast<String*>(pEnum->GetCurrent());
1024                                         if (pProfileName != null)
1025                                         {
1026                                                 r = NetAccountDatabase::RemoveAccountByProfileName(*pProfileName);
1027                                         }
1028                                 }
1029                         }
1030                 }
1031         }
1032
1033         ClearLastResult();
1034
1035         SysLog(NID_NET, "Network account database is updated.");
1036 }