fix code cleanup with file property change
[platform/framework/native/appfw.git] / src / app / FApp_AppControlManager.cpp
old mode 100755 (executable)
new mode 100644 (file)
index a109998..3d48a30
@@ -102,6 +102,7 @@ _AppControlManager::_AppControlManager(void)
        // AppControl event handling is expected to be performed in the main thread.
        __appControlEvent.Construct();
        __appControlEvent.AddListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
+       __listenerList.Construct();
 }
 
 _AppControlManager::~_AppControlManager(void)
@@ -152,8 +153,12 @@ _AppControlManager::OnAppControlEventReceivedN(int reqId, _AppArg* pAppArg, int
                if (pInfo->magic == LAUNCH_INFO_MAGIC)
                {
                        SysLog(NID_APP, "Invoking callback 0x%x", pInfo->launchCb);
+                       //pAppArg->Print();
 
-                       (*pInfo->launchCb)(pInfo->pUserData, pInfo->pArg, pAppArg, static_cast<service_result_e>(res), pInfo->property);
+                       if (pInfo->pUserData && (!__listenerList.Contains(pInfo->pUserData)))
+                       {
+                               (*pInfo->launchCb)(pInfo->pUserData, pInfo->pArg, pAppArg, static_cast<service_result_e>(res), pInfo->property);
+                       }
                }
                else
                {
@@ -248,8 +253,9 @@ _AppControlManager::OnAppControlEventReceivedN(int reqId, int res, const IMap* p
                else
                {
                        IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
-                       if (pListener)
+                       if (pListener && (!__listenerList.Contains(pInfo->pListener)))
                        {
+                               SysLog(NID_APP, "OSP_AC OnAppControlCompleteResponseReceived");
                                pListener->OnAppControlCompleteResponseReceived(aId, oId, static_cast<AppCtrlResult>(res), pArgs);
                        }
                        else
@@ -353,15 +359,31 @@ _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const
                appsvc_set_uri(kb, uri);
        }
 
-       const long handle = _AppImpl::GetInstance()->GetWindowHandle();
-       _AppArg::UpdateWindowHandle(kb, handle);
+       if (_AppImpl::GetInstance() != null)
+       {
+               const long handle = _AppImpl::GetInstance()->GetWindowHandle();
+               _AppArg::UpdateWindowHandle(kb, handle);
+       }
 
        SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
        int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
 
-       SysTryReturnResult(NID_APP, pid >= 0, E_SYSTEM, "Launching service %s failure with %d", pkg_name, pid);
+       result r = E_SUCCESS;
+       if (pid < 0)
+       {
+               switch (pid)
+               {
+               case APPSVC_RET_EILLACC:
+                       r = E_ILLEGAL_ACCESS;
+                       break;
+               default:
+                       r = E_SYSTEM;
+                       break;
+               }
+               SysLog(NID_APP, "[%s]Launching service %s failure", GetErrorMessage(r), pkg_name);
+       }
 
-       return E_SUCCESS;
+       return r;
 }
 int
 _AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
@@ -386,13 +408,30 @@ _AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const cha
                appsvc_set_uri(kb, uri);
        }
 
-       const long handle = _AppImpl::GetInstance()->GetWindowHandle();
-       _AppArg::UpdateWindowHandle(kb, handle);
+       if (_AppImpl::GetInstance() != null)
+       {
+               const long handle = _AppImpl::GetInstance()->GetWindowHandle();
+               _AppArg::UpdateWindowHandle(kb, handle);
+       }
 
        SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
        int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
 
-       SysTryReturn(NID_APP, pid >= 0, -1, E_SYSTEM, "Launching service %s failure with %d", pkg_name, pid);
+       result r = E_SUCCESS;
+       if (pid < 0)
+       {
+               switch (pid)
+               {
+               case APPSVC_RET_EILLACC:
+                       r = E_ILLEGAL_ACCESS;
+                       break;
+               default:
+                       r = E_SYSTEM;
+                       break;
+               }
+               SysLog(NID_APP, "[%s]Launching service %s failure", GetErrorMessage(r), pkg_name);
+       }
+       SetLastResult(r);
 
        return pid;
 }
@@ -407,18 +446,16 @@ _AppControlManager::LaunchPkg(const char* pkg_name, const char* op, const char*
 }
 
 result
-_AppControlManager::LaunchAppWithCondition(const AppId& appId, const String& executableName, const String& condition, IList* pArrayArgs)
+_AppControlManager::LaunchAppWithCondition(const AppId& appId, const String& condition, IList* pArrayArgs)
 {
        result r = E_SUCCESS;
-       const String& actualAppId = appId + L'.' + executableName;
        _AppArg * pArg = new (std::nothrow) _AppArg();
        SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
 
        r = pArg->ConstructForAppLaunchCondition(condition, pArrayArgs);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] ConstructForAppLaunchCondition(%ls, .. ) fails", GetErrorMessage(r), condition.GetPointer());
 
