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);
_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;
// 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);
{
public:
virtual void OnApplicationTerminated(const _AppContext& appInfo) = 0;
+ virtual void OnApplicationTerminated(const AppId& appId) = 0;
+ virtual void OnApplicationLaunched(const AppId& appId) = 0;
};
/**
*/
#include <FBaseSysLog.h>
+#include <FBaseColIListT.h>
#include <FApp_AppInfo.h>
#include <FApp_Aul.h>
#include <FApp_AppManagerEventArg.h>
using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
using namespace Tizen::Io;
using namespace Tizen::Text;
__pContextMgr->SetEventListener(*this);
__pStub = pStub;
__eventListeners.Construct();
+
+ __appListForAppLifecycleEvent.Construct(0, 0, __strHashCodeProvider, __comparer);
SysLog(NID_APP, "Exit\n");
return E_SUCCESS;
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 {
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
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()
}
}
+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 {
_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);