Update to handle the FG/BG on AppControl response callback
[platform/framework/native/appfw.git] / src / app / FApp_Aul.cpp
index 104b4e0..c87413a 100644 (file)
@@ -30,6 +30,7 @@
 #include <bundle.h>
 #include <appsvc/appsvc.h>
 #include <vconf.h>
+#include <pkgmgr-info.h>
 
 #include <FBaseObject.h>
 #include <FBaseString.h>
@@ -114,7 +115,7 @@ _Aul::GetConvertedResult(const int aul_ret, const char* pFunctionName)
 }
 
 result
-_Aul::SendResult(bundle* b, appsvc_result_val res, bool isSubMode, bool isServiceApp)
+_Aul::SendResult(bundle* b, appsvc_result_val res, bool isRaiseMode)
 {
        // to skip error handling, of appsvc_send_result, use aul_send_service_result() directly.
        //int ret = appsvc_send_result(b, res);
@@ -123,14 +124,9 @@ _Aul::SendResult(bundle* b, appsvc_result_val res, bool isSubMode, bool isServic
        snprintf(tmp, 32, "%d", static_cast<int>(res));
        appsvc_add_data(b, APP_SVC_K_RES_VAL, tmp);
 
-       if (isSubMode)
+       if (isRaiseMode)
        {
-               _AppArg::UpdateSubMode(b);
-       }
-
-       if (isServiceApp)
-       {
-               _AppArg::UpdateServiceApp(b);
+               _AppArg::UpdateRaiseMode(b);
        }
 
        const int aul_ret = aul_send_service_result(b);
@@ -282,27 +278,43 @@ _Aul::IsInstalled(const AppId& appId)
 }
 
 
+String
+_Aul::GetMainAppId(const char* appid)
+{
+       pkgmgrinfo_appinfo_h handle = NULL;
+       int ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+       if (ret != PMINFO_R_OK)
+       {
+               return String();
+       }
+
+       char* mainid = NULL;
+       ret = pkgmgrinfo_appinfo_get_submode_mainid(handle, &mainid);
+       SysTryLog(NID_APP, ret == PMINFO_R_OK, "Cannot get main id for %s.", appid);
+
+       const String tmp = String(mainid);
+       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+       return tmp;
+}
+
+
 AppId
 _Aul::GetRealAppId(const AppId& appId)
 {
        String temp;
-       // [INFO] ugly code for submode callee
        appId.SubString(11, temp);
-       if (temp == L"_AppControl")
+       if (temp == String(SUBMODE_NAME))
        {
-               String id;
-               appId.SubString(0, 10, id);
-               const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(id);
-
-               const String retVal = id + L'.' + name;
-               SysLog(NID_APP, "Converted caller Id is %ls", retVal.GetPointer());
-
-               return retVal;
-       }
-       else
-       {
-               return appId;
+               std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId));
+               const String& main = GetMainAppId(pAppId.get());
+               if (!main.IsEmpty())
+               {
+                       SysLog(NID_APP, "main Id is %ls", main.GetPointer());
+                       return main;
+               }
        }
+
+       return appId;
 }
 
 } } // Tizen::App