Revert "Fix intApp TC failure"
[platform/framework/native/appfw.git] / src / app / FApp_AppControlManager.cpp
index 0d15ee1..40a69e6 100644 (file)
@@ -43,6 +43,7 @@
 #include <FAppSqlDataControl.h>
 #include <FAppMapDataControl.h>
 #include <FAppPkgPackageInfo.h>
+#include <FAppPkgPackageAppInfo.h>
 #include <FBaseSysLog.h>
 
 #include <FBase_StringConverter.h>
@@ -143,6 +144,30 @@ _AppControlManager::GetMimeFromExt(const String& ext, String& out)
        return E_SUCCESS;
 }
 
+
+String
+_AppControlManager::GetMimeTypeFromDataType(const String& data)
+{
+       // Data type is either MIME type or .[extension]
+
+       if (data.IsEmpty() || data[0] != L'.')
+       {
+               return data;
+       }
+
+       // .[extension]
+       String ext;
+       data.SubString(1, ext);
+
+       String res;
+       result r = _AppControlManager::GetMimeFromExt(ext, res);
+       SysTryReturn(NID_APP, !IsFailed(r), L"", r, "[%s] MIME type conversion failed for %ls.", GetErrorMessage(r), ext.GetPointer());
+
+       SysLog(NID_APP, "Conversion from %ls into %ls.", data.GetPointer(), res.GetPointer());
+       return res;
+}
+
+
 void
 _AppControlManager::OnAppControlEventReceivedN(int reqId, _AppArg* pAppArg, int res)
 {
@@ -283,8 +308,8 @@ _AppControlManager::OnAppControlPluginEventReceivedN(int reqId, int res, const A
 
                if (optAppId.IsEmpty())
                {
-                       String aId = pInfo->providerId;
-                       String oId = pInfo->operationId;
+                       aId = pInfo->providerId;
+                       oId = pInfo->operationId;
                }
                else
                {
@@ -351,15 +376,6 @@ _AppControlManager::OnAppControlPluginEventReceivedN(int reqId, int res, const A
                SysLogException(NID_APP, E_SYSTEM, "Invalid AppControl listener.");
        }
 
-#if 0
-       // [FIXME] following logic is not needed.
-       // call TerminateAppControl
-       if (pInfo->pProvider)
-       {
-               pInfo->pProvider->StopAppControlPlugin(pInfo->reqId);
-               SysLog(NID_APP, "AppControl stopped for req %d.", pInfo->reqId);
-       }
-#endif
 
        // remove from list and unload dll
        __inAppManager.RemoveItem(reqId);
@@ -570,36 +586,14 @@ _AppControlManager::LaunchPkg(_AppMessageImpl& msg, AppSvcResFn pCb, void* data)
 
 
 result
-_AppControlManager::LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
-{
-       _AppMessageImpl msg;
-
-       return LaunchPkg(msg, pkg_name, op, mime, uri, pCb, data);
-}
-
-result
-_AppControlManager::LaunchAppWithCondition(const AppId& appId, const String& condition, IList* pArrayArgs)
-{
-       result r = E_SUCCESS;
-       _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(appId, pArg);
-CATCH:
-       delete pArg;
-       return r;
-}
-
-result
 _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
 {
        SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
        SysLog(NID_APP, "App: %ls.", appId.GetPointer());
 
        String actualAppId = appId;
+#if 0
+       // This logic is only for very old legacy code to support "pkgid" launch and should be removed
        if (appId.GetLength() == 10)
        {
                const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
@@ -610,6 +604,7 @@ _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
                        actualAppId.Append(name);
                }
        }
+#endif
 
        pArg->UpdateRequestId(req);
 
@@ -621,25 +616,34 @@ _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
 
        int pid = -1;
        bundle* kb = NULL;
-       String tempId;
-       actualAppId.SubString(0, 10, tempId);
-       tempId += L'.';
-       tempId += L"_AppControl";
 
-       // [INFO] Ugly solution for submode support
-       pArg->UpdateAppId(tempId);
-       kb = pArg->GetBundle();
-       
-       pid = appsvc_run_service(kb, req, LaunchResultCb, this);
-       if (pid >= 0)
-       {
-               SysLog(NID_APP, "Submode launch successful");
-               return E_SUCCESS;
-       }
-       else if (pid == APPSVC_RET_EINVAL)
+       std::unique_ptr< PackageAppInfo > pAppInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
+       SysTryReturn(NID_APP, pAppInfo != null, E_SYSTEM, GetLastResult(), "[%s] Getting AppInfo failed.", GetErrorMessage(GetLastResult()));
+       _PackageAppInfoImpl* pAppInfoImpl = _PackageAppInfoImpl::GetInstance(pAppInfo.get());
+       SysTryReturnResult(NID_APP, pAppInfoImpl != null , E_SYSTEM, "Severe system error");
+
+       if (pAppInfoImpl->IsServiceApp() == false)
        {
-               SysLog(NID_APP, "Argument overflow");
-               return E_MAX_EXCEEDED;
+               String tempId;
+               actualAppId.SubString(0, 10, tempId);
+               tempId += L'.';
+               tempId += String(SUBMODE_NAME);
+
+               // [INFO] Ugly solution for submode support
+               pArg->UpdateAppId(tempId);
+               kb = pArg->GetBundle();
+
+               pid = appsvc_run_service(kb, req, LaunchResultCb, this);
+               if (pid >= 0)
+               {
+                       SysLog(NID_APP, "Submode launch successful");
+                       return E_SUCCESS;
+               }
+               else if (pid == APPSVC_RET_EINVAL)
+               {
+                       SysLog(NID_APP, "Argument overflow");
+                       return E_MAX_EXCEEDED;
+               }
        }
 
        pArg->UpdateAppId(actualAppId);
@@ -754,7 +758,7 @@ _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, AppSvcResFn pCb, v
        if ((!(type & _APP_TYPE_SERVICE_APP)) && _IsDefaultApplication(tempId, appId))
        {
                tempId += L'.';
-               tempId += L"_AppControl";
+               tempId += String(SUBMODE_NAME);
 
                // [INFO] Ugly solution for submode support
                pArg->UpdateAppId(tempId);