fix appcontrol result behavior from service callee
[platform/framework/native/appfw.git] / src / app / FApp_AppArg.cpp
index 83824ad..67ffb46 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
 
 #include <cstdio>
 #include <cstdlib>
-#include <vector>
 #include <new>
 #include <typeinfo>
 #include <unique_ptr.h>
 
 #include <aul.h>
 #include <app.h>
+#include <bundle.h>
 #include <appsvc/appsvc.h>
+#include <Ecore_X.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_AppControlEventArg.h"
 #include "FApp_AppArg.h"
 #include "FApp_AppMessageImpl.h"
-#include "FAppPkg_PackageManagerImpl.h"
+#include "FApp_Aul.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);
 
 namespace Tizen { namespace App
 {
@@ -67,18 +70,18 @@ static const char OSP_V_REQUEST_TYPE_MAP_QEURY[] = "map_query";
 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 BUNDLE_KEY_WINDOW[] = "__APP_SVC_K_WIN_ID__";
+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_";
-const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
+static const char BUNDLE_KEY_PREFIX_UG[] = "__UG_";
 
-static const char SAMSUNG_ACCOUNT_KEY_CLIENT_ID[] = "client_id";
-static const char SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET[] = "client_secret";
-static const char SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY[] = "service_category";
+static const char OSP_K_SUBMODE_CALLEE[] = "__OSP_SUB_CALLEE__";
+static const char OSP_K_SERVICE_CALLEE[] = "__OSP_SERVICE_CALLEE__";
 
-static const char SMS_KEY_SERVICE_CALLER[] = "service_caller";
-static const char SMS_KEY_SERVICE_DATA[] = "service_data";
+const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
+const wchar_t LEGACY_OPERATION_MAIN[] = L"osp.operation.MAIN";
 
 
 _AppArg::_AppArg(void)
@@ -102,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);
 }
 
 
@@ -137,6 +140,16 @@ _AppArg::Construct(const _AppControlImpl& ac, const String* pUri, const String*
 
 
 result
+_AppArg::Construct(const _AppMessageImpl& msg, const String& oId, const String* pUri, const String* pMime)
+{
+       __pBundle = bundle_dup(const_cast<bundle*>(msg.GetBundle()));
+       SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
+
+       return CreateAppControlArg(__pBundle, oId, pUri, pMime, null);
+}
+
+
+result
 _AppArg::Construct(const _SqlDataControlImpl& dc, _DataControlRequestType requestType, const IList* pList)
 {
        __pBundle = bundle_create();
@@ -195,6 +208,16 @@ _AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pL
        return CreateAppLaunchConditionArg(__pBundle, condition, pList);
 }
 
+result
+_AppArg::ConstructForAppLaunchCondition(const String& condition, const IList* pList, const IMap* pMap)
+{
+       __pBundle = bundle_create();
+       SysTryReturnResult(NID_APP, __pBundle != null, E_OUT_OF_MEMORY, "Bundle creation failure.");
+
+       CreateAppLaunchConditionArg(__pBundle, condition, pList);
+
+       return CreateResultArg(__pBundle, pMap);
+}
 
 ArrayList*
 _AppArg::GetArgListN(int num) const
@@ -270,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:
@@ -305,6 +328,8 @@ _AppArg::GetArgMapN(void) const
 {
        SysTryReturn(NID_APP, __pBundle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
 
+       //Print();
+
        HashMap* pHashMap = new (std::nothrow) HashMap(SingleObjectDeleter);
        SysTryReturn(NID_APP, pHashMap != null, null, E_OUT_OF_MEMORY, "HashMap creation failure.");
 
@@ -314,30 +339,10 @@ _AppArg::GetArgMapN(void) const
 
        if (pHashMap->GetCount() == 0)
        {
-               // [FIXME] temporary resolution for PolarisOffice
-               const char* p = appsvc_get_uri(__pBundle);
-               if (p == null)
-               {
-                       delete pHashMap;
-                       return null;
-               }
-               else
-               {
-                       pHashMap->Add(new (std::nothrow) String(L"reqId"), new (std::nothrow) String(L"-1"));
-                       pHashMap->Add(new (std::nothrow) String(L"path1"), new (std::nothrow) String(L""));
-                       pHashMap->Add(new (std::nothrow) String(L"path2"), new (std::nothrow) String(L""));
-                       pHashMap->Add(new (std::nothrow) String(L"path3"), new (std::nothrow) String(L""));
-                       pHashMap->Add(new (std::nothrow) String(L"path"), new (std::nothrow) String(p));
-
-                       return pHashMap;
-               }
+               delete pHashMap;
+               return null;
        }
 
-       ArrayList* pList = _AppMessageImpl::GetValueArray(__pBundle, OSP_K_ARG);
-       if (pList)
-       {
-               pHashMap->Add(new (std::nothrow) String(TIZEN_APPCONTROL_DATA_LEGACY), pList);
-       }
        return pHashMap;
 }
 
@@ -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;
 }
 
@@ -383,7 +393,6 @@ BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, vo
                        bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
                        if (pStr)
                        {
-                               SysLog(NID_APP, "(%s, %s)", pKey, pStr);
                                pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(pStr));
                        }
                        break;
