isReadOnly = true;
}
- if (owner == _NET_ACCOUNT_OWNER_SYSTEM_INTERNET)
+ pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_MAX_ACCOUNT_ID_STATEMENT)));
+ r = GetLastResult();
+ SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
+
+ pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
+ if (pEnum != null)
{
- netAccountId = _DEFAULT_PS_ACCOUNT_ID;
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ pEnum->GetIntAt(0, netAccountId);
+ break;
+ }
}
- else if (owner == _NET_ACCOUNT_OWNER_SYSTEM_MMS)
+
+ if (netAccountId >= _PS_ACCOUNT_ID_START)
{
- netAccountId = _DEFAULT_MMS_ACCOUNT_ID;
+ netAccountId++;
}
else
{
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_MAX_ACCOUNT_ID_STATEMENT)));
- r = GetLastResult();
- SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- if (pEnum != null)
- {
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetIntAt(0, netAccountId);
- break;
- }
- }
-
- SysTryReturnResult(NID_NET, netAccountId >= 0, E_SYSTEM,
- "[%s] A system error has been occurred. Failed to allocate a new accountId.", GetErrorMessage(E_SYSTEM));
-
- if (netAccountId >= _CUSTOM_ACCOUNT_ID_START)
- {
- netAccountId++;
- }
- else
- {
- netAccountId = _CUSTOM_ACCOUNT_ID_START;
- }
+ netAccountId = _PS_ACCOUNT_ID_START;
}
pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_ADD_ACCOUNT_STATEMENT)));
return pList.release();
}
-IList*
-_NetAccountDatabase::GetAppProfileNamesN(void)
-{
- static const wchar_t _NET_ACCOUNT_DATABASE_GET_PROFILE_NAMES_STATEMENT[] =
- L"SELECT profileName FROM NetAccountTable WHERE accountId>=?";
-
- result r = E_SUCCESS;
- Database accountDb;
- unique_ptr<DbStatement> pStmt;
- unique_ptr<DbEnumerator> pEnum;
- unique_ptr<ArrayList, _CollectionDeleter> pList;
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_PROFILE_NAMES_STATEMENT)));
- r = GetLastResult();
- SysTryReturn(NID_NET, pStmt != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- r = pStmt->BindInt(0, _CUSTOM_ACCOUNT_ID_START);
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pList.reset(new (std::nothrow) ArrayList());
- r = GetLastResult();
- SysTryReturn(NID_NET, pList != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- r = pList->Construct();
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- r = GetLastResult();
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- if (pEnum != null)
- {
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- unique_ptr<String> pProfileName(new (std::nothrow) String());
- SysTryReturn(NID_NET, pProfileName != null, null, E_OUT_OF_MEMORY,
- "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
- r = pEnum->GetStringAt(0, *pProfileName);
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- r = pList->Add(*pProfileName);
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pProfileName.release();
- }
- }
-
- ClearLastResult(); // To suppress E_OUT_OF_RANGE
-
- return pList.release();
-}
-
result
_NetAccountDatabase::GetAccountName(NetAccountId accountId, String& accountName)
{
_NetAccountDatabase::GetDbPath(void)
{
static const wchar_t _OLD_DATA_PATH[] = L"/Home/";
- static const wchar_t _NET_ACCOUNT_DATABASE_FILE_NAME[] = L"netAccount.db";
+ static const wchar_t _NET_ACCOUNT_DATABASE_FILE_NAME[] = L".tizen_netaccount.db";
String dbPath;
_ApiVersion apiVersion = _AppInfo::GetApiVersion();
#include <FNetNetAccountManager.h>
#include <FNetWifiWifiNetAccountInfo.h>
#include <FBaseSysLog.h>
+#include <FBaseRtMutexGuard.h>
#include <FBase_StringConverter.h>
#include "FNet_NetTypes.h"
#include "FNet_NetAccountInfoImpl.h"
#include "FNet_NetConnectionManagerImpl.h"
#include "FNet_SystemNetConnection.h"
#include "FNet_NetAccountDatabase.h"
+#include "FNet_NetUtility.h"
#include "FNetWifi_WifiNetAccountInfoImpl.h"
using namespace std;
using namespace Tizen::Base;
using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Runtime;
using namespace Tizen::Net::Wifi;
namespace Tizen { namespace Net {
static const char _WIFI_LIBRARY_NAME[] = "libosp-wifi.so";
-_NetProfileInfo::_NetProfileInfo(void)
-{
-}
-
-_NetProfileInfo::_NetProfileInfo(const String& profileName, const String& profileDisplayName)
- : __profileName(profileName)
- , __profileDisplayName(profileDisplayName)
-{
-}
-
-_NetProfileInfo::~_NetProfileInfo(void)
-{
-}
-
-String
-_NetProfileInfo::GetProfileName(void) const
-{
- return __profileName;
-}
-
-String
-_NetProfileInfo::GetProfileDisplayName(void) const
-{
- return __profileDisplayName;
-}
+bool _NetAccountManagerImpl::__isNetAccountDbInitialized = false;
+NetAccountId _NetAccountManagerImpl::__internetAccountId = INVALID_HANDLE;
+NetAccountId _NetAccountManagerImpl::__mmsAccountId = INVALID_HANDLE;
+String* _NetAccountManagerImpl::__pInternetProfileName = null;
+String* _NetAccountManagerImpl::__pMmsProfileName = null;
_NetAccountManagerImpl::_NetAccountManagerImpl(void)
: __pConnectionHandle(null)
"Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
_SystemNetConnection::InitializeNetworkFramework();
+ _NetAccountManagerImpl::UpdateNetAccountDb();
ret = connection_create(&connectionHandle);
SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
IListT<NetAccountId>*
_NetAccountManagerImpl::GetNetAccountIdsN(void) const
{
- ClearLastResult();
-
SysAssertf(__pConnectionHandle != null, "Not yet constructed. Construct() should be called before use.");
+ _NetAccountManagerImpl::UpdateNetAccountDb(true);
+
+ ClearLastResult();
+
return _NetAccountDatabase::GetAccountIdsN();
}
IList*
_NetAccountManagerImpl::GetNetAccountNamesN(void) const
{
- ClearLastResult();
-
SysAssertf(__pConnectionHandle != null, "Not yet constructed. Construct() should be called before use.");
+ _NetAccountManagerImpl::UpdateNetAccountDb(true);
+
+ ClearLastResult();
+
return _NetAccountDatabase::GetAccountNamesN();
}
if (netBearerType == NET_BEARER_PS)
{
- accountId = _DEFAULT_PS_ACCOUNT_ID;
+ accountId = _NetAccountManagerImpl::GetInternetAccountId();
}
else if (netBearerType == NET_BEARER_MMS)
{
- accountId = _DEFAULT_MMS_ACCOUNT_ID;
+ accountId = _NetAccountManagerImpl::GetMmsAccountId();
}
else if (netBearerType == NET_BEARER_WIFI)
{
return matchingProfileHandle;
}
-_NetProfileInfo
-_NetAccountManagerImpl::GetInternetProfileInfo(void)
-{
- ClearLastResult();
-
- _NetProfileInfo profileInfo;
- int ret = CONNECTION_ERROR_NONE;
- connection_h connectionHandle = null;
- connection_profile_h profileHandle = null;
-
- ret = connection_create(&connectionHandle);
- SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, profileInfo, E_SYSTEM,
- "[%s] A system error has been occurred. The return value from connection_create() is %d",
- GetErrorMessage(E_SYSTEM), ret);
- unique_ptr<void, _ConnectionDeleter> pConnectionHandle(connectionHandle);
-
- ret = connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, &profileHandle);
- if ((ret != CONNECTION_ERROR_NONE) || (profileHandle == null))
- {
- SysLog(NID_NET, "Internet profile is not found, so search a prepaid-Internet profile.");
-
- ret = connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET, &profileHandle);
- }
- SysTryReturn(NID_NET, profileHandle != null, profileInfo, E_INVALID_ACCOUNT,
- "[%s] Internet(incl. prepaid) profile is not found.", GetErrorMessage(E_INVALID_ACCOUNT));
- unique_ptr<void, _ProfileDeleter> pProfileHandle(profileHandle);
-
- char* pProfileName = null;
- char* pProfileDisplayName = null;
- String profileName;
- String profileDisplayName;
-
- ret = connection_profile_get_id(profileHandle, &pProfileName);
- SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, profileInfo, E_SYSTEM,
- "[%s] A system error has been occurred. The return value from connection_profile_get_id() is %d",
- GetErrorMessage(E_SYSTEM), ret);
-
- profileName = String(pProfileName);
- free(pProfileName);
-
- ret = connection_profile_get_name(profileHandle, &pProfileDisplayName);
- SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, profileInfo, E_SYSTEM,
- "[%s] A system error has been occurred. The return value from connection_profile_get_name() is %d",
- GetErrorMessage(E_SYSTEM), ret);
-
- profileDisplayName = String(pProfileDisplayName);
- free(pProfileDisplayName);
-
- profileInfo = _NetProfileInfo(profileName, profileDisplayName);
-
- SysLog(NID_NET, "GetInternetProfileInfo() has been succeeded with profile[%ls][%ls]", profileInfo.GetProfileDisplayName().GetPointer(), profileInfo.GetProfileName().GetPointer());
-
- return profileInfo;
-}
-
-_NetProfileInfo
-_NetAccountManagerImpl::GetMmsProfileInfo(void)
-{
- ClearLastResult();
-
- _NetProfileInfo profileInfo;
- int ret = CONNECTION_ERROR_NONE;
- connection_h connectionHandle = null;
- connection_profile_h profileHandle = null;
-
- ret = connection_create(&connectionHandle);
- SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, profileInfo, E_SYSTEM,
- "[%s] A system error has been occurred. The return value from connection_create() is %d",
- GetErrorMessage(E_SYSTEM), ret);
- unique_ptr<void, _ConnectionDeleter> pConnectionHandle(connectionHandle);
-
- ret = connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profileHandle);
- if ((ret != CONNECTION_ERROR_NONE) || (profileHandle == null))
- {
- SysLog(NID_NET, "MMS profile is not found, so search a prepaid-MMS profile.");
-
- ret = connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS, &profileHandle);
- }
- SysTryReturn(NID_NET, profileHandle != null, profileInfo, E_INVALID_ACCOUNT,
- "[%s] MMS(incl. prepaid) profile is not found.", GetErrorMessage(E_INVALID_ACCOUNT));
- unique_ptr<void, _ProfileDeleter> pProfileHandle(profileHandle);
-
- char* pProfileName = null;
- char* pProfileDisplayName = null;
- String profileName;
- String profileDisplayName;
-
- ret = connection_profile_get_id(profileHandle, &pProfileName);
- SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, profileInfo, E_SYSTEM,
- "[%s] A system error has been occurred. The return value from connection_profile_get_id() is %d",
- GetErrorMessage(E_SYSTEM), ret);
-
- profileName = String(pProfileName);
- free(pProfileName);
-
- ret = connection_profile_get_name(profileHandle, &pProfileDisplayName);
- SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, profileInfo, E_SYSTEM,
- "[%s] A system error has been occurred. The return value from connection_profile_get_name() is %d",
- GetErrorMessage(E_SYSTEM), ret);
-
- profileDisplayName = String(pProfileDisplayName);
- free(pProfileDisplayName);
-
- profileInfo = _NetProfileInfo(profileName, profileDisplayName);
-
- SysLog(NID_NET, "GetMmsProfileInfo() has been succeeded with profile[%ls][%ls]", profileInfo.GetProfileDisplayName().GetPointer(), profileInfo.GetProfileName().GetPointer());
-
- return profileInfo;
-}
-
IList*
_NetAccountManagerImpl::GetAppProfileNamesN(void)
{
}
IList*
-_NetAccountManagerImpl::GetAllProfileInfosN(void)
+_NetAccountManagerImpl::GetAllProfileNamesN(void)
{
ClearLastResult();
profileDisplayName = String(pProfileDisplayName);
free(pProfileDisplayName);
- unique_ptr<_NetProfileInfo> pProfileInfo(new (std::nothrow) _NetProfileInfo(profileName, profileDisplayName));
+ unique_ptr<String> pNetProfileName(new (std::nothrow) String(profileName));
SysLog(NID_NET, "Cellular profile is found: [%d][%ls][%ls].", serviceType, profileDisplayName.GetPointer(), profileName.GetPointer());
- r = pList->Add(*pProfileInfo);
+ r = pList->Add(*pNetProfileName);
SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
- pProfileInfo.release();
+ pNetProfileName.release();
}
else
{
- SysLog(NID_NET, "Ignore non-app profile.");
+ SysLog(NID_NET, "Ignore unknown profile.");
}
}
else
ret = connection_profile_iterator_next(iterator, &profileHandle);
}
- SysLog(NID_NET, "GetAllProfileInfosN() has been succeeded with profiles count:%d", pList->GetCount());
+ SysLog(NID_NET, "GetAllProfileNamesN() has been succeeded with profiles count:%d", pList->GetCount());
return pList.release();
}
return null;
}
+NetAccountId
+_NetAccountManagerImpl::GetInternetAccountId(void)
+{
+ result r = E_SUCCESS;
+ NetAccountId accountId = INVALID_HANDLE;
+
+ int ret = CONNECTION_ERROR_NONE;
+ connection_h connectionHandle = null;
+ connection_profile_h profileHandle = null;
+
+ _NetAccountManagerImpl::UpdateNetAccountDb();
+
+ ret = connection_create(&connectionHandle);
+ SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
+ "[%s] A system error has been occurred. The return value from connection_create() is %d",
+ GetErrorMessage(E_SYSTEM), ret);
+ unique_ptr<void, _ConnectionDeleter> pConnectionHandle(connectionHandle);
+
+ ret = connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, &profileHandle);
+ if ((ret != CONNECTION_ERROR_NONE) || (profileHandle == null))
+ {
+ SysLog(NID_NET, "Internet profile is not found, so search a prepaid-Internet profile.");
+
+ ret = connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET, &profileHandle);
+ }
+ SysTryReturn(NID_NET, profileHandle != null, INVALID_HANDLE, E_INVALID_ACCOUNT,
+ "[%s] Internet(incl. prepaid) profile is not found.", GetErrorMessage(E_INVALID_ACCOUNT));
+ unique_ptr<void, _ProfileDeleter> pProfileHandle(profileHandle);
+
+ char* pProfileName = null;
+ char* pProfileDisplayName = null;
+ String profileName;
+ String profileDisplayName;
+
+ ret = connection_profile_get_id(profileHandle, &pProfileName);
+ SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
+ "[%s] A system error has been occurred. The return value from connection_profile_get_id() is %d",
+ GetErrorMessage(E_SYSTEM), ret);
+
+ profileName = String(pProfileName);
+ free(pProfileName);
+
+ ret = connection_profile_get_name(profileHandle, &pProfileDisplayName);
+ SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
+ "[%s] A system error has been occurred. The return value from connection_profile_get_name() is %d",
+ GetErrorMessage(E_SYSTEM), ret);
+
+ profileDisplayName = String(pProfileDisplayName);
+ free(pProfileDisplayName);
+
+ SysLog(NID_NET, "Internet profile is found. [%ls][%ls]", profileDisplayName.GetPointer(), profileName.GetPointer());
+
+ Mutex* pLock = _NetUtility::GetLock();
+ MutexGuard locked(*pLock);
+
+ if (__pInternetProfileName != null)
+ {
+ if (!profileName.Equals(*__pInternetProfileName, false))
+ {
+ // Internet profile is changed.
+ SysLog(NID_NET, "Internet profile is changed. [%ls]->[%ls]", __pInternetProfileName->GetPointer(), profileName.GetPointer());
+
+ _NetAccountManagerImpl::UpdateNetAccountDb(true);
+ r = _NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
+
+ delete __pInternetProfileName;
+ __pInternetProfileName = new (std::nothrow) String(profileName);
+ __internetAccountId = accountId;
+ }
+ else
+ {
+ accountId = __internetAccountId;
+ }
+ }
+ else
+ {
+ SysLog(NID_NET, "Initialize Internet profile.");
+
+ _NetAccountManagerImpl::UpdateNetAccountDb(true);
+ r = _NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
+
+ __pInternetProfileName = new (std::nothrow) String(profileName);
+ __internetAccountId = accountId;
+ }
+
+ locked.Unlock();
+
+ ClearLastResult();
+
+ return accountId;
+}
+
+NetAccountId
+_NetAccountManagerImpl::GetMmsAccountId(void)
+{
+ result r = E_SUCCESS;
+ NetAccountId accountId = INVALID_HANDLE;
+
+ int ret = CONNECTION_ERROR_NONE;
+ connection_h connectionHandle = null;
+ connection_profile_h profileHandle = null;
+
+ _NetAccountManagerImpl::UpdateNetAccountDb();
+
+ ret = connection_create(&connectionHandle);
+ SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
+ "[%s] A system error has been occurred. The return value from connection_create() is %d",
+ GetErrorMessage(E_SYSTEM), ret);
+ unique_ptr<void, _ConnectionDeleter> pConnectionHandle(connectionHandle);
+
+ ret = connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profileHandle);
+ if ((ret != CONNECTION_ERROR_NONE) || (profileHandle == null))
+ {
+ SysLog(NID_NET, "MMS profile is not found, so search a prepaid-MMS profile.");
+
+ ret = connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS, &profileHandle);
+ }
+ SysTryReturn(NID_NET, profileHandle != null, INVALID_HANDLE, E_INVALID_ACCOUNT,
+ "[%s] MMS(incl. prepaid) profile is not found.", GetErrorMessage(E_INVALID_ACCOUNT));
+ unique_ptr<void, _ProfileDeleter> pProfileHandle(profileHandle);
+
+ char* pProfileName = null;
+ char* pProfileDisplayName = null;
+ String profileName;
+ String profileDisplayName;
+
+ ret = connection_profile_get_id(profileHandle, &pProfileName);
+ SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
+ "[%s] A system error has been occurred. The return value from connection_profile_get_id() is %d",
+ GetErrorMessage(E_SYSTEM), ret);
+
+ profileName = String(pProfileName);
+ free(pProfileName);
+
+ ret = connection_profile_get_name(profileHandle, &pProfileDisplayName);
+ SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
+ "[%s] A system error has been occurred. The return value from connection_profile_get_name() is %d",
+ GetErrorMessage(E_SYSTEM), ret);
+
+ profileDisplayName = String(pProfileDisplayName);
+ free(pProfileDisplayName);
+
+ SysLog(NID_NET, "MMS profile is found. [%ls][%ls]", profileDisplayName.GetPointer(), profileName.GetPointer());
+
+ Mutex* pLock = _NetUtility::GetLock();
+ MutexGuard locked(*pLock);
+
+ if (__pMmsProfileName != null)
+ {
+ if (!profileName.Equals(*__pMmsProfileName, false))
+ {
+ // MMS profile is changed.
+ SysLog(NID_NET, "MMS profile is changed. [%ls]->[%ls]", __pMmsProfileName->GetPointer(), profileName.GetPointer());
+
+ _NetAccountManagerImpl::UpdateNetAccountDb(true);
+ r = _NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
+
+ delete __pMmsProfileName;
+ __pMmsProfileName = new (std::nothrow) String(profileName);
+ __mmsAccountId = accountId;
+ }
+ else
+ {
+ accountId = __mmsAccountId;
+ }
+ }
+ else
+ {
+ SysLog(NID_NET, "Initialize MMS profile.");
+
+ _NetAccountManagerImpl::UpdateNetAccountDb(true);
+ r = _NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
+
+ __pMmsProfileName = new (std::nothrow) String(profileName);
+ __mmsAccountId = accountId;
+ }
+
+ locked.Unlock();
+
+ ClearLastResult();
+
+ return accountId;
+}
+
+void
+_NetAccountManagerImpl::UpdateNetAccountDb(bool force)
+{
+ if (__isNetAccountDbInitialized && !force)
+ {
+ // Already done
+ return;
+ }
+
+ Mutex* pLock = _NetUtility::GetLock();
+ MutexGuard locked(*pLock);
+
+ result r = E_SUCCESS;
+ NetAccountId accountId = INVALID_HANDLE;
+ unique_ptr<IList, _CollectionDeleter> pAccountList(_NetAccountDatabase::GetProfileNamesN());
+ unique_ptr<IList, _CollectionDeleter> pProfileList(_NetAccountManagerImpl::GetAllProfileNamesN());
+
+ if (pProfileList != null)
+ {
+ if (pProfileList->GetCount() > 0)
+ {
+ SysLog(NID_NET, "[%d] profiles are found.", pProfileList->GetCount());
+
+ unique_ptr<IEnumerator> pEnum(pProfileList->GetEnumeratorN());
+ if (pEnum != null)
+ {
+ String* pProfileName = null;
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ pProfileName = dynamic_cast<String*>(pEnum->GetCurrent());
+ if (pProfileName != null)
+ {
+ if (pAccountList->Contains(*pProfileName))
+ {
+ SysLog(NID_NET, "ProfileName[%ls] is already on DB.", pProfileName->GetPointer());
+ pAccountList->Remove(*pProfileName, true);
+ }
+ else
+ {
+ SysLog(NID_NET, "ProfileName[%ls] is not found on DB, so add it.", pProfileName->GetPointer());
+ r = _NetAccountDatabase::AddAccount(*pProfileName, *pProfileName, _NET_ACCOUNT_OWNER_OTHER, accountId);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (pAccountList != null)
+ {
+ if (pAccountList->GetCount() > 0)
+ {
+ SysLog(NID_NET, "[%d] zombie accounts are on DB.", pAccountList->GetCount());
+
+ unique_ptr<IEnumerator> pEnum(pAccountList->GetEnumeratorN());
+ if (pEnum != null)
+ {
+ String* pProfileName = null;
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ pProfileName = dynamic_cast<String*>(pEnum->GetCurrent());
+ if (pProfileName != null)
+ {
+ r = _NetAccountDatabase::RemoveAccountByProfileName(*pProfileName);
+ }
+ }
+ }
+ }
+ }
+
+ __isNetAccountDbInitialized = true;
+
+ ClearLastResult();
+
+ locked.Unlock();
+
+ SysLog(NID_NET, "Network account database is updated.");
+}
+
} } // Tizen::Net
_SystemNetConnection::InitializeNetworkFrameworkOnce(void)
{
result r = E_SUCCESS;
- NetAccountId accountId = INVALID_HANDLE;
- String accountName;
__pPsSystemConnectionMap = new (std::nothrow) HashMap();
SysTryReturnVoidResult(NID_NET, __pPsSystemConnectionMap != null, E_OUT_OF_MEMORY,
SysTryReturnVoidResult(NID_NET, r == E_SUCCESS, r,
"[%s] A system error has been occurred. Failed to initialize the network database.", GetErrorMessage(r));
- _NetProfileInfo internetProfileInfo = _NetAccountManagerImpl::GetInternetProfileInfo();
- _NetProfileInfo mmsProfileInfo = _NetAccountManagerImpl::GetMmsProfileInfo();
- String profileName;
-
- r = _NetAccountDatabase::GetProfileName(_DEFAULT_PS_ACCOUNT_ID, profileName);
- if (internetProfileInfo.GetProfileName().IsEmpty())
- {
- SysLog(NID_NET, "Internet profile is not found.");
-
- if (!profileName.IsEmpty())
- {
- SysLog(NID_NET, "Remove Internet profile from database.");
- r = _NetAccountDatabase::RemoveAccountByAccountId(_DEFAULT_PS_ACCOUNT_ID);
- }
- }
- else
- {
- if (internetProfileInfo.GetProfileName() != profileName)
- {
- SysLog(NID_NET, "Internet profile is changed. [%ls] -> [%ls]", profileName.GetPointer(), internetProfileInfo.GetProfileName().GetPointer());
-
- if (!profileName.IsEmpty())
- {
- r = _NetAccountDatabase::RemoveAccountByAccountId(_DEFAULT_PS_ACCOUNT_ID);
- }
-
- r = _NetAccountDatabase::RemoveAccountByProfileName(internetProfileInfo.GetProfileName());
-
- accountName.Clear();
- accountName.Append(internetProfileInfo.GetProfileDisplayName());
- accountName.Append(internetProfileInfo.GetProfileName());
-
- r = _NetAccountDatabase::AddAccount(accountName, internetProfileInfo.GetProfileName(), _NET_ACCOUNT_OWNER_SYSTEM_INTERNET, accountId);
- }
- }
-
- profileName.Clear();
-
- r = _NetAccountDatabase::GetProfileName(_DEFAULT_MMS_ACCOUNT_ID, profileName);
- if (mmsProfileInfo.GetProfileName().IsEmpty())
- {
- SysLog(NID_NET, "MMS profile is not found.");
-
- if (!profileName.IsEmpty())
- {
- SysLog(NID_NET, "Remove MMS profile from database.");
- r = _NetAccountDatabase::RemoveAccountByAccountId(_DEFAULT_MMS_ACCOUNT_ID);
- }
- }
- else
- {
- if (mmsProfileInfo.GetProfileName() != profileName)
- {
- SysLog(NID_NET, "MMS profile is changed. [%ls] -> [%ls]", profileName.GetPointer(), mmsProfileInfo.GetProfileName().GetPointer());
-
- if (!profileName.IsEmpty())
- {
- r = _NetAccountDatabase::RemoveAccountByAccountId(_DEFAULT_MMS_ACCOUNT_ID);
- }
-
- r = _NetAccountDatabase::RemoveAccountByProfileName(mmsProfileInfo.GetProfileName());
-
- accountName.Clear();
- accountName.Append(mmsProfileInfo.GetProfileDisplayName());
- accountName.Append(mmsProfileInfo.GetProfileName());
-
- r = _NetAccountDatabase::AddAccount(accountName, mmsProfileInfo.GetProfileName(), _NET_ACCOUNT_OWNER_SYSTEM_MMS, accountId);
- }
- }
-
- unique_ptr<IList, _CollectionDeleter> pAccountList(_NetAccountDatabase::GetProfileNamesN());
- unique_ptr<IList, _CollectionDeleter> pProfileList(_NetAccountManagerImpl::GetAllProfileInfosN());
-
- if (pProfileList != null)
- {
- if (pProfileList->GetCount() > 0)
- {
- SysLog(NID_NET, "[%d] profiles are found.", pProfileList->GetCount());
-
- unique_ptr<IEnumerator> pEnum(pProfileList->GetEnumeratorN());
- if (pEnum != null)
- {
- _NetProfileInfo* pProfileInfo = null;
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pProfileInfo = dynamic_cast<_NetProfileInfo*>(pEnum->GetCurrent());
- if (pProfileInfo != null)
- {
- if (pAccountList->Contains(pProfileInfo->GetProfileName()))
- {
- SysLog(NID_NET, "ProfileName[%ls] is already on DB.", pProfileInfo->GetProfileName().GetPointer());
- pAccountList->Remove(pProfileInfo->GetProfileName(), true);
- }
- else
- {
- // OSP or Non-default account
- accountName.Clear();
- accountName.Append(pProfileInfo->GetProfileDisplayName());
- accountName.Append(pProfileInfo->GetProfileName());
-
- SysLog(NID_NET, "ProfileName[%ls] is not found on DB, so add it.", pProfileInfo->GetProfileName().GetPointer());
- r = _NetAccountDatabase::AddAccount(accountName, pProfileInfo->GetProfileName(), _NET_ACCOUNT_OWNER_OTHER, accountId);
- }
- }
- }
- }
- }
- }
-
- if (pAccountList != null)
- {
- if (pAccountList->GetCount() > 0)
- {
- SysLog(NID_NET, "[%d] zombie accounts are on DB.", pAccountList->GetCount());
-
- unique_ptr<IEnumerator> pEnum(pAccountList->GetEnumeratorN());
- if (pEnum != null)
- {
- String* pProfileName = null;
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pProfileName = dynamic_cast<String*>(pEnum->GetCurrent());
- if (pProfileName != null)
- {
- r = _NetAccountDatabase::RemoveAccountByProfileName(*pProfileName);
- }
- }
- }
- }
- }
-
-#ifdef _OSP_EMUL_
- static const wchar_t _DEFAULT_PS_ACCOUNT_NAME_FOR_EMULATOR[] = L"Tizen_Internet_1";
- static const wchar_t _DEFAULT_MMS_ACCOUNT_NAME_FOR_EMULATOR[] = L"Tizen_Mms_2";
-
- String defaultAccountName;
- int defaultAccountId;
-
- r = _NetAccountDatabase::GetAccountName(_DEFAULT_PS_ACCOUNT_ID, defaultAccountName);
- if (r != E_SUCCESS)
- {
- SysLog(NID_NET, "Default PS account is not found, so add it now.");
- r = _NetAccountDatabase::AddAccount(String(_DEFAULT_PS_ACCOUNT_NAME_FOR_EMULATOR),
- String(_DEFAULT_PS_ACCOUNT_NAME_FOR_EMULATOR), _NET_ACCOUNT_OWNER_SYSTEM_INTERNET, defaultAccountId);
- r = _NetAccountDatabase::AddAccount(String(_DEFAULT_MMS_ACCOUNT_NAME_FOR_EMULATOR),
- String(_DEFAULT_MMS_ACCOUNT_NAME_FOR_EMULATOR), _NET_ACCOUNT_OWNER_SYSTEM_MMS, defaultAccountId);
- }
-#endif // _OSP_EMUL_
-
__isInitialized = true;
}