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 <FBaseSysLog.h>
48 #include <FBase_StringConverter.h>
49 #include <FIo_DataControlResultSetImpl.h>
51 #include "FApp_AppArg.h"
52 #include "FApp_AppControlEventArg.h"
53 #include "FApp_AppControlRegistry.h"
54 #include "FApp_AppControlImpl.h"
55 #include "FApp_AppImpl.h"
56 #include "FApp_AppInfo.h"
58 #include "FApp_AppControlManager.h"
59 #include "FApp_AppManagerProxy.h"
60 #include "FApp_ConditionManagerProxy.h"
61 #include "FApp_MapDataControlImpl.h"
62 #include "FApp_SqlDataControlImpl.h"
63 #include "FAppPkg_PackageManagerImpl.h"
64 #include "FAppPkg_PackageInfoImpl.h"
65 #include "FApp_AppMessageImpl.h"
66 #include "FApp_AppManagerImpl.h"
67 #include "FApp_AppControlResponseEvent.h"
68 #include "FApp_IAppControlPluginProvider.h"
71 using namespace Tizen::App::Package;
72 using namespace Tizen::Base;
73 using namespace Tizen::Base::Collection;
74 using namespace Tizen::Base::Runtime;
75 using namespace Tizen::Base::Utility;
76 using namespace Tizen::Io;
79 namespace Tizen { namespace App
82 const wchar_t TIZEN_OPERATION_PICK[] = L"http://tizen.org/appcontrol/operation/pick";
83 const wchar_t TIZEN_OPERATION_MAIN[] = L"http://tizen.org/appcontrol/operation/main";
84 const wchar_t LEGACY_OPERATION_MAIN[] = L"osp.operation.MAIN";
85 const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
87 _AppControlManager::_AppControlManager(void)
91 // AppControl event handling is expected to be performed in the main thread.
92 __appControlEvent.Construct();
93 __appControlEvent.AddListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
94 __appControlResponseEventContainer.Construct();
95 __appControlResponseEventList.Construct();
98 _AppControlManager::~_AppControlManager(void)
101 __appControlEvent.RemoveListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
102 IEnumeratorT<int>* pEnum = __appControlResponseEventList.GetEnumeratorN();
106 while(pEnum->MoveNext() == E_SUCCESS)
109 pEnum->GetCurrent(reqId);
110 _AppControlResponseEvent* pResponseEvent = null;
111 __appControlResponseEventContainer.GetValue(reqId, pResponseEvent);
112 delete pResponseEvent;
114 __appControlResponseEventContainer.Remove(reqId);
115 SysLog(NID_APP, "pResponseEvent gets deleted. reqId(%d)", reqId);
122 _AppControlManager::GetInstance(void)
124 static _AppControlManager inst;
130 _AppControlManager::GetMimeFromExt(const String& ext, String& out)
132 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(ext));
133 SysTryReturnResult(NID_APP, pExtension != null, E_OUT_OF_MEMORY, "String allocation failure.");
136 mime_type_get_mime_type(pExtension.get(), &mime);
138 SysTryReturnResult(NID_APP, mime != NULL, E_UNSUPPORTED_FORMAT, "MIME type conversion failure for %ls.", ext.GetPointer());
147 _AppControlManager::OnAppControlEventReceivedN(int reqId, _AppArg* pAppArg, int res)
149 SysLog(NID_APP, "Received request Id %d, arg 0x%x", reqId, pAppArg);
152 // get launch info from request Id
153 _DataControlInfo* pInfo = __launchManager.FindItem(reqId);
154 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with response %d", reqId,
160 if (pInfo->magic == LAUNCH_INFO_MAGIC)
162 SysLog(NID_APP, "Invoking callback 0x%x", pInfo->launchCb);
165 if (pInfo->pUserData)
167 (*pInfo->launchCb)(pInfo->pUserData, pInfo->pArg, pAppArg, static_cast<service_result_e>(res), pInfo->property, reqId);
172 SysLogException(NID_APP, E_SYSTEM, "Corrupted data structure.");
177 __launchManager.RemoveItem(reqId);
181 // callback for AppControl start event
183 _AppControlManager::OnAppControlEventReceivedN(int reqId, const AppId& appId, const String& operationId)
185 SysLog(NID_APP, "Received request Id %d, app %ls, operationId %ls", reqId, appId.GetPointer(), operationId.GetPointer());
187 // get launch info from request Id
188 _InProcessInfo* pInfo = __inAppManager.FindItem(reqId);
189 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found.", reqId);
192 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
193 SysTryReturnVoidResult(NID_APP, pListener != null, E_SYSTEM, "[E_SYSTEM] Invalid result callback for req %d, app %ls.", reqId, appId.GetPointer());
195 result r = E_SUCCESS;
199 AppId actualAppId = appId;
203 r = E_OPERATION_CANCELED;
205 SysLog(NID_APP, "Invoking callback 0x%x.", pListener);
207 _AppControlResponseEvent* pResponseEvent = null;
208 __appControlResponseEventContainer.GetValue(reqId, pResponseEvent);
209 SysLog(NID_APP, "StartResponseReceived Request Id(%d), ResponseEvent 0x%x.", reqId, pResponseEvent);
210 if (pResponseEvent != null)
212 String oId(operationId);
213 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_START, actualAppId, oId, r, APP_CTRL_RESULT_SUCCEEDED, null, reqId, false);
215 if (pResponseEventArg != null)
217 pResponseEvent->Fire(*pResponseEventArg);
218 SysLog(NID_APP, "pResponseEvent is Fired");
223 pListener->OnAppControlStartResponseReceived(actualAppId, operationId, r);
224 SysLog(NID_APP, "OnAppControlStartResponseReceived called directly");
229 SysLog(NID_APP, "No listener registered.");
232 if (r == E_OPERATION_CANCELED)
234 SysLog(NID_APP, "Removed start listener as operation is canceled.");
235 __inAppManager.RemoveItem(reqId);
241 _AppControlManager::InvokeAppControlCompleteListener(IAppControlResponseListener& listener, const AppId& appId, const String& op, AppCtrlResult res, const IMap* pExtraData, bool noRaise)
243 listener.OnAppControlCompleteResponseReceived(appId, op, res, pExtraData);
247 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
250 SysLog(NID_APP, "AppControl response finished.");
255 _AppControlManager::InvokeLegacyAppControlCompleteListener(IAppControlEventListener& listener, const AppId& appId, const String& op, const IList* pList, bool noRaise)
257 listener.OnAppControlCompleted(appId, op, pList);
261 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
264 SysLog(NID_APP, "Legacy AppControl response finished.");
268 // callback for in-process event handling
270 _AppControlManager::OnAppControlPluginEventReceivedN(int reqId, int res, const AppId& optAppId, const String& optOperation, const IMap* pArgs, int property)
272 SysLog(NID_APP, "Received request Id %d, res %d, args 0x%x", reqId, res, pArgs);
274 // process proper callback
275 _InProcessInfo* pInfo = __inAppManager.FindItem(reqId);
276 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with args 0x%x", reqId,
279 if (pInfo->pListener)
284 if (optAppId.IsEmpty())
286 aId = pInfo->providerId;
287 oId = pInfo->operationId;
291 // implicit launch only
295 SysLog(NID_APP, "Changing appId/operation for implicit launch.");
298 SysLog(NID_APP, "Invoking callback 0x%x for (%ls, %ls).", pInfo->pListener, aId.GetPointer(), oId.GetPointer());
300 const bool isSubMode = (property & _APPCONTROL_PROPERTY_SUBMODE);
301 const bool isServiceCallee = (property & _APPCONTROL_PROPERTY_SERVICE_CALLEE);
305 IAppControlEventListener* pListener = dynamic_cast<IAppControlEventListener*>(pInfo->pListener);
308 ArrayList list(SingleObjectDeleter);
309 _AppArg::FillLegacyAppControlResult(list, res, pArgs, aId);
311 InvokeLegacyAppControlCompleteListener(*pListener, aId, oId, &list, isSubMode | isServiceCallee);
315 SysLog(NID_APP, "Wrong AppControl listener type.");
320 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
323 _AppControlResponseEvent* pResponseEvent = null;
324 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + reqId;
325 __appControlResponseEventContainer.GetValue(responseEventRequestId, pResponseEvent);
327 if (pResponseEvent != null)
329 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, aId, oId, E_SUCCESS, static_cast<AppCtrlResult>(res), const_cast<IMap*> (pArgs), responseEventRequestId, isSubMode);
330 if (pResponseEventArg != null)
332 pResponseEvent->Fire(*pResponseEventArg);
333 SysLog(NID_APP, "pResponseEvent is Fired");
338 InvokeAppControlCompleteListener(*pListener, aId, oId, ConvertAppControlResultCode(res), pArgs, isSubMode | isServiceCallee);
339 SysLog(NID_APP, "Listener called directly");
345 SysLog(NID_APP, "Wrong AppControl listener type.");
351 SysLogException(NID_APP, E_SYSTEM, "Invalid AppControl listener.");
355 // [FIXME] following logic is not needed.
356 // call TerminateAppControl
357 if (pInfo->pProvider)
359 pInfo->pProvider->StopAppControlPlugin(pInfo->reqId);
360 SysLog(NID_APP, "AppControl stopped for req %d.", pInfo->reqId);
364 // remove from list and unload dll
365 __inAppManager.RemoveItem(reqId);
370 _AppControlManager::SendAppControlEvent(IEventArg& arg)
372 return __appControlEvent.FireAsync(arg);
375 Tizen::Base::Collection::IMapT<int,_AppControlResponseEvent*>*
376 _AppControlManager::GetAppControlResponseEventContainer(void)
378 return &__appControlResponseEventContainer;
383 IsMatchingProcListener(const _InProcessInfo& info, IEventListener* pListener)
385 return (info.pListener == pListener);
390 _AppControlManager::StopAppControlResponseListener(IAppControlResponseListener* pListener)
392 // __inAppManager, __launchManager
393 _InProcessInfo* pProcInfo = __inAppManager.FindItemWithListener(IsMatchingProcListener, pListener);
396 __inAppManager.RemoveItem(pProcInfo);
397 SysLog(NID_APP, "Listener 0x%x is removed from in-process stub list.", pListener);
402 // generic launch callback
404 LaunchResultCb(bundle* b, int request_code, appsvc_result_val res, void* data)
406 SysLog(NID_APP, "SLP callee result: %d", res);
408 _AppControlManager* pImpl = static_cast<_AppControlManager*>(data);
414 _AppArg* pAppArg = new (std::nothrow) _AppArg;
415 SysTryReturnVoidResult(NID_APP, pAppArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
417 _AppControlEventArg* pArg = null;
418 result r = pAppArg->Construct(b);
419 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] AppControl event argument creation failure.", GetErrorMessage(r));
421 pArg = new (std::nothrow) _AppControlEventArg(request_code, pAppArg, res);
422 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
425 pImpl->SendAppControlEvent(*pArg);
435 _AppControlManager::SendAppControlStartResponse(int req, const char* pValue, const char* pOp)
437 _AppControlStartEventArg* pArg = new (std::nothrow) _AppControlStartEventArg(req, AppId(pValue), String(pOp));
438 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "AppControl start event creation failure.");
440 SendAppControlEvent(*pArg);
447 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
449 bundle* kb = msg.GetBundle();
453 appsvc_set_pkgname(kb, pkg_name);
456 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
460 appsvc_set_mime(kb, mime);
465 appsvc_set_uri(kb, uri);
468 int pid = LaunchPkg(msg, pCb, data);
470 result r = E_SUCCESS;
481 _AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
483 bundle* kb = msg.GetBundle();
484 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
488 appsvc_set_pkgname(kb, pkg_name);
491 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
495 appsvc_set_mime(kb, mime);
500 appsvc_set_uri(kb, uri);
503 if (_AppImpl::GetInstance() != null)
505 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
506 _AppArg::UpdateWindowHandle(kb, handle);
509 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
510 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
512 result r = E_SUCCESS;
517 case APPSVC_RET_EILLACC:
518 r = E_ILLEGAL_ACCESS;
520 case APPSVC_RET_EINVAL:
527 SysLog(NID_APP, "[%s]Launching service %s failure", GetErrorMessage(r), pkg_name);
536 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, AppSvcResFn pCb, void* data)
538 bundle* kb = msg.GetBundle();
539 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
541 if (_AppImpl::GetInstance() != null)
543 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
544 _AppArg::UpdateWindowHandle(kb, handle);
547 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
549 result r = E_SUCCESS;
554 case APPSVC_RET_EILLACC:
555 r = E_ILLEGAL_ACCESS;
557 case APPSVC_RET_EINVAL:
564 SysLog(NID_APP, "[%s] Launching service %s failure", GetErrorMessage(r), appsvc_get_appid(kb));
573 _AppControlManager::LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
577 return LaunchPkg(msg, pkg_name, op, mime, uri, pCb, data);
581 _AppControlManager::LaunchAppWithCondition(const AppId& appId, const String& condition, IList* pArrayArgs)
583 result r = E_SUCCESS;
584 _AppArg * pArg = new (std::nothrow) _AppArg();
585 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
587 r = pArg->ConstructForAppLaunchCondition(condition, pArrayArgs);
588 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] ConstructForAppLaunchCondition(%ls, .. ) fails", GetErrorMessage(r), condition.GetPointer());
590 r = _AppControlManager::LaunchApp(appId, pArg);
597 _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
599 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
600 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
602 String actualAppId = appId;
603 if (appId.GetLength() == 10)
605 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
609 actualAppId.Append(L'.');
610 actualAppId.Append(name);
614 pArg->UpdateRequestId(req);
616 if (_AppImpl::GetInstance() != null)
618 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
619 pArg->UpdateWindowHandle(handle);
625 actualAppId.SubString(0, 10, tempId);
627 tempId += L"_AppControl";
629 // [INFO] Ugly solution for submode support
630 pArg->UpdateAppId(tempId);
631 kb = pArg->GetBundle();
633 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
636 SysLog(NID_APP, "Submode launch successful");
639 else if (pid == APPSVC_RET_EINVAL)
641 SysLog(NID_APP, "Argument overflow");
642 return E_MAX_EXCEEDED;
645 pArg->UpdateAppId(actualAppId);
647 // retry for possible failure
649 const int TRY_COUNT = 3;
650 const int TRY_SLEEP_TIME = 65;
653 kb = pArg->GetBundle();
654 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
657 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
660 else if (pid == APPSVC_RET_EINVAL)
662 SysLog(NID_APP, "Argument overflow");
663 return E_MAX_EXCEEDED;
667 SysLog(NID_APP, "Waiting %dth time.", count);
668 Thread::Sleep(TRY_SLEEP_TIME);
670 while (count < TRY_COUNT);
672 result r = E_SUCCESS;
675 case APPSVC_RET_EILLACC:
676 r = E_ILLEGAL_ACCESS;
683 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
689 _IsDefaultApplication(const AppId& packageId, const String& appId)
691 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
694 result r = appId.IndexOf(L'.', 0, index);
701 appId.SubString(index + 1, tmp);
704 SysLog(NID_APP, "Default application %ls", tmp.GetPointer());
713 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
715 return Launch(appId, pArg, reinterpret_cast<AppSvcResFn>(LaunchResultCb), this, req);
720 _AppControlManager::Launch(const _AppMessageImpl& msg, AppSvcResFn pCb, void* pData, int req)
722 const bundle* pBundle = msg.GetBundle();
725 arg.Construct(pBundle);
727 return Launch(_AppMessageImpl::GetApplicationId(pBundle), &arg, pCb, pData, req);
732 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, AppSvcResFn pCb, void* pData, int req)
734 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid launch argument");
735 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
737 String actualAppId = appId;
739 pArg->UpdateRequestId(req);
741 if (_AppImpl::GetInstance() != null)
743 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
744 pArg->UpdateWindowHandle(handle);
751 actualAppId.SubString(0, 10, tempId);
753 const int type = _AppInfo::GetAppType();
754 if ((!(type & _APP_TYPE_SERVICE_APP)) && _IsDefaultApplication(tempId, appId))
757 tempId += L"_AppControl";
759 // [INFO] Ugly solution for submode support
760 pArg->UpdateAppId(tempId);
761 kb = pArg->GetBundle();
763 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
766 SysLog(NID_APP, "Submode launch successful");
767 SetLastResult(E_SUCCESS);
770 else if (pid == APPSVC_RET_EINVAL)
772 SetLastResult(E_MAX_EXCEEDED);
777 pArg->UpdateAppId(actualAppId);
779 // retry for possible failure
781 const int TRY_COUNT = 3;
782 const int TRY_SLEEP_TIME = 65;
785 kb = pArg->GetBundle();
786 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
789 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
790 SetLastResult(E_SUCCESS);
793 else if (pid == APPSVC_RET_EINVAL)
795 SetLastResult(E_MAX_EXCEEDED);
800 SysLog(NID_APP, "Waiting %dth time with %d.", count, pid);
801 Thread::Sleep(TRY_SLEEP_TIME);
803 while (count < TRY_COUNT);
805 result r = E_SUCCESS;
808 case APPSVC_RET_EILLACC:
809 r = E_ILLEGAL_ACCESS;
816 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
825 _AppControlManager::FinishAppControl(int reqId, int res, IMap* pMap)
827 SysLog(NID_APP, "req %d, res %d.", reqId, res);
828 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, pMap, _APPCONTROL_PROPERTY_SUBMODE);
829 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
831 SendAppControlEvent(*pArg);
836 _AppControlManager::FinishAppControl(int reqId, int res, const AppId& appId, const String& oId, IMap* pMap, int prop)
838 SysLog(NID_APP, "req %d, res %d, appId(%ls), oId(%ls).", reqId, res, appId.GetPointer(), oId.GetPointer());
839 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, appId, oId, pMap, prop);
840 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
842 SendAppControlEvent(*pArg);
847 _AppControlManager::RemoveResultRequest(int reqId)
849 __resultManager.RemoveItem(reqId);
853 _AppControlManager::FindResultRequest(int reqId) const
855 const _ResultInfo* pInfo = __resultManager.FindItem(reqId);
856 return (pInfo) ? &(pInfo->arg) : null;
860 _AppControlManager::AddLaunchRequest(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
862 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
864 _DataControlInfo* pItem = new (std::nothrow) _DataControlInfo(pArg, pCb, pData, prop);
865 SysTryReturn(NID_APP, pItem != null, -1, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
867 SysLog(NID_APP, "Registering callback 0x%x, 0x%x", pCb, pData);
869 return __launchManager.InsertItem(pItem);
873 _AppControlManager::RemoveLaunchRequest(int req)
875 __launchManager.RemoveItem(req);
879 _AppControlManager::RegisterRequest(service_s* service, int& req, _AppHandler& handler)
881 bundle* b = _AppArg::GetBundleFromSvc(service);
883 _AppArg* pArg = new (std::nothrow) _AppArg();
884 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
887 result r = E_SUCCESS;
889 // ownership is transfered to RequestManager
890 _ResultInfo* pItem = new (std::nothrow) _ResultInfo(*pArg);
891 SysTryCatch(NID_APP, pItem != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
893 req = __resultManager.InsertItem(pItem);
894 SysTryCatch(NID_APP, req != -1, , r = E_INVALID_STATE, "[E_INVALID_STATE] Invalid argument handling state.");
896 handler = _AppArg::GetHandler(b);
908 _AppControlManager::ConvertAppControlResultCode(int resCode)
910 AppCtrlResult ret = APP_CTRL_RESULT_FAILED;
914 case SERVICE_RESULT_SUCCEEDED:
915 ret = APP_CTRL_RESULT_SUCCEEDED;
917 case SERVICE_RESULT_FAILED:
918 ret = APP_CTRL_RESULT_CANCELED;
920 case SERVICE_RESULT_CANCELED:
921 ret = APP_CTRL_RESULT_ABORTED;
923 case APPSVC_OSP_RES_FAIL:
924 ret = APP_CTRL_RESULT_FAILED;
926 case APPSVC_OSP_RES_TERMINATE:
927 ret = APP_CTRL_RESULT_TERMINATED;
930 ret = APP_CTRL_RESULT_FAILED;
939 _AppControlManager::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
941 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
943 if (pEventArg != null)
945 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
947 if(pResponseListener != null)
949 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_START)
951 pResponseListener->OnAppControlStartResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetResult());
952 SysLog(NID_APP, "OnAppControlStartResponseReceived called");
956 InvokeAppControlCompleteListener(*pResponseListener, pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData(), pEventArg->IsSubMode());
957 SysLog(NID_APP, "Listener called");
959 _AppControlResponseEvent* pResponseEvent = null;
960 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
961 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
963 delete pResponseEvent;
964 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
969 SysLog(NID_APP, "Invalid ResponseListener");
974 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);