@@ -393,15 +402,29 @@ BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, vo
                                bundle_keyval_get_array_val(const_cast<bundle_keyval_t*>(pVal), &pArr, &size, NULL);
                                if (pArr && size > 0)
                                {
-                                       String str = static_cast<char*>(*pArr);
-                                       for (size_t i = 1; i < size; i++)
+                                       ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+                                       if (pList)
                                        {
-                                               str += L';';
-                                               str += static_cast<char*>(*(pArr + i));
+                                               pList->Construct();
+
+                                               for (size_t i = 0; i < size; i++)
+                                               {
+                                                       // type unsafe ugly static casting required
+                                                       pList->Add(new (std::nothrow) String(static_cast<char*>(*(pArr + i))));
+                                               }
+
+                                               const int count = pList->GetCount();
+                                               if (count != 0)
+                                               {
+                                                       SysLog(NID_APP, "Adding %d elements for %s", count, pKey);
+                                                       pMap->Add(new (std::nothrow) String(pKey), pList);
+                                               }
+                                               else
+                                               {
+                                                       SysLog(NID_APP, "No object for %s", pKey);
+                                                       delete pList;
+                                               }
                                        }
-
-                                       SysLog(NID_APP, "(%s, %ls)", pKey, str.GetPointer());
-                                       pMap->Add(new (std::nothrow) String(pKey), new (std::nothrow) String(str));
                                }
                                else
                                {
@@ -409,6 +432,26 @@ BundleIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVal, vo
                                }
                        }
                        break;
+               case BUNDLE_TYPE_BYTE:
+                       bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
+
+                       SysLog(NID_IO, "Bundle byte value = %s, size = %d", pStr, size);
+
+                       if (pStr)
+                       {
+                               ByteBuffer* pBuffer = new (std::nothrow) ByteBuffer();
+                               SysTryLog(NID_IO, pBuffer != null, "The memory is insufficient.");
+                               result r = pBuffer->Construct(size);
+                               SysTryLog(NID_IO, r == E_SUCCESS, "Constructing pBuffer is failed.");
+
+                               r = pBuffer->SetArray((const byte*)pStr, 0, size);
+                               SysTryLog(NID_IO, r == E_SUCCESS, "SetArray()for ByteBuffer is failed.");
+
+                               pBuffer->Flip();
+
+                               pMap->Add(new (std::nothrow) String(pKey), pBuffer);
+                       }
+                       break;
                default:
                        SysLog(NID_APP, "Invalid type for %s : %d", pKey, type);
                        break;
@@ -449,47 +492,6 @@ _AppArg::SetArgList(bundle* pBundle, ArrayList* pList)
                SysLog(NID_APP, "argument is %s", p);
        }
 
