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.
18 * @file FNetNetAccountManager.cpp
19 * @brief This is the implementation for the %NetAccountManagerclass.
22 #include <unique_ptr.h>
23 #include <FNetNetAccountManager.h>
24 #include <FBaseSysLog.h>
25 #include <FSec_AccessController.h>
26 #include <FSys_SystemInfoImpl.h>
27 #include "FNet_NetAccountManagerImpl.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Security;
33 using namespace Tizen::System;
35 namespace Tizen { namespace Net
38 NetAccountManager::NetAccountManager(void)
39 : __pNetAccountManagerImpl(null)
43 NetAccountManager::~NetAccountManager(void)
45 delete __pNetAccountManagerImpl;
46 __pNetAccountManagerImpl = null;
50 NetAccountManager::Construct(void)
54 SysAssertf(__pNetAccountManagerImpl == null,
55 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
57 unique_ptr<_NetAccountManagerImpl> pNetAccountManagerImpl(new (std::nothrow) _NetAccountManagerImpl());
58 SysTryReturnResult(NID_NET, pNetAccountManagerImpl != null, E_OUT_OF_MEMORY,
59 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
61 r = pNetAccountManagerImpl->Construct();
62 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
64 __pNetAccountManagerImpl = pNetAccountManagerImpl.release();
70 NetAccountManager::CreateNetAccount(NetAccountInfo& netAccountInfo)
73 NetAccountId netAccountId = INVALID_HANDLE;
75 r = _AccessController::CheckUserPrivilege(_PRV_NETWORK_ACCOUNT);
76 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY);
77 SysTryReturn(NID_NET, r == E_SUCCESS, INVALID_HANDLE, r,
78 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(r));
81 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
83 bool isTelephonySupported = false;
85 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
86 SysTryReturn(NID_NET, r == E_SUCCESS && isTelephonySupported, INVALID_HANDLE, E_UNSUPPORTED_OPERATION,
87 "[%s] Telephony is not supported.", GetErrorMessage(E_UNSUPPORTED_OPERATION));
90 SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
92 netAccountId = __pNetAccountManagerImpl->CreateNetAccount(netAccountInfo);
94 SysTryReturn(NID_NET, netAccountId != INVALID_HANDLE, INVALID_HANDLE, r, "[%s] Propagating.", GetErrorMessage(r));
100 NetAccountManager::DeleteNetAccount(NetAccountId netAccountId)
102 result r = E_SUCCESS;
104 r = _AccessController::CheckUserPrivilege(_PRV_NETWORK_ACCOUNT);
105 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY);
106 SysTryReturnResult(NID_NET, r == E_SUCCESS, r,
107 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(r));
109 SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
111 r = __pNetAccountManagerImpl->DeleteNetAccount(netAccountId);
112 SysTryReturn(NID_NET, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
118 NetAccountManager::UpdateNetAccount(const NetAccountInfo& netAccountInfo)
120 result r = E_SUCCESS;
122 r = _AccessController::CheckUserPrivilege(_PRV_NETWORK_ACCOUNT);
123 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY);
124 SysTryReturnResult(NID_NET, r == E_SUCCESS, r,
125 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(r));
128 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
130 bool isTelephonySupported = false;
132 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
133 SysTryReturnResult(NID_NET, r == E_SUCCESS && isTelephonySupported, E_UNSUPPORTED_OPERATION, "Telephony is not supported.");
134 #endif // !_OSP_EMUL_
136 SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
138 r = __pNetAccountManagerImpl->UpdateNetAccount(netAccountInfo);
139 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
145 NetAccountManager::GetNetAccountInfoN(NetAccountId netAccountId) const
147 result r = E_SUCCESS;
148 NetAccountInfo* pInfo = null;
150 SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
152 pInfo = __pNetAccountManagerImpl->GetNetAccountInfoN(netAccountId);
154 SysTryReturn(NID_NET, pInfo != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
159 IListT<NetAccountId>*
160 NetAccountManager::GetNetAccountIdsN(void) const
162 result r = E_SUCCESS;
163 IListT<NetAccountId>* pList = null;
165 SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
167 pList = __pNetAccountManagerImpl->GetNetAccountIdsN();
169 SysTryReturn(NID_NET, pList != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
175 NetAccountManager::GetNetAccountNamesN(void) const
177 result r = E_SUCCESS;
180 SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
182 pList = __pNetAccountManagerImpl->GetNetAccountNamesN();
184 SysTryReturn(NID_NET, pList != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
190 NetAccountManager::GetNetAccountId(const String& netAccountName) const
192 result r = E_SUCCESS;
193 NetAccountId netAccountId = INVALID_HANDLE;
195 SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
197 netAccountId = __pNetAccountManagerImpl->GetNetAccountId(netAccountName);
199 SysTryReturn(NID_NET, netAccountId != INVALID_HANDLE, INVALID_HANDLE, r, "[%s] Propagating.", GetErrorMessage(r));
205 NetAccountManager::GetNetAccountId(NetBearerType netBearerType) const
207 result r = E_SUCCESS;
208 NetAccountId netAccountId = INVALID_HANDLE;
210 SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
213 if (netBearerType == NET_BEARER_PS)
215 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
217 bool isTelephonySupported = false;
219 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
220 SysTryReturn(NID_NET, r == E_SUCCESS && isTelephonySupported, INVALID_HANDLE, E_UNSUPPORTED_OPERATION,
221 "[%s] Telephony is not supported.", GetErrorMessage(E_UNSUPPORTED_OPERATION));
223 else if (netBearerType == NET_BEARER_WIFI)
225 static const wchar_t _WIFI[] = L"http://tizen.org/feature/network.wifi";
227 bool isWifiSupported = false;
229 r = _SystemInfoImpl::GetSysInfo(_WIFI, isWifiSupported);
230 SysTryReturn(NID_NET, r == E_SUCCESS && isWifiSupported, INVALID_HANDLE, E_UNSUPPORTED_OPERATION,
231 "[%s] Wi-Fi is not supported.", GetErrorMessage(E_UNSUPPORTED_OPERATION));
233 else if (netBearerType == NET_BEARER_WIFI_DIRECT)
235 static const wchar_t _WIFI_DIRECT[] = L"http://tizen.org/feature/network.wifi.direct";
237 bool isWifiDirectSupported = false;
239 r = _SystemInfoImpl::GetSysInfo(_WIFI_DIRECT, isWifiDirectSupported);
240 SysTryReturn(NID_NET, r == E_SUCCESS && isWifiDirectSupported, INVALID_HANDLE, E_UNSUPPORTED_OPERATION,
241 "[%s] Wi-Fi direct is not supported.", GetErrorMessage(E_UNSUPPORTED_OPERATION));
243 else if (netBearerType == NET_BEARER_USB)
245 static const wchar_t _USB[] = L"http://tizen.org/feature/usb.host";
247 bool isUsbSupported = false;
249 r = _SystemInfoImpl::GetSysInfo(_USB, isUsbSupported);
250 SysTryReturn(NID_NET, r == E_SUCCESS && isUsbSupported, INVALID_HANDLE, E_UNSUPPORTED_OPERATION,
251 "[%s] USB is not supported.", GetErrorMessage(E_UNSUPPORTED_OPERATION));
253 else if (netBearerType == NET_BEARER_MMS)
255 static const wchar_t _MMS[] = L"http://tizen.org/feature/network.telephony.mms";
257 bool isMmsSupported = false;
259 r = _SystemInfoImpl::GetSysInfo(_MMS, isMmsSupported);
260 SysTryReturn(NID_NET, r == E_SUCCESS && isMmsSupported, INVALID_HANDLE, E_UNSUPPORTED_OPERATION,
261 "[%s] MMS is not supported.", GetErrorMessage(E_UNSUPPORTED_OPERATION));
263 #endif // !_OSP_EMUL_
265 netAccountId = __pNetAccountManagerImpl->GetNetAccountId(netBearerType);
266 SysTryReturn(NID_NET, netAccountId != INVALID_HANDLE, INVALID_HANDLE, E_SYSTEM, "[%s] Failed to get a network account.", GetErrorMessage(E_SYSTEM));
272 NetAccountManager::GetNetPreference(void) const
274 NetPreferenceType netPreference = NET_WIFI_FIRST;
276 SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
278 netPreference = __pNetAccountManagerImpl->GetNetPreference();
280 return netPreference;
284 NetAccountManager::SetNetPreference(NetPreferenceType netPreference)
286 result r = E_SUCCESS;
288 r = _AccessController::CheckUserPrivilege(_PRV_NETWORK_CONNECTION);
289 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
290 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "The application is not permitted to call this method.");
293 if (netPreference == NET_WIFI_ONLY)
295 static const wchar_t _WIFI[] = L"http://tizen.org/feature/network.wifi";
297 bool isWifiSupported = false;
299 r = _SystemInfoImpl::GetSysInfo(_WIFI, isWifiSupported);
300 SysTryReturnResult(NID_NET, r == E_SUCCESS && isWifiSupported, E_UNSUPPORTED_OPERATION, "Wi-Fi is not supported.");
302 else if (netPreference == NET_PS_ONLY)
304 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
306 bool isTelephonySupported = false;
308 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
309 SysTryReturnResult(NID_NET, r == E_SUCCESS && isTelephonySupported, E_UNSUPPORTED_OPERATION, "Telephony is not supported.");
311 #endif // !_OSP_EMUL_
313 SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
315 r = __pNetAccountManagerImpl->SetNetPreference(netPreference);
316 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");