fix appcontrol result behavior from service callee
[platform/framework/native/appfw.git] / src / app / FApp_AppArg.cpp
index 2d33f5a..67ffb46 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <cstdio>
 #include <cstdlib>
-#include <vector>
 #include <new>
 #include <typeinfo>
 #include <unique_ptr.h>
 #include <FBaseInteger.h>
 #include <FBaseColArrayList.h>
 #include <FBaseColHashMap.h>
+#include <FBaseByteBuffer.h>
 #include <FBaseUtilStringTokenizer.h>
-
 #include <FBaseSysLog.h>
+
 #include <FBase_StringConverter.h>
 
 #include "FApp_MapDataControlImpl.h"
 #include "FApp_AppArg.h"
 #include "FApp_AppMessageImpl.h"
 #include "FApp_Aul.h"
-#include "FAppPkg_PackageManagerImpl.h"
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::Base::Utility;
-using namespace Tizen::App::Package;
 
 
 extern "C" int appsvc_allow_transient_app(bundle*, Ecore_X_Window);
@@ -73,10 +71,17 @@ static const char OSP_V_REQUEST_TYPE_MAP_INSERT[] = "map_insert";
 static const char OSP_V_REQUEST_TYPE_MAP_UPDATE[] = "map_update";
 static const char OSP_V_REQUEST_TYPE_MAP_DELETE[] = "map_delete";
 static const char OSP_V_VERSION_2_1_0_3[] = "ver_2.1.0.3";
+
 static const char BUNDLE_KEY_PREFIX_AUL[] = "__AUL_";
 static const char BUNDLE_KEY_PREFIX_SERVICE[] = "__APP_SVC_";
 static const char BUNDLE_KEY_PREFIX_OSP[] = "__OSP_";
+static const char BUNDLE_KEY_PREFIX_UG[] = "__UG_";
+
+static const char OSP_K_SUBMODE_CALLEE[] = "__OSP_SUB_CALLEE__";
+static const char OSP_K_SERVICE_CALLEE[] = "__OSP_SERVICE_CALLEE__";
+
 const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
+const wchar_t LEGACY_OPERATION_MAIN[] = L"osp.operation.MAIN";
 
 
 _AppArg::_AppArg(void)
@@ -100,7 +105,7 @@ _AppArg::Construct(const String& argText)
        __pBundle = bundle_create();
        SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
 
-       return CreateLaunchArg(__pBundle, argText);
+       return CreateNotificationArg(__pBundle, argText);
 }
 
 
@@ -288,7 +293,7 @@ _AppArg::GetArgListN(int num) const
 
        case _APP_HANDLER_LAUNCH_NORMAL:
                pList->Add(*new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL));
-               pList->Add(*new (std::nothrow) String(L"osp.operation.MAIN"));
+               pList->Add(*new (std::nothrow) String(LEGACY_OPERATION_MAIN));
                break;
 
        default:
@@ -359,6 +364,11 @@ IsInternalKey(const char* pKey)
                return true;
        }
 
+       if (strncmp(BUNDLE_KEY_PREFIX_UG, pKey, strlen(BUNDLE_KEY_PREFIX_UG)) == 0)
+       {
+               return true;
+       }
+
        return false;
 }
 
@@ -824,7 +834,7 @@ _AppArg::GetListN(bundle* b, const char* key)
 
 
 result
-_AppArg::CreateLaunchArg(bundle* b, const String& arg)
+_AppArg::CreateNotificationArg(bundle* b, const String& arg)
 {
        SysAssertf(b != null, "Valid bundle should be supplied");
 
@@ -832,15 +842,8 @@ _AppArg::CreateLaunchArg(bundle* b, const String& arg)
 
        if (!arg.IsEmpty())
        {
-               const char** pSa = new (std::nothrow) const char*[1];
-               SysTryReturnResult(NID_APP, pSa != null, E_OUT_OF_MEMORY, "Insufficient memory.");
-               pSa[0] = _StringConverter::CopyToCharArrayN(arg);
-               bundle_add_str_array(pb, OSP_K_ARG, pSa, 1);
-
-               bundle_add(pb, TIZEN_NOTIFICATION_DATA, pSa[0]);
-
-               delete[] pSa[0];
-               delete[] pSa;
+               std::unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(arg));
+               bundle_add(pb, TIZEN_NOTIFICATION_DATA, pStr.get());
        }
 
        bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_LAUNCH);
@@ -1053,21 +1056,10 @@ _AppArg::CreateBundleFromSvc(void* svc)
 bundle*
 _AppArg::GetBundleFromSvc(void* svc)
 {
-       struct DummyS
-       {
-               int dummy1;
-               int dummy2;
-               bundle* pData;
-       };
+       bundle* pBundle = NULL;
+       int ret = service_to_bundle(static_cast<service_h>(svc), &pBundle);
 
-       DummyS* pDummy = static_cast<DummyS*>(svc);
-
-       if (pDummy && pDummy->pData)
-       {
-               return pDummy->pData;
-       }
-
-       return NULL;
+       return (ret == SERVICE_ERROR_NONE) ? pBundle : NULL;
 }
 
 
@@ -1163,12 +1155,22 @@ bool
 _AppArg::IsSubMode(bundle* pBundle)
 {
        const char* p = appsvc_get_data(pBundle, OSP_K_SUBMODE_CALLEE);
-       if (p && (strncmp(p, "1", sizeof(char)) == 0))
-       {
-               return true;
-       }
+       return (p && (strncmp(p, "1", sizeof(char)) == 0));
+}
 
-       return false;
+
+void
+_AppArg::UpdateServiceApp(bundle* pBundle)
+{
+       appsvc_add_data(pBundle, OSP_K_SERVICE_CALLEE, "1");
+}
+
+
+bool
+_AppArg::IsServiceApp(bundle* pBundle)
+{
+       const char* p = appsvc_get_data(pBundle, OSP_K_SERVICE_CALLEE);
+       return (p && (strncmp(p, "1", sizeof(char)) == 0));
 }
 
 
@@ -1242,49 +1244,6 @@ _AppArg::Print(bundle* b)
                return;
        }
 
-       const char* p = null;
-       p = appsvc_get_data(b, AUL_K_CALLER_PID);
-       if (p)
-       {
-               SysLog(NID_APP, "CallerPId[%s]", p);
-       }
-
-       p = appsvc_get_data(b, AUL_K_WAIT_RESULT);
-       if (p)
-       {
-               SysLog(NID_APP, "WaitResult[%s]", p);
-       }
-
-       p = appsvc_get_data(b, OSP_K_COND);
-       if (p)
-       {
-               SysLog(NID_APP, "Condition[%s]", p);
-       }
-
-       p = appsvc_get_operation(b);
-       if (p)
-       {
-               SysLog(NID_APP, "operation[%s]", p);
-       }
-
-       p = appsvc_get_uri(b);
-       if (p)
-       {
-               SysLog(NID_APP, "uri[%s]", p);
-       }
-
-       p = appsvc_get_mime(b);
-       if (p)
-       {
-               SysLog(NID_APP, "mime[%s]", p);
-       }
-
-       p = appsvc_get_category(b);
-       if (p)
-       {
-               SysLog(NID_APP, "Category[%s]", p);
-       }
-
        bundle_foreach(b, BundlePrintIterFnCb, NULL);
 
        int len = 0;