-       String tmp;
-       p = appsvc_get_data(pBundle, SMS_KEY_SERVICE_CALLER);
-       if (p)
-       {
-               tmp.Format(60, L"%s:%s", SMS_KEY_SERVICE_CALLER, p);
-               pList->Add(*new (std::nothrow) String(tmp));
-               SysLog(NID_APP, "service_caller is %s", p);
-       }
-       
-       p = appsvc_get_data(pBundle, SMS_KEY_SERVICE_DATA);
-       if (p)
-       {
-               tmp.Format(60, L"%s:%s", SMS_KEY_SERVICE_DATA, p);
-               pList->Add(*new (std::nothrow) String(tmp));
-               SysLog(NID_APP, "service_data is set");
-       }
-       
-       p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_CLIENT_ID);
-       if (p)
-       {
-               tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_CLIENT_ID, p);
-               pList->Add(*new (std::nothrow) String(tmp));
-               SysLog(NID_APP, "client_id is %s", p);
-       }
-       
-       p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET);
-       if (p)
-       {
-               tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_CLIENT_SECRET, p);
-               pList->Add(*new (std::nothrow) String(tmp));
-               SysLog(NID_APP, "client_secret is %s", p);
-       }
-
-       p = appsvc_get_data(pBundle, SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY);
-       if (p)
-       {
-               tmp.Format(60, L"%s:%s", SAMSUNG_ACCOUNT_KEY_SERVICE_CATEGORY, p);
-               pList->Add(*new (std::nothrow) String(tmp));
-               SysLog(NID_APP, "service_category is %s", p);
-       }
-
        return E_SUCCESS;
 }
 
@@ -564,44 +566,20 @@ _AppArg::GetCallerPid(bundle* pBundle)
 AppId
 _AppArg::GetCallerAppId(void) const
 {
-       pid_t callerPid = GetCallerPid();
-       SysTryReturn(NID_APP, callerPid > 0, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Wrong process id: %d.", callerPid);
-
-       char appId[PATH_MAX] = {0, };
-       SysTryReturn(NID_APP, aul_app_get_appid_bypid(callerPid, appId, sizeof(appId)) == AUL_R_OK, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found for %d.", callerPid);
+       const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLER_APPID);
 
-       return String(appId);
+       return String(pBundleValue);
 }
 
 
 AppId
 _AppArg::GetCalleeAppId(void) const
 {
-       const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLEE_PID);
+       const char* pBundleValue = bundle_get_val(__pBundle, AUL_K_CALLEE_APPID);
 
-       SysTryReturn(NID_APP, pBundleValue != null, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found.");
+       const AppId retVal = pBundleValue;
 
-       pid_t calleePid = atoi(pBundleValue);
-       SysTryReturn(NID_APP, calleePid > 0, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Wrong process id: %d.", calleePid);
-
-       char appId[PATH_MAX] = {0, };
-       SysTryReturn(NID_APP, aul_app_get_appid_bypid(calleePid, appId, sizeof(appId)) == AUL_R_OK, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Object not found for %d.", calleePid);
-
-       String temp;
-       String retVal = appId;
-       // [INFO] ugly code for submode callee
-       retVal.SubString(11, temp);
-       if (temp == L"_AppControl")
-       {
-               String id;
-               retVal.SubString(0, 10, id);
-               const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(id);
-
-               retVal = id + L'.' + name;
-               SysLog(NID_APP, "Converted caller Id is %ls", retVal.GetPointer());
-       }
-
-       return retVal;
+       return _Aul::GetRealAppId(retVal);
 }
 
 
@@ -632,9 +610,8 @@ _AppArg::AddStrArray(bundle* b, const String& key, const IList* pList)
 
 
 result
-_AppArg::AddStrArray(bundle* b, const char* key, const IList* pList)
+_AppArg::AddStrArray(bundle* pb, const char* key, const IList* pList)
 {
-       bundle* pb = b;
        SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
 
        if (pList == null || pList->GetCount() == 0)
@@ -643,47 +620,11 @@ _AppArg::AddStrArray(bundle* b, const char* key, const IList* pList)
                return E_SUCCESS;
        }
 
-       int i = 0;
-       const int count = pList->GetCount();
-
-       const char** pSa = new (std::nothrow) const char*[count];
-       SysTryReturnResult(NID_APP, pSa != null, E_OUT_OF_MEMORY, "Memory allocation failure with cound %d.", count);
-
-       for (i = 0; i < count; i++)
-       {
-               pSa[i] = null;
-
-               const String* pStr = static_cast<const String*>(pList->GetAt(i));
-               if (pStr)
-               {
-                       pSa[i] = _StringConverter::CopyToCharArrayN(*pStr);
-               }
-       }
-
-       result r = E_SUCCESS;
-
-       int ret = bundle_add_str_array(pb, key, pSa, count);
-       if (ret >= 0)
-       {
-               _AppMessageImpl::AddData(pb, pList);
-       }
-       else
-       {
-               SysLog(NID_APP, "Bundle add failre :%d.", ret);
-               r = E_SYSTEM;
-       }
+       _AppMessageImpl::AddValueArray(pb, key, pList);
 
        _AppMessageImpl::AddData(pb, pList);
 
-//CATCH:
-       for (i = 0; i < count; i++)
-       {
-               delete[] pSa[i];
-       }
-
-       delete[] pSa;
-
-       return r;
+       return E_SUCCESS;
 }
 
 
@@ -718,16 +659,20 @@ _AppArg::AddStrMap(bundle* b, const IMap* pMap)
                        else if (typeid(*pObj) == typeid(const ArrayList))
                        {
                                const ArrayList* pList = static_cast<const ArrayList*>(pEnum->GetValue());
-                               if (pList && *pKey == TIZEN_APPCONTROL_DATA_LEGACY)
+                               if (pList)
                                {
-                                       SysLog(NID_APP, "Legacy AppControl argument");
-                                       _AppArg::AddStrArray(pb, OSP_K_ARG, pList);
-                                       _AppMessageImpl::AddData(pb, pList);
+                                       SysLog(NID_APP, "ArrayList type");
+
+                                       _AppMessageImpl::AddValueArray(pb, *pKey, pList);
                                }
                        }
                        else if (typeid(*pObj) == typeid(const ByteBuffer))
                        {
                                SysLog(NID_APP, "ByteBuffer type");
+                               const ByteBuffer* pBuffer = static_cast<const ByteBuffer*>(pObj);
+
+                               std::unique_ptr<char[]> pBundleKey(_StringConverter::CopyToCharArrayN(*pKey));
+                               bundle_add_byte(b, pBundleKey.get(), pBuffer->GetPointer(), pBuffer->GetLimit());
                        }
                }
        }
