refactoring active app handling
authorYoung Ik Cho <youngik.cho@samsung.com>
Tue, 16 Jul 2013 05:44:41 +0000 (14:44 +0900)
committerYoung Ik Cho <youngik.cho@samsung.com>
Wed, 24 Jul 2013 03:15:24 +0000 (12:15 +0900)
Change-Id: If77c94d14f14fd9b39fbfd6b2dc5a57277966697
Signed-off-by: Young Ik Cho <youngik.cho@samsung.com>
src/app/CMakeLists.txt [changed mode: 0755->0644]
src/app/FApp_ActiveWindowManager.cpp [new file with mode: 0644]
src/app/FApp_ActiveWindowManager.h [new file with mode: 0644]
src/app/FApp_AppManagerImpl.cpp
src/app/inc/FApp_AppManagerImpl.h

old mode 100755 (executable)
new mode 100644 (file)
index 954d3fd..e392e2e
@@ -67,6 +67,7 @@ SET (${this_target}_SOURCE_FILES
        FApp_LongevityManager.cpp
        FApp_AppControlResponseEvent.cpp
        FApp_AppLifecycleEvent.cpp
+       FApp_ActiveWindowManager.cpp
        )
 
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_SINGLETON_CLEANUP -fvisibility=hidden")
diff --git a/src/app/FApp_ActiveWindowManager.cpp b/src/app/FApp_ActiveWindowManager.cpp
new file mode 100644 (file)
index 0000000..f06c428
--- /dev/null
@@ -0,0 +1,434 @@
+//
+// Copyright (c) 2012 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        FApp_ActiveWindowManager.cpp
+ * @brief      This is the implementation for the _ActiveWindowManager.cpp class.
+ */
+
+#include <unique_ptr.h>
+
+#include <aul/aul.h>
+#include <Ecore.h>
+#include <Ecore_X.h>
+#include <X11/Xlib.h>
+
+#include <FBaseSysLog.h>
+#include <FAppIActiveAppEventListener.h>
+
+#include <FBaseRt_LibraryImpl.h>
+
+#include "FApp_Aul.h"
+#include "FApp_ActiveWindowManager.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+//using namespace Tizen::Base::Utility;
+using namespace Tizen::Base::Runtime;
+
+namespace
+{
+
+const wchar_t OSP_ECORE_X_SONAME[] = L"libecore_x.so.1";
+const wchar_t OSP_ECORE_SONAME[] = L"libecore.so.1";
+const wchar_t OSP_X11_SONAME[] = L"libX11.so.6";
+
+// ActiveWindow related function and variable from shared library.
+// libecore_x.so.1
+static Ecore_X_Atom(* p_ecore_x_atom_get)(const char* name) = null;
+static int(* p_ecore_x_window_prop_window_get)(Ecore_X_Window win, Ecore_X_Atom atom, Ecore_X_Window* val, unsigned int len) = null;
+static Eina_Bool(* p_ecore_x_netwm_pid_get)(Ecore_X_Window win, int* pid) = null;
+static int(* p_ecore_x_netwm_name_get)(Ecore_X_Window win, char** name) = null;
+static Ecore_X_Window* (* p_ecore_x_window_root_list)(int* num_ret) = null;
+static int* p_ECORE_X_EVENT_WINDOW_PROPERTY = null;
+// libecore.so.1
+static Ecore_Event_Handler* (* p_ecore_event_handler_add)(int type, Ecore_Event_Handler_Cb func, const void* data) = null;
+static void* (* p_ecore_event_handler_del)(Ecore_Event_Handler* event_handler) = null;
+// libX11.so
+static int (* p_XSelectInput)(Display* display, Window w, long event_mask) = null;
+static Display* (* p_XOpenDisplay)(_Xconst char* display_name) = null;
+static int (* p_XCloseDisplay)(Display* display) = null;
+
+static Ecore_Event_Handler* pWindowPropertyChanged = null;
+
+struct _DisplayDeleter
+{
+       void operator()(Display* pDisplay)
+       {
+               if (p_XOpenDisplay)
+               {
+                       p_XCloseDisplay(pDisplay);
+               }
+       }
+};
+
+} // anonymous name-space
+
+
+namespace Tizen { namespace App
+{
+
+_ActiveWindowManager::_ActiveWindowManager(void)
+       : __pX11Library(null)
+       , __pEcoreXLibrary(null)
+       , __pEcoreLibrary(null)
+{
+}
+
+_ActiveWindowManager::~_ActiveWindowManager(void)
+{
+       if (__activeAppEventListenerList.GetCount() > 0)
+       {
+               if (p_ecore_event_handler_del == null)
+               {
+                       _LibraryImpl& lib = GetEcoreLibraryImpl();
+                       p_ecore_event_handler_del = reinterpret_cast<void*(*)(Ecore_Event_Handler* event_handler)>(lib.GetProcAddress(L"ecore_event_handler_del"));
+               }
+               if (p_ecore_event_handler_del)
+               {
+                       if (pWindowPropertyChanged)
+                       {
+                               p_ecore_event_handler_del(pWindowPropertyChanged);
+                               pWindowPropertyChanged = null;
+                       }
+               }
+       }
+
+       delete __pX11Library;
+       delete __pEcoreXLibrary;
+       __pEcoreXLibrary = null;
+       delete __pEcoreLibrary;
+       __pEcoreLibrary = null;
+}
+
+Eina_Bool
+_ActiveWindowManager::OnPropertyChanged(void* pData, int type, void* pEvent)
+{
+       if (!pData)
+       {
+               SysLog(NID_UI, "The data is not valid.");
+               return EINA_FALSE;
+       }
+
+       _ActiveWindowManager* pThis = static_cast<_ActiveWindowManager*>(pData);
+
+       if (p_ecore_x_atom_get == null)
+       {
+               _LibraryImpl& lib = pThis->GetEcoreXLibraryImpl();
+               p_ecore_x_atom_get = reinterpret_cast<Ecore_X_Atom(*)(const char* name)>(lib.GetProcAddress(L"ecore_x_atom_get"));
+               SysTryReturnResult(NID_APP, p_ecore_x_atom_get != null, EINA_FALSE,
+                               "A system error has been occurred. Failed to get ecore_x_atom_get.");
+       }
+       if (p_ecore_x_window_prop_window_get == null)
+       {
+               _LibraryImpl& lib = pThis->GetEcoreXLibraryImpl();
+               p_ecore_x_window_prop_window_get = reinterpret_cast<int(*)(Ecore_X_Window win, Ecore_X_Atom atom, Ecore_X_Window* val, unsigned int len)>(lib.GetProcAddress(L"ecore_x_window_prop_window_get"));
+               SysTryReturnResult(NID_APP, p_ecore_x_window_prop_window_get != null, EINA_FALSE,
+                               "A system error has been occurred. Failed to get ecore_x_window_prop_window_get.");
+       }
+       if (p_ecore_x_netwm_pid_get == null)
+       {
+               _LibraryImpl& lib = pThis->GetEcoreXLibraryImpl();
+               p_ecore_x_netwm_pid_get = reinterpret_cast<Eina_Bool(*)(Ecore_X_Window win, int* pid)>(lib.GetProcAddress(L"ecore_x_netwm_pid_get"));
+               SysTryReturnResult(NID_APP, p_ecore_x_netwm_pid_get != null, EINA_FALSE,
+                               "A system error has been occurred. Failed to get ecore_x_netwm_pid_get.");
+       }
+       if (p_ecore_x_netwm_name_get == null)
+       {
+               _LibraryImpl& lib = pThis->GetEcoreXLibraryImpl();
+               p_ecore_x_netwm_name_get = reinterpret_cast<int(*)(Ecore_X_Window win, char** name)>(lib.GetProcAddress(L"ecore_x_netwm_name_get"));
+               SysTryReturnResult(NID_APP, p_ecore_x_netwm_name_get != null, EINA_FALSE,
+                               "A system error has been occurred. Failed to get ecore_x_netwm_name_get.");
+       }
+
+       if (!pEvent)
+       {
+               SysLog(NID_UI, "The event is not valid.");
+               return EINA_FALSE;
+       }
+
+       Ecore_X_Event_Window_Property* pE = (Ecore_X_Event_Window_Property*) pEvent;
+       Ecore_X_Atom atom = pE->atom;
+       Ecore_X_Atom activeAtom = p_ecore_x_atom_get("_NET_ACTIVE_WINDOW");
+
+       if (atom != activeAtom)
+       {
+               return ECORE_CALLBACK_PASS_ON;
+       }
+
+       Ecore_X_Window win = pE->win;
+       Ecore_X_Window activeWin = 0;
+       p_ecore_x_window_prop_window_get(win, activeAtom, &activeWin, 1);
+
+       int pid = 0;
+       p_ecore_x_netwm_pid_get(activeWin, &pid);
+
+       char* pAppName = null;
+       p_ecore_x_netwm_name_get(activeWin, &pAppName);
+
+       pThis->FireActiveAppEvent(activeWin, pid, pAppName);
+
+       if (pAppName)
+       {
+               free(pAppName);
+       }
+
+       return ECORE_CALLBACK_PASS_ON;
+}
+
+result
+_ActiveWindowManager::AddActiveAppEventListener(IActiveAppEventListener& listener)
+{
+       if (p_ecore_x_window_root_list == null)
+       {
+               _LibraryImpl& lib = GetEcoreXLibraryImpl();
+               p_ecore_x_window_root_list = reinterpret_cast<Ecore_X_Window*(*)(int* num_ret)>(lib.GetProcAddress(L"ecore_x_window_root_list"));
+               SysTryReturnResult(NID_APP, p_ecore_x_window_root_list != null, E_SYSTEM,
+                               "A system error has been occurred. Failed to get p_ecore_x_window_root_list.");
+       }
+       if (p_ECORE_X_EVENT_WINDOW_PROPERTY == null)
+       {
+               _LibraryImpl& lib = GetEcoreXLibraryImpl();
+               p_ECORE_X_EVENT_WINDOW_PROPERTY = reinterpret_cast<int*>(lib.GetProcAddress(L"ECORE_X_EVENT_WINDOW_PROPERTY"));
+               SysTryReturnResult(NID_APP, p_ECORE_X_EVENT_WINDOW_PROPERTY != null, E_SYSTEM,
+                               "A system error has been occurred. Failed to get p_ECORE_X_EVENT_WINDOW_PROPERTY.");
+       }
+       if (p_XOpenDisplay == null)
+       {
+               _LibraryImpl& lib = GetX11LibraryImpl();
+               p_XOpenDisplay = reinterpret_cast<Display*(*)(_Xconst char* display_name)>(lib.GetProcAddress(L"XOpenDisplay"));
+               SysTryReturnResult(NID_APP, p_XOpenDisplay != null, E_SYSTEM,
+                               "A system error has been occurred. Failed to get p_XOpenDisplay.");
+       }
+       if (p_XCloseDisplay == null)
+       {
+               _LibraryImpl& lib = GetX11LibraryImpl();
+               p_XCloseDisplay = reinterpret_cast<int(*)(Display* display)>(lib.GetProcAddress(L"XCloseDisplay"));
+               SysTryReturnResult(NID_APP, p_XCloseDisplay != null, E_SYSTEM,
+                               "A system error has been occurred. Failed to get p_XCloseDisplay.");
+       }
+       if (p_XSelectInput == null)
+       {
+               _LibraryImpl& lib = GetX11LibraryImpl();
+               p_XSelectInput = reinterpret_cast<int(*)(Display* display, Window w, long event_mask)>(lib.GetProcAddress(L"XSelectInput"));
+               SysTryReturnResult(NID_APP, p_XSelectInput != null, E_SYSTEM,
+                               "A system error has been occurred. Failed to get p_XSelectInput.");
+       }
+
+       if (p_ecore_event_handler_add == null)
+       {
+               _LibraryImpl& lib = GetEcoreLibraryImpl();
+               p_ecore_event_handler_add = reinterpret_cast<Ecore_Event_Handler*(*)(int type, Ecore_Event_Handler_Cb func, const void* data)>(lib.GetProcAddress(L"ecore_event_handler_add"));
+               SysTryReturnResult(NID_APP, p_ecore_event_handler_add != null, E_SYSTEM,
+                               "A system error has been occurred. Failed to get p_ecore_event_handler_add.");
+       }
+
+       bool alreadyExist = __activeAppEventListenerList.Contains(&listener);
+       SysTryReturnResult(NID_APP, !alreadyExist, E_OBJ_ALREADY_EXIST, "The event listener already exist.");
+       result r = __activeAppEventListenerList.Add(&listener);
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       if (!pWindowPropertyChanged)
+       {
+               std::unique_ptr<Display, _DisplayDeleter> pDisplay(p_XOpenDisplay(NULL));
+               SysTryReturnResult(NID_APP, pDisplay != null, E_SYSTEM, "A system error has been occurred. Failed to XOpenDisplay.");
+
+               int num = 0;
+               Ecore_X_Window* pRoots = p_ecore_x_window_root_list(&num);
+               SysTryReturnResult(NID_APP, pRoots != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+               for (int i = 0; i < num; i++)
+               {
+                       p_XSelectInput(pDisplay.get(), pRoots[i], PropertyChangeMask);
+               }
+
+               pWindowPropertyChanged = p_ecore_event_handler_add(*p_ECORE_X_EVENT_WINDOW_PROPERTY, OnPropertyChanged, (void*) this);
+               free(pRoots);
+               SysTryReturnResult(NID_APP, pWindowPropertyChanged, E_SYSTEM, "A system error has been occurred.");
+       }
+
+       return r;
+}
+
+result
+_ActiveWindowManager::RemoveActiveAppEventListener(IActiveAppEventListener& listener)
+{
+       if (p_ecore_event_handler_del == null)
+       {
+               _LibraryImpl& lib = GetEcoreLibraryImpl();
+               p_ecore_event_handler_del = reinterpret_cast<void*(*)(Ecore_Event_Handler* event_handler)>(lib.GetProcAddress(L"ecore_event_handler_del"));
+               SysTryReturnResult(NID_APP, p_ecore_event_handler_del != null, E_SYSTEM,
+                               "A system error has been occurred. Failed to get p_ecore_event_handler_del.");
+       }
+
+       result r = __activeAppEventListenerList.Remove(&listener);
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       if (__activeAppEventListenerList.GetCount() == 0)
+       {
+               p_ecore_event_handler_del(pWindowPropertyChanged);
+               pWindowPropertyChanged = null;
+       }
+
+       return r;
+}
+
+
+void
+_ActiveWindowManager::FireActiveAppEvent(unsigned int xid, int pid, const char* pAppName)
+{
+       static int oldPid = 0;
+       if (oldPid != pid)
+       {
+               oldPid = pid;
+               char pkgname[255] = {0, };
+               if ((AUL_R_OK != aul_app_get_pkgname_bypid(pid, pkgname, 255)) || pkgname[0] == 0)
+               {
+                       SysSecureLog(NID_APP, "Failed to get the package name from pid=%x pAppName=%s", pid, pAppName ? pAppName : "null");
+                       return;
+               }
+               AppId appId(_Aul::GetRealAppId(String(pkgname)));
+
+               std::unique_ptr<IEnumeratorT<Tizen::App::IActiveAppEventListener* > > pEnum(__activeAppEventListenerList.GetEnumeratorN());
+               if (pEnum.get())
+               {
+                       while (pEnum->MoveNext() == E_SUCCESS)
+                       {
+                               Tizen::App::IActiveAppEventListener* pListener = null;
+                               pEnum->GetCurrent(pListener);
+                               if (pListener)
+                               {
+                                       pListener->OnActiveAppChanged(appId);
+                               }
+                       }
+               }
+       }
+}
+
+
+result
+_ActiveWindowManager::GetActiveApp(AppId& appId)
+{
+       const unsigned int windowId = GetActiveWindow();
+       const int processId = GetProcessId(windowId);
+       char pkgname[255] = {0, };
+       aul_app_get_pkgname_bypid(processId, pkgname, 255);
+
+       appId = _Aul::GetRealAppId(String(pkgname));
+
+       SysLog(NID_APP, "ActiveApp is %ls.", appId.GetPointer());
+       return E_SUCCESS;
+}
+
+_LibraryImpl&
+_ActiveWindowManager::GetEcoreXLibraryImpl(void)
+{
+       if (__pEcoreXLibrary == null)
+       {
+               __pEcoreXLibrary = new (std::nothrow) _LibraryImpl;
+               SysAssertf(__pEcoreXLibrary != null, "_LibraryImpl allocation failure.");
+
+               result r = __pEcoreXLibrary->Construct(OSP_ECORE_X_SONAME);
+               SysAssertf(r == E_SUCCESS, "Dynamic loading error : %s.", GetErrorMessage(r));
+       }
+       return *__pEcoreXLibrary;
+}
+
+_LibraryImpl&
+_ActiveWindowManager::GetEcoreLibraryImpl(void)
+{
+       if (__pEcoreLibrary == null)
+       {
+               __pEcoreLibrary = new (std::nothrow) _LibraryImpl;
+               SysAssertf(__pEcoreLibrary != null, "_LibraryImpl allocation failure.");
+
+               result r = __pEcoreLibrary->Construct(OSP_ECORE_SONAME);
+               SysAssertf(r == E_SUCCESS, "Dynamic loading error : %s.", GetErrorMessage(r));
+       }
+       return *__pEcoreLibrary;
+}
+
+_LibraryImpl&
+_ActiveWindowManager::GetX11LibraryImpl(void)
+{
+       if (__pX11Library == null)
+       {
+               __pX11Library = new (std::nothrow) _LibraryImpl;
+               SysAssertf(__pX11Library != null, "_LibraryImpl allocation failure.");
+
+               result r = __pX11Library->Construct(OSP_X11_SONAME);
+               SysAssertf(r == E_SUCCESS, "Dynamic loading error : %s.", GetErrorMessage(r));
+       }
+       return *__pX11Library;
+}
+
+unsigned int
+_ActiveWindowManager::GetActiveWindow(void)
+{
+       if (p_ecore_x_window_root_list == null)
+       {
+               _LibraryImpl& lib = GetEcoreXLibraryImpl();
+               p_ecore_x_window_root_list = reinterpret_cast<Ecore_X_Window*(*)(int* num_ret)>(lib.GetProcAddress(L"ecore_x_window_root_list"));
+               SysTryReturnResult(NID_APP, p_ecore_x_window_root_list != null, 0,
+                               "A system error has been occurred. Failed to get p_ecore_x_window_root_list.");
+       }
+       if (p_ecore_x_atom_get == null)
+       {
+               _LibraryImpl& lib = GetEcoreXLibraryImpl();
+               p_ecore_x_atom_get = reinterpret_cast<Ecore_X_Atom(*)(const char* name)>(lib.GetProcAddress(L"ecore_x_atom_get"));
+               SysTryReturnResult(NID_APP, p_ecore_x_atom_get != null, 0,
+                               "A system error has been occurred. Failed to get ecore_x_atom_get.");
+       }
+       if (p_ecore_x_window_prop_window_get == null)
+       {
+               _LibraryImpl& lib = GetEcoreXLibraryImpl();
+               p_ecore_x_window_prop_window_get = reinterpret_cast<int(*)(Ecore_X_Window win, Ecore_X_Atom atom, Ecore_X_Window* val, unsigned int len)>(lib.GetProcAddress(L"ecore_x_window_prop_window_get"));
+               SysTryReturnResult(NID_APP, p_ecore_x_window_prop_window_get != null, EINA_FALSE,
+                               "A system error has been occurred. Failed to get ecore_x_window_prop_window_get.");
+       }
+
+       int num = 0;
+       Ecore_X_Window* pRoots = p_ecore_x_window_root_list(&num);
+
+       Ecore_X_Window activeWin = 0;
+       if (pRoots)
+       {
+               Ecore_X_Atom activeAtom = p_ecore_x_atom_get("_NET_ACTIVE_WINDOW");
+               p_ecore_x_window_prop_window_get(pRoots[0], activeAtom, &activeWin, 1);
+               free(pRoots);
+       }
+
+       return activeWin;
+}
+
+int
+_ActiveWindowManager::GetProcessId(unsigned int window)
+{
+       if (p_ecore_x_netwm_pid_get == null)
+       {
+               _LibraryImpl& lib = GetEcoreXLibraryImpl();
+               p_ecore_x_netwm_pid_get = reinterpret_cast<Eina_Bool(*)(Ecore_X_Window win, int* pid)>(lib.GetProcAddress(L"ecore_x_netwm_pid_get"));
+               SysTryReturnResult(NID_APP, p_ecore_x_netwm_pid_get != null, EINA_FALSE,
+                               "A system error has been occurred. Failed to get ecore_x_netwm_pid_get.");
+       }
+
+       int pid = 0;
+       p_ecore_x_netwm_pid_get(window, &pid);
+
+       return pid;
+}
+
+}} // Tizen::App
diff --git a/src/app/FApp_ActiveWindowManager.h b/src/app/FApp_ActiveWindowManager.h
new file mode 100644 (file)
index 0000000..2dcf696
--- /dev/null
@@ -0,0 +1,100 @@
+//
+// Copyright (c) 2012 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       FApp_ActiveWindowManager.h
+ * @brief      This is the header file of the %_ActiveWindowManager class.
+ *
+ * This header file contains the declarations of the %_ActiveWindowManager class.
+ */
+
+#ifndef _FAPP_INTERNAL_ACTIVE_WINDOW_MANAGER_H_
+#define _FAPP_INTERNAL_ACTIVE_WINDOW_MANAGER_H_
+
+#include <FOspConfig.h>
+#include <FBaseColLinkedListT.h>
+
+#include <Ecore.h>
+
+
+namespace Tizen { namespace Base
+{
+       class String;
+       namespace Runtime
+       {
+               class _LibraryImpl;
+       }
+}}
+
+namespace Tizen { namespace App
+{
+
+class _IActiveAppEventListener;
+
+/**
+ * @class       _ActiveWindowManager
+ * @brief
+ */
+class _OSP_LOCAL_ _ActiveWindowManager
+{
+public:
+       _ActiveWindowManager(void);
+
+       ~_ActiveWindowManager(void);
+
+       result AddActiveAppEventListener(IActiveAppEventListener& listener);
+
+       result RemoveActiveAppEventListener(IActiveAppEventListener& listener);
+
+       result GetActiveApp(AppId& appId);
+
+private:
+       Tizen::Base::Runtime::_LibraryImpl& GetEcoreXLibraryImpl(void);
+
+       Tizen::Base::Runtime::_LibraryImpl& GetEcoreLibraryImpl(void);
+
+       Tizen::Base::Runtime::_LibraryImpl& GetX11LibraryImpl(void);
+
+       static Eina_Bool OnPropertyChanged(void* pData, int type, void* pEvent);
+
+       void FireActiveAppEvent(unsigned int xid, int pid, const char* pAppName);
+
+       unsigned int GetActiveWindow(void);
+
+       int GetProcessId(unsigned int window);
+
+       /**
+        * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
+        */
+       _ActiveWindowManager(const _ActiveWindowManager& rhs);
+
+       /**
+        * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
+        */
+       _ActiveWindowManager& operator=(const _ActiveWindowManager& rhs);
+
+private:
+       Tizen::Base::Runtime::_LibraryImpl* __pX11Library;
+       Tizen::Base::Runtime::_LibraryImpl* __pEcoreXLibrary;
+       Tizen::Base::Runtime::_LibraryImpl* __pEcoreLibrary;
+
+       Tizen::Base::Collection::LinkedListT<IActiveAppEventListener*> __activeAppEventListenerList;
+};
+
+}} // Tizen::App
+
+#endif //_FAPP_INTERNAL_ACTIVE_WINDOW_MANAGER_H_
+
index 9131b91..d5f6bc9 100755 (executable)
@@ -27,9 +27,6 @@
 #include <aul/aul.h>
 #include <bundle.h>
 #include <app_manager.h>
-#include <Ecore.h>
-#include <Ecore_X.h>
-#include <X11/Xlib.h>
 
 #include <FBaseInteger.h>
 #include <FBaseObject.h>
@@ -48,6 +45,7 @@
 #include <FBase_StringConverter.h>
 #include <FBaseRt_LibraryImpl.h>
 #include <FIo_DataControlResultSetImpl.h>
+#include <FSys_SystemInfoImpl.h>
 
 #include "FApp_AppControlRegistry.h"
 #include "FApp_AppImpl.h"
 #include "FAppPkg_PackageInfoImpl.h"
 #include "FApp_AppControlManager.h"
 #include "FApp_Aul.h"
-#include "FSys_SystemInfoImpl.h"
-
 #include "FApp_AppLifecycleEvent.h"
 #include "FApp_AppLifecycleEventArg.h"
 #include "FApp_IAppLifecycleEventListener.h"
+#include "FApp_ActiveWindowManager.h"
+
 using namespace Tizen::App::Package;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
@@ -85,35 +83,6 @@ namespace
 const long MAX_APPCONTROL_ARGUMENT = 1024;
 const long MAX_CONDITION_LENGTH = 400;
 
-// ActiveWindow related function and variable from shared library.
-// libecore_x.so.1
-static Ecore_X_Atom(* p_ecore_x_atom_get)(const char* name) = null;
-static int(* p_ecore_x_window_prop_window_get)(Ecore_X_Window win, Ecore_X_Atom atom, Ecore_X_Window* val, unsigned int len) = null;
-static Eina_Bool(* p_ecore_x_netwm_pid_get)(Ecore_X_Window win, int* pid) = null;
-static int(* p_ecore_x_netwm_name_get)(Ecore_X_Window win, char** name) = null;
-static Ecore_X_Window* (* p_ecore_x_window_root_list)(int* num_ret) = null;
-static int* p_ECORE_X_EVENT_WINDOW_PROPERTY = null;
-// libecore.so.1
-static Ecore_Event_Handler* (* p_ecore_event_handler_add)(int type, Ecore_Event_Handler_Cb func, const void* data) = null;
-static void* (* p_ecore_event_handler_del)(Ecore_Event_Handler* event_handler) = null;
-// libX11.so
-static int (* p_XSelectInput)(Display* display, Window w, long event_mask) = null;
-static Display* (* p_XOpenDisplay)(_Xconst char* display_name) = null;
-static int (* p_XCloseDisplay)(Display* display) = null;
-
-Ecore_Event_Handler* pWindowPropertyChanged = null;
-
-struct _DisplayDeleter
-{
-       void operator()(Display* pDisplay)
-       {
-               if (p_XOpenDisplay)
-               {
-                       p_XCloseDisplay(pDisplay);
-               }
-       }
-};
-
 int
 GetTotalSize(const Tizen::Base::Collection::ICollection& col)
 {
@@ -136,81 +105,6 @@ GetTotalSize(const Tizen::Base::Collection::ICollection& col)
        return size;
 }
 
-Eina_Bool
-OnPropertyChanged(void* pData, int type, void* pEvent)
-{
-       using namespace Tizen::App;
-
-       if (p_ecore_x_atom_get == null)
-       {
-               _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl();
-               p_ecore_x_atom_get = reinterpret_cast<Ecore_X_Atom(*)(const char* name)>(lib.GetProcAddress(L"ecore_x_atom_get"));
-               SysTryReturnResult(NID_APP, p_ecore_x_atom_get != null, EINA_FALSE,
-                                                  "A system error has been occurred. Failed to get ecore_x_atom_get.");
-       }
-       if (p_ecore_x_window_prop_window_get == null)
-       {
-               _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl();
-               p_ecore_x_window_prop_window_get = reinterpret_cast<int(*)(Ecore_X_Window win, Ecore_X_Atom atom, Ecore_X_Window* val, unsigned int len)>(lib.GetProcAddress(L"ecore_x_window_prop_window_get"));
-               SysTryReturnResult(NID_APP, p_ecore_x_window_prop_window_get != null, EINA_FALSE,
-                                                  "A system error has been occurred. Failed to get ecore_x_window_prop_window_get.");
-       }
-       if (p_ecore_x_netwm_pid_get == null)
-       {
-               _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl();
-               p_ecore_x_netwm_pid_get = reinterpret_cast<Eina_Bool(*)(Ecore_X_Window win, int* pid)>(lib.GetProcAddress(L"ecore_x_netwm_pid_get"));
-               SysTryReturnResult(NID_APP, p_ecore_x_netwm_pid_get != null, EINA_FALSE,
-                                                  "A system error has been occurred. Failed to get ecore_x_netwm_pid_get.");
-       }
-       if (p_ecore_x_netwm_name_get == null)
-       {
-               _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl();
-               p_ecore_x_netwm_name_get = reinterpret_cast<int(*)(Ecore_X_Window win, char** name)>(lib.GetProcAddress(L"ecore_x_netwm_name_get"));
-               SysTryReturnResult(NID_APP, p_ecore_x_netwm_name_get != null, EINA_FALSE,
-                                                  "A system error has been occurred. Failed to get ecore_x_netwm_name_get.");
-       }
-
-       if (!pData)
-       {
-               SysLog(NID_UI, "The data is not valid.");
-               return EINA_FALSE;
-       }
-       if (!pEvent)
-       {
-               SysLog(NID_UI, "The event is not valid.");
-               return EINA_FALSE;
-       }
-
-       Ecore_X_Event_Window_Property* pE = (Ecore_X_Event_Window_Property*) pEvent;
-       Ecore_X_Atom atom = pE->atom;
-       Ecore_X_Atom activeAtom = p_ecore_x_atom_get("_NET_ACTIVE_WINDOW");
-
-       if (atom != activeAtom)
-       {
-               return ECORE_CALLBACK_PASS_ON;
-       }
-
-       Ecore_X_Window win = pE->win;
-       Ecore_X_Window activeWin = 0;
-       p_ecore_x_window_prop_window_get(win, activeAtom, &activeWin, 1);
-
-       int pid = 0;
-       p_ecore_x_netwm_pid_get(activeWin, &pid);
-
-       char* pAppName = null;
-       p_ecore_x_netwm_name_get(activeWin, &pAppName);
-
-       Tizen::App::_AppManagerImpl* pAppManagerImpl = static_cast<Tizen::App::_AppManagerImpl*>(pData);
-       pAppManagerImpl->FireActiveAppEvent(activeWin, pid, pAppName);
-
-       if (pAppName)
-       {
-               free(pAppName);
-       }
-
-       return ECORE_CALLBACK_PASS_ON;
-}
-
 } // anonymous name-space
 
 
