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>
47 #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;
80 const char SELECTOR_NOTI_KEY[] = "__APP_SVC_CALLER_NOTI__";
83 namespace Tizen { namespace App
85 const wchar_t TIZEN_OPERATION_PICK[] = L"http://tizen.org/appcontrol/operation/pick";
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());
148 _AppControlManager::OnAppControlEventReceivedN(int reqId, _AppArg* pAppArg, int res)
150 SysLog(NID_APP, "Received request Id %d, arg 0x%x", reqId, pAppArg);
153 // get launch info from request Id
154 _LaunchInfo* pInfo = __launchManager.FindItem(reqId);
155 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with response %d", reqId,
161 if (pInfo->magic == LAUNCH_INFO_MAGIC)
163 SysLog(NID_APP, "Invoking callback 0x%x", pInfo->launchCb);
166 if (pInfo->pUserData)
168 (*pInfo->launchCb)(pInfo->pUserData, pInfo->pArg, pAppArg, static_cast<service_result_e>(res), pInfo->property, reqId);
173 SysLogException(NID_APP, E_SYSTEM, "Corrupted data structure.");
178 __launchManager.RemoveItem(reqId);
182 // callback for out-of-process AppControl start event
184 _AppControlManager::OnAppControlEventReceivedN(int reqId, const AppId& appId, const String& operationId)
186 SysLog(NID_APP, "Received request Id %d, app %ls, operationId %ls", reqId, appId.GetPointer(), operationId.GetPointer());
188 // get launch info from request Id
189 _LaunchInfo* pInfo = __launchManager.FindItem(reqId);
190 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found.", reqId);
193 IAppControlResponseListener* pListener = static_cast<IAppControlResponseListener*>(pInfo->pUserData);
194 SysTryReturnVoidResult(NID_APP, typeid(pListener) == typeid(IAppControlResponseListener*), E_SYSTEM, "[E_SYSTEM] Invalid result callback.");
198 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.");
235 _AppControlManager::InvokeAppControlCompleteListener(IAppControlResponseListener& listener, const AppId& appId, const String& op, AppCtrlResult res, const IMap* pExtraData, bool noRaise)
237 listener.OnAppControlCompleteResponseReceived(appId, op, res, pExtraData);
241 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
244 SysLog(NID_APP, "AppControl response finished.");
249 _AppControlManager::InvokeLegacyAppControlCompleteListener(IAppControlEventListener& listener, const AppId& appId, const String& op, const IList* pList, bool noRaise)
251 listener.OnAppControlCompleted(appId, op, pList);
255 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
258 SysLog(NID_APP, "Legacy AppControl response finished.");
262 // callback for in-process event handling
264 _AppControlManager::OnAppControlEventReceivedN(int reqId, int res, const IMap* pArgs, int property)
266 SysLog(NID_APP, "Received request Id %d, res %d, args 0x%x", reqId, res, pArgs);
268 // process proper callback
269 _InProcessInfo* pInfo = __inAppManager.FindItem(reqId);
270 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with args 0x%x", reqId,
273 if (pInfo->pListener)
275 String aId = pInfo->providerId;
276 String oId = pInfo->operationId;
278 SysLog(NID_APP, "Invoking callback 0x%x for (%ls, %ls).", pInfo->pListener, aId.GetPointer(), oId.GetPointer());
280 if (pInfo->property & _APPCONTROL_PROPERTY_ALIAS)
282 const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
283 pEntry = _AppControlRegistry::GetInstance()->GetReverseAppControlAliasEntry(aId, oId);
286 aId = pEntry->provider;
287 oId = pEntry->operation;
289 SysLog(NID_APP, "Legacy AppControl (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
293 const bool isSubMode = (property & _APPCONTROL_PROPERTY_SUBMODE);
294 const bool isServiceCallee = (property & _APPCONTROL_PROPERTY_SERVICE_CALLEE);
298 IAppControlEventListener* pListener = dynamic_cast<IAppControlEventListener*>(pInfo->pListener);
301 ArrayList list(SingleObjectDeleter);
302 _AppArg::FillLegacyAppControlResult(list, res, pArgs, aId);
304 InvokeLegacyAppControlCompleteListener(*pListener, aId, oId, &list, isSubMode | isServiceCallee);
308 SysLog(NID_APP, "Wrong AppControl listener type.");
313 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
316 _AppControlResponseEvent* pResponseEvent = null;
317 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + reqId;
318 __appControlResponseEventContainer.GetValue(responseEventRequestId, pResponseEvent);
320 if (pResponseEvent != null)
322 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, aId, oId, E_SUCCESS, static_cast<AppCtrlResult>(res), const_cast<IMap*> (pArgs), responseEventRequestId, isSubMode);
323 if (pResponseEventArg != null)
325 pResponseEvent->Fire(*pResponseEventArg);
326 SysLog(NID_APP, "pResponseEvent is Fired");
331 InvokeAppControlCompleteListener(*pListener, aId, oId, ConvertAppControlResultCode(res), pArgs, isSubMode | isServiceCallee);
332 SysLog(NID_APP, "Listener called directly");
338 SysLog(NID_APP, "Wrong AppControl listener type.");
344 SysLogException(NID_APP, E_SYSTEM, "Invalid AppControl listener.");
347 // call TerminateAppControl
348 if (pInfo->pProvider)
350 pInfo->pProvider->StopAppControlPlugin(pInfo->reqId);
351 SysLog(NID_APP, "AppControl stopped for req %d.", pInfo->reqId);
354 // remove from list and unload dll
355 __inAppManager.RemoveItem(reqId);
360 _AppControlManager::SendAppControlEvent(IEventArg& arg)
362 return __appControlEvent.FireAsync(arg);
365 Tizen::Base::Collection::IMapT<int,_AppControlResponseEvent*>*
366 _AppControlManager::GetAppControlResponseEventContainer(void)
368 return &__appControlResponseEventContainer;
373 IsMatchingProcListener(const _InProcessInfo& info, IEventListener* pListener)
375 return (info.pListener == pListener);
379 IsMatchingLaunchListener(const _LaunchInfo& info, IEventListener* pListener)
381 return (info.pUserData == pListener);
385 _AppControlManager::StopAppControlResponseListener(IAppControlResponseListener* pListener)
387 // __inAppManager, __launchManager
388 _InProcessInfo* pProcInfo = __inAppManager.FindItemWithListener(IsMatchingProcListener, pListener);
391 __inAppManager.RemoveItem(pProcInfo);
392 SysLog(NID_APP, "Listener 0x%x is removed from in-process stub list.", pListener);
395 _LaunchInfo* pLaunchInfo = __launchManager.FindItemWithListener(IsMatchingLaunchListener, pListener);
398 __launchManager.RemoveItem(pLaunchInfo);
399 SysLog(NID_APP, "Listener 0x%x is removed from launch request list.", pListener);
405 // generic launch callback
407 LaunchResultCb(bundle* b, int request_code, appsvc_result_val res, void* data)
409 SysLog(NID_APP, "SLP callee result: %d", res);
411 _AppControlManager* pImpl = static_cast<_AppControlManager*>(data);
417 _AppArg* pAppArg = new (std::nothrow) _AppArg;
418 SysTryReturnVoidResult(NID_APP, pAppArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
420 _AppControlEventArg* pArg = null;
421 result r = pAppArg->Construct(b);
422 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] AppControl event argument creation failure.", GetErrorMessage(r));
424 pArg = new (std::nothrow) _AppControlEventArg(request_code, pAppArg, res);
425 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
428 pImpl->SendAppControlEvent(*pArg);
438 _AppControlManager::SendAppControlStartResponse(int req, const char* pValue, const char* pOp)
440 _AppControlStartEventArg* pArg = new (std::nothrow) _AppControlStartEventArg(req, AppId(pValue), String(pOp));
441 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "AppControl start event creation failure.");
443 SendAppControlEvent(*pArg);
450 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
452 bundle* kb = msg.GetBundle();
453 SysTryReturnResult(NID_APP, kb != NULL, E_OUT_OF_MEMORY, "Bundle allocation failure.");
457 appsvc_set_pkgname(kb, pkg_name);
460 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
464 appsvc_set_mime(kb, mime);
469 appsvc_set_uri(kb, uri);
472 if (_AppImpl::GetInstance() != null)
474 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
475 _AppArg::UpdateWindowHandle(kb, handle);
478 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
479 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
481 result r = E_SUCCESS;
486 case APPSVC_RET_EILLACC:
487 r = E_ILLEGAL_ACCESS;
489 case APPSVC_RET_EINVAL:
496 SysLog(NID_APP, "[%s] Launching service %s failure", GetErrorMessage(r), pkg_name);
504 _AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
506 bundle* kb = msg.GetBundle();
507 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
511 appsvc_set_pkgname(kb, pkg_name);
514 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
518 appsvc_set_mime(kb, mime);
523 appsvc_set_uri(kb, uri);
526 if (_AppImpl::GetInstance() != null)
528 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
529 _AppArg::UpdateWindowHandle(kb, handle);
532 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
533 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
535 result r = E_SUCCESS;
540 case APPSVC_RET_EILLACC:
541 r = E_ILLEGAL_ACCESS;
543 case APPSVC_RET_EINVAL:
550 SysLog(NID_APP, "[%s]Launching service %s failure", GetErrorMessage(r), pkg_name);
559 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, AppSvcResFn pCb, void* data)
561 bundle* kb = msg.GetBundle();
562 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
564 if (_AppImpl::GetInstance() != null)
566 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
567 _AppArg::UpdateWindowHandle(kb, handle);
570 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
572 result r = E_SUCCESS;
577 case APPSVC_RET_EILLACC:
578 r = E_ILLEGAL_ACCESS;
580 case APPSVC_RET_EINVAL:
587 SysLog(NID_APP, "[%s] Launching service %s failure", GetErrorMessage(r), appsvc_get_appid(kb));
596 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const AppId& appId, const String& opId, const String* pUri, const String* pMime, AppSvcResFn pCb, void* data)
598 std::unique_ptr<char[]> pPackage(_StringConverter::CopyToCharArrayN(appId));
599 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(opId));
601 const char* pUriData = null;
604 pUriData = _StringConverter::CopyToCharArrayN(*pUri);
607 const char* pMimeData = null;
610 pMimeData = _StringConverter::CopyToCharArrayN(*pMime);
613 int pid = Launch(msg, pPackage.get(), pOperation.get(), pMimeData, pUriData, pCb, data);
623 _AppControlManager::LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
627 return LaunchPkg(msg, pkg_name, op, mime, uri, pCb, data);
631 _AppControlManager::LaunchAppWithCondition(const AppId& appId, const String& condition, IList* pArrayArgs)
633 result r = E_SUCCESS;
634 _AppArg * pArg = new (std::nothrow) _AppArg();
635 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
637 r = pArg->ConstructForAppLaunchCondition(condition, pArrayArgs);
638 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] ConstructForAppLaunchCondition(%ls, .. ) fails", GetErrorMessage(r), condition.GetPointer());
640 r = _AppControlManager::LaunchApp(appId, pArg);
647 _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
649 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
650 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
652 String actualAppId = appId;
653 if (appId.GetLength() == 10)
655 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
659 actualAppId.Append(L'.');
660 actualAppId.Append(name);
664 pArg->UpdateRequestId(req);
666 if (_AppImpl::GetInstance() != null)
668 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
669 pArg->UpdateWindowHandle(handle);
675 actualAppId.SubString(0, 10, tempId);
677 tempId += L"_AppControl";
679 // [INFO] Ugly solution for submode support
680 pArg->UpdateAppId(tempId);
681 kb = pArg->GetBundle();
683 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
686 SysLog(NID_APP, "Submode launch successful");
689 else if (pid == APPSVC_RET_EINVAL)
691 SysLog(NID_APP, "Argument overflow");
692 return E_MAX_EXCEEDED;
695 pArg->UpdateAppId(actualAppId);
697 // retry for possible failure
699 const int TRY_COUNT = 3;
700 const int TRY_SLEEP_TIME = 65;
703 kb = pArg->GetBundle();
704 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
707 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
710 else if (pid == APPSVC_RET_EINVAL)
712 SysLog(NID_APP, "Argument overflow");
713 return E_MAX_EXCEEDED;
717 SysLog(NID_APP, "Waiting %dth time.", count);
718 Thread::Sleep(TRY_SLEEP_TIME);
720 while (count < TRY_COUNT);
722 result r = E_SUCCESS;
725 case APPSVC_RET_EILLACC:
726 r = E_ILLEGAL_ACCESS;
733 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
739 _IsDefaultApplication(const AppId& packageId, const String& appId)
741 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
744 result r = appId.IndexOf(L'.', 0, index);
751 appId.SubString(index + 1, tmp);
754 SysLog(NID_APP, "Default application %ls", tmp.GetPointer());
763 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
765 return Launch(appId, pArg, reinterpret_cast<AppSvcResFn>(LaunchResultCb), this, req);
770 _AppControlManager::Launch(const _AppMessageImpl& msg, AppSvcResFn pCb, void* pData)
772 const bundle* pBundle = msg.GetBundle();
775 arg.Construct(pBundle);
777 return Launch(_AppMessageImpl::GetApplicationId(pBundle), &arg, pCb, pData, -1);
782 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, AppSvcResFn pCb, void* pData, int req)
784 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid launch argument");
785 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
787 String actualAppId = appId;
789 if (appId.GetLength() == 10)
791 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
793 if (!execName.IsEmpty())
795 actualAppId.Append(L'.');
796 actualAppId.Append(execName);
801 pArg->UpdateRequestId(req);
803 if (_AppImpl::GetInstance() != null)
805 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
806 pArg->UpdateWindowHandle(handle);
813 actualAppId.SubString(0, 10, tempId);
815 const int type = _AppInfo::GetAppType();
816 if ((!(type & _APP_TYPE_SERVICE_APP)) && _IsDefaultApplication(tempId, appId))
819 tempId += L"_AppControl";
821 // [INFO] Ugly solution for submode support
822 pArg->UpdateAppId(tempId);
823 kb = pArg->GetBundle();
825 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
828 SysLog(NID_APP, "Submode launch successful");
829 SetLastResult(E_SUCCESS);
832 else if (pid == APPSVC_RET_EINVAL)
834 SetLastResult(E_MAX_EXCEEDED);
839 pArg->UpdateAppId(actualAppId);
841 // retry for possible failure
843 const int TRY_COUNT = 3;
844 const int TRY_SLEEP_TIME = 65;
847 kb = pArg->GetBundle();
848 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
851 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
852 SetLastResult(E_SUCCESS);
855 else if (pid == APPSVC_RET_EINVAL)
857 SetLastResult(E_MAX_EXCEEDED);
862 SysLog(NID_APP, "Waiting %dth time with %d.", count, pid);
863 Thread::Sleep(TRY_SLEEP_TIME);
865 while (count < TRY_COUNT);
867 result r = E_SUCCESS;
870 case APPSVC_RET_EILLACC:
871 r = E_ILLEGAL_ACCESS;
878 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
886 _AppControlManager::LaunchAppImplicit(_AppArg* pArg, int req)
888 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
890 result r = E_SUCCESS;
891 bundle* kb = pArg->GetBundle();
895 pArg->UpdateRequestId(req);
896 appsvc_add_data(kb, SELECTOR_NOTI_KEY, appinfo_get_appid());
899 if (_AppImpl::GetInstance() != null)
901 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
902 _AppArg::UpdateWindowHandle(kb, handle);
905 int pid = appsvc_run_service(kb, req, LaunchResultCb, this);
910 SysLog(NID_APP, "Sending local process again.");
914 char pkgname[255] = {0, };
915 if (aul_app_get_pkgname_bypid(pid, pkgname, 255) != AUL_R_OK)
917 SysLog(NID_APP, "Fail to get package name by pid : (%d).", pid);
921 if (strncmp(pkgname, APP_SELECTOR, strlen(APP_SELECTOR)) != 0)
923 const char* pOperation = appsvc_get_operation(kb);
925 SysLog(NID_APP, "Starting application without selector : (%s, %s).", pkgname, pOperation);
927 SendAppControlStartResponse(req, pkgname, pOperation);
934 case APPSVC_RET_EINVAL:
937 case APPSVC_RET_ENOMATCH:
940 case APPSVC_RET_EILLACC:
941 r = E_ILLEGAL_ACCESS;
943 case APPSVC_RET_ERROR:
945 case APPSVC_RET_ELAUNCH:
953 SysLog(NID_APP, "[%s] Application(%d) launched with reqId(%d) and arg(0x%x).", GetErrorMessage(r), pid, req, pArg);
959 _AppControlManager::FinishAppControl(int reqId, int res, IMap* pMap)
961 SysLog(NID_APP, "req %d, res %d.", reqId, res);
962 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, pMap, _APPCONTROL_PROPERTY_SUBMODE);
963 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
965 SendAppControlEvent(*pArg);
966 SysLog(NID_APP, "Exit.");
970 _AppControlManager::RemoveResultRequest(int reqId)
972 __resultManager.RemoveItem(reqId);
976 _AppControlManager::FindResultRequest(int reqId) const
978 const _ResultInfo* pInfo = __resultManager.FindItem(reqId);
979 return (pInfo) ? &(pInfo->arg) : null;
983 _AppControlManager::AddLaunchRequest(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
985 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
987 _LaunchInfo* pItem = new (std::nothrow) _LaunchInfo(pArg, pCb, pData, prop);
988 SysTryReturn(NID_APP, pItem != null, -1, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
990 SysLog(NID_APP, "Registering callback 0x%x, 0x%x", pCb, pData);
992 return __launchManager.InsertItem(pItem);
996 _AppControlManager::RemoveLaunchRequest(int req)
998 __launchManager.RemoveItem(req);
1002 _AppControlManager::RegisterRequest(service_s* service, int& req, _AppHandler& handler)
1004 bundle* b = _AppArg::GetBundleFromSvc(service);
1006 _AppArg* pArg = new (std::nothrow) _AppArg();
1007 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
1010 result r = E_SUCCESS;
1012 // ownership is transfered to RequestManager
1013 _ResultInfo* pItem = new (std::nothrow) _ResultInfo(*pArg);
1014 SysTryCatch(NID_APP, pItem != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
1016 req = __resultManager.InsertItem(pItem);
1017 SysTryCatch(NID_APP, req != -1, , r = E_INVALID_STATE, "[E_INVALID_STATE] Invalid argument handling state.");
1019 handler = _AppArg::GetHandler(b);
1031 _AppControlManager::ConvertAppControlResultCode(int resCode)
1033 AppCtrlResult ret = APP_CTRL_RESULT_FAILED;
1037 case SERVICE_RESULT_SUCCEEDED:
1038 ret = APP_CTRL_RESULT_SUCCEEDED;
1040 case SERVICE_RESULT_FAILED:
1041 ret = APP_CTRL_RESULT_CANCELED;
1043 case SERVICE_RESULT_CANCELED:
1044 ret = APP_CTRL_RESULT_ABORTED;
1046 case APPSVC_OSP_RES_FAIL:
1047 ret = APP_CTRL_RESULT_FAILED;
1049 case APPSVC_OSP_RES_TERMINATE:
1050 ret = APP_CTRL_RESULT_TERMINATED;
1053 ret = APP_CTRL_RESULT_FAILED;
1062 _AppControlManager::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
1064 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
1066 if (pEventArg != null)
1068 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
1070 if(pResponseListener != null)
1072 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_START)
1074 pResponseListener->OnAppControlStartResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetResult());
1075 SysLog(NID_APP, "OnAppControlStartResponseReceived called");
1079 InvokeAppControlCompleteListener(*pResponseListener, pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData(), pEventArg->IsSubMode());
1080 SysLog(NID_APP, "Listener called");
1082 _AppControlResponseEvent* pResponseEvent = null;
1083 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
1084 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
1086 delete pResponseEvent;
1087 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
1092 SysLog(NID_APP, "Invalid ResponseListener");
1097 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);