2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FApp_AppControlManager.cpp
19 * @brief This is the implementation for the _AppControlManager class.
24 #include <unique_ptr.h>
26 #include <appsvc/appsvc.h>
29 #include <content/mime_type.h>
32 #include <FBaseInteger.h>
33 #include <FBaseObject.h>
34 #include <FBaseString.h>
35 #include <FBaseColIListT.h>
36 #include <FBaseColArrayList.h>
37 #include <FBaseErrors.h>
38 #include <FAppAppControl.h>
39 #include <FAppAppManager.h>
40 #include <FAppIAppControlListener.h>
41 #include <FAppIAppControlResponseListener.h>
42 #include <FAppIAppFrame.h>
43 #include <FAppSqlDataControl.h>
44 #include <FAppMapDataControl.h>
45 #include <FAppPkgPackageInfo.h>
46 #include <FAppPkgPackageAppInfo.h>
47 #include <FBaseSysLog.h>
49 #include <FBase_StringConverter.h>
50 #include <FIo_DataControlResultSetImpl.h>
52 #include "FApp_AppArg.h"
53 #include "FApp_AppControlEventArg.h"
54 #include "FApp_AppControlRegistry.h"
55 #include "FApp_AppControlImpl.h"
56 #include "FApp_AppImpl.h"
57 #include "FApp_AppInfo.h"
59 #include "FApp_AppControlManager.h"
60 #include "FApp_AppManagerProxy.h"
61 #include "FApp_ConditionManagerProxy.h"
62 #include "FApp_MapDataControlImpl.h"
63 #include "FApp_SqlDataControlImpl.h"
64 #include "FAppPkg_PackageManagerImpl.h"
65 #include "FAppPkg_PackageInfoImpl.h"
66 #include "FApp_AppMessageImpl.h"
67 #include "FApp_AppManagerImpl.h"
68 #include "FApp_AppControlResponseEvent.h"
69 #include "FApp_IAppControlPluginProvider.h"
72 using namespace Tizen::App::Package;
73 using namespace Tizen::Base;
74 using namespace Tizen::Base::Collection;
75 using namespace Tizen::Base::Runtime;
76 using namespace Tizen::Base::Utility;
77 using namespace Tizen::Io;
80 namespace Tizen { namespace App
83 const wchar_t TIZEN_OPERATION_PICK[] = L"http://tizen.org/appcontrol/operation/pick";
84 const wchar_t TIZEN_OPERATION_MAIN[] = L"http://tizen.org/appcontrol/operation/main";
85 const wchar_t LEGACY_OPERATION_MAIN[] = L"osp.operation.MAIN";
86 const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
88 _AppControlManager::_AppControlManager(void)
92 // AppControl event handling is expected to be performed in the main thread.
93 __appControlEvent.Construct();
94 __appControlEvent.AddListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
95 __appControlResponseEventContainer.Construct();
96 __appControlResponseEventList.Construct();
99 _AppControlManager::~_AppControlManager(void)
102 __appControlEvent.RemoveListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
103 IEnumeratorT<int>* pEnum = __appControlResponseEventList.GetEnumeratorN();
107 while(pEnum->MoveNext() == E_SUCCESS)
110 pEnum->GetCurrent(reqId);
111 _AppControlResponseEvent* pResponseEvent = null;
112 __appControlResponseEventContainer.GetValue(reqId, pResponseEvent);
113 delete pResponseEvent;
115 __appControlResponseEventContainer.Remove(reqId);
116 SysLog(NID_APP, "pResponseEvent gets deleted. reqId(%d)", reqId);
123 _AppControlManager::GetInstance(void)
125 static _AppControlManager inst;
131 _AppControlManager::GetMimeFromExt(const String& ext, String& out)
133 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(ext));
134 SysTryReturnResult(NID_APP, pExtension != null, E_OUT_OF_MEMORY, "String allocation failure.");
137 mime_type_get_mime_type(pExtension.get(), &mime);
139 SysTryReturnResult(NID_APP, mime != NULL, E_UNSUPPORTED_FORMAT, "MIME type conversion failure for %ls.", ext.GetPointer());
149 _AppControlManager::GetMimeTypeFromDataType(const String& data)
151 // Data type is either MIME type or .[extension]
153 if (data.IsEmpty() || data[0] != L'.')
160 data.SubString(1, ext);
163 result r = _AppControlManager::GetMimeFromExt(ext, res);
164 SysTryReturn(NID_APP, !IsFailed(r), L"", r, "[%s] MIME type conversion failed for %ls.", GetErrorMessage(r), ext.GetPointer());
166 SysLog(NID_APP, "Conversion from %ls into %ls.", data.GetPointer(), res.GetPointer());
172 _AppControlManager::OnAppControlEventReceivedN(int reqId, _AppArg* pAppArg, int res)
174 SysLog(NID_APP, "Received request Id %d, arg 0x%x", reqId, pAppArg);
177 // get launch info from request Id
178 _DataControlInfo* pInfo = __launchManager.FindItem(reqId);
179 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with response %d", reqId,
185 if (pInfo->magic == LAUNCH_INFO_MAGIC)
187 SysLog(NID_APP, "Invoking callback 0x%x", pInfo->launchCb);
190 if (pInfo->pUserData)
192 (*pInfo->launchCb)(pInfo->pUserData, pInfo->pArg, pAppArg, static_cast<service_result_e>(res), pInfo->property, reqId);
197 SysLogException(NID_APP, E_SYSTEM, "Corrupted data structure.");
202 __launchManager.RemoveItem(reqId);
206 // callback for AppControl start event
208 _AppControlManager::OnAppControlEventReceivedN(int reqId, const AppId& appId, const String& operationId)
210 SysLog(NID_APP, "Received request Id %d, app %ls, operationId %ls", reqId, appId.GetPointer(), operationId.GetPointer());
212 // get launch info from request Id
213 _InProcessInfo* pInfo = __inAppManager.FindItem(reqId);
214 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found.", reqId);
217 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
218 SysTryReturnVoidResult(NID_APP, pListener != null, E_SYSTEM, "[E_SYSTEM] Invalid result callback for req %d, app %ls.", reqId, appId.GetPointer());
220 result r = E_SUCCESS;
224 AppId actualAppId = appId;
228 r = E_OPERATION_CANCELED;
230 SysLog(NID_APP, "Invoking callback 0x%x.", pListener);
232 _AppControlResponseEvent* pResponseEvent = null;
233 __appControlResponseEventContainer.GetValue(reqId, pResponseEvent);
234 SysLog(NID_APP, "StartResponseReceived Request Id(%d), ResponseEvent 0x%x.", reqId, pResponseEvent);
235 if (pResponseEvent != null)
237 String oId(operationId);
238 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_START, actualAppId, oId, r, APP_CTRL_RESULT_SUCCEEDED, null, reqId, false);
240 if (pResponseEventArg != null)
242 pResponseEvent->Fire(*pResponseEventArg);
243 SysLog(NID_APP, "pResponseEvent is Fired");
248 pListener->OnAppControlStartResponseReceived(actualAppId, operationId, r);
249 SysLog(NID_APP, "OnAppControlStartResponseReceived called directly");
254 SysLog(NID_APP, "No listener registered.");
257 if (r == E_OPERATION_CANCELED)
259 SysLog(NID_APP, "Removed start listener as operation is canceled.");
260 __inAppManager.RemoveItem(reqId);
266 _AppControlManager::InvokeAppControlCompleteListener(IAppControlResponseListener& listener, const AppId& appId, const String& op, AppCtrlResult res, const IMap* pExtraData, bool noRaise)
268 listener.OnAppControlCompleteResponseReceived(appId, op, res, pExtraData);
272 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
275 SysLog(NID_APP, "AppControl response finished.");
280 _AppControlManager::InvokeLegacyAppControlCompleteListener(IAppControlEventListener& listener, const AppId& appId, const String& op, const IList* pList, bool noRaise)
282 listener.OnAppControlCompleted(appId, op, pList);
286 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
289 SysLog(NID_APP, "Legacy AppControl response finished.");
293 // callback for in-process event handling
295 _AppControlManager::OnAppControlPluginEventReceivedN(int reqId, int res, const AppId& optAppId, const String& optOperation, const IMap* pArgs, int property)
297 SysLog(NID_APP, "Received request Id %d, res %d, args 0x%x", reqId, res, pArgs);
299 // process proper callback
300 _InProcessInfo* pInfo = __inAppManager.FindItem(reqId);
301 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with args 0x%x", reqId,
304 if (pInfo->pListener)
309 if (optAppId.IsEmpty())
311 aId = pInfo->providerId;
312 oId = pInfo->operationId;
316 // implicit launch only
320 SysLog(NID_APP, "Changing appId/operation for implicit launch.");
323 SysLog(NID_APP, "Invoking callback 0x%x for (%ls, %ls).", pInfo->pListener, aId.GetPointer(), oId.GetPointer());
325 const bool isSubMode = (property & _APPCONTROL_PROPERTY_SUBMODE);
326 const bool isServiceCallee = (property & _APPCONTROL_PROPERTY_SERVICE_CALLEE);
330 IAppControlEventListener* pListener = dynamic_cast<IAppControlEventListener*>(pInfo->pListener);
333 ArrayList list(SingleObjectDeleter);
334 _AppArg::FillLegacyAppControlResult(list, res, pArgs, aId);
336 InvokeLegacyAppControlCompleteListener(*pListener, aId, oId, &list, isSubMode | isServiceCallee);
340 SysLog(NID_APP, "Wrong AppControl listener type.");
345 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
348 _AppControlResponseEvent* pResponseEvent = null;
349 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + reqId;
350 __appControlResponseEventContainer.GetValue(responseEventRequestId, pResponseEvent);
352 if (pResponseEvent != null)
354 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, aId, oId, E_SUCCESS, static_cast<AppCtrlResult>(res), const_cast<IMap*> (pArgs), responseEventRequestId, isSubMode);
355 if (pResponseEventArg != null)
357 pResponseEvent->Fire(*pResponseEventArg);
358 SysLog(NID_APP, "pResponseEvent is Fired");
363 InvokeAppControlCompleteListener(*pListener, aId, oId, ConvertAppControlResultCode(res), pArgs, isSubMode | isServiceCallee);
364 SysLog(NID_APP, "Listener called directly");
370 SysLog(NID_APP, "Wrong AppControl listener type.");
376 SysLogException(NID_APP, E_SYSTEM, "Invalid AppControl listener.");
380 // remove from list and unload dll
381 __inAppManager.RemoveItem(reqId);
386 _AppControlManager::SendAppControlEvent(IEventArg& arg)
388 return __appControlEvent.FireAsync(arg);
391 Tizen::Base::Collection::IMapT<int,_AppControlResponseEvent*>*
392 _AppControlManager::GetAppControlResponseEventContainer(void)
394 return &__appControlResponseEventContainer;
399 IsMatchingProcListener(const _InProcessInfo& info, IEventListener* pListener)
401 return (info.pListener == pListener);
406 _AppControlManager::StopAppControlResponseListener(IAppControlResponseListener* pListener)
408 // __inAppManager, __launchManager
409 _InProcessInfo* pProcInfo = __inAppManager.FindItemWithListener(IsMatchingProcListener, pListener);
412 __inAppManager.RemoveItem(pProcInfo);
413 SysLog(NID_APP, "Listener 0x%x is removed from in-process stub list.", pListener);
418 // generic launch callback
420 LaunchResultCb(bundle* b, int request_code, appsvc_result_val res, void* data)
422 SysLog(NID_APP, "SLP callee result: %d", res);
424 _AppControlManager* pImpl = static_cast<_AppControlManager*>(data);
430 _AppArg* pAppArg = new (std::nothrow) _AppArg;
431 SysTryReturnVoidResult(NID_APP, pAppArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
433 _AppControlEventArg* pArg = null;
434 result r = pAppArg->Construct(b);
435 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] AppControl event argument creation failure.", GetErrorMessage(r));
437 pArg = new (std::nothrow) _AppControlEventArg(request_code, pAppArg, res);
438 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
441 pImpl->SendAppControlEvent(*pArg);
451 _AppControlManager::SendAppControlStartResponse(int req, const char* pValue, const char* pOp)
453 _AppControlStartEventArg* pArg = new (std::nothrow) _AppControlStartEventArg(req, AppId(pValue), String(pOp));
454 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "AppControl start event creation failure.");
456 SendAppControlEvent(*pArg);
463 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
465 bundle* kb = msg.GetBundle();
469 appsvc_set_pkgname(kb, pkg_name);
472 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
476 appsvc_set_mime(kb, mime);
481 appsvc_set_uri(kb, uri);
484 int pid = LaunchPkg(msg, pCb, data);
486 result r = E_SUCCESS;
497 _AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
499 bundle* kb = msg.GetBundle();
500 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
504 appsvc_set_pkgname(kb, pkg_name);
507 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
511 appsvc_set_mime(kb, mime);
516 appsvc_set_uri(kb, uri);
519 if (_AppImpl::GetInstance() != null)
521 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
522 _AppArg::UpdateWindowHandle(kb, handle);
525 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
526 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
528 result r = E_SUCCESS;
533 case APPSVC_RET_EILLACC:
534 r = E_ILLEGAL_ACCESS;
536 case APPSVC_RET_EINVAL:
543 SysLog(NID_APP, "[%s]Launching service %s failure", GetErrorMessage(r), pkg_name);
552 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, AppSvcResFn pCb, void* data)
554 bundle* kb = msg.GetBundle();
555 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
557 if (_AppImpl::GetInstance() != null)
559 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
560 _AppArg::UpdateWindowHandle(kb, handle);
563 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
565 result r = E_SUCCESS;
570 case APPSVC_RET_EILLACC:
571 r = E_ILLEGAL_ACCESS;
573 case APPSVC_RET_EINVAL:
580 SysLog(NID_APP, "[%s] Launching service %s failure", GetErrorMessage(r), appsvc_get_appid(kb));
589 _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
591 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
592 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
594 String actualAppId = appId;
596 // This logic is only for very old legacy code to support "pkgid" launch and should be removed
597 if (appId.GetLength() == 10)
599 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
603 actualAppId.Append(L'.');
604 actualAppId.Append(name);
609 pArg->UpdateRequestId(req);
611 if (_AppImpl::GetInstance() != null)
613 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
614 pArg->UpdateWindowHandle(handle);
620 std::unique_ptr< PackageAppInfo > pAppInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
621 SysTryReturn(NID_APP, pAppInfo != null, E_SYSTEM, GetLastResult(), "[%s] Getting AppInfo failed.", GetErrorMessage(GetLastResult()));
622 _PackageAppInfoImpl* pAppInfoImpl = _PackageAppInfoImpl::GetInstance(pAppInfo.get());
623 SysTryReturnResult(NID_APP, pAppInfoImpl != null , E_SYSTEM, "Severe system error");
625 if (pAppInfoImpl->IsServiceApp() == false)
628 actualAppId.SubString(0, 10, tempId);
630 tempId += String(SUBMODE_NAME);
632 // [INFO] Ugly solution for submode support
633 pArg->UpdateAppId(tempId);
634 kb = pArg->GetBundle();
636 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
639 SysLog(NID_APP, "Submode launch successful");
642 else if (pid == APPSVC_RET_EINVAL)
644 SysLog(NID_APP, "Argument overflow");
645 return E_MAX_EXCEEDED;
649 pArg->UpdateAppId(actualAppId);
651 // retry for possible failure
653 const int TRY_COUNT = 3;
654 const int TRY_SLEEP_TIME = 65;
657 kb = pArg->GetBundle();
658 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
661 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
664 else if (pid == APPSVC_RET_EINVAL)
666 SysLog(NID_APP, "Argument overflow");
667 return E_MAX_EXCEEDED;
671 SysLog(NID_APP, "Waiting %dth time.", count);
672 Thread::Sleep(TRY_SLEEP_TIME);
674 while (count < TRY_COUNT);
676 result r = E_SUCCESS;
679 case APPSVC_RET_EILLACC:
680 r = E_ILLEGAL_ACCESS;
687 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
693 _IsDefaultApplication(const AppId& packageId, const String& appId)
695 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
698 result r = appId.IndexOf(L'.', 0, index);
705 appId.SubString(index + 1, tmp);
708 SysLog(NID_APP, "Default application %ls", tmp.GetPointer());
717 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
719 return Launch(appId, pArg, reinterpret_cast<AppSvcResFn>(LaunchResultCb), this, req);
724 _AppControlManager::Launch(const _AppMessageImpl& msg, AppSvcResFn pCb, void* pData, int req)
726 const bundle* pBundle = msg.GetBundle();
729 arg.Construct(pBundle);
731 return Launch(_AppMessageImpl::GetApplicationId(pBundle), &arg, pCb, pData, req);
736 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, AppSvcResFn pCb, void* pData, int req)
738 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid launch argument");
739 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
741 String actualAppId = appId;
743 pArg->UpdateRequestId(req);
745 if (_AppImpl::GetInstance() != null)
747 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
748 pArg->UpdateWindowHandle(handle);
755 actualAppId.SubString(0, 10, tempId);
757 const int type = _AppInfo::GetAppType();
758 if ((!(type & _APP_TYPE_SERVICE_APP)) && _IsDefaultApplication(tempId, appId))
761 tempId += String(SUBMODE_NAME);
763 // [INFO] Ugly solution for submode support
764 pArg->UpdateAppId(tempId);
765 kb = pArg->GetBundle();
767 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
770 SysLog(NID_APP, "Submode launch successful");
771 SetLastResult(E_SUCCESS);
774 else if (pid == APPSVC_RET_EINVAL)
776 SetLastResult(E_MAX_EXCEEDED);
781 pArg->UpdateAppId(actualAppId);
783 // retry for possible failure
785 const int TRY_COUNT = 3;
786 const int TRY_SLEEP_TIME = 65;
789 kb = pArg->GetBundle();
790 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
793 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
794 SetLastResult(E_SUCCESS);
797 else if (pid == APPSVC_RET_EINVAL)
799 SetLastResult(E_MAX_EXCEEDED);
804 SysLog(NID_APP, "Waiting %dth time with %d.", count, pid);
805 Thread::Sleep(TRY_SLEEP_TIME);
807 while (count < TRY_COUNT);
809 result r = E_SUCCESS;
812 case APPSVC_RET_EILLACC:
813 r = E_ILLEGAL_ACCESS;
820 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
829 _AppControlManager::FinishAppControl(int reqId, int res, IMap* pMap)
831 SysLog(NID_APP, "req %d, res %d.", reqId, res);
832 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, pMap, _APPCONTROL_PROPERTY_SUBMODE);
833 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
835 SendAppControlEvent(*pArg);
840 _AppControlManager::FinishAppControl(int reqId, int res, const AppId& appId, const String& oId, IMap* pMap, int prop)
842 SysLog(NID_APP, "req %d, res %d, appId(%ls), oId(%ls).", reqId, res, appId.GetPointer(), oId.GetPointer());
843 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, appId, oId, pMap, prop);
844 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
846 SendAppControlEvent(*pArg);
851 _AppControlManager::RemoveResultRequest(int reqId)
853 __resultManager.RemoveItem(reqId);
857 _AppControlManager::FindResultRequest(int reqId) const
859 const _ResultInfo* pInfo = __resultManager.FindItem(reqId);
860 return (pInfo) ? &(pInfo->arg) : null;
864 _AppControlManager::AddLaunchRequest(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
866 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
868 _DataControlInfo* pItem = new (std::nothrow) _DataControlInfo(pArg, pCb, pData, prop);
869 SysTryReturn(NID_APP, pItem != null, -1, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
871 SysLog(NID_APP, "Registering callback 0x%x, 0x%x", pCb, pData);
873 return __launchManager.InsertItem(pItem);
877 _AppControlManager::RemoveLaunchRequest(int req)
879 __launchManager.RemoveItem(req);
883 _AppControlManager::RegisterRequest(service_s* service, int& req, _AppHandler& handler)
885 bundle* b = _AppArg::GetBundleFromSvc(service);
887 _AppArg* pArg = new (std::nothrow) _AppArg();
888 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
891 result r = E_SUCCESS;
893 // ownership is transfered to RequestManager
894 _ResultInfo* pItem = new (std::nothrow) _ResultInfo(*pArg);
895 SysTryCatch(NID_APP, pItem != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
897 req = __resultManager.InsertItem(pItem);
898 SysTryCatch(NID_APP, req != -1, , r = E_INVALID_STATE, "[E_INVALID_STATE] Invalid argument handling state.");
900 handler = _AppArg::GetHandler(b);
912 _AppControlManager::ConvertAppControlResultCode(int resCode)
914 AppCtrlResult ret = APP_CTRL_RESULT_FAILED;
918 case SERVICE_RESULT_SUCCEEDED:
919 ret = APP_CTRL_RESULT_SUCCEEDED;
921 case SERVICE_RESULT_FAILED:
922 ret = APP_CTRL_RESULT_CANCELED;
924 case SERVICE_RESULT_CANCELED:
925 ret = APP_CTRL_RESULT_ABORTED;
927 case APPSVC_OSP_RES_FAIL:
928 ret = APP_CTRL_RESULT_FAILED;
930 case APPSVC_OSP_RES_TERMINATE:
931 ret = APP_CTRL_RESULT_TERMINATED;
934 ret = APP_CTRL_RESULT_FAILED;
943 _AppControlManager::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
945 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
947 if (pEventArg != null)
949 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
951 if(pResponseListener != null)
953 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_START)
955 pResponseListener->OnAppControlStartResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetResult());
956 SysLog(NID_APP, "OnAppControlStartResponseReceived called");
960 InvokeAppControlCompleteListener(*pResponseListener, pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData(), pEventArg->IsSubMode());
961 SysLog(NID_APP, "Listener called");
963 _AppControlResponseEvent* pResponseEvent = null;
964 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
965 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
967 delete pResponseEvent;
968 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
973 SysLog(NID_APP, "Invalid ResponseListener");
978 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);