Update to handle the FG/BG on AppControl response callback
[platform/framework/native/appfw.git] / src / app / FApp_Aul.cpp
index 8523a63..c87413a 100644 (file)
@@ -29,7 +29,8 @@
 #include <aul.h>
 #include <bundle.h>
 #include <appsvc/appsvc.h>
-#include <heynoti.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)
+_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,9 +124,9 @@ _Aul::SendResult(bundle* b, appsvc_result_val res, bool isSubMode)
        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);
+               _AppArg::UpdateRaiseMode(b);
        }
 
        const int aul_ret = aul_send_service_result(b);
@@ -155,7 +156,7 @@ _Aul::IsRunning(const String& appId)
 result
 _Aul::TerminateApplicationByPid(int pid)
 {
-       int ret_aul = aul_terminate_pid(pid);
+       int ret_aul = aul_subapp_terminate_request_pid(pid);
 
        return GetConvertedResult(ret_aul, "TerminateApplicationByPid");
 }
@@ -203,9 +204,16 @@ _Aul::SetOomAdj(int pid, int adj)
        return r;
 }
 
+typedef void (* cbForVconf)(keynode_t* node, void *pData);
+
 result
-_Aul::SetPowerOffNotiListener( void (*powerOffCb)(void *pData), void *pData)
+_Aul::SetPowerOffNotiListener( void (*powerOffCb)(void* node, void *pData), void *pData)
 {
+
+#if 1
+       int ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, (cbForVconf)powerOffCb, pData);
+       SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It failed to set power off");
+#else
        int heyFd = heynoti_init();
        SysTryReturnResult(NID_APP, heyFd >= 0, E_SYSTEM, "heynoti_init failed.");
 
@@ -214,6 +222,7 @@ _Aul::SetPowerOffNotiListener( void (*powerOffCb)(void *pData), void *pData)
 
        ret = heynoti_attach_handler(heyFd);
        SysTryReturnResult(NID_APP, ret >= 0, E_SYSTEM, "heynoti_attach_handler failed.");
+#endif
 
        return E_SUCCESS;
 }
@@ -269,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")
-       {
-               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
+       if (temp == String(SUBMODE_NAME))
        {
-               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