@@ -889,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");
 
@@ -897,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);
@@ -973,13 +911,20 @@ _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const IList*
 
 
 result
-_AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String* pUriData, const String* pMimeType, const IMap* pList)
+_AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String* pUriData, const String* pMimeType, const IMap* pMap)
+{
+       return CreateAppControlArg(b, ac._opId, pUriData, pMimeType, pMap);
+}
+
+
+result
+_AppArg::CreateAppControlArg(bundle* b, const String& oId, const String* pUriData, const String* pMimeType, const IMap* pMap)
 {
        SysAssertf(b != null, "Valid bundle should be supplied");
 
        bundle* pb = b;
 
-       std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(ac._opId));
+       std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(oId));
        if (pOperation.get())
        {
                appsvc_set_operation(pb, pOperation.get());
@@ -1003,7 +948,7 @@ _AppArg::CreateAppControlArg(bundle* b, const _AppControlImpl& ac, const String*
                }
        }
 
-       AddStrMap(pb, pList);
+       AddStrMap(pb, pMap);
 
        bundle_add(pb, OSP_K_LAUNCH_TYPE, OSP_V_LAUNCH_TYPE_APPCONTROL);
 
@@ -1026,6 +971,8 @@ _AppArg::CreateSqlDataControlArg(bundle* b, const _SqlDataControlImpl& dc, _Data
        char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
        snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast<int>(requestType));
        bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
+       bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
+       bundle_add(b, AUL_K_NO_CANCEL, "1");
 
        std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
        if (pProvider)
