Update for AppLifecycleEvent
authorJaesung Ku <jaesung.ku@samsung.com>
Wed, 10 Jul 2013 12:27:43 +0000 (21:27 +0900)
committerJaesung Ku <jaesung.ku@samsung.com>
Thu, 11 Jul 2013 01:46:59 +0000 (10:46 +0900)
Change-Id: I6e7845252f92ea519e837ebb2648f14bf7afd48a
Signed-off-by: Jaesung Ku <jaesung.ku@samsung.com>
inc/FApp_AppManagerService.h
inc/FApp_AppManagerStub.h
inc/FApp_ContextManager.h
src/FApp_AppManagerService.cpp
src/FApp_AppManagerStub.cpp
src/FApp_ContextManager.cpp

index d4d20df..0682762 100755 (executable)
@@ -68,9 +68,13 @@ public:
        virtual result AddEventListener(int clientId);
        virtual result RemoveEventListener(int clientId);
        virtual void OnApplicationTerminated(const _AppContext& appInfo);
+       virtual void OnApplicationLaunched(const AppId& appId);
+       virtual void OnApplicationTerminated(const AppId& appId);       
 
        virtual bool IsUserPreferredAppForAppControlResolution(const AppId& appId);
        virtual result ClearUserPreferenceForAppControlResolution(const AppId& appId);
+       virtual result RegisterAppForAppLifecycleEvent(const AppId& appId, int clientId);
+       virtual result UnregisterAppForAppLifecycleEvent(const AppId& appId, int clientId);
 
 private:
        result SendEventToAllListeners(const _AppManagerEventArg& arg);
@@ -84,6 +88,9 @@ private:
        _IAppManagerServiceEventListener*       __pStub;
        _IAppManagerServiceEventListener*       __pProxy;
 
+       Tizen::Base::Collection::MultiHashMapT<AppId, int> __appListForAppLifecycleEvent;
+       Tizen::Base::ComparerT<Tizen::Base::String>     __comparer;
+       Tizen::Base::StringHashCodeProvider     __strHashCodeProvider;
        void Dump(void);
 
 friend class UTs_AppManagerServiceP;
index 1731386..bf5b393 100755 (executable)
@@ -81,10 +81,14 @@ public:
        // to client
        virtual result OnServiceEventReceived(int clientId, const _AppManagerEventArg& arg);
        virtual result OnTerminateApplicationRequested(int clientId);
+       virtual result OnAppLifecycleEventReceived(int clientId, const AppId& appId, _AppLifecycleEventType appLifecycleEventType);
 
        bool OnIsUserPreferredAppForAppControlResolution(const AppId& appId, bool *pRes, result *pResException);
        bool OnClearUserPreferenceForAppControlResolution(const AppId& appId, result *pRes);
 
+       bool OnRegisterAppForAppLifecycleEvent(const AppId& appId, result *pRes);
+       bool OnUnregisterAppForAppLifecycleEvent(const AppId& appId, result *pRes);
+
 private:
        result StartIpcServer(void);
        _AppManagerStub(const _AppManagerStub& value);
index 4460914..ce492c1 100755 (executable)
@@ -90,6 +90,8 @@ class _IContextManagerEventListener
 {
 public:
        virtual void OnApplicationTerminated(const _AppContext& appInfo) = 0;
+       virtual void OnApplicationTerminated(const AppId& appId) = 0;
+       virtual void OnApplicationLaunched(const AppId& appId) = 0;
 };
 
 /**
index 340be15..efc29df 100755 (executable)
@@ -20,6 +20,7 @@
  */
 
 #include <FBaseSysLog.h>
+#include <FBaseColIListT.h>
 #include <FApp_AppInfo.h>
 #include <FApp_Aul.h>
 #include <FApp_AppManagerEventArg.h>
@@ -32,6 +33,7 @@
 
 
 using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
 using namespace Tizen::Io;
 using namespace Tizen::Text;
 
@@ -62,6 +64,8 @@ _AppManagerService::Construct(_ContextManager *pContextMgr, _IAppManagerServiceE
        __pContextMgr->SetEventListener(*this);
        __pStub = pStub;
        __eventListeners.Construct();
+
+       __appListForAppLifecycleEvent.Construct(0, 0, __strHashCodeProvider, __comparer);
        SysLog(NID_APP, "Exit\n");
 
        return E_SUCCESS;
@@ -225,4 +229,60 @@ _AppManagerService::ClearUserPreferenceForAppControlResolution(const AppId& appI
        return _AulServer::ClearUserPreferenceForAppControlResolution(appId);
 }
 
+result
+_AppManagerService::RegisterAppForAppLifecycleEvent(const AppId& appId, int clientId)
+{
+       AppId* pAppId = new (std::nothrow) Tizen::App::AppId(appId);
+       SysTryReturnResult(NID_APP, pAppId != null, E_OUT_OF_MEMORY, "pAppId is null.");
+               
+       return __appListForAppLifecycleEvent.Add(*pAppId, clientId);
+}
+
+result
+_AppManagerService::UnregisterAppForAppLifecycleEvent(const AppId& appId, int clientId)
+{
+       return __appListForAppLifecycleEvent.Remove(appId, clientId);
+}
+
+void
+_AppManagerService::OnApplicationLaunched(const AppId& appId)
+{
+       IEnumeratorT<int>* pEnum = __appListForAppLifecycleEvent.GetValuesN(appId);
+
+       if (pEnum)
+       {
+               int clientId = 0;
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       result r = pEnum->GetCurrent(clientId);
+                       if (r == E_SUCCESS && clientId > -1)
+                       {
+                               __pStub->OnAppLifecycleEventReceived(clientId, appId, _APP_LIFECYCLE_EVENT_LAUNCH);
+                       }                       
+               }
+               delete pEnum;
+       }
+}
+
+void
+_AppManagerService::OnApplicationTerminated(const AppId& appId)
+{
+       IEnumeratorT<int>* pEnum = __appListForAppLifecycleEvent.GetValuesN(appId);
+
+       if (pEnum)
+       {
+               int clientId = 0;
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       result r = pEnum->GetCurrent(clientId);
+                       if (r == E_SUCCESS && clientId > -1)
+                       {
+                               __pStub->OnAppLifecycleEventReceived(clientId, appId, _APP_LIFECYCLE_EVENT_TERMINATE);
+                       }                       
+               }
+               delete pEnum;
+       }
+
+}
+
 }}//namespace Tizen { namespace App {