-       r = _AppControlManager::LaunchApp(actualAppId, pArg);
-
+       r = _AppControlManager::LaunchApp(appId, pArg);
 CATCH:
        delete pArg;
        return r;
@@ -444,8 +481,11 @@ _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
 
        pArg->UpdateRequestId(req);
 
-       const long handle = _AppImpl::GetInstance()->GetWindowHandle();
-       pArg->UpdateWindowHandle(handle);
+       if (_AppImpl::GetInstance() != null)
+       {
+               const long handle = _AppImpl::GetInstance()->GetWindowHandle();
+               pArg->UpdateWindowHandle(handle);
+       }
 
        int pid = -1;
        bundle* kb = NULL;
@@ -486,9 +526,20 @@ _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
        }
        while (count < TRY_COUNT);
 
-       SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Launching service failure for %ls with %d", appId.GetPointer(), pid);
+       result r = E_SUCCESS;
+       switch (pid)
+       {
+       case APPSVC_RET_EILLACC:
+               r = E_ILLEGAL_ACCESS;
+               break;
+       default:
+               r = E_SYSTEM;
+               break;
+       }
+
+       SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
 
-       return E_SYSTEM;
+       return r;
 }
 
 int
@@ -511,8 +562,11 @@ _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
 
        pArg->UpdateRequestId(req);
 
-       const long handle = _AppImpl::GetInstance()->GetWindowHandle();
-       pArg->UpdateWindowHandle(handle);
+       if (_AppImpl::GetInstance() != null)
+       {
+               const long handle = _AppImpl::GetInstance()->GetWindowHandle();
+               pArg->UpdateWindowHandle(handle);
+       }
 
        int pid = -1;
        bundle* kb = NULL;
@@ -553,7 +607,20 @@ _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
        }
        while (count < TRY_COUNT);
 
-       SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Launching service failure for %ls with %d", appId.GetPointer(), pid);
+       result r = E_SUCCESS;
+       switch (pid)
+       {
+       case APPSVC_RET_EILLACC:
+               r = E_ILLEGAL_ACCESS;
+               break;
+       default:
+               r = E_SYSTEM;
+               break;
+       }
+
+       SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
+
+       SetLastResult(r);
 
        return pid;
 }
@@ -573,21 +640,41 @@ _AppControlManager::LaunchAppImplicit(_AppArg* pArg, int req)
        }
 
        int pid = appsvc_run_service(kb, req, LaunchResultCb, this);
-       switch (pid)
+       if (pid > 0)
        {
-       case APPSVC_RET_EINVAL:
-               r = E_OBJ_NOT_FOUND;
-               break;
-       case APPSVC_RET_ENOMATCH:
-               r = E_OBJ_NOT_FOUND;
-               break;
-       case APPSVC_RET_ERROR:
-               // fall through
-       case APPSVC_RET_ELAUNCH:
-               r = E_SYSTEM;
-               break;
-       default:
-               break;
+               char pkgname[255] = {0, };
+               aul_app_get_pkgname_bypid(pid, pkgname, 255);
+
+               if (strncmp(pkgname, APP_SELECTOR, strlen(APP_SELECTOR)) != 0)
+               {
+                       const char* pOperation = appsvc_get_operation(kb);
+
+                       SysLog(NID_APP, "Starting application without selector : (%s, %s).", pkgname, pOperation);
+
+                       SendAppControlStartResponse(req, pkgname, pOperation);
+               }
+       }
+       else
+       {
+               switch (pid)
+               {
+                       case APPSVC_RET_EINVAL:
+                               r = E_OBJ_NOT_FOUND;
+                               break;
+                       case APPSVC_RET_ENOMATCH:
+                               r = E_OBJ_NOT_FOUND;
+                               break;
+                       case APPSVC_RET_EILLACC:
+                               r = E_ILLEGAL_ACCESS;
+                               break;
+                       case APPSVC_RET_ERROR:
+                               // fall through
+                       case APPSVC_RET_ELAUNCH:
+                               // fall through
+                       default:
+                               r = E_SYSTEM;
+                               break;
+               }
        }
 
        SysLog(NID_APP, "[%s] Application(%d) launched with reqId(%d) and arg(0x%x).", GetErrorMessage(r), pid, req, pArg);
@@ -629,6 +716,11 @@ _AppControlManager::RemoveLaunchRequest(int req)
 {
        __launchManager.RemoveItem(req);
 }
+int
+_AppControlManager::GetLaunchRequestCount(void)
+{
+       return __launchManager.GetCount();
+}
 
 result
 _AppControlManager::RegisterRequest(service_s* service, int& req, _AppHandler& handler)