Merged from Tizen2.2 35/13535/1 accepted/tizen/mobile accepted/tizen/mobile/20131216.220442 submit/tizen/20131209.075824 submit/{branch}/20131209.075743
authordukan.kim <dukan.kim@samsung.com>
Mon, 9 Dec 2013 07:24:27 +0000 (16:24 +0900)
committerdukan.kim <dukan.kim@samsung.com>
Mon, 9 Dec 2013 07:24:27 +0000 (16:24 +0900)
Change-Id: I66372907c16525c1b9170e568af84dfaf0b53c00
Signed-off-by: dukan.kim <dukan.kim@samsung.com>
40 files changed:
CMakeLists.txt [changed mode: 0644->0755]
inc/ConnectivityUtility.h [new file with mode: 0755]
inc/IWifiProximityEventListener.h [changed mode: 0644->0755]
inc/NetAccountDatabase.h [new file with mode: 0755]
inc/NetConnectivityIpcStub.h [changed mode: 0644->0755]
inc/NetDefaultConnection.h [new file with mode: 0755]
inc/NetPsConnection.h [new file with mode: 0755]
inc/NetService.h [changed mode: 0644->0755]
inc/NetWifiConnection.h [new file with mode: 0755]
inc/NfcConnectivityIpcStub.h [changed mode: 0644->0755]
inc/NfcMessageRegisterService.h [changed mode: 0644->0755]
inc/NfcService.h [changed mode: 0644->0755]
inc/TelephonyConnectivityIpcStub.h [changed mode: 0644->0755]
inc/TelephonyService.h [changed mode: 0644->0755]
inc/WifiConnectivityIpcStub.h [changed mode: 0644->0755]
inc/WifiDirectService.h [new file with mode: 0755]
inc/WifiProximityService.h [changed mode: 0644->0755]
inc/WifiService.h [changed mode: 0644->0755]
inc/WifiSystemAdapter.h [new file with mode: 0755]
osp-connectivity-service.manifest [changed mode: 0644->0755]
packaging/osp-connectivity-service.spec
src/BluetoothService.cpp [changed mode: 0644->0755]
src/ConnectivityUtility.cpp [new file with mode: 0755]
src/NetAccountDatabase.cpp [new file with mode: 0755]
src/NetConnectivityIpcStub.cpp [changed mode: 0644->0755]
src/NetDefaultConnection.cpp [new file with mode: 0755]
src/NetPsConnection.cpp [new file with mode: 0755]
src/NetService.cpp [changed mode: 0644->0755]
src/NetWifiConnection.cpp [new file with mode: 0755]
src/NfcConnectivityIpcStub.cpp [changed mode: 0644->0755]
src/NfcMessagePushDelegate.cpp [changed mode: 0644->0755]
src/NfcMessageRegisterService.cpp [changed mode: 0644->0755]
src/NfcService.cpp [changed mode: 0644->0755]
src/TelephonyConnectivityIpcStub.cpp
src/TelephonyService.cpp
src/WifiConnectivityIpcStub.cpp [changed mode: 0644->0755]
src/WifiDirectService.cpp [new file with mode: 0755]
src/WifiProximityService.cpp [changed mode: 0644->0755]
src/WifiService.cpp [changed mode: 0644->0755]
src/WifiSystemAdapter.cpp [new file with mode: 0755]

old mode 100644 (file)
new mode 100755 (executable)
index 76f380a..60049c9
@@ -3,35 +3,58 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 SET (this_target osp-connectivity-service)
 SET (APPID 57r43275q7)
 
-INCLUDE(FindPkgConfig)
-pkg_check_modules(${this_target} REQUIRED osp-appfw-server osp-system-server osp-wifi ecore-x wifi-direct vconf tapi pkgmgr osp-telephony osp-nfc osp-net osp-bluetooth osp-appfw glib-2.0 evas ecore chromium capi-telephony-sim capi-system-info capi-system-device capi-network-wifi capi-network-nfc capi-network-connection capi-network-bluetooth capi-appfw-app-manager)
-
 SET(CMAKE_EXECUTABLE_SUFFIX ".exe")
 SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/output")
 
+
 INCLUDE_DIRECTORIES (
-       ${${this_target}_INCLUDE_DIRS}
-       /usr/include/osp
-       /usr/include/osp/app
-       /usr/include/osp/base
-       /usr/include/osp/io
-       /usr/include/osp/system
-       /usr/include/osp/security
        /usr/include/osp/net
        /usr/include/osp/telephony
-       /usr/include/osp/server
+       /usr/include/telephony-client
        inc
        )
 
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED
+       glib-2.0
+       osp-appfw
+       osp-appfw-server
+       osp-net
+       osp-wifi
+       chromium
+       vconf
+       ecore
+       ecore-x
+       evas
+       capi-appfw-app-manager
+       capi-telephony-sim
+       capi-telephony-network-info
+       wifi-direct
+       capi-network-wifi
+       capi-network-nfc
+       capi-network-bluetooth
+       capi-network-connection
+       tapi
+)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
 SET (${this_target}_SOURCE_FILES
        src/BluetoothConnectivityIpcMessages.cpp
        src/BluetoothConnectivityIpcStub.cpp
        src/BluetoothService.cpp
        src/ConnectivityService.cpp
        src/ConnectivityServiceEntry.cpp
+       src/ConnectivityUtility.cpp
        src/NetConnectivityIpcMessages.cpp
        src/NetConnectivityIpcStub.cpp
        src/NetService.cpp
+       src/NetAccountDatabase.cpp
+       src/NetDefaultConnection.cpp
+       src/NetPsConnection.cpp
+       src/NetWifiConnection.cpp
        src/NfcConnectivityIpcMessages.cpp
        src/NfcConnectivityIpcStub.cpp
        src/NfcMessagePushDelegate.cpp
@@ -42,10 +65,12 @@ SET (${this_target}_SOURCE_FILES
        src/TelephonyService.cpp
        src/WifiConnectivityIpcMessages.cpp
        src/WifiConnectivityIpcStub.cpp
+       src/WifiService.cpp
+       src/WifiDirectService.cpp
+       src/WifiProximityService.cpp
        src/WifiProximityEvent.cpp
        src/WifiProximityEventArg.cpp
-       src/WifiProximityService.cpp
-       src/WifiService.cpp
+       src/WifiSystemAdapter.cpp
        )
        
 ## SET EXTRA COMPILER FLAGS
@@ -66,7 +91,10 @@ SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
 ## Create Library
 ADD_EXECUTABLE (${this_target} ${${this_target}_SOURCE_FILES})
 
-TARGET_LINK_LIBRARIES(${this_target} ${${this_target}_LDFLAGS} ${${this_target}_LIBRARIES})
+
+TARGET_LINK_LIBRARIES(${this_target} -Xlinker --no-undefined -Xlinker --as-needed -pie)
+TARGET_LINK_LIBRARIES(${this_target} -Xlinker --version-script=${CMAKE_CURRENT_SOURCE_DIR}/system-service-export.ver)
+TARGET_LINK_LIBRARIES(${this_target} ${pkgs_LDFLAGS})
 
 ## Cory additional info
 INSTALL(TARGETS ${this_target} DESTINATION ../usr/apps/${APPID}/bin)
diff --git a/inc/ConnectivityUtility.h b/inc/ConnectivityUtility.h
new file mode 100755 (executable)
index 0000000..f65cb47
--- /dev/null
@@ -0,0 +1,94 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+/**
+ * @file       ConnectivityUtility.h
+ * @brief      This is the header file for the %ConnectivityUtility class.
+ *
+ * This header file contains the declarations of the %ConnectivityUtility class.
+ */
+
+#ifndef _CONNECTIVITY_UTILITY_H_
+#define _CONNECTIVITY_UTILITY_H_
+
+#include <net_connection.h>
+#include <unique_ptr.h>
+#include <FBaseDataType.h>
+
+struct _CharDeleter
+{
+       void operator()(char* pChar)
+       {
+               free(pChar);
+       }
+};
+
+struct _ConnectionDeleter
+{
+       void operator()(void* pConnection)
+       {
+               connection_destroy(pConnection);
+       }
+};
+
+struct _ProfileDeleter
+{
+       void operator()(void* pProfile)
+       {
+               connection_profile_destroy(pProfile);
+       }
+};
+
+struct _ProfileIteratorDeleter
+{
+       void operator()(void* pIterator)
+       {
+               connection_destroy_profile_iterator(pIterator);
+       }
+};
+
+
+namespace Tizen { namespace Net {
+
+class NetAccountInfo;
+class NetConnectionInfo;
+
+namespace Wifi {
+
+class _WifiNetAccountInfoImpl;
+} } }
+
+class  ConnectivityUtility
+{
+public:
+       static void UpdateNetConnectionInfo(Tizen::Net::NetConnectionInfo* pInfo, connection_profile_h profileHandle, bool isDefault);
+       static result UpdateNetAccountInfo(Tizen::Net::NetAccountInfo* pInfo, connection_profile_h profileHandle);
+       static result UpdateProfileInfo(const Tizen::Net::NetAccountInfo* pInfo, connection_profile_h profileHandle, bool isAppProfile);
+       static result UpdateWifiNetAccountInfo(Tizen::Net::Wifi::_WifiNetAccountInfoImpl* pWifiNetAccountInfoImpl, connection_profile_h profileHandle);
+
+       static connection_profile_h GetWifiProfileHandleN(void);
+       static connection_profile_h GetPsProfileHandleN(const Tizen::Base::String& profileName);
+
+private:
+       ConnectivityUtility(void);
+       virtual ~ConnectivityUtility(void);
+
+       ConnectivityUtility(const ConnectivityUtility& rhs);
+       ConnectivityUtility& operator =(const ConnectivityUtility& rhs);
+}; // ConnectivityUtility
+
+#endif // _CONNECTIVITY_UTILITY_H_
+
old mode 100644 (file)
new mode 100755 (executable)
index 7e8b5ad..10ddd54
@@ -30,8 +30,8 @@
  * @brief       This interface implements listeners for WifiProximityService internal events.
  */
 
-class IWifiProximityEventListener:
-       public Tizen::Base::Runtime::IEventListener
+class IWifiProximityEventListener
+        : public Tizen::Base::Runtime::IEventListener
 {
 
 public:
@@ -47,6 +47,6 @@ public:
       */
     virtual void OnWifiProximityDeactivated(void) = 0;
 
-}; // _IWifiManagerEventListener
+}; // IWifiProximityEventListener
 
 #endif /* _IWIFI_PROXIMITY_EVENT_LISTENER_H_ */
diff --git a/inc/NetAccountDatabase.h b/inc/NetAccountDatabase.h
new file mode 100755 (executable)
index 0000000..02e6dad
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+/**
+ * @file       NetAccountDatabase.h
+ * @brief      This is the header file for the %NetAccountDatabase class.
+ *
+ * This header file contains the declarations of the %NetAccountDatabase class.
+ */
+
+#ifndef _NET_ACCOUNT_DATABASE_H_
+#define _NET_ACCOUNT_DATABASE_H_
+
+#include <FBaseDataType.h>
+#include <FBaseString.h>
+#include <FBaseCol.h>
+#include <FNetNetTypes.h>
+
+extern const wchar_t SYSTEM_PACKAGE_NAME[];
+
+class NetAccountDatabase
+{
+public:
+       static result InitializeRepository(void);
+       static result AddAccount(const Tizen::Base::String& accountName, const Tizen::Base::String& profileName, const Tizen::Base::String& packageId, Tizen::Net::NetAccountId& accountId);
+       static result RemoveAccountByAccountId(Tizen::Net::NetAccountId accountId);
+       static result RemoveAccountByProfileName(const Tizen::Base::String& profileName);
+       static result UpdateAccountName(Tizen::Net::NetAccountId accountId, const Tizen::Base::String& accountName);
+       static result GetAccountIds(Tizen::Base::Collection::ArrayListT<Tizen::Net::NetAccountId>* pList);
+       static result GetAccountNames(Tizen::Base::Collection::ArrayList* pList);
+       static Tizen::Base::Collection::IList* GetProfileNamesN(void);
+       static result GetAccountName(Tizen::Net::NetAccountId accountId, Tizen::Base::String& accountName);
+       static result GetProfileName(Tizen::Net::NetAccountId accountId, Tizen::Base::String& profileName);
+       static result GetAccountIdByAccountName(const Tizen::Base::String& accountName, Tizen::Net::NetAccountId& accountId);
+       static result GetAccountIdByProfileName(const Tizen::Base::String& profileName, Tizen::Net::NetAccountId& accountId);
+       static bool IsReadOnly(const Tizen::Base::String& packageId, Tizen::Net::NetAccountId accountId);
+
+private:
+       static Tizen::Base::String GetDbPath(void);
+
+private:
+       NetAccountDatabase(void);
+       virtual ~NetAccountDatabase(void);
+
+       NetAccountDatabase(const NetAccountDatabase& rhs);
+       NetAccountDatabase& operator =(const NetAccountDatabase& rhs);
+}; // NetAccountDatabase
+
+#endif // _NET_ACCOUNT_DATABASE_H_
+
old mode 100644 (file)
new mode 100755 (executable)
index 797d549..ba395df
@@ -27,6 +27,7 @@
 
 #include <FBaseObject.h>
 #include <FNetNetAccountInfo.h>
+#include <FNetNetConnectionInfo.h>
 #include <FIo_IIpcServerEventListener.h>
 
 namespace Tizen { namespace Base {
@@ -38,6 +39,8 @@ class _IpcServer;
 } }
 
 class NetService;
+class NetDefaultConnection;
+class NetWifiConnection;
 
 /**
  * @class      NetConnectivityIpcStub
@@ -63,22 +66,56 @@ public:
        virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId);
        virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
 
+       result SendDefaultConnectionChanged(int clientId, unsigned long res, int eventType, int connectionState, int bearerType, const Tizen::Net::NetConnectionInfo& connectionInfo);
+       result SendWifiConnectionChanged(int clientId, unsigned long res, int eventType, int connectionState, const Tizen::Net::NetConnectionInfo& connectionInfo);
+       result SendPsConnectionStarted(int clientId, const Tizen::Base::String& profileName, unsigned long res, const Tizen::Net::NetConnectionInfo& connectionInfo);
+       result SendPsConnectionStopped(int clientId, const Tizen::Base::String& profileName, unsigned long res);
+       result SendDefaultProxyChanged(int clientId, const Tizen::Base::String& proxy);
+
 private:
        NetConnectivityIpcStub(const NetConnectivityIpcStub& rhs);
        NetConnectivityIpcStub& operator =(const NetConnectivityIpcStub& rhs);
 
-       // Net
        void OnGetAppNetAccountId(const Tizen::Base::String& profileName, int* pNetAccountId, unsigned long* pResult);
        void OnSetNetAccountId(int netAccountId, int* pNetAccountId2, unsigned long* pResult);
-       void OnUpdateSystemNetAccount(const Tizen::Base::String& profileName, const Tizen::Net::NetAccountInfo& netAccountInfo,
-                       int bearerType, unsigned long* pResult);
+       void OnUpdateSystemNetAccount(const Tizen::Net::NetAccountInfo& netAccountInfo,unsigned long* pResult);
        void OnResetNetStatistics(int bearerType, int statType, unsigned long* pResult);
        void OnResetAllNetStatistics(int bearerType, unsigned long* pResult);
 
+       void OnAddDefaultConnectionListener(int* pConnectionState, int* pBearerType, Tizen::Net::NetConnectionInfo* pConnectionInfo, unsigned long* pResult);
+       void OnRemoveDefaultConnectionListener(unsigned long* pResult);
+       void OnAddWifiConnectionListener(int* pConnectionState, Tizen::Net::NetConnectionInfo* pConnectionInfo, unsigned long* pResult);
+       void OnRemoveWifiConnectionListener(unsigned long* pResult);
+       void OnStartWifiConnection(unsigned long* pResult);
+       void OnStartPsConnection(const Tizen::Base::String& profileName, unsigned long* pResult);
+       void OnStopPsConnection(const Tizen::Base::String& profileName, unsigned long* pResult);
+       void OnGetPsConnectionState(const Tizen::Base::String& profileName, int* pConnectionState, Tizen::Base::String* pDeviceName, unsigned long* pResult);
+       void OnGetNetAccountName(int netAccountId, Tizen::Base::String* pNetAccountName, unsigned long* pResult);
+       void OnGetNetProfileName(int netAccountId, Tizen::Base::String* pNetProfileName, unsigned long* pResult);
+       void OnGetNetConnectionInfo(int netAccountId, Tizen::Net::NetConnectionInfo* pConnectionInfo, unsigned long* pResult);
+       void OnGetNetAccountInfo(int netAccountId, Tizen::Net::NetAccountInfo* pAccountInfo, unsigned long* pResult);
+       void OnGetNetAccountId(const Tizen::Base::String& accountName, int* pAccountId, unsigned long* pResult);
+       void OnGetInternetNetAccountId(int* pAccountId, unsigned long* pResult);
+       void OnGetMmsNetAccountId(int* pAccountId, unsigned long* pResult);
+       void OnCreateNetAccount(const Tizen::Net::NetAccountInfo& netAccountInfo, int* pAccountId, unsigned long* pResult);
+       void OnDeleteNetAccount(int netAccountId, unsigned long* pResult);
+       void OnUpdateNetAccount(const Tizen::Net::NetAccountInfo& netAccountInfo, unsigned long* pResult);
+       void OnGetNetAccountIds(Tizen::Base::Collection::ArrayListT<int>* pList, unsigned long* pResult);
+       void OnGetNetAccountNames(Tizen::Base::Collection::ArrayList* pList, unsigned long* pResult);
+       void OnGetAllNetConnectionInfo(Tizen::Base::Collection::ArrayListT<Tizen::Net::NetConnectionInfo*>* pList, unsigned long* pResult);
+
+private:
+       NetService* GetNetService(void);
+       NetDefaultConnection* GetNetDefaultConnection(void);
+       NetWifiConnection* GetNetWifiConnection(void);
+
 private:
        NetService* __pNetService;
+       NetDefaultConnection* __pNetDefaultConnection;
+       NetWifiConnection* __pNetWifiConnection;
        Tizen::Io::_IpcServer* __pIpcServer;
-
+       Tizen::Base::Collection::ArrayList* __pAccountNameList;
+       Tizen::Base::Collection::ArrayList* __pConnectionInfoList;
 };
 
 #endif // _NET_CONNECTIVITY_IPC_STUB_H_
diff --git a/inc/NetDefaultConnection.h b/inc/NetDefaultConnection.h
new file mode 100755 (executable)
index 0000000..d67d8b5
--- /dev/null
@@ -0,0 +1,81 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+/**
+ * @file       NetDefaultConnection.h
+ * @brief      This is the header file for the %NetDefaultConnection class.
+ *
+ * This header file contains the declarations of the %NetDefaultConnection class.
+ */
+
+#ifndef _NET_DEFAULT_CONNECTION_H_
+#define _NET_DEFAULT_CONNECTION_H_
+
+#include <net_connection.h>
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseColAllElementsDeleter.h>
+#include <FNetNetConnectionInfo.h>
+#include <FNetNetTypes.h>
+#include <FNet_NetTypes.h>
+
+
+class NetConnectivityIpcStub;
+
+class NetDefaultConnection
+{
+public:
+    static NetDefaultConnection* GetInstance(NetConnectivityIpcStub* pStub);
+
+    NetDefaultConnection(void);
+    virtual ~NetDefaultConnection(void);
+
+    result AddEventListener(int clientId, int* pConnectionState, int* pBearerType, Tizen::Net::NetConnectionInfo* pInfo);
+    result RemoveEventListener(int clientId);
+
+private:
+    NetDefaultConnection(const NetDefaultConnection& rhs);
+    NetDefaultConnection& operator =(const NetDefaultConnection& rhs);
+
+    result Construct(NetConnectivityIpcStub* pStub);
+
+       static void ActiveConnectionTypeChangedCallback(connection_type_e type, void* pUserData);
+       static void ActiveConnectionProxyChangedCallback(const char* pIpv4Address, const char* pIpv6Address, void *pUserData);
+
+       void HandleEvent(Tizen::Net::_NetConnectionEventType type, result error = E_SUCCESS);
+
+       void UpdateConnectionInfo(void* pData);
+
+private:
+    NetConnectivityIpcStub* __pStub;
+    bool __isInitialized;
+       Tizen::Net::NetBearerType __bearerType;
+       Tizen::Net::NetConnectionState __connectionState;
+       Tizen::Net::NetConnectionInfo __connectionInfo;
+
+       connection_h __pConnectionHandle;
+
+       std::unique_ptr< Tizen::Base::Collection::ArrayListT<int> > __pClientList;
+
+       int __clientCount;
+
+    static NetDefaultConnection* __pNetDefaultConnection;
+
+       friend class std::default_delete<NetDefaultConnection>;
+}; // NetDefaultConnection
+
+#endif // _NET_DEFAULT_CONNECTION_H_
+
diff --git a/inc/NetPsConnection.h b/inc/NetPsConnection.h
new file mode 100755 (executable)
index 0000000..fcc799c
--- /dev/null
@@ -0,0 +1,85 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+/**
+ * @file       NetPsConnection.h
+ * @brief      This is the header file for the %NetPsConnection class.
+ *
+ * This header file contains the declarations of the %NetPsConnection class.
+ */
+
+#ifndef _NET_PS_CONNECTION_H_
+#define _NET_PS_CONNECTION_H_
+
+#include <net_connection.h>
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseColAllElementsDeleter.h>
+#include <FBaseColHashMap.h>
+#include <FNetNetConnectionInfo.h>
+#include <FNetNetTypes.h>
+#include <FNet_NetTypes.h>
+
+
+class NetConnectivityIpcStub;
+
+class NetPsConnection
+       : public Tizen::Base::Object
+{
+public:
+    static NetPsConnection* GetInstance(const Tizen::Base::String& profileName, NetConnectivityIpcStub* pStub);
+       static void StopAll(int clientId);
+
+    result Start(int clientId);
+    result Stop(int clientId);
+    result GetState(int clientId, int* pConnectionState, Tizen::Base::String* pDeviceName);
+
+private:
+    NetPsConnection(void);
+    virtual ~NetPsConnection(void);
+    NetPsConnection(const NetPsConnection& rhs);
+    NetPsConnection& operator =(const NetPsConnection& rhs);
+
+    result Construct(const Tizen::Base::String& profileName, NetConnectivityIpcStub* pStub);
+
+    static void PsConnectionOpenCallback(connection_error_e res, void* pUserData);
+    static void PsConnectionCloseCallback(connection_error_e res, void* pUserData);
+    static void PsConnectionStateChangedCallback(connection_profile_state_e state, void* pUserData);
+
+       void HandleEvent(Tizen::Net::_NetConnectionEventType type, result error = E_SUCCESS);
+
+       void UpdateConnectionInfo(void* pData);
+
+private:
+    NetConnectivityIpcStub* __pStub;
+    Tizen::Base::String __profileName;
+       Tizen::Net::NetConnectionState __connectionState;
+       Tizen::Net::NetConnectionInfo __connectionInfo;
+
+       connection_h __pConnectionHandle;
+       connection_profile_h __pProfileHandle;
+
+       std::unique_ptr< Tizen::Base::Collection::ArrayListT<int> > __pClientList;
+
+       int __clientCount;
+
+       static Tizen::Base::Collection::HashMap* __pPsConnectionMap;
+
+       friend class std::default_delete<NetPsConnection>;
+}; // NetPsConnection
+
+#endif // _NET_PS_CONNECTION_H_
+
old mode 100644 (file)
new mode 100755 (executable)
index 03121d2..529821d
@@ -26,6 +26,7 @@
 #define _NET_SERVICE_H_
 
 #include <FBaseString.h>
+#include <FBaseCol.h>
 #include <FNetNetAccountInfo.h>
 #include <FNetNetTypes.h>
 
 class NetService
 {
 public:
-    NetService(void);
+    static NetService* GetInstance(void);
 
+       NetService(void);
     virtual ~NetService(void);
 
     result GetAppNetAccountId(const Tizen::Base::String& profileName, int& netAccountId);
     result SetNetAccountId(int netAccountId, int& netAccountId2);
-    result UpdateSystemNetAccount(const Tizen::Base::String& profileName, const Tizen::Net::NetAccountInfo& netAccountInfo, int bearerType);
+    result UpdateSystemNetAccount(const Tizen::Net::NetAccountInfo& netAccountInfo);
     result ResetNetStatistics(int bearerType, int statType);
     result ResetAllNetStatistics(int bearerType);
+    result GetNetConnectionInfo(int netAccountId, Tizen::Net::NetConnectionInfo* pConnectionInfo);
+    result GetAllNetConnectionInfo(Tizen::Base::Collection::ArrayList* pList);
 
 private:
-    void* GetPsProfileHandleN(const Tizen::Base::String& profileName);
-    result ConvertToProfileInfo(void* pProfileHandle, const Tizen::Net::NetAccountInfo& netAccountInfo, int bearerType) const;
+    NetService(const NetService& rhs);
+    NetService& operator =(const NetService& rhs);
+
+    result Construct(void);
+
+public:
+       Tizen::Net::NetAccountId CreateNetAccount(const Tizen::Base::String& packageId, const Tizen::Net::NetAccountInfo& netAccountInfo);
+       result DeleteNetAccount(const Tizen::Base::String& packageId, Tizen::Net::NetAccountId netAccountId);
+       result UpdateNetAccount(const Tizen::Base::String& packageId, const Tizen::Net::NetAccountInfo& netAccountInfo);
+       Tizen::Net::NetAccountId GetNetAccountId(const Tizen::Base::String& netAccountName);
+       Tizen::Net::NetAccountId GetNetAccountId(Tizen::Net::NetBearerType netBearerType);
+       result GetNetAccountInfo(const Tizen::Base::String& packageId, Tizen::Net::NetAccountId netAccountId, Tizen::Net::NetAccountInfo* pNetAccountInfo) const;
+       result GetNetAccountIds(Tizen::Base::Collection::ArrayListT<Tizen::Net::NetAccountId>* pList);
+       result GetNetAccountNames(Tizen::Base::Collection::ArrayList* pList);
+       Tizen::Net::NetAccountId GetInternetAccountId(void);
+       Tizen::Net::NetAccountId GetMmsAccountId(void);
+
+private:
+       Tizen::Base::Collection::IList* GetAppProfileNamesN(void);
+       Tizen::Base::Collection::IList* GetAllProfileNamesN(void);
+       void UpdateNetAccountDb();
 
 private:
     void* __pConnectionHandle;
+       Tizen::Net::NetAccountId __internetAccountId;
+       Tizen::Net::NetAccountId __mmsAccountId;
+       Tizen::Base::String __internetProfileName;
+       Tizen::Base::String __mmsProfileName;
+
+    static NetService* __pNetService;
 };
 
 #endif // _NET_SERVICE_H_
diff --git a/inc/NetWifiConnection.h b/inc/NetWifiConnection.h
new file mode 100755 (executable)
index 0000000..8dbe245
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+/**
+ * @file       NetWifiConnection.h
+ * @brief      This is the header file for the %NetWifiConnection class.
+ *
+ * This header file contains the declarations of the %NetWifiConnection class.
+ */
+
+#ifndef _NET_WIFI_CONNECTION_H_
+#define _NET_WIFI_CONNECTION_H_
+
+#include <net_connection.h>
+#include <wifi.h>
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FBaseColAllElementsDeleter.h>
+#include <FNetNetConnectionInfo.h>
+#include <FNetNetTypes.h>
+#include <FNet_NetTypes.h>
+#include <FApp_IAppEventListener.h>
+
+
+class NetConnectivityIpcStub;
+
+class NetWifiConnection
+       : public Tizen::App::_IAppEventListener
+{
+public:
+    static NetWifiConnection* GetInstance(NetConnectivityIpcStub* pStub);
+
+    NetWifiConnection(void);
+    virtual ~NetWifiConnection(void);
+
+    result AddEventListener(int clientId, int* pConnectionState, Tizen::Net::NetConnectionInfo* pInfo);
+    result RemoveEventListener(int clientId);
+
+    result Start(void);
+
+private:
+    NetWifiConnection(const NetWifiConnection& rhs);
+    NetWifiConnection& operator =(const NetWifiConnection& rhs);
+
+    result Construct(NetConnectivityIpcStub* pStub);
+
+       static void WifiConnectionTypeChangedCallback(connection_type_e type, void* pUserData);
+       static void WifiConnectionProxyChangedCallback(const char* pIpv4Address, const char* pIpv6Address, void *pUserData);
+       static void WifiConnectionActivatedCallback(wifi_error_e res, void* pUserData);
+
+       virtual void OnApplicationLaunched(const Tizen::App::AppId& appId, int pid);
+       virtual void OnApplicationTerminated(const Tizen::App::AppId& appId, int pid);
+
+       void HandleEvent(Tizen::Net::_NetConnectionEventType type, result error = E_SUCCESS);
+
+       void UpdateConnectionInfo(void* pData);
+
+private:
+    NetConnectivityIpcStub* __pStub;
+    bool __isInitialized;
+    bool __isStarting;
+       Tizen::Net::NetConnectionState __connectionState;
+       Tizen::Net::NetConnectionInfo __connectionInfo;
+
+       connection_h __pConnectionHandle;
+
+       std::unique_ptr< Tizen::Base::Collection::ArrayListT<int> > __pClientList;
+
+       int __clientCount;
+
+    static NetWifiConnection* __pNetWifiConnection;
+
+       friend class std::default_delete<NetWifiConnection>;
+}; // NetWifiConnection
+
+#endif // _NET_WIFI_CONNECTION_H_
+
old mode 100644 (file)
new mode 100755 (executable)
index 662f24c..708b621
@@ -27,6 +27,7 @@
 
 #include <FBaseObject.h>
 #include <FIo_IIpcServerEventListener.h>
+#include "FIo_IpcCommonDataTypes.h"
 
 namespace Tizen { namespace Base {
 class String;
@@ -69,14 +70,13 @@ private:
 
        // Nfc
        void OnInitializeNfc(unsigned long* pResult);
-       void OnSetNfcLaunchPopupEnabled(bool enable, unsigned long* pResult);
        void OnRegisterNfcPushMessage(const Tizen::Base::ByteBuffer& pushMessageBuffer, const Tizen::Base::String& description,
                        unsigned long* pResult);
        void OnUnregisterNfcPushMessage(unsigned long* pResult);
        void OnActivateReservedPush(unsigned long* pResult);
        void OnDeactivateReservedPush(unsigned long* pResult);
        void OnIsReservedPushActivated(bool* pIsActivated);
-       void OnGetReservedPushCandidates(Tizen::Base::Collection::HashMap* pCandidates, unsigned long* pResult);
+       void OnGetReservedPushCandidates(Tizen::Io::_StringMap* pCandidates, unsigned long* pResult);
        void OnPickReservedPushMessage(const Tizen::Base::String& appId, unsigned long* pResult);
        void OnGetPickedReservedPushMessage(Tizen::Base::String* pAppId, unsigned long* pResult);
 
old mode 100644 (file)
new mode 100755 (executable)
index 7b210bc..5bcfa3b
@@ -31,6 +31,7 @@
 #include <FBaseColLinkedListT.h>
 #include <FIoDatabase.h>
 #include <FAppPkgIPackageInstallationEventListener.h>
+#include "FIo_IpcCommonDataTypes.h"
 
 namespace Tizen { namespace Base
 {
@@ -62,7 +63,7 @@ public:
        result RegisterPushMessage(const Tizen::Base::String& appPkgId,
                        const Tizen::Base::ByteBuffer& pushMessageBuffer, const Tizen::Base::String& description);
        result UnregisterPushMessage(const Tizen::Base::String& appPkgId);
-       result GetReservedPushCandidates(Tizen::Base::Collection::HashMap* pCandidates);
+       result GetReservedPushCandidates(Tizen::Io::_StringMap* pCandidates);
        result PickReservedPushMessage(const Tizen::Base::String& ownerAppId);
 
        // From IPackageInstallationEventListener;
old mode 100644 (file)
new mode 100755 (executable)
index f1183da..c89fa2d
@@ -29,6 +29,7 @@
 #include <FBaseRtMutex.h>
 #include <FBaseString.h>
 #include <FBaseColLinkedListT.h>
+#include "FIo_IpcCommonDataTypes.h"
 
 namespace Tizen { namespace Base
 {
@@ -62,7 +63,7 @@ public:
        result ActivateReservedPush(void);
        result DeactivateReservedPush(void);
        bool IsReservedPushActivated(void);
-       result GetReservedPushCandidates(Tizen::Base::Collection::HashMap* pCandidates);
+       result GetReservedPushCandidates(Tizen::Io::_StringMap* pCandidates);
        result PickReservedPushMessage(const Tizen::Base::String& appId);
        result GetPickedReservedPushMessage(Tizen::Base::String& appId);
 
@@ -75,10 +76,7 @@ public:
 private:
        NfcMessageRegisterService* __pRegisterService;
        NfcMessagePushDelegate* __pPushDelegate;
-       Tizen::Base::Runtime::Mutex __enablingMutex;
-       bool __popupEnabled;
        Tizen::Base::String __serviceDaemonId;
-       Tizen::Base::String __popupDisablerId;
        Tizen::Base::Runtime::Mutex __listMutex;
        Tizen::Base::Collection::LinkedListT<Tizen::Base::String> __appPkgIdList;
 
old mode 100644 (file)
new mode 100755 (executable)
index 192e31a..c00c069
@@ -26,7 +26,6 @@
 #define _TELEPHONY_CONNECTIVITY_IPC_STUB_H_
 
 #include <FBaseObject.h>
-#include <FNetNetAccountInfo.h>
 #include <FIo_IIpcServerEventListener.h>
 
 namespace Tizen { namespace Base {
@@ -64,6 +63,7 @@ public:
     result SendCallForwardResponseReceived(int clientId, Tizen::Base::String phoneNumber, unsigned long res);
     result SendCallForwardStopped(int clientId, Tizen::Base::String phoneNumber, unsigned long res);
 
+    result SendNetworkStatusChanged(int clientId, bool isCallServiceAvailable, bool isDataServiceAvailable, bool isRoaming);
 
        // from _IIpcServerEventListener
        virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server);
@@ -87,6 +87,8 @@ private:
        void OnRequestCallForward(const Tizen::Base::String& phoneNumber, unsigned long* pResult);
        void OnStopCallForward(unsigned long* pResult);
        void OnGetCallForwardNumber(unsigned long* pResult);
+       void OnAddNetworkStatusEventListener(unsigned long* pResult);
+       void OnRemoveNetworkStatusEventListener(unsigned long* pResult);
 
 private:
        TelephonyService* __pTelephonyService;
old mode 100644 (file)
new mode 100755 (executable)
index 3b969fc..8c7345d
 #ifndef _TELEPHONY_SERVICE_H_
 #define _TELEPHONY_SERVICE_H_
 
+#include <net_connection.h>
 #include <tapi_type.h>
 #include <TelNetwork.h>
+#include <telephony_network.h>
 #include <FBaseString.h>
+#include <FBaseCol.h>
+#include <FBaseColAllElementsDeleter.h>
 
 
 class TelephonyConnectivityIpcStub;
@@ -43,9 +47,7 @@ class TelephonyConnectivityIpcStub;
 class TelephonyService
 {
 public:
-    static TelephonyService* GetInstance(void);
-
-    result Construct(TelephonyConnectivityIpcStub* pStub);
+    static TelephonyService* GetInstance(TelephonyConnectivityIpcStub* pStub);
 
     result GetImsi(Tizen::Base::String* pImsi);
     result GetNetworkSelectionMode(int clientId);
@@ -57,6 +59,9 @@ public:
     result StopCallForward(int clientId);
     result GetCallForwardNumber(int clientId);
 
+    result AddNetworkStatusEventListener(int clientId);
+    result RemoveNetworkStatusEventListener(int clientId);
+
     static void OnNetworkSelectionModeReceived(TapiHandle* pHandle, int err, void* pData, void* pUserData);
     static void OnNetworkSelectCompleted(TapiHandle* pHandle, int err, void* pData, void* pUserData);
     static void OnNetworkSearchCompleted(TapiHandle* pHandle, int err, void* pData, void* pUserData);
@@ -97,24 +102,45 @@ public:
      */
     static void OnCallForwardStoppedCallback(TapiHandle* pHandle, int err, void* pData, void* pUserData);
 
-
-
-
     static Tizen::Base::String MakeNetworkInfoMessage(TelNetworkIdentity_t& info);
     static result ConvertError(int err);
 
+       static void OnDataServiceStateChangedCallback(connection_type_e type, void* pUserData);
+       static void OnCallServiceStateChangedCallback(network_info_service_state_e serviceState, void* pUserData);
+       static void OnRoamingStateChangedCallback(bool isRoaming, void* pUserData);
 
 private:
     TelephonyService(void);
     virtual ~TelephonyService(void);
     static void InitTelephonyService();
 
+    result Construct(void);
+    void SetIpcStub(TelephonyConnectivityIpcStub* pStub);
+
+       bool IsServiceAvailable(void) const;
+       bool IsDataAvailable(void) const;
+       bool IsRoaming(void) const;
+       bool IsNetworkAvailable(void) const;
+
+       void OnTelephonyNetworkStatusChanged(void);
+
 private:
-    Tizen::Base::String __imsi;
-    TapiHandle* __pHandle;
     TelephonyConnectivityIpcStub* __pStub;
 
+    TapiHandle* __pHandle;
+       connection_h __pConnectionHandle;
+
+       std::unique_ptr< Tizen::Base::Collection::ArrayListT<int> > __pClientList;
+
+       int __clientCount;
+
+       bool __isCallServiceAvailable;
+       bool __isDataServiceAvailable;
+       bool __isRoaming;
+
     static TelephonyService* __pTelephonyService;
+
+       friend class std::default_delete<TelephonyService>;
 };
 
 #endif // _WIFI_SERVICE_H_
old mode 100644 (file)
new mode 100755 (executable)
index b5c39f7..5698835
 #ifndef _WIFI_CONNECTIVITY_IPC_STUB_H_
 #define _WIFI_CONNECTIVITY_IPC_STUB_H_
 
+#include <unique_ptr.h>
 #include <FBaseObject.h>
 #include <FIo_IIpcServerEventListener.h>
 
 namespace Tizen { namespace Base {
 class String;
+
+namespace Collection {
+template<typename T>
+class ArrayListT;
+
+}
+
 } }
 
 namespace Tizen { namespace Io {
 class _IpcServer;
 } }
 
-namespace Tizen { namespace Net { namespace Wifi {
+namespace Tizen { namespace Net {
+
+class NetAccountInfo;
+
+namespace Wifi {
 class WifiBssInfo;
+class _WifiNetAccountInfoImpl;
 } } }
 
 class WifiService;
+class WifiDirectService;
 class WifiProximityService;
 
 /**
@@ -60,6 +74,17 @@ public:
        virtual ~WifiConnectivityIpcStub(void);
        result Construct(void);
 
+       // Wifi
+       result SendWifiActivated(int clientId, unsigned long res);
+       result SendWifiDeactivated(int clientId, unsigned long res);
+       result SendWifiScanCompleted(int clientId, Tizen::Base::Collection::ArrayListT<Tizen::Net::Wifi::WifiBssInfo*>* pBssInfoList, unsigned long res);
+       result SendWifiConnected(int clientId, const Tizen::Base::String& ssid, unsigned long res);
+       result SendWifiDisconnected(int clientId);
+       result SendWifiRssiChanged(int clientId, long rssi);
+       result SendWifiConnectionStateChanged(int clientId, int state);
+       result SendWifiSystemScanResultUpdated(int clientId);
+
+       // WifiProximity
     result SendProximityCheckActivated(int clientId);
     result SendProximityCheckDeactivated(int clientId);
     result SendWifiBssDetected(int clientId, const Tizen::Net::Wifi::WifiBssInfo& wifiBssInfo);
@@ -77,12 +102,31 @@ private:
        WifiConnectivityIpcStub& operator =(const WifiConnectivityIpcStub& rhs);
 
        // Wifi
+       void OnRegisterManagerEventCallback(unsigned long* pResult);
+       void OnUnregisterManagerEventCallback(unsigned long* pResult);
+       void OnActivateWifi(unsigned long* pResult);
+       void OnDeactivateWifi(unsigned long* pResult);
+       void OnScanWifi(unsigned long* pResult);
+       void OnConnectWifi(const Tizen::Net::Wifi::WifiBssInfo& bssInfo, unsigned long* pResult);
+       void OnGetWifiConnectionTargetInfo(Tizen::Net::Wifi::WifiBssInfo* pBssInfo, unsigned long* pResult);
+       void OnGetWifiNetAccountInfo(Tizen::Net::NetAccountInfo* pNetAccountInfo,
+                       Tizen::Net::Wifi::_WifiNetAccountInfoImpl* pWifiNetAccountInfoImpl, unsigned long* pResult);
+       void OnGetWifiSystemScanResult(Tizen::Base::Collection::ArrayListT<Tizen::Net::Wifi::WifiBssInfo*>* pBssInfoList,
+                       unsigned long* pResult);
+       void OnGetWifiMacAddress(Tizen::Base::String* pMacAddress, unsigned long* pResult);
+       void OnIsWifiActivated(bool* pIsActivated, unsigned long* pResult);
+       void OnIsWifiConnected(bool* pIsConnected, unsigned long* pResult);
+       void OnGetWifiConnectionState(int* pState, unsigned long* pResult);
+
+       void OnRegisterSystemMonitoringCallback(unsigned long* pResult);
+       void OnUnregisterSystemMonitoringCallback(unsigned long* pResult);
        void OnSetWifiSystemScanMode(int mode, unsigned long* pResult);
-       void OnCheckWifiSystemSettingPrivilege(unsigned long* pResult);
        void OnUpdateWifiBssInfo(const Tizen::Net::Wifi::WifiBssInfo& bssInfo, unsigned long* pResult);
+
+       // Wifi Direct
        void OnInitializeWifiDirect(unsigned long* pResult);
        void OnGetWifiDirectLocalDeviceName(Tizen::Base::String* pLocalName, unsigned long* pResult);
-       void OnSetWifiDirectLocalDeviceName(Tizen::Base::String localName, unsigned long* pResult);
+       void OnSetWifiDirectLocalDeviceName(const Tizen::Base::String& localName, unsigned long* pResult);
 
        // WifiProximity
        void OnRegisterBssId(const Tizen::Base::String& bssId, unsigned long* pResult);
@@ -92,10 +136,11 @@ private:
        void OnIsProximityCheckActivated(bool* pIsActivated, unsigned long* pResult);
 
 private:
-       WifiProximityService* __pWifiProximityService;
-       WifiService* __pWifiService;
-       Tizen::Io::_IpcServer* __pIpcServer;
-
+       std::unique_ptr<Tizen::Io::_IpcServer> __pIpcServer;
+       std::unique_ptr<WifiService> __pWifiService;
+       std::unique_ptr<WifiDirectService> __pWifiDirectService;
+       std::unique_ptr<WifiProximityService> __pWifiProximityService;
 };
 
 #endif // _WIFI_CONNECTIVITY_IPC_STUB_H_
+
diff --git a/inc/WifiDirectService.h b/inc/WifiDirectService.h
new file mode 100755 (executable)
index 0000000..520ad6c
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file       WifiDirectService.h
+ * @brief      This is the header file for the %WifiDirectService class.
+ *
+ * This header file contains the declarations of the %WifiDirectService class.
+ */
+
+#ifndef _WIFI_DIRECT_SERVICE_H_
+#define _WIFI_DIRECT_SERVICE_H_
+
+#include <FBaseString.h>
+#include <FBaseRtMutex.h>
+#include <FBaseColLinkedListT.h>
+#include <wifi-direct.h>
+
+class WifiConnectivityIpcStub;
+
+/**
+ * @class      WifiDirectService
+ * @brief      This class represents Wi-Fi Direct service of the Connectivity service daemon.
+ *
+ * This class represents Wi-Fi Direct service of the Connectivity service daemon.
+ */
+class WifiDirectService
+{
+public:
+       WifiDirectService(void);
+       virtual ~WifiDirectService(void);
+       result Construct(WifiConnectivityIpcStub& stub);
+
+       result InitializeWifiDirect(const Tizen::Base::String& clientPkgId);
+       result GetWifiDirectLocalDeviceName(Tizen::Base::String* pLocalName);
+       result SetWifiDirectLocalDeviceName(const Tizen::Base::String& clientPkgId, const Tizen::Base::String& localName);
+
+       // Process application termination cases such that an IPC client is disconnected.
+       void ProcessAppTermination(const Tizen::Base::String& clientPkgId);
+       // Callback used by SLP Wi-Fi Direct F/W to notify that Wi-Fi Direct is activated on the device.
+       void OnWifiDirectActivated(void);
+private:
+       result UpdateWifiDirectLocalDeviceName(const Tizen::Base::String& name);
+       bool IsWifiDirectActivated(void) const;
+
+       static void WifiDirectDeviceStateChangedCallbackFunction(int error_code, wifi_direct_device_state_e device_state,
+                                                                                                                               void* user_data);
+
+private:
+       Tizen::Base::String __newWifiDirectName;
+       Tizen::Base::String __wifiDirectNameChangerId;
+       Tizen::Base::Runtime::Mutex __listMutex;
+       Tizen::Base::Collection::LinkedListT<Tizen::Base::String> __appPkgIdList;
+
+       WifiConnectivityIpcStub* __pStub;
+};
+
+#endif // _WIFI_DIRECT_SERVICE_H_
old mode 100644 (file)
new mode 100755 (executable)
index 5a4eb86..cc66a6a
@@ -39,6 +39,7 @@ class String;
 } }
 
 class ConnectivityIpcStub;
+class WifiSystemAdapter;
 
 class WifiProximityService
        : public Tizen::Base::Object
@@ -48,31 +49,31 @@ class WifiProximityService
 public:
        WifiProximityService(void);
        virtual ~WifiProximityService(void);
-       result Construct(WifiConnectivityIpcStub* pStub);
+       result Construct(WifiConnectivityIpcStub& stub);
 
-       result RegisterBssId(const Tizen::Base::String& macAddress, const int clientId);
-       result UnregisterBssId(const Tizen::Base::String& macAddress, const int clientId);
+       result RegisterBssId(const Tizen::Base::String& bssId, const int clientId);
+       result UnregisterBssId(const Tizen::Base::String& bssId, const int clientId);
        result UnregisterClient(const int clientId);
        result ActivateProximityCheck(void);
        result DeactivateProximityCheck(void);
        bool IsProximityCheckActivated(void) const;
 
-       // from ITimerEventListener
-       virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
+    // from ITimerEventListener
+    virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
 
-       // from IWifiProximityServiceEventListener
-       virtual void OnWifiProximityActivated(void);
+    // from IWifiProximityServiceEventListener
+    virtual void OnWifiProximityActivated(void);
     virtual void OnWifiProximityDeactivated(void);
 
-    // callback methods that the underlying system defines
-       static void OnWifiDeviceStateChanged(wifi_device_state_e state, void* pUserData);
-       static void OnWifiScanCompleted(wifi_error_e error_code, void* pUserData);
-       static bool OnWifiEachAccessPointFound(wifi_ap_h apHandler, void* pUserData);
+    // from WIfiSysetmAdapter
+    void OnWifiActivated();
+    void OnWifiDeactivated();
+    void OnWifiScanCompleted(const Tizen::Base::Collection::LinkedList* pWifiBssInfoList, result r);
 
 private:
        result ScanAndResetTimer(void);
        result ResetTimer(void);
-       void CheckingProximityStatusChanged(void);
+       void CheckingProximityStatusChanged(const Tizen::Base::Collection::LinkedList* pWifiBssInfoList);
 
 private:
        Tizen::Base::Collection::HashMapT<int, bool> __clientStateMap;
@@ -85,6 +86,8 @@ private:
        bool __isWifiActivated;
        bool __isProximityCheckActivated;
        bool __isTimerOn;
+
+       WifiSystemAdapter* __pWifiSystemAdapter;
 };
 
 #endif // _WIFI_PROXIMITY_SERVICE_H_
old mode 100644 (file)
new mode 100755 (executable)
index e4300e3..ea6d63c
 #include <FBaseRtMutex.h>
 #include <FBaseColLinkedListT.h>
 
-namespace Tizen { namespace Net { namespace Wifi {
+namespace Tizen { namespace Net {
+
+class NetAccountInfo;
+
+namespace Wifi {
 class WifiBssInfo;
+class _WifiNetAccountInfoImpl;
 } } }
 
+
+class WifiConnectivityIpcStub;
+class WifiSystemAdapter;
+
 /**
  * @class      WifiService
  * @brief      This class represents Wi-Fi service of the Connectivity service daemon.
@@ -45,35 +54,45 @@ class WifiBssInfo;
 class WifiService
 {
 public:
-       WifiService(void);
-       virtual ~WifiService(void);
-       result Construct(void);
+    WifiService(void);
+    virtual ~WifiService(void);
+    result Construct(WifiConnectivityIpcStub& stub);
 
-       result SetWifiSystemScanMode(int mode);
-       result UpdateWifiBssInfo(const Tizen::Net::Wifi::WifiBssInfo& bssInfo);
-       result Initialize(const Tizen::Base::String& clientPkgId);
-       result GetWifiDirectLocalDeviceName(Tizen::Base::String* pLocalName);
-       result SetWifiDirectLocalDeviceName(const Tizen::Base::String& clientPkgId, const Tizen::Base::String& localName);
+    result RegisterManagerClientId(int clientId);
+    result UnregisterManagerClientId(int clientId);
+    result WifiActivate(int clientId);
+    result WifiDeactivate(int clientId);
+    result WifiScan(int clientId);
+    result WifiConnect(int clientId, const Tizen::Net::Wifi::WifiBssInfo& bssInfo);
+    result GetWifiConnectionTargetInfo(Tizen::Net::Wifi::WifiBssInfo* pBssInfo) const;
+    result GetWifiNetAccountInfo(Tizen::Net::NetAccountInfo* pNetAccountInfo,
+            Tizen::Net::Wifi::_WifiNetAccountInfoImpl* pWifiNetAccountInfoImpl) const;
+    result GetWifiSystemScanResultN(Tizen::Base::Collection::ArrayListT<Tizen::Net::Wifi::WifiBssInfo*>* pBssInfoList) const;
+    result UpdateWifiBssInfo(const Tizen::Net::Wifi::WifiBssInfo& bssInfo);
+    result GetWifiMacAddress(Tizen::Base::String* pMacAddress);
+    result IsWifiActivated(bool& isActivated);
+    result IsWifiConnected(bool& isConnected);
+    result GetWifiConnectionState(int& connectionState);
 
-       // Process application termination cases such that an IPC client is disconnected.
-       void ProcessAppTermination(const Tizen::Base::String& clientPkgId);
+    result RegisterMonitoringClientId(int clientId);
+    result UnregisterMonitoringClientId(int clientId);
+    result SetWifiSystemScanMode(int mode);
 
-       // Callback used by SLP Wi-Fi Direct F/W to notify that Wi-Fi Direct is activated on the device.
-       void OnWifiDirectActivated(void);
-
-    static bool OnWifiEachAccessPointFound(wifi_ap_h apHandle, void* pUserData);
-
-private:
-       result UpdateWifiDirectLocalDeviceName(const Tizen::Base::String& name);
-       bool IsWifiDirectActivated(void) const;
-       wifi_ap_h GetApHandle(const Tizen::Base::String& bssId);
+    void OnWifiActivated(int clientId, result r);
+    void OnWifiDeactivated(int clientId, result r);
+    void OnWifiConnected(int clientId, const Tizen::Base::String ssid, result r);
+    void OnWifiScanCompleted(int clientId, Tizen::Base::Collection::IList* pWifiBssInfoList, result r);
+    void OnWifiDisconnected();
+    void OnWifiConnectionStateChanged(Tizen::Net::Wifi::WifiConnectionState state);
+    void OnWifiRssiLevelChanged(long rssi);
+    void OnWifiBackgroundScanResultUpdated();
 
 private:
-       Tizen::Base::String __newWifiDirectName;
-       Tizen::Base::String __wifiDirectNameChangerId;
        Tizen::Base::Runtime::Mutex __listMutex;
-       Tizen::Base::Collection::LinkedListT<Tizen::Base::String> __appPkgIdList;
-
+       Tizen::Base::Collection::ArrayListT<int> __managerClientIdList;
+       Tizen::Base::Collection::ArrayListT<int> __monitorClientIdList;
+       WifiConnectivityIpcStub* __pStub;
+       WifiSystemAdapter* __pWifiSystemAdapter;
 };
 
 #endif // _WIFI_SERVICE_H_
diff --git a/inc/WifiSystemAdapter.h b/inc/WifiSystemAdapter.h
new file mode 100755 (executable)
index 0000000..a2166da
--- /dev/null
@@ -0,0 +1,333 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+/**
+ * @file    WifiSystemAdapter.h
+ * @brief   This is the header file for the _WifiSystemAdapter class.
+ *
+ * This header file contains declarations of the _WifiSystemAdapter class.
+ */
+#ifndef _WIFI_SYSTEM_ADAPTER_H_
+#define _WIFI_SYSTEM_ADAPTER_H_
+
+#include <unique_ptr.h>
+#include <wifi.h>
+#include <FOspConfig.h>
+#include <FBaseObject.h>
+#include <FBaseColLinkedList.h>
+#include <FNetWifiWifiTypes.h>
+
+namespace Tizen { namespace Net {
+
+class NetAccountInfo;
+
+namespace Wifi {
+
+class WifiBssInfo;
+class _WifiNetAccountInfoImpl;
+} } }
+
+class WifiService;
+class WifiProximityService;
+
+class WifiSystemAdapter
+{
+
+public:
+       /**
+     * Sets the WifiService for receiving Wi-Fi related events.
+     *
+     * @param[in]   pWifiService       A pointer of WifiService instance.
+     *                                                                 The parameter can be set to null to remove the WifiService.
+     */
+       void SetWifiService(WifiService* pWifiService);
+
+       /**
+        * Sets the WifiService for receiving Wi-Fi related events.
+        *
+        * @param[in]   pWifiService    A pointer of WifiService instance.
+        *                                                              The parameter can be set to null to remove the WifiService.
+        */
+       void SetProximityService(WifiProximityService* pProximityService);
+
+    /**
+     * Activates the local Wifi device.
+     *
+     * @return      An error code
+     * @exception   E_SUCCESS           The activation was successful.
+     * @exception   E_FAILURE           Failed to activate.
+     * @exception   E_SYSTEM            A system error occurred.
+     */
+    result Activate(int clientId);
+
+    /**
+     * Deactivates the local Wifi device.
+     *
+     * @return      An error code
+     * @exception   E_SUCCESS           The deactivation was successful.
+     * @exception   E_FAILURE           Failed to deactivate.
+     * @exception   E_SYSTEM            A system error occurred.
+     */
+    result Deactivate(int clientId);
+
+    /**
+     * Gets the MAC address of the Wifi device.
+     * @return      The MAC address in the form '00-00-00-00-00-00'
+     */
+    Tizen::Base::String GetMacAddress(void) const;
+
+    /**
+     * Checks whether the local device is activated.
+     * @return      @c true, if the local device is activated @n
+     *              @c false, otherwise
+     */
+    bool IsActivated(void) const;
+
+    /**
+     * Checks whether the local device is connected with a remote STA.
+     * @return      @c true, if the local device is connected with a remote STA @n
+     *              @c false, otherwise
+     */
+    bool IsConnected(void) const;
+
+    /**
+     * Checks whether the local device is already connected with a specific remote STA.
+     *
+     * @return      @c true, if the local device is already connected with a specific remote STA @n
+     *              @c false, otherwise
+     * @param[in]   pApHandle        a handle of access point
+     *
+     */
+    bool IsConnected(wifi_ap_h pApHandle) const;
+
+    /**
+     * Requests a scan for nearby BSS with both infrastructure and independent mode.
+     *
+     * @return      An error code
+     * @exception   E_SUCCESS           The method was successful.
+     * @exception   E_FAILURE           The method failed.
+     * @remarks     Only active scan - i.e. probing for APs in the range - is supported.
+     * @see         IWifiManagerEventListener::OnWifiScanCompleted()
+     */
+    result Scan(int clientId);
+
+
+    result ScanforProximity(void);
+
+    /**
+     * Establishes a connection to a specific access point - only BSS with infrastructure mode.
+     *
+     * @return      An error code
+     * @param[in]   targetApInfo        A BSS information that represents target access point.
+     * @exception   E_SUCCESS           The method was successful.
+     * @exception   E_FAILURE           The method failed.
+     * @exception   E_INVALID_ARG       A specified input parameter is invalid. E.g. BSS type is independent mode.
+     * @remarks     If a connection to other access point is already established, it will be disconnected and the new connection
+     *              of this method will be established.
+     * @see         IWifiManagerEventListener::OnWifiConnected()
+     */
+    result Connect(int clientId, const Tizen::Net::Wifi::WifiBssInfo& targetApInfo);
+
+    /**
+     * Gets the state of current Wi-Fi connection.
+     *
+     * @return      The state of the current Wi-Fi connection
+     */
+    Tizen::Net::Wifi::WifiConnectionState GetConnectionState(void) const;
+
+    /**
+     * Gets the information of current Wi-Fi connection target which the local device is connecting or connected with.
+     *
+     * @param[out]  pBssInfo        A BSS information that represents target access point
+     * @return      An error code
+     */
+    result GetConnectionTargetInfo(Tizen::Net::Wifi::WifiBssInfo* pBssInfo) const;
+
+    /**
+     * Gets the information on a wifi network account.
+     *
+     * @param[out]  pNetAccountInfo    A NetAccountInfo instance containing account information
+     * @param[out]  pWifiNetAccountInfoImpl    A WifiNetAccountInfo instance containing Wi-Fi account information
+     * @return      An error code
+     */
+    result GetWifiNetAccountInfo(Tizen::Net::NetAccountInfo* pNetAccountInfo,
+               Tizen::Net::Wifi::_WifiNetAccountInfoImpl* pWifiNetAccountInfoImpl) const;
+
+    /**
+     * Gets a list of the latest search results which the underlying Wi-Fi system scan periodically on background.
+     *
+     * @return      An IList containing WifiBssInfo of existing Wi-Fi connections if successful, @n
+     *              else @c null
+     */
+    Tizen::Base::Collection::IList* GetSystemScanResult(void);
+
+    /**
+        * Sets the behavior mode of the Wi-Fi background system about connection and background scanning.
+        *
+        * @return      An error code
+        * @param[in]   mode                A Wi-Fi background system mode
+        * @exception   E_SUCCESS           The method is successful.
+        * @exception   E_OPERATION_FAILED  The operation has failed.
+        */
+    result SetWifiSystemScanMode(int mode);
+
+    /**
+     * Updates the Wi-Fi BSS information which is saved in the underlying Wi-Fi system.
+     * @param[in]   bssInfo    A BSS information representing the access point
+     * @return      An error code
+     *
+     * @exception   E_SUCCESS           The method is successful.
+        * @exception   E_OPERATION_FAILED  The operation has failed.
+     */
+    result UpdateWifiBssInfo(const Tizen::Net::Wifi::WifiBssInfo& bssInfo);
+
+    /**
+     * Called when the device state is changed.
+     *
+     * @param[in]   state               Device status
+     * @param[in]   pUserData           The user data passed from the callback registration function
+     */
+    static void OnWifiDeviceStateChanged(wifi_device_state_e state, void* pUserData);
+
+    /**
+     * Called when the connection state is changed.
+     *
+     * @param[in]   state               Connection status
+     * @param[in]   pApHandle           A handle of access point
+     * @param[in]   pUserData           The user data passed from the callback registration function
+     */
+    static void OnWifiConnectionStateChanged(wifi_connection_state_e state, wifi_ap_h pApHandle, void* pUserData);
+    
+    /**
+     * Called when each access point is found.
+     *
+     * @param[in]   pApHandle          A handle of access point
+     * @param[in]   pUserData          The user data passed from the callback registration function
+     */
+    static bool OnWifiEachAccessPointFound(wifi_ap_h pApHandle, void* pUserData);
+
+    /**
+     * Called when each access point is checked.
+     *
+     * @param[in]   pApHandle           A handle of access point
+     * @param[in]   pUserData           The user data passed from the callback registration function
+     */
+    static bool OnWifiEachAccessPointChecked(wifi_ap_h pApHandle, void* pUserData);
+
+    /**
+     * Called when Wifi is activated.
+     *
+     * @param[in]   errorCode           Error code
+     * @param[in]   pUserData           The user data passed from the callback registration function
+     */
+    static void OnWifiActivated(wifi_error_e errorCode, void* pUserData);
+
+    /**
+     * Called when Wifi is dectivated.
+     *
+     * @param[in]   errorCode           Error code
+     * @param[in]   pUserData           The user data passed from the callback registration function
+     */
+    static void OnWifiDeactivated(wifi_error_e errorCode, void* pUserData);
+
+    /**
+     * Called when the local device is connected with Wifi access point.
+     *
+     * @param[in]   errorCode           Error code
+     * @param[in]   pUserData           The user data passed from the callback registration function
+     */
+    static void OnWifiConnected(wifi_error_e errorCode, void* pUserData);
+
+    /**
+     * Called when the scan process is completed.
+     *
+     * @param[in]   errorCode           Error code
+     * @param[in]   pUserData           The user data passed from the callback registration function
+     */
+    static void OnWifiScanCompleted(wifi_error_e errorCode, void* pUserData);
+    
+    /**
+     * Called when the rssi value is changed.
+     *
+     * @param[in]   rssiLevel           Rssi level
+     * @param[in]   pUserData           The user data passed from the callback registration function
+     */
+    static void OnWifiRssiLevelChanged(wifi_rssi_level_e rssiLevel, void* pUserData);
+
+    /**
+     * Called when the background scan result is updated.
+     *
+     * @param[in]   errorCode           Error code
+     * @param[in]   pUserData           The user data passed from the callback registration function
+     */
+    static void OnWifiBackgroundScanResultUpdated(wifi_error_e errorCode, void* pUserData);
+
+    /**
+     * Get the singleton insatnce of WifiSystemAdapter.
+     *
+     * @return      The pointer to WifiSystemAdapter
+     */
+    static WifiSystemAdapter* GetInstance(void);
+
+private:
+    /**
+     * This default constructor is intentionally declared as private to implement the Singleton semantic.
+     *
+     * @remarks     After creating an instance of this class, you must explicitly call
+     *              the construction method to initialize the instance.
+     * @see Construct()
+     */
+    WifiSystemAdapter(void);
+
+    /**
+     * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
+     *
+     * @param[in]   rhs                 An instance of %WifiSystemAdapter
+     */
+    WifiSystemAdapter(const WifiSystemAdapter& rhs);
+
+    /**
+     * This destructor is intentionally declared as private to implement the Singleton semantic.
+     *
+     */
+    virtual ~WifiSystemAdapter(void);
+
+    /**
+     * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
+     *
+     * @param[in] rhs An instance of %WifiSystemAdapter
+     */
+    WifiSystemAdapter& operator=(const WifiSystemAdapter& rhs);
+
+    result Construct();
+       static void InitSingleton(void);
+       static void DestroySingleton(void);
+    static const char* GetStringOfConnectionState(wifi_connection_state_e state);
+
+    wifi_ap_h GetApHandle(const Tizen::Base::String& bssId);
+
+private:
+    wifi_connection_state_e __prevconnState;
+    WifiService* __pWifiService;
+    WifiProximityService* __pWifiProximityService;
+    Tizen::Base::Collection::LinkedList __scanResultList;
+
+
+    friend class std::default_delete<WifiSystemAdapter>;
+
+}; // WifiSystemAdapter
+
+#endif // _WIFI_SYSTEM_ADAPTER_H_
old mode 100644 (file)
new mode 100755 (executable)
index bce4bf8..810d771
@@ -6,6 +6,7 @@
                <domain name="57r43275q7"/>
        </request>
        <assign>
+               <filesystem path="/opt/dbspace/.net-nfcpush.db*" label="57r43275q7::db"/>
                <filesystem path="/usr/share/license/osp-connectivity-service" label="_"/>
        </assign>
 </manifest>
\ No newline at end of file
index 2d8f1ed..7a34132 100755 (executable)
@@ -1,63 +1,86 @@
-Name:           osp-connectivity-service
-Version:        1.2.1.0
-Release:        2
-License:        Apache-2.0 or Flora
-Summary:        OSP Connectivity Service
-Group:          Telephony/Libraries
-Source0:        %{name}-%{version}.tar.gz
+Name:          osp-connectivity-service
+Summary:       osp connectivity service
+Version:       1.2.2.0
+Release:       2
+Group:         TO_BE/FILLED_IN
+License:       Apache-2.0, Flora-1.1
+Source0:       %{name}-%{version}.tar.gz
 BuildRequires:  cmake
-BuildRequires:  osp-bluetooth-internal-devel
-BuildRequires:  osp-net-internal-devel
-BuildRequires:  osp-nfc-internal-devel
-BuildRequires:  osp-telephony-devel
-BuildRequires:  osp-telephony-internal-devel
-BuildRequires:  pkgconfig(capi-appfw-app-manager)
+BuildRequires:  pkgconfig(chromium)
+BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(capi-telephony-sim)
+BuildRequires:  pkgconfig(capi-telephony-network-info)
+BuildRequires:  pkgconfig(wifi-direct)
+BuildRequires:  pkgconfig(capi-network-wifi)
+BuildRequires:  pkgconfig(capi-network-nfc)
 BuildRequires:  pkgconfig(capi-network-bluetooth)
 BuildRequires:  pkgconfig(capi-network-connection)
-BuildRequires:  pkgconfig(capi-network-nfc)
-BuildRequires:  pkgconfig(capi-network-wifi)
-BuildRequires:  pkgconfig(capi-system-device)
 BuildRequires:  pkgconfig(capi-system-info)
-BuildRequires:  pkgconfig(capi-telephony-sim)
-BuildRequires:  pkgconfig(chromium)
-BuildRequires:  pkgconfig(ecore)
-BuildRequires:  pkgconfig(evas)
-BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(capi-system-device)
 BuildRequires:  pkgconfig(osp-appfw)
-BuildRequires:  pkgconfig(osp-bluetooth)
+BuildRequires:  osp-appfw-internal-devel
 BuildRequires:  pkgconfig(osp-net)
+BuildRequires:  osp-net-internal-devel
 BuildRequires:  pkgconfig(osp-nfc)
+BuildRequires:  osp-nfc-internal-devel
+BuildRequires:  pkgconfig(osp-bluetooth)
+BuildRequires:  osp-bluetooth-internal-devel
 BuildRequires:  pkgconfig(osp-telephony)
-BuildRequires:  pkgconfig(pkgmgr)
-BuildRequires:  pkgconfig(tapi)
+BuildRequires:  osp-telephony-devel
+BuildRequires:  osp-telephony-internal-devel
 BuildRequires:  pkgconfig(vconf)
-BuildRequires:  pkgconfig(wifi-direct)
-BuildRequires:  pkgconfig(osp-appfw-server)
-BuildRequires:  pkgconfig(appinfo)
-Requires:       osp-app-service
-Requires:       osp-appfw
-Requires:       osp-channel-service
-Requires:       osp-installer
+BuildRequires:  pkgconfig(tapi)
+BuildRequires:  pkgconfig(pkgmgr)
+BuildRequires:  pkgconfig(evas)
+BuildRequires:  pkgconfig(ecore)
+BuildRequires:  pkgconfig(ecore-x)
+BuildRequires:  pkgconfig(capi-appfw-app-manager)
+BuildRequires:  pkgconfig(sqlite3)
+BuildRequires:  hash-signer
+
+# runtime requires
+Requires: osp-appfw 
+Requires: osp-installer 
+Requires: osp-app-service
+Requires: osp-channel-service
+Requires: capi-network-connection
+Requires: capi-network-wifi
 
 %description
-OSP Connectivity Service
+osp connectivity service
 
 %prep
 %setup -q
 
-%build
+%build 
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %ifarch %{ix86}
-CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_SECURE_LOG -D_OSP_X86_ -D_OSP_EMUL_" %cmake .
+%if 0%{?simulator}
+CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_SECURE_LOG -D_OSP_X86_ -D_OSP_EMUL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
 %else
-CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_SECURE_LOG -D_OSP_ARMEL_" %cmake .
+CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_SECURE_LOG -D_OSP_X86_ " cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+%endif
+%else
+CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_SECURE_LOG -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
 %endif
 
 # Call make instruction with smp support
-make %{?_smp_mflags}
+make %{?jobs:-j%jobs}
 
 %install
+rm -rf %{buildroot}
+mkdir -p %{buildroot}/usr/share/license
+cp %{_builddir}/%{name}-%{version}/LICENSE.Flora  %{buildroot}/usr/share/license/%{name}
+cat %{_builddir}/%{name}-%{version}/LICENSE.APLv2.0 >> %{buildroot}/usr/share/license/%{name}
+mkdir -p %{buildroot}/opt/dbspace/
+sqlite3 %{buildroot}/opt/dbspace/.net-nfcpush.db "CREATE TABLE IF NOT EXISTS NfcPushMsgTable ( AppId TEXT PRIMARY KEY, PkgName TEXT, IconPath TEXT, MsgDesc TEXT )"
+
 %make_install
+%define tizen_sign 1
+%define tizen_sign_base /usr/apps/57r43275q7
+%define tizen_sign_level platform
+%define tizen_author_sign 1
+%define tizen_dist_sign 1
 
 %post
 mkdir -p /opt/usr/share/nfcpush
@@ -66,10 +89,11 @@ mkdir -p /opt/usr/share/nfcpush
 
 /usr/etc/package-manager/backend/tpk -i /usr/apps/57r43275q7
 
+#%postun -p /sbin/ldconfig
 
 %files
 %manifest osp-connectivity-service.manifest
-%license LICENSE.APLv2.0  LICENSE.Flora
-%{_prefix}/apps/57r43275q7/bin/osp-connectivity-service.exe
-%{_prefix}/apps/57r43275q7/data/.readme
-%{_prefix}/apps/57r43275q7/info/manifest.xml
+/usr/share/license/%{name}
+/usr/apps/*
+%attr(660,root,app) /opt/dbspace/.net-nfcpush.db
+%attr(660,root,app) /opt/dbspace/.net-nfcpush.db-journal
old mode 100644 (file)
new mode 100755 (executable)
index 6477170..062f09d
@@ -152,8 +152,8 @@ BluetoothService::SetDiscoverableMode(int mode, int seconds)
        // Updates the local name instantly if the Bluetooth is turned on.
        // Saves the setting name for the later use, otherwise.
        ret = bt_adapter_get_state(&adapter_state);
-       SysTryReturnResult(NID_NET_BT, (ret == BT_ERROR_NONE && adapter_state == BT_ADAPTER_ENABLED), E_SYSTEM,
-                       "Setting the discoverable mode of Bluetooth has failed");
+       SysTryReturnResult(NID_NET_BT, ret == BT_ERROR_NONE, E_SYSTEM, "Setting the discoverable mode of Bluetooth has failed");
+       SysTryReturnResult(NID_NET_BT, adapter_state == BT_ADAPTER_ENABLED, E_INVALID_OPERATION, "Bluetooth is not activated");
 
        ret = bt_adapter_set_visibility(discoverable_mode, seconds);
        SysTryReturnResult(NID_NET_BT, ret == BT_ERROR_NONE, E_SYSTEM,  "Setting the discoverable mode of Bluetooth has failed");
diff --git a/src/ConnectivityUtility.cpp b/src/ConnectivityUtility.cpp
new file mode 100755 (executable)
index 0000000..059b0e7
--- /dev/null
@@ -0,0 +1,796 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+/**
+ * @file               ConnectivityUtility.cpp
+ * @brief              This is the implementation file for %ConnectivityUtility class.
+ *
+ * This file contains the implementation of %ConnectivityUtility class.
+ */
+
+#include <pthread.h>
+#include <unique_ptr.h>
+#include <FBaseResult.h>
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FBaseSysLog.h>
+#include <FNetNetAccountInfo.h>
+#include <FNetNetConnectionInfo.h>
+#include <FBase_StringConverter.h>
+#include <FNet_NetAccountInfoImpl.h>
+#include <FNet_NetConnectionInfoImpl.h>
+#include <FNetWifi_WifiNetAccountInfoImpl.h>
+#include <FNetWifi_WifiSecurityInfoImpl.h>
+#include <FNetWifi_WifiUtility.h>
+#include <FNet_NetTypes.h>
+#include "ConnectivityUtility.h"
+#include "NetAccountDatabase.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Net;
+using namespace Tizen::Net::Wifi;
+
+ConnectivityUtility::ConnectivityUtility(void)
+{
+}
+
+ConnectivityUtility::~ConnectivityUtility(void)
+{
+}
+
+void
+ConnectivityUtility::UpdateNetConnectionInfo(NetConnectionInfo* pInfo, connection_profile_h profileHandle, bool isDefault)
+{
+       SysTryReturnVoidResult(NID_NET, pInfo != null, E_INVALID_ARG, "[E_INVALID_ARG] NetConnectionInfo is NULL.");
+
+       _NetConnectionInfoImpl* pImpl = _NetConnectionInfoImpl::GetInstance(*pInfo);
+       SysTryReturnVoidResult(NID_NET, pImpl != null, E_INVALID_ARG, "[E_INVALID_ARG] NetConnectionInfo is not constructed.");
+
+       NetBearerType bearerType = NET_BEARER_NONE;
+       NetProtocolType protocolType = NET_PROTO_TYPE_NONE;
+       String apn;
+       String deviceName;
+       String proxyAddress;
+       NetAddressScheme localAddressScheme = NET_ADDRESS_SCHEME_NONE;
+       NetAddressScheme dnsAddressScheme = NET_ADDRESS_SCHEME_NONE;
+
+       int ret = CONNECTION_ERROR_NONE;
+       connection_profile_type_e type = CONNECTION_PROFILE_TYPE_WIFI;
+
+       SysLog(NID_NET, "UpdateNetConnectionInfo() has been called with isDefault:%d", isDefault);
+
+       pImpl->Clear();
+
+       if (profileHandle == null)
+       {
+               return;
+       }
+
+       ret = connection_profile_get_type(profileHandle, &type);
+       SysLog(NID_NET, "The return value from connection_profile_get_type() is %d. Network type is %d", ret, type);
+
+       if (type == CONNECTION_PROFILE_TYPE_WIFI)
+       {
+               SysLog(NID_NET, "Profile type is Wi-Fi.");
+               bearerType = NET_BEARER_WIFI;
+       }
+       else if (type == CONNECTION_PROFILE_TYPE_CELLULAR)
+       {
+               SysLog(NID_NET, "Profile type is Cellular.");
+
+               char* pApn = null;
+               ret = connection_profile_get_cellular_apn(profileHandle, &pApn);
+               if ((ret == CONNECTION_ERROR_NONE) && (pApn != null))
+               {
+                       apn = String(pApn);
+                       free(pApn);
+               }
+
+               bearerType = NET_BEARER_PS;
+       }
+       else
+       {
+               // CONNECTION_PROFILE_TYPE_ETHERNET (For emulator: Treat ethernet as cellular.)
+               SysLog(NID_NET, "Profile type is Ethernet.");
+               bearerType = NET_BEARER_PS;
+       }
+
+       protocolType = NET_PROTO_TYPE_IPV4;
+
+       connection_ip_config_type_e ipConfigType = CONNECTION_IP_CONFIG_TYPE_NONE;
+       ret = connection_profile_get_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &ipConfigType);
+       SysTryReturnVoidResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                       "[%s] A system error has been occurred. The return value from connection_profile_get_ip_config_type() is %d",
+                       GetErrorMessage(E_SYSTEM), ret);
+
+       if ((ipConfigType == CONNECTION_IP_CONFIG_TYPE_STATIC) || (ipConfigType == CONNECTION_IP_CONFIG_TYPE_FIXED))
+       {
+               localAddressScheme = NET_ADDRESS_SCHEME_STATIC;
+               dnsAddressScheme = NET_ADDRESS_SCHEME_STATIC;
+       }
+       else
+       {
+               localAddressScheme = NET_ADDRESS_SCHEME_DYNAMIC;
+               dnsAddressScheme = NET_ADDRESS_SCHEME_DYNAMIC;
+       }
+
+       char* pIpAddr = null;
+       String ipAddr;
+
+       ret = connection_profile_get_ip_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
+       if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
+       {
+               ipAddr = String(pIpAddr);
+               free(pIpAddr);
+               pIpAddr = null;
+
+               pImpl->SetLocalAddress(ipAddr);
+       }
+
+       ret = connection_profile_get_subnet_mask(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
+       if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
+       {
+               ipAddr = String(pIpAddr);
+               free(pIpAddr);
+               pIpAddr = null;
+
+               pImpl->SetSubnetMaskAddress(ipAddr);
+       }
+
+       ret = connection_profile_get_gateway_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
+       {
+               ipAddr = String(pIpAddr);
+               free(pIpAddr);
+               pIpAddr = null;
+
+               pImpl->SetDefaultGatewayAddress(ipAddr);
+       }
+
+       ret = connection_profile_get_dns_address(profileHandle, 1, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
+       if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
+       {
+               ipAddr = String(pIpAddr);
+               free(pIpAddr);
+               pIpAddr = null;
+
+               pImpl->SetPrimaryDnsAddress(ipAddr);
+       }
+
+       ret = connection_profile_get_dns_address(profileHandle, 2, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
+       if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
+       {
+               ipAddr = String(pIpAddr);
+               free(pIpAddr);
+               pIpAddr = null;
+
+               pImpl->SetSecondaryDnsAddress(ipAddr);
+       }
+
+       char* pProxyAddr = null;
+
+       ret = connection_profile_get_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pProxyAddr);
+       SysSecureLog(NID_NET, "The return value from connection_profile_get_proxy_address() is [%d], Proxy address is [%s]", ret, pProxyAddr);
+       if ((ret == CONNECTION_ERROR_NONE) && (pProxyAddr != null))
+       {
+               proxyAddress = String(pProxyAddr);
+               free(pProxyAddr);
+       }
+
+       if (isDefault)
+       {
+               deviceName.Clear();
+       }
+       else
+       {
+               char* pDeviceName = null;
+
+               ret = connection_profile_get_network_interface_name(profileHandle, &pDeviceName);
+               if ((ret == CONNECTION_ERROR_NONE) && (pDeviceName != null))
+               {
+                       deviceName = String(pDeviceName);
+                       free(pDeviceName);
+               }
+       }
+
+       pImpl->SetBearerType(bearerType);
+       pImpl->SetProtocolType(protocolType);
+       pImpl->SetAccessPointName(apn);
+       pImpl->SetLocalAddressScheme(localAddressScheme);
+       pImpl->SetDnsAddressScheme(dnsAddressScheme);
+
+       pImpl->SetProxyAddress(proxyAddress);
+       pImpl->SetDeviceName(deviceName);
+}
+
+result
+ConnectivityUtility::UpdateNetAccountInfo(NetAccountInfo* pInfo, connection_profile_h profileHandle)
+{
+       result r = E_SUCCESS;
+       NetAccountId accountId = INVALID_HANDLE;
+       String accountName;
+       String accessPointName;
+       NetNapAuthType  authType = NET_NAPAUTH_NONE;
+       String authId;
+       String authPassword;
+       String homeUrl;
+       NetBearerType bearerType;
+       NetProtocolType protocolType;
+       NetAddressScheme localAddressScheme;
+       NetAddressScheme dnsAddressScheme;
+       std::unique_ptr<IpAddress> pLocalAddress;
+       std::unique_ptr<IpAddress> pPrimaryDnsAddress;
+       std::unique_ptr<IpAddress> pSecondaryDnsAddress;
+       std::unique_ptr<NetEndPoint> pProxyAddress;
+       bool isReadOnly = true;
+       int ret = CONNECTION_ERROR_NONE;
+
+       SysTryReturnResult(NID_NET, pInfo != null, E_INVALID_ARG, "NetAccountInfo is NULL.");
+
+       _NetAccountInfoImpl* pImpl = _NetAccountInfoImpl::GetInstance(*pInfo);
+       if (pImpl == null)
+       {
+               r = pInfo->Construct();
+               SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+               pImpl = _NetAccountInfoImpl::GetInstance(*pInfo);
+               SysTryReturnResult(NID_NET, pImpl != null, E_SYSTEM, "Failed to construct NetAccountInfo.");
+       }
+
+       SysTryReturnResult(NID_NET, profileHandle != null, E_INVALID_ARG, "Invalid argument is used. The profile handle is null.");
+
+       connection_profile_type_e profileType = CONNECTION_PROFILE_TYPE_CELLULAR;
+       ret = connection_profile_get_type(profileHandle, &profileType);
+       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                       "A system error has been occurred. The return value from connection_profile_get_type() is %d", ret);
+
+       if (profileType == CONNECTION_PROFILE_TYPE_CELLULAR)
+       {
+               String profileName;
+               char* pProfileName = null;
+               char* pApn = null;
+               connection_cellular_service_type_e serviceType = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
+               connection_cellular_auth_type_e netAuthType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
+               char* pAuthId = null;
+               char* pAuthPassword = null;
+               char* pHomeUrl = null;
+
+               ret = connection_profile_get_id(profileHandle, &pProfileName);
+               SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                               "A system error has been occurred. The return value from connection_profile_get_id() is %d", ret);
+
+               profileName = String(pProfileName);
+               free(pProfileName);
+
+               r = NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
+               SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
+               SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM,
+                               "A system error has been occurred. Failed to get the account Id from DB.");
+
+               r = NetAccountDatabase::GetAccountName(accountId, accountName);
+               SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
+               SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM,
+                               "A system error has been occurred. Failed to get the account name from DB.");
+
+               connection_profile_get_cellular_service_type(profileHandle, &serviceType);
+               if ((serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_MMS) || (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS))
+               {
+                       bearerType = NET_BEARER_MMS;
+                       isReadOnly  = true;
+               }
+               else if ((serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET) || (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET))
+               {
+                       bearerType = NET_BEARER_PS;
+                       isReadOnly  = true;
+               }
+               else
+               {
+                       bearerType = NET_BEARER_PS;
+                       isReadOnly  = false;
+               }
+
+               ret = connection_profile_get_cellular_apn(profileHandle, &pApn);
+               SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                               "A system error has been occurred. The return value from connection_profile_get_cellular_apn() is %d", ret);
+
+               accessPointName = String(pApn);
+               free(pApn);
+
+               ret = connection_profile_get_cellular_auth_info(profileHandle, &netAuthType, &pAuthId, &pAuthPassword);
+               if (netAuthType == CONNECTION_CELLULAR_AUTH_TYPE_PAP)
+               {
+                       authType = NET_NAPAUTH_PAP;
+               }
+               else if (netAuthType == CONNECTION_CELLULAR_AUTH_TYPE_CHAP)
+               {
+                       authType = NET_NAPAUTH_CHAP;
+               }
+               else
+               {
+                       authType = NET_NAPAUTH_NONE;
+               }
+
+               if (pAuthId != null)
+               {
+                       authId = String(pAuthId);
+                       free(pAuthId);
+               }
+
+               if (pAuthPassword != null)
+               {
+                       authPassword = String(pAuthPassword);
+                       free(pAuthPassword);
+               }
+
+               ret = connection_profile_get_cellular_home_url(profileHandle, &pHomeUrl);
+               if ((ret == CONNECTION_ERROR_NONE) && (pHomeUrl != null))
+               {
+                       homeUrl = String(pHomeUrl);
+                       free(pHomeUrl);
+               }
+       }
+       else if (profileType == CONNECTION_PROFILE_TYPE_WIFI)
+       {
+               accountId = _DEFAULT_WIFI_ACCOUNT_ID;
+               bearerType = NET_BEARER_WIFI;
+       }
+       else
+       {
+               SysLogException(NID_NET, E_INVALID_ARG, "[%s] Invalid argument is used. The profile info is invalid.", GetErrorMessage(E_INVALID_ARG));
+               return E_INVALID_ARG;
+       }
+
+       protocolType = NET_PROTO_TYPE_IPV4;
+
+       connection_ip_config_type_e ipConfigType = CONNECTION_IP_CONFIG_TYPE_NONE;
+       ret = connection_profile_get_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &ipConfigType);
+       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                       "A system error has been occurred. The return value from connection_profile_get_ip_config_type() is %d", ret);
+       if ((ipConfigType == CONNECTION_IP_CONFIG_TYPE_STATIC) || (ipConfigType == CONNECTION_IP_CONFIG_TYPE_FIXED))
+       {
+               localAddressScheme = NET_ADDRESS_SCHEME_STATIC;
+               dnsAddressScheme = NET_ADDRESS_SCHEME_STATIC;
+       }
+       else
+       {
+               localAddressScheme = NET_ADDRESS_SCHEME_DYNAMIC;
+               dnsAddressScheme = NET_ADDRESS_SCHEME_DYNAMIC;
+       }
+
+       char* pIpAddr = null;
+       String ipAddr;
+
+       ret = connection_profile_get_ip_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
+       if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
+       {
+               ipAddr = String(pIpAddr);
+               pLocalAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
+               free(pIpAddr);
+               pIpAddr = null;
+               SysTryReturnResult(NID_NET, pLocalAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+       }
+
+       ret = connection_profile_get_dns_address(profileHandle, 1, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
+       if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
+       {
+               ipAddr = String(pIpAddr);
+               pPrimaryDnsAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
+               free(pIpAddr);
+               pIpAddr = null;
+               SysTryReturnResult(NID_NET, pPrimaryDnsAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+       }
+
+       ret = connection_profile_get_dns_address(profileHandle, 2, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
+       if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
+       {
+               ipAddr = String(pIpAddr);
+               pSecondaryDnsAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
+               free(pIpAddr);
+               pIpAddr = null;
+               SysTryReturnResult(NID_NET, pSecondaryDnsAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+       }
+
+       char* pProxyAddr = null;
+       String proxyAddr;
+       int delimeterIndex = 0;
+
+       ret = connection_profile_get_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pProxyAddr);
+       if ((ret == CONNECTION_ERROR_NONE) && (pProxyAddr != null))
+       {
+               proxyAddr = String(pProxyAddr);
+               free(pProxyAddr);
+
+               r = proxyAddr.IndexOf(L":", 0, delimeterIndex);
+               if (r == E_SUCCESS)
+               {
+                       String  proxyIpAddr;
+                       String proxyPort;
+                       int port = 0;
+
+                       r = proxyAddr.SubString(0, delimeterIndex, proxyIpAddr);
+                       r = proxyAddr.SubString(delimeterIndex+1, proxyPort);
+
+                       Ip4Address address(proxyIpAddr);
+                       Integer::Parse(proxyPort, port);
+
+                       pProxyAddress.reset(new (std::nothrow) NetEndPoint(address, port));
+                       SysTryReturnResult(NID_NET, pProxyAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+               }
+       }
+
+       pImpl->SetAccountId(accountId);
+       pImpl->SetAccountName(accountName);
+       pImpl->SetAccessPointName(accessPointName);
+       pImpl->SetAuthenticationInfo(authType, authId, authPassword);
+       pImpl->SetHomeUrl(homeUrl);
+       pImpl->SetBearerType(bearerType);
+       pImpl->SetProtocolType(protocolType);
+       pImpl->SetLocalAddress(localAddressScheme, pLocalAddress.get());
+       pImpl->SetDnsAddress(dnsAddressScheme, pPrimaryDnsAddress.get(), pSecondaryDnsAddress.get());
+       pImpl->SetProxyAddress(pProxyAddress.get());
+       pImpl->SetReadOnly(isReadOnly);
+
+       return E_SUCCESS;
+}
+
+result
+ConnectivityUtility::UpdateProfileInfo(const NetAccountInfo* pInfo, connection_profile_h profileHandle, bool isAppProfile)
+{
+       result r = E_SUCCESS;
+       int ret = CONNECTION_ERROR_NONE;
+       connection_ip_config_type_e ipConfigType = CONNECTION_IP_CONFIG_TYPE_NONE;
+
+       unique_ptr<char[]> pApn;
+       unique_ptr<char[]> pAuthId;
+       unique_ptr<char[]> pAuthPassword;
+       unique_ptr<char[]> pHomeUrl;
+       unique_ptr<char[]> pLocalAddr;
+       unique_ptr<char[]> pPrimaryDnsAddr;
+       unique_ptr<char[]> pSecondaryDnsAddr;
+       unique_ptr<char[]> pProxyAddr;
+       String proxyAddr;
+
+       SysTryReturnResult(NID_NET, pInfo != null, E_INVALID_ARG, "NetAccountInfo is null.");
+       SysTryReturnResult(NID_NET, _NetAccountInfoImpl::GetInstance(*pInfo) != null, E_INVALID_ARG, "NetAccountInfo is not constructed.");
+       SysTryReturnResult(NID_NET, profileHandle != null, E_INVALID_ARG, "Profile handle is null.");
+
+       NetBearerType bearerType = pInfo->GetBearerType();
+
+       SysTryReturnResult(NID_NET, ((bearerType == NET_BEARER_PS) || (bearerType == NET_BEARER_MMS)), E_INVALID_ARG,
+                       "Invalid argument is used. BearerType is NOT PS. bearerType=%d", bearerType);
+
+       if (isAppProfile)
+       {
+               ret = connection_profile_set_cellular_service_type(profileHandle, CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
+               SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                               "A system error has been occurred. The return value from connection_profile_set_cellular_service_type() is %d", ret);
+       }
+
+       String apn = pInfo->GetAccessPointName();
+       if (!apn.IsEmpty())
+       {
+               pApn.reset(_StringConverter::CopyToCharArrayN(apn));
+               SysTryReturnResult(NID_NET, pApn != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+               ret = connection_profile_set_cellular_apn(profileHandle, pApn.get());
+               SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                               "A system error has been occurred. The return value from connection_profile_set_cellular_apn() is %d", ret);
+       }
+
+       NetNapAuthType auth = NET_NAPAUTH_NONE;
+       String authId;
+       String authPassword;
+       connection_cellular_auth_type_e authType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
+
+       r = pInfo->GetAuthenticationInfo(auth, authId, authPassword);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       if (auth == NET_NAPAUTH_PAP)
+       {
+               authType = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
+       }
+       else if (auth == NET_NAPAUTH_CHAP)
+       {
+               authType = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
+       }
+       else
+       {
+               authType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
+       }
+
+       if (!authId.IsEmpty())
+       {
+               pAuthId.reset(_StringConverter::CopyToCharArrayN(authId));
+               SysTryReturnResult(NID_NET, pAuthId != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+       }
+
+       if (!authPassword.IsEmpty())
+       {
+               pAuthPassword.reset(_StringConverter::CopyToCharArrayN(authPassword));
+               SysTryReturnResult(NID_NET, pAuthPassword != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+       }
+
+       if ((pAuthId != null) && (pAuthPassword != null))
+       {
+               ret = connection_profile_set_cellular_auth_info(profileHandle, authType, pAuthId.get(), pAuthPassword.get());
+       }
+       else
+       {
+               ret = connection_profile_set_cellular_auth_info(profileHandle, authType, " ", " ");
+       }
+       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                       "A system error has been occurred. The return value from connection_profile_set_cellular_auth_info() is %d", ret);
+
+       String homeUrl = pInfo->GetHomeUrl();
+       if (!homeUrl.IsEmpty())
+       {
+               pHomeUrl.reset(_StringConverter::CopyToCharArrayN(homeUrl));
+               SysTryReturnResult(NID_NET, pHomeUrl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+               ret = connection_profile_set_cellular_home_url(profileHandle, pHomeUrl.get());
+       }
+       else
+       {
+               ret = connection_profile_set_cellular_home_url(profileHandle, " ");
+       }
+       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                       "A system error has been occurred. The return value from connection_profile_set_cellular_home_url() is %d", ret);
+
+       ret = connection_profile_get_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &ipConfigType);
+
+       if (ipConfigType != CONNECTION_IP_CONFIG_TYPE_FIXED)
+       {
+               if (pInfo->GetLocalAddressScheme() == NET_ADDRESS_SCHEME_STATIC)
+               {
+                       const IpAddress* pLocalAddress = pInfo->GetLocalAddress();
+                       SysTryReturnResult(NID_NET, pLocalAddress != null, E_INVALID_ARG, "Invalid argument is used. Local Addr Scheme is static, but local addr is null.");
+
+                       ret = connection_profile_set_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, CONNECTION_IP_CONFIG_TYPE_STATIC);
+                       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                                       "A system error has been occurred. The return value from connection_profile_set_ip_config_type() is %d", ret);
+
+                       pLocalAddr.reset(_StringConverter::CopyToCharArrayN(pLocalAddress->ToString()));
+                       SysTryReturnResult(NID_NET, pLocalAddr != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+                       ret = connection_profile_set_ip_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, pLocalAddr.get());
+                       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                                       "A system error has been occurred. The return value from connection_profile_set_ip_address() is %d", ret);
+               }
+               else
+               {
+                       ret = connection_profile_set_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
+                       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                                       "A system error has been occurred. The return value from connection_profile_set_ip_config_type() is %d", ret);
+               }
+
+               if (pInfo->GetDnsAddressScheme() == NET_ADDRESS_SCHEME_STATIC)
+               {
+                       const IpAddress* pDnsAddress = pInfo->GetPrimaryDnsAddress();
+                       if (pDnsAddress != null)
+                       {
+                               pPrimaryDnsAddr.reset(_StringConverter::CopyToCharArrayN(pDnsAddress->ToString()));
+                               SysTryReturnResult(NID_NET, pPrimaryDnsAddr != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+                               ret = connection_profile_set_dns_address(profileHandle, 1, CONNECTION_ADDRESS_FAMILY_IPV4, pPrimaryDnsAddr.get());
+                               SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                                               "A system error has been occurred. The return value from connection_profile_set_dns_address() is %d", ret);
+                       }
+
+                       pDnsAddress = pInfo->GetSecondaryDnsAddress();
+                       if (pDnsAddress != null)
+                       {
+                               pSecondaryDnsAddr.reset(_StringConverter::CopyToCharArrayN(pDnsAddress->ToString()));
+                               SysTryReturnResult(NID_NET, pSecondaryDnsAddr != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+                               ret = connection_profile_set_dns_address(profileHandle, 2, CONNECTION_ADDRESS_FAMILY_IPV4, pSecondaryDnsAddr.get());
+                               SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                                               "A system error has been occurred. The return value from connection_profile_set_dns_address() is %d", ret);
+                       }
+               }
+       }
+
+       const NetEndPoint* pProxyAddress = pInfo->GetProxyAddress();
+       if (pProxyAddress != null)
+       {
+               proxyAddr = pProxyAddress->GetNetEndPoint();
+               if (!proxyAddr.IsEmpty())
+               {
+                       ret = connection_profile_set_proxy_type(profileHandle, CONNECTION_PROXY_TYPE_MANUAL);
+                       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                                       "A system error has been occurred. The return value from connection_profile_set_proxy_type() is %d", ret);
+
+                       pProxyAddr.reset(_StringConverter::CopyToCharArrayN(proxyAddr));
+                       SysTryReturnResult(NID_NET, pProxyAddr != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+                       ret = connection_profile_set_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, pProxyAddr.get());
+               }
+               else
+               {
+                       ret = connection_profile_set_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, null);
+               }
+       }
+       else
+       {
+               ret = connection_profile_set_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, null);
+       }
+       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                       "A system error has been occurred. The return value from connection_profile_set_proxy_address() is %d", ret);
+
+       return r;
+}
+
+result
+ConnectivityUtility::UpdateWifiNetAccountInfo(_WifiNetAccountInfoImpl* pWifiNetAccountInfoImpl, connection_profile_h profileHandle)
+{
+    SysTryReturnResult(NID_NET_WIFI, pWifiNetAccountInfoImpl != null, E_INVALID_ARG, "A WifiNetAccountInfo is null.");
+    SysTryReturnResult(NID_NET_WIFI, profileHandle != null, E_INVALID_ARG, "A profile is NULL.");
+
+    int err = CONNECTION_ERROR_NONE;
+
+    char *pSsid = null;
+    err = connection_profile_get_wifi_essid(profileHandle, &pSsid);
+    SysTryReturnResult(NID_NET_WIFI, pSsid != null, E_SYSTEM, "Failed result from connection_profile_get_wifi_essid() is 0x%x.", err);
+    String ssid(pSsid);
+    free(pSsid);
+
+    char *pBssid = null;
+    err = connection_profile_get_wifi_bssid(profileHandle, &pBssid);
+    SysTryReturnResult(NID_NET_WIFI, pSsid != null, E_SYSTEM, "Failed result from connection_profile_get_wifi_bssid() is 0x%x.", err);
+    String bssid = _WifiUtility::ConvertMacAddress(pBssid);
+    free(pBssid);
+
+    int radioChannel = 0;
+    err = connection_profile_get_wifi_frequency(profileHandle, &radioChannel);
+    SysTryReturnResult(NID_NET_WIFI, pSsid != null, E_SYSTEM, "Failed result from connection_profile_get_wifi_frequency() is 0x%x.", err);
+    WifiRadioChannel wifiRadioChannel = Tizen::Net::Wifi::_WifiUtility::ConvertRadioChannel(radioChannel);
+
+    connection_wifi_encryption_type_e encType = CONNECTION_WIFI_ENCRYPTION_TYPE_NONE;
+    err = connection_profile_get_wifi_encryption_type(profileHandle,&encType);
+    SysTryReturnResult(NID_NET_WIFI, pSsid != null, E_SYSTEM, "Failed result from connection_profile_get_wifi_encryption_type() is 0x%x.", err);
+
+    connection_wifi_security_type_e secType = CONNECTION_WIFI_SECURITY_TYPE_NONE;
+    err = connection_profile_get_wifi_security_type(profileHandle,&secType);
+    SysTryReturnResult(NID_NET_WIFI, pSsid != null, E_SYSTEM, "Failed result from connection_profile_get_wifi_security_type() is 0x%x.", err);
+
+    _WifiSecurityInfoImpl* pSecuInfoImpl = const_cast<_WifiSecurityInfoImpl*>(_WifiSecurityInfoImpl::GetInstance(*pWifiNetAccountInfoImpl->GetSecurityInfo()));
+    pSecuInfoImpl->SetAuthenticationType(_WifiUtility::ConvertAuthType(static_cast <wifi_security_type_e>(secType), static_cast <wifi_encryption_type_e>(encType)));
+    pSecuInfoImpl->SetEncryptionType(_WifiUtility::ConvertEncryptionType(static_cast <wifi_encryption_type_e>(encType)));
+
+    pWifiNetAccountInfoImpl->SetSsid(ssid);
+    pWifiNetAccountInfoImpl->SetBssType(WIFI_BSS_TYPE_INFRASTRUCTURE);
+    pWifiNetAccountInfoImpl->SetBssId(bssid);
+    pWifiNetAccountInfoImpl->SetRadioChannel(wifiRadioChannel);
+
+    return E_SUCCESS;
+
+}
+
+connection_profile_h
+ConnectivityUtility::GetWifiProfileHandleN(void)
+{
+       int ret = CONNECTION_ERROR_NONE;
+       connection_h connectionHandle = null;
+       connection_profile_iterator_h iterator = null;
+       connection_profile_h profileHandle = null;
+       connection_profile_h matchingProfileHandle = null;
+       connection_profile_type_e profileType = CONNECTION_PROFILE_TYPE_CELLULAR;
+
+       ret = connection_create(&connectionHandle);
+       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, 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_profile_iterator(connectionHandle, CONNECTION_ITERATOR_TYPE_CONNECTED, &iterator);
+       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                       "[%s] A system error has been occurred. The return value from connection_get_profile_iterator() is %d",
+                       GetErrorMessage(E_SYSTEM), ret);
+       unique_ptr<void, _ProfileIteratorDeleter> pIterator(iterator);
+
+       ret = connection_profile_iterator_next(iterator, &profileHandle);
+       while ((ret == CONNECTION_ERROR_NONE) && (profileHandle != null))
+       {
+               ret = connection_profile_get_type(profileHandle, &profileType);
+               SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                               "[%s] A system error has been occurred. The return value from connection_profile_get_type() is %d",
+                               GetErrorMessage(E_SYSTEM), ret);
+
+               if (profileType == CONNECTION_PROFILE_TYPE_WIFI)
+               {
+                       SysLog(NID_NET, "Connected WiFi profile is found.");
+                       ret = connection_profile_clone(&matchingProfileHandle,
+                                       profileHandle);
+                       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                                       "[%s] A system error has been occurred. The return value from connection_profile_clone() is %d",
+                                       GetErrorMessage(E_SYSTEM), ret);
+
+                       break;
+               }
+
+               profileHandle = null;
+               ret = connection_profile_iterator_next(iterator, &profileHandle);
+       }
+
+       SysTryReturn(NID_NET, matchingProfileHandle != null, null, E_INVALID_ACCOUNT,
+                       "[%s] Active Wi-Fi profile is not found.", GetErrorMessage(E_INVALID_ACCOUNT));
+
+       ClearLastResult();
+
+       return matchingProfileHandle;
+}
+
+connection_profile_h
+ConnectivityUtility::GetPsProfileHandleN(const String& profileName)
+{
+       int ret = CONNECTION_ERROR_NONE;
+       connection_h connectionHandle = null;
+       connection_profile_iterator_h iterator = null;
+       connection_profile_h profileHandle = null;
+       connection_profile_h matchingProfileHandle = null;
+
+       SysLog(NID_NET, "GetPsProfileHandleN() has been called with profileName[%ls]", profileName.GetPointer());
+
+       SysTryReturn(NID_NET, !profileName.IsEmpty(), null, E_INVALID_ARG,
+                       "[%s] Invalid argument is used. profileName is an empty string.", GetErrorMessage(E_INVALID_ARG));
+
+       ret = connection_create(&connectionHandle);
+       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, 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_profile_iterator(connectionHandle, CONNECTION_ITERATOR_TYPE_REGISTERED, &iterator);
+       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                       "[%s] A system error has been occurred. The return value from connection_get_profile_iterator() is %d",
+                       GetErrorMessage(E_SYSTEM), ret);
+       unique_ptr<void, _ProfileIteratorDeleter> pIterator(iterator);
+
+       ret = connection_profile_iterator_next(iterator, &profileHandle);
+       while ((ret == CONNECTION_ERROR_NONE) && (profileHandle != null))
+       {
+               char* pTempProfileName = null;
+               String tempProfileName;
+
+               ret = connection_profile_get_id(profileHandle, &pTempProfileName);
+               SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                               "[%s] A system error has been occurred. The return value from connection_profile_get_id() is %d",
+                               GetErrorMessage(E_SYSTEM), ret);
+
+               tempProfileName = String(pTempProfileName);
+               free(pTempProfileName);
+
+               if (profileName.Equals(tempProfileName))
+               {
+                       ret = connection_profile_clone(&matchingProfileHandle, profileHandle);
+                       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                                       "[%s] A system error has been occurred. The return value from connection_profile_clone() is %d",
+                                       GetErrorMessage(E_SYSTEM), ret);
+
+                       break;
+               }
+
+               profileHandle = null;
+               ret = connection_profile_iterator_next(iterator, &profileHandle);
+       }
+
+       SysTryReturn(NID_NET, matchingProfileHandle != null, null, E_INVALID_ACCOUNT,
+                       "[%s] Matching profileName is not found. profileName[%ls]", GetErrorMessage(E_INVALID_ACCOUNT), profileName.GetPointer());
+
+       ClearLastResult();
+
+       return matchingProfileHandle;
+}
diff --git a/src/NetAccountDatabase.cpp b/src/NetAccountDatabase.cpp
new file mode 100755 (executable)
index 0000000..b36f3a7
--- /dev/null
@@ -0,0 +1,607 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+/**
+* @file                        NetAccountDatabase.cpp
+* @brief               This is the implementation file for the %NetAccountDatabase class.
+*
+* This file contains the implementation of the %NetAccountDatabase class.
+*/
+
+#include <unique_ptr.h>
+#include <FBaseString.h>
+#include <FBaseColIList.h>
+#include <FBaseColIListT.h>
+#include <FBaseColAllElementsDeleter.h>
+#include <FIoDatabase.h>
+#include <FIoDbStatement.h>
+#include <FIoDbEnumerator.h>
+#include <FIoDirectory.h>
+#include <FAppApp.h>
+#include <FBaseSysLog.h>
+#include <FApp_AppInfo.h>
+#include <FNet_NetTypes.h>
+#include "NetAccountDatabase.h"
+
+using namespace std;
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Io;
+using namespace Tizen::Net;
+
+extern const wchar_t SYSTEM_PACKAGE_NAME[] = L"system";
+
+result
+NetAccountDatabase::InitializeRepository(void)
+{
+       static const wchar_t _NET_ACCOUNT_DATABASE_CREATE_TABLE_STATEMENT[] =
+                       L"CREATE TABLE IF NOT EXISTS NetAccountTable (accountId INTEGER UNIQUE, accountName TEXT(256) UNIQUE, profileName TEXT(256) UNIQUE, packageId TEXT(256))";
+
+       result r = E_SUCCESS;
+       Database accountDb;
+
+       if (!Database::Exists(NetAccountDatabase::GetDbPath()))
+       {
+               SysLog(NID_NET, "NetAccount database is NOT found, so create it now.");
+       }
+
+       r = accountDb.Construct(NetAccountDatabase::GetDbPath(), true);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       r = accountDb.ExecuteSql(String(_NET_ACCOUNT_DATABASE_CREATE_TABLE_STATEMENT), true);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       return r;
+}
+
+result
+NetAccountDatabase::AddAccount(const String& accountName, const String& profileName, const String& packageId, NetAccountId& accountId)
+{
+       static const wchar_t _NET_ACCOUNT_DATABASE_GET_MAX_ACCOUNT_ID_STATEMENT[] =
+                       L"SELECT MAX(accountId) FROM NetAccountTable";
+       static const wchar_t _NET_ACCOUNT_DATABASE_ADD_ACCOUNT_STATEMENT[] =
+                       L"INSERT INTO NetAccountTable (accountId, accountName, profileName, packageId) VALUES(?, ?, ?, ?)";
+
+       result r = E_SUCCESS;
+       Database accountDb;
+       unique_ptr<DbStatement> pStmt;
+       unique_ptr<DbEnumerator> pEnum;
+       NetAccountId netAccountId = INVALID_HANDLE;
+
+       SysSecureLog(NID_NET, "AddAccount() has been called with accountName:%ls, profileName:%ls, packageId:%ls",
+                       accountName.GetPointer(), profileName.GetPointer(), packageId.GetPointer());
+
+       accountId = INVALID_HANDLE;
+
+       SysTryReturnResult(NID_NET, !accountName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. accountName is an empty string.");
+       SysTryReturnResult(NID_NET, !profileName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. profileName is an empty string.");
+       SysTryReturnResult(NID_NET, !packageId.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. packageName is an empty string.");
+
+       r = accountDb.Construct(NetAccountDatabase::GetDbPath(), false);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       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;
+               }
+       }
+
+       if (netAccountId >= _PS_ACCOUNT_ID_START)
+       {
+               netAccountId++;
+       }
+       else
+       {
+               netAccountId = _PS_ACCOUNT_ID_START;
+       }
+
+       pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_ADD_ACCOUNT_STATEMENT)));
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
+
+       r = pStmt->BindInt(0, netAccountId);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       r = pStmt->BindString(1, accountName);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       r = pStmt->BindString(2, profileName);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       r = pStmt->BindString(3, packageId);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       accountId = netAccountId;
+
+       return r;
+}
+
+result
+NetAccountDatabase::RemoveAccountByAccountId(NetAccountId accountId)
+{
+       static const wchar_t _NET_ACCOUNT_DATABASE_REMOVE_ACCOUNT_BY_ACCOUNT_ID_STATEMENT[] =
+                       L"DELETE FROM NetAccountTable WHERE accountId=?";
+
+       SysSecureLog(NID_NET, "RemoveAccountByAccountId() has been called with accountId:%d", accountId);
+
+       result r = E_SUCCESS;
+       Database accountDb;
+       unique_ptr<DbStatement> pStmt;
+       unique_ptr<DbEnumerator> pEnum;
+
+       SysTryReturnResult(NID_NET, accountId > 0, E_INVALID_ARG, "Invalid argument is used. accountId=%d", accountId);
+
+       r = accountDb.Construct(NetAccountDatabase::GetDbPath(), false);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_REMOVE_ACCOUNT_BY_ACCOUNT_ID_STATEMENT)));
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
+
+       r = pStmt->BindInt(0, accountId);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
+       r = GetLastResult();
+
+       return r;
+}
+
+result
+NetAccountDatabase::RemoveAccountByProfileName(const String& profileName)
+{
+       static const wchar_t _NET_ACCOUNT_DATABASE_REMOVE_ACCOUNT_BY_PROFILE_NAME_STATEMENT[] =
+                       L"DELETE FROM NetAccountTable WHERE profileName=?";
+
+       SysLog(NID_NET, "RemoveAccountByProfileName() has been called with profileName:%ls", profileName.GetPointer());
+
+       result r = E_SUCCESS;
+       Database accountDb;
+       unique_ptr<DbStatement> pStmt;
+       unique_ptr<DbEnumerator> pEnum;
+
+       SysTryReturnResult(NID_NET, !profileName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. profileName is an empty string.");
+
+       r = accountDb.Construct(NetAccountDatabase::GetDbPath(), false);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_REMOVE_ACCOUNT_BY_PROFILE_NAME_STATEMENT)));
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
+
+       r = pStmt->BindString(0, profileName);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
+       r = GetLastResult();
+
+       return r;
+}
+
+result
+NetAccountDatabase::UpdateAccountName(NetAccountId accountId, const String& accountName)
+{
+       static const wchar_t _NET_ACCOUNT_DATABASE_UPDATE_ACCOUNT_NAME_STATEMENT[] =
+                       L"UPDATE NetAccountTable SET accountName=? WHERE accountId=?";
+
+       SysSecureLog(NID_NET, "UpdateAccountName() has been called with accountId:%d, accountName:%ls", accountId, accountName.GetPointer());
+
+       result r = E_SUCCESS;
+       Database accountDb;
+       unique_ptr<DbStatement> pStmt;
+       unique_ptr<DbEnumerator> pEnum;
+
+       SysTryReturnResult(NID_NET, accountId > 0, E_INVALID_ARG, "AccountId[%d] is invalid.", accountId);
+       SysTryReturnResult(NID_NET, !accountName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. accountName is an empty string.");
+
+       r = accountDb.Construct(NetAccountDatabase::GetDbPath(), false);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_UPDATE_ACCOUNT_NAME_STATEMENT)));
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
+
+       r = pStmt->BindString(0, accountName);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       r = pStmt->BindInt(1, accountId);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
+       r = GetLastResult();
+
+       return r;
+}
+
+result
+NetAccountDatabase::GetAccountIds(ArrayListT<NetAccountId>* pList)
+{
+       static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_IDS_STATEMENT[] =
+                       L"SELECT accountId FROM NetAccountTable";
+
+       result r = E_SUCCESS;
+       Database accountDb;
+       unique_ptr<DbStatement> pStmt;
+       unique_ptr<DbEnumerator> pEnum;
+
+       r = accountDb.Construct(NetAccountDatabase::GetDbPath(), false);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_IDS_STATEMENT)));
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
+
+       pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       if (pEnum != null)
+       {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       NetAccountId accountId = INVALID_HANDLE;
+
+                       r = pEnum->GetIntAt(0, accountId);
+                       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+                       r = pList->Add(accountId);
+                       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+               }
+       }
+
+       return E_SUCCESS;
+}
+
+result
+NetAccountDatabase::GetAccountNames(ArrayList* pList)
+{
+       static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_NAMES_STATEMENT[] =
+                       L"SELECT accountName FROM NetAccountTable";
+
+       result r = E_SUCCESS;
+       Database accountDb;
+       unique_ptr<DbStatement> pStmt;
+       unique_ptr<DbEnumerator> pEnum;
+
+       r = accountDb.Construct(NetAccountDatabase::GetDbPath(), false);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_NAMES_STATEMENT)));
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
+
+       pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       if (pEnum != null)
+       {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       unique_ptr<String> pAccountName(new (std::nothrow) String());
+                       SysTryReturnResult(NID_NET, pAccountName != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+                       r = pEnum->GetStringAt(0, *pAccountName);
+                       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+                       r = pList->Add(*pAccountName);
+                       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+                       pAccountName.release();
+               }
+       }
+
+       return E_SUCCESS;
+}
+
+IList*
+NetAccountDatabase::GetProfileNamesN(void)
+{
+       static const wchar_t _NET_ACCOUNT_DATABASE_GET_PROFILE_NAMES_STATEMENT[] =
+                       L"SELECT profileName FROM NetAccountTable";
+
+       result r = E_SUCCESS;
+       Database accountDb;
+       unique_ptr<DbStatement> pStmt;
+       unique_ptr<DbEnumerator> pEnum;
+       unique_ptr<ArrayList, AllElementsDeleter> 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));
+
+       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)
+{
+       static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_NAME_STATEMENT[] =
+                       L"SELECT accountName FROM NetAccountTable WHERE accountId=?";
+
+       SysSecureLog(NID_NET, "GetAccountName() has been called with accountId:%d", accountId);
+
+       result r = E_SUCCESS;
+       Database accountDb;
+       unique_ptr<DbStatement> pStmt;
+       unique_ptr<DbEnumerator> pEnum;
+
+       SysTryReturnResult(NID_NET, accountId > 0, E_INVALID_ARG, "Invalid argument is used. accountId=%d", accountId);
+
+       r = accountDb.Construct(NetAccountDatabase::GetDbPath(), false);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_NAME_STATEMENT)));
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
+
+       r = pStmt->BindInt(0, accountId);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       r = E_OBJ_NOT_FOUND;
+
+       pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
+       if (pEnum != null)
+       {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pEnum->GetStringAt(0, accountName);
+                       r = E_SUCCESS;
+                       break;
+               }
+       }
+
+       return r;
+}
+
+result
+NetAccountDatabase::GetProfileName(NetAccountId accountId, String& profileName)
+{
+       static const wchar_t _NET_ACCOUNT_DATABASE_GET_PROFILE_NAME_STATEMENT[] =
+                       L"SELECT profileName FROM NetAccountTable WHERE accountId=?";
+
+       SysSecureLog(NID_NET, "GetProfileName() has been called with accountId:%d", accountId);
+
+       result r = E_SUCCESS;
+       Database accountDb;
+       unique_ptr<DbStatement> pStmt;
+       unique_ptr<DbEnumerator> pEnum;
+
+       SysTryReturnResult(NID_NET, accountId > 0, E_INVALID_ARG, "Invalid argument is used. accountId=%d", accountId);
+
+       r = accountDb.Construct(NetAccountDatabase::GetDbPath(), false);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_PROFILE_NAME_STATEMENT)));
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
+
+       r = pStmt->BindInt(0, accountId);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       r = E_OBJ_NOT_FOUND;
+
+       pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
+       if (pEnum != null)
+       {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pEnum->GetStringAt(0, profileName);
+                       r = E_SUCCESS;
+                       break;
+               }
+       }
+
+       return r;
+}
+
+result
+NetAccountDatabase::GetAccountIdByAccountName(const String& accountName, NetAccountId& accountId)
+{
+       static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_ID_BY_ACCOUNT_NAME_STATEMENT[] =
+                       L"SELECT accountId FROM NetAccountTable WHERE accountName=?";
+
+       SysSecureLog(NID_NET, "GetAccountIdByAccountName() has been called with accountName:%ls", accountName.GetPointer());
+
+       result r = E_SUCCESS;
+       Database accountDb;
+       unique_ptr<DbStatement> pStmt;
+       unique_ptr<DbEnumerator> pEnum;
+
+       SysTryReturnResult(NID_NET, !accountName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. accountName is an empty string.");
+
+       r = accountDb.Construct(NetAccountDatabase::GetDbPath(), false);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_ID_BY_ACCOUNT_NAME_STATEMENT)));
+       SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
+
+       r = pStmt->BindString(0, accountName);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       r = E_OBJ_NOT_FOUND;
+
+       pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
+       if (pEnum != null)
+       {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pEnum->GetIntAt(0, accountId);
+                       r = E_SUCCESS;
+                       break;
+               }
+       }
+
+       return r;
+}
+
+result
+NetAccountDatabase::GetAccountIdByProfileName(const String& profileName, NetAccountId& accountId)
+{
+       static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_ID_BY_PROFILE_NAME_STATEMENT[] =
+                       L"SELECT accountId FROM NetAccountTable WHERE profileName=?";
+
+       SysLog(NID_NET, "GetAccountIdByProfileName() has been called with profileName:%ls", profileName.GetPointer());
+
+       result r = E_SUCCESS;
+       Database accountDb;
+       unique_ptr<DbStatement> pStmt;
+       unique_ptr<DbEnumerator> pEnum;
+
+       SysTryReturnResult(NID_NET, !profileName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. profileName is an empty string.");
+
+       r = accountDb.Construct(NetAccountDatabase::GetDbPath(), false);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_ID_BY_PROFILE_NAME_STATEMENT)));
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
+
+       r = pStmt->BindString(0, profileName);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       r = E_OBJ_NOT_FOUND;
+
+       pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
+       if (pEnum != null)
+       {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pEnum->GetIntAt(0, accountId);
+                       r = E_SUCCESS;
+                       break;
+               }
+       }
+
+       return r;
+}
+
+bool
+NetAccountDatabase::IsReadOnly(const String& packageId, NetAccountId accountId)
+{
+       static const wchar_t NET_ACCOUNT_DATABASE_GET_PACKAGE_ID_STATEMENT[] =
+                       L"SELECT packageId FROM NetAccountTable WHERE accountId=?";
+
+       SysSecureLog(NID_NET, "IsReadOnly() has been called with packageId[%ls] accountId:%d", packageId.GetPointer(), accountId);
+
+       result r = E_SUCCESS;
+       Database accountDb;
+       unique_ptr<DbStatement> pStmt;
+       unique_ptr<DbEnumerator> pEnum;
+       String ownerPackageId;
+       bool isReadOnly = true;
+
+       SysTryReturn(NID_NET, accountId > 0, true, E_INVALID_ARG,
+                       "[%s] Invalid argument is used. accountId=%d", GetErrorMessage(E_INVALID_ARG), accountId);
+
+       r = accountDb.Construct(NetAccountDatabase::GetDbPath(), false);
+       SysTryReturn(NID_NET, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       pStmt.reset(accountDb.CreateStatementN(String(NET_ACCOUNT_DATABASE_GET_PACKAGE_ID_STATEMENT)));
+       r = GetLastResult();
+       SysTryReturn(NID_NET, pStmt != null, true, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       r = pStmt->BindInt(0, accountId);
+       SysTryReturn(NID_NET, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       r = E_OBJ_NOT_FOUND;
+       pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
+       if (pEnum != null)
+       {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pEnum->GetStringAt(0, ownerPackageId);
+                       r = E_SUCCESS;
+                       break;
+               }
+       }
+       SysTryReturn(NID_NET, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       if (packageId == ownerPackageId)
+       {
+               isReadOnly = false;
+       }
+       else
+       {
+               isReadOnly = true;
+       }
+
+       ClearLastResult();
+
+       return isReadOnly;
+}
+
+String
+NetAccountDatabase::GetDbPath(void)
+{
+       static const wchar_t _NET_ACCOUNT_DATABASE_FILE_NAME[] = L".tizen_netaccount.db";
+
+       String dbPath = Tizen::App::App::GetInstance()->GetAppDataPath();
+
+       dbPath += String(_NET_ACCOUNT_DATABASE_FILE_NAME);
+
+       SysLog(NID_NET, "GetDbPath() has been succeeded with the path:%ls", dbPath.GetPointer());
+
+       return dbPath;
+}
+
old mode 100644 (file)
new mode 100755 (executable)
index 1b46be2..8853efa
 #include <unique_ptr.h>
 #include <FBaseSysLog.h>
 #include <FIo_IpcServer.h>
-#include <FNet_ConnectivityIpcMessages.h>
 #include <FIo_IpcCommonParamTraits.h>
+#include <FNet_ConnectivityIpcMessages.h>
 #include <FSec_AccessController.h>
 #include "NetConnectivityIpcStub.h"
 #include "NetService.h"
+#include "NetAccountDatabase.h"
+#include "NetDefaultConnection.h"
+#include "NetPsConnection.h"
+#include "NetWifiConnection.h"
 
+using namespace std;
 using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
 using namespace Tizen::Io;
 using namespace Tizen::Security;
 using namespace Tizen::Net;
 
 NetConnectivityIpcStub::NetConnectivityIpcStub(void)
        : __pNetService(null)
+       , __pNetDefaultConnection(null)
+       , __pNetWifiConnection(null)
        , __pIpcServer(null)
+       , __pAccountNameList(null)
+       , __pConnectionInfoList(null)
 {
 }
 
 NetConnectivityIpcStub::~NetConnectivityIpcStub(void)
 {
+       if (__pAccountNameList != null)
+       {
+               __pAccountNameList->RemoveAll(true);
+               delete __pAccountNameList;
+       }
+       if (__pConnectionInfoList != null)
+       {
+               __pConnectionInfoList->RemoveAll(true);
+               delete __pConnectionInfoList;
+       }
+
        delete __pIpcServer;
+       delete __pNetWifiConnection;
+       delete __pNetDefaultConnection;
        delete __pNetService;
 }
 
@@ -49,31 +72,34 @@ result
 NetConnectivityIpcStub::Construct(void)
 {
        result r = E_SUCCESS;
-       result retVal = E_SUCCESS;
 
-       __pNetService = new (std::nothrow) NetService;
-       SysTryCatch(NID_NET, __pNetService != null, retVal = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
-                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysLog(NID_NET, "NetService is created.");
+       unique_ptr<ArrayList> pAccountNameList(new (std::nothrow) ArrayList());
+       SysTryReturnResult(NID_NET, pAccountNameList != null, E_OUT_OF_MEMORY, "Insufficient memory.");
 
-       __pIpcServer = new (std::nothrow) _IpcServer;
-       SysTryCatch(NID_NET, __pIpcServer != null, retVal = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
-                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       r = pAccountNameList->Construct();
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
 
-       r = __pIpcServer->Construct(NET_CONNECTIVITY_IPC_SERVER_NAME, *this);
-       SysTryCatch(NID_NET, r == E_SUCCESS, retVal = E_SYSTEM, E_SYSTEM,
-                       "[%s] A system error has been occurred. Failed to construct IpcServer.", GetErrorMessage(E_SYSTEM));
+       unique_ptr<ArrayList> pConnectionInfoList(new (std::nothrow) ArrayList());
+       SysTryReturnResult(NID_NET, pConnectionInfoList != null, E_OUT_OF_MEMORY, "Insufficient memory.");
 
-       return E_SUCCESS;
+       r = pConnectionInfoList->Construct();
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
 
-CATCH:
-       delete __pIpcServer;
-       __pIpcServer = null;
+       unique_ptr<_IpcServer> pIpcServer(new (std::nothrow) _IpcServer());
+       SysTryReturnResult(NID_NET, pIpcServer != null, E_OUT_OF_MEMORY, "Insufficient memory.");
 
-       delete __pNetService;
-       __pNetService = null;
+       r = pIpcServer->Construct(NET_CONNECTIVITY_IPC_SERVER_NAME, *this);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       __pNetService = NetService::GetInstance();
+       __pNetDefaultConnection = NetDefaultConnection::GetInstance(this);
+       __pNetWifiConnection = NetWifiConnection::GetInstance(this);
 
-       return retVal;
+       __pAccountNameList = pAccountNameList.release();
+       __pConnectionInfoList = pConnectionInfoList.release();
+       __pIpcServer = pIpcServer.release();
+
+       return E_SUCCESS;
 }
 
 void
@@ -98,6 +124,18 @@ void
 NetConnectivityIpcStub::OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId)
 {
        SysLog(NID_NET, "Disconnected with clientId[%d].", clientId);
+
+       if (__pNetDefaultConnection != null)
+       {
+               __pNetDefaultConnection->RemoveEventListener(clientId);
+       }
+
+       if (__pNetWifiConnection != null)
+       {
+               __pNetWifiConnection->RemoveEventListener(clientId);
+       }
+
+       NetPsConnection::StopAll(clientId);
 }
 
 void
@@ -109,169 +147,675 @@ NetConnectivityIpcStub::OnIpcRequestReceived(Tizen::Io::_IpcServer& server, cons
        IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_updateSystemNetAccount, OnUpdateSystemNetAccount, &server)
        IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_resetNetStatistics, OnResetNetStatistics, &server)
        IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_resetAllNetStatistics, OnResetAllNetStatistics, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_addDefaultConnectionListener, OnAddDefaultConnectionListener, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_removeDefaultConnectionListener, OnRemoveDefaultConnectionListener, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_addWifiConnectionListener, OnAddWifiConnectionListener, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_removeWifiConnectionListener, OnRemoveWifiConnectionListener, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_startWifiConnection, OnStartWifiConnection, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_startPsConnection, OnStartPsConnection, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_stopPsConnection, OnStopPsConnection, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_getPsConnectionState, OnGetPsConnectionState, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_getNetAccountName, OnGetNetAccountName, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_getNetProfileName, OnGetNetProfileName, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_getNetConnectionInfo, OnGetNetConnectionInfo, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_getNetAccountInfo, OnGetNetAccountInfo, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_getNetAccountId, OnGetNetAccountId, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_getInternetNetAccountId, OnGetInternetNetAccountId, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_getMmsNetAccountId, OnGetMmsNetAccountId, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_createNetAccount, OnCreateNetAccount, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_deleteNetAccount, OnDeleteNetAccount, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_updateNetAccount, OnUpdateNetAccount, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_getNetAccountIds, OnGetNetAccountIds, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_getNetAccountNames, OnGetNetAccountNames, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityNetServiceMsg_getAllNetConnectionInfo, OnGetAllNetConnectionInfo, &server)
        IPC_END_MESSAGE_MAP()
 }
 
 void
 NetConnectivityIpcStub::OnGetAppNetAccountId(const String& profileName, int* pNetAccountId, unsigned long* pResult)
 {
-    SysSecureLog(NID_NET, "Received the request of getting application specific account id with clientId : %d, PkgId : %ls",
-            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+    SysSecureLog(NID_NET, "OnGetAppNetAccountId with clientId[%d] PkgId[%ls] profile[%ls]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer(), profileName.GetPointer());
 
     String pkgId = __pIpcServer->GetClientPackageId();
     int netAccountId = INVALID_HANDLE;
 
-     *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_CUSTOMNETACCOUNT);
-
+    *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_CUSTOMNETACCOUNT);
     if (*pResult != E_SUCCESS)
     {
         *pResult = E_PRIVILEGE_DENIED;
         SysLogException(NID_NET, E_PRIVILEGE_DENIED,
-                       "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+                       "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
     }
     else
     {
-        *pResult = __pNetService->GetAppNetAccountId(profileName, netAccountId);
-        *pNetAccountId = netAccountId;
+       if (GetNetService() == null)
+       {
+            *pResult = E_SYSTEM;
+            SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+               *pResult = GetNetService()->GetAppNetAccountId(profileName, netAccountId);
+               *pNetAccountId = netAccountId;
+       }
     }
 }
 
 void
 NetConnectivityIpcStub::OnSetNetAccountId(int netAccountId, int* pNetAccountId2, unsigned long* pResult)
 {
-       SysSecureLog(NID_NET, "Received the request of setting network account id with clientId : %d, PkgId : %ls",
-            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+       SysSecureLog(NID_NET, "OnSetNetAccountId with clientId[%d] PkgId[%ls] account[%d]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer(), netAccountId);
 
     String pkgId = __pIpcServer->GetClientPackageId();
     int netAccountId2 = INVALID_HANDLE;
 
     *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_CUSTOMNETACCOUNT);
-
     if (*pResult != E_SUCCESS)
     {
         *pResult = E_PRIVILEGE_DENIED;
         SysLogException(NID_NET, E_PRIVILEGE_DENIED,
-                       "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+                       "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
     }
     else
     {
-        *pResult = __pNetService->SetNetAccountId(netAccountId, netAccountId2);
-        *pNetAccountId2 = netAccountId2;
+       if (GetNetService() == null)
+       {
+            *pResult = E_SYSTEM;
+            SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+            *pResult = GetNetService()->SetNetAccountId(netAccountId, netAccountId2);
+            *pNetAccountId2 = netAccountId2;
+       }
     }
 }
 
 void
-NetConnectivityIpcStub::OnUpdateSystemNetAccount(const String& profileName, const NetAccountInfo& netAccountInfo, int bearerType,
-               unsigned long* pResult)
+NetConnectivityIpcStub::OnUpdateSystemNetAccount(const NetAccountInfo& netAccountInfo, unsigned long* pResult)
 {
-       SysSecureLog(NID_NET, "Received the request of updating system network account with clientId : %d, PkgId : %ls",
+       SysSecureLog(NID_NET, "OnUpdateSystemNetAccount with clientId[%d] PkgId[%ls]",
             __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
     String pkgId = __pIpcServer->GetClientPackageId();
 
     *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_NETWORKMANAGER);
-
     if (*pResult != E_SUCCESS)
     {
         *pResult = E_PRIVILEGE_DENIED;
         SysLogException(NID_NET, E_PRIVILEGE_DENIED,
-                       "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+                       "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
     }
     else
     {
-       NetNapAuthType authType;
-       String authId;
-       String authPw;
-       netAccountInfo.GetAuthenticationInfo(authType, authId, authPw);
-
-       SysLog(NID_NET, "ProfileName : %ls, BearerType : %d, AccessPointName : %ls, AccountId : %d, AccountName : %ls",
-                       profileName.GetPointer(), bearerType, netAccountInfo.GetAccessPointName().GetPointer(),
-                       netAccountInfo.GetAccountId(), netAccountInfo.GetAccountName().GetPointer());
-       SysLog(NID_NET, "AuthType : %d, AuthId : %ls, AuthPassword : %ls, HomeURL : %ls",
-                       authType, authId.GetPointer(), authPw.GetPointer(), netAccountInfo.GetHomeUrl().GetPointer());
-
-               if (netAccountInfo.GetDnsAddressScheme() == NET_ADDRESS_SCHEME_STATIC)
-               {
-               SysLog(NID_NET, "Dns Address Scheme is static.");
-
-               if (netAccountInfo.GetPrimaryDnsAddress() != null)
-               {
-                       SysLog(NID_NET, "Primary Dns Address is %ls", netAccountInfo.GetPrimaryDnsAddress()->ToString().GetPointer());
-               }
-
-               if (netAccountInfo.GetSecondaryDnsAddress() != null)
-               {
-                       SysLog(NID_NET, "Secondary Dns Address is %ls", netAccountInfo.GetSecondaryDnsAddress()->ToString().GetPointer());
-               }
-               }
-               else
-               {
-               SysLog(NID_NET, "Dns Address Scheme is dynamic.");
-               }
-
-               if (netAccountInfo.GetLocalAddressScheme() == NET_ADDRESS_SCHEME_STATIC)
-               {
-               SysLog(NID_NET, "Local Address Scheme is static.");
-
-               if (netAccountInfo.GetLocalAddress() != null )
-               {
-                       SysLog(NID_NET, "Local Address is %ls", netAccountInfo.GetLocalAddress()->ToString().GetPointer());
-               }
-               }
-               else
-               {
-               SysLog(NID_NET, "Local Address Scheme is dynamic.");
-               }
-
-       if (netAccountInfo.GetProxyAddress() != null)
+       if (GetNetService() == null)
        {
-               SysLog(NID_NET, "Proxy Address is %ls", netAccountInfo.GetProxyAddress()->GetNetEndPoint().GetPointer());
+            *pResult = E_SYSTEM;
+            SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+               *pResult = GetNetService()->UpdateSystemNetAccount(netAccountInfo);
        }
-
-        *pResult = __pNetService->UpdateSystemNetAccount(profileName, netAccountInfo, bearerType);
     }
 }
 
 void
 NetConnectivityIpcStub::OnResetNetStatistics(int bearerType, int statType, unsigned long* pResult)
 {
-       SysSecureLog(NID_NET, "Received to reset network statistics with bearer: %d, statType : %d, clientId : %d, PkgId : %ls",
-                       bearerType, statType, __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+       SysSecureLog(NID_NET, "OnResetNetStatistics with clientId[%d] PkgId[%ls] bearer[%d] statType[%d]",
+                       __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer(), bearerType, statType);
 
        String pkgId = __pIpcServer->GetClientPackageId();
 
        *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_NETSTATISTICSMANAGER);
-
        if (*pResult != E_SUCCESS)
        {
                *pResult = E_PRIVILEGE_DENIED;
                SysLogException(NID_NET, E_PRIVILEGE_DENIED,
-                               "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+                               "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
        }
        else
        {
-               *pResult = __pNetService->ResetNetStatistics(bearerType, statType);
+       if (GetNetService() == null)
+       {
+            *pResult = E_SYSTEM;
+            SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+               *pResult = GetNetService()->ResetNetStatistics(bearerType, statType);
+       }
        }
 }
 
 void
 NetConnectivityIpcStub::OnResetAllNetStatistics(int bearerType, unsigned long* pResult)
 {
-       SysSecureLog(NID_NET, "Received to reset all network statistics with bearer: %d, clientId : %d, PkgId : %ls",
-                       bearerType, __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+       SysSecureLog(NID_NET, "OnResetAllNetStatistics with clientId[%d] PkgId[%ls] bearer[%d]",
+                       __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer(), bearerType);
 
        String pkgId = __pIpcServer->GetClientPackageId();
 
        *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_NETSTATISTICSMANAGER);
-
        if (*pResult != E_SUCCESS)
        {
                *pResult = E_PRIVILEGE_DENIED;
                SysLogException(NID_NET, E_PRIVILEGE_DENIED,
-                               "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
+                               "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
+       }
+       else
+       {
+       if (GetNetService() == null)
+       {
+            *pResult = E_SYSTEM;
+            SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+               *pResult = GetNetService()->ResetAllNetStatistics(bearerType);
+       }
+       }
+}
+
+void
+NetConnectivityIpcStub::OnAddDefaultConnectionListener(int* pConnectionState, int* pBearerType, NetConnectionInfo* pConnectionInfo, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnAddDefaultConnectionListener with clientId[%d] PkgId[%ls]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (GetNetDefaultConnection() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetDefaultConnection is not ready.");
+       }
+       else
+       {
+        *pResult = GetNetDefaultConnection()->AddEventListener(__pIpcServer->GetClientId(), pConnectionState, pBearerType, pConnectionInfo);
+       }
+}
+
+void
+NetConnectivityIpcStub::OnRemoveDefaultConnectionListener(unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnRemoveDefaultConnectionListener with clientId[%d] PkgId[%ls]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (GetNetDefaultConnection() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetDefaultConnection is not ready.");
+       }
+       else
+       {
+        *pResult = GetNetDefaultConnection()->RemoveEventListener(__pIpcServer->GetClientId());
+       }
+}
+
+void
+NetConnectivityIpcStub::OnAddWifiConnectionListener(int* pConnectionState, NetConnectionInfo* pConnectionInfo, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnAddWifiConnectionListener with clientId[%d] PkgId[%ls]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (GetNetWifiConnection() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetWifiConnection is not ready.");
+       }
+       else
+       {
+        *pResult = GetNetWifiConnection()->AddEventListener(__pIpcServer->GetClientId(), pConnectionState, pConnectionInfo);
+       }
+}
+
+void
+NetConnectivityIpcStub::OnRemoveWifiConnectionListener(unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnRemoveWifiConnectionListener with clientId[%d] PkgId[%ls]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (GetNetWifiConnection() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetWifiConnection is not ready.");
+       }
+       else
+       {
+        *pResult = GetNetWifiConnection()->RemoveEventListener(__pIpcServer->GetClientId());
+       }
+}
+
+void
+NetConnectivityIpcStub::OnStartWifiConnection(unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnStartWifiConnection with clientId[%d] PkgId[%ls]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (GetNetWifiConnection() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetWifiConnection is not ready.");
+       }
+       else
+       {
+        *pResult = GetNetWifiConnection()->Start();
+       }
+}
+
+void
+NetConnectivityIpcStub::OnStartPsConnection(const String& profileName, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnStartPsConnection with clientId[%d] PkgId[%ls] profile[%ls]",
+                       __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer(), profileName.GetPointer());
+
+       NetPsConnection* pConnection = NetPsConnection::GetInstance(profileName, this);
+
+       if (pConnection == null)
+    {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetPsConnection is not ready.");
+    }
+    else
+    {
+        *pResult = pConnection->Start(__pIpcServer->GetClientId());
+    }
+}
+
+void
+NetConnectivityIpcStub::OnStopPsConnection(const String& profileName, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnStopPsConnection with clientId[%d] PkgId[%ls] profile[%ls]",
+                       __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer(), profileName.GetPointer());
+
+       NetPsConnection* pConnection = NetPsConnection::GetInstance(profileName, this);
+
+       if (pConnection == null)
+    {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetPsConnection is not ready.");
+    }
+    else
+    {
+        *pResult = pConnection->Stop(__pIpcServer->GetClientId());
+    }
+}
+
+void
+NetConnectivityIpcStub::OnGetPsConnectionState(const String& profileName, int* pConnectionState, String* pDeviceName, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnGetPsConnectionState with clientId[%d] PkgId[%ls] profile[%ls]",
+                       __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer(), profileName.GetPointer());
+
+       NetPsConnection* pConnection = NetPsConnection::GetInstance(profileName, this);
+
+       if (pConnection == null)
+    {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetPsConnection is not ready.");
+    }
+    else
+    {
+        *pResult = pConnection->GetState(__pIpcServer->GetClientId(), pConnectionState, pDeviceName);
+    }
+}
+
+void
+NetConnectivityIpcStub::OnGetNetAccountName(int netAccountId, String* pNetAccountName, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnGetNetAccountName with clientId[%d] PkgId[%ls] accountId[%d]",
+                       __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer(), netAccountId);
+
+       String netAccountName;
+
+       *pResult = NetAccountDatabase::GetAccountName(netAccountId, netAccountName);
+       if (*pResult == E_SUCCESS)
+       {
+               *pNetAccountName = netAccountName;
+       }
+}
+
+void
+NetConnectivityIpcStub::OnGetNetProfileName(int netAccountId, String* pNetProfileName, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnGetNetProfileName with clientId[%d] PkgId[%ls] accountId[%d]",
+                       __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer(), netAccountId);
+
+       String netProfileName;
+
+       *pResult =      NetAccountDatabase::GetProfileName(netAccountId, netProfileName);
+       if (*pResult == E_SUCCESS)
+       {
+               *pNetProfileName = netProfileName;
+       }
+}
+
+void
+NetConnectivityIpcStub::OnGetNetConnectionInfo(int netAccountId, NetConnectionInfo* pConnectionInfo, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnGetNetConnectionInfo with clientId[%d] PkgId[%ls] accountId[%d]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer(), netAccountId);
+
+       if (GetNetService() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+               *pResult = GetNetService()->GetNetConnectionInfo(netAccountId, pConnectionInfo);
+       }
+}
+
+void
+NetConnectivityIpcStub::OnGetNetAccountInfo(int netAccountId, NetAccountInfo* pAccountInfo, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnGetNetAccountInfo with clientId[%d] PkgId[%ls] accountId[%d]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer(), netAccountId);
+
+       if (GetNetService() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+               *pResult = GetNetService()->GetNetAccountInfo(__pIpcServer->GetClientPackageId(), netAccountId, pAccountInfo);
+       }
+}
+
+void
+NetConnectivityIpcStub::OnGetNetAccountId(const String& accountName, int* pAccountId, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnGetNetAccountId with clientId[%d] PkgId[%ls] accountName[%ls]",
+                       __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer(), accountName.GetPointer());
+
+       NetAccountId netAccountId;
+
+       *pResult =      NetAccountDatabase::GetAccountIdByAccountName(accountName, netAccountId);
+       if (*pResult == E_SUCCESS)
+       {
+               *pAccountId = netAccountId;
+       }
+}
+
+void
+NetConnectivityIpcStub::OnGetInternetNetAccountId(int* pAccountId, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnGetInternetNetAccountId with clientId[%d] PkgId[%ls]",
+                       __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (GetNetService() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+               *pAccountId = GetNetService()->GetInternetAccountId();
+               if (*pAccountId > 0)
+               {
+                       *pResult = E_SUCCESS;
+               }
+               else
+               {
+                       *pResult = GetLastResult();
+               }
+       }
+}
+
+void
+NetConnectivityIpcStub::OnGetMmsNetAccountId(int* pAccountId, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnGetMmsNetAccountId with clientId[%d] PkgId[%ls]",
+                       __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (GetNetService() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+               *pAccountId = GetNetService()->GetMmsAccountId();
+               if (*pAccountId > 0)
+               {
+                       *pResult = E_SUCCESS;
+               }
+               else
+               {
+                       *pResult = GetLastResult();
+               }
+       }
+}
+
+void
+NetConnectivityIpcStub::OnCreateNetAccount(const NetAccountInfo& netAccountInfo, int* pAccountId, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnCreateNetAccount with clientId[%d] PkgId[%ls]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (GetNetService() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+       *pAccountId = GetNetService()->CreateNetAccount(__pIpcServer->GetClientPackageId(), netAccountInfo);
+       if (*pAccountId > 0)
+       {
+               *pResult = E_SUCCESS;
+       }
+       else
+       {
+               *pResult = GetLastResult();
+       }
+       }
+}
+
+void
+NetConnectivityIpcStub::OnDeleteNetAccount(int netAccountId, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnDeleteNetAccount with clientId[%d] PkgId[%ls] accountId[%d]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer(), netAccountId);
+
+       if (GetNetService() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
        }
        else
        {
-               *pResult = __pNetService->ResetAllNetStatistics(bearerType);
+       *pResult = GetNetService()->DeleteNetAccount(__pIpcServer->GetClientPackageId(), netAccountId);
+    }
+}
+
+void
+NetConnectivityIpcStub::OnUpdateNetAccount(const NetAccountInfo& netAccountInfo, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnUpdateNetAccount with clientId[%d] PkgId[%ls]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (GetNetService() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+       *pResult = GetNetService()->UpdateNetAccount(__pIpcServer->GetClientPackageId(), netAccountInfo);
        }
 }
+
+void
+NetConnectivityIpcStub::OnGetNetAccountIds(ArrayListT<int>* pList, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnGetNetAccountIds with clientId[%d] PkgId[%ls]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       *pResult = pList->Construct();
+    SysTryReturnVoidResult(NID_NET, *pResult == E_SUCCESS, *pResult, "[%s] Propagating.", GetErrorMessage(*pResult));
+
+       if (GetNetService() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+       *pResult = GetNetService()->GetNetAccountIds(pList);
+       }
+}
+
+void
+NetConnectivityIpcStub::OnGetNetAccountNames(ArrayList* pList, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnGetNetAccountNames with clientId[%d] PkgId[%ls]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       *pResult = pList->Construct();
+    SysTryReturnVoidResult(NID_NET, *pResult == E_SUCCESS, *pResult, "[%s] Propagating.", GetErrorMessage(*pResult));
+
+       if (GetNetService() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+       __pAccountNameList->RemoveAll(true);
+
+       *pResult = GetNetService()->GetNetAccountNames(__pAccountNameList);
+        SysTryReturnVoidResult(NID_NET, *pResult == E_SUCCESS, *pResult, "[%s] Propagating.", GetErrorMessage(*pResult));
+
+        *pResult = pList->AddItems(*__pAccountNameList);
+   }
+}
+
+void
+NetConnectivityIpcStub::OnGetAllNetConnectionInfo(ArrayListT<NetConnectionInfo*>* pList, unsigned long* pResult)
+{
+       SysSecureLog(NID_NET, "OnGetAllNetConnectionInfo with clientId[%d] PkgId[%ls]",
+            __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       *pResult = pList->Construct();
+    SysTryReturnVoidResult(NID_NET, *pResult == E_SUCCESS, *pResult, "[%s] Propagating.", GetErrorMessage(*pResult));
+
+       if (GetNetService() == null)
+       {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] NetService is not ready.");
+       }
+       else
+       {
+       __pConnectionInfoList->RemoveAll(true);
+
+       *pResult = GetNetService()->GetAllNetConnectionInfo(__pConnectionInfoList);
+        SysTryReturnVoidResult(NID_NET, *pResult == E_SUCCESS, *pResult, "[%s] Propagating.", GetErrorMessage(*pResult));
+
+        unique_ptr<IEnumerator> pEnum(__pConnectionInfoList->GetEnumeratorN());
+        if (pEnum != null)
+        {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+               NetConnectionInfo* pInfo = dynamic_cast<NetConnectionInfo*>(pEnum->GetCurrent());
+               if (pInfo != null)
+               {
+                       pList->Add(pInfo);
+               }
+               }
+        }
+    }
+}
+
+result
+NetConnectivityIpcStub::SendDefaultConnectionChanged(int clientId, unsigned long res, int eventType, int connectionState, int bearerType, const NetConnectionInfo& connectionInfo)
+{
+    SysLog(NID_NET, "SendDefaultConnectionChanged with clientId[%d] state[%d] bearer[%d]", clientId, connectionState, bearerType);
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityNetServiceMsg_onDefaultConnectionChanged(res, eventType, connectionState, bearerType, connectionInfo));
+    SysTryReturnResult(NID_NET, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+NetConnectivityIpcStub::SendWifiConnectionChanged(int clientId, unsigned long res, int eventType, int connectionState, const NetConnectionInfo& connectionInfo)
+{
+    SysLog(NID_NET, "SendWifiConnectionChanged with clientId[%d] state[%d]", clientId, connectionState);
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityNetServiceMsg_onWifiConnectionChanged(res, eventType, connectionState, connectionInfo));
+    SysTryReturnResult(NID_NET, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+NetConnectivityIpcStub::SendPsConnectionStarted(int clientId, const String& profileName, unsigned long res, const NetConnectionInfo& connectionInfo)
+{
+    SysLog(NID_NET, "SendPsConnectionStarted with clientId[%d] profileName[%ls] result[%s]", clientId, profileName.GetPointer(), GetErrorMessage(res));
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityNetServiceMsg_onPsConnectionStarted(profileName, res, connectionInfo));
+    SysTryReturnResult(NID_NET, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+NetConnectivityIpcStub::SendPsConnectionStopped(int clientId, const String& profileName, unsigned long res)
+{
+    SysLog(NID_NET, "SendPsConnectionStopped with clientId[%d] profileName[%ls] result[%s]", clientId, profileName.GetPointer(), GetErrorMessage(res));
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityNetServiceMsg_onPsConnectionStopped(profileName, res));
+    SysTryReturnResult(NID_NET, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+NetConnectivityIpcStub::SendDefaultProxyChanged(int clientId, const String& proxy)
+{
+    SysLog(NID_NET, "SendDefaultProxyChanged with clientId[%d] proxy[%ls]", clientId, proxy.GetPointer());
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityNetServiceMsg_onDefaultProxyChanged(proxy));
+    SysTryReturnResult(NID_NET, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+NetService*
+NetConnectivityIpcStub::GetNetService(void)
+{
+       if (__pNetService == null)
+       {
+               __pNetService = NetService::GetInstance();
+       }
+
+       return __pNetService;
+}
+
+NetDefaultConnection*
+NetConnectivityIpcStub::GetNetDefaultConnection(void)
+{
+       if (__pNetDefaultConnection == null)
+       {
+               __pNetDefaultConnection = NetDefaultConnection::GetInstance(this);
+       }
+
+       return __pNetDefaultConnection;
+}
+
+NetWifiConnection*
+NetConnectivityIpcStub::GetNetWifiConnection(void)
+{
+       if (__pNetWifiConnection == null)
+       {
+               __pNetWifiConnection = NetWifiConnection::GetInstance(this);
+       }
+
+       return __pNetWifiConnection;
+}
+
diff --git a/src/NetDefaultConnection.cpp b/src/NetDefaultConnection.cpp
new file mode 100755 (executable)
index 0000000..a7fdcc7
--- /dev/null
@@ -0,0 +1,390 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+/**
+ * @file               NetDefaultConnection.cpp
+ * @brief              This is the implementation file for NetDefaultConnection class.
+ * @version    3.0
+ *
+ * This file contains the implementation of NetDefaultConnection class.
+ */
+
+#include <net_connection.h>
+#include <FNetNetConnectionInfo.h>
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include <FNet_NetTypes.h>
+#include <FNet_NetConnectionInfoImpl.h>
+#include "ConnectivityUtility.h"
+#include "NetDefaultConnection.h"
+#include "NetConnectivityIpcStub.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Net;
+
+
+NetDefaultConnection* NetDefaultConnection::__pNetDefaultConnection = null;
+
+NetDefaultConnection*
+NetDefaultConnection::GetInstance(NetConnectivityIpcStub* pStub)
+{
+    result r = E_SUCCESS;
+
+    if (__pNetDefaultConnection == null)
+       {
+               unique_ptr<NetDefaultConnection> pInstance(new (std::nothrow) NetDefaultConnection());
+               SysTryReturn(NID_NET, pInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+               r = pInstance->Construct(pStub);
+               SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+               __pNetDefaultConnection = pInstance.release();
+       }
+
+       return __pNetDefaultConnection;
+}
+
+NetDefaultConnection::NetDefaultConnection(void)
+       : __pStub(null)
+       , __isInitialized(false)
+       , __pConnectionHandle(null)
+       , __pClientList(null)
+       , __clientCount(0)
+{
+}
+
+NetDefaultConnection::~NetDefaultConnection(void)
+{
+       if (__pConnectionHandle != null)
+       {
+               connection_destroy(__pConnectionHandle);
+       }
+}
+
+result
+NetDefaultConnection::Construct(NetConnectivityIpcStub* pStub)
+{
+    result r = E_SUCCESS;
+
+    unique_ptr< ArrayListT<int> > pClientList(new (std::nothrow) ArrayListT<int>());
+    SysTryReturnResult(NID_NET, pClientList != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    r = pClientList->Construct();
+    SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       int err = CONNECTION_ERROR_NONE;
+
+       err = connection_create(&__pConnectionHandle);
+       SysLog(NID_NET, "The return value of connection_create() is 0x%x", err);
+    SysTryReturnResult(NID_NET, err == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to create a connection handle.");
+
+    __pStub = pStub;
+    __pClientList = move(pClientList);
+    __clientCount = 0;
+
+    return E_SUCCESS;
+}
+
+void
+NetDefaultConnection::ActiveConnectionTypeChangedCallback(connection_type_e type, void* pUserData)
+{
+       SysLog(NID_NET, "ActiveConnectionTypeChangedCallback() has been called with type : %d", type);
+
+       NetDefaultConnection* pThis = static_cast<NetDefaultConnection*>(pUserData);
+       SysTryReturnVoidResult(NID_NET, pThis != null, E_SYSTEM, "[E_SYSTEM] The instance handle is NULL.");
+
+       bool isBearerChanged = false;
+       int ret = CONNECTION_ERROR_NONE;
+       connection_h connectionHandle = pThis->__pConnectionHandle;
+       connection_profile_h profileHandle = null;
+
+       if (type != CONNECTION_TYPE_DISCONNECTED)
+       {
+               // Connected
+               if ((type == CONNECTION_TYPE_WIFI) && (pThis->__bearerType != NET_BEARER_WIFI))
+               {
+                       isBearerChanged = true;
+               }
+               else if ((type == CONNECTION_TYPE_CELLULAR) && (pThis->__bearerType != NET_BEARER_PS))
+               {
+                       isBearerChanged = true;
+               }
+
+               NetConnectionState oldState = pThis->__connectionState;
+
+               ret = connection_get_current_profile(connectionHandle, &profileHandle);
+               SysTryReturnVoidResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                               "[%s] The return value from connection_get_current_profile() is %d", GetErrorMessage(E_SYSTEM), ret);
+
+               pThis->UpdateConnectionInfo(profileHandle);
+               connection_profile_destroy(profileHandle);
+
+               if (oldState != NET_CONNECTION_STATE_STARTED)
+               {
+                       pThis->HandleEvent(_NET_CONNECTION_EVENT_TYPE_STARTED);
+               }
+               else if (isBearerChanged)
+               {
+                       pThis->HandleEvent(_NET_CONNECTION_EVENT_TYPE_CHANGED);
+               }
+               else
+               {
+                       SysLog(NID_NET, "Ignore the event, because this is already in started state.");
+               }
+       }
+       else
+       {
+               // Not connected
+               if ((pThis->__connectionState != NET_CONNECTION_STATE_NONE) && (pThis->__connectionState != NET_CONNECTION_STATE_STOPPED))
+               {
+                       pThis->UpdateConnectionInfo(null);
+                       pThis->HandleEvent(_NET_CONNECTION_EVENT_TYPE_STOPPED, E_NETWORK_FAILED);
+               }
+               else
+               {
+                       SysLog(NID_NET, "Ignore the event, because this is already in stopped state.");
+               }
+       }
+}
+
+void
+NetDefaultConnection::ActiveConnectionProxyChangedCallback(const char* pIpv4Address, const char* pIpv6Address, void *pUserData)
+{
+       NetDefaultConnection* pThis = static_cast<NetDefaultConnection*>(pUserData);
+       SysTryReturnVoidResult(NID_NET, pThis != null, E_SYSTEM, "[E_SYSTEM] The instance handle is NULL.");
+
+       String proxy = String(pIpv4Address);
+       _NetConnectionInfoImpl* pConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(pThis->__connectionInfo);
+       SysTryReturnVoidResult(NID_NET, pConnectionInfoImpl != null, E_SYSTEM, "[E_SYSTEM] The connection info is not initialized.");
+
+       String before = pConnectionInfoImpl->GetProxyAddress();
+
+       SysLog(NID_NET, "Set proxy address [%ls]->[%ls]", before.GetPointer(), proxy.GetPointer());
+       pConnectionInfoImpl->SetProxyAddress(proxy);
+
+       String after = pConnectionInfoImpl->GetProxyAddress();
+
+       if (before != after)
+       {
+               SysLog(NID_NET, "Default proxy is changed. [%ls]->[%ls]", before.GetPointer(), after.GetPointer());
+
+               result r = E_SUCCESS;
+               int clientId = 0;
+
+               unique_ptr< IEnumeratorT<int> > pEnum(pThis->__pClientList->GetEnumeratorN());
+               if (pEnum != null)
+               {
+                       while (pEnum->MoveNext() == E_SUCCESS)
+                       {
+                               r = pEnum->GetCurrent(clientId);
+                               if ((r == E_SUCCESS) && (clientId > 0))
+                               {
+                                       pThis->__pStub->SendDefaultProxyChanged(clientId, pConnectionInfoImpl->GetProxyAddress());
+                               }
+                       }
+               }
+       }
+}
+
+result
+NetDefaultConnection::AddEventListener(int clientId, int* pConnectionState, int* pBearerType, NetConnectionInfo* pInfo)
+{
+       result r = E_SUCCESS;
+       int err = CONNECTION_ERROR_NONE;
+
+       r = __pClientList->Add(clientId);
+    SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+//     if (__clientCount == 0)
+       if (!__isInitialized)
+       {
+               SysLog(NID_NET, "Set default network event callback.");
+
+               connection_type_e type = CONNECTION_TYPE_DISCONNECTED;
+
+               err = connection_set_type_changed_cb(__pConnectionHandle, (connection_type_changed_cb)NetDefaultConnection::ActiveConnectionTypeChangedCallback, this);
+               if (err != CONNECTION_ERROR_NONE)
+               {
+                       SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The return value from connection_set_type_changed_cb() is [%d]", err);
+                       __pClientList->Remove(clientId);
+
+               return E_SYSTEM;
+               }
+
+               err = connection_set_proxy_address_changed_cb(__pConnectionHandle, (connection_address_changed_cb)NetDefaultConnection::ActiveConnectionProxyChangedCallback, this);
+               if (err != CONNECTION_ERROR_NONE)
+               {
+                       SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The return value from connection_set_proxy_address_changed_cb() is [%d]", err);
+               connection_unset_type_changed_cb(__pConnectionHandle);
+                       __pClientList->Remove(clientId);
+
+               return E_SYSTEM;
+               }
+
+               err = connection_get_type(__pConnectionHandle, &type);
+               if (err != CONNECTION_ERROR_NONE)
+               {
+                       SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The return value from connection_get_type() is [%d]", err);
+                       connection_unset_proxy_address_changed_cb(__pConnectionHandle);
+               connection_unset_type_changed_cb(__pConnectionHandle);
+                       __pClientList->Remove(clientId);
+
+               return E_SYSTEM;
+               }
+
+               if (type != CONNECTION_TYPE_DISCONNECTED)
+               {
+                       // Default connection is ON
+                       SysLog(NID_NET, "Default connection is ON. type=%d", type);
+
+                       connection_profile_h profileHandle = null;
+
+                       err = connection_get_current_profile(__pConnectionHandle, &profileHandle);
+                       if (err == CONNECTION_ERROR_NONE)
+                       {
+                               UpdateConnectionInfo(profileHandle);
+                               connection_profile_destroy(profileHandle);
+                       }
+                       else
+                       {
+                               SysLog(NID_NET, "The return value from connection_get_current_profile() is %d", err);
+                               UpdateConnectionInfo(null);
+                       }
+               }
+               else
+               {
+                       // Default connection is OFF
+                       SysLog(NID_NET, "Default connection is OFF.");
+                       UpdateConnectionInfo(null);
+               }
+
+               __isInitialized = true;
+       }
+#if 0
+       else
+       {
+               char* pProxy = null;
+
+           err = connection_get_proxy(__pConnectionHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pProxy);
+           if (pProxy != null)
+           {
+               String proxy = String(pProxy);
+               free(pProxy);
+
+               _NetConnectionInfoImpl* pConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(__connectionInfo);
+               if (pConnectionInfoImpl != null)
+               {
+                               SysLog(NID_NET, "Set proxy address [%ls]->[%ls]", pConnectionInfoImpl->GetProxyAddress().GetPointer(), proxy.GetPointer());
+                       pConnectionInfoImpl->SetProxyAddress(proxy);
+               }
+           }
+       }
+#endif
+
+    __clientCount++;
+
+    *pConnectionState = __connectionState;
+    *pBearerType = __bearerType;
+    *pInfo = __connectionInfo;
+
+       return E_SUCCESS;
+}
+
+result
+NetDefaultConnection::RemoveEventListener(int clientId)
+{
+       if (!__pClientList->Contains(clientId))
+       {
+               SysLog(NID_NET, "Client[%d] is not found, so ignore the request.", clientId);
+               return E_SUCCESS;
+       }
+
+       result r = __pClientList->Remove(clientId);
+       if (r == E_SUCCESS)
+       {
+               __clientCount--;
+       }
+
+#if 0
+       if (__clientCount == 0)
+       {
+               SysLog(NID_NET, "Unset default network event callback.");
+
+               connection_unset_proxy_address_changed_cb(__pConnectionHandle);
+               connection_unset_type_changed_cb(__pConnectionHandle);
+       }
+#endif
+
+       return E_SUCCESS;
+}
+
+void
+NetDefaultConnection::HandleEvent(_NetConnectionEventType type, result error)
+{
+       result r = E_SUCCESS;
+       int clientId = 0;
+
+       unique_ptr< IEnumeratorT<int> > pEnum(__pClientList->GetEnumeratorN());
+       if (pEnum != null)
+       {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       r = pEnum->GetCurrent(clientId);
+                       if ((r == E_SUCCESS) && (clientId > 0))
+                       {
+                           __pStub->SendDefaultConnectionChanged(clientId, error, type, __connectionState, __bearerType, __connectionInfo);
+                       }
+               }
+       }
+}
+
+void
+NetDefaultConnection::UpdateConnectionInfo(void* pData)
+{
+       _NetConnectionInfoImpl* pConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(__connectionInfo);
+       SysTryReturnVoidResult(NID_NET, pConnectionInfoImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Connection information is null.");
+
+       connection_profile_h profileHandle = pData;
+       connection_profile_type_e type = CONNECTION_PROFILE_TYPE_WIFI;
+       int ret = CONNECTION_ERROR_NONE;
+
+       if (pData != null)
+       {
+               ret = connection_profile_get_type(profileHandle, &type);
+               SysLog(NID_NET, "The return value from connection_profile_get_type() is %d, Type is %d", ret, type);
+               if (type == CONNECTION_PROFILE_TYPE_WIFI)
+               {
+                       __bearerType = NET_BEARER_WIFI;
+               }
+               else
+               {
+                       __bearerType = NET_BEARER_PS;
+               }
+
+               __connectionState = NET_CONNECTION_STATE_STARTED;
+               ConnectivityUtility::UpdateNetConnectionInfo(&__connectionInfo, pData, true);
+       }
+       else
+       {
+               __bearerType = NET_BEARER_NONE;
+               __connectionState = NET_CONNECTION_STATE_STOPPED;
+               pConnectionInfoImpl->Clear();
+       }
+}
+
diff --git a/src/NetPsConnection.cpp b/src/NetPsConnection.cpp
new file mode 100755 (executable)
index 0000000..515e8ec
--- /dev/null
@@ -0,0 +1,514 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+/**
+ * @file               NetPsConnection.cpp
+ * @brief              This is the implementation file for NetPsConnection class.
+ * @version    3.0
+ *
+ * This file contains the implementation of NetPsConnection class.
+ */
+
+#include <net_connection.h>
+#include <FNetNetConnectionInfo.h>
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include "FNet_NetTypes.h"
+#include "FNet_NetConnectionInfoImpl.h"
+#include "ConnectivityUtility.h"
+#include "NetPsConnection.h"
+#include "NetConnectivityIpcStub.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Net;
+
+
+HashMap* NetPsConnection::__pPsConnectionMap = null;
+
+
+NetPsConnection*
+NetPsConnection::GetInstance(const String& profileName, NetConnectivityIpcStub* pStub)
+{
+    result r = E_SUCCESS;
+
+       if (__pPsConnectionMap == null)
+       {
+               unique_ptr<HashMap> pHashMap(new (std::nothrow) HashMap());
+               SysTryReturn(NID_NET, pHashMap != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+               r = pHashMap->Construct();
+               SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+               __pPsConnectionMap = pHashMap.release();
+       }
+
+       NetPsConnection* pConnection = null;
+
+       if (__pPsConnectionMap->ContainsKey(profileName))
+       {
+               pConnection = dynamic_cast<NetPsConnection*>(__pPsConnectionMap->GetValue(profileName));
+       }
+
+       if (pConnection == null)
+       {
+               pConnection = new (std::nothrow) NetPsConnection();
+               SysTryReturn(NID_NET, pConnection != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+               r = pConnection->Construct(profileName, pStub);
+               if (r != E_SUCCESS)
+               {
+                       SysLogException(NID_NET, r, "[%s] Propagating.", GetErrorMessage(r));
+
+                       delete pConnection;
+                       pConnection = null;
+               }
+               else
+               {
+                       r = __pPsConnectionMap->Add(&pConnection->__profileName, pConnection);
+                       if (r != E_SUCCESS)
+                       {
+                               SysLogException(NID_NET, r, "[%s] Propagating.", GetErrorMessage(r));
+
+                               delete pConnection;
+                               pConnection = null;
+                       }
+               }
+       }
+
+       return pConnection;
+}
+
+void
+NetPsConnection::StopAll(int clientId)
+{
+    result r = E_SUCCESS;
+
+       if (__pPsConnectionMap == null)
+       {
+               SysLog(NID_NET, "NetPsConnection is not used yet. so ignore the request.");
+               return;
+       }
+
+       unique_ptr<IMapEnumerator> pEnum(__pPsConnectionMap->GetMapEnumeratorN());
+       if (pEnum != null)
+       {
+               NetPsConnection* pConnection = null;
+
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pConnection = dynamic_cast<NetPsConnection*>(pEnum->GetValue());
+                       if (pConnection != null)
+                       {
+                               r = pConnection->Stop(clientId);
+                       }
+               }
+       }
+}
+
+NetPsConnection::NetPsConnection(void)
+       : __pStub(null)
+       , __connectionState(NET_CONNECTION_STATE_NONE)
+       , __pConnectionHandle(null)
+       , __pProfileHandle(null)
+       , __pClientList(null)
+       , __clientCount(0)
+{
+}
+
+NetPsConnection::~NetPsConnection(void)
+{
+       if (__pProfileHandle != null)
+       {
+               connection_profile_destroy(__pProfileHandle);
+       }
+
+       if (__pConnectionHandle != null)
+       {
+               connection_destroy(__pConnectionHandle);
+       }
+}
+
+result
+NetPsConnection::Construct(const String& profileName, NetConnectivityIpcStub* pStub)
+{
+    result r = E_SUCCESS;
+
+    unique_ptr< ArrayListT<int> > pClientList(new (std::nothrow) ArrayListT<int>());
+    SysTryReturnResult(NID_NET, pClientList != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    r = pClientList->Construct();
+    SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       int err = CONNECTION_ERROR_NONE;
+
+       err = connection_create(&__pConnectionHandle);
+       SysLog(NID_NET, "The return value of connection_create() is 0x%x", err);
+    SysTryReturnResult(NID_NET, err == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to create a connection handle.");
+
+    __pProfileHandle = ConnectivityUtility::GetPsProfileHandleN(profileName);
+    if (__pProfileHandle == null)
+    {
+               SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] Failed to get profile handle.");
+               connection_destroy(__pConnectionHandle);
+               __pConnectionHandle = null;
+
+               return E_SYSTEM;
+    }
+
+    err = connection_profile_set_state_changed_cb(__pProfileHandle, NetPsConnection::PsConnectionStateChangedCallback, this);
+    if (err != CONNECTION_ERROR_NONE)
+    {
+               SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. The return value from connection_profile_set_state_changed_cb() is %d", err);
+               connection_profile_destroy(__pProfileHandle);
+               __pProfileHandle = null;
+               connection_destroy(__pConnectionHandle);
+               __pConnectionHandle = null;
+
+               return E_SYSTEM;
+    }
+
+    __pStub = pStub;
+    __profileName = profileName;
+    __pClientList = move(pClientList);
+    __clientCount = 0;
+
+    return E_SUCCESS;
+}
+
+void
+NetPsConnection::PsConnectionOpenCallback(connection_error_e res, void* pUserData)
+{
+       NetPsConnection* pThis = static_cast<NetPsConnection*>(pUserData);
+       NetConnectionState connectionState = pThis->__connectionState;
+       bool isConnected = false;
+       char* pProfileName = null;
+       char* pProfileDisplayName = null;
+       int ret = CONNECTION_ERROR_NONE;
+       connection_profile_h profileHandle = pThis->__pProfileHandle;
+       connection_profile_state_e state = CONNECTION_PROFILE_STATE_DISCONNECTED;
+
+       ret = connection_profile_refresh(profileHandle);
+       ret = connection_profile_get_id(profileHandle, &pProfileName);
+       ret = connection_profile_get_name(profileHandle, &pProfileDisplayName);
+       ret = connection_profile_get_state(profileHandle, &state);
+
+       SysSecureLog(NID_NET, "PsConnectionOpenCallback() has been called with res:%d, state:%d, name:[%s][%s]", res, state, pProfileDisplayName, pProfileName);
+
+       if ((res == CONNECTION_ERROR_NONE) && (state == CONNECTION_PROFILE_STATE_CONNECTED))
+       {
+               SysLog(NID_NET, "Profile[%s] is connected.", pProfileName);
+               isConnected = true;
+       }
+       else
+       {
+               SysLog(NID_NET, "Profile[%s] is disconnected.", pProfileName);
+               isConnected = false;
+       }
+
+       free(pProfileName);
+       free(pProfileDisplayName);
+
+       if (connectionState != NET_CONNECTION_STATE_STARTING)
+       {
+               SysLog(NID_NET, "Ignore open response because it is in state[%d].", connectionState);
+               return;
+       }
+
+       if (isConnected)
+       {
+               pThis->HandleEvent(_NET_CONNECTION_EVENT_TYPE_STARTED, E_SUCCESS);
+       }
+       else
+       {
+               pThis->HandleEvent(_NET_CONNECTION_EVENT_TYPE_STOPPED, E_NETWORK_FAILED);
+       }
+}
+
+void
+NetPsConnection::PsConnectionCloseCallback(connection_error_e res, void* pUserData)
+{
+       NetPsConnection* pThis = static_cast<NetPsConnection*>(pUserData);
+       NetConnectionState connectionState = pThis->__connectionState;
+       bool isConnected = false;
+       char* pProfileName = null;
+       char* pProfileDisplayName = null;
+       int ret = CONNECTION_ERROR_NONE;
+       connection_profile_h profileHandle = pThis->__pProfileHandle;
+       connection_profile_state_e state = CONNECTION_PROFILE_STATE_DISCONNECTED;
+
+       ret = connection_profile_refresh(profileHandle);
+       ret = connection_profile_get_id(profileHandle, &pProfileName);
+       ret = connection_profile_get_name(profileHandle, &pProfileDisplayName);
+       ret = connection_profile_get_state(profileHandle, &state);
+
+       SysSecureLog(NID_NET, "PsConnectionCloseCallback() has been called with res:%d, state:%d, name:[%s][%s]", res, state, pProfileDisplayName, pProfileName);
+
+       if (state == CONNECTION_PROFILE_STATE_CONNECTED)
+       {
+               SysLog(NID_NET, "Profile[%s] is connected.", pProfileName);
+               isConnected = true;
+       }
+       else
+       {
+               SysLog(NID_NET, "Profile[%s] is disconnected.", pProfileName);
+               isConnected = false;
+       }
+
+       free(pProfileName);
+       free(pProfileDisplayName);
+
+       if (connectionState != NET_CONNECTION_STATE_STOPPING)
+       {
+               SysLog(NID_NET, "Ignore close response because it is in state[%d].", connectionState);
+               return;
+       }
+
+       pThis->HandleEvent(_NET_CONNECTION_EVENT_TYPE_STOPPED, E_SUCCESS);
+}
+
+void
+NetPsConnection::PsConnectionStateChangedCallback(connection_profile_state_e state, void* pUserData)
+{
+       NetPsConnection* pThis = static_cast<NetPsConnection*>(pUserData);
+       NetConnectionState connectionState = pThis->__connectionState;
+       bool isConnected = false;
+       char* pProfileName = null;
+       char* pProfileDisplayName = null;
+       int ret = CONNECTION_ERROR_NONE;
+       connection_profile_h profileHandle = pThis->__pProfileHandle;
+
+       ret = connection_profile_refresh(profileHandle);
+       ret = connection_profile_get_id(profileHandle, &pProfileName);
+       ret = connection_profile_get_name(profileHandle, &pProfileDisplayName);
+
+       SysSecureLog(NID_NET, "PsConnectionStateChangedCallback() has been called with state:%d, name:[%s][%s]", state, pProfileDisplayName, pProfileName);
+
+       if (state == CONNECTION_PROFILE_STATE_CONNECTED)
+       {
+               SysLog(NID_NET, "Profile[%s] is connected.", pProfileName);
+               isConnected = true;
+       }
+       else
+       {
+               SysLog(NID_NET, "Profile[%s] is disconnected.", pProfileName);
+               isConnected = false;
+       }
+
+       free(pProfileName);
+       free(pProfileDisplayName);
+
+       if ((connectionState == NET_CONNECTION_STATE_STARTING) || (connectionState == NET_CONNECTION_STATE_STOPPING))
+       {
+               SysLog(NID_NET, "Ignore (not requested) event because it is in state[%d].", connectionState);
+               return;
+       }
+
+       if (isConnected)
+       {
+               // Start event
+               SysLog(NID_NET, "Ignore started event.");
+       }
+       else
+       {
+               // Stop event
+               pThis->HandleEvent(_NET_CONNECTION_EVENT_TYPE_STOPPED, E_NETWORK_FAILED);
+       }
+}
+
+result
+NetPsConnection::Start(int clientId)
+{
+       result r = E_SUCCESS;
+
+       r = __pClientList->Add(clientId);
+    SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       if (__connectionState == NET_CONNECTION_STATE_STARTED)
+       {
+               // Already Started
+               SysLog(NID_NET, "PS connection[%ls] is already started.", __profileName.GetPointer());
+
+               r = __pStub->SendPsConnectionStarted(clientId, __profileName, E_SUCCESS, __connectionInfo);
+           SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+       }
+       else if ((__connectionState == NET_CONNECTION_STATE_STARTING) || (__connectionState == NET_CONNECTION_STATE_STOPPING))
+       {
+               // Waiting Response
+               SysLog(NID_NET, "PS connection[%ls] is waiting response.", __profileName.GetPointer());
+       }
+       else
+       {
+               // None or Stopped
+               SysLog(NID_NET, "PS connection[%ls] is not active, so start now.", __profileName.GetPointer());
+
+               int ret = CONNECTION_ERROR_NONE;
+
+               ret = connection_open_profile(__pConnectionHandle, __pProfileHandle, NetPsConnection::PsConnectionOpenCallback, this);
+           SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "The return value from connection_open_profile() is [%d].", ret);
+
+               __connectionState = NET_CONNECTION_STATE_STARTING;
+       }
+
+    __clientCount++;
+
+       return E_SUCCESS;
+}
+
+result
+NetPsConnection::Stop(int clientId)
+{
+       if (!__pClientList->Contains(clientId))
+       {
+               SysLog(NID_NET, "Client[%d] is not found, so ignore the request.", clientId);
+               return E_SUCCESS;
+       }
+
+       result r = __pClientList->Remove(clientId);
+       if (r == E_SUCCESS)
+       {
+               __clientCount--;
+       }
+
+       if (__clientCount == 0)
+       {
+               SysLog(NID_NET, "Stop ps connection.");
+
+               if (__connectionState == NET_CONNECTION_STATE_STARTED)
+               {
+                       SysLog(NID_NET, "PS connection[%ls] is not used any longer, so stop it.", __profileName.GetPointer());
+
+                       int ret = CONNECTION_ERROR_NONE;
+
+                       ret = connection_close_profile(__pConnectionHandle, __pProfileHandle, NetPsConnection::PsConnectionCloseCallback, this);
+                       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                                       "A system error has been occurred. The return value from connection_close_profile() is %d", ret);
+
+                       __connectionState = NET_CONNECTION_STATE_STOPPING;
+               }
+               else if ((__connectionState == NET_CONNECTION_STATE_STOPPING) ||
+                               (__connectionState == NET_CONNECTION_STATE_STARTING))
+               {
+                       // Waiting Response
+                       SysLog(NID_NET, "PS connection[%ls] is waiting response.", __profileName.GetPointer());
+               }
+               else
+               {
+                       // None or Stopped
+                       SysLog(NID_NET, "PS connection[%ls] is already stopped.", __profileName.GetPointer());
+               }
+       }
+
+       return E_SUCCESS;
+}
+
+result
+NetPsConnection::GetState(int clientId, int* pConnectionState, String* pDeviceName)
+{
+       _NetConnectionInfoImpl* pConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(__connectionInfo);
+       SysTryReturnResult(NID_NET, pConnectionInfoImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Connection information is null.");
+
+       *pConnectionState = __connectionState;
+       *pDeviceName = pConnectionInfoImpl->GetDeviceName();
+
+       return E_SUCCESS;
+}
+
+void
+NetPsConnection::HandleEvent(_NetConnectionEventType type, result error)
+{
+       result r = E_SUCCESS;
+       int clientId = 0;
+
+       if ((type == _NET_CONNECTION_EVENT_TYPE_STARTED) && (error == E_SUCCESS))
+       {
+               __connectionState = NET_CONNECTION_STATE_STARTED;
+               UpdateConnectionInfo(__pProfileHandle);
+
+               if (__clientCount == 0)
+               {
+                       SysLog(NID_NET, "Connection is started, but not used any more, so stop it.");
+
+                       int ret = CONNECTION_ERROR_NONE;
+
+                       ret = connection_close_profile(__pConnectionHandle, __pProfileHandle, NetPsConnection::PsConnectionCloseCallback, this);
+                       if (ret == CONNECTION_ERROR_NONE)
+                       {
+                               __connectionState = NET_CONNECTION_STATE_STOPPING;
+                       }
+               }
+       }
+       else
+       {
+               if ((__connectionState == NET_CONNECTION_STATE_STOPPING) && (__clientCount > 0))
+               {
+                       SysLog(NID_NET, "Connection is stopped, but another start request is found, so start the connection.");
+
+                       int ret = CONNECTION_ERROR_NONE;
+
+                       ret = connection_open_profile(__pConnectionHandle, __pProfileHandle, NetPsConnection::PsConnectionOpenCallback, this);
+                       SysLog(NID_NET, "Invoke connection_open_profile() ret[%d].", ret);
+                       if (ret == CONNECTION_ERROR_NONE)
+                       {
+                               __connectionState = NET_CONNECTION_STATE_STARTING;
+                               return;
+                       }
+               }
+
+               __connectionState = NET_CONNECTION_STATE_STOPPED;
+               UpdateConnectionInfo(null);
+       }
+
+       unique_ptr< IEnumeratorT<int> > pEnum(__pClientList->GetEnumeratorN());
+       if (pEnum != null)
+       {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       r = pEnum->GetCurrent(clientId);
+                       if ((r == E_SUCCESS) && (clientId > 0))
+                       {
+                               if (type == _NET_CONNECTION_EVENT_TYPE_STARTED)
+                               {
+                                       __pStub->SendPsConnectionStarted(clientId, __profileName, error, __connectionInfo);
+                               }
+                               else
+                               {
+                                       __pStub->SendPsConnectionStopped(clientId, __profileName, error);
+                               }
+                       }
+               }
+       }
+}
+
+void
+NetPsConnection::UpdateConnectionInfo(void* pData)
+{
+       _NetConnectionInfoImpl* pConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(__connectionInfo);
+       SysTryReturnVoidResult(NID_NET, pConnectionInfoImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Connection information is null.");
+
+       if (pData != null)
+       {
+               __connectionState = NET_CONNECTION_STATE_STARTED;
+               ConnectivityUtility::UpdateNetConnectionInfo(&__connectionInfo, pData, false);
+       }
+       else
+       {
+               __connectionState = NET_CONNECTION_STATE_STOPPED;
+               pConnectionInfoImpl->Clear();
+       }
+}
old mode 100644 (file)
new mode 100755 (executable)
index 7d8fa9a..14b9b23
  */
 
 #include <net_connection.h>
-#include <FApp_AppManagerImpl.h>
 #include <FBaseSysLog.h>
-
-#include <FNetNetAccountManager.h>
 #include <FBaseString.h>
+#include <FNetNetAccountManager.h>
+#include <FNetNetConnectionInfo.h>
+#include <FApp_AppManagerImpl.h>
+#include <FBase_StringConverter.h>
 #include <FNet_NetTypes.h>
-#include "FBase_StringConverter.h"
+#include <FNet_NetAccountInfoImpl.h>
+#include "ConnectivityUtility.h"
 #include "NetService.h"
+#include "NetAccountDatabase.h"
 
+using namespace std;
 using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
 using namespace Tizen::Net;
 
 
+NetService* NetService::__pNetService = null;
+
+
+NetService*
+NetService::GetInstance(void)
+{
+    result r = E_SUCCESS;
+
+    if (__pNetService == null)
+       {
+               unique_ptr<NetService> pInstance(new (std::nothrow) NetService());
+               SysTryReturn(NID_NET, pInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+               r = pInstance->Construct();
+               SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+               __pNetService = pInstance.release();
+       }
+
+       return __pNetService;
+}
+
+
 NetService::NetService(void)
        : __pConnectionHandle(null)
+       , __internetAccountId(INVALID_HANDLE)
+       , __mmsAccountId(INVALID_HANDLE)
 {
-       int ret = CONNECTION_ERROR_NONE;
-       ret = connection_create(&__pConnectionHandle);
-
-       SysLog(NID_NET, "The return value from connection_create() is %d", ret);
+       __internetProfileName.Clear();
+       __mmsProfileName.Clear();
 }
 
 NetService::~NetService(void)
@@ -53,17 +81,34 @@ NetService::~NetService(void)
 }
 
 result
+NetService::Construct(void)
+{
+       result r = E_SUCCESS;
+       int ret = CONNECTION_ERROR_NONE;
+
+       r = NetAccountDatabase::InitializeRepository();
+    SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+    UpdateNetAccountDb();
+
+       ret = connection_create(&__pConnectionHandle);
+    SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to create a connection handle.[%d]", ret);
+
+    return E_SUCCESS;
+}
+
+result
 NetService::GetAppNetAccountId(const String& profileName, int& netAccountId)
 {
        result r = E_SUCCESS;
 
        if (profileName.Equals(L"Internet", false))
        {
-               netAccountId = _DEFAULT_PS_ACCOUNT_ID;
+               netAccountId = GetInternetAccountId();
        }
        else if (profileName.Equals(L"Mms", false))
        {
-               netAccountId = _DEFAULT_MMS_ACCOUNT_ID;
+               netAccountId = GetMmsAccountId();
        }
        else
        {
@@ -84,10 +129,8 @@ NetService::SetNetAccountId(int netAccountId, int& netAccountId2)
        return r;
 }
 
-
-
 result
-NetService::UpdateSystemNetAccount(const String& profileName, const NetAccountInfo& netAccountInfo, int bearerType)
+NetService::UpdateSystemNetAccount(const NetAccountInfo& netAccountInfo)
 {
        result r = E_SUCCESS;
 
@@ -95,17 +138,20 @@ NetService::UpdateSystemNetAccount(const String& profileName, const NetAccountIn
        connection_h connectionHandle = null;
        connection_profile_h profileHandle = null;
 
+       String profileName;
+
+       r = NetAccountDatabase::GetProfileName(netAccountInfo.GetAccountId(), profileName);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
        ret = connection_create(&connectionHandle);
        SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
                        "A system error has been occurred. The return value from connection_create() is %d", ret);
 
-       SysAssertf(connectionHandle != null, "Not yet constructed. Construct() should be called before use.");
-
-       profileHandle = GetPsProfileHandleN(profileName);
+       profileHandle = ConnectivityUtility::GetPsProfileHandleN(profileName);
        SysTryReturnResult(NID_NET, profileHandle != null, E_INVALID_ACCOUNT,
                        "Invalid network account. The current value of account id is %d", netAccountInfo.GetAccountId());
 
-       r = ConvertToProfileInfo((void*)profileHandle, netAccountInfo, bearerType);
+       r = ConnectivityUtility::UpdateProfileInfo(&netAccountInfo, profileHandle, false);
        if (IsFailed(r))
        {
                SysLogException(NID_NET, r, "[%s] Propagating.", GetErrorMessage(r));
@@ -124,6 +170,9 @@ NetService::UpdateSystemNetAccount(const String& profileName, const NetAccountIn
        SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
                        "A system error has been occurred. The return value from connection_update_profile() is %d", ret);
 
+       r = NetAccountDatabase::UpdateAccountName(netAccountInfo.GetAccountId(), netAccountInfo.GetAccountName());
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
        return r;
 }
 
@@ -240,267 +289,748 @@ NetService::ResetAllNetStatistics(int bearerType)
        return E_SUCCESS;
 }
 
-void*
-NetService::GetPsProfileHandleN(const String& profileName)
+result
+NetService::GetNetConnectionInfo(int netAccountId, NetConnectionInfo* pConnectionInfo)
 {
-       SysLog(NID_NET, "GetPsProfileHandleN() has been called with ProfileName : %ls", profileName.GetPointer());
+       result r = E_SUCCESS;
+    String profileName;
+       connection_profile_h profileHandle = null;
 
-       ClearLastResult();
+       r = NetAccountDatabase::GetProfileName(netAccountId, profileName);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, E_INVALID_ACCOUNT, "Invalid network account. accountId:%d", netAccountId);
+
+       profileHandle = ConnectivityUtility::GetPsProfileHandleN(profileName);
+       SysTryReturnResult(NID_NET, profileHandle != null, E_INVALID_ACCOUNT, "Invalid network account. accountId:%d", netAccountId);
+
+       ConnectivityUtility::UpdateNetConnectionInfo(pConnectionInfo, profileHandle, false);
+       connection_profile_destroy(profileHandle);
+
+       return E_SUCCESS;
+}
 
+result
+NetService::GetAllNetConnectionInfo(ArrayList* pList)
+{
+       NetConnectionInfo* pInfo = null;
        int ret = CONNECTION_ERROR_NONE;
-       connection_h connectionHandle = null;
        connection_profile_iterator_h iterator = null;
        connection_profile_h profileHandle = null;
-       connection_profile_h matchingProfileHandle = null;
-
-       SysTryReturn(NID_NET, !profileName.IsEmpty(), null, E_INVALID_ARG,
-                       "[%s] Invalid argument is used. profileName is an empty string.", GetErrorMessage(E_INVALID_ARG));
-
-       ret = connection_create(&connectionHandle);
-       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
-                       "[%s] A system error has been occurred. The return value from connection_create() is %d", GetErrorMessage(E_SYSTEM), ret);
 
-       ret = connection_get_profile_iterator(connectionHandle, CONNECTION_ITERATOR_TYPE_REGISTERED, &iterator);
-       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, , E_SYSTEM,
-                       "[%s] A system error has been occurred. The return value from connection_get_profile_iterator() is %d", GetErrorMessage(E_SYSTEM), ret);
+       ret = connection_get_profile_iterator(__pConnectionHandle, CONNECTION_ITERATOR_TYPE_CONNECTED, &iterator);
+       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                       "A system error has been occurred. The return value from connection_get_profile_iterator() is %d", ret);
+       unique_ptr<void, _ProfileIteratorDeleter> pIterator(iterator);
 
        ret = connection_profile_iterator_next(iterator, &profileHandle);
-       while (profileHandle != null)
+       while ((ret == CONNECTION_ERROR_NONE) && (profileHandle != null))
        {
-               char* pTempProfileName = null;
-               String tempProfileName;
-
-               ret = connection_profile_get_id(profileHandle, &pTempProfileName);
-               SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, , E_SYSTEM,
-                               "[%s] A system error has been occurred. The return value from connection_profile_get_id() is %d", GetErrorMessage(E_SYSTEM), ret);
+               pInfo = new (std::nothrow) NetConnectionInfo();
+               SysTryReturnResult(NID_NET, pInfo != null, E_OUT_OF_MEMORY, "Insufficient memory.");
 
-               tempProfileName = String(pTempProfileName);
-               free(pTempProfileName);
-
-               if (profileName.Equals(tempProfileName))
-               {
-                       ret = connection_profile_clone(&matchingProfileHandle, profileHandle);
-                       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, matchingProfileHandle = null, E_SYSTEM,
-                                       "[%s] A system error has been occurred. The return value from connection_profile_clone() is %d", GetErrorMessage(E_SYSTEM), ret);
-
-                       break;
-               }
+               ConnectivityUtility::UpdateNetConnectionInfo(pInfo, profileHandle, false);
+               pList->Add(pInfo);
 
                profileHandle = null;
                ret = connection_profile_iterator_next(iterator, &profileHandle);
        }
 
-       SysTryCatch(NID_NET, matchingProfileHandle != null, , E_INVALID_ACCOUNT,
-                       "[%s] Matching account is not found.", GetErrorMessage(E_INVALID_ACCOUNT));
+       SysLog(NID_NET, "GetAllNetConnectionInfo() has been succeeded with count:%d", pList->GetCount());
 
-       connection_destroy_profile_iterator(iterator);
-       connection_destroy(connectionHandle);
+       return E_SUCCESS;
+}
+
+NetAccountId
+NetService::CreateNetAccount(const String& packageId, const NetAccountInfo& netAccountInfo)
+{
+       result r = E_SUCCESS;
+       NetAccountId accountId = INVALID_HANDLE;
+       String profileName;
+       bool isCreated = false;
+       int ret = CONNECTION_ERROR_NONE;
+       connection_h connectionHandle = __pConnectionHandle;
+       connection_profile_h profileHandle = null;
 
-       return matchingProfileHandle;
+       SysTryReturn(NID_NET, !netAccountInfo.GetAccountName().IsEmpty(),
+                       INVALID_HANDLE, E_INVALID_ARG,
+                       "[%s] Invalid argument is used. accountName is an empty string.", GetErrorMessage(E_INVALID_ARG));
 
-CATCH:
-       if (iterator != null)
-       {
-               connection_destroy_profile_iterator(iterator);
-       }
+       unique_ptr<IList, AllElementsDeleter> pProfileNamesBefore(NetService::GetAppProfileNamesN());
+       SysTryReturn(NID_NET, pProfileNamesBefore != null, INVALID_HANDLE, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       if (connectionHandle != null)
+       unique_ptr<char[]> pAccountName(_StringConverter::CopyToCharArrayN(netAccountInfo.GetAccountName()));
+       SysTryReturn(NID_NET, pAccountName != null, INVALID_HANDLE, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       ret = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, pAccountName.get(), &profileHandle);
+       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE,     E_SYSTEM,
+                       "[%s] A system error has been occurred. The return value from connection_profile_create() is %d",
+                       GetErrorMessage(E_SYSTEM), ret);
+
+       unique_ptr<void, _ProfileDeleter> pProfileHandle(profileHandle);
+       r = ConnectivityUtility::UpdateProfileInfo(&netAccountInfo, profileHandle, true);
+       SysTryReturn(NID_NET, r == E_SUCCESS, INVALID_HANDLE, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       ret = connection_add_profile(connectionHandle, profileHandle);
+       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, INVALID_HANDLE, E_SYSTEM,
+                       "[%s] A system error has been occurred. The return value from connection_add_profile() is %d",
+                       GetErrorMessage(E_SYSTEM), ret);
+
+       unique_ptr<IList, AllElementsDeleter> pProfileNamesAfter(NetService::GetAppProfileNamesN());
+       SysTryReturn(NID_NET, pProfileNamesAfter != null, INVALID_HANDLE, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       unique_ptr<IEnumerator> pEnum(pProfileNamesAfter->GetEnumeratorN());
+       SysTryReturn(NID_NET, pEnum != null, INVALID_HANDLE, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       while (pEnum->MoveNext() == E_SUCCESS)
        {
-               connection_destroy(connectionHandle);
+               String* pProfileName = null;
+
+               pProfileName = dynamic_cast<String*>(pEnum->GetCurrent());
+               if ((pProfileName != null) && (!pProfileName->IsEmpty()))
+               {
+                       if (!pProfileNamesBefore->Contains(*pProfileName))
+                       {
+                               SysLog(NID_NET, "ProfileName[%ls] is not found before, so it is a new profile name.", pProfileName->GetPointer());
+                               isCreated = true;
+                               profileName = *pProfileName;
+
+                               break;
+                       }
+               }
        }
 
-       return null;
+       SysTryReturn(NID_NET, isCreated, INVALID_HANDLE, E_SYSTEM,
+                       "[%s] A system error has been occurred. New account is not found.", GetErrorMessage(E_SYSTEM));
+       SysTryReturn(NID_NET, !profileName.IsEmpty(), INVALID_HANDLE, E_SYSTEM,
+                       "[%s] A system error has been occurred. The profileName of new account is an empty string.", GetErrorMessage(E_SYSTEM));
+
+       r = NetAccountDatabase::AddAccount(netAccountInfo.GetAccountName(), profileName, packageId, accountId);
+       SysTryReturn(NID_NET, r == E_SUCCESS, INVALID_HANDLE, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       ClearLastResult();
+
+       SysSecureLog( NID_NET, "CreateNetAccount() has been succeeded with accountId:%d, accountName:%ls, profileName:%ls",
+                       netAccountInfo.GetAccountId(), netAccountInfo.GetAccountName().GetPointer(), profileName.GetPointer());
+
+       return accountId;
 }
 
 result
-NetService::ConvertToProfileInfo(void* pProfileHandle, const NetAccountInfo& netAccountInfo, int bearerType) const
+NetService::DeleteNetAccount(const String& packageId, NetAccountId netAccountId)
 {
        result r = E_SUCCESS;
-       connection_profile_h profileHandle = (connection_profile_h)pProfileHandle;
+       String profileName;
+       bool isReadOnly = true;
        int ret = CONNECTION_ERROR_NONE;
-       connection_cellular_auth_type_e cellAuthType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
-       connection_ip_config_type_e ipConfigType = CONNECTION_IP_CONFIG_TYPE_NONE;
-
-       char* pApn = null;
-       char* pAuthId = null;
-       char* pAuthPassword = null;
-       char* pHomeUrl = null;
-       char* pDnsAddr = null;
-       char* pLocalAddr = null;
-       char* pProxyAddr = null;
-       String proxyAddr;
-
-       NetNapAuthType authType;
-       String authId;
-       String authPw;
-
-       SysTryReturnResult(NID_NET, pProfileHandle != null, E_INVALID_ARG, "pProfileHandle is null.");
-       SysTryReturnResult(NID_NET, ((bearerType == NET_BEARER_PS) || (bearerType == NET_BEARER_MMS)),
-                       E_INVALID_ARG, "Invalid argument is used. BearerType has to be PS. bearerType=%d", bearerType);
-
-       if (!netAccountInfo.GetAccessPointName().IsEmpty())
-       {
-               pApn = _StringConverter::CopyToCharArrayN(netAccountInfo.GetAccessPointName());
-               SysTryCatch(NID_NET, pApn != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
-                               "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
-               ret = connection_profile_set_cellular_apn(profileHandle, pApn);
-               delete[] pApn;
-               SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
-                               "[%s] A system error has been occurred. The return value from connection_profile_set_cellular_apn() is %d", GetErrorMessage(E_SYSTEM), ret);
-       }
+       connection_h connectionHandle = __pConnectionHandle;
+
+       SysLog(NID_NET, "DeleteNetAccount() has been called with accountId:%d", netAccountId);
+
+       SysTryReturnResult(NID_NET, netAccountId > 0, E_INVALID_ACCOUNT,
+                       "Invalid network account. accountId=%d", netAccountId);
+
+       isReadOnly = NetAccountDatabase::IsReadOnly(packageId, netAccountId);
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
+       SysTryReturnResult(NID_NET, !isReadOnly, E_INVALID_OPERATION, "Not allowed on the specified network account.");
+
+       r = NetAccountDatabase::GetProfileName(netAccountId, profileName);
+       SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, E_INVALID_ACCOUNT, "Invalid network account. accountId=%d", netAccountId);
+
+       unique_ptr<void, _ProfileDeleter> pProfileHandle(ConnectivityUtility::GetPsProfileHandleN(profileName));
+       SysTryReturnResult(NID_NET, pProfileHandle != null, E_INVALID_ACCOUNT,
+                       "Invalid network account. accountId=%d", netAccountId);
+
+       ret = connection_remove_profile(connectionHandle, pProfileHandle.get());
+       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                       "A system error has been occurred. The return value from connection_remove_profile() is %d", ret);
+
+       r = NetAccountDatabase::RemoveAccountByAccountId(netAccountId);
+       SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM,
+                       "A system error has been occurred. Failed to remove the account.");
+
+       return r;
+}
+
+result
+NetService::UpdateNetAccount(const String& packageId, const NetAccountInfo& netAccountInfo)
+{
+       result r = E_SUCCESS;
+       String profileName;
+       bool isReadOnly = true;
+       const _NetAccountInfoImpl* pInfoImpl = _NetAccountInfoImpl::GetInstance(netAccountInfo);
+       int ret = CONNECTION_ERROR_NONE;
+       connection_h connectionHandle = __pConnectionHandle;
+
+       SysTryReturnResult(NID_NET, pInfoImpl != null, E_INVALID_ARG,
+                       "Invalid argument is used. Network account info is invalid.");
+       SysTryReturnResult(NID_NET, netAccountInfo.GetAccountId() > 0, E_INVALID_ARG,
+                       "Invalid argument is used. accountId=%d", netAccountInfo.GetAccountId());
+       SysTryReturnResult(NID_NET, !netAccountInfo.GetAccountName().IsEmpty(), E_INVALID_ARG,
+                       "Invalid argument is used. accountName is an empty string.");
+
+       isReadOnly = NetAccountDatabase::IsReadOnly(packageId, netAccountInfo.GetAccountId());
+       r = GetLastResult();
+       SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
+       SysTryReturnResult(NID_NET, !isReadOnly, E_INVALID_OPERATION,
+                       "Not allowed on the specified network account.");
+
+       r = NetAccountDatabase::GetProfileName(netAccountInfo.GetAccountId(), profileName);
+       SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, E_INVALID_ARG,
+                       "Invalid argument is used. accountId=%d.", netAccountInfo.GetAccountId());
+
+       unique_ptr<void, _ProfileDeleter> pProfileHandle(ConnectivityUtility::GetPsProfileHandleN(profileName));
+       SysTryReturnResult(NID_NET, pProfileHandle != null, E_INVALID_ACCOUNT,
+                       "Invalid network account. accountId=%d", netAccountInfo.GetAccountId());
+
+       r = ConnectivityUtility::UpdateProfileInfo(&netAccountInfo, pProfileHandle.get(), true);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       ret = connection_update_profile(connectionHandle, pProfileHandle.get());
+       SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                       "A system error has been occurred. The return value from connection_update_profile() is %d",
+                       GetErrorMessage(E_SYSTEM), ret);
+
+       r = NetAccountDatabase::UpdateAccountName(netAccountInfo.GetAccountId(), netAccountInfo.GetAccountName());
+       SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM,
+                       "A system error has been occurred. Failed to update accountName.");
 
-       netAccountInfo.GetAuthenticationInfo(authType, authId, authPw);
+       return r;
+}
 
-       if (authType == NET_NAPAUTH_PAP)
+result
+NetService::GetNetAccountInfo(const String& packageId, NetAccountId netAccountId, NetAccountInfo* pNetAccountInfo) const
+{
+       result r = E_SUCCESS;
+       connection_profile_h profileHandle = null;
+       unique_ptr<void, _ProfileDeleter> pProfileHandle;
+
+       SysTryReturnResult(NID_NET, netAccountId > 0, E_INVALID_ACCOUNT, "Invalid network account. accountId=%d.", netAccountId);
+       SysTryReturnResult(NID_NET, netAccountId != _DEFAULT_WIFI_DIRECT_ACCOUNT_ID, E_INVALID_ACCOUNT, "Wifi direct account information is not found.");
+       SysTryReturnResult(NID_NET, netAccountId != _DEFAULT_USB_ACCOUNT_ID, E_INVALID_ACCOUNT, "USB account information is not found.");
+
+       _NetAccountInfoImpl* pImpl = _NetAccountInfoImpl::GetInstance(*pNetAccountInfo);
+       if (pImpl == null)
        {
-               cellAuthType = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
+               r = pNetAccountInfo->Construct();
+               SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+               pImpl = _NetAccountInfoImpl::GetInstance(*pNetAccountInfo);
+               SysTryReturnResult(NID_NET, pImpl != null, E_SYSTEM, "Failed to construct NetAccountInfo.");
        }
-       else if (authType == NET_NAPAUTH_CHAP)
+
+       String profileName;
+
+       r = NetAccountDatabase::GetProfileName(netAccountId, profileName);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, E_INVALID_ACCOUNT, "Ps account is NOT found for accountId[%d].", netAccountId);
+
+       profileHandle = ConnectivityUtility::GetPsProfileHandleN(profileName);
+       SysTryReturnResult(NID_NET, profileHandle != null, E_INVALID_ACCOUNT, "Ps account is NOT found for accountId[%d].", netAccountId);
+       pProfileHandle.reset(profileHandle);
+
+       pImpl->SetReadOnly(NetAccountDatabase::IsReadOnly(packageId, netAccountId));
+
+       r = ConnectivityUtility::UpdateNetAccountInfo(pNetAccountInfo, profileHandle);
+
+       return r;
+}
+
+result
+NetService::GetNetAccountIds(ArrayListT<NetAccountId>* pList)
+{
+       UpdateNetAccountDb();
+
+       ClearLastResult();
+
+       return NetAccountDatabase::GetAccountIds(pList);
+}
+
+result
+NetService::GetNetAccountNames(ArrayList* pList)
+{
+       UpdateNetAccountDb();
+
+       ClearLastResult();
+
+       return NetAccountDatabase::GetAccountNames(pList);
+}
+
+NetAccountId
+NetService::GetNetAccountId(const String& netAccountName)
+{
+       ClearLastResult();
+
+       result r = E_SUCCESS;
+       NetAccountId accountId = INVALID_HANDLE;
+
+       r = NetAccountDatabase::GetAccountIdByAccountName(netAccountName, accountId);
+       SysTryReturn(NID_NET, r == E_SUCCESS, INVALID_HANDLE, E_INVALID_ARG,
+                       "[%s] Invalid argument is used. AccountName[%ls] is not found.",
+                       GetErrorMessage(E_INVALID_ARG), netAccountName.GetPointer());
+
+       SysSecureLog(NID_NET, "GetNetAccountId() has been succeeded with accountId:%d", accountId);
+
+       return accountId;
+}
+
+NetAccountId
+NetService::GetNetAccountId(NetBearerType netBearerType)
+{
+       ClearLastResult();
+
+       NetAccountId accountId = INVALID_HANDLE;
+
+       if (netBearerType == NET_BEARER_PS)
        {
-               cellAuthType = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
+               accountId = GetInternetAccountId();
        }
-       else
+       else if (netBearerType == NET_BEARER_MMS)
        {
-               cellAuthType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
+               accountId = GetMmsAccountId();
        }
-
-       if (!authId.IsEmpty())
+       else if (netBearerType == NET_BEARER_WIFI)
        {
-               pAuthId = _StringConverter::CopyToCharArrayN(authId);
-               // OOM can occur.
+               accountId = _DEFAULT_WIFI_ACCOUNT_ID;
        }
-
-       if (!authPw.IsEmpty())
+       else if (netBearerType == NET_BEARER_WIFI_DIRECT)
        {
-               pAuthPassword = _StringConverter::CopyToCharArrayN(authPw);
-               // OOM can occur.
+               accountId = _DEFAULT_WIFI_DIRECT_ACCOUNT_ID;
        }
-
-       if ((pAuthId != null) && (pAuthPassword != null))
+       else if (netBearerType == NET_BEARER_USB)
        {
-               ret = connection_profile_set_cellular_auth_info(profileHandle, cellAuthType, pAuthId, pAuthPassword);
+               accountId = _DEFAULT_USB_ACCOUNT_ID;
        }
        else
        {
-               ret = connection_profile_set_cellular_auth_info(profileHandle, cellAuthType, " ", " ");
+               SysLogException(NID_NET, E_INVALID_ARG,
+                               "[%s] Invalid argument is used. bearerType=%d", GetErrorMessage(E_INVALID_ARG), netBearerType);
        }
-       if (pAuthId != null)
-       {
-               delete[] pAuthId;
-       }
-       if (pAuthPassword != null)
+
+       return accountId;
+}
+
+IList*
+NetService::GetAppProfileNamesN(void)
+{
+       ClearLastResult();
+
+       result r = E_SUCCESS;
+       int ret = CONNECTION_ERROR_NONE;
+       connection_h connectionHandle = null;
+       connection_profile_iterator_h iterator = null;
+       connection_profile_h profileHandle = null;
+       connection_profile_type_e profileType = CONNECTION_PROFILE_TYPE_WIFI;
+
+       ret = connection_create(&connectionHandle);
+       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, 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);
+
+       unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+       SysTryReturn(NID_NET, pList != null, null, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       r = pList->Construct();
+       SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       ret = connection_get_profile_iterator(connectionHandle, CONNECTION_ITERATOR_TYPE_REGISTERED, &iterator);
+       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                       "[%s] A system error has been occurred. The return value from connection_get_profile_iterator() is %d",
+                       GetErrorMessage(E_SYSTEM), ret);
+       unique_ptr<void, _ProfileIteratorDeleter> pIterator(iterator);
+
+       ret = connection_profile_iterator_next(iterator, &profileHandle);
+       while ((ret == CONNECTION_ERROR_NONE) && (profileHandle != null))
        {
-               delete[] pAuthPassword;
+               char* pProfileName = null;
+
+               ret = connection_profile_get_type(profileHandle, &profileType);
+               SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                               "[%s] A system error has been occurred. The return value from connection_profile_get_type() is %d",
+                       GetErrorMessage(E_SYSTEM), ret);
+
+               if (profileType == CONNECTION_PROFILE_TYPE_CELLULAR)
+               {
+                       connection_cellular_service_type_e serviceType = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
+
+                       ret = connection_profile_get_cellular_service_type(profileHandle, &serviceType);
+                       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                                       "[%s] A system error has been occurred. The return value from connection_profile_get_cellular_service_type() is %d",
+                                       GetErrorMessage(E_SYSTEM), ret);
+
+                       if (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION)
+                       {
+                               ret = connection_profile_get_id(profileHandle, &pProfileName);
+                               SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                                               "[%s] A system error has been occurred. The return value from connection_profile_get_id() is %d",
+                                               GetErrorMessage(E_SYSTEM), ret);
+
+                               unique_ptr<String> pProfileNameString(new (std::nothrow) String(pProfileName));
+                               free(pProfileName);
+                               SysTryReturn(NID_NET, pProfileNameString != null, null, E_OUT_OF_MEMORY,
+                                               "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                               r = pList->Add(*pProfileNameString);
+                               SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+                               pProfileNameString.release();
+                       }
+//                     else
+//                     {
+//                             SysLog(NID_NET, "Ignore non-app profile.");
+//                     }
+               }
+//             else
+//             {
+//                     SysLog(NID_NET, "Ignore non-cellular profile.");
+//             }
+
+               profileHandle = null;
+               ret = connection_profile_iterator_next(iterator, &profileHandle);
        }
-       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
-                       "[%s] A system error has been occurred. The return value from connection_profile_set_cellular_auth_info() is %d", GetErrorMessage(E_SYSTEM), ret);
 
-       if (!netAccountInfo.GetHomeUrl().IsEmpty())
+       SysLog(NID_NET, "GetAppProfileNamesN() has been succeeded with profiles count:%d", pList->GetCount());
+
+       return pList.release();
+}
+
+IList*
+NetService::GetAllProfileNamesN(void)
+{
+       ClearLastResult();
+
+       result r = E_SUCCESS;
+       int ret = CONNECTION_ERROR_NONE;
+       connection_h connectionHandle = null;
+       connection_profile_iterator_h iterator = null;
+       connection_profile_h profileHandle = null;
+       connection_profile_type_e profileType = CONNECTION_PROFILE_TYPE_WIFI;
+
+       ret = connection_create(&connectionHandle);
+       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, 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);
+
+       unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+       SysTryReturn(NID_NET, pList != null, null, E_OUT_OF_MEMORY,
+                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       r = pList->Construct();
+       SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       ret = connection_get_profile_iterator(connectionHandle, CONNECTION_ITERATOR_TYPE_REGISTERED, &iterator);
+       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                       "[%s] A system error has been occurred. The return value from connection_get_profile_iterator() is %d",
+                       GetErrorMessage(E_SYSTEM), ret);
+       unique_ptr<void, _ProfileIteratorDeleter> pIterator(iterator);
+
+       ret = connection_profile_iterator_next(iterator, &profileHandle);
+       while ((ret == CONNECTION_ERROR_NONE) && (profileHandle != null))
        {
-               pHomeUrl = _StringConverter::CopyToCharArrayN(netAccountInfo.GetHomeUrl());
-               SysTryCatch(NID_NET, pHomeUrl != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
+               ret = connection_profile_get_type(profileHandle, &profileType);
+               SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                               "[%s] A system error has been occurred. The return value from connection_profile_get_type() is %d",
+                       GetErrorMessage(E_SYSTEM), ret);
+
+               if (profileType == CONNECTION_PROFILE_TYPE_CELLULAR)
+               {
+                       connection_cellular_service_type_e serviceType = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
+
+                       ret = connection_profile_get_cellular_service_type(profileHandle, &serviceType);
+                       SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, E_SYSTEM,
+                                       "[%s] A system error has been occurred. The return value from connection_profile_get_cellular_service_type() is %d",
+                                       GetErrorMessage(E_SYSTEM), ret);
+
+                       if ((serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET)
+                                       || (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET)
+                                       || (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_MMS)
+                                       || (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS)
+                                       || (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION))
+                       {
+                               char* pProfileName = null;
+                               char* pProfileDisplayName = null;
+                               String profileName;
+                               String profileDisplayName;
+
+                               ret = connection_profile_get_id(profileHandle, &pProfileName);
+                               SysTryReturn(NID_NET, ret == CONNECTION_ERROR_NONE, null, 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, null, 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);
+
+                               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(*pNetProfileName);
+                               SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+                               pNetProfileName.release();
+                       }
+//                     else
+//                     {
+//                             SysLog(NID_NET, "Ignore unknown profile.");
+//                     }
+               }
+//             else
+//             {
+//                     SysLog(NID_NET, "Ignore non-cellular profile.");
+//             }
 
-               ret = connection_profile_set_cellular_home_url(profileHandle, pHomeUrl);
-               delete[] pHomeUrl;
+               profileHandle = null;
+               ret = connection_profile_iterator_next(iterator, &profileHandle);
        }
-       else
+
+       SysLog(NID_NET, "GetAllProfileNamesN() has been succeeded with profiles count:%d", pList->GetCount());
+
+       return pList.release();
+}
+
+NetAccountId
+NetService::GetInternetAccountId(void)
+{
+       result r = E_SUCCESS;
+       NetAccountId accountId = INVALID_HANDLE;
+
+       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, 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))
        {
-               ret = connection_profile_set_cellular_home_url(profileHandle, " ");
+               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);
        }
-       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
-                       "[%s] A system error has been occurred. The return value from connection_profile_set_cellular_home_url() is %d", GetErrorMessage(E_SYSTEM), ret);
+       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);
 
-       ret = connection_profile_get_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &ipConfigType);
-       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
-                       "[%s] A system error has been occurred. The return value from connection_profile_get_ip_config_type() is %d", GetErrorMessage(E_SYSTEM), ret);
+       profileDisplayName = String(pProfileDisplayName);
+       free(pProfileDisplayName);
 
-       if (ipConfigType != CONNECTION_IP_CONFIG_TYPE_FIXED)
+       SysLog(NID_NET, "Internet profile is found. [%ls][%ls]", profileDisplayName.GetPointer(), profileName.GetPointer());
+
+       if (!__internetProfileName.IsEmpty())
        {
-               if (netAccountInfo.GetLocalAddressScheme() == NET_ADDRESS_SCHEME_STATIC)
+               if (!profileName.Equals(__internetProfileName, false))
                {
-                       ret = connection_profile_set_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, CONNECTION_IP_CONFIG_TYPE_STATIC);
-                       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM,
-                                       E_SYSTEM, "[%s] A system error has been occurred. The return value from connection_profile_set_ip_config_type() is %d", ret);
-
-                       SysTryCatch(NID_NET, netAccountInfo.GetLocalAddress() != null, r = E_INVALID_ARG, E_INVALID_ARG,
-                                       "[%s] Invalid argument is used. Local Address Scheme is static, but local address is null.", GetErrorMessage(E_INVALID_ARG));
+                       // Internet profile is changed.
+                       SysLog(NID_NET, "Internet profile is changed. [%ls]->[%ls]", __internetProfileName.GetPointer(), profileName.GetPointer());
 
-                       pLocalAddr = _StringConverter::CopyToCharArrayN(netAccountInfo.GetLocalAddress()->ToString());
-                       SysTryCatch(NID_NET, pLocalAddr != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
-                                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+                       UpdateNetAccountDb();
+                       r = NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
 
-                       ret = connection_profile_set_ip_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, pLocalAddr);
-                       delete[] pLocalAddr;
-                       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
-                                       "[%s] A system error has been occurred. The return value from connection_profile_set_ip_address() is %d", GetErrorMessage(E_SYSTEM), ret);
+                       __internetProfileName = profileName;
+                       __internetAccountId = accountId;
                }
                else
                {
-                       ret = connection_profile_set_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
-                       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
-                                       "[%s] A system error has been occurred. The return value connection_profile_set_ip_config_type() is %d", GetErrorMessage(E_SYSTEM), ret);
+                       accountId = __internetAccountId;
                }
        }
+       else
+       {
+               SysLog(NID_NET, "Initialize Internet profile.");
+
+               UpdateNetAccountDb();
+               r = NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
+
+               __internetProfileName = profileName;
+               __internetAccountId = accountId;
+       }
+
+       ClearLastResult();
+
+       return accountId;
+}
+
+NetAccountId
+NetService::GetMmsAccountId(void)
+{
+       result r = E_SUCCESS;
+       NetAccountId accountId = INVALID_HANDLE;
+
+       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, 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);
 
-       if (netAccountInfo.GetDnsAddressScheme() == NET_ADDRESS_SCHEME_STATIC)
+       ret = connection_get_default_cellular_service_profile(connectionHandle, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profileHandle);
+       if ((ret != CONNECTION_ERROR_NONE) || (profileHandle == null))
        {
-               if (netAccountInfo.GetPrimaryDnsAddress() != null)
-               {
-                       pDnsAddr = _StringConverter::CopyToCharArrayN(netAccountInfo.GetPrimaryDnsAddress()->ToString());
-                       SysTryCatch(NID_NET, pDnsAddr != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
-                                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
-                       ret = connection_profile_set_dns_address(profileHandle, 1, CONNECTION_ADDRESS_FAMILY_IPV4, pDnsAddr);
-                       delete[] pDnsAddr;
-                       pDnsAddr = null;
-                       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
-                                       "[%s] A system error has been occurred. The return value from connection_profile_set_dns_address() is %d", GetErrorMessage(E_SYSTEM), ret);
-               }
+               SysLog(NID_NET, "MMS profile is not found, so search a prepaid-MMS profile.");
 
-               if (netAccountInfo.GetSecondaryDnsAddress() != null)
-               {
-                       pDnsAddr = _StringConverter::CopyToCharArrayN(netAccountInfo.GetSecondaryDnsAddress()->ToString());
-                       SysTryCatch(NID_NET, pDnsAddr != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
-                                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
-                       ret = connection_profile_set_dns_address(profileHandle, 2, CONNECTION_ADDRESS_FAMILY_IPV4, pDnsAddr);
-                       delete[] pDnsAddr;
-                       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
-                                       "[%s] A system error has been occurred. The return value from connection_profile_set_dns_address() is %d", GetErrorMessage(E_SYSTEM), ret);
-               }
+               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);
 
-       if (netAccountInfo.GetProxyAddress() != null)
+       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());
+
+       if (!__mmsProfileName.IsEmpty())
        {
-               proxyAddr = netAccountInfo.GetProxyAddress()->GetNetEndPoint();
-               if (proxyAddr.IsEmpty() == false)
+               if (!profileName.Equals(__mmsProfileName, false))
                {
-                       ret = connection_profile_set_proxy_type(profileHandle, CONNECTION_PROXY_TYPE_MANUAL);
-                       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
-                                       "[%s] A system error has been occurred. The return value connection_profile_set_proxy_type() is %d", GetErrorMessage(E_SYSTEM), ret);
+                       // MMS profile is changed.
+                       SysLog(NID_NET, "MMS profile is changed. [%ls]->[%ls]", __mmsProfileName.GetPointer(), profileName.GetPointer());
 
-                       pProxyAddr = _StringConverter::CopyToCharArrayN(proxyAddr);
-                       SysTryCatch(NID_NET, pProxyAddr != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
-                                       "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+                       UpdateNetAccountDb();
+                       r = NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
 
-                       ret = connection_profile_set_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, pProxyAddr);
-                       delete[] pProxyAddr;
+                       __mmsProfileName = profileName;
+                       __mmsAccountId = accountId;
                }
                else
                {
-                       ret = connection_profile_set_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, null);
+                       accountId = __mmsAccountId;
                }
        }
        else
        {
-               ret = connection_profile_set_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, null);
+               SysLog(NID_NET, "Initialize MMS profile.");
+
+               UpdateNetAccountDb();
+               r = NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
+
+               __mmsProfileName = profileName;
+               __mmsAccountId = accountId;
        }
-       SysTryCatch(NID_NET, ret == CONNECTION_ERROR_NONE, r = E_SYSTEM, E_SYSTEM,
-                       "[%s] A system error has been occurred. The return value connection_profile_set_proxy_address() is %d", GetErrorMessage(E_SYSTEM), ret);
 
-       return r;
+       ClearLastResult();
 
-CATCH:
-       return r;
+       return accountId;
+}
+
+void
+NetService::UpdateNetAccountDb(void)
+{
+       result r = E_SUCCESS;
+       NetAccountId accountId = INVALID_HANDLE;
+       unique_ptr<IList, AllElementsDeleter> pAccountList(NetAccountDatabase::GetProfileNamesN());
+       unique_ptr<IList, AllElementsDeleter> pProfileList(NetService::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, String(SYSTEM_PACKAGE_NAME), 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);
+                                       }
+                               }
+                       }
+               }
+       }
+
+       ClearLastResult();
+
+       SysLog(NID_NET, "Network account database is updated.");
 }
diff --git a/src/NetWifiConnection.cpp b/src/NetWifiConnection.cpp
new file mode 100755 (executable)
index 0000000..b9a0642
--- /dev/null
@@ -0,0 +1,462 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+/**
+ * @file               NetWifiConnection.cpp
+ * @brief              This is the implementation file for NetWifiConnection class.
+ * @version    3.0
+ *
+ * This file contains the implementation of NetWifiConnection class.
+ */
+
+#include <net_connection.h>
+#include <wifi.h>
+#include <FNetNetConnectionInfo.h>
+#include <FBaseSysLog.h>
+#include <FSysSettingInfo.h>
+#include <FBase_StringConverter.h>
+#include <FApp_AppManagerImpl.h>
+#include <FNet_NetTypes.h>
+#include <FNet_NetConnectionInfoImpl.h>
+#include "ConnectivityUtility.h"
+#include "NetWifiConnection.h"
+#include "NetConnectivityIpcStub.h"
+
+using namespace std;
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Net;
+using namespace Tizen::System;
+
+static const char* _WIFI_QS_APP_ID = "net.wifi-qs";
+
+NetWifiConnection* NetWifiConnection::__pNetWifiConnection = null;
+
+NetWifiConnection*
+NetWifiConnection::GetInstance(NetConnectivityIpcStub* pStub)
+{
+    result r = E_SUCCESS;
+
+    if (__pNetWifiConnection == null)
+       {
+               unique_ptr<NetWifiConnection> pInstance(new (std::nothrow) NetWifiConnection());
+               SysTryReturn(NID_NET, pInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+               r = pInstance->Construct(pStub);
+               SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+               __pNetWifiConnection = pInstance.release();
+       }
+
+       return __pNetWifiConnection;
+}
+
+NetWifiConnection::NetWifiConnection(void)
+       : __pStub(null)
+       , __isInitialized(false)
+       , __isStarting(false)
+       , __pConnectionHandle(null)
+       , __pClientList(null)
+       , __clientCount(0)
+{
+}
+
+NetWifiConnection::~NetWifiConnection(void)
+{
+       if (__pConnectionHandle != null)
+       {
+               connection_destroy(__pConnectionHandle);
+       }
+}
+
+result
+NetWifiConnection::Construct(NetConnectivityIpcStub* pStub)
+{
+    result r = E_SUCCESS;
+
+    unique_ptr< ArrayListT<int> > pClientList(new (std::nothrow) ArrayListT<int>());
+    SysTryReturnResult(NID_NET, pClientList != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    r = pClientList->Construct();
+    SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+       int err = CONNECTION_ERROR_NONE;
+
+       err = connection_create(&__pConnectionHandle);
+       SysLog(NID_NET, "The return value of connection_create() is 0x%x", err);
+    SysTryReturnResult(NID_NET, err == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to create a connection handle.");
+
+    __pStub = pStub;
+    __pClientList = move(pClientList);
+    __clientCount = 0;
+
+    return E_SUCCESS;
+}
+
+void
+NetWifiConnection::WifiConnectionTypeChangedCallback(connection_type_e type, void* pUserData)
+{
+       NetWifiConnection* pThis = static_cast<NetWifiConnection*>(pUserData);
+       SysTryReturnVoidResult(NID_NET, pThis != null, E_SYSTEM, "[E_SYSTEM] The instance handle is NULL.");
+
+       int ret = CONNECTION_ERROR_NONE;
+       connection_h connectionHandle = pThis->__pConnectionHandle;
+       connection_profile_h profileHandle = null;
+       connection_wifi_state_e state = CONNECTION_WIFI_STATE_DEACTIVATED;
+       NetConnectionState oldState = pThis->__connectionState;
+
+       SysLog(NID_NET, "WifiConnectionTypeChangedCallback() has been called with type:%d", type);
+
+       ret = connection_get_wifi_state(connectionHandle, &state);
+       SysTryReturnVoidResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
+                       "[E_SYSTEM] A system error has been called. The return value from connection_get_wifi_state() is %d", ret);
+
+       if (state == CONNECTION_WIFI_STATE_CONNECTED)
+       {
+               SysLog(NID_NET, "Wifi is connected.");
+
+               if (pThis->__isStarting)
+               {
+                       _AppManagerImpl::GetInstance()->RemoveAppEventListener(*pThis);
+                       pThis->__isStarting = false;
+               }
+
+               if (oldState != NET_CONNECTION_STATE_STARTED)
+               {
+                       profileHandle = ConnectivityUtility::GetWifiProfileHandleN();
+                       SysTryReturnVoidResult(NID_NET, profileHandle != null, E_SYSTEM, "WIFI profileHandle is not found.");
+
+                       pThis->UpdateConnectionInfo(profileHandle);
+                       connection_profile_destroy(profileHandle);
+
+                       pThis->HandleEvent(_NET_CONNECTION_EVENT_TYPE_STARTED);
+               }
+               else
+               {
+                       SysLog(NID_NET, "Ignore the event, because this is already in started state.");
+               }
+       }
+       else
+       {
+               SysLog(NID_NET, "Wifi is not connected.");
+
+               if (pThis->__isStarting)
+               {
+                       bool isWifiQsRunning = false;
+
+                       isWifiQsRunning = _AppManagerImpl::GetInstance()->IsRunning(String(_WIFI_QS_APP_ID));
+
+                       if (isWifiQsRunning)
+                       {
+                               SysLog(NID_NET, "Ignore disconnected event on the starting state because Wi-Fi QuickStart is running.");
+
+                               return;
+                       }
+                       else
+                       {
+                               _AppManagerImpl::GetInstance()->RemoveAppEventListener(*pThis);
+                               pThis->__isStarting = false;
+                       }
+               }
+
+               if ((oldState != NET_CONNECTION_STATE_NONE) && (oldState != NET_CONNECTION_STATE_STOPPED))
+               {
+                       pThis->UpdateConnectionInfo(null);
+                       pThis->HandleEvent(_NET_CONNECTION_EVENT_TYPE_STOPPED, E_NETWORK_FAILED);
+               }
+               else
+               {
+                       SysLog(NID_NET, "Ignore the event, because this is already in stopped state.");
+               }
+       }
+}
+
+void
+NetWifiConnection::WifiConnectionProxyChangedCallback(const char* pIpv4Address, const char* pIpv6Address, void *pUserData)
+{
+       NetWifiConnection* pThis = static_cast<NetWifiConnection*>(pUserData);
+       SysTryReturnVoidResult(NID_NET, pThis != null, E_SYSTEM, "[E_SYSTEM] The instance handle is NULL.");
+
+       String proxy = String(pIpv4Address);
+       _NetConnectionInfoImpl* pConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(pThis->__connectionInfo);
+       if (pConnectionInfoImpl != null)
+       {
+               SysLog(NID_NET, "Set proxy address [%ls]->[%ls]", pConnectionInfoImpl->GetProxyAddress().GetPointer(), proxy.GetPointer());
+               pConnectionInfoImpl->SetProxyAddress(proxy);
+       }
+}
+
+void
+NetWifiConnection::WifiConnectionActivatedCallback(wifi_error_e res, void* pUserData)
+{
+       NetWifiConnection* pThis = static_cast<NetWifiConnection*>(pUserData);
+       SysTryReturnVoidResult(NID_NET, pThis != null, E_SYSTEM, "[E_SYSTEM] The instance handle is NULL.");
+
+       SysLog(NID_NET, "Enter with res[%d].", res);
+
+       if (res != WIFI_ERROR_NONE)
+       {
+               SysLogException(NID_NET, E_NETWORK_FAILED, "[E_NETWORK_FAILED] Failed to activate Wi-Fi.");
+
+               _AppManagerImpl::GetInstance()->RemoveAppEventListener(*pThis);
+               pThis->__isStarting = false;
+
+               pThis->UpdateConnectionInfo(null);
+               pThis->HandleEvent(_NET_CONNECTION_EVENT_TYPE_STOPPED, E_NETWORK_FAILED);
+       }
+}
+
+void
+NetWifiConnection::OnApplicationLaunched(const AppId& appId, int pid)
+{
+       SysLog(NID_NET, "App is launched. appid[%ls] pid[%d].", appId.GetPointer(), pid);
+}
+
+void
+NetWifiConnection::OnApplicationTerminated(const AppId& appId, int pid)
+{
+       SysLog(NID_NET, "App is terminated. appid[%ls] pid[%d].", appId.GetPointer(), pid);
+
+       if (appId.Equals(String(_WIFI_QS_APP_ID), false))
+       {
+               SysLog(NID_NET, "Wi-Fi QuickStart is terminated before Wi-Fi is connected.");
+
+               if (__pNetWifiConnection != null)
+               {
+                       _AppManagerImpl::GetInstance()->RemoveAppEventListener(*__pNetWifiConnection);
+                       __pNetWifiConnection->__isStarting = false;
+
+                       __pNetWifiConnection->UpdateConnectionInfo(null);
+                       __pNetWifiConnection->HandleEvent(_NET_CONNECTION_EVENT_TYPE_STOPPED, E_NETWORK_FAILED);
+               }
+       }
+}
+
+result
+NetWifiConnection::AddEventListener(int clientId, int* pConnectionState, NetConnectionInfo* pInfo)
+{
+       result r = E_SUCCESS;
+       int err = CONNECTION_ERROR_NONE;
+
+       r = __pClientList->Add(clientId);
+    SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
+
+//     if (__clientCount == 0)
+       if (!__isInitialized)
+       {
+               SysLog(NID_NET, "Set wifi network event callback.");
+
+               connection_profile_h profileHandle = null;
+               connection_wifi_state_e state = CONNECTION_WIFI_STATE_DEACTIVATED;
+
+               err = wifi_initialize();
+               if ((err != WIFI_ERROR_NONE) && (err != WIFI_ERROR_INVALID_OPERATION))
+               {
+                       SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] wifi_initialize() failed with err=[%d]", err);
+                       __pClientList->Remove(clientId);
+
+               return E_SYSTEM;
+               }
+
+               err = connection_set_type_changed_cb(__pConnectionHandle, (connection_type_changed_cb)NetWifiConnection::WifiConnectionTypeChangedCallback, this);
+               if (err != CONNECTION_ERROR_NONE)
+               {
+                       SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The return value from connection_set_type_changed_cb() is [%d]", err);
+                       __pClientList->Remove(clientId);
+
+               return E_SYSTEM;
+               }
+
+               err = connection_set_proxy_address_changed_cb(__pConnectionHandle, (connection_address_changed_cb)NetWifiConnection::WifiConnectionProxyChangedCallback, this);
+               if (err != CONNECTION_ERROR_NONE)
+               {
+                       SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The return value from connection_set_proxy_address_changed_cb() is [%d]", err);
+               connection_unset_type_changed_cb(__pConnectionHandle);
+                       __pClientList->Remove(clientId);
+
+               return E_SYSTEM;
+               }
+
+               err = connection_get_wifi_state(__pConnectionHandle, &state);
+               if (err != CONNECTION_ERROR_NONE)
+               {
+                       SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] connection_get_wifi_state() failed with err=[%d]", err);
+                       connection_unset_proxy_address_changed_cb(__pConnectionHandle);
+                       connection_unset_type_changed_cb(__pConnectionHandle);
+                       __pClientList->Remove(clientId);
+
+               return E_SYSTEM;
+               }
+
+               if (state == CONNECTION_WIFI_STATE_CONNECTED)
+               {
+                       profileHandle = ConnectivityUtility::GetWifiProfileHandleN();
+                       if (profileHandle != null)
+                       {
+                               SysLog(NID_NET, "Wifi is connected.");
+                               UpdateConnectionInfo(profileHandle);
+                               connection_profile_destroy(profileHandle);
+                       }
+                       else
+                       {
+                               SysLog(NID_NET, "Wifi state is connected, but profileHandle is not found.");
+                               UpdateConnectionInfo(null);
+                       }
+               }
+               else
+               {
+                       SysLog(NID_NET, "Wifi is not connected.");
+                       UpdateConnectionInfo(null);
+               }
+
+               __isInitialized = true;
+       }
+#if 0
+       else
+       {
+               char* pProxy = null;
+
+           err = connection_get_proxy(__pConnectionHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pProxy);
+           if (pProxy != null)
+           {
+               String proxy = String(pProxy);
+               free(pProxy);
+
+               _NetConnectionInfoImpl* pConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(__connectionInfo);
+               if (pConnectionInfoImpl != null)
+               {
+                               SysLog(NID_NET, "Set proxy address [%ls]->[%ls]", pConnectionInfoImpl->GetProxyAddress().GetPointer(), proxy.GetPointer());
+                       pConnectionInfoImpl->SetProxyAddress(proxy);
+               }
+           }
+       }
+#endif
+
+    __clientCount++;
+
+    *pConnectionState = __connectionState;
+    *pInfo = __connectionInfo;
+
+       return E_SUCCESS;
+}
+
+result
+NetWifiConnection::RemoveEventListener(int clientId)
+{
+       if (!__pClientList->Contains(clientId))
+       {
+               SysLog(NID_NET, "Client[%d] is not found, so ignore the request.", clientId);
+               return E_SUCCESS;
+       }
+
+       result r = __pClientList->Remove(clientId);
+       if (r == E_SUCCESS)
+       {
+               __clientCount--;
+       }
+
+#if 0
+       if (__clientCount == 0)
+       {
+               SysLog(NID_NET, "Unset default network event callback.");
+
+               connection_unset_proxy_address_changed_cb(__pConnectionHandle);
+               connection_unset_type_changed_cb(__pConnectionHandle);
+       }
+#endif
+
+       return E_SUCCESS;
+}
+
+result
+NetWifiConnection::Start(void)
+{
+       if (__isStarting)
+       {
+               SysLog(NID_NET, "Already on starting.");
+
+               return E_SUCCESS;
+       }
+
+       result r = E_SUCCESS;
+       int ret = WIFI_ERROR_NONE;
+       bool isActivated = false;
+
+       ret = wifi_is_activated(&isActivated);
+       SysTryReturnResult(NID_NET, ret == WIFI_ERROR_NONE, E_SYSTEM, "wifi_is_activated() failed with ret=[%d].", ret);
+       SysTryReturnResult(NID_NET, !isActivated, E_INVALID_CONNECTION, "Wi-Fi is already activated, so can't start it.");
+
+       bool isFlightModeEnabled = false;
+       r = SettingInfo::GetValue(L"http://tizen.org/setting/network.flight_mode", isFlightModeEnabled);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS && !isFlightModeEnabled, E_INVALID_CONNECTION, "Flight mode is enabled.");
+
+       r = _AppManagerImpl::GetInstance()->AddAppEventListener(*this);
+       SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM, "Failed to set application event listener.");
+
+       ret = wifi_activate(NetWifiConnection::WifiConnectionActivatedCallback, this);
+       if (ret != WIFI_ERROR_NONE)
+       {
+               SysLogException(NID_NET, E_SYSTEM, "[E_SYSTEM] wifi_activate() failed with ret=[%d].", ret);
+
+               _AppManagerImpl::GetInstance()->RemoveAppEventListener(*this);
+
+               return E_SYSTEM;
+       }
+
+       __isStarting = true;
+
+       return E_SUCCESS;
+}
+
+void
+NetWifiConnection::HandleEvent(_NetConnectionEventType type, result error)
+{
+       result r = E_SUCCESS;
+       int clientId = 0;
+
+       unique_ptr< IEnumeratorT<int> > pEnum(__pClientList->GetEnumeratorN());
+       if (pEnum != null)
+       {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       r = pEnum->GetCurrent(clientId);
+                       if ((r == E_SUCCESS) && (clientId > 0))
+                       {
+                           __pStub->SendWifiConnectionChanged(clientId, error, type, __connectionState, __connectionInfo);
+                       }
+               }
+       }
+}
+
+void
+NetWifiConnection::UpdateConnectionInfo(void* pData)
+{
+       _NetConnectionInfoImpl* pConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(__connectionInfo);
+       SysTryReturnVoidResult(NID_NET, pConnectionInfoImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Connection information is null.");
+
+       if (pData != null)
+       {
+               __connectionState = NET_CONNECTION_STATE_STARTED;
+               ConnectivityUtility::UpdateNetConnectionInfo(&__connectionInfo, pData, false);
+       }
+       else
+       {
+               __connectionState = NET_CONNECTION_STATE_STOPPED;
+               pConnectionInfoImpl->Clear();
+       }
+}
old mode 100644 (file)
new mode 100755 (executable)
index c905746..03060ca
@@ -114,7 +114,6 @@ NfcConnectivityIpcStub::OnIpcRequestReceived(Tizen::Io::_IpcServer& server, cons
 {
        IPC_BEGIN_MESSAGE_MAP(NfcConnectivityIpcStub, message)
        IPC_MESSAGE_HANDLER(ConnectivityNfcServiceMsg_initialize, OnInitializeNfc, &server)
-       IPC_MESSAGE_HANDLER(ConnectivityNfcServiceMsg_setLaunchPopupEnabled, OnSetNfcLaunchPopupEnabled, &server)
        IPC_MESSAGE_HANDLER(ConnectivityNfcServiceMsg_registerPushMessage, OnRegisterNfcPushMessage, &server)
        IPC_MESSAGE_HANDLER(ConnectivityNfcServiceMsg_unregisterPushMessage, OnUnregisterNfcPushMessage, &server)
        IPC_MESSAGE_HANDLER(ConnectivityNfcServiceMsg_activateReservedPush, OnActivateReservedPush, &server)
@@ -145,24 +144,6 @@ NfcConnectivityIpcStub::OnInitializeNfc(unsigned long* pResult)
 }
 
 void
-NfcConnectivityIpcStub::OnSetNfcLaunchPopupEnabled(bool enable, unsigned long* pResult)
-{
-       String packageId = __pIpcServer->GetClientPackageId();
-
-       SysLog(NID_NET_NFC, "Received the request of setting the launch popup enabled with clientId : %d, AppPkgId : %ls",
-                               __pIpcServer->GetClientId(), packageId.GetPointer());
-
-       if (__pNfcService == null)
-       {
-               *pResult = E_SYSTEM;
-       }
-       else
-       {
-               *pResult = __pNfcService->SetLaunchPopupEnabled(packageId, enable);
-       }
-}
-
-void
 NfcConnectivityIpcStub::OnRegisterNfcPushMessage(const Tizen::Base::ByteBuffer& pushMessageBuffer,
                const Tizen::Base::String& description, unsigned long* pResult)
 {
@@ -268,7 +249,7 @@ NfcConnectivityIpcStub::OnIsReservedPushActivated(bool* pIsActivated)
 }
 
 void
-NfcConnectivityIpcStub::OnGetReservedPushCandidates(Tizen::Base::Collection::HashMap* pCandidates, unsigned long* pResult)
+NfcConnectivityIpcStub::OnGetReservedPushCandidates(Tizen::Io::_StringMap* pCandidates, unsigned long* pResult)
 {
        SysLog(NID_NET_NFC, "Received the request of getting the NFC Reserved Push candidate list with clientId : %d, AppPkgId : %ls",
                                __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
old mode 100644 (file)
new mode 100755 (executable)
index 977ab1b..db6f148
@@ -234,7 +234,7 @@ NfcMessagePushDelegate::SendReservedMessage(nfc_p2p_target_h targetH)
 
        // send the reserved NDEF message as a raw format - byte array type.
        nfcRes = nfc_ndef_message_create_from_rawdata(&ndefMessageH, messageBuffer.GetPointer() + messageBuffer.GetPosition(),
-                       messageBuffer.GetRemaining());
+                       (unsigned int)messageBuffer.GetRemaining());
        SysTryReturnVoidResult(NID_NET_NFC, nfcRes == NFC_ERROR_NONE, E_OPERATION_FAILED,
                        "[E_OPERATION_FAILED] Failed to convert raw data to NDEF message [0x%08X].", nfcRes);
 
old mode 100644 (file)
new mode 100755 (executable)
index 08b5d86..e3bf41d
@@ -46,7 +46,7 @@ using namespace Tizen::App::Package;
 using namespace Tizen::Io;
 
 const wchar_t* NfcMessageRegisterService::_SELECTED_APP_ID_NONE = L"None";
-const wchar_t* NfcMessageRegisterService::_META_DATA_DB_NAME = L"/opt/usr/dbspace/.net-nfcpush.db";
+const wchar_t* NfcMessageRegisterService::_META_DATA_DB_NAME = L"/opt/dbspace/.net-nfcpush.db";
 const wchar_t* NfcMessageRegisterService::_PUSH_MESSAGE_DIRECTORY = L"/opt/usr/share/nfcpush/";
 const wchar_t* NfcMessageRegisterService::_PUSH_MESSAGE_EXT_NAME = L".ndef";
 
@@ -235,16 +235,14 @@ NfcMessageRegisterService::UnregisterPushMessage(const Tizen::Base::String& appP
 }
 
 result
-NfcMessageRegisterService::GetReservedPushCandidates(Tizen::Base::Collection::HashMap* pCandidates)
+NfcMessageRegisterService::GetReservedPushCandidates(Tizen::Io::_StringMap* pCandidates)
 {
        const wchar_t* _QUERY_ALL_ITEM_SQL = L"SELECT AppId, MsgDesc FROM NfcPushMsgTable";
        result r = E_SUCCESS;
-       unique_ptr<String> pAppPkgId;
-       unique_ptr<String> pMsgDesc;
+       String appPkgId;
+       String msgDesc;
        unique_ptr<DbEnumerator> pQueryEnum;
 
-       pCandidates->Construct();
-
        pQueryEnum.reset(__rsvdPushDb.QueryN(_QUERY_ALL_ITEM_SQL));
        r = GetLastResult();
        SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Failed get the reserved push candidiates from DB.");
@@ -253,18 +251,13 @@ NfcMessageRegisterService::GetReservedPushCandidates(Tizen::Base::Collection::Ha
        {
                while (pQueryEnum->MoveNext() == E_SUCCESS)
                {
-                       pAppPkgId.reset(new (std::nothrow) String());
-                       SysTryReturnResult(NID_NET_NFC, pAppPkgId != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
-                       pMsgDesc.reset(new (std::nothrow) String());
-                       SysTryReturnResult(NID_NET_NFC, pMsgDesc != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
-
-                       r = pQueryEnum->GetStringAt(0, *pAppPkgId);
+                       r = pQueryEnum->GetStringAt(0, appPkgId);
                        SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Failed get a reserved push candidate from DB.");
 
-                       r = pQueryEnum->GetStringAt(1, *pMsgDesc);
+                       r = pQueryEnum->GetStringAt(1, msgDesc);
                        SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Failed get a reserved push candidate from DB.");
 
-                       pCandidates->Add(pAppPkgId.release(), pMsgDesc.release());
+                       pCandidates->Add(appPkgId, msgDesc);
                }
        }
 
@@ -313,19 +306,17 @@ NfcMessageRegisterService::OnPackageUninstallationCompleted(const Tizen::App::Pa
 result
 NfcMessageRegisterService::InitializeAppIdList(void)
 {
-       const wchar_t* _CREATE_TABLE_SQL =
-                       L"CREATE TABLE IF NOT EXISTS NfcPushMsgTable ( AppId TEXT PRIMARY KEY, PkgName TEXT, IconPath TEXT, MsgDesc TEXT )";
+       // Table Schema -------------------------------------------------------------------------------------
+       // CREATE TABLE NfcPushMsgTable ( AppId TEXT PRIMARY KEY, PkgName TEXT, IconPath TEXT, MsgDesc TEXT );
+       // --------------------------------------------------------------------------------------------------
+
        const wchar_t* _QUERY_ALL_ITEM_SQL = L"SELECT AppId FROM NfcPushMsgTable";
        result r = E_SUCCESS;
        DbEnumerator* pQueryEnum = null;
 
-       r = __rsvdPushDb.Construct(_META_DATA_DB_NAME, true);
+       r = __rsvdPushDb.Construct(_META_DATA_DB_NAME, false);
        SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Construction of the database has failed.");
 
-       // create the table if it does not exist.
-       r = __rsvdPushDb.ExecuteSql(_CREATE_TABLE_SQL, true);
-       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Creating the DB table for push message has failed.");
-
        pQueryEnum = __rsvdPushDb.QueryN(_QUERY_ALL_ITEM_SQL);
        if (pQueryEnum != null)
        {
old mode 100644 (file)
new mode 100755 (executable)
index e02a6f8..a4d0658
@@ -43,10 +43,7 @@ using namespace Tizen::System;
 NfcService::NfcService(void)
        : __pRegisterService(null)
        , __pPushDelegate(null)
-       , __enablingMutex()
-       , __popupEnabled(false)
        , __serviceDaemonId()
-       , __popupDisablerId()
        , __listMutex()
        , __appPkgIdList()
 {
@@ -79,9 +76,6 @@ NfcService::Construct(void)
        SysTryReturnResult(NID_NET_NFC, (r == E_SUCCESS) && (isNfcSupported == true), E_UNSUPPORTED_OPERATION,
                          "NFC is not supported.");
 
-       r = __enablingMutex.Create();
-       SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Failed to create a mutex.");
-
        r = __listMutex.Create();
        SysTryReturnResult(NID_NET_NFC, r == E_SUCCESS, E_SYSTEM, "Failed to create a mutex.");
 
@@ -170,58 +164,6 @@ NfcService::RemoveNfcAppId(const Tizen::Base::String& appPkgId)
 }
 
 result
-NfcService::SetLaunchPopupEnabled(const Tizen::Base::String& clientPkgId, bool enable)
-{
-       result r = E_SUCCESS;
-       int nfcRes = NFC_ERROR_NONE;
-
-       MutexGuard locked(__enablingMutex);
-
-       // Updates the setting value and saves the ID of the setter application.
-       if (enable == false)
-       {
-               nfcRes = nfc_manager_set_system_handler_enable(false);
-
-               if (nfcRes == NFC_ERROR_NONE)
-               {
-                       __popupEnabled = false;
-                       __popupDisablerId = clientPkgId;
-
-                       SysLog(NID_NET_NFC, "Disabling the launch popup is successful.");
-               }
-               else
-               {
-                       r = E_SYSTEM;
-                       SysLog(NID_NET_NFC, "Disabling the launch popup has failed.");
-               }
-       }
-       else
-       {
-               if ((__popupEnabled == false) && (__popupDisablerId == clientPkgId))
-               {
-                       nfcRes = nfc_manager_set_system_handler_enable(true);
-
-                       if (nfcRes == NFC_ERROR_NONE)
-                       {
-                               __popupEnabled = true;
-                               __popupDisablerId.Clear();
-
-                               SysLog(NID_NET_NFC, "Enabling the launch popup is successful.");
-                       }
-                       else
-                       {
-                               r = E_SYSTEM;
-                               SysLog(NID_NET_NFC, "Enabling the launch popup has failed.");
-                       }
-               }
-       }
-
-       locked.Unlock();
-
-       return r;
-}
-
-result
 NfcService::RegisterPushMessage(const Tizen::Base::String& clientPkgId, const Tizen::Base::ByteBuffer& pushMessageBuffer,
                const Tizen::Base::String& description)
 {
@@ -253,7 +195,7 @@ NfcService::IsReservedPushActivated(void)
 }
 
 result
-NfcService::GetReservedPushCandidates(Tizen::Base::Collection::HashMap* pCandidates)
+NfcService::GetReservedPushCandidates(Tizen::Io::_StringMap* pCandidates)
 {
        return __pRegisterService->GetReservedPushCandidates(pCandidates);
 }
@@ -275,31 +217,6 @@ NfcService::GetPickedReservedPushMessage(Tizen::Base::String& appId)
 void
 NfcService::ProcessAppTermination(const Tizen::Base::String& clientPkgId)
 {
-       int nfcRes = NFC_ERROR_NONE;
-
-       MutexGuard locked(__enablingMutex);
-
-       if ((__popupEnabled == false) && (__popupDisablerId == clientPkgId))
-       {
-               SysLog(NID_NET_NFC, "The application (ID:'%S') which disabled the launch popup is terminated.", clientPkgId.GetPointer());
-
-               nfcRes = nfc_manager_set_system_handler_enable(true);
-
-               if (nfcRes == NFC_ERROR_NONE)
-               {
-                       __popupEnabled = true;
-                       __popupDisablerId.Clear();
-
-                       SysLog(NID_NET_NFC, "Enabling the launch popup is successful.");
-               }
-               else
-               {
-                       SysLog(NID_NET_NFC, "Enabling the launch popup has failed.");
-               }
-       }
-
-       locked.Unlock();
-
        // Remove appId if it was added to the list.
        RemoveNfcAppId(clientPkgId);
 }
index 9562b5d..6f05552 100755 (executable)
@@ -50,23 +50,18 @@ TelephonyConnectivityIpcStub::Construct(void)
        result r = E_SUCCESS;
        result retVal = E_SUCCESS;
 
-       __pTelephonyService = TelephonyService::GetInstance();
-       SysTryCatch(NID_TEL, __pTelephonyService != null, retVal = E_SYSTEM, E_SYSTEM,
-                       "[%s] A system error has been occurred. Failed to get the instance of TelephonyService.");
-
-       r = __pTelephonyService->Construct(this);
-       if (r == E_SUCCESS)
+       __pTelephonyService = TelephonyService::GetInstance(this);
+       if (__pTelephonyService != null)
     {
            SysLog(NID_TEL, "TelephonyService is created.");
     }
     else
     {
-        // skip Telephony service
-        SysLogException(NID_TEL, r, "[%s] Failed to construct TelephonyService.", GetErrorMessage(r));
-        __pTelephonyService = null;
+               // ignore the failure of creating the telephony service
+        SysLogException(NID_TEL, r, "[%s] Failed to construct TelephonyService.", GetErrorMessage(GetLastResult()));
     }
 
-       __pIpcServer = new (std::nothrow) _IpcServer;
+       __pIpcServer = new (std::nothrow) _IpcServer();
        SysTryCatch(NID_TEL, __pIpcServer != null, retVal = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                        "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
@@ -105,6 +100,11 @@ void
 TelephonyConnectivityIpcStub::OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId)
 {
        SysLog(NID_TEL, "Disconnected with clientId[%d].", clientId);
+
+       if (__pTelephonyService != null)
+       {
+               __pTelephonyService->RemoveNetworkStatusEventListener(clientId);
+       }
 }
 
 void
@@ -121,6 +121,8 @@ TelephonyConnectivityIpcStub::OnIpcRequestReceived(Tizen::Io::_IpcServer& server
        IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_requestCallForward, OnRequestCallForward, &server)
        IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_stopCallForward, OnStopCallForward, &server)
        IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_getCallForwardNumber, OnGetCallForwardNumber, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_addNetworkStatusEventListener, OnAddNetworkStatusEventListener, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_removeNetworkStatusEventListener, OnRemoveNetworkStatusEventListener, &server)
        IPC_END_MESSAGE_MAP()
 }
 
@@ -130,8 +132,13 @@ TelephonyConnectivityIpcStub::OnGetTelephonyImsi(Tizen::Base::String* pImsi, uns
     SysSecureLog(NID_TEL, "Received the request of getting the telephony imsi with clientId : %d, PkgId : %ls",
             __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
-    String pkgId = __pIpcServer->GetClientPackageId();
+       if (__pTelephonyService == null)
+       {
+               __pTelephonyService = TelephonyService::GetInstance(this);
+       }
 
+       String pkgId = __pIpcServer->GetClientPackageId();
+       SysSecureLog(NID_TEL, "[PERF] Check privilege.");
     *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_USERIDENTITY, _PRV_SYSTEMMANAGER);
 
     if (*pResult != E_SUCCESS)
@@ -140,6 +147,11 @@ TelephonyConnectivityIpcStub::OnGetTelephonyImsi(Tizen::Base::String* pImsi, uns
         SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
                        "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
     }
+    else if (__pTelephonyService == null)
+    {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_TEL, E_SYSTEM, "[%s] Telephony service is not ready.", GetErrorMessage(E_SYSTEM));
+    }
     else
     {
         *pResult = __pTelephonyService->GetImsi(pImsi);
@@ -169,10 +181,12 @@ TelephonyConnectivityIpcStub::OnGetTelephonyNetworkSelectionMode(unsigned long*
     SysLog(NID_TEL, "Received the request of getting the network selected mode with clientId : %d, PkgId : %ls",
             __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
-    SysLog(NID_TEL, "ipcserver : %d",__pIpcServer);
+       if (__pTelephonyService == null)
+       {
+               __pTelephonyService = TelephonyService::GetInstance(this);
+       }
 
     String pkgId = __pIpcServer->GetClientPackageId();
-
     *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_TELEPHONYMANAGER);
 
     if (*pResult != E_SUCCESS)
@@ -181,6 +195,11 @@ TelephonyConnectivityIpcStub::OnGetTelephonyNetworkSelectionMode(unsigned long*
        SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
                   "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
     }
+    else if (__pTelephonyService == null)
+    {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_TEL, E_SYSTEM, "[%s] Telephony service is not ready.", GetErrorMessage(E_SYSTEM));
+    }
     else
     {
        *pResult = __pTelephonyService->GetNetworkSelectionMode(__pIpcServer->GetClientId());
@@ -193,6 +212,11 @@ TelephonyConnectivityIpcStub::OnSelectTelephonyNetworkManual(const Tizen::Base::
     SysLog(NID_TEL, "Received the request for selecting network manually with clientId : %d, PkgId : %ls",
             __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
+       if (__pTelephonyService == null)
+       {
+               __pTelephonyService = TelephonyService::GetInstance(this);
+       }
+
     String pkgId = __pIpcServer->GetClientPackageId();
     *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_TELEPHONYMANAGER);
 
@@ -202,6 +226,11 @@ TelephonyConnectivityIpcStub::OnSelectTelephonyNetworkManual(const Tizen::Base::
        SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
                   "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
     }
+    else if (__pTelephonyService == null)
+    {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_TEL, E_SYSTEM, "[%s] Telephony service is not ready.", GetErrorMessage(E_SYSTEM));
+    }
     else
     {
        *pResult = __pTelephonyService->SelectNetwork(__pIpcServer->GetClientId(), plmn, networkType);
@@ -214,20 +243,28 @@ TelephonyConnectivityIpcStub::OnSelectTelephonyNetworkAutomatic(unsigned long* p
     SysLog(NID_TEL, "Received the request for selecting network automatically with clientId : %d, PkgId : %ls",
             __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
+       if (__pTelephonyService == null)
+       {
+               __pTelephonyService = TelephonyService::GetInstance(this);
+       }
+
     String pkgId = __pIpcServer->GetClientPackageId();
     *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_TELEPHONYMANAGER);
 
-
     if (*pResult != E_SUCCESS)
     {
        *pResult = E_PRIVILEGE_DENIED;
        SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
                   "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
     }
+    else if (__pTelephonyService == null)
+    {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_TEL, E_SYSTEM, "[%s] Telephony service is not ready.", GetErrorMessage(E_SYSTEM));
+    }
     else
     {
        *pResult = __pTelephonyService->SelectNetwork(__pIpcServer->GetClientId());
-
     }
 }
 
@@ -237,7 +274,12 @@ TelephonyConnectivityIpcStub::OnSearchTelephonyNetwork(unsigned long* pResult)
     SysLog(NID_TEL, "Received the request for searching network with clientId : %d, PkgId : %ls",
             __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
-    String pkgId = __pIpcServer->GetClientPackageId();
+       if (__pTelephonyService == null)
+       {
+               __pTelephonyService = TelephonyService::GetInstance(this);
+       }
+
+       String pkgId = __pIpcServer->GetClientPackageId();
     *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_TELEPHONYMANAGER);
 
     if (*pResult != E_SUCCESS)
@@ -246,7 +288,12 @@ TelephonyConnectivityIpcStub::OnSearchTelephonyNetwork(unsigned long* pResult)
        SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
                   "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
     }
-    else
+    else if (__pTelephonyService == null)
+    {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_TEL, E_SYSTEM, "[%s] Telephony service is not ready.", GetErrorMessage(E_SYSTEM));
+    }
+   else
     {
        *pResult = __pTelephonyService->SearchNetwork(__pIpcServer->GetClientId());
     }
@@ -275,6 +322,11 @@ TelephonyConnectivityIpcStub::OnRequestCallForward(const String& phoneNumber, un
     SysLog(NID_TEL, "Received the request for requesting call forward with clientId : %d, PkgId : %ls",
             __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
+       if (__pTelephonyService == null)
+       {
+               __pTelephonyService = TelephonyService::GetInstance(this);
+       }
+
        String pkgId = __pIpcServer->GetClientPackageId();
        *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_CALLFORWARD);
 
@@ -284,6 +336,11 @@ TelephonyConnectivityIpcStub::OnRequestCallForward(const String& phoneNumber, un
        SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
                   "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
     }
+    else if (__pTelephonyService == null)
+    {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_TEL, E_SYSTEM, "[%s] Telephony service is not ready.", GetErrorMessage(E_SYSTEM));
+    }
     else
     {
        *pResult = __pTelephonyService->RequestCallForward(__pIpcServer->GetClientId(), phoneNumber);
@@ -296,6 +353,11 @@ TelephonyConnectivityIpcStub::OnStopCallForward(unsigned long* pResult)
     SysLog(NID_TEL, "Received the request for stopping call forward with clientId : %d, PkgId : %ls",
             __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
+       if (__pTelephonyService == null)
+       {
+               __pTelephonyService = TelephonyService::GetInstance(this);
+       }
+
        String pkgId = __pIpcServer->GetClientPackageId();
        *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_CALLFORWARD);
 
@@ -305,6 +367,11 @@ TelephonyConnectivityIpcStub::OnStopCallForward(unsigned long* pResult)
        SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
                   "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
     }
+    else if (__pTelephonyService == null)
+    {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_TEL, E_SYSTEM, "[%s] Telephony service is not ready.", GetErrorMessage(E_SYSTEM));
+    }
     else
     {
        *pResult = __pTelephonyService->StopCallForward(__pIpcServer->GetClientId());
@@ -317,6 +384,11 @@ TelephonyConnectivityIpcStub::OnGetCallForwardNumber(unsigned long* pResult)
     SysLog(NID_TEL, "Received the request for getting call forward number with clientId : %d, PkgId : %ls",
           __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
+       if (__pTelephonyService == null)
+       {
+               __pTelephonyService = TelephonyService::GetInstance(this);
+       }
+
        String pkgId = __pIpcServer->GetClientPackageId();
        *pResult = _AccessController::CheckSystemPrivilege(pkgId, _PRV_CALLFORWARD);
 
@@ -326,11 +398,61 @@ TelephonyConnectivityIpcStub::OnGetCallForwardNumber(unsigned long* pResult)
         SysLogException(NID_TEL, E_PRIVILEGE_DENIED,
                        "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
     }
+    else if (__pTelephonyService == null)
+    {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_TEL, E_SYSTEM, "[%s] Telephony service is not ready.", GetErrorMessage(E_SYSTEM));
+    }
     else
     {
          *pResult = __pTelephonyService->GetCallForwardNumber(__pIpcServer->GetClientId());
     }
 }
+
+void
+TelephonyConnectivityIpcStub::OnAddNetworkStatusEventListener(unsigned long* pResult)
+{
+    SysLog(NID_TEL, "Received the request for adding network status event listener with clientId : %d, PkgId : %ls",
+          __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (__pTelephonyService == null)
+       {
+               __pTelephonyService = TelephonyService::GetInstance(this);
+       }
+
+    if (__pTelephonyService == null)
+    {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_TEL, E_SYSTEM, "[%s] Telephony service is not ready.", GetErrorMessage(E_SYSTEM));
+    }
+    else
+    {
+        *pResult = __pTelephonyService->AddNetworkStatusEventListener(__pIpcServer->GetClientId());
+    }
+ }
+
+void
+TelephonyConnectivityIpcStub::OnRemoveNetworkStatusEventListener(unsigned long* pResult)
+{
+    SysLog(NID_TEL, "Received the request for removing network status event listener with clientId : %d, PkgId : %ls",
+          __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (__pTelephonyService == null)
+       {
+               __pTelephonyService = TelephonyService::GetInstance(this);
+       }
+
+    if (__pTelephonyService == null)
+    {
+        *pResult = E_SYSTEM;
+        SysLogException(NID_TEL, E_SYSTEM, "[%s] Telephony service is not ready.", GetErrorMessage(E_SYSTEM));
+    }
+    else
+    {
+       *pResult = __pTelephonyService->RemoveNetworkStatusEventListener(__pIpcServer->GetClientId());
+    }
+ }
+
 result
 TelephonyConnectivityIpcStub::SendNetworkSelectionModeReceived(int clientId, bool isManual, unsigned long res)
 {
@@ -365,10 +487,8 @@ TelephonyConnectivityIpcStub::SendNetworkSearchCompleted(int clientId, Tizen::Ba
     SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
 
     return __pIpcServer->SendResponse(clientId, *pMessage);
-
 }
 
-
 result
 TelephonyConnectivityIpcStub::SendCallForwardNumberReceived(int clientId, String phoneNumber, unsigned long res)
 {
@@ -403,3 +523,14 @@ TelephonyConnectivityIpcStub::SendCallForwardStopped(int clientId, String phoneN
 
     return __pIpcServer->SendResponse(clientId, *pMessage);
 }
+
+result
+TelephonyConnectivityIpcStub::SendNetworkStatusChanged(int clientId, bool isCallServiceAvailable, bool isDataServiceAvailable, bool isRoaming)
+{
+    SysLog(NID_TEL, "SendNetworkStatusChanged with clientId : %d", clientId);
+
+    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityTelephonyServiceMsg_onNetworkStatusChanged(isCallServiceAvailable, isDataServiceAvailable, isRoaming));
+    SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    return __pIpcServer->SendResponse(clientId, *pMessage);
+}
index d4ed1cc..690a0a2 100755 (executable)
 #include <unique_ptr.h>
 #include <pthread.h>
 #include <sim.h>
+#include <tapi_common.h>
 #include <ITapiNetwork.h>
+#include <ITapiSim.h>
 #include <ITapiSs.h>
 #include <TapiUtility.h>
 #include <TelNetwork.h>
-#include <FApp_AppManagerImpl.h>
+#include <telephony_network.h>
+#include <FBase.h>
 #include <FBaseSysLog.h>
 #include <FBaseString.h>
-#include <TelephonyConnectivityIpcStub.h>
-#include "FBase_StringConverter.h"
+#include <FSystem.h>
+#include <FApp_AppManagerImpl.h>
+#include <FBase_StringConverter.h>
+#include "TelephonyConnectivityIpcStub.h"
 #include "TelephonyService.h"
 
 using namespace std;
 using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::System;
 
 TelephonyService* TelephonyService::__pTelephonyService = null;
 
 void
 TelephonyService::InitTelephonyService()
 {
-    static TelephonyService telephonyService;
-    __pTelephonyService = &telephonyService;
+    result r = E_SUCCESS;
+
+       unique_ptr<TelephonyService> pInstance(new (std::nothrow) TelephonyService());
+       SysTryReturnVoidResult(NID_TEL, pInstance != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+       r = pInstance->Construct();
+       SysTryReturnVoidResult(NID_TEL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       ClearLastResult();
+
+       __pTelephonyService = pInstance.release();
 }
 
 TelephonyService*
-TelephonyService::GetInstance(void)
+TelephonyService::GetInstance(TelephonyConnectivityIpcStub* pStub)
 {
-    static pthread_once_t once_block = PTHREAD_ONCE_INIT;
-
-    if (__pTelephonyService == null)
-    {
-        pthread_once(&once_block, InitTelephonyService);
-    }
+       static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
+
+       if (__pTelephonyService == null)
+       {
+               ClearLastResult();
+               pthread_once(&onceBlock, InitTelephonyService);
+               result r = GetLastResult();
+               if (r != E_SUCCESS)
+               {
+                       onceBlock = PTHREAD_ONCE_INIT;
+               }
+               else
+               {
+                       __pTelephonyService->SetIpcStub(pStub);
+               }
+       }
 
-    return __pTelephonyService;
+       return __pTelephonyService;
 }
 
-
 TelephonyService::TelephonyService(void)
-    : __pHandle(null)
-    , __pStub(null)
+       : __pStub(null)
+    , __pHandle(null)
+       , __pConnectionHandle(null)
+       , __pClientList(null)
+       , __clientCount(0)
+       , __isCallServiceAvailable(false)
+       , __isDataServiceAvailable(false)
+       , __isRoaming(false)
 {
 }
 
-
 TelephonyService::~TelephonyService(void)
 {
+       if (__pConnectionHandle != null)
+       {
+               connection_destroy(__pConnectionHandle);
+       }
+
     if (__pHandle != null)
     {
         tel_deinit(__pHandle);
@@ -75,14 +110,36 @@ TelephonyService::~TelephonyService(void)
 }
 
 result
-TelephonyService::Construct(TelephonyConnectivityIpcStub* pStub)
+TelephonyService::Construct(void)
 {
+    result r = E_SUCCESS;
+
+    unique_ptr< ArrayListT<int> > pClientList(new (std::nothrow) ArrayListT<int>());
+    SysTryReturnResult(NID_TEL, pClientList != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+    r = pClientList->Construct();
+    SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
+
+       int err = CONNECTION_ERROR_NONE;
+
+       err = connection_create(&__pConnectionHandle);
+       SysLog(NID_TEL, "The return value of connection_create() is 0x%x", err);
+    SysTryReturnResult(NID_TEL, err == CONNECTION_ERROR_NONE, E_SYSTEM, "A system error has occurred. Failed to create a connection handle.");
+
     __pHandle = tel_init(null);
-    __pStub = pStub;
+
+    __pClientList = move(pClientList);
+    __clientCount = 0;
 
     return E_SUCCESS;
 }
 
+void
+TelephonyService::SetIpcStub(TelephonyConnectivityIpcStub* pStub)
+{
+    __pStub = pStub;
+}
+
 result
 TelephonyService::GetImsi(Tizen::Base::String* pImsi)
 {
@@ -284,6 +341,106 @@ TelephonyService::GetCallForwardNumber(int clientId)
     return E_SUCCESS;
 }
 
+result
+TelephonyService::AddNetworkStatusEventListener(int clientId)
+{
+       result r = E_SUCCESS;
+
+    if (__pHandle == null)
+    {
+       __pHandle = tel_init(null);
+    }
+    SysTryReturnResult(NID_TEL, __pHandle != null, E_SYSTEM, "Failed to initialize telephony handle.");
+
+       r = __pClientList->Add(clientId);
+    SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
+
+       if (__clientCount == 0)
+       {
+               SysLog(NID_TEL, "Set network event callback.");
+
+               int err = CONNECTION_ERROR_NONE;
+
+               // Register data service state changed event
+           err = connection_set_type_changed_cb(__pConnectionHandle,(connection_type_changed_cb)TelephonyService::OnDataServiceStateChangedCallback, this);
+               SysLog(NID_TEL, "The return value of connection_set_type_changed_cb() is 0x%x", err);
+               if (err != CONNECTION_ERROR_NONE)
+               {
+                       SysLogException(NID_TEL, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to register the callback function to received the data service state changed event.");
+                       __pClientList->Remove(clientId);
+
+               return E_SYSTEM;
+               }
+
+        // Register call service state changed event
+               err = network_info_set_service_state_changed_cb((network_info_service_state_changed_cb)TelephonyService::OnCallServiceStateChangedCallback, this);
+               SysLog(NID_TEL, "The return value of network_info_set_service_state_changed_cb() is 0x%x", err);
+               if (err != NETWORK_INFO_ERROR_NONE)
+               {
+                       SysLogException(NID_TEL, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to register the callback function to received the call service state changed event.");
+               connection_unset_type_changed_cb(__pConnectionHandle);
+               __pClientList->Remove(clientId);
+
+               return E_SYSTEM;
+               }
+
+        // Register roaming state changed event
+           err = network_info_set_roaming_state_changed_cb((network_info_roaming_state_changed_cb)TelephonyService::OnRoamingStateChangedCallback, this);
+               SysLog(NID_TEL, "The return value of network_info_set_roaming_state_changed_cb() is 0x%x", err);
+               if (err != NETWORK_INFO_ERROR_NONE)
+               {
+                       SysLogException(NID_TEL, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to register the callback function to received the roaming state changed event.");
+               network_info_unset_service_state_changed_cb();
+               connection_unset_type_changed_cb(__pConnectionHandle);
+               __pClientList->Remove(clientId);
+
+               return E_SYSTEM;
+               }
+
+           __isCallServiceAvailable = IsServiceAvailable();
+           if (__isCallServiceAvailable)
+           {
+               __isDataServiceAvailable = IsDataAvailable();
+           }
+           else
+           {
+               __isDataServiceAvailable = false;
+           }
+           __isRoaming = IsRoaming();
+       }
+
+    __clientCount++;
+
+       return E_SUCCESS;
+}
+
+result
+TelephonyService::RemoveNetworkStatusEventListener(int clientId)
+{
+       if (!__pClientList->Contains(clientId))
+       {
+               SysLog(NID_TEL, "Client[%d] is not found, so ignore the request.", clientId);
+               return E_SUCCESS;
+       }
+
+       result r = __pClientList->Remove(clientId);
+       if (r == E_SUCCESS)
+       {
+               __clientCount--;
+       }
+
+       if (__clientCount == 0)
+       {
+               SysLog(NID_TEL, "Unset network event callback.");
+
+               network_info_unset_service_state_changed_cb();
+        network_info_unset_roaming_state_changed_cb();
+        connection_unset_type_changed_cb(__pConnectionHandle);
+       }
+
+       return E_SUCCESS;
+}
+
 void
 TelephonyService::OnNetworkSelectionModeReceived(TapiHandle* pHandle, int err, void* pData, void* pUserData)
 {
@@ -520,3 +677,155 @@ TelephonyService::ConvertError(int err)
 
     return r;
 }
+
+void
+TelephonyService::OnRoamingStateChangedCallback(bool isRoaming, void* pUserData)
+{
+       SysLog(NID_TEL, "The callback has called and the roaming state is %s", isRoaming ? "True" : "False");
+
+       TelephonyService* pTelephonyService = static_cast <TelephonyService*>(pUserData);
+       SysTryReturnVoidResult(NID_TEL, pTelephonyService != null, E_SYSTEM, "[E_SYSTEM] The instance handle is NULL.");
+
+       pTelephonyService->OnTelephonyNetworkStatusChanged();
+}
+
+void
+TelephonyService::OnCallServiceStateChangedCallback(network_info_service_state_e serviceState, void* pUserData)
+{
+    SysLog(NID_TEL, "The callback has called and the service state is %d", serviceState);
+
+       TelephonyService* pTelephonyService = static_cast <TelephonyService*>(pUserData);
+       SysTryReturnVoidResult(NID_TEL, pTelephonyService != null, E_SYSTEM, "[E_SYSTEM] The instance handle is NULL.");
+
+       pTelephonyService->OnTelephonyNetworkStatusChanged();
+}
+
+void
+TelephonyService::OnDataServiceStateChangedCallback(connection_type_e type, void* pUserData)
+{
+    SysLog(NID_TEL, "The callback has called and the connection state is %d", type);
+
+       TelephonyService* pTelephonyService = static_cast <TelephonyService*>(pUserData);
+       SysTryReturnVoidResult(NID_TEL, pTelephonyService != null, E_SYSTEM, "[E_SYSTEM] The instance handle is NULL.");
+
+       pTelephonyService->OnTelephonyNetworkStatusChanged();
+}
+
+void
+TelephonyService::OnTelephonyNetworkStatusChanged(void)
+{
+       bool isCallServiceAvailable = false;
+       bool isDataServiceAvailable = false;
+       bool isRoaming = false;
+
+    isCallServiceAvailable = IsServiceAvailable();
+    if (isCallServiceAvailable)
+    {
+       isDataServiceAvailable = IsDataAvailable();
+    }
+    else
+    {
+       isDataServiceAvailable = false;
+    }
+    isRoaming = IsRoaming();
+
+    SysLog(NID_TEL, "The network status Call[%d]->[%d] Data[%d]->[%d] Roaming[%d]->[%d]",
+               __isCallServiceAvailable, isCallServiceAvailable, __isDataServiceAvailable,
+               isDataServiceAvailable, __isRoaming, isRoaming);
+
+    if ((__isCallServiceAvailable == isCallServiceAvailable) &&
+       (__isDataServiceAvailable == isDataServiceAvailable) &&
+       (__isRoaming == isRoaming))
+    {
+       return;
+    }
+
+    __isCallServiceAvailable = isCallServiceAvailable;
+    __isDataServiceAvailable = isDataServiceAvailable;
+    __isRoaming = isRoaming;
+
+       result r = E_SUCCESS;
+       int clientId = 0;
+
+       unique_ptr< IEnumeratorT<int> > pEnum(__pClientList->GetEnumeratorN());
+       if (pEnum != null)
+       {
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       r = pEnum->GetCurrent(clientId);
+                       if ((r == E_SUCCESS) && (clientId > 0))
+                       {
+                           __pStub->SendNetworkStatusChanged(clientId, __isCallServiceAvailable, __isDataServiceAvailable, __isRoaming);
+                       }
+               }
+       }
+}
+
+bool
+TelephonyService::IsServiceAvailable(void) const
+{
+    bool isAvailable = false;
+    int err = NETWORK_INFO_ERROR_NONE;
+    network_info_service_state_e state;
+
+    err = network_info_get_service_state(&state);
+       SysLog(NID_TEL, "The return value of network_info_get_service_state() is 0x%x and the state is %d", err, state);
+
+    if (state == NETWORK_INFO_SERVICE_STATE_IN_SERVICE)
+    {
+        isAvailable = true;
+    }
+
+    return isAvailable;
+}
+
+bool
+TelephonyService::IsDataAvailable(void) const
+{
+    int err = CONNECTION_ERROR_NONE;
+    connection_cellular_state_e dataServiceState = CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
+    bool isDataAvailable = false;
+
+    err = connection_get_cellular_state(__pConnectionHandle, &dataServiceState);
+
+    SysLog(NID_TEL, "The return value of connection_get_cellular_state() is 0x%x and the dataServiceState is %d", err, dataServiceState);
+
+    if (dataServiceState == CONNECTION_CELLULAR_STATE_AVAILABLE || dataServiceState == CONNECTION_CELLULAR_STATE_CONNECTED)
+    {
+       isDataAvailable = true;
+    }
+    else
+    {
+       isDataAvailable = false;
+    }
+
+    return isDataAvailable;
+}
+
+bool
+TelephonyService::IsRoaming(void) const
+{
+    int err = NETWORK_INFO_ERROR_NONE;
+    bool isRoaming = false;
+
+    err = network_info_is_roaming(&isRoaming);
+    SysLog(NID_TEL, "The return value of network_info_is_roaming() is 0x%x and the roming state is %s", err, isRoaming ? "True" : "False");
+
+    return isRoaming;
+}
+
+bool
+TelephonyService::IsNetworkAvailable(void) const
+{
+    bool isFlightModeEnabled = false;
+    result r = SettingInfo::GetValue(L"http://tizen.org/setting/network.flight_mode", isFlightModeEnabled);
+       SysLog(NID_TEL, "isFlightModeEnabled is %s", isFlightModeEnabled ? "True":"False");
+       SysLog(NID_TEL, "The return value of SettingInfo::GetValue() is %s", GetErrorMessage(r));
+
+       if (r != E_SUCCESS)
+       {
+           return false;
+       }
+
+    return !isFlightModeEnabled;
+}
old mode 100644 (file)
new mode 100755 (executable)
index 849725c..0acbab3
 #include <unique_ptr.h>
 #include <FBaseSysLog.h>
 #include <FNetWifiWifiBssInfo.h>
+#include <FNetNetAccountInfo.h>
+#include <FBaseColArrayListT.h>
 #include <FIo_IpcServer.h>
 #include <FNetWifi_ConnectivityIpcMessages.h>
 #include <FSec_AccessController.h>
 #include "WifiConnectivityIpcStub.h"
 #include "WifiService.h"
+#include "WifiDirectService.h"
 #include "WifiProximityService.h"
+#include "FNetWifi_WifiNetAccountInfoImpl.h"
 
 using namespace std;
 using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
 using namespace Tizen::Io;
 using namespace Tizen::Security;
 using namespace Tizen::Net;
+using namespace Tizen::Net::Wifi;
 
 WifiConnectivityIpcStub::WifiConnectivityIpcStub(void)
-       : __pWifiProximityService(null)
+       : __pIpcServer(null)
        , __pWifiService(null)
-       , __pIpcServer(null)
+       , __pWifiDirectService(null)
+       , __pWifiProximityService(null) 
 {
 }
 
 WifiConnectivityIpcStub::~WifiConnectivityIpcStub(void)
 {
-       delete __pIpcServer;
-       delete __pWifiService;
-       delete __pWifiProximityService;
+
 }
 
 result
 WifiConnectivityIpcStub::Construct(void)
 {
        result r = E_SUCCESS;
-       unique_ptr<WifiService> pWifiService;
        unique_ptr<_IpcServer> pIpcServer;
+       unique_ptr<WifiService> pWifiService;
+       unique_ptr<WifiDirectService> pWifiDirectService;
        unique_ptr<WifiProximityService> pWifiProximityService;
 
        pWifiService.reset(new (std::nothrow) WifiService());
        SysTryReturnResult(NID_NET_WIFI, pWifiService != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
 
-       r = pWifiService->Construct();
+       r = pWifiService->Construct(*this);
+
        if (r == E_SUCCESS)
        {
-               SysLog(NID_NET_WIFI, "WifiService is created.");
+
+               SysLog(NID_NET_WIFI, "WifiService is created");
 
                pWifiProximityService.reset(new (std::nothrow) WifiProximityService());
                SysTryReturnResult(NID_NET_WIFI, pWifiProximityService != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
 
-               r = pWifiProximityService->Construct(this);
+               r = pWifiProximityService->Construct(*this);
+
                if (r == E_SUCCESS)
-           {
-                   SysLog(NID_NET_WIFI, "WifiProximityService is created.");
-           }
-           else
-           {
-                       // ignore the failure of creating the Wi-Fi Proximity service
-               SysLogException(NID_NET_WIFI, r, "[%s] Failed to construct WifiProximityService.", GetErrorMessage(r));
-               pWifiProximityService.reset(null);
-           }
+               {
+                       SysLog(NID_NET_WIFI, "WifiProximityService is created");
+               }
+               else
+               {
+                       // ignore the failure of creating the WifiProximityService
+                       SysLogException(NID_NET_WIFI, r, "[%s] Failed to construct WifiProximityService.", GetErrorMessage(r));
+                       pWifiService.reset(null);
+               }
        }
        else
        {
-               // ignore the failure of creating the Wi-Fi service
+               // ignore the failure of creating the Wifi service
                SysLogException(NID_NET_WIFI, r, "[%s] Failed to construct WifiService.", GetErrorMessage(r));
                pWifiService.reset(null);
        }
 
+       pWifiDirectService.reset(new (std::nothrow) WifiDirectService());
+       SysTryReturnResult(NID_NET_WIFI, pWifiDirectService != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       r = pWifiDirectService->Construct(*this);
+       if (r == E_SUCCESS)
+       {
+               SysLog(NID_NET_WIFI, "WifiDirectService is created.");
+       }
+       else
+       {
+               // ignore the failure of creating the WifiDirect service
+               SysLogException(NID_NET_WIFI, r, "[%s] Failed to construct WifiDirectService.", GetErrorMessage(r));
+               pWifiDirectService.reset(null);
+       }
+
+
        pIpcServer.reset(new (std::nothrow) _IpcServer());
        SysTryReturnResult(NID_NET_WIFI, pIpcServer != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
 
        r = pIpcServer->Construct(WIFI_CONNECTIVITY_IPC_SERVER_NAME, *this);
        SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Failed to construct IpcServer.");
+       SysLog(NID_NET_WIFI, "_IpcServer is created");
 
-       __pWifiService = pWifiService.release();
-       __pWifiProximityService = pWifiProximityService.release();
-       __pIpcServer = pIpcServer.release();
+       __pWifiService = move(pWifiService);
+       __pWifiProximityService = move(pWifiProximityService);
+       __pWifiDirectService = move(pWifiDirectService);
+       __pIpcServer = move(pIpcServer);
 
        return E_SUCCESS;
+
+}
+
+// Wifi
+result
+WifiConnectivityIpcStub::SendWifiActivated(int clientId, unsigned long res)
+{
+       SysLog(NID_NET_WIFI, "SendWifiActivated with clientId : %d", clientId);
+
+       unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiActivated(res));
+       SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+WifiConnectivityIpcStub::SendWifiDeactivated(int clientId, unsigned long res)
+{
+       SysLog(NID_NET_WIFI, "SendWifiDeactivated with clientId : %d", clientId);
+
+       unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiDeactivated(res));
+       SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       return __pIpcServer->SendResponse(clientId, *pMessage);
+
+}
+
+result
+WifiConnectivityIpcStub::SendWifiScanCompleted(int clientId,
+               Tizen::Base::Collection::ArrayListT<Tizen::Net::Wifi::WifiBssInfo*>* pBssInfoList, unsigned long res)
+{
+       SysLog(NID_NET_WIFI, "SendWifiScanCompleted with clientId : %d", clientId);
+
+       unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiScanCompleted(*pBssInfoList, res));
+       SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       return __pIpcServer->SendResponse(clientId, *pMessage);
+
+}
+
+result
+WifiConnectivityIpcStub::SendWifiConnected(int clientId, const Tizen::Base::String& ssid, unsigned long res)
+{
+       SysLog(NID_NET_WIFI, "SendWifiConnected with clientId : %d", clientId);
+
+       unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiConnected(ssid, res));
+       SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       return __pIpcServer->SendResponse(clientId, *pMessage);
+
+}
+result
+WifiConnectivityIpcStub::SendWifiDisconnected(int clientId)
+{
+       SysLog(NID_NET_WIFI, "SendWifiDisconnected with clientId : %d", clientId);
+
+       unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiDisconnected());
+       SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       return __pIpcServer->SendResponse(clientId, *pMessage);
+
+}
+
+result
+WifiConnectivityIpcStub::SendWifiRssiChanged(int clientId, long rssi)
+{
+       SysLog(NID_NET_WIFI, "SendWifiRssiChanged with clientId : %d", clientId);
+
+       unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiRssiChanged(rssi));
+       SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+WifiConnectivityIpcStub::SendWifiConnectionStateChanged(int clientId, int state)
+{
+       SysLog(NID_NET_WIFI, "SendWifiConnectionStateChanged with clientId : %d", clientId);
+
+       unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiConnectionStateChanged(state));
+       SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+WifiConnectivityIpcStub::SendWifiSystemScanResultUpdated(int clientId)
+{
+       SysLog(NID_NET_WIFI, "SendWifiSystemScanResultUpdated with clientId : %d", clientId);
+
+       unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiSystemScanResultUpdated());
+       SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       return __pIpcServer->SendResponse(clientId, *pMessage);
 }
 
 void
@@ -117,6 +238,7 @@ void
 WifiConnectivityIpcStub::OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId)
 {
        SysLog(NID_NET_WIFI, "Connected with clientId[%d].", clientId);
+
 }
 
 void
@@ -126,30 +248,106 @@ WifiConnectivityIpcStub::OnIpcClientDisconnected(const Tizen::Io::_IpcServer&ser
 
        if (__pWifiService != null)
        {
-               __pWifiService->ProcessAppTermination(__pIpcServer->GetClientPackageId());
+               __pWifiService->UnregisterManagerClientId(clientId);
+               __pWifiService->UnregisterMonitoringClientId(clientId);
        }
 
        if (__pWifiProximityService != null)
        {
                __pWifiProximityService->UnregisterClient(clientId);
        }
+
+       if (__pWifiDirectService != null)
+       {
+               __pWifiDirectService->ProcessAppTermination(__pIpcServer->GetClientPackageId());
+       }
 }
 
+// WifiProximity
+result
+WifiConnectivityIpcStub::SendProximityCheckActivated(int clientId)
+{
+       SysLog(NID_NET_WIFI, "SendProximityCheckActivated with clientId : %d", clientId);
+
+       unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onProximityCheckActivated());
+       SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+WifiConnectivityIpcStub::SendProximityCheckDeactivated(int clientId)
+{
+       SysLog(NID_NET_WIFI, "SendProximityCheckDeactivated with clientId : %d", clientId);
+
+       unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onProximityCheckDeactivated());
+       SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+WifiConnectivityIpcStub::SendWifiBssDetected(int clientId, const Tizen::Net::Wifi::WifiBssInfo& wifiBssInfo)
+{
+       SysLog(NID_NET_WIFI, "SendWifiBssDetected with clientId : %d", clientId);
+
+       unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiBssDetected(wifiBssInfo));
+       SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+result
+WifiConnectivityIpcStub::SendWifiBssLost(int clientId, const Tizen::Base::String& bssId)
+{
+       SysLog(NID_NET_WIFI, "SendWifiBssLost with clientId : %d", clientId);
+
+       unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiBssLost(bssId));
+       SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+       return __pIpcServer->SendResponse(clientId, *pMessage);
+}
+
+
+
 void
 WifiConnectivityIpcStub::OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message)
 {
        IPC_BEGIN_MESSAGE_MAP(WifiConnectivityIpcStub, message)
-       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_setSystemScanMode, OnSetWifiSystemScanMode, &server)
-       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_checkSystemSettingPrivilege, OnCheckWifiSystemSettingPrivilege, &server)
+
+       // Wifi(13)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_registerManagerEventCallback, OnRegisterManagerEventCallback, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_unregisterManagerEventCallback, OnUnregisterManagerEventCallback, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_activateWifi,OnActivateWifi, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_deactivateWifi, OnDeactivateWifi, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_scanWifi, OnScanWifi, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_connectWifi, OnConnectWifi, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_getWifiMacAddress, OnGetWifiMacAddress, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_isWifiActivated, OnIsWifiActivated, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_isWifiConnected, OnIsWifiConnected, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_getWifiConnectionState, OnGetWifiConnectionState, &server)
        IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_updateWifiBssInfo, OnUpdateWifiBssInfo, &server)
-       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_initializeWifiDirect, OnInitializeWifiDirect, &server)
-       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_getWifiDirectLocalDeviceName, OnGetWifiDirectLocalDeviceName, &server)
-       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_setWifiDirectLocalDeviceName, OnSetWifiDirectLocalDeviceName, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_getWifiConnectionTargetInfo, OnGetWifiConnectionTargetInfo, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_getWifiNetAccountInfo, OnGetWifiNetAccountInfo, &server)
+
+       // Wifi System Monitoring(4)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_registerSystemMonitoringEventCallback, OnRegisterSystemMonitoringCallback, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_unregisterSystemMonitoringEventCallback, OnUnregisterSystemMonitoringCallback, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_setSystemScanMode, OnSetWifiSystemScanMode, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_getWifiSystemScanResult, OnGetWifiSystemScanResult, &server)
+
+       // Wifi Proximity(5)
        IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_registerBssId, OnRegisterBssId, &server)
        IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_unregisterBssId, OnUnregisterBssId, &server)
        IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_activateProximityCheck, OnProximityCheckActivated, &server)
        IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_deactivateProximityCheck, OnProximityCheckDeactivated, &server)
        IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_isProximityCheckActivated, OnIsProximityCheckActivated, &server)
+
+       // Wifi Direct(3)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_initializeWifiDirect, OnInitializeWifiDirect, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_getWifiDirectLocalDeviceName, OnGetWifiDirectLocalDeviceName, &server)
+       IPC_MESSAGE_HANDLER(ConnectivityWifiServiceMsg_setWifiDirectLocalDeviceName, OnSetWifiDirectLocalDeviceName, &server)
+
        IPC_END_MESSAGE_MAP()
 }
 
@@ -157,12 +355,10 @@ void
 WifiConnectivityIpcStub::OnSetWifiSystemScanMode(int mode, unsigned long* pResult)
 {
 #if !defined (_OSP_EMUL_)
-       String packageId = __pIpcServer->GetClientPackageId();
-
        SysSecureLog(NID_NET_WIFI, "Received the request of setting the Wi-Fi system scan mode with clientId : %d, AppPkgId : %ls",
-                               __pIpcServer->GetClientId(), packageId.GetPointer());
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
-       *pResult = _AccessController::CheckSystemPrivilege(packageId, _PRV_WIFIMANAGER);
+       *pResult = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientPackageId(), _PRV_WIFIMANAGER);
 
        if (*pResult != E_SUCCESS)
        {
@@ -170,13 +366,14 @@ WifiConnectivityIpcStub::OnSetWifiSystemScanMode(int mode, unsigned long* pResul
                SysLogException(NID_NET_WIFI, E_PRIVILEGE_DENIED,
                                "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
        }
-       else if (__pWifiService == null)
+       else if(__pWifiService == null)
        {
                *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
        }
        else
        {
-               *pResult = __pWifiService->SetWifiSystemScanMode(mode);
+        *pResult = __pWifiService->SetWifiSystemScanMode(mode);
        }
 #else
        SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
@@ -185,9 +382,78 @@ WifiConnectivityIpcStub::OnSetWifiSystemScanMode(int mode, unsigned long* pResul
 }
 
 void
-WifiConnectivityIpcStub::OnCheckWifiSystemSettingPrivilege(unsigned long* pResult)
+WifiConnectivityIpcStub::OnRegisterManagerEventCallback(unsigned long* pResult)
 {
 #if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "OnRegisterManagerEventCallback with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
+       }
+       else
+       {
+               *pResult = __pWifiService->RegisterManagerClientId(__pIpcServer->GetClientId());
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnUnregisterManagerEventCallback(unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "OnRegisterManagerEventCallback with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
+       }
+       else
+       {
+               *pResult = __pWifiService->UnregisterManagerClientId(__pIpcServer->GetClientId());
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+
+void
+WifiConnectivityIpcStub::OnRegisterSystemMonitoringCallback(unsigned long* pResult)
+{
+       SysSecureLog(NID_NET_WIFI, "Received the request of checking the Wi-Fi system setting privilege with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       *pResult = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientPackageId(), _PRV_WIFIMANAGER);
+
+       if (*pResult != E_SUCCESS)
+       {
+               *pResult = E_PRIVILEGE_DENIED;
+               SysLogException(NID_NET_WIFI, E_PRIVILEGE_DENIED,
+                               "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
+       }
+       else if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
+       }
+       else
+       {
+               *pResult = __pWifiService->RegisterMonitoringClientId(__pIpcServer->GetClientId());
+       }
+}
+
+void
+WifiConnectivityIpcStub::OnUnregisterSystemMonitoringCallback(unsigned long* pResult)
+{
        String packageId = __pIpcServer->GetClientPackageId();
 
        SysSecureLog(NID_NET_WIFI, "Received the request of checking the Wi-Fi system setting privilege with clientId : %d, AppPkgId : %ls",
@@ -201,10 +467,15 @@ WifiConnectivityIpcStub::OnCheckWifiSystemSettingPrivilege(unsigned long* pResul
                SysLogException(NID_NET_WIFI, E_PRIVILEGE_DENIED,
                                "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
        }
-#else
-       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
-       *pResult = E_INVALID_OPERATION;
-#endif
+       else if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
+       }
+       else
+       {
+               *pResult = __pWifiService->UnregisterMonitoringClientId(__pIpcServer->GetClientId());
+       }
 }
 
 void
@@ -227,6 +498,7 @@ WifiConnectivityIpcStub::OnUpdateWifiBssInfo(const Tizen::Net::Wifi::WifiBssInfo
        else if (__pWifiService == null)
        {
                *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
        }
        else
        {
@@ -242,18 +514,73 @@ void
 WifiConnectivityIpcStub::OnInitializeWifiDirect(unsigned long* pResult)
 {
 #if !defined (_OSP_EMUL_)
+
        String packageId = __pIpcServer->GetClientPackageId();
 
        SysSecureLog(NID_NET_WIFI, "Received the request of initializing the Wi-Fi Direct with clientId : %d, AppPkgId : %ls",
                                __pIpcServer->GetClientId(), packageId.GetPointer());
 
+       SysTryReturnVoidResult(NID_NET_WIFI, __pWifiDirectService != null, E_SYSTEM, "The WifiDirectService is not constructed.");
+
+       result r = __pWifiDirectService->InitializeWifiDirect(packageId);
+
+       *pResult = r;
+       SysTryLog(NID_NET_WIFI, r == E_SUCCESS, "[%s] Failed to initialize WifiDirectService.", GetErrorMessage(r));
+
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi Direct is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnGetWifiDirectLocalDeviceName(Tizen::Base::String* pLocalName, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysSecureLog(NID_NET_WIFI, "Received the request of getting the local device name with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       *pResult = __pWifiDirectService->GetWifiDirectLocalDeviceName(pLocalName);
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi Direct is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnSetWifiDirectLocalDeviceName(const Tizen::Base::String& localName, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       String packageId = __pIpcServer->GetClientPackageId();
+
+       SysSecureLog(NID_NET_WIFI, "Received the request of setting the local device name with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), packageId.GetPointer());
+
+       SysTryReturnVoidResult(NID_NET_WIFI, __pWifiDirectService != null, E_SYSTEM, "The WifiDirectService is not constructed.");
+
+       *pResult = __pWifiDirectService->SetWifiDirectLocalDeviceName(packageId, localName);
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi Direct is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+
+void
+WifiConnectivityIpcStub::OnGetWifiMacAddress(Tizen::Base::String* pMacAddress, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysSecureLog(NID_NET_WIFI, "Received the request of getting the Wi-Fi mac address with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
        if (__pWifiService == null)
        {
                *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
        }
        else
        {
-               *pResult = __pWifiService->Initialize(packageId);
+               *pResult = __pWifiService->GetWifiMacAddress(pMacAddress);
        }
 #else
        SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi Direct is unavailable on the emulator.");
@@ -262,66 +589,114 @@ WifiConnectivityIpcStub::OnInitializeWifiDirect(unsigned long* pResult)
 }
 
 void
-WifiConnectivityIpcStub::OnGetWifiDirectLocalDeviceName(Tizen::Base::String* pLocalName, unsigned long* pResult)
+WifiConnectivityIpcStub::OnIsWifiActivated(bool* pIsActivated, unsigned long* pResult)
 {
 #if !defined (_OSP_EMUL_)
-       SysSecureLog(NID_NET_WIFI, "Received the request of getting the local device name with clientId : %d, AppPkgId : %ls",
+       SysLog(NID_NET_WIFI, "OnIsWifiActivated with clientId : %d, AppPkgId : %ls",
                                __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
        if (__pWifiService == null)
        {
                *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
        }
        else
        {
-               *pResult = __pWifiService->GetWifiDirectLocalDeviceName(pLocalName);
+               *pResult = __pWifiService->IsWifiActivated(*pIsActivated);
        }
 #else
-       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi Direct is unavailable on the emulator.");
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
        *pResult = E_INVALID_OPERATION;
 #endif
 }
 
 void
-WifiConnectivityIpcStub::OnSetWifiDirectLocalDeviceName(Tizen::Base::String localName, unsigned long* pResult)
+WifiConnectivityIpcStub::OnIsWifiConnected(bool* pIsConnected, unsigned long* pResult)
 {
 #if !defined (_OSP_EMUL_)
-       String packageId = __pIpcServer->GetClientPackageId();
+       SysLog(NID_NET_WIFI, "OnIsWifiConnected with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
-       SysSecureLog(NID_NET_WIFI, "Received the request of setting the local device name with clientId : %d, AppPkgId : %ls",
-                               __pIpcServer->GetClientId(), packageId.GetPointer());
+       if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
+       }
+       else
+       {
+               *pResult = __pWifiService->IsWifiConnected(*pIsConnected);
+       }
+
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+
+void
+WifiConnectivityIpcStub::OnGetWifiConnectionState(int* pState, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "OnGetWifiConnectionState with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
        if (__pWifiService == null)
        {
                *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
        }
        else
        {
-               *pResult = __pWifiService->SetWifiDirectLocalDeviceName(packageId, localName);
+               *pResult =  __pWifiService->GetWifiConnectionState(*pState);
        }
+
 #else
-       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi Direct is unavailable on the emulator.");
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
        *pResult = E_INVALID_OPERATION;
 #endif
 }
 
+
+
 void
-WifiConnectivityIpcStub::OnRegisterBssId(const Tizen::Base::String& bssId, unsigned long* pResult)
+WifiConnectivityIpcStub::OnActivateWifi(unsigned long* pResult)
 {
 #if !defined (_OSP_EMUL_)
-       int clientId = __pIpcServer->GetClientId();
+       SysLog(NID_NET_WIFI, "OnActivateWifi with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
-       SysLog(NID_NET_WIFI, "OnRegisterBssId with clientId : %d, AppPkgId : %ls",
-                               clientId, __pIpcServer->GetClientPackageId().GetPointer());
+       if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
+       }
+       else
+       {
+               *pResult = __pWifiService->WifiActivate(__pIpcServer->GetClientId());
+       }
 
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+
+}
+void
+WifiConnectivityIpcStub::OnDeactivateWifi(unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "OnDeactivateWifi with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
        if (__pWifiService == null)
        {
                *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
        }
        else
        {
-               *pResult = __pWifiProximityService->RegisterBssId(bssId, clientId);
+               *pResult = __pWifiService->WifiDeactivate(__pIpcServer->GetClientId());
        }
+
 #else
        SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
        *pResult = E_INVALID_OPERATION;
@@ -329,22 +704,43 @@ WifiConnectivityIpcStub::OnRegisterBssId(const Tizen::Base::String& bssId, unsig
 }
 
 void
-WifiConnectivityIpcStub::OnUnregisterBssId(const Tizen::Base::String& bssId, unsigned long* pResult)
+WifiConnectivityIpcStub::OnScanWifi(unsigned long* pResult)
 {
 #if !defined (_OSP_EMUL_)
-       int clientId = __pIpcServer->GetClientId();
+       SysLog(NID_NET_WIFI, "OnScanWifi with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
-       SysLog(NID_NET_WIFI, "OnUnregisterBssId with clientId : %d, AppPkgId : %ls",
-                               clientId, __pIpcServer->GetClientPackageId().GetPointer());
+       if (__pWifiService == null)
+       {
+               *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
+       }
+       else
+       {
+               *pResult = __pWifiService->WifiScan(__pIpcServer->GetClientId());
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
+void
+WifiConnectivityIpcStub::OnConnectWifi(const Tizen::Net::Wifi::WifiBssInfo& bssInfo, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "OnConnectWifi with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
        if (__pWifiService == null)
        {
                *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
        }
        else
        {
-               *pResult = __pWifiProximityService->UnregisterBssId(bssId, clientId);
+               *pResult = __pWifiService->WifiConnect(__pIpcServer->GetClientId(), bssInfo);
        }
+
 #else
        SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
        *pResult = E_INVALID_OPERATION;
@@ -352,109 +748,182 @@ WifiConnectivityIpcStub::OnUnregisterBssId(const Tizen::Base::String& bssId, uns
 }
 
 void
-WifiConnectivityIpcStub::OnProximityCheckActivated(unsigned long* pResult)
+WifiConnectivityIpcStub::OnGetWifiConnectionTargetInfo(Tizen::Net::Wifi::WifiBssInfo* pBssInfo, unsigned long* pResult)
 {
 #if !defined (_OSP_EMUL_)
-       SysLog(NID_NET_WIFI, "OnProximityCheckActivated with clientId : %d, AppPkgId : %ls",
+       SysLog(NID_NET_WIFI, "OnConnectWifi with clientId : %d, AppPkgId : %ls",
                                __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
        if (__pWifiService == null)
        {
                *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
        }
        else
        {
-               *pResult = __pWifiProximityService->ActivateProximityCheck();
+               *pResult = __pWifiService->GetWifiConnectionTargetInfo(pBssInfo);
        }
+
+
 #else
        SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
        *pResult = E_INVALID_OPERATION;
 #endif
 }
 
+
 void
-WifiConnectivityIpcStub::OnProximityCheckDeactivated(unsigned long* pResult)
+WifiConnectivityIpcStub::OnGetWifiNetAccountInfo(NetAccountInfo* pNetAccountInfo, _WifiNetAccountInfoImpl* pWifiNetAccountInfoImpl, unsigned long* pResult)
 {
 #if !defined (_OSP_EMUL_)
-       SysLog(NID_NET_WIFI, "OnProximityCheckDeactivated with clientId : %d, AppPkgId : %ls",
+       SysLog(NID_NET_WIFI, "OnGetWifiNetAccountInfo with clientId : %d, AppPkgId : %ls",
                                __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
        if (__pWifiService == null)
        {
                *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
        }
        else
        {
-               *pResult = __pWifiProximityService->DeactivateProximityCheck();
+               *pResult = __pWifiService->GetWifiNetAccountInfo(pNetAccountInfo, pWifiNetAccountInfoImpl);
        }
+
 #else
        SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
        *pResult = E_INVALID_OPERATION;
 #endif
 }
 
+
 void
-WifiConnectivityIpcStub::OnIsProximityCheckActivated(bool* isActivated, unsigned long* pResult)
+WifiConnectivityIpcStub::OnGetWifiSystemScanResult(ArrayListT<Tizen::Net::Wifi::WifiBssInfo*>* pBssInfoList, unsigned long* pResult)
 {
 #if !defined (_OSP_EMUL_)
-       SysLog(NID_NET_WIFI, "OnIsProximityCheckActivated with clientId : %d, AppPkgId : %ls",
+       SysLog(NID_NET_WIFI, "OnGetWifiSystemScanResult with clientId : %d, AppPkgId : %ls",
                                __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
-
        if (__pWifiService == null)
        {
                *pResult = E_SYSTEM;
+               SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] The WifiService is not constructed.");
        }
        else
        {
-               *pResult = E_SUCCESS;
-               *isActivated = __pWifiProximityService->IsProximityCheckActivated();
+               *pResult = __pWifiService->GetWifiSystemScanResultN(pBssInfoList);
        }
+
 #else
        SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
        *pResult = E_INVALID_OPERATION;
 #endif
 }
 
-result
-WifiConnectivityIpcStub::SendProximityCheckActivated(int clientId)
+void
+WifiConnectivityIpcStub::OnRegisterBssId(const Tizen::Base::String& bssId, unsigned long* pResult)
 {
-    SysLog(NID_NET_WIFI, "SendProximityCheckActivated with clientId : %d", clientId);
+#if !defined (_OSP_EMUL_)
+       int clientId = __pIpcServer->GetClientId();
 
-    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onProximityCheckActivated());
-    SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+       SysLog(NID_NET_WIFI, "OnRegisterBssId with clientId : %d, AppPkgId : %ls",
+                               clientId, __pIpcServer->GetClientPackageId().GetPointer());
 
-    return __pIpcServer->SendResponse(clientId, *pMessage);
+       if (__pWifiProximityService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pWifiProximityService->RegisterBssId(bssId, clientId);
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
 }
 
-result
-WifiConnectivityIpcStub::SendProximityCheckDeactivated(int clientId)
+void
+WifiConnectivityIpcStub::OnUnregisterBssId(const Tizen::Base::String& bssId, unsigned long* pResult)
 {
-    SysLog(NID_NET_WIFI, "SendProximityCheckDeactivated with clientId : %d", clientId);
+#if !defined (_OSP_EMUL_)
+       int clientId = __pIpcServer->GetClientId();
 
-    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onProximityCheckDeactivated());
-    SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+       SysLog(NID_NET_WIFI, "OnUnregisterBssId with clientId : %d, AppPkgId : %ls",
+                               clientId, __pIpcServer->GetClientPackageId().GetPointer());
 
-    return __pIpcServer->SendResponse(clientId, *pMessage);
+       if (__pWifiProximityService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pWifiProximityService->UnregisterBssId(bssId, clientId);
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
 }
 
-result
-WifiConnectivityIpcStub::SendWifiBssDetected(int clientId, const Tizen::Net::Wifi::WifiBssInfo& wifiBssInfo)
+void
+WifiConnectivityIpcStub::OnProximityCheckActivated(unsigned long* pResult)
 {
-    SysLog(NID_NET_WIFI, "SendWifiBssDetected with clientId : %d", clientId);
-
-    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiBssDetected(wifiBssInfo));
-    SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "OnProximityCheckActivated with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
-    return __pIpcServer->SendResponse(clientId, *pMessage);
+       if (__pWifiProximityService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pWifiProximityService->ActivateProximityCheck();
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
 }
 
-result
-WifiConnectivityIpcStub::SendWifiBssLost(int clientId, const Tizen::Base::String& bssId)
+void
+WifiConnectivityIpcStub::OnProximityCheckDeactivated(unsigned long* pResult)
 {
-    SysLog(NID_NET_WIFI, "SendWifiBssLost with clientId : %d", clientId);
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "OnProximityCheckDeactivated with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
+
+       if (__pWifiProximityService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = __pWifiProximityService->DeactivateProximityCheck();
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
+}
 
-    std::unique_ptr<IPC::Message> pMessage(new (std::nothrow) ConnectivityWifiServiceMsg_onWifiBssLost(bssId));
-    SysTryReturnResult(NID_NET_WIFI, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
+void
+WifiConnectivityIpcStub::OnIsProximityCheckActivated(bool* isActivated, unsigned long* pResult)
+{
+#if !defined (_OSP_EMUL_)
+       SysLog(NID_NET_WIFI, "OnIsProximityCheckActivated with clientId : %d, AppPkgId : %ls",
+                               __pIpcServer->GetClientId(), __pIpcServer->GetClientPackageId().GetPointer());
 
-    return __pIpcServer->SendResponse(clientId, *pMessage);
+       if (__pWifiProximityService == null)
+       {
+               *pResult = E_SYSTEM;
+       }
+       else
+       {
+               *pResult = E_SUCCESS;
+               *isActivated = __pWifiProximityService->IsProximityCheckActivated();
+       }
+#else
+       SysLog(NID_NET_WIFI, "Invalid Operation because Wi-Fi is unavailable on the emulator.");
+       *pResult = E_INVALID_OPERATION;
+#endif
 }
diff --git a/src/WifiDirectService.cpp b/src/WifiDirectService.cpp
new file mode 100755 (executable)
index 0000000..0d5cde0
--- /dev/null
@@ -0,0 +1,328 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file    WifiDirectService.cpp
+ * @brief   This is the implementation file for the %WifiService class.
+ */
+
+#include <glib.h>
+#include <vconf.h>
+#include <vconf-keys.h>
+#include <unique_ptr.h>
+#include <FBaseUtilStringUtil.h>
+#include <FBaseRtMutexGuard.h>
+#include <FBaseSysLog.h>
+#include <FNetWifiWifiTypes.h>
+#include <FNetWifiWifiBssInfo.h>
+#include <FSys_SystemInfoImpl.h>
+#include <FBase_StringConverter.h>
+#include <FNetWifi_WifiBssInfoImpl.h>
+#include <FNetWifi_WifiUtility.h>
+#include "WifiDirectService.h"
+#include "WifiConnectivityIpcStub.h"
+
+#ifdef _WifiConvertErrorResult
+#undef _WifiConvertErrorResult
+#endif
+#define _WifiConvertErrorResult(condition, r, value) \
+               do \
+               { \
+                       if (condition) {   \
+                               r = value; \
+                       } \
+               } while (0);
+
+static const int WIFIDIRECT_DEVICE_NAME_LENGTH_MAX = 32;
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::App;
+using namespace Tizen::System;
+using namespace Tizen::Net;
+using namespace Tizen::Net::Wifi;
+
+
+WifiDirectService::WifiDirectService(void)
+       : __newWifiDirectName()
+       , __wifiDirectNameChangerId()
+       , __listMutex()
+       , __appPkgIdList()
+       , __pStub(null)
+{
+}
+
+WifiDirectService::~WifiDirectService(void)
+{
+       if (__appPkgIdList.GetCount() > 0)
+       {
+           (void) wifi_direct_unset_device_state_changed_cb();
+           (void) wifi_direct_deinitialize();
+       }
+}
+
+result
+WifiDirectService::Construct(WifiConnectivityIpcStub& stub)
+{
+       result r = E_SUCCESS;
+       bool isWifiDirectSupported = false;
+       String key(L"http://tizen.org/feature/network.wifi.direct");
+
+       r = Tizen::System::_SystemInfoImpl::GetSysInfo(key, isWifiDirectSupported);
+       SysTryReturnResult(NID_NET_WIFI, (r == E_SUCCESS) && (isWifiDirectSupported == true), E_UNSUPPORTED_OPERATION,
+                       "Wi-Fi Direct is not supported.");
+
+       r = __listMutex.Create();
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Failed to create a mutex.");
+
+       __pStub = &stub;
+
+       return E_SUCCESS;
+}
+
+result
+WifiDirectService::InitializeWifiDirect(const Tizen::Base::String& clientPkgId)
+{
+       result r = E_SUCCESS;
+       int ret = WIFI_DIRECT_ERROR_NONE;
+
+       MutexGuard locked(__listMutex);
+
+       // Initialize Wi-Fi Direct client of osp-connectivity-service
+       // if the first application initializes its Wi-Fi Direct client.
+       if (__appPkgIdList.GetCount() == 0)
+       {
+           ret = wifi_direct_initialize();
+           SysTryReturnResult(NID_NET_WIFI, ret == WIFI_DIRECT_ERROR_NONE, E_SYSTEM,
+                               "Initializing Wi-Fi Direct has failed. [0x%08X]", ret);
+
+               ret = wifi_direct_set_device_state_changed_cb(WifiDirectDeviceStateChangedCallbackFunction, this);
+               if (ret != WIFI_DIRECT_ERROR_NONE)
+               {
+                       SysLogException(NID_NET_WIFI, E_SYSTEM,
+                               "[E_SYSTEM] Registration of a Wi-Fi Direct callback method has failed. [0x%08X]", ret);
+                   (void) wifi_direct_deinitialize();
+                       return E_SYSTEM;
+               }
+
+               SysLog(NID_NET_WIFI, "Initializing Wi-Fi Direct is successful.");
+       }
+
+       // Add the ID of the application which initializes Wi-Fi Direct client to the list.
+       if (!__appPkgIdList.Contains(clientPkgId))
+       {
+               r = __appPkgIdList.Add(clientPkgId);
+               // Ignore the error result of list operation.
+               SysTryLog(NID_NET_WIFI, r == E_SUCCESS, "Insertion a new item to the app ID list has failed. (%s)", GetErrorMessage(r));
+       }
+
+       return r;
+}
+
+result
+WifiDirectService::GetWifiDirectLocalDeviceName(Tizen::Base::String* pLocalName)
+{
+       result r = E_SYSTEM;
+       int ret = WIFI_DIRECT_ERROR_NONE;
+
+       // Gets the local name from the underlying Wi-Fi Direct subsystem, if Wi-Fi Direct is on.
+       if (IsWifiDirectActivated() == true)
+       {
+           char* pDeviceName = null;
+               ret = wifi_direct_get_device_name(&pDeviceName);
+               SysTryReturnResult(NID_NET_WIFI, ret == WIFI_DIRECT_ERROR_NONE && pDeviceName != null, E_SYSTEM,
+                               "Getting the SSID from Wi-Fi Direct subsystem has failed. [0x%x]", ret);
+
+               // Converts the UTF8 multibyte string to Unicode String
+               r = StringUtil::Utf8ToString(pDeviceName, *pLocalName);
+               free(pDeviceName);
+       }
+       // Gets the name to be set, if Wi-Fi Direct is off and there is the name set by an application
+       else if (__newWifiDirectName.GetLength() > 0)
+       {
+               *pLocalName = __newWifiDirectName;
+               r = E_SUCCESS;
+       }
+       // Gets the phone name from the system info
+       else
+       {
+           char* pPhoneName = null;
+               pPhoneName = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
+               SysTryReturnResult(NID_NET_WIFI, pPhoneName != null, E_SYSTEM, "Getting the phone name has failed");
+
+               // Converts the UTF8 multibyte string to Unicode String
+               r = StringUtil::Utf8ToString(pPhoneName, *pLocalName);
+               free(pPhoneName);
+       }
+
+       return r;
+}
+
+result
+WifiDirectService::SetWifiDirectLocalDeviceName(const Tizen::Base::String& clientPkgId, const Tizen::Base::String& localName)
+{
+       result r = E_SUCCESS;
+
+       // Updates the local name instantly if the Wi-Fi Direct is turned on.
+       // Saves the setting name for the later use, otherwise.
+       if (IsWifiDirectActivated() == true)
+       {
+               r = UpdateWifiDirectLocalDeviceName(localName);
+               if (!IsFailed(r))
+               {
+                       __newWifiDirectName = localName;
+                       __wifiDirectNameChangerId = clientPkgId;
+               }
+       }
+       else
+       {
+               __newWifiDirectName = localName;
+               __wifiDirectNameChangerId = clientPkgId;
+               SysLog(NID_NET_WIFI, "The input name is reserved as the Wi-Fi Direct local name.");
+       }
+
+       return r;
+}
+
+result
+WifiDirectService::UpdateWifiDirectLocalDeviceName(const Tizen::Base::String& name)
+{
+       int ret = 0;
+       char* pConvertedName = NULL;
+       char deviceName[WIFIDIRECT_DEVICE_NAME_LENGTH_MAX+1]  = {0,};
+
+       pConvertedName = _StringConverter::CopyToCharArrayN(name);
+       SysTryReturnResult(NID_NET_WIFI, pConvertedName != null, E_INVALID_ARG, "Invalid device name.");
+
+       strncpy(deviceName, pConvertedName, WIFIDIRECT_DEVICE_NAME_LENGTH_MAX);
+       delete[] pConvertedName;
+       ret = wifi_direct_set_device_name(deviceName);
+       SysTryReturnResult(NID_NET_WIFI, ret == WIFI_DIRECT_ERROR_NONE, E_SYSTEM,
+                                               "Setting the Wi-Fi Direct SSID (local name) has failed. [0x%x]", ret);
+
+       SysLog(NID_NET_WIFI, "Updating the Wi-Fi Direct local name is successful.");
+
+       return E_SUCCESS;
+}
+
+bool
+WifiDirectService::IsWifiDirectActivated(void) const
+{
+       int ret = WIFI_DIRECT_ERROR_NONE;
+       wifi_direct_state_e currentState = WIFI_DIRECT_STATE_DEACTIVATED;
+
+       ret = wifi_direct_get_state(&currentState);
+       if (ret == WIFI_DIRECT_ERROR_NONE)
+       {
+               if (currentState != WIFI_DIRECT_STATE_DEACTIVATED)
+               {
+                       return true;
+               }
+       }
+       else
+       {
+               SysLog(NID_NET_WIFI, "Getting the current status of Wi-Fi Direct has failed. [0x%x]", ret);
+       }
+
+       return false;
+}
+
+void
+WifiDirectService::ProcessAppTermination(const Tizen::Base::String& clientPkgId)
+{
+       char* pPhoneName = null;
+       String convertedName;
+       result r = E_SUCCESS;
+
+       if (__wifiDirectNameChangerId == clientPkgId)
+       {
+               SysLog(NID_NET_WIFI, "The application which set the Wi-Fi Direct local name is terminated.");
+
+               if (IsWifiDirectActivated() == true)
+               {
+                       SysLog(NID_NET_WIFI, "The Wi-Fi Direct SSID is restored to the phone name.");
+
+                       // Gets the phone name from the system info
+                       pPhoneName = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
+                       if (pPhoneName)
+                       {
+                               r = StringUtil::Utf8ToString(pPhoneName, convertedName);
+                               free(pPhoneName);
+
+                               if (!IsFailed(r))
+                               {
+                                       // Updates the Wi-Fi Direct local name with the phone name
+                                       (void) UpdateWifiDirectLocalDeviceName(convertedName);
+                               }
+                       }
+               }
+
+               __newWifiDirectName.Clear();
+               __wifiDirectNameChangerId.Clear();
+       }
+
+       // Deinitialize Wi-Fi Direct client if the last application which initialized Wi-Fi Direct is terminated.
+       MutexGuard locked(__listMutex);
+
+       if (__appPkgIdList.Contains(clientPkgId))
+       {
+               r = __appPkgIdList.Remove(clientPkgId);
+
+               if ((r == E_SUCCESS) && (__appPkgIdList.GetCount() == 0))
+               {
+                       (void) wifi_direct_unset_device_state_changed_cb();
+                       (void) wifi_direct_deinitialize();
+                       SysLog(NID_NET_WIFI, "Deinitializing Wi-Fi Direct is successful.");
+               }
+       }
+}
+
+void
+WifiDirectService::OnWifiDirectActivated(void)
+{
+       // Updates the local Wi-Fi Direct name.
+       // This is a reserved action.
+       if (__newWifiDirectName.GetLength() > 0)
+       {
+               (void) UpdateWifiDirectLocalDeviceName(__newWifiDirectName);
+       }
+}
+
+void
+WifiDirectService::WifiDirectDeviceStateChangedCallbackFunction(int error_code, wifi_direct_device_state_e device_state, void* user_data)
+{
+       WifiDirectService* pService = (WifiDirectService*)user_data;
+
+       switch (device_state)
+       {
+       case WIFI_DIRECT_DEVICE_STATE_ACTIVATED:
+               // if the Wi-Fi Direct is activated successfully
+               if (error_code == WIFI_DIRECT_ERROR_NONE)
+               {
+                       SysLog(NID_NET_WIFI, "An event received from SLP Wi-Fi Direct FW (type: WIFI_DIRECT_DEVICE_STATE_ACTIVATED)");
+                       pService->OnWifiDirectActivated();
+               }
+               break;
+
+       default:
+               break;       // ignore other types of event
+       }
+}
+
old mode 100644 (file)
new mode 100755 (executable)
index 0f215e8..bfad7fd
@@ -27,6 +27,7 @@
 #include "FNetWifi_WifiUtility.h"
 #include "WifiProximityService.h"
 #include "WifiProximityEventArg.h"
+#include "WifiSystemAdapter.h"
 
 using namespace std;
 using namespace Tizen::Base;
@@ -93,24 +94,27 @@ WifiProximityService::WifiProximityService(void)
        , __isWifiActivated(false)
        , __isProximityCheckActivated(false)
        , __isTimerOn(false)
+       , __pWifiSystemAdapter(null)
 {
 }
 
 WifiProximityService::~WifiProximityService(void)
 {
-       (void) wifi_unset_device_state_changed_cb();
-       (void) wifi_unset_background_scan_cb();
-       (void) wifi_deinitialize();
 }
 
 result
-WifiProximityService::Construct(WifiConnectivityIpcStub* pStub)
+WifiProximityService::Construct(WifiConnectivityIpcStub& stub)
 {
        result r = E_SUCCESS;
-       int err = WIFI_ERROR_NONE;
        static _StringHashCodeProvider strHashCodeProvider;
        static _StringComparer strComparer;
 
+    SysAssertf(__pWifiSystemAdapter == null,
+                    "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
+
+    __pWifiSystemAdapter = WifiSystemAdapter::GetInstance();
+    SysTryReturnResult(NID_NET_WIFI, __pWifiSystemAdapter != null, GetLastResult(), "Failed to get Wi-Fi System adapter instance");
+
        r = __clientStateMap.Construct();
        SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Constructing the internal map(table) has failed.");
 
@@ -129,21 +133,8 @@ WifiProximityService::Construct(WifiConnectivityIpcStub* pStub)
        r = __proxEvent.AddListener(*((IWifiProximityEventListener*)this), true);
        SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Adding listeners to the internal event has failed.");
 
-       err = wifi_initialize();
-       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Initializing Wi-Fi has failed. [0x%08X]", err);
-
-       err = wifi_set_device_state_changed_cb(OnWifiDeviceStateChanged, this);
-       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM,
-                       "Registration of a Wi-Fi callback method about the state change has failed. [0x%08X]", err);
-
-       err = wifi_set_background_scan_cb(OnWifiScanCompleted, this);
-       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM,
-                       "Registration of a Wi-Fi callback method about the scanning has failed. [0x%08X]", err);
-
-       err = wifi_is_activated(&__isWifiActivated);
-       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Checking Wi-Fi activation has failed. [0x%08X]", err);
-
-       __pStub = pStub;
+       __isWifiActivated = __pWifiSystemAdapter->IsActivated();
+       __pStub = &stub;
 
        return r;
 }
@@ -364,8 +355,8 @@ WifiProximityService::ScanAndResetTimer(void)
        // scan nearby Wi-Fi APs in background and set the timer with the predefined duration time.
        if (__isWifiActivated && __isProximityCheckActivated)
        {
-               int err = wifi_scan(OnWifiScanCompleted, this);
-               SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Wi-Fi scan has failed. [0x%08X]", err);
+               r = __pWifiSystemAdapter->ScanforProximity();
+               SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Wi-Fi scan has failed.");
 
                r = __timer.Start(_PROX_BG_SCAN_DURATION);
                SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Starting the timer has failed.");
@@ -399,11 +390,9 @@ WifiProximityService::ResetTimer(void)
 }
 
 void
-WifiProximityService::CheckingProximityStatusChanged(void)
+WifiProximityService::CheckingProximityStatusChanged(const LinkedList* pWifiBssInfoList)
 {
        result r = E_SUCCESS;
-       LinkedList bssInfoList(SingleObjectDeleter);
-       int err = WIFI_ERROR_NONE;
        unique_ptr< IMapEnumeratorT<String, bool> > pMapEnum;
        int bssCount = 0;
 
@@ -412,11 +401,7 @@ WifiProximityService::CheckingProximityStatusChanged(void)
                return;
        }
 
-       err = wifi_foreach_found_aps(OnWifiEachAccessPointFound, &bssInfoList);
-       SysTryReturnVoidResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM,
-                       "[E_SYSTEM] wifi_foreach_found_aps() has failed. [0x%08X]", err);
-
-       bssCount = bssInfoList.GetCount();
+       bssCount = pWifiBssInfoList->GetCount();
 
        // inspects the all APs in the result of scanning
        pMapEnum.reset(__bssDetectionMap.GetMapEnumeratorN());
@@ -424,7 +409,7 @@ WifiProximityService::CheckingProximityStatusChanged(void)
        {
                String bssId;
                bool wasDetected = false;
-               WifiBssInfo* pWifiBssInfo = null;
+               const WifiBssInfo* pWifiBssInfo = null;
 
                r = pMapEnum->GetKey(bssId);
                SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS,  E_SYSTEM, "[E_SYSTEM] Getting the key from the map has failed.");
@@ -439,7 +424,7 @@ WifiProximityService::CheckingProximityStatusChanged(void)
 
                        for (int i = 0; i < bssCount; i++)
                        {
-                               pWifiBssInfo = dynamic_cast<WifiBssInfo*>(bssInfoList.GetAt(i));
+                               pWifiBssInfo = dynamic_cast<const WifiBssInfo*>(pWifiBssInfoList->GetAt(i));
                                SysTryReturnVoidResult(NID_NET_WIFI, pWifiBssInfo != null, E_SYSTEM,
                                                "[E_SYSTEM] An internal dynamic casting error.");
 
@@ -478,7 +463,7 @@ WifiProximityService::CheckingProximityStatusChanged(void)
 
                        for (int i = 0; i < bssCount; i++)
                        {
-                               pWifiBssInfo = dynamic_cast<WifiBssInfo*>(bssInfoList.GetAt(i));
+                               pWifiBssInfo = dynamic_cast<const WifiBssInfo*>(pWifiBssInfoList->GetAt(i));
                                SysTryReturnVoidResult(NID_NET_WIFI, pWifiBssInfo != null, E_SYSTEM,
                                                "[E_SYSTEM] An internal dynamic casting error.");
 
@@ -578,62 +563,25 @@ WifiProximityService::OnWifiProximityDeactivated(void)
 }
 
 void
-WifiProximityService::OnWifiDeviceStateChanged(wifi_device_state_e state, void* pUserData)
+WifiProximityService::OnWifiActivated()
 {
-       WifiProximityService* pWifiProximityService = static_cast<WifiProximityService*>(pUserData);
-
-       switch (state)
-       {
-       case WIFI_DEVICE_STATE_ACTIVATED:
-               pWifiProximityService->__isWifiActivated = true;
-               pWifiProximityService->ScanAndResetTimer();
-               break;
-       case WIFI_DEVICE_STATE_DEACTIVATED:
-               pWifiProximityService->__isWifiActivated = false;
-               break;
-       default:
-               break;
-       }
+       __isWifiActivated = true;
+       ScanAndResetTimer();
 }
 
 void
-WifiProximityService::OnWifiScanCompleted(wifi_error_e errorCode, void* pUserData)
+WifiProximityService::OnWifiDeactivated()
 {
-       WifiProximityService* pWifiProximityService = static_cast<WifiProximityService*>(pUserData);
-
-       SysLog(NID_NET_WIFI, "The Wi-FI BG Scanning is completed %s. [0x%08X] ",
-                       errorCode == WIFI_ERROR_NONE ? "successfully" : "insuccessfully", errorCode);
-
-       pWifiProximityService->ResetTimer(); // ignore the result
-
-       if (errorCode == WIFI_ERROR_NONE)
-       {
-               pWifiProximityService->CheckingProximityStatusChanged();
-       }
+       __isWifiActivated = false;
 }
 
-bool
-WifiProximityService::OnWifiEachAccessPointFound(wifi_ap_h apHandler, void* pUserData)
+void
+WifiProximityService::OnWifiScanCompleted(const LinkedList* pWifiBssInfoList, result r)
 {
-       unique_ptr<WifiBssInfo> pBssInfo;
-       int err = WIFI_ERROR_NONE;
-       result r = E_SUCCESS;
-       LinkedList* pBssInfoList = static_cast<LinkedList*>(pUserData);
-       wifi_ap_h apHandlerCopy;
+       ResetTimer(); // ignore the result
 
-       err = wifi_ap_clone(&apHandlerCopy, apHandler);
-       SysTryReturn(NID_NET_WIFI, err == WIFI_ERROR_NONE, false, E_SYSTEM,
-                       "[E_SYSTEM] Cloning the wifi_ap_h has failed. [0x%08X]", err);
-
-       pBssInfo.reset(_WifiUtility::CreateWifiBssInfoInstanceN(apHandlerCopy));
-       // keeps processing although creating instance fails.
-       SysTryReturn(NID_NET_WIFI, pBssInfo != null, true, E_SYSTEM, "[E_SYSTEM] Creating a WifiBssInfo instance has failed.");
-
-       r = pBssInfoList->Add(*pBssInfo);
-       // keeps processing although adding instance to the list fails.
-       SysTryReturn(NID_NET_WIFI, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
-       // transfer the ownership.
-       pBssInfo.release();
-
-       return true;
+       if (r == E_SUCCESS)
+       {
+               CheckingProximityStatusChanged(pWifiBssInfoList);
+       }
 }
old mode 100644 (file)
new mode 100755 (executable)
index 72cf082..35bed3c
@@ -23,7 +23,7 @@
 #include <glib.h>
 #include <vconf.h>
 #include <vconf-keys.h>
-#include <wifi-direct.h>
+#include <wifi.h>
 #include <unique_ptr.h>
 #include <FBaseUtilStringUtil.h>
 #include <FBaseRtMutexGuard.h>
 #include <FNetIp4Address.h>
 #include <FNetWifiWifiTypes.h>
 #include <FNetWifiWifiBssInfo.h>
+#include <FNetNetAccountInfo.h>
 #include <FSys_SystemInfoImpl.h>
 #include <FBase_StringConverter.h>
 #include <FNetWifi_WifiBssInfoImpl.h>
 #include <FNetWifi_WifiUtility.h>
+#include <FNetWifi_WifiNetAccountInfoImpl.h>
 #include "WifiService.h"
+#include "WifiProximityService.h"
+#include "WifiConnectivityIpcStub.h"
+#include "WifiSystemAdapter.h"
+
+#ifdef _WifiConvertErrorResult
+#undef _WifiConvertErrorResult
+#endif
+#define _WifiConvertErrorResult(condition, r, value) \
+               do \
+               { \
+                       if (condition) {   \
+                               r = value; \
+                       } \
+               } while (0);
 
 using namespace std;
 using namespace Tizen::Base;
@@ -47,469 +63,359 @@ using namespace Tizen::System;
 using namespace Tizen::Net;
 using namespace Tizen::Net::Wifi;
 
-static void WifiDirectDeviceStateChangedCallbackFunction(int error_code, wifi_direct_device_state_e device_state,
-                                                                                                                       void* user_data);
-
-struct _WifiBssIdHandlePair
-{
-       const Tizen::Base::String* pBssId;
-       wifi_ap_h apHandle;
-};
-
 WifiService::WifiService(void)
-       : __newWifiDirectName()
-       , __wifiDirectNameChangerId()
-       , __listMutex()
-       , __appPkgIdList()
+       : __listMutex()
+       , __managerClientIdList()
+       , __monitorClientIdList()
+       , __pStub(null)
+       , __pWifiSystemAdapter(null)
 {
 }
 
 WifiService::~WifiService(void)
 {
-       if (__appPkgIdList.GetCount() > 0)
-       {
-           (void) wifi_direct_unset_device_state_changed_cb();
-           (void) wifi_direct_deinitialize();
-       }
 }
 
 result
-WifiService::Construct(void)
+WifiService::Construct(WifiConnectivityIpcStub& stub)
 {
        result r = E_SUCCESS;
-       bool isWifiDirectSupported = false;
-    String key(L"http://tizen.org/feature/network.wifi.direct");
+       bool isWifiSupported = false;
+       String key(L"http://tizen.org/feature/network.wifi");
 
-       r = Tizen::System::_SystemInfoImpl::GetSysInfo(key, isWifiDirectSupported);
-       SysTryReturnResult(NID_NET_WIFI, (r == E_SUCCESS) && (isWifiDirectSupported == true), E_UNSUPPORTED_OPERATION,
-                       "Wi-Fi Direct is not supported.");
+       r = Tizen::System::_SystemInfoImpl::GetSysInfo(key, isWifiSupported);
+       SysTryReturnResult(NID_NET_WIFI, (r == E_SUCCESS) && (isWifiSupported == true), E_UNSUPPORTED_OPERATION,
+                       "Wi-Fi is not supported.");
 
        r = __listMutex.Create();
        SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Failed to create a mutex.");
 
+       SysAssertf(__pWifiSystemAdapter == null,
+                           "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
+
+       __pWifiSystemAdapter = WifiSystemAdapter::GetInstance();
+       SysTryReturnResult(NID_NET_WIFI, __pWifiSystemAdapter != null, GetLastResult(), "Failed to get Wi-Fi System adapter instance");
+
+       __pStub = &stub;
        return E_SUCCESS;
 }
 
 result
-WifiService::SetWifiSystemScanMode(int mode)
+WifiService::RegisterManagerClientId(int clientId)
 {
-       // changes vconf value about Wi-Fi BG scan mode.
-       // Key:   VCONFKEY_WIFI_BGSCAN_MODE                "memory/wifi/bgscan_mode"
-       // Value: VCONFKEY_WIFI_BGSCAN_MODE_PERIODIC
-       //        VCONFKEY_WIFI_BGSCAN_MODE_EXPONENTIAL
-
-       // changes vconf value about Wi-Fi UG running mode.
-       // Key:   VCONFKEY_WIFI_UG_RUN_STATE                "memory/wifi/ug_run_state"
-       // Value: VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND - auto connect pop-up for selecting the AP is not displayed.
-       //        VCONFKEY_WIFI_UG_RUN_STATE_OFF
-
-       int vconfRes = 0;
-       //int bgScanMode = VCONFKEY_WIFI_BGSCAN_MODE_EXPONENTIAL;
-       int ugRunState = VCONFKEY_WIFI_UG_RUN_STATE_OFF;
-       WifiSystemScanMode scanMode = (WifiSystemScanMode) mode;
-
-       switch(scanMode)
-       {
-       case WIFI_SYSTEM_SCAN_MODE_ACTIVE:
-               //bgScanMode = VCONFKEY_WIFI_BGSCAN_MODE_PERIODIC;
-               //SysLog(NID_NET_WIFI, "Change BG scan mode (VCONFKEY_WIFI_BGSCAN_MODE_PERIODIC)");
-               ugRunState = VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND;
-               SysLog(NID_NET_WIFI, "Change UG state (ON_FOREGROUND)");
-               break;
-       case WIFI_SYSTEM_SCAN_MODE_PASSIVE:
-       default:
-               //bgScanMode = VCONFKEY_WIFI_BGSCAN_MODE_EXPONENTIAL;
-               //SysLog(NID_NET_WIFI, "Change BG scan mode (VCONFKEY_WIFI_BGSCAN_MODE_EXPONENTIAL)");
-               ugRunState = VCONFKEY_WIFI_UG_RUN_STATE_OFF;
-               SysLog(NID_NET_WIFI, "Change UG state (OFF)");
-
-               break;
-       }
+       result r = E_SUCCESS;
+       bool isContain = true;
 
-       vconfRes = vconf_set_int(VCONFKEY_WIFI_UG_RUN_STATE, ugRunState);
-       SysTryReturnResult(NID_NET_WIFI, vconfRes == 0, E_OPERATION_FAILED, "Setting the running mode of the Wi-Fi UG has failed.");
+       isContain = __managerClientIdList.Contains(clientId);
+       SysTryReturnResult(NID_NET_WIFI, isContain == false, E_OBJ_ALREADY_EXIST, "The client was already registered.");
 
-//     vconfRes = vconf_set_int(VCONFKEY_WIFI_BGSCAN_MODE, bgScanMode);
-//     SysTryReturnResult(NID_NET_WIFI, vconfRes == 0, E_OPERATION_FAILED, "Setting the BG scanning mode of the Wi-Fi has failed.[%d]"
-//     , vconfRes);
+       r = __managerClientIdList.Add(clientId);
+       r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating. Internal map error.");
 
+       if (__managerClientIdList.GetCount() == 1)
+       {
+               __pWifiSystemAdapter->SetWifiService(this);
+       }
 
-       return E_SUCCESS;
+       return r;
 }
 
 result
-WifiService::UpdateWifiBssInfo(const Tizen::Net::Wifi::WifiBssInfo& bssInfo)
+WifiService::UnregisterManagerClientId(int clientId)
 {
-       wifi_ap_h apHandle = null;
-       const _WifiBssInfoImpl* pBssInfoImpl = null;
-       int apRes = WIFI_ERROR_NONE;
-       NetAddressScheme ipScheme = NET_ADDRESS_SCHEME_DYNAMIC;
-       wifi_ip_config_type_e apIpScheme = WIFI_IP_CONFIG_TYPE_NONE;
-       const IpAddress* pAddress = null;
-       unique_ptr<char[]> pAddressStr;
-       NetProxyType proxyType = NET_PROXY_TYPE_NONE;
-       wifi_proxy_type_e apProxyType = WIFI_PROXY_TYPE_DIRECT;
-       String proxyAddressStr;
-       bool isKnown = false;
-
-       pBssInfoImpl = _WifiBssInfoImpl::GetInstance(bssInfo);
-       apHandle = GetApHandle(pBssInfoImpl->GetBssId());
-       SysTryReturnResult(NID_NET_WIFI, apHandle != null, E_OPERATION_FAILED,
-                       "The AP is not found in the current AP list of the system.");
-
-       // Setting the AP unknown
-       apRes = wifi_ap_is_favorite(apHandle, &isKnown);
-       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
-                       "Checking the AP is a known device has failed. [0x%08X].", apRes);
-       if (isKnown && !(pBssInfoImpl->IsKnown()))
-       {
-               apRes = wifi_forget_ap(apHandle);
-               SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
-                               "Setting the AP unknown has failed. [0x%08X].", apRes);
-       }
+       result r = E_SUCCESS;
+
+       if (__managerClientIdList.GetCount() == 0)
+               return r;
 
-       // Setting the IP address scheme. Only IPv4 as the address family is taken into consideration for now.
-       ipScheme = pBssInfoImpl->GetLocalAddressScheme();
-       apIpScheme = (ipScheme == NET_ADDRESS_SCHEME_STATIC) ? WIFI_IP_CONFIG_TYPE_STATIC : WIFI_IP_CONFIG_TYPE_DYNAMIC;
-       apRes = wifi_ap_set_ip_config_type(apHandle, WIFI_ADDRESS_FAMILY_IPV4, apIpScheme);
-       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
-                       "Setting the IP address scheme to AP has failed. [0x%08X].", apRes);
+       r = __managerClientIdList.Remove(clientId);
+       r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating. Internal map error.");
 
-       if (ipScheme == NET_ADDRESS_SCHEME_STATIC)
+       if (__managerClientIdList.GetCount() == 0
+               && __monitorClientIdList.GetCount() == 0)
        {
-               // Setting the IP address. Only IPv4 as the address family is taken into consideration for now.
-               pAddress = pBssInfoImpl->GetLocalAddress();
-               if (pAddress != null)
-               {
-                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
-                       apRes = wifi_ap_set_ip_address(apHandle, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
-                       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
-                                       "Setting the IP address to AP has failed. [0x%08X].", apRes);
-               }
+               __pWifiSystemAdapter->SetWifiService(null);
+       }
 
-               // Setting the subnet mask. Only IPv4 as the address family is taken into consideration for now.
-               pAddress = pBssInfoImpl->GetSubnetMaskAddress();
-               if (pAddress != null)
-               {
-                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
-                       apRes = wifi_ap_set_subnet_mask(apHandle, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
-                       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
-                                       "Setting the subnet mask to AP has failed. [0x%08X].", apRes);
-               }
+       return r;
+}
 
-               // Setting the default gateway address. Only IPv4 as the address family is taken into consideration for now.
-               pAddress = pBssInfoImpl->GetDefaultGatewayAddress();
-               if (pAddress != null)
-               {
-                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
-                       apRes = wifi_ap_set_gateway_address(apHandle, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
-                       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
-                                       "Setting the default gateway address to AP has failed. [0x%08X].", apRes);
-               }
 
-               // Setting the primary DNS address. Only IPv4 as the address family is taken into consideration for now.
-               pAddress = pBssInfoImpl->GetPrimaryDnsAddress();
-               if (pAddress != null)
-               {
-                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
-                       apRes = wifi_ap_set_dns_address(apHandle, 1, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
-                       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
-                                       "Setting the primary DNS address to AP has failed. [0x%08X].", apRes);
-               }
+result
+WifiService::RegisterMonitoringClientId(int clientId)
+{
+       result r = E_SUCCESS;
+       bool isContain = true;
 
-               // Setting the secondary DNS address. Only IPv4 as the address family is taken into consideration for now.
-               pAddress = pBssInfoImpl->GetSecondaryDnsAddress();
-               if (pAddress != null)
-               {
-                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
-                       apRes = wifi_ap_set_dns_address(apHandle, 2, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
-                       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
-                                       "Setting the secondary DNS address to AP has failed. [0x%08X].", apRes);
-               }
-       }
+       isContain = __monitorClientIdList.Contains(clientId);
+       SysTryReturnResult(NID_NET_WIFI, isContain == false, E_OBJ_ALREADY_EXIST, "The client was already registered.");
 
-       proxyType = pBssInfoImpl->GetProxyType();
+       r = __monitorClientIdList.Add(clientId);
+       r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating. Internal map error.");
 
-       if (proxyType == NET_PROXY_TYPE_MANUAL)
+       if (__monitorClientIdList.GetCount() == 1)
        {
-               // Setting the proxy address. Only IPv4 as the address family is taken into consideration for now.
-               proxyAddressStr = pBssInfoImpl->GetProxyAddress();
-               pAddressStr.reset(_StringConverter::CopyToCharArrayN(proxyAddressStr));
-               apRes = wifi_ap_set_proxy_address(apHandle, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
-               SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
-                               "Setting the proxy address to AP has failed. [0x%08X].", apRes);
+               __pWifiSystemAdapter->SetWifiService(this);
        }
 
-       // Setting the proxy type.
-       apProxyType = (proxyType == NET_PROXY_TYPE_MANUAL) ? WIFI_PROXY_TYPE_MANUAL : WIFI_PROXY_TYPE_DIRECT;
-       apRes = wifi_ap_set_proxy_type(apHandle, apProxyType);
-       SysTryReturnResult(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, E_OPERATION_FAILED,
-                       "Setting the proxy type to AP has failed. [0x%08X].", apRes);
-
-       return E_SUCCESS;
+       return r;
 }
 
+
 result
-WifiService::Initialize(const Tizen::Base::String& clientPkgId)
+WifiService::UnregisterMonitoringClientId(int clientId)
 {
        result r = E_SUCCESS;
-    int ret = WIFI_DIRECT_ERROR_NONE;
+       if (__monitorClientIdList.GetCount() == 0)
+                       return r;
 
-       MutexGuard locked(__listMutex);
+       r = __monitorClientIdList.Remove(clientId);
+       r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Propagating. Internal map error.");
 
-       // Initialize Wi-Fi Direct client of osp-connectivity-service
-       // if the first application initializes its Wi-Fi Direct client.
-       if (__appPkgIdList.GetCount() == 0)
+       if (__managerClientIdList.GetCount() == 0
+               && __monitorClientIdList.GetCount() == 0)
        {
-           ret = wifi_direct_initialize();
-           SysTryReturnResult(NID_NET_WIFI, ret == WIFI_DIRECT_ERROR_NONE, E_SYSTEM,
-                               "Initializing Wi-Fi Direct has failed. [0x%08X]", ret);
+               __pWifiSystemAdapter->SetWifiService(null);
+       }
 
-               ret = wifi_direct_set_device_state_changed_cb(WifiDirectDeviceStateChangedCallbackFunction, this);
-               if (ret != WIFI_DIRECT_ERROR_NONE)
-               {
-                       SysLogException(NID_NET_WIFI, E_SYSTEM,
-                               "[E_SYSTEM] Registration of a Wi-Fi Direct callback method has failed. [0x%08X]", ret);
-                   (void) wifi_direct_deinitialize();
-                       return E_SYSTEM;
-               }
+       return r;
+}
 
-               SysLog(NID_NET_WIFI, "Initializing Wi-Fi Direct is successful.");
-       }
+result
+WifiService::SetWifiSystemScanMode(int mode)
+{
+       return __pWifiSystemAdapter->SetWifiSystemScanMode(mode);
+}
 
-       // Add the ID of the application which initializes Wi-Fi Direct client to the list.
-       if (!__appPkgIdList.Contains(clientPkgId))
-       {
-               r = __appPkgIdList.Add(clientPkgId);
-               // Ignore the error result of list operation.
-               SysTryLog(NID_NET_WIFI, r == E_SUCCESS, "Insertion a new item to the app ID list has failed. (%s)", GetErrorMessage(r));
-       }
+result
+WifiService::UpdateWifiBssInfo(const WifiBssInfo& bssInfo)
+{
+       return __pWifiSystemAdapter->UpdateWifiBssInfo(bssInfo);
+}
 
-       locked.Unlock();
+result
+WifiService::GetWifiMacAddress(String* pMacAddress)
+{
+       *pMacAddress = __pWifiSystemAdapter->GetMacAddress();
+       return GetLastResult();
+}
+result
+WifiService::IsWifiActivated(bool& isActivated)
+{
+       isActivated = __pWifiSystemAdapter->IsActivated();
 
-       return r;
+       return GetLastResult();
 }
 
 result
-WifiService::GetWifiDirectLocalDeviceName(Tizen::Base::String* pLocalName)
+WifiService::IsWifiConnected(bool& isConnected)
 {
-       result r = E_SYSTEM;
-       int ret = WIFI_DIRECT_ERROR_NONE;
+       isConnected = __pWifiSystemAdapter->IsConnected();
 
-       // Gets the local name from the underlying Wi-Fi Direct subsystem, if Wi-Fi Direct is on.
-       if (IsWifiDirectActivated() == true)
-       {
-           char* pDeviceName = null;
-               ret = wifi_direct_get_device_name(&pDeviceName);
-               SysTryReturnResult(NID_NET_WIFI, ret == WIFI_DIRECT_ERROR_NONE && pDeviceName != null, E_SYSTEM,
-                               "Getting the SSID from Wi-Fi Direct subsystem has failed. [0x%x]", ret);
-
-               // Converts the UTF8 multibyte string to Unicode String
-               r = StringUtil::Utf8ToString(pDeviceName, *pLocalName);
-               free(pDeviceName);
-       }
-       // Gets the name to be set, if Wi-Fi Direct is off and there is the name set by an application
-       else if (__newWifiDirectName.GetLength() > 0)
-       {
-               *pLocalName = __newWifiDirectName;
-               r = E_SUCCESS;
-       }
-       // Gets the phone name from the system info
-       else
-       {
-           char* pPhoneName = null;
-               pPhoneName = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
-               SysTryReturnResult(NID_NET_WIFI, pPhoneName != null, E_SYSTEM, "Getting the phone name has failed");
+       return GetLastResult();
+}
 
-               // Converts the UTF8 multibyte string to Unicode String
-               r = StringUtil::Utf8ToString(pPhoneName, *pLocalName);
-               free(pPhoneName);
-       }
+result
+WifiService::GetWifiConnectionState(int& connectionState)
+{
+       connectionState = __pWifiSystemAdapter->GetConnectionState();
 
-       return r;
+       return GetLastResult();
 }
 
 result
-WifiService::SetWifiDirectLocalDeviceName(const Tizen::Base::String& clientPkgId, const Tizen::Base::String& localName)
+WifiService::WifiActivate(int clientId)
 {
-       result r = E_SUCCESS;
+       return __pWifiSystemAdapter->Activate(clientId);
+}
 
-       // Updates the local name instantly if the Wi-Fi Direct is turned on.
-       // Saves the setting name for the later use, otherwise.
-       if (IsWifiDirectActivated() == true)
-       {
-               r = UpdateWifiDirectLocalDeviceName(localName);
-               if (!IsFailed(r))
-               {
-                       __newWifiDirectName = localName;
-                       __wifiDirectNameChangerId = clientPkgId;
-               }
-       }
-       else
-       {
-               __newWifiDirectName = localName;
-               __wifiDirectNameChangerId = clientPkgId;
-               SysLog(NID_NET_WIFI, "The input name is reserved as the Wi-Fi Direct local name.");
-       }
+result
+WifiService::WifiDeactivate(int clientId)
+{
+       return __pWifiSystemAdapter->Deactivate(clientId);
+}
 
-       return r;
+result
+WifiService::WifiScan(int clientId)
+{
+       return __pWifiSystemAdapter->Scan(clientId);
+}
+
+result
+WifiService::WifiConnect(int clientId, const Tizen::Net::Wifi::WifiBssInfo& bssInfo)
+{
+       return __pWifiSystemAdapter->Connect(clientId, bssInfo);
 }
 
 result
-WifiService::UpdateWifiDirectLocalDeviceName(const Tizen::Base::String& name)
+WifiService::GetWifiConnectionTargetInfo(Tizen::Net::Wifi::WifiBssInfo* pBssInfo) const
 {
-       int ret = 0;
-       char* pConvertedName = NULL;
+       return __pWifiSystemAdapter->GetConnectionTargetInfo(pBssInfo);
+}
 
-       pConvertedName = _StringConverter::CopyToCharArrayN(name);
-       SysTryReturnResult(NID_NET_WIFI, pConvertedName != null, E_INVALID_ARG, "Invalid device name.");
+result
+WifiService::GetWifiNetAccountInfo(NetAccountInfo* pNetAccountInfo, _WifiNetAccountInfoImpl* pWifiNetAccountInfoImpl) const
+{
+       return __pWifiSystemAdapter->GetWifiNetAccountInfo(pNetAccountInfo, pWifiNetAccountInfoImpl);
+}
 
-       ret = wifi_direct_set_device_name(pConvertedName);
+result
+WifiService::GetWifiSystemScanResultN(ArrayListT<Tizen::Net::Wifi::WifiBssInfo*>* pBssInfoList) const
+{
+       IList* pList = __pWifiSystemAdapter->GetSystemScanResult();
+       result r = GetLastResult();
+       SysTryReturnResult(NID_NET_WIFI, pList != null, r, "Failed to get scan results.");
 
-       delete[] pConvertedName;
-       SysTryReturnResult(NID_NET_WIFI, ret == WIFI_DIRECT_ERROR_NONE, E_SYSTEM,
-                                               "Setting the Wi-Fi Direct SSID (local name) has failed. [0x%x]", ret);
+       for (int i = 0; i < pList->GetCount() ; i++)
+       {
+               r = pBssInfoList->Add(static_cast<Tizen::Net::Wifi::WifiBssInfo*>(pList->GetAt(i)));
+       }
 
-       SysLog(NID_NET_WIFI, "Updating the Wi-Fi Direct local name is successful.");
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to get scan results.");
 
        return E_SUCCESS;
 }
 
-bool
-WifiService::IsWifiDirectActivated(void) const
-{
-       int ret = WIFI_DIRECT_ERROR_NONE;
-       wifi_direct_state_e currentState = WIFI_DIRECT_STATE_DEACTIVATED;
+// Wifi callback functions
 
-       ret = wifi_direct_get_state(&currentState);
-       if (ret == WIFI_DIRECT_ERROR_NONE)
+void
+WifiService::OnWifiActivated(int clientId, result r)
+{
+       int id = 0;
+       if (r == E_SUCCESS)
        {
-               if (currentState != WIFI_DIRECT_STATE_DEACTIVATED)
+               // broadcast to all clients
+               for (int i = 0 ; i < __managerClientIdList.GetCount() ; i++)
                {
-                       return true;
+                       __managerClientIdList.GetAt(i, id);
+                       __pStub->SendWifiActivated(id, r);
                }
        }
        else
        {
-               SysLog(NID_NET_WIFI, "Getting the current status of Wi-Fi Direct has failed. [0x%x]", ret);
+               __pStub->SendWifiActivated(clientId, r);
        }
-
-       return false;
 }
 
-wifi_ap_h
-WifiService::GetApHandle(const Tizen::Base::String& bssId)
+void
+WifiService::OnWifiDeactivated(int clientId, result r)
 {
-       _WifiBssIdHandlePair pair;
-       pair.pBssId = &bssId;
-       pair.apHandle = null;
-
-    wifi_foreach_found_aps(OnWifiEachAccessPointFound, &pair);
+       int id = 0;
+       if (r == E_SUCCESS)
+       {
+               // broadcast to all clients
+               for (int i = 0 ; i < __managerClientIdList.GetCount() ; i++)
+               {
+                       __managerClientIdList.GetAt(i, id);
+                       __pStub->SendWifiDeactivated(id, r);
+               }
 
-    return pair.apHandle;
+       }
+       else
+       {
+               __pStub->SendWifiDeactivated(clientId, r);
+       }
 }
 
 void
-WifiService::ProcessAppTermination(const Tizen::Base::String& clientPkgId)
+WifiService::OnWifiConnected(int clientId, const String ssid, result r)
 {
-       char* pPhoneName = null;
-       String convertedName;
-       result r = E_SUCCESS;
-
-       if (__wifiDirectNameChangerId == clientPkgId)
+       int id = 0;
+       if (r == E_SUCCESS)
        {
-               SysLog(NID_NET_WIFI, "The application which set the Wi-Fi Direct local name is terminated.");
-
-               if (IsWifiDirectActivated() == true)
+               // broadcast to all clients
+               for (int i = 0 ; i < __managerClientIdList.GetCount() ; i++)
                {
-                       SysLog(NID_NET_WIFI, "The Wi-Fi Direct SSID is restored to the phone name.");
-
-                       // Gets the phone name from the system info
-                       pPhoneName = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
-                       if (pPhoneName)
-                       {
-                               r = StringUtil::Utf8ToString(pPhoneName, convertedName);
-                               free(pPhoneName);
-
-                               if (!IsFailed(r))
-                               {
-                                       // Updates the Wi-Fi Direct local name with the phone name
-                                       (void) UpdateWifiDirectLocalDeviceName(convertedName);
-                               }
-                       }
+                       __managerClientIdList.GetAt(i, id);
+                       __pStub->SendWifiConnected(id, ssid, r);
                }
-
-               __newWifiDirectName.Clear();
-               __wifiDirectNameChangerId.Clear();
        }
+       else
+       {
+               __pStub->SendWifiConnected(clientId, ssid, r);
+       }
+}
 
-       // Deinitialize Wi-Fi Direct client if the last application which initialized Wi-Fi Direct is terminated.
-       __listMutex.Acquire();
-
-       if (__appPkgIdList.Contains(clientPkgId))
+void
+WifiService::OnWifiScanCompleted(int clientId, Tizen::Base::Collection::IList* pWifiBssInfoList, result r)
+{
+       if (r == E_SUCCESS && pWifiBssInfoList != null)
        {
-               r = __appPkgIdList.Remove(clientPkgId);
+               ArrayListT<Tizen::Net::Wifi::WifiBssInfo*>* pBssInfoList = new ArrayListT<Tizen::Net::Wifi::WifiBssInfo*>();
+               SysTryCatch(NID_NET_WIFI, pBssInfoList != null, r = E_OUT_OF_MEMORY, r, "Memory allocation failed.");
 
-               if ((r == E_SUCCESS) && (__appPkgIdList.GetCount() == 0))
+
+               for (int i = 0; i < pWifiBssInfoList->GetCount(); i++)
                {
-                   (void) wifi_direct_unset_device_state_changed_cb();
-                   (void) wifi_direct_deinitialize();
-                       SysLog(NID_NET_WIFI, "Deinitializing Wi-Fi Direct is successful.");
+                       result res = pBssInfoList->Add(static_cast<Tizen::Net::Wifi::WifiBssInfo*>(pWifiBssInfoList->GetAt(i)));
+                       SysTryCatch(NID_NET_WIFI, res == E_SUCCESS, ,E_SYSTEM, "Failed to get scan results.");
                }
+
+               __pStub->SendWifiScanCompleted(clientId, pBssInfoList, r);
+               delete pBssInfoList;
+       }
+       else
+       {
+               goto CATCH;
        }
 
-       __listMutex.Release();
+       return;
+
+CATCH:
+       unique_ptr< ArrayListT<Tizen::Net::Wifi::WifiBssInfo*> > pBssInfoList(new ArrayListT<Tizen::Net::Wifi::WifiBssInfo*>());
+       __pStub->SendWifiScanCompleted(clientId, pBssInfoList.get(), r);
+
 }
 
 void
-WifiService::OnWifiDirectActivated(void)
+WifiService::OnWifiDisconnected()
 {
-       // Updates the local Wi-Fi Direct name.
-       // This is a reserved action.
-       if (__newWifiDirectName.GetLength() > 0)
+       int id = 0;
+       // broadcast to all clients
+       for (int i = 0 ; i < __managerClientIdList.GetCount() ; i++)
        {
-               (void) UpdateWifiDirectLocalDeviceName(__newWifiDirectName);
+               __managerClientIdList.GetAt(i, id);
+               __pStub->SendWifiDisconnected(id);
        }
 }
 
-bool
-WifiService::OnWifiEachAccessPointFound(wifi_ap_h apHandle, void* pUserData)
+void
+WifiService::OnWifiRssiLevelChanged(long rssi)
 {
-       int res = WIFI_ERROR_NONE;
-       char* bssId = null;
-       _WifiBssIdHandlePair* pPair = static_cast<_WifiBssIdHandlePair*>(pUserData);
-
-    res = wifi_ap_get_bssid (apHandle, &bssId);
-    SysTryReturn(NID_NET_WIFI, res == WIFI_ERROR_NONE && bssId != null, true, E_OPERATION_FAILED,
-               "[E_OPERATION_FAILED] Getting BSSID has failed.");
-
-    if (pPair->pBssId->Equals(String(_WifiUtility::ConvertMacAddress(bssId))))
-    {
-       pPair->apHandle = apHandle;
-       return false;
-    }
-
-    return true;
+       // broadcast to all clients
+       int id = 0;
+       for (int i = 0 ; i < __managerClientIdList.GetCount() ; i++)
+       {
+               __managerClientIdList.GetAt(i, id);
+               __pStub->SendWifiRssiChanged(id, rssi);
+       }
 }
 
+// __monitorClientIdList
 void
-WifiDirectDeviceStateChangedCallbackFunction(int error_code, wifi_direct_device_state_e device_state, void* user_data)
+WifiService::OnWifiConnectionStateChanged(Tizen::Net::Wifi::WifiConnectionState state)
 {
-       WifiService* pService = (WifiService*)user_data;
-
-       switch (device_state)
+       int id = 0;
+       // broadcast to all clients
+       for (int i = 0 ; i < __monitorClientIdList.GetCount() ; i++)
        {
-       case WIFI_DIRECT_DEVICE_STATE_ACTIVATED:
-               // if the Wi-Fi Direct is activated successfully
-               if (error_code == WIFI_DIRECT_ERROR_NONE)
-               {
-                       SysLog(NID_NET_WIFI, "An event received from SLP Wi-Fi Direct FW (type: WIFI_DIRECT_DEVICE_STATE_ACTIVATED)");
-                       pService->OnWifiDirectActivated();
-               }
-               break;
-
-       default:
-               break;       // ignore other types of event
+               __monitorClientIdList.GetAt(i, id);
+               __pStub->SendWifiConnectionStateChanged(id, state);
        }
 }
 
+void
+WifiService::OnWifiBackgroundScanResultUpdated()
+{
+       // broadcast to all clients
+       int id = 0;
+       for (int i = 0 ; i < __monitorClientIdList.GetCount() ; i++)
+       {
+               __monitorClientIdList.GetAt(i, id);
+               __pStub->SendWifiSystemScanResultUpdated(id);
+       }
+}
diff --git a/src/WifiSystemAdapter.cpp b/src/WifiSystemAdapter.cpp
new file mode 100755 (executable)
index 0000000..a8fc0e8
--- /dev/null
@@ -0,0 +1,1021 @@
+//
+// Open Service Platform
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file    WifiSystemAdapter.cpp
+ * @brief   This is the implementation file for the WifiSystemAdapter Class.
+ */
+#include <pthread.h>
+#include <vconf.h>
+#include <vconf-keys.h>
+#include <net_connection.h>
+#include <FBaseUtilStringUtil.h>
+#include <FBaseSysLog.h>
+#include <FNetWifiWifiBssInfo.h>
+#include <FNetNetAccountInfo.h>
+#include <FNetNetTypes.h>
+#include <FNetIp4Address.h>
+#include <FBase_StringConverter.h>
+#include <FSecCert_CertService.h>
+#include <FNetWifi_WifiBssInfoImpl.h>
+#include <FNetWifi_WifiManagerImpl.h>
+#include <FNetWifi_WifiNetAccountInfoImpl.h>
+#include <FNetWifi_WifiSecurityInfoImpl.h>
+#include <FNetWifi_WifiUtility.h>
+#include "WifiSystemAdapter.h"
+#include "WifiService.h"
+#include "WifiProximityService.h"
+#include "ConnectivityUtility.h"
+
+#ifdef _WifiConvertErrorResult
+#undef _WifiConvertErrorResult
+#endif
+#define _WifiConvertErrorResult(condition, r, value) \
+               do \
+               { \
+                       if (condition) {   \
+                               r = value; \
+                       } \
+               } while (0);
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Net;
+using namespace Tizen::Net::Wifi;
+using namespace Tizen::Security::Cert;
+
+
+
+static WifiSystemAdapter* pInstance = null;
+
+WifiSystemAdapter::WifiSystemAdapter(void)
+       : __prevconnState(WIFI_CONNECTION_STATE_DISCONNECTED)
+       , __pWifiService(null)
+       , __pWifiProximityService(null)
+       , __scanResultList(SingleObjectDeleter)
+{
+}
+
+WifiSystemAdapter::~WifiSystemAdapter(void)
+{
+}
+
+result
+WifiSystemAdapter::Construct(void)
+{
+       int err = WIFI_ERROR_NONE;
+
+       err = wifi_initialize();
+       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_initialize() [0x%08X]", err);
+
+       result r = E_SUCCESS;
+
+       err = wifi_set_device_state_changed_cb(OnWifiDeviceStateChanged, null);
+       SysTryCatch(NID_NET_WIFI, err == WIFI_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to wifi_set_device_state_changed_cb() [0x%08X]", err);
+
+       err = wifi_set_connection_state_changed_cb(OnWifiConnectionStateChanged, null);
+       SysTryCatch(NID_NET_WIFI, err == WIFI_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to wifi_set_connection_state_changed_cb() [0x%08X]", err);
+
+       err = wifi_set_rssi_level_changed_cb(OnWifiRssiLevelChanged, null);
+       SysTryCatch(NID_NET_WIFI, err == WIFI_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to wifi_set_rssi_level_changed_cb() [0x%08X]", err);
+
+       err = wifi_set_background_scan_cb(OnWifiBackgroundScanResultUpdated, null);
+       SysTryCatch(NID_NET_WIFI, err == WIFI_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to wifi_set_background_scan_cb() [0x%08X]", err);
+
+       err = wifi_get_connection_state(&__prevconnState);
+       SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed to wifi_get_connection_state() [0x%08X]", err);
+
+       err = wifi_foreach_found_aps(OnWifiEachAccessPointFound, &__scanResultList);
+       SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed to wifi_foreach_found_aps() [0x%08X]", err);
+
+       return r;
+
+CATCH:
+       err = wifi_deinitialize();
+       SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed to wifi_deinitialize() [0x%08X]", err);
+       return r;
+}
+
+void
+WifiSystemAdapter::InitSingleton(void)
+{
+       result r = E_SUCCESS;
+       unique_ptr<WifiSystemAdapter> pInst(new (std::nothrow) WifiSystemAdapter());
+
+       SysTryReturnVoidResult(NID_NET_WIFI, pInst != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+       r = pInst->Construct();
+       SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS, r, "[%s] Error occurred in construct.", GetErrorMessage(r));
+
+       pInstance = pInst.release();
+
+       std::atexit(DestroySingleton);
+}
+
+void 
+WifiSystemAdapter::DestroySingleton(void)
+{
+       wifi_unset_connection_state_changed_cb();
+       wifi_unset_device_state_changed_cb();
+       wifi_unset_rssi_level_changed_cb();
+       wifi_unset_background_scan_cb();
+       wifi_deinitialize();
+}
+
+WifiSystemAdapter*
+WifiSystemAdapter::GetInstance(void)
+{
+       static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
+
+       if (!pInstance)
+       {
+               ClearLastResult();
+               pthread_once(&onceBlock, InitSingleton);
+
+               result r = GetLastResult();
+               if (IsFailed(r))
+               {
+                       onceBlock = PTHREAD_ONCE_INIT;
+               }
+       }
+       return pInstance;
+}
+
+void
+WifiSystemAdapter::SetWifiService(WifiService* pWifiService)
+{
+       SysLog(NID_NET_WIFI, "pWifiServie is %d",pWifiService);
+       __pWifiService = pWifiService;
+}
+
+void
+WifiSystemAdapter::SetProximityService(WifiProximityService* pProximityService)
+{
+       __pWifiProximityService = pProximityService;
+}
+
+result
+WifiSystemAdapter::Activate(int clientId)
+{
+       unique_ptr<int> pClientId(new int(clientId));
+       result r = E_SYSTEM;
+       int err = WIFI_ERROR_NONE;
+
+       err = wifi_activate(OnWifiActivated, pClientId.get());
+       _WifiConvertErrorResult(err == WIFI_ERROR_OPERATION_FAILED, r, E_FAILURE);
+       _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_OPERATION, r, E_INVALID_OPERATION);
+       _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to activate Wi-Fi. [0x%08X]", err);
+
+       pClientId.release();
+
+               return E_SUCCESS;
+}
+
+result
+WifiSystemAdapter::Deactivate(int clientId)
+{
+
+       unique_ptr<int> pClientId(new int(clientId));
+       result r = E_SYSTEM;
+       int err = WIFI_ERROR_NONE;
+
+       err = wifi_deactivate(OnWifiDeactivated, pClientId.get());
+       _WifiConvertErrorResult(err == WIFI_ERROR_OPERATION_FAILED, r, E_FAILURE);
+       _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_OPERATION, r, E_INVALID_OPERATION);
+       _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to deactivate Wi-Fi. [0x%08X]", err);
+
+       pClientId.release();
+
+       return E_SUCCESS;
+}
+
+String
+WifiSystemAdapter::GetMacAddress(void) const
+{
+
+       ClearLastResult();
+
+       int err = 0;
+       char* pMacAddress = null;
+       err = wifi_get_mac_address(&pMacAddress);
+       SysTryReturn(NID_NET_WIFI, err == WIFI_ERROR_NONE && pMacAddress != null, String(), E_SYSTEM,
+                                               "Getting the mac addresss has failed. [0x%x]", err);
+       String macAddress(_WifiUtility::ConvertMacAddress(pMacAddress));
+
+       free(pMacAddress);
+
+       return macAddress;
+}
+
+bool
+WifiSystemAdapter::IsActivated(void) const
+{
+       ClearLastResult();
+
+       bool val = false;
+
+       int err = wifi_is_activated(&val);
+       SysTryReturn(NID_NET_WIFI, err == WIFI_ERROR_NONE, false, E_SYSTEM, "result from wifi_is_activated() is 0x%x", err);
+
+        return val;
+}
+
+bool
+WifiSystemAdapter::IsConnected(void) const
+{
+       ClearLastResult();
+
+       wifi_connection_state_e connectionState = WIFI_CONNECTION_STATE_DISCONNECTED;
+
+       int err = wifi_get_connection_state(&connectionState);
+       SysTryReturn(NID_NET_WIFI, err == WIFI_ERROR_NONE, false, E_SYSTEM, "result from wifi_get_connection_state() is 0x%x", err);
+       switch (connectionState)
+       {
+       case WIFI_CONNECTION_STATE_CONNECTED:
+       return true;
+       default:
+       return false;
+       }
+}
+
+
+bool
+WifiSystemAdapter::IsConnected(wifi_ap_h pApHandle) const
+{
+       int err = WIFI_ERROR_NONE;
+       bool isSame = false;
+
+       if (IsConnected())
+       {
+               wifi_ap_h pConnectedApHandle = null;
+               err = wifi_get_connected_ap(&pConnectedApHandle);
+
+               if (err != WIFI_ERROR_NONE && pConnectedApHandle == null)
+               {
+                       SysLog(NID_NET_WIFI, "Failed result from wifi_get_connected_ap() is 0x%x", err);
+                       return false;
+               }
+
+               String connectedBssId(_WifiUtility::GetBssIdFromApHandle(pConnectedApHandle));
+               String targetBssId(_WifiUtility::GetBssIdFromApHandle(pApHandle));
+
+               if (connectedBssId.CompareTo(targetBssId) == 0)
+               {
+                       isSame = true;
+               }
+
+               (void)wifi_ap_destroy(pConnectedApHandle);
+       }
+
+       return isSame;
+}
+
+
+result
+WifiSystemAdapter::Scan(int clientId)
+{
+       unique_ptr<int> pClientId(new int(clientId));
+       result r = E_FAILURE;
+       int err = WIFI_ERROR_NONE;
+
+       err = wifi_scan(OnWifiScanCompleted, pClientId.get());
+       _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to scan for a nearby BSS. [0x%08X]", err);
+
+       pClientId.release();
+       return E_SUCCESS;
+}
+
+result
+WifiSystemAdapter::ScanforProximity()
+{
+       result r = E_FAILURE;
+       int err = WIFI_ERROR_NONE;
+
+       err = wifi_scan(OnWifiScanCompleted, null);
+       _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS);
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to scan for a nearby BSS. [0x%08X]", err);
+
+       return E_SUCCESS;
+}
+
+WifiConnectionState
+WifiSystemAdapter::GetConnectionState(void) const
+{
+       ClearLastResult();
+
+       result r = E_SYSTEM;
+       wifi_connection_state_e currentState = WIFI_CONNECTION_STATE_DISCONNECTED;
+       WifiConnectionState connectionState = WIFI_CONN_STATE_NOT_CONNECTED;
+
+       int err = wifi_get_connection_state(&currentState);
+       _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS);
+       SysTryReturn(NID_NET_WIFI, r == E_SUCCESS, WIFI_CONN_STATE_NOT_CONNECTED, r, "Failed result from wifi_get_connection_state() is 0x%x", err);
+
+       switch (currentState)
+       {
+       case WIFI_CONNECTION_STATE_ASSOCIATION:
+               connectionState = WIFI_CONN_STATE_ASSOCIATING;
+               break;
+       case WIFI_CONNECTION_STATE_CONFIGURATION:
+               connectionState = WIFI_CONN_STATE_CONFIGURING;
+               break;
+       case WIFI_CONNECTION_STATE_CONNECTED:
+               connectionState = WIFI_CONN_STATE_CONNECTED;
+               break;
+       case WIFI_CONNECTION_STATE_DISCONNECTED:
+       default:
+               connectionState = WIFI_CONN_STATE_NOT_CONNECTED;
+               break;
+       }
+
+       return connectionState;
+}
+
+result
+WifiSystemAdapter::GetConnectionTargetInfo(WifiBssInfo* pBssInfo) const
+{
+       if (GetConnectionState() != WIFI_CONN_STATE_CONNECTED)
+       {
+               SysLog(NID_NET_WIFI, "The current state is not connected to AP.");
+               return E_SUCCESS;
+       }
+
+       result r = E_SUCCESS;
+       int err = WIFI_ERROR_NONE;
+       wifi_ap_h pApHandle = null;
+       err = wifi_get_connected_ap(&pApHandle);
+       SysTryReturnResult(NID_NET_WIFI, err != WIFI_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "Memory allocation failed.");
+       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to get the connected AP handle.");
+
+        r = _WifiUtility::GetWifiBssInfoFromApHandle(pApHandle, pBssInfo);
+       (void)wifi_ap_destroy(pApHandle);
+
+       return r;
+}
+
+result
+WifiSystemAdapter::GetWifiNetAccountInfo(Tizen::Net::NetAccountInfo* pNetAccountInfo,
+               Tizen::Net::Wifi::_WifiNetAccountInfoImpl* pWifiNetAccountInfoImpl) const
+{
+       if (GetConnectionState() != WIFI_CONN_STATE_CONNECTED)
+       {
+               SysLog(NID_NET_WIFI, "The current state is not connected to AP.");
+               pNetAccountInfo->Construct();
+               return E_INVALID_STATE;
+       }
+    result r = E_SUCCESS;
+
+       unique_ptr<void, _ProfileDeleter> pProfileHandle(ConnectivityUtility::GetWifiProfileHandleN());
+
+       r = ConnectivityUtility::UpdateNetAccountInfo(pNetAccountInfo, pProfileHandle.get());
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Failed to update a NetAccountInfo.");
+
+       r = ConnectivityUtility::UpdateWifiNetAccountInfo(pWifiNetAccountInfoImpl, pProfileHandle.get());
+       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, E_SYSTEM, "Failed to update a WifiNetAccountInfo.");
+
+
+       return r;
+}
+
+Tizen::Base::Collection::IList*
+WifiSystemAdapter::GetSystemScanResult(void)
+{
+       __scanResultList.RemoveAll();
+       int err = wifi_foreach_found_aps(OnWifiEachAccessPointFound, &__scanResultList);
+       SysTryReturn(NID_NET_WIFI, err == WIFI_ERROR_NONE, null, E_OPERATION_FAILED, "Failed to wifi_foreach_found_aps() [0x%08X]", err);
+
+       return &__scanResultList;
+}
+
+result
+WifiSystemAdapter::SetWifiSystemScanMode(int mode)
+{
+       // changes vconf value about Wi-Fi BG scan mode.
+       // Key:   VCONFKEY_WIFI_BGSCAN_MODE                "memory/wifi/bgscan_mode"
+       // Value: VCONFKEY_WIFI_BGSCAN_MODE_PERIODIC
+       //        VCONFKEY_WIFI_BGSCAN_MODE_EXPONENTIAL
+
+       // changes vconf value about Wi-Fi UG running mode.
+       // Key:   VCONFKEY_WIFI_UG_RUN_STATE                "memory/wifi/ug_run_state"
+       // Value: VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND - auto connect pop-up for selecting the AP is not displayed.
+       //        VCONFKEY_WIFI_UG_RUN_STATE_OFF
+
+       int vconfRes = 0;
+       //int bgScanMode = VCONFKEY_WIFI_BGSCAN_MODE_EXPONENTIAL;
+       int ugRunState = VCONFKEY_WIFI_UG_RUN_STATE_OFF;
+       WifiSystemScanMode scanMode = (WifiSystemScanMode) mode;
+
+       switch(scanMode)
+       {
+       case WIFI_SYSTEM_SCAN_MODE_ACTIVE:
+               //bgScanMode = VCONFKEY_WIFI_BGSCAN_MODE_PERIODIC;
+               //SysLog(NID_NET_WIFI, "Change BG scan mode (VCONFKEY_WIFI_BGSCAN_MODE_PERIODIC)");
+               ugRunState = VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND;
+               SysLog(NID_NET_WIFI, "Change UG state (ON_FOREGROUND)");
+               break;
+       case WIFI_SYSTEM_SCAN_MODE_PASSIVE:
+       default:
+               //bgScanMode = VCONFKEY_WIFI_BGSCAN_MODE_EXPONENTIAL;
+               //SysLog(NID_NET_WIFI, "Change BG scan mode (VCONFKEY_WIFI_BGSCAN_MODE_EXPONENTIAL)");
+               ugRunState = VCONFKEY_WIFI_UG_RUN_STATE_OFF;
+               SysLog(NID_NET_WIFI, "Change UG state (OFF)");
+
+               break;
+       }
+
+       vconfRes = vconf_set_int(VCONFKEY_WIFI_UG_RUN_STATE, ugRunState);
+       SysTryReturnResult(NID_NET_WIFI, vconfRes == 0, E_OPERATION_FAILED, "Setting the running mode of the Wi-Fi UG has failed.");
+
+//     vconfRes = vconf_set_int(VCONFKEY_WIFI_BGSCAN_MODE, bgScanMode);
+//     SysTryReturnResult(NID_NET_WIFI, vconfRes == 0, E_OPERATION_FAILED, "Setting the BG scanning mode of the Wi-Fi has failed.[%d]"
+//     , vconfRes);
+
+       return E_SUCCESS;
+
+}
+
+result
+WifiSystemAdapter::UpdateWifiBssInfo(const Tizen::Net::Wifi::WifiBssInfo& bssInfo)
+{
+       const _WifiBssInfoImpl* pBssInfoImpl = null;
+       int err = WIFI_ERROR_NONE;
+       NetAddressScheme ipScheme = NET_ADDRESS_SCHEME_DYNAMIC;
+       wifi_ip_config_type_e apIpScheme = WIFI_IP_CONFIG_TYPE_NONE;
+       const IpAddress* pAddress = null;
+       unique_ptr<char[]> pAddressStr;
+       NetProxyType proxyType = NET_PROXY_TYPE_NONE;
+       wifi_proxy_type_e apProxyType = WIFI_PROXY_TYPE_DIRECT;
+       String proxyAddressStr;
+       bool isKnown = false;
+
+       pBssInfoImpl = _WifiBssInfoImpl::GetInstance(bssInfo);
+
+       wifi_ap_h pApHandle = null;
+       unique_ptr<IEnumerator> pEnum(__scanResultList.GetEnumeratorN());
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               WifiBssInfo* pBssInfo = static_cast<WifiBssInfo*>(pEnum->GetCurrent());
+               const _WifiBssInfoImpl* pBssInfoImplTemp = _WifiBssInfoImpl::GetInstance(*pBssInfo);
+               if (bssInfo.GetBssId() == pBssInfoImplTemp->GetBssId())
+               {
+                       pApHandle = static_cast <wifi_ap_h> (pBssInfoImplTemp->GetBssHandle());
+                       break;
+               }
+       }
+       SysTryReturnResult(NID_NET_WIFI, pApHandle != null, E_OPERATION_FAILED,
+                       "The AP is not found in the current AP list of the system.");
+
+       // Setting the AP unknown
+       err = wifi_ap_is_favorite(pApHandle, &isKnown);
+       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                       "Checking the AP is a known device has failed. [0x%08X].", err);
+       if (isKnown && !(pBssInfoImpl->IsKnown()))
+       {
+               err = wifi_forget_ap(pApHandle);
+               SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                               "Setting the AP unknown has failed. [0x%08X].", err);
+       }
+
+       // Setting the IP address scheme. Only IPv4 as the address family is taken into consideration for now.
+       ipScheme = pBssInfoImpl->GetLocalAddressScheme();
+       apIpScheme = (ipScheme == NET_ADDRESS_SCHEME_STATIC) ? WIFI_IP_CONFIG_TYPE_STATIC : WIFI_IP_CONFIG_TYPE_DYNAMIC;
+       err = wifi_ap_set_ip_config_type(pApHandle, WIFI_ADDRESS_FAMILY_IPV4, apIpScheme);
+       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                       "Setting the IP address scheme to AP has failed. [0x%08X].", err);
+
+       if (ipScheme == NET_ADDRESS_SCHEME_STATIC)
+       {
+               // Setting the IP address. Only IPv4 as the address family is taken into consideration for now.
+               pAddress = pBssInfoImpl->GetLocalAddress();
+               if (pAddress != null)
+               {
+                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
+                       err = wifi_ap_set_ip_address(pApHandle, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
+                       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                                       "Setting the IP address to AP has failed. [0x%08X].", err);
+               }
+
+               // Setting the subnet mask. Only IPv4 as the address family is taken into consideration for now.
+               pAddress = pBssInfoImpl->GetSubnetMaskAddress();
+               if (pAddress != null)
+               {
+                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
+                       err = wifi_ap_set_subnet_mask(pApHandle, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
+                       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                                       "Setting the subnet mask to AP has failed. [0x%08X].", err);
+               }
+
+               // Setting the default gateway address. Only IPv4 as the address family is taken into consideration for now.
+               pAddress = pBssInfoImpl->GetDefaultGatewayAddress();
+               if (pAddress != null)
+               {
+                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
+                       err = wifi_ap_set_gateway_address(pApHandle, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
+                       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                                       "Setting the default gateway address to AP has failed. [0x%08X].", err);
+               }
+
+               // Setting the primary DNS address. Only IPv4 as the address family is taken into consideration for now.
+               pAddress = pBssInfoImpl->GetPrimaryDnsAddress();
+               if (pAddress != null)
+               {
+                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
+                       err = wifi_ap_set_dns_address(pApHandle, 1, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
+                       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                                       "Setting the primary DNS address to AP has failed. [0x%08X].", err);
+               }
+
+               // Setting the secondary DNS address. Only IPv4 as the address family is taken into consideration for now.
+               pAddress = pBssInfoImpl->GetSecondaryDnsAddress();
+               if (pAddress != null)
+               {
+                       pAddressStr.reset(_StringConverter::CopyToCharArrayN(pAddress->ToString()));
+                       err = wifi_ap_set_dns_address(pApHandle, 2, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
+                       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                                       "Setting the secondary DNS address to AP has failed. [0x%08X].", err);
+               }
+       }
+
+       proxyType = pBssInfoImpl->GetProxyType();
+
+       if (proxyType == NET_PROXY_TYPE_MANUAL)
+       {
+               // Setting the proxy address. Only IPv4 as the address family is taken into consideration for now.
+               proxyAddressStr = pBssInfoImpl->GetProxyAddress();
+               pAddressStr.reset(_StringConverter::CopyToCharArrayN(proxyAddressStr));
+               err = wifi_ap_set_proxy_address(pApHandle, WIFI_ADDRESS_FAMILY_IPV4, pAddressStr.get());
+               SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                               "Setting the proxy address to AP has failed. [0x%08X].", err);
+       }
+
+       // Setting the proxy type.
+       apProxyType = (proxyType == NET_PROXY_TYPE_MANUAL) ? WIFI_PROXY_TYPE_MANUAL : WIFI_PROXY_TYPE_DIRECT;
+       err = wifi_ap_set_proxy_type(pApHandle, apProxyType);
+       SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_OPERATION_FAILED,
+                       "Setting the proxy type to AP has failed. [0x%08X].", err);
+
+       return E_SUCCESS;
+}
+
+void
+WifiSystemAdapter::OnWifiDeviceStateChanged(wifi_device_state_e state, void* pUserData)
+{
+       WifiService* pWifiService = pInstance->__pWifiService;
+       if (pWifiService != null)
+       {
+               if(state == WIFI_DEVICE_STATE_ACTIVATED)
+               {
+                       SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_ACTIVATED]");
+                       pWifiService->OnWifiActivated(0, E_SUCCESS);
+               }
+               else
+               {
+                       SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DEACTIVATED]");
+                       pWifiService->OnWifiDeactivated(0, E_SUCCESS);
+               }
+       }
+
+       WifiProximityService* pWifiProximityService = pInstance->__pWifiProximityService;
+       if (pWifiProximityService != null)
+       {
+               if(state == WIFI_DEVICE_STATE_ACTIVATED)
+               {
+                       SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_ACTIVATED]");
+                       pWifiProximityService->OnWifiActivated();
+               }
+               else
+               {
+                       SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DEACTIVATED]");
+                       pWifiProximityService->OnWifiDeactivated();
+               }
+       }
+}
+
+void 
+WifiSystemAdapter::OnWifiActivated(wifi_error_e errorCode, void* pUserData)
+{
+
+       // If errorCode is a WIFI_ERROR_NONE, the OnWifiDeactivated() will be notified through OnWifiDeviceStateChanged()
+       if (errorCode != WIFI_ERROR_NONE)
+       {
+               int* pClientId = static_cast<int*>(pUserData);
+          SysLog(NID_NET_WIFI, "Client ID : %d", *pClientId);
+
+               WifiService* pWifiService = pInstance->__pWifiService;
+               if (pWifiService != null)
+               {
+                       pWifiService->OnWifiActivated(*pClientId, E_FAILURE);
+
+               }
+               delete pClientId;
+       }
+}
+void 
+WifiSystemAdapter::OnWifiDeactivated(wifi_error_e errorCode, void* pUserData)
+{
+
+       // If errorCode is a WIFI_ERROR_NONE, the OnWifiDeactivated() will be notified through OnWifiDeviceStateChanged()
+       if (errorCode != WIFI_ERROR_NONE)
+       {
+               int* pClientId = static_cast<int*>(pUserData);
+               SysLog(NID_NET_WIFI, "Client ID : %d", *pClientId);
+
+               WifiService* pWifiService = pInstance->__pWifiService;
+               if (pWifiService != null)
+               {
+                        pWifiService->OnWifiDeactivated(*pClientId, E_FAILURE);
+
+               }
+               delete pClientId;
+       }
+}
+
+void
+WifiSystemAdapter::OnWifiConnected(wifi_error_e errorCode, void* pUserData)
+{
+       result r = E_SUCCESS;
+       _WifiConvertErrorResult(errorCode != WIFI_ERROR_NONE, r, E_FAILURE);
+       _WifiConvertErrorResult(errorCode == WIFI_ERROR_ALREADY_EXISTS, r, E_SUCCESS);
+       _WifiConvertErrorResult(errorCode == WIFI_ERROR_INVALID_KEY, r, E_AUTHENTICATION);
+       _WifiConvertErrorResult(errorCode == WIFI_ERROR_NO_REPLY, r, E_NOT_RESPONDING);
+       _WifiConvertErrorResult(errorCode == WIFI_ERROR_DHCP_FAILED, r, E_DHCP);
+       SysTryLog(NID_NET_WIFI, r == E_SUCCESS, "Failed result from OnWifiConnected() is 0x%x.", errorCode);
+
+       int* pClientId = static_cast<int*>(pUserData);
+       SysLog(NID_NET_WIFI, "Client ID : %d", *pClientId);
+
+       WifiService* pWifiService = pInstance->__pWifiService;
+       if (pWifiService == null)
+       {
+               SysLog(NID_NET_WIFI, "WifiService is not registered.");
+               return;
+       }
+
+       if(r == E_SUCCESS)
+       {
+               char* pEssid = null;
+               wifi_ap_h apHandler;
+               int err = wifi_get_connected_ap(&apHandler);
+               SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_get_connected_ap() is 0x%x.", err);
+               _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
+               _WifiConvertErrorResult(err == WIFI_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY);
+
+               err = wifi_ap_get_essid(apHandler, &pEssid);
+               SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_get_essid() is 0x%x.", err);
+               String ssid(pEssid);
+               free(pEssid);
+
+               (void)wifi_ap_destroy(apHandler);
+
+               SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:%s]", GetErrorMessage(r));
+               pWifiService->OnWifiConnected(*pClientId, ssid, r);
+
+       }
+       else
+       {
+               SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:%s]", GetErrorMessage(r));
+               pWifiService->OnWifiConnected(*pClientId, String(), r);
+
+       }
+
+       delete pClientId;
+}
+
+void
+WifiSystemAdapter::OnWifiConnectionStateChanged(wifi_connection_state_e state, wifi_ap_h pApHandle, void *pUserData)
+{
+       WifiSystemAdapter* pAdapter = pInstance;
+       WifiService* pWifiService = pInstance->__pWifiService;
+
+       if (pWifiService == null)
+       {
+               SysLog(NID_NET_WIFI, "WifiService is not registered.");
+               return;
+       }
+
+       char* pEssid = null;
+       int err = wifi_ap_get_essid(pApHandle, &pEssid);
+       unique_ptr<char, Wifi::_CharDeleter> pSsid(pEssid);
+       SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_get_essid() is 0x%x.", err);
+       SysLog(NID_NET_WIFI, "The connection state is %s, ssid : %s", GetStringOfConnectionState(state), pSsid.get());
+
+       if (pAdapter->__prevconnState == state)
+       {
+               SysLog(NID_NET_WIFI, "The connection state is same as the previous state.[%d]", state);
+               return;
+       }
+
+       pAdapter->__prevconnState = state;
+
+       switch(state)
+       {
+       case WIFI_CONNECTION_STATE_CONNECTED:
+       {
+               String ssid(pSsid.release());
+               // Fire a CONNECTED event for notifying that the connection is established not by this system adapter.
+               SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:E_SUCCESS]");
+               pWifiService->OnWifiConnected(0, ssid, E_SUCCESS);
+
+               // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to 'CONNECTED' state.
+               // This seems a little redundant but the purpose of it is quite different from CONNECTED event.
+               SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONNECTION_STATE_CONNECTED]");
+               pWifiService->OnWifiConnectionStateChanged(WIFI_CONN_STATE_CONNECTED);
+       }
+               break;
+
+       case WIFI_CONNECTION_STATE_DISCONNECTED:
+       {
+               wifi_connection_state_e connectionState = WIFI_CONNECTION_STATE_DISCONNECTED;
+
+               int err = wifi_get_connection_state(&connectionState);
+               SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_get_connection_state() is 0x%x.", err);
+
+               // Ignore if wifi state is connected.
+               if (connectionState == WIFI_CONNECTION_STATE_CONNECTED)
+                       break;
+
+               // Fire a DISCONNECTED event for notifying that the connection is broken off not by this system adapter.
+               SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DISCONNECTED]");
+               pWifiService->OnWifiDisconnected();
+
+               // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "IDLE' state.
+               // This seems a little redundant but the purpose of it is quite different from DISCONNECTED event.
+               SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_NOT_CONNECTED]");
+               pWifiService->OnWifiConnectionStateChanged(WIFI_CONN_STATE_NOT_CONNECTED);
+       }
+               break;
+
+       case WIFI_CONNECTION_STATE_ASSOCIATION:
+               // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "ASSOCIATING" state.
+               SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_ASSOCIATING]");
+               pWifiService->OnWifiConnectionStateChanged(WIFI_CONN_STATE_ASSOCIATING);
+               break;
+
+       case WIFI_CONNECTION_STATE_CONFIGURATION:
+               // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "CONFIGURING" state.
+               SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_CONFIGURING]");
+               pWifiService->OnWifiConnectionStateChanged(WIFI_CONN_STATE_CONFIGURING);
+               break;
+       default:
+               break;
+       }
+}
+
+bool
+WifiSystemAdapter::OnWifiEachAccessPointFound(wifi_ap_h pApHandle, void* pUserData)
+{
+       WifiBssInfo* pBssInfo = null;
+       LinkedList* pBssInfoList = static_cast<LinkedList*>(pUserData);
+       wifi_ap_h pApHandleClone = null;
+
+       int err = wifi_ap_clone(&pApHandleClone, pApHandle);
+       SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_clone() is 0x%x.", err);
+       pBssInfo = _WifiUtility::CreateWifiBssInfoInstanceN(pApHandleClone);
+       // keep gonig even though creating one WifiBssInfo instance.
+       SysTryReturn(NID_NET_WIFI, pBssInfo != null, true, GetLastResult(),
+                       "[%s] Propagating because of creating a new WifiBssInfo fails.", GetErrorMessage(GetLastResult()));
+
+       pBssInfoList->Add(*pBssInfo);
+       return true;
+}
+
+void
+WifiSystemAdapter::OnWifiScanCompleted(wifi_error_e errorCode, void *pUserData)
+{
+       result r = E_FAILURE;
+       _WifiConvertErrorResult(errorCode == WIFI_ERROR_NONE, r, E_SUCCESS);
+
+       pInstance->__scanResultList.RemoveAll();
+
+       int err = wifi_foreach_found_aps(OnWifiEachAccessPointFound, &pInstance->__scanResultList);
+       SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_foreach_found_aps() is 0x%x.", err);
+
+       WifiProximityService* pWifiProximityService = pInstance->__pWifiProximityService;
+       if (pWifiProximityService != null)
+       {
+               SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_SCAN_COMPLETED],[result:%s]", GetErrorMessage(r));
+               pWifiProximityService->OnWifiScanCompleted(&pInstance->__scanResultList, r);
+       }
+
+       if (pUserData != null)
+       {
+               unique_ptr<int> pClientId(static_cast<int*>(pUserData));
+               SysLog(NID_NET_WIFI, "Client ID : %d", *pClientId);
+               WifiService* pWifiService = pInstance->__pWifiService;
+               if (pWifiService != null)
+               {
+                       SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_SCAN_COMPLETED],[result:%s]", GetErrorMessage(r));
+
+                       pWifiService->OnWifiScanCompleted(*pClientId, &pInstance->__scanResultList, r);
+
+               }
+       }
+}
+
+void
+WifiSystemAdapter::OnWifiBackgroundScanResultUpdated(wifi_error_e errorCode, void* pUserData)
+{
+       SysLog(NID_NET_WIFI, "The background scan result updated.");
+       if (errorCode == WIFI_ERROR_NONE)
+       {
+               WifiService* pWifiService = pInstance->__pWifiService;
+               if (pWifiService != null)
+               {
+                       SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_SCAN_COMPLETED]");
+                       pWifiService->OnWifiBackgroundScanResultUpdated();
+               }
+       }
+}
+
+result
+WifiSystemAdapter::Connect(int clientId, const WifiBssInfo& bssInfo)
+{
+       result r = E_SUCCESS;
+       int err = WIFI_ERROR_NONE;
+
+       wifi_ap_h pApHandle = null;
+       wifi_security_type_e securityType;
+       const WifiBssInfo* pBssInfo = null;
+       const _WifiBssInfoImpl* pBssInfoImpl = null;
+       const WifiSecurityInfo* pSecurityInfo = bssInfo.GetSecurityInfo();
+       const _WifiSecurityInfoImpl* pSecurityInfoImpl = _WifiSecurityInfoImpl::GetInstance(*pSecurityInfo);
+
+       unique_ptr<IEnumerator> pEnum(__scanResultList.GetEnumeratorN());
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               pBssInfo = static_cast<WifiBssInfo*>(pEnum->GetCurrent());
+               pBssInfoImpl = _WifiBssInfoImpl::GetInstance(*pBssInfo);
+               if (bssInfo.GetBssId() == pBssInfoImpl->GetBssId())
+               {
+                       pApHandle = static_cast <wifi_ap_h> (pBssInfoImpl->GetBssHandle());
+                       break;
+               }
+       }
+
+       if(pApHandle == null)
+       {
+               SysLog(NID_NET_WIFI, "It's a hidden AP");
+
+               // Sets SSID
+               unique_ptr<char[]> pSsidTemp(_StringConverter::CopyToCharArrayN(bssInfo.GetSsid()));
+               SysTryReturnResult(NID_NET_WIFI, pSsidTemp != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+               err = wifi_ap_create(pSsidTemp.get(), &pApHandle);
+               SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_create() is 0x%x.", err);
+               _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
+               _WifiConvertErrorResult(err == WIFI_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY);
+               SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to create handle of ap.");
+
+               // Sets Authentication Type
+               securityType = _WifiUtility::ConvertSecurityType(pSecurityInfo->GetAuthenticationType());
+               err = wifi_ap_set_security_type(pApHandle, securityType);
+               SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_security_type() is 0x%x.", err);
+               _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
+               SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set authenticatino type.");
+       }
+       else
+       {
+               SysTryReturnResult(NID_NET_WIFI, !IsConnected(pApHandle), E_INVALID_STATE, "There is already connected to the same access point.");
+       }
+
+
+       if (pSecurityInfoImpl->GetEncryptionType() != WIFI_ENCRYPTION_NONE
+               && pSecurityInfoImpl->GetAuthenticationType() != WIFI_AUTHENTICATION_WPA
+               && pSecurityInfoImpl->GetAuthenticationType() != WIFI_AUTHENTICATION_WPA2)
+       {
+               unique_ptr<char[]> pKeyTemp(_StringConverter::CopyToCharArrayN(pSecurityInfoImpl->GetNetworkKey()));
+               SysTryReturnResult(NID_NET_WIFI, pKeyTemp != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+               err = wifi_ap_set_passphrase(pApHandle,pKeyTemp.get());
+               SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_passphrase() is 0x%x.", err);
+               _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
+               SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set network key.");
+       }
+       else if(pSecurityInfoImpl->GetAuthenticationType() == WIFI_AUTHENTICATION_WPA
+                       || pSecurityInfoImpl->GetAuthenticationType() == WIFI_AUTHENTICATION_WPA2)
+       {
+               wifi_eap_type_e eapType = _WifiUtility::ConvertEapType(pSecurityInfoImpl->GetEapType());
+               err = wifi_ap_set_eap_type(pApHandle, eapType);
+               SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_eap_type() is 0x%x.", err);
+               _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
+               _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG);
+               SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set eap type.");
+
+               if (eapType == WIFI_EAP_TYPE_PEAP
+                       || eapType == WIFI_EAP_TYPE_TTLS
+                       || eapType == WIFI_EAP_TYPE_TLS)
+               {
+                       wifi_eap_auth_type_e eapAuthType = _WifiUtility::ConvertEapAuthType(pSecurityInfoImpl->GetEapType());
+                       err = wifi_ap_set_eap_auth_type(pApHandle, eapAuthType);
+                       SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_eap_auth_type() is 0x%x.", err);
+                       _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
+                       _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG);
+                       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set eap authentication type.");
+
+                       unique_ptr<char[]> pUserId(_StringConverter::CopyToCharArrayN(pSecurityInfoImpl->GetEapUserId()));
+                       unique_ptr<char[]> pPassword(_StringConverter::CopyToCharArrayN(pSecurityInfoImpl->GetEapPassword()));
+
+                       err = wifi_ap_set_eap_passphrase(pApHandle, pUserId.get(), pPassword.get());
+                       SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_eap_passphrase() is 0x%x.", err);
+                       _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
+                       _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG);
+                       SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set eap authentication type.");
+
+                       if (pSecurityInfoImpl->GetValidateServerCertificate() == true)
+                       {
+                               String caPath = _CertService::GetCertificateCrtFilePath();
+                               SysTryReturnResult(NID_NET_WIFI, caPath.GetLength() != 0, E_SYSTEM, "Failed to get the CA certificate file path.");
+
+                               char* pCaPath = _StringConverter::CopyToCharArrayN(caPath);
+                               SysTryReturnResult(NID_NET_WIFI, pCaPath != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+                               err = wifi_ap_set_eap_ca_cert_file(pApHandle, pCaPath);
+                               delete [] pCaPath;
+                               SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_eap_ca_cert_file() is 0x%x.", err);
+                               _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
+                               _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG);
+                               SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set cacert file.");
+                       }
+
+               // ToDo: 3.0
+               // if (eapType == WIFI_EAP_TYPE_TLS)
+               }
+       }
+
+       int* pClientId = new int(clientId);
+       err = wifi_connect(pApHandle, OnWifiConnected, pClientId);
+       SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_connect() is 0x%x.", err);
+       _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
+
+       if (err != WIFI_ERROR_NONE)
+       {
+               delete pClientId;
+       }
+
+       return r;
+}
+
+void
+WifiSystemAdapter::OnWifiRssiLevelChanged(wifi_rssi_level_e rssiLevel, void *pUserData)
+{
+       if (pInstance->__pWifiService == null)
+       {
+               SysLog(NID_NET_WIFI, "WifiService is not registered.");
+               return;
+       }
+
+       long rssi = _WifiUtility::ConvertLeveltoRssiValue(rssiLevel);
+       SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_RSSI_LEVEL_CHANGED]");
+       pInstance->__pWifiService->OnWifiRssiLevelChanged(rssi);
+}
+
+const char*
+WifiSystemAdapter::GetStringOfConnectionState(wifi_connection_state_e state)
+{
+       const char* pStateStr[] =
+       {
+               "DISCONNECTED",
+               "ASSOCIATION",
+               "CONFIGURATION",
+               "CONNECTED",
+       };
+
+       return pStateStr[state];
+}
+
+struct _WifiBssIdHandlePair
+{
+       const Tizen::Base::String* pBssId;
+       wifi_ap_h apHandle;
+};
+
+wifi_ap_h
+WifiSystemAdapter::GetApHandle(const Tizen::Base::String& bssId)
+{
+       _WifiBssIdHandlePair pair;
+       pair.pBssId = &bssId;
+       pair.apHandle = null;
+
+       wifi_foreach_found_aps(OnWifiEachAccessPointFound, &pair);
+
+       return pair.apHandle;
+}
+