index 9300a12..f1d0ce7 100755 (executable)
@@ -129,6 +129,32 @@ _AppManagerStub::OnTerminateApplicationRequested(int clientId)
        return E_SUCCESS;
 }
 
+result
+_AppManagerStub::OnAppLifecycleEventReceived(int clientId, const AppId& appId, _AppLifecycleEventType appLifecycleEventType)
+{
+       SysTryReturnResult(NID_APP, __pIpcServer != null, E_INVALID_STATE, "__pIpcServer is null.");
+
+       _AppLifecycleEventType eventType;
+
+       if (appLifecycleEventType == 0)
+       {
+               eventType = _APP_LIFECYCLE_EVENT_LAUNCH;
+       }
+       else if (appLifecycleEventType == 1)
+       {
+               eventType = _APP_LIFECYCLE_EVENT_TERMINATE;
+       }
+       else
+       {
+               SysLog(NID_APP, "Not expected appLifecycleEventType(%d)", appLifecycleEventType);
+       }
+
+       result r = __pIpcServer->SendResponse(clientId, new AppManager_OnAppLifecycleEventReceived(appId, eventType));
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
+
+       return E_SUCCESS;
+
+}
 
 /////////////////////////////////////////////
 // handlers
@@ -251,6 +277,8 @@ _AppManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& me
                IPC_MESSAGE_HANDLER_EX(AppManager_RemoveEventListener, &server, OnRemoveEventListener)
                IPC_MESSAGE_HANDLER_EX(AppManager_IsUserPreferredAppForAppControlResolution, &server, OnIsUserPreferredAppForAppControlResolution)
                IPC_MESSAGE_HANDLER_EX(AppManager_ClearUserPreferenceForAppControlResolution, &server, OnClearUserPreferenceForAppControlResolution)
+               IPC_MESSAGE_HANDLER_EX(AppManager_RegisterAppForAppLifecycleEvent, &server, OnRegisterAppForAppLifecycleEvent)
+               IPC_MESSAGE_HANDLER_EX(AppManager_UnregisterAppForAppLifecycleEvent, &server, OnUnregisterAppForAppLifecycleEvent)
        IPC_END_MESSAGE_MAP()
 }
 
@@ -323,4 +351,41 @@ CATCH:
 
 }
 
+bool
+_AppManagerStub::OnRegisterAppForAppLifecycleEvent(const AppId& appId, result *pRes)
+{
+       SysTryReturn(NID_APP, __pAppManagerService != null, false,*pRes = E_SYSTEM, "__pAppManagerService is null!");
+       SysLog(NID_APP, "app(%ls)", appId.GetPointer());
+/*
+       *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientPackageId(), _PRV_APP_LIFECYCLE_EVENT);
+
+       if (IsFailed(*pRes))
+       {
+               SysLog(NID_APP, "[E_PRIVILEGE_DENIED]The application(%ls) does not have the privilege to call this method.", appId.GetPointer());
+               *pRes = E_PRIVILEGE_DENIED;
+               return true;    
+       }
+*/
+       *pRes = __pAppManagerService->RegisterAppForAppLifecycleEvent(appId, __pIpcServer->GetClientId());
+}
+
+bool
+_AppManagerStub::OnUnregisterAppForAppLifecycleEvent(const AppId& appId, result *pRes)
+{
+       SysTryReturn(NID_APP, __pAppManagerService != null, false,*pRes = E_SYSTEM, "__pAppManagerService is null!");
+       SysLog(NID_APP, "app(%ls)", appId.GetPointer());
+/*
+       *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientPackageId(), _PRV_APP_LIFECYCLE_EVENT);
+
+       if (IsFailed(*pRes))
+       {
+               SysLog(NID_APP, "[E_PRIVILEGE_DENIED]The application(%ls) does not have the privilege to call this method.", appId.GetPointer());
+               *pRes = E_PRIVILEGE_DENIED;
+               return true;    
+       }
+*/
+       *pRes = __pAppManagerService->UnregisterAppForAppLifecycleEvent(appId, __pIpcServer->GetClientId());
+
+}
+
 }}//namespace Tizen { namespace App {
index 6770242..706d1c2 100755 (executable)
@@ -465,11 +465,13 @@ void
 _ContextManager::OnApplicationLaunched(const AppId& appId, int pid)
 {
        SysLog(NID_APP, "LaunchedApp(%ls)", appId.GetPointer());
+       __pEventListener->OnApplicationLaunched(appId);
 }
 void
 _ContextManager::OnApplicationTerminated(const AppId& appId, int pid)
 {
        SysLog(NID_APP, "TerminatedApp(%ls)", appId.GetPointer());
+       __pEventListener->OnApplicationTerminated(appId);
 
        _AppContext* pAppContext = __appContexts[pid];
        SysTryReturnVoidResult(NID_APP, pAppContext != null, E_INVALID_STATE, "Not registered pid(%d)", pid);