@@ -220,19 +114,13 @@ namespace Tizen { namespace App
 const wchar_t LEGACY_LAUNCH_REASON_NORMAL[] = L"LAUNCH_NORMAL";
 const wchar_t LEGACY_LAUNCH_REASON_CONDITIONAL[] = L"LAUNCH_CONDITIONAL";
 const wchar_t OSP_UI_SONAME[] = L"libosp-uifw.so.1";
-const wchar_t OSP_ECORE_X_SONAME[] = L"libecore_x.so.1";
-const wchar_t OSP_ECORE_SONAME[] = L"libecore.so.1";
-const wchar_t OSP_X11_SONAME[] = L"libX11.so.6";
 const int _MAX_PACKAGE_ID_LENGTH = 10;
 
-_LibraryImpl* _AppManagerImpl::__pEcoreLibrary = null;
-_LibraryImpl* _AppManagerImpl::__pEcoreXLibrary = null;
 
 _AppManagerImpl::_AppManagerImpl(void)
        : __pConditionManager(null)
-       , __eventListenerCount(0)
+       , __pActiveWindowManager(new (std::nothrow) _ActiveWindowManager)
        , __pUiLibrary(null)
-       , __pX11Library(null)
 {
        SysLog(NID_APP, "");
 }
@@ -241,30 +129,8 @@ _AppManagerImpl::~_AppManagerImpl(void)
 {
        SysLog(NID_APP, "");
 
-       if (__activeAppEventListenerList.GetCount() > 0)
-       {
-               if (p_ecore_event_handler_del == null)
-               {
-                       _LibraryImpl& lib = GetEcoreLibraryImpl();
-                       p_ecore_event_handler_del = reinterpret_cast<void*(*)(Ecore_Event_Handler* event_handler)>(lib.GetProcAddress(L"ecore_event_handler_del"));
-               }
-               if (p_ecore_event_handler_del)
-               {
-                       if (pWindowPropertyChanged)
-                       {
-                               p_ecore_event_handler_del(pWindowPropertyChanged);
-                               pWindowPropertyChanged = null;
-                       }
-               }
-       }
-
        delete __pConditionManager;
        delete __pUiLibrary;
-       delete __pX11Library;
-       delete __pEcoreXLibrary;
-       __pEcoreXLibrary = null;
-       delete __pEcoreLibrary;
-       __pEcoreLibrary = null;
 }
 
 
@@ -826,10 +692,10 @@ _AppManagerImpl::AddEventListener(_IAppManagerEventListener& listener)
        result r = __appManagerEvent.AddListener(listener);
        SysTryReturn(NID_APP, IsFailed(r) == false, r, r, "[%s]", GetErrorMessage(r));
 
-       __eventListenerCount++;
-       SysLog(NID_APP, "registered event listener(s) # %d", __eventListenerCount);
+       const int count = __appManagerEvent.GetListenerCount();
+       SysLog(NID_APP, "registered event listener(s) # %d", count);
 
-       if( __eventListenerCount > 1)
+       if (count > 1)
        {
                return E_SUCCESS;
        }
@@ -846,10 +712,10 @@ _AppManagerImpl::RemoveEventListener(_IAppManagerEventListener& listener)
        result r = __appManagerEvent.RemoveListener(listener);
        SysTryReturn(NID_APP, IsFailed(r) == false, r, r, "[%s]", GetErrorMessage(r));
 
-       __eventListenerCount--;
-       SysLog(NID_APP, "registered event listener(s) # %d", __eventListenerCount);
+       const int count = __appManagerEvent.GetListenerCount();
+       SysLog(NID_APP, "registered event listener(s) # %d", count);
 
-       if (__eventListenerCount == 0)
+       if (count == 0)
        {
                return pMgr->RemoveEventListener(-1);
        }
@@ -1020,245 +886,28 @@ _AppManagerImpl::GetUiLibraryImpl(void)
        return *__pUiLibrary;
 }
 
