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);
216 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
217 if (pListener == null)
219 SysLog(NID_APP, "Empty AppControl listener callback for req %d, app %ls.", reqId, appId.GetPointer());
223 result r = E_SUCCESS;
225 AppId actualAppId = appId;
229 r = E_OPERATION_CANCELED;
231 SysLog(NID_APP, "Invoking callback 0x%x.", pListener);
233 _AppControlResponseEvent* pResponseEvent = null;
234 __appControlResponseEventContainer.GetValue(reqId, pResponseEvent);
235 SysLog(NID_APP, "StartResponseReceived Request Id(%d), ResponseEvent 0x%x.", reqId, pResponseEvent);
236 if (pResponseEvent != null)
238 String oId(operationId);
239 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_START, actualAppId, oId, r, APP_CTRL_RESULT_SUCCEEDED, null, reqId, false);
241 if (pResponseEventArg != null)
243 pResponseEvent->Fire(*pResponseEventArg);
244 SysLog(NID_APP, "pResponseEvent is Fired");
249 pListener->OnAppControlStartResponseReceived(actualAppId, operationId, r);
250 SysLog(NID_APP, "OnAppControlStartResponseReceived called directly");
253 if (r == E_OPERATION_CANCELED)
255 SysLog(NID_APP, "Removed start listener as operation is canceled.");
256 __inAppManager.RemoveItem(reqId);
262 _AppControlManager::InvokeAppControlCompleteListener(IAppControlResponseListener& listener, const AppId& appId, const String& op, AppCtrlResult res, const IMap* pExtraData, bool noRaise)
264 listener.OnAppControlCompleteResponseReceived(appId, op, res, pExtraData);
268 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
271 SysLog(NID_APP, "AppControl response finished.");
276 _AppControlManager::InvokeLegacyAppControlCompleteListener(IAppControlEventListener& listener, const AppId& appId, const String& op, const IList* pList, bool noRaise)
278 listener.OnAppControlCompleted(appId, op, pList);
282 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
285 SysLog(NID_APP, "Legacy AppControl response finished.");
289 // callback for in-process event handling
291 _AppControlManager::OnAppControlPluginEventReceivedN(int reqId, int res, const AppId& optAppId, const String& optOperation, const IMap* pArgs, int property)
293 SysLog(NID_APP, "Received request Id %d, res %d, args 0x%x", reqId, res, pArgs);
295 // process proper callback
296 _InProcessInfo* pInfo = __inAppManager.FindItem(reqId);
297 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with args 0x%x", reqId,
300 if (pInfo->pListener)
305 if (optAppId.IsEmpty())
307 aId = pInfo->providerId;
308 oId = pInfo->operationId;
312 // implicit launch only
316 SysLog(NID_APP, "Changing appId/operation for implicit launch.");
319 SysLog(NID_APP, "Invoking callback 0x%x for (%ls, %ls).", pInfo->pListener, aId.GetPointer(), oId.GetPointer());
321 const bool isSubMode = (property & _APPCONTROL_PROPERTY_SUBMODE);
322 const bool isServiceCallee = (property & _APPCONTROL_PROPERTY_SERVICE_CALLEE);
326 IAppControlEventListener* pListener = dynamic_cast<IAppControlEventListener*>(pInfo->pListener);
329 ArrayList list(SingleObjectDeleter);
330 _AppArg::FillLegacyAppControlResult(list, res, pArgs, aId);
332 InvokeLegacyAppControlCompleteListener(*pListener, aId, oId, &list, isSubMode | isServiceCallee);
336 SysLog(NID_APP, "Wrong AppControl listener type.");
341 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
344 _AppControlResponseEvent* pResponseEvent = null;
345 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + reqId;
346 __appControlResponseEventContainer.GetValue(responseEventRequestId, pResponseEvent);
348 if (pResponseEvent != null)
350 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, aId, oId, E_SUCCESS, static_cast<AppCtrlResult>(res), const_cast<IMap*> (pArgs), responseEventRequestId, isSubMode);
351 if (pResponseEventArg != null)
353 pResponseEvent->Fire(*pResponseEventArg);
354 SysLog(NID_APP, "pResponseEvent is Fired");
359 InvokeAppControlCompleteListener(*pListener, aId, oId, ConvertAppControlResultCode(res), pArgs, isSubMode | isServiceCallee);
360 SysLog(NID_APP, "Listener called directly");
366 SysLog(NID_APP, "Wrong AppControl listener type.");
372 SysLog(NID_APP, "Empty AppControl listener.");
376 // remove from list and unload dll
377 __inAppManager.RemoveItem(reqId);
382 _AppControlManager::SendAppControlEvent(IEventArg& arg)
384 return __appControlEvent.FireAsync(arg);
387 Tizen::Base::Collection::IMapT<int,_AppControlResponseEvent*>*
388 _AppControlManager::GetAppControlResponseEventContainer(void)
390 return &__appControlResponseEventContainer;
395 IsMatchingProcListener(const _InProcessInfo& info, IEventListener* pListener)
397 return (info.pListener == pListener);
402 _AppControlManager::StopAppControlResponseListener(IAppControlResponseListener* pListener)
404 // __inAppManager, __launchManager
405 _InProcessInfo* pProcInfo = __inAppManager.FindItemWithListener(IsMatchingProcListener, pListener);
408 pProcInfo->pListener = null;
409 SysLog(NID_APP, "Listener 0x%x is removed from in-process stub list.", pListener);
414 // generic launch callback
416 LaunchResultCb(bundle* b, int request_code, appsvc_result_val res, void* data)
418 SysLog(NID_APP, "SLP callee result: %d", res);
420 _AppControlManager* pImpl = static_cast<_AppControlManager*>(data);
426 _AppArg* pAppArg = new (std::nothrow) _AppArg;
427 SysTryReturnVoidResult(NID_APP, pAppArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
429 _AppControlEventArg* pArg = null;
430 result r = pAppArg->Construct(b);
431 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] AppControl event argument creation failure.", GetErrorMessage(r));
433 pArg = new (std::nothrow) _AppControlEventArg(request_code, pAppArg, res);
434 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
437 pImpl->SendAppControlEvent(*pArg);
447 _AppControlManager::SendAppControlStartResponse(int req, const char* pValue, const char* pOp)
449 _AppControlStartEventArg* pArg = new (std::nothrow) _AppControlStartEventArg(req, AppId(pValue), String(pOp));
450 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "AppControl start event creation failure.");
452 SendAppControlEvent(*pArg);
459 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
461 bundle* kb = msg.GetBundle();
465 appsvc_set_pkgname(kb, pkg_name);
468 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
472 appsvc_set_mime(kb, mime);
477 appsvc_set_uri(kb, uri);
480 int pid = LaunchPkg(msg, pCb, data);
482 result r = E_SUCCESS;
493 _AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
495 bundle* kb = msg.GetBundle();
496 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
500 appsvc_set_pkgname(kb, pkg_name);
503 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
507 appsvc_set_mime(kb, mime);
512 appsvc_set_uri(kb, uri);
515 if (_AppImpl::GetInstance() != null)
517 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
518 _AppArg::UpdateWindowHandle(kb, handle);
521 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
522 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
524 result r = E_SUCCESS;
529 case APPSVC_RET_EILLACC:
530 r = E_ILLEGAL_ACCESS;
532 case APPSVC_RET_EINVAL:
539 SysLog(NID_APP, "[%s]Launching service %s failure", GetErrorMessage(r), pkg_name);
548 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, AppSvcResFn pCb, void* data)
550 bundle* kb = msg.GetBundle();
551 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
553 if (_AppImpl::GetInstance() != null)
555 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
556 _AppArg::UpdateWindowHandle(kb, handle);
559 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
561 result r = E_SUCCESS;
566 case APPSVC_RET_EILLACC:
567 r = E_ILLEGAL_ACCESS;
569 case APPSVC_RET_EINVAL:
576 SysLog(NID_APP, "[%s] Launching service %s failure", GetErrorMessage(r), appsvc_get_appid(kb));
585 _AppControlManager::LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
589 return LaunchPkg(msg, pkg_name, op, mime, uri, pCb, data);
593 _AppControlManager::LaunchAppWithCondition(const AppId& appId, const String& condition, IList* pArrayArgs)
595 result r = E_SUCCESS;
596 _AppArg * pArg = new (std::nothrow) _AppArg();
597 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
599 r = pArg->ConstructForAppLaunchCondition(condition, pArrayArgs);
600 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] ConstructForAppLaunchCondition(%ls, .. ) fails", GetErrorMessage(r), condition.GetPointer());
602 r = _AppControlManager::LaunchApp(appId, pArg);
609 _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
611 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
612 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
614 String actualAppId = appId;
615 if (appId.GetLength() == 10)
617 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
621 actualAppId.Append(L'.');
622 actualAppId.Append(name);
626 pArg->UpdateRequestId(req);
628 if (_AppImpl::GetInstance() != null)
630 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
631 pArg->UpdateWindowHandle(handle);
637 std::unique_ptr< PackageAppInfo > pAppInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
638 SysTryReturn(NID_APP, pAppInfo != null, E_SYSTEM, GetLastResult(), "[%s] Getting AppInfo failed.", GetErrorMessage(GetLastResult()));
639 _PackageAppInfoImpl* pAppInfoImpl = _PackageAppInfoImpl::GetInstance(pAppInfo.get());
640 SysTryReturnResult(NID_APP, pAppInfoImpl != null , E_SYSTEM, "Severe system error");
642 if (pAppInfoImpl->IsServiceApp() == false)
645 actualAppId.SubString(0, 10, tempId);
647 tempId += String(SUBMODE_NAME);
649 // [INFO] Ugly solution for submode support
650 pArg->UpdateAppId(tempId);
651 kb = pArg->GetBundle();
653 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
656 SysLog(NID_APP, "Submode launch successful");
659 else if (pid == APPSVC_RET_EINVAL)
661 SysLog(NID_APP, "Argument overflow");
662 return E_MAX_EXCEEDED;
666 pArg->UpdateAppId(actualAppId);
668 // retry for possible failure
670 const int TRY_COUNT = 3;
671 const int TRY_SLEEP_TIME = 65;
674 kb = pArg->GetBundle();
675 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
678 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
681 else if (pid == APPSVC_RET_EINVAL)
683 SysLog(NID_APP, "Argument overflow");
684 return E_MAX_EXCEEDED;
688 SysLog(NID_APP, "Waiting %dth time.", count);
689 Thread::Sleep(TRY_SLEEP_TIME);
691 while (count < TRY_COUNT);
693 result r = E_SUCCESS;
696 case APPSVC_RET_EILLACC:
697 r = E_ILLEGAL_ACCESS;
704 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
710 _IsDefaultApplication(const AppId& packageId, const String& appId)
712 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
715 result r = appId.IndexOf(L'.', 0, index);
722 appId.SubString(index + 1, tmp);
725 SysLog(NID_APP, "Default application %ls", tmp.GetPointer());
734 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
736 return Launch(appId, pArg, reinterpret_cast<AppSvcResFn>(LaunchResultCb), this, req);
741 _AppControlManager::Launch(const _AppMessageImpl& msg, AppSvcResFn pCb, void* pData, int req)
743 const bundle* pBundle = msg.GetBundle();
746 arg.Construct(pBundle);
748 return Launch(_AppMessageImpl::GetApplicationId(pBundle), &arg, pCb, pData, req);
753 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, AppSvcResFn pCb, void* pData, int req)
755 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid launch argument");
756 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
758 String actualAppId = appId;
760 pArg->UpdateRequestId(req);
762 if (_AppImpl::GetInstance() != null)
764 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
765 pArg->UpdateWindowHandle(handle);
772 actualAppId.SubString(0, 10, tempId);
774 const int type = _AppInfo::GetAppType();
775 if ((!(type & _APP_TYPE_SERVICE_APP)) && _IsDefaultApplication(tempId, appId))
778 tempId += String(SUBMODE_NAME);
780 // [INFO] Ugly solution for submode support
781 pArg->UpdateAppId(tempId);
782 kb = pArg->GetBundle();
784 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
787 SysLog(NID_APP, "Submode launch successful");
788 SetLastResult(E_SUCCESS);
791 else if (pid == APPSVC_RET_EINVAL)
793 SetLastResult(E_MAX_EXCEEDED);
798 pArg->UpdateAppId(actualAppId);
800 // retry for possible failure
802 const int TRY_COUNT = 3;
803 const int TRY_SLEEP_TIME = 65;
806 kb = pArg->GetBundle();
807 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
810 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
811 SetLastResult(E_SUCCESS);
814 else if (pid == APPSVC_RET_EINVAL)
816 SetLastResult(E_MAX_EXCEEDED);
821 SysLog(NID_APP, "Waiting %dth time with %d.", count, pid);
822 Thread::Sleep(TRY_SLEEP_TIME);
824 while (count < TRY_COUNT);
826 result r = E_SUCCESS;
829 case APPSVC_RET_EILLACC:
830 r = E_ILLEGAL_ACCESS;
837 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
846 _AppControlManager::FinishAppControl(int reqId, int res, IMap* pMap)
848 SysLog(NID_APP, "req %d, res %d.", reqId, res);
849 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, pMap, _APPCONTROL_PROPERTY_SUBMODE);
850 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
852 SendAppControlEvent(*pArg);
857 _AppControlManager::FinishAppControl(int reqId, int res, const AppId& appId, const String& oId, IMap* pMap, int prop)
859 SysLog(NID_APP, "req %d, res %d, appId(%ls), oId(%ls).", reqId, res, appId.GetPointer(), oId.GetPointer());
860 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, appId, oId, pMap, prop);
861 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
863 SendAppControlEvent(*pArg);
868 _AppControlManager::RemoveResultRequest(int reqId)
870 __resultManager.RemoveItem(reqId);
874 _AppControlManager::FindResultRequest(int reqId) const
876 const _ResultInfo* pInfo = __resultManager.FindItem(reqId);
877 return (pInfo) ? &(pInfo->arg) : null;
881 _AppControlManager::AddLaunchRequest(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
883 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
885 _DataControlInfo* pItem = new (std::nothrow) _DataControlInfo(pArg, pCb, pData, prop);
886 SysTryReturn(NID_APP, pItem != null, -1, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
888 SysLog(NID_APP, "Registering callback 0x%x, 0x%x", pCb, pData);
890 return __launchManager.InsertItem(pItem);
894 _AppControlManager::RemoveLaunchRequest(int req)
896 __launchManager.RemoveItem(req);
900 _AppControlManager::RegisterRequest(service_s* service, int& req, _AppHandler& handler)
902 bundle* b = _AppArg::GetBundleFromSvc(service);
904 _AppArg* pArg = new (std::nothrow) _AppArg();
905 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
908 result r = E_SUCCESS;
910 // ownership is transfered to RequestManager
911 _ResultInfo* pItem = new (std::nothrow) _ResultInfo(*pArg);
912 SysTryCatch(NID_APP, pItem != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
914 req = __resultManager.InsertItem(pItem);
915 SysTryCatch(NID_APP, req != -1, , r = E_INVALID_STATE, "[E_INVALID_STATE] Invalid argument handling state.");
917 handler = _AppArg::GetHandler(b);
929 _AppControlManager::ConvertAppControlResultCode(int resCode)
931 AppCtrlResult ret = APP_CTRL_RESULT_FAILED;
935 case SERVICE_RESULT_SUCCEEDED:
936 ret = APP_CTRL_RESULT_SUCCEEDED;
938 case SERVICE_RESULT_FAILED:
939 ret = APP_CTRL_RESULT_CANCELED;
941 case SERVICE_RESULT_CANCELED:
942 ret = APP_CTRL_RESULT_ABORTED;
944 case APPSVC_OSP_RES_FAIL:
945 ret = APP_CTRL_RESULT_FAILED;
947 case APPSVC_OSP_RES_TERMINATE:
948 ret = APP_CTRL_RESULT_TERMINATED;
951 ret = APP_CTRL_RESULT_FAILED;
960 _AppControlManager::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
962 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
964 if (pEventArg != null)
966 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
968 if(pResponseListener != null)
970 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_START)
972 pResponseListener->OnAppControlStartResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetResult());
973 SysLog(NID_APP, "OnAppControlStartResponseReceived called");
977 InvokeAppControlCompleteListener(*pResponseListener, pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData(), pEventArg->IsSubMode());
978 SysLog(NID_APP, "Listener called");
980 _AppControlResponseEvent* pResponseEvent = null;
981 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
982 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
984 delete pResponseEvent;
985 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
990 SysLog(NID_APP, "Invalid ResponseListener");
995 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);