2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
19 * @file FNetNetAccountManagerPartner.cpp
20 * @brief This is the implementation for the %NetAccountManager class. (only partner visibility)
23 #include <net_connection.h>
24 #include <FNetNetAccountManager.h>
25 #include <FBaseSysLog.h>
26 #include <FSec_AccessController.h>
27 #include <FSys_SystemInfoImpl.h>
28 #include "FNet_NetTypes.h"
29 #include "FNet_NetAccountDatabase.h"
30 #include "FNet_NetAccountInfoImpl.h"
31 #include "FNet_NetAccountManagerImpl.h"
32 #include "FNet_NetConnectionManagerImpl.h"
33 #include "FNet_NetIpcProxy.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Security;
37 using namespace Tizen::System;
39 namespace Tizen { namespace Net
43 NetAccountManager::UpdateSystemNetAccount(const NetAccountInfo& netAccountInfo)
47 NetBearerType bearerType = netAccountInfo.GetBearerType();
49 SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
52 if (bearerType == NET_BEARER_PS)
54 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
56 bool isTelephonySupported = false;
58 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
59 SysTryReturnResult(NID_NET, r == E_SUCCESS && isTelephonySupported, E_UNSUPPORTED_OPERATION, "Telephony is not supported.");
61 else if (bearerType == NET_BEARER_MMS)
63 static const wchar_t _MMS[] = L"http://tizen.org/feature/network.telephony.mms";
65 bool isMmsSupported = false;
67 r = _SystemInfoImpl::GetSysInfo(_MMS, isMmsSupported);
68 SysTryReturnResult(NID_NET, r == E_SUCCESS && isMmsSupported, E_UNSUPPORTED_OPERATION, "MMS is not supported.");
72 SysTryReturnResult(NID_NET, netAccountInfo.GetAccountId() > 0, E_INVALID_ARG,
73 "Invalid argument is used. accountId=%d", netAccountInfo.GetAccountId());
74 SysTryReturnResult(NID_NET, !netAccountInfo.GetAccountName().IsEmpty(), E_INVALID_ARG,
75 "Invalid argument is used. accountName is an empty string.");
77 r = _NetAccountDatabase::GetProfileName(netAccountInfo.GetAccountId(), profileName);
78 SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
79 SysTryReturnResult(NID_NET, r == E_SUCCESS, E_INVALID_ARG,
80 "Invalid argument is used. accountId=%d", netAccountInfo.GetAccountId());
82 _NetIpcProxy* pProxy = _NetIpcProxy::GetInstance();
83 SysTryReturnResult(NID_NET, pProxy != null, E_SYSTEM,
84 "A system error has been occurred. Failed to get an IPC proxy.");
86 r = pProxy->UpdateSystemNetAccount(profileName, netAccountInfo, bearerType);
87 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
89 r = _NetAccountDatabase::UpdateAccountName(netAccountInfo.GetAccountId(), netAccountInfo.GetAccountName());
90 SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
91 SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM,
92 "A system error has been occurred. Failed to update account name.");
98 NetAccountManager::GetAppNetAccountId(const String& netProfileName) const
100 result r = E_SUCCESS;
101 NetAccountId netAccountId = INVALID_HANDLE;
103 SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
106 if (netProfileName.Equals(L"Internet", false))
108 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
110 bool isTelephonySupported = false;
112 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
113 SysTryReturn(NID_NET, r == E_SUCCESS && isTelephonySupported, INVALID_HANDLE, E_UNSUPPORTED_OPERATION,
114 "[%s] Telephony is not supported.", GetErrorMessage(E_UNSUPPORTED_OPERATION));
116 else if (netProfileName.Equals(L"Mms", false))
118 static const wchar_t _MMS[] = L"http://tizen.org/feature/network.telephony.mms";
120 bool isMmsSupported = false;
122 r = _SystemInfoImpl::GetSysInfo(_MMS, isMmsSupported);
123 SysTryReturn(NID_NET, r == E_SUCCESS && isMmsSupported, INVALID_HANDLE, E_UNSUPPORTED_OPERATION,
124 "[%s] MMS is not supported.", GetErrorMessage(E_UNSUPPORTED_OPERATION));
126 #endif // !_OSP_EMUL_
128 _NetIpcProxy* pProxy = _NetIpcProxy::GetInstance();
129 SysTryReturn(NID_NET, pProxy != null, INVALID_HANDLE, E_SYSTEM,
130 "[%s] A system error has been occurred. Failed to get an IPC proxy.", GetErrorMessage(E_SYSTEM));
132 r = pProxy->GetAppNetAccountId(netProfileName, netAccountId);
133 SysTryReturn(NID_NET, r == E_SUCCESS, INVALID_HANDLE, r, "[%s] Propagating.", GetErrorMessage(r));
135 if (netAccountId == _DEFAULT_PS_ACCOUNT_ID)
137 netAccountId = _NetAccountManagerImpl::GetInternetAccountId();
139 else if (netAccountId == _DEFAULT_MMS_ACCOUNT_ID)
141 netAccountId = _NetAccountManagerImpl::GetMmsAccountId();
150 NetAccountManager::SetNetAccountId(NetAccountId netAccountId)
152 result r = E_SUCCESS;
153 NetAccountId netAccountId2 = INVALID_HANDLE;
155 SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
157 SysTryReturnResult(NID_NET, netAccountId > 0, E_INVALID_ARG,
158 "Invalid argument is used. accountId=%d", netAccountId);
160 _NetConnectionManagerImpl* pConnectionManager = _NetConnectionManagerImpl::GetInstance();
161 SysTryReturnResult(NID_NET, pConnectionManager != null, E_SYSTEM,
162 "A system error has been occurred. Failed to get NetConnectionManager instance.");
164 _NetIpcProxy* pProxy = _NetIpcProxy::GetInstance();
165 SysTryReturnResult(NID_NET, pProxy != null, E_SYSTEM,
166 "A system error has been occurred. Failed to get an IPC proxy.");
168 r = pProxy->SetNetAccountId(netAccountId, netAccountId2);
169 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
171 r = pConnectionManager->SetManagedNetAccountId(netAccountId2);
172 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");