@@ -1050,6 +997,8 @@ _AppArg::CreateMapDataControlArg(bundle* b, const _MapDataControlImpl& dc, _Data
        char dataControlRequestType[MAX_LEN_DATA_CONTROL_REQ_TYPE] = {0, };
        snprintf(dataControlRequestType, MAX_LEN_DATA_CONTROL_REQ_TYPE, "%d", static_cast < int >(requestType));
        bundle_add(b, OSP_K_DATACONTROL_REQUEST_TYPE, dataControlRequestType);
+       bundle_add(b, OSP_K_DATACONTROL_PROTOCOL_VERSION, OSP_V_VERSION_2_1_0_3);
+       bundle_add(b, AUL_K_NO_CANCEL, "1");
 
        std::unique_ptr<char[]> pProvider(_StringConverter::CopyToCharArrayN(dc.__providerId));
        if (pProvider)
@@ -1107,21 +1056,10 @@ _AppArg::CreateBundleFromSvc(void* svc)
 bundle*
 _AppArg::GetBundleFromSvc(void* svc)
 {
-       struct DummyS
-       {
-               int dummy1;
-               int dummy2;
-               bundle* pData;
-       };
-
-       DummyS* pDummy = static_cast<DummyS*>(svc);
-
-       if (pDummy && pDummy->pData)
-       {
-               return pDummy->pData;
-       }
+       bundle* pBundle = NULL;
+       int ret = service_to_bundle(static_cast<service_h>(svc), &pBundle);
 
-       return NULL;
+       return (ret == SERVICE_ERROR_NONE) ? pBundle : NULL;
 }
 
 
@@ -1158,7 +1096,12 @@ _AppArg::UpdateAppId(bundle* b, const AppId& appId)
        std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
        SysTryReturnVoidResult(NID_APP, pId != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Converting %ls failed.", appId.GetPointer());
 
-       bundle_add(b, OSP_K_APPID, pId.get());
+       int res = bundle_add(b, OSP_K_APPID, pId.get());
+       if (res < 0 && errno == EPERM) // key exists
+       {
+               bundle_del(b, OSP_K_APPID);
+               bundle_add(b, OSP_K_APPID, pId.get());
+       }
 
        appsvc_set_appid(b, pId.get());
 }
@@ -1177,7 +1120,57 @@ _AppArg::UpdateRequestId(bundle* pBundle, int reqId)
 
        char buffer[32] = {0, };
        snprintf(buffer, 32, "%d", reqId);
-       bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
+       int res = bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
+       if (res < 0 && errno == EPERM) // key exists
+       {
+               bundle_del(pBundle, OSP_K_REQUEST_ID);
+               bundle_add(pBundle, OSP_K_REQUEST_ID, buffer);
+       }
+}
+
+void
+_AppArg::UpdateKeyValue(bundle* pBundle, const char* pKey, const String& value)
+{
+       SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] Improper bundle state.");
+
+       char pBuffer[128] = {0, };
+       snprintf(pBuffer, 128, "%ls", value.GetPointer());
+       int res = bundle_add(pBundle, pKey, pBuffer);
+       if (res < 0 && errno == EPERM) // key exists
+       {
+               bundle_del(pBundle, pKey);
+               bundle_add(pBundle, pKey, pBuffer);
+       }
+}
+
+
+void
+_AppArg::UpdateSubMode(bundle* pBundle)
+{
+       appsvc_add_data(pBundle, OSP_K_SUBMODE_CALLEE, "1");
+}
+
+
+bool
+_AppArg::IsSubMode(bundle* pBundle)
+{
+       const char* p = appsvc_get_data(pBundle, OSP_K_SUBMODE_CALLEE);
+       return (p && (strncmp(p, "1", sizeof(char)) == 0));
+}
+
+
+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));
 }
 
 
@@ -1198,16 +1191,8 @@ _AppArg::GetRequestIdFromBundle(bundle* pBundle)
 result
 _AppArg::UpdateWindowHandle(bundle* pBundle, long handle)
 {
-       if (handle == -1)
-       {
-               SysLog(NID_APP, "Invalid window handle.");
-               return E_SUCCESS;
-       }
-
-       char handleName[32] = {0, };
-       snprintf(handleName, 32, "%ld", handle);
+       appsvc_allow_transient_app(pBundle, handle);
 
-       bundle_add(pBundle, BUNDLE_KEY_WINDOW, handleName);
        SysLog(NID_APP, "Window Handle 0x%x added.", handle);
 
        return E_SUCCESS;
@@ -1241,7 +1226,7 @@ BundlePrintIterFnCb(const char* pKey, const int type, const bundle_keyval_t* pVa
                        bundle_keyval_get_basic_val(const_cast<bundle_keyval_t*>(pVal), reinterpret_cast<void**>(&pStr), &size);
                        if (pStr)
                        {
-                               SysLog(NID_APP, "(%s, %s)", pKey, pStr);
+                               SysSecureLog(NID_APP, "(%s, %s)", pKey, pStr);
                        }
                        break;
                default:
@@ -1259,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;