-_LibraryImpl&
-_AppManagerImpl::GetEcoreXLibraryImpl(void)
-{
-       if (__pEcoreXLibrary == null)
-       {
-               __pEcoreXLibrary = new (std::nothrow) _LibraryImpl;
-               SysAssertf(__pEcoreXLibrary != null, "_LibraryImpl allocation failure.");
-
-               result r = __pEcoreXLibrary->Construct(OSP_ECORE_X_SONAME);
-               SysAssertf(r == E_SUCCESS, "Dynamic loading error : %s.", GetErrorMessage(r));
-       }
-       return *__pEcoreXLibrary;
-}
-
-_LibraryImpl&
-_AppManagerImpl::GetEcoreLibraryImpl(void)
-{
-       if (__pEcoreLibrary == null)
-       {
-               __pEcoreLibrary = new (std::nothrow) _LibraryImpl;
-               SysAssertf(__pEcoreLibrary != null, "_LibraryImpl allocation failure.");
-
-               result r = __pEcoreLibrary->Construct(OSP_ECORE_SONAME);
-               SysAssertf(r == E_SUCCESS, "Dynamic loading error : %s.", GetErrorMessage(r));
-       }
-       return *__pEcoreLibrary;
-}
-
-_LibraryImpl&
-_AppManagerImpl::GetX11LibraryImpl(void)
-{
-       if (__pX11Library == null)
-       {
-               __pX11Library = new (std::nothrow) _LibraryImpl;
-               SysAssertf(__pX11Library != null, "_LibraryImpl allocation failure.");
-
-               result r = __pX11Library->Construct(OSP_X11_SONAME);
-               SysAssertf(r == E_SUCCESS, "Dynamic loading error : %s.", GetErrorMessage(r));
-       }
-       return *__pX11Library;
-}
-
-void
-_AppManagerImpl::FireActiveAppEvent(unsigned int xid, int pid, char* pAppName)
-{
-       static int oldPid = 0;
-       if (oldPid != pid)
-       {
-               oldPid = pid;
-               char pkgname[255] = {0, };
-               if ((AUL_R_OK != aul_app_get_pkgname_bypid(pid, pkgname, 255)) || pkgname[0] == 0)
-               {
-                       SysSecureLog(NID_APP, "Failed to get the package name from pid=%x pAppName=%s", pid, pAppName ? pAppName : "null");
-                       return;
-               }
-               AppId appId(_Aul::GetRealAppId(String(pkgname)));
-
-               std::unique_ptr<IEnumeratorT<Tizen::App::IActiveAppEventListener* > > pEnum(__activeAppEventListenerList.GetEnumeratorN());
-               if (pEnum.get())
-               {
-                       while (pEnum->MoveNext() == E_SUCCESS)
-                       {
-                               Tizen::App::IActiveAppEventListener* pListener = null;
-                               pEnum->GetCurrent(pListener);
-                               if (pListener)
-                               {
-                                       pListener->OnActiveAppChanged(appId);
-                               }
-                       }
-               }
-       }
-}
-
-unsigned int
-_AppManagerImpl::GetActiveWindow(void)
-{
-       if (p_ecore_x_window_root_list == null)
-       {
-               _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl();
-               p_ecore_x_window_root_list = reinterpret_cast<Ecore_X_Window*(*)(int* num_ret)>(lib.GetProcAddress(L"ecore_x_window_root_list"));
-               SysTryReturnResult(NID_APP, p_ecore_x_window_root_list != null, 0,
-                                                  "A system error has been occurred. Failed to get p_ecore_x_window_root_list.");
-       }
-       if (p_ecore_x_atom_get == null)
-       {
-               _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl();
-               p_ecore_x_atom_get = reinterpret_cast<Ecore_X_Atom(*)(const char* name)>(lib.GetProcAddress(L"ecore_x_atom_get"));
-               SysTryReturnResult(NID_APP, p_ecore_x_atom_get != null, 0,
-                                                  "A system error has been occurred. Failed to get ecore_x_atom_get.");
-       }
-       if (p_ecore_x_window_prop_window_get == null)
-       {
-               _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl();
-               p_ecore_x_window_prop_window_get = reinterpret_cast<int(*)(Ecore_X_Window win, Ecore_X_Atom atom, Ecore_X_Window* val, unsigned int len)>(lib.GetProcAddress(L"ecore_x_window_prop_window_get"));
-               SysTryReturnResult(NID_APP, p_ecore_x_window_prop_window_get != null, EINA_FALSE,
-                                                  "A system error has been occurred. Failed to get ecore_x_window_prop_window_get.");
-       }
-
-       int num = 0;
-       Ecore_X_Window* pRoots = p_ecore_x_window_root_list(&num);
-
-       Ecore_X_Window activeWin = 0;
-       if (pRoots)
-       {
-               Ecore_X_Atom activeAtom = p_ecore_x_atom_get("_NET_ACTIVE_WINDOW");
-               p_ecore_x_window_prop_window_get(pRoots[0], activeAtom, &activeWin, 1);
-               free(pRoots);
-       }
-
-       return activeWin;
-}
-
-int
-_AppManagerImpl::GetProcessId(unsigned int window)
-{
-       if (p_ecore_x_netwm_pid_get == null)
-       {
-               _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl();
-               p_ecore_x_netwm_pid_get = reinterpret_cast<Eina_Bool(*)(Ecore_X_Window win, int* pid)>(lib.GetProcAddress(L"ecore_x_netwm_pid_get"));
-               SysTryReturnResult(NID_APP, p_ecore_x_netwm_pid_get != null, EINA_FALSE,
-                                                  "A system error has been occurred. Failed to get ecore_x_netwm_pid_get.");
-       }
-
-       int pid = 0;
-       p_ecore_x_netwm_pid_get(window, &pid);
-
-       return pid;
-}
 
 result
 _AppManagerImpl::AddActiveAppEventListener(IActiveAppEventListener& listener)
 {
-       if (p_ecore_x_window_root_list == null)
-       {
-               _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl();
-               p_ecore_x_window_root_list = reinterpret_cast<Ecore_X_Window*(*)(int* num_ret)>(lib.GetProcAddress(L"ecore_x_window_root_list"));
-               SysTryReturnResult(NID_APP, p_ecore_x_window_root_list != null, E_SYSTEM,
-                                                  "A system error has been occurred. Failed to get p_ecore_x_window_root_list.");
-       }
-       if (p_ECORE_X_EVENT_WINDOW_PROPERTY == null)
-       {
-               _LibraryImpl& lib = _AppManagerImpl::GetEcoreXLibraryImpl();
-               p_ECORE_X_EVENT_WINDOW_PROPERTY = reinterpret_cast<int*>(lib.GetProcAddress(L"ECORE_X_EVENT_WINDOW_PROPERTY"));
-               SysTryReturnResult(NID_APP, p_ECORE_X_EVENT_WINDOW_PROPERTY != null, E_SYSTEM,
-                                                  "A system error has been occurred. Failed to get p_ECORE_X_EVENT_WINDOW_PROPERTY.");
-       }
-       if (p_XOpenDisplay == null)
-       {
-               _LibraryImpl& lib = GetX11LibraryImpl();
-               p_XOpenDisplay = reinterpret_cast<Display*(*)(_Xconst char* display_name)>(lib.GetProcAddress(L"XOpenDisplay"));
-               SysTryReturnResult(NID_APP, p_XOpenDisplay != null, E_SYSTEM,
-                                                  "A system error has been occurred. Failed to get p_XOpenDisplay.");
-       }
-       if (p_XCloseDisplay == null)
-       {
-               _LibraryImpl& lib = GetX11LibraryImpl();
-               p_XCloseDisplay = reinterpret_cast<int(*)(Display* display)>(lib.GetProcAddress(L"XCloseDisplay"));
-               SysTryReturnResult(NID_APP, p_XCloseDisplay != null, E_SYSTEM,
-                                                  "A system error has been occurred. Failed to get p_XCloseDisplay.");
-       }
-       if (p_XSelectInput == null)
-       {
-               _LibraryImpl& lib = GetX11LibraryImpl();
-               p_XSelectInput = reinterpret_cast<int(*)(Display* display, Window w, long event_mask)>(lib.GetProcAddress(L"XSelectInput"));
-               SysTryReturnResult(NID_APP, p_XSelectInput != null, E_SYSTEM,
-                                                  "A system error has been occurred. Failed to get p_XSelectInput.");
-       }
-       if (p_ecore_event_handler_add == null)
-       {
-               _LibraryImpl& lib = GetEcoreLibraryImpl();
-               p_ecore_event_handler_add = reinterpret_cast<Ecore_Event_Handler*(*)(int type, Ecore_Event_Handler_Cb func, const void* data)>(lib.GetProcAddress(L"ecore_event_handler_add"));
-               SysTryReturnResult(NID_APP, p_ecore_event_handler_add != null, E_SYSTEM,
-                                                  "A system error has been occurred. Failed to get p_ecore_event_handler_add.");
-       }
-
-       bool alreadyExist = __activeAppEventListenerList.Contains(&listener);
-       SysTryReturnResult(NID_APP, !alreadyExist, E_OBJ_ALREADY_EXIST, "The event listener already exist.");
-       result r = __activeAppEventListenerList.Add(&listener);
-       SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       if (!pWindowPropertyChanged)
-       {
-               std::unique_ptr<Display, _DisplayDeleter> pDisplay(p_XOpenDisplay(NULL));
-               SysTryReturnResult(NID_APP, pDisplay != null, E_SYSTEM, "A system error has been occurred. Failed to XOpenDisplay.");
-
-               int num = 0;
-               Ecore_X_Window* pRoots = p_ecore_x_window_root_list(&num);
-               SysTryReturnResult(NID_APP, pRoots != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
-
-               for (int i = 0; i < num; i++)
-               {
-                       p_XSelectInput(pDisplay.get(), pRoots[i], PropertyChangeMask);
-               }
-
-               pWindowPropertyChanged = p_ecore_event_handler_add(*p_ECORE_X_EVENT_WINDOW_PROPERTY, OnPropertyChanged, (void*) this);
-               free(pRoots);
-               SysTryReturnResult(NID_APP, pWindowPropertyChanged, E_SYSTEM, "A system error has been occurred.");
-       }
-
-       return r;
+       return __pActiveWindowManager->AddActiveAppEventListener(listener);
 }
 
+
 result
 _AppManagerImpl::RemoveActiveAppEventListener(IActiveAppEventListener& listener)
 {
-       if (p_ecore_event_handler_del == null)
-       {
-               _LibraryImpl& lib = GetEcoreLibraryImpl();
-               p_ecore_event_handler_del = reinterpret_cast<void*(*)(Ecore_Event_Handler* event_handler)>(lib.GetProcAddress(L"ecore_event_handler_del"));
-               SysTryReturnResult(NID_APP, p_ecore_event_handler_del != null, E_SYSTEM,
-                                                  "A system error has been occurred. Failed to get p_ecore_event_handler_del.");
-       }
-
-       result r = __activeAppEventListenerList.Remove(&listener);
-       SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       if (__activeAppEventListenerList.GetCount() == 0)
-       {
-               p_ecore_event_handler_del(pWindowPropertyChanged);
-               pWindowPropertyChanged = null;
-       }
-
-       return r;
+       return __pActiveWindowManager->RemoveActiveAppEventListener(listener);
 }
 
+
 result
 _AppManagerImpl::GetActiveApp(AppId& appId)
 {
-       const unsigned int windowId = GetActiveWindow();
-       const int processId = GetProcessId(windowId);
-       char pkgname[255] = {0, };
-       aul_app_get_pkgname_bypid(processId, pkgname, 255);
-       
-       appId = _Aul::GetRealAppId(String(pkgname));
-
-       SysLog(NID_APP, "ActiveApp is %ls.", appId.GetPointer());
-       return E_SUCCESS;
+       return __pActiveWindowManager->GetActiveApp(appId);
 }
 
+
 bool 
 _AppManagerImpl::IsUserPreferredAppForAppControlResolution(const AppId& appId) const
 {
@@ -1345,7 +994,7 @@ _AppManagerImpl::UnregisterAppForAppLifecycleEvent(const AppId& appId)
                if (currentRefCnt < 0)
                {
                        r = __appListForAppLifecycle.Remove(appId);
-                       
+
                        _IAppManager* pMgr = _AppManagerProxy::GetService();
                        SysTryReturnResult(NID_APP, pMgr, E_SYSTEM, "_AppManagerProxy::GetService() is failed.");
 
index fefdcda..524d637 100755 (executable)
 #ifndef _FAPP_INTERNAL_APP_MANAGER_IMPL_H_
 #define _FAPP_INTERNAL_APP_MANAGER_IMPL_H_
 
-#include <appfw/app_context.h>
+#include <unique_ptr.h>
 
 #include <FOspConfig.h>
 #include <FBaseObject.h>
 #include <FBaseString.h>
-#include <FBaseColIListT.h>
 #include <FBaseColIList.h>
 #include <FBaseColLinkedListT.h>
 #include <FBaseColHashMapT.h>
@@ -65,6 +64,7 @@ class _IAppManagerEventListener;
 class _IAppEventListener;
 class _AppManagerEventArg;
 class _IAppLifecycleEventListener;
+class _ActiveWindowManager;
 
 
 class _AppLifecycleManager
@@ -366,24 +366,14 @@ public:
 
        virtual result OnAppLifecycleEventReceived(int clientId, const AppId& appId, _AppLifecycleEventType appLifecycleEventType);
 
-       static void SetAppManagerService(_IAppManager* pAppManager );
-
        _OSP_LOCAL_ Tizen::Base::Runtime::_LibraryImpl& GetUiLibraryImpl(void);
 
-       static Tizen::Base::Runtime::_LibraryImpl& GetEcoreXLibraryImpl(void);
-
-       static Tizen::Base::Runtime::_LibraryImpl& GetEcoreLibraryImpl(void);
-
-       Tizen::Base::Runtime::_LibraryImpl& GetX11LibraryImpl(void);
-
        result AddActiveAppEventListener(IActiveAppEventListener& listener);
 
        result RemoveActiveAppEventListener(IActiveAppEventListener& listener);
 
        result GetActiveApp(AppId& appId);
 
-       void FireActiveAppEvent(unsigned int xid, int pid, char* pAppName);
-
        bool IsUserPreferredAppForAppControlResolution(const AppId& appId) const;
 
        result ClearUserPreferenceForAppControlResolution(const AppId& appId);
@@ -409,22 +399,12 @@ private:
 
        _OSP_LOCAL_ _ConditionManagerProxy* GetConditionManagerProxy(void);
 
-       unsigned int GetActiveWindow(void);
-
-       int GetProcessId(unsigned int window);
-
-       static void AppEventCallback(app_context_h app_context, app_context_event_e event, void* pData);
-
 private:
        _ConditionManagerProxy* __pConditionManager;
-       int     __eventListenerCount;
+       std::unique_ptr<_ActiveWindowManager> __pActiveWindowManager;
        Tizen::Base::Runtime::_LibraryImpl* __pUiLibrary;
-       Tizen::Base::Runtime::_LibraryImpl* __pX11Library;
-       static Tizen::Base::Runtime::_LibraryImpl* __pEcoreXLibrary;
-       static Tizen::Base::Runtime::_LibraryImpl* __pEcoreLibrary;
        _AppLifecycleManager __lifeManager;
        _AppManagerEvent __appManagerEvent;
-       Tizen::Base::Collection::LinkedListT<IActiveAppEventListener*> __activeAppEventListenerList;
        Tizen::App::_AppLifecycleEvent __appLifecycleEvent;
        Tizen::Base::Collection::HashMapT<Tizen::Base::String, int> __appListForAppLifecycle;
        Tizen::Base::ComparerT<Tizen::Base::String>     __comparer;
@@ -437,7 +417,6 @@ private:
        friend class _MapDataControlImpl;
        friend class _DataControlProviderManagerImpl;
        friend class _AppControlProviderManagerImpl;
-       friend class _ActiveWindowEventListener;
        friend class Tizen::Io::_DataControlResultSetImpl;
 }; // _AppManagerImpl