Initialize Tizen 2.3
[framework/osp/net.git] / src / FNetNetAccountManagerPartner.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
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                        FNetNetAccountManagerPartner.cpp
20  * @brief               This is the implementation for the %NetAccountManager class. (only partner visibility)
21  */
22
23 #include <FNetNetAccountManager.h>
24 #include <FBaseSysLog.h>
25 #include <FSec_AccessController.h>
26 #include <FSys_SystemInfoImpl.h>
27 #include "FNet_NetTypes.h"
28 #include "FNet_NetAccountInfoImpl.h"
29 #include "FNet_NetAccountManagerImpl.h"
30 #include "FNet_NetConnectionManagerImpl.h"
31 #include "FNet_NetIpcProxy.h"
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Security;
35 using namespace Tizen::System;
36
37 namespace Tizen { namespace Net
38 {
39
40 result
41 NetAccountManager::UpdateSystemNetAccount(const NetAccountInfo& netAccountInfo)
42 {
43         result r = E_SUCCESS;
44         NetBearerType bearerType = netAccountInfo.GetBearerType();
45
46         SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
47
48 #ifndef _OSP_EMUL_
49         if (bearerType == NET_BEARER_PS)
50         {
51                 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
52
53                 bool isTelephonySupported = false;
54
55                 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
56                 SysTryReturnResult(NID_NET, r == E_SUCCESS && isTelephonySupported, E_UNSUPPORTED_OPERATION, "Telephony is not supported.");
57         }
58         else if (bearerType == NET_BEARER_MMS)
59         {
60                 static const wchar_t _MMS[] = L"http://tizen.org/feature/network.telephony.mms";
61
62                 bool isMmsSupported = false;
63
64                 r = _SystemInfoImpl::GetSysInfo(_MMS, isMmsSupported);
65                 SysTryReturnResult(NID_NET, r == E_SUCCESS && isMmsSupported, E_UNSUPPORTED_OPERATION, "MMS is not supported.");
66         }
67 #endif // !_OSP_EMUL_
68
69         SysTryReturnResult(NID_NET, netAccountInfo.GetAccountId() > 0, E_INVALID_ARG,
70                         "Invalid argument is used. accountId=%d", netAccountInfo.GetAccountId());
71         SysTryReturnResult(NID_NET, !netAccountInfo.GetAccountName().IsEmpty(), E_INVALID_ARG,
72                         "Invalid argument is used. accountName is an empty string.");
73         SysTryReturnResult(NID_NET, ((bearerType == NET_BEARER_PS) || (bearerType == NET_BEARER_MMS)), E_INVALID_ARG,
74                         "Invalid argument is used. accountId=%d", netAccountInfo.GetAccountId());
75
76         _NetIpcProxy* pProxy = _NetIpcProxy::GetInstance();
77         SysTryReturnResult(NID_NET, pProxy != null, E_SYSTEM,
78                         "A system error has been occurred. Failed to get an IPC proxy.");
79
80         r = pProxy->UpdateSystemNetAccount(netAccountInfo);
81         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
82
83         return r;
84 }
85
86 NetAccountId
87 NetAccountManager::GetAppNetAccountId(const String& netProfileName) const
88 {
89         result r = E_SUCCESS;
90         NetAccountId netAccountId = INVALID_HANDLE;
91
92         SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
93
94 #ifndef _OSP_EMUL_
95         if (netProfileName.Equals(L"Internet", false))
96         {
97                 static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
98
99                 bool isTelephonySupported = false;
100
101                 r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
102                 SysTryReturn(NID_NET, r == E_SUCCESS && isTelephonySupported, INVALID_HANDLE, E_UNSUPPORTED_OPERATION,
103                                 "[%s] Telephony is not supported.", GetErrorMessage(E_UNSUPPORTED_OPERATION));
104         }
105         else if (netProfileName.Equals(L"Mms", false))
106         {
107                 static const wchar_t _MMS[] = L"http://tizen.org/feature/network.telephony.mms";
108
109                 bool isMmsSupported = false;
110
111                 r = _SystemInfoImpl::GetSysInfo(_MMS, isMmsSupported);
112                 SysTryReturn(NID_NET, r == E_SUCCESS && isMmsSupported, INVALID_HANDLE, E_UNSUPPORTED_OPERATION,
113                                 "[%s] MMS is not supported.", GetErrorMessage(E_UNSUPPORTED_OPERATION));
114         }
115 #endif // !_OSP_EMUL_
116
117         _NetIpcProxy* pProxy = _NetIpcProxy::GetInstance();
118         SysTryReturn(NID_NET, pProxy != null, INVALID_HANDLE, E_SYSTEM,
119                         "[%s] A system error has been occurred. Failed to get an IPC proxy.", GetErrorMessage(E_SYSTEM));
120
121         r = pProxy->GetAppNetAccountId(netProfileName, netAccountId);
122         SysTryReturn(NID_NET, r == E_SUCCESS, INVALID_HANDLE, r, "[%s] Propagating.", GetErrorMessage(r));
123
124         ClearLastResult();
125
126         return netAccountId;
127 }
128
129 result
130 NetAccountManager::SetNetAccountId(NetAccountId netAccountId)
131 {
132         result r = E_SUCCESS;
133         NetAccountId netAccountId2 = INVALID_HANDLE;
134
135         SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
136
137         SysTryReturnResult(NID_NET, netAccountId > 0, E_INVALID_ARG,
138                         "Invalid argument is used. accountId=%d", netAccountId);
139
140         _NetConnectionManagerImpl* pConnectionManager = _NetConnectionManagerImpl::GetInstance();
141         SysTryReturnResult(NID_NET, pConnectionManager != null, E_SYSTEM,
142                         "A system error has been occurred. Failed to get NetConnectionManager instance.");
143
144         _NetIpcProxy* pProxy = _NetIpcProxy::GetInstance();
145         SysTryReturnResult(NID_NET, pProxy != null, E_SYSTEM,
146                         "A system error has been occurred. Failed to get an IPC proxy.");
147
148         r = pProxy->SetNetAccountId(netAccountId, netAccountId2);
149         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
150
151         r = pConnectionManager->SetManagedNetAccountId(netAccountId2);
152         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
153
154         return r;
155 }
156
157 }} // Tizen::Net