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>
31 #include <FBaseInteger.h>
32 #include <FBaseObject.h>
33 #include <FBaseString.h>
34 #include <FBaseColIListT.h>
35 #include <FBaseColArrayList.h>
36 #include <FBaseErrors.h>
37 #include <FAppAppControl.h>
38 #include <FAppAppManager.h>
39 #include <FAppIAppControlListener.h>
40 #include <FAppIAppControlResponseListener.h>
41 #include <FAppIAppFrame.h>
42 #include <FAppSqlDataControl.h>
43 #include <FAppMapDataControl.h>
44 #include <FAppPkgPackageInfo.h>
46 #include <FBaseSysLog.h>
47 #include <FBase_StringConverter.h>
48 #include <FBaseRt_LibraryImpl.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"
57 #include "FApp_AppManagerEventArg.h"
59 #include "FApp_AppControlManager.h"
60 #include "FApp_AppManagerProxy.h"
61 #include "FApp_ConditionManagerProxy.h"
62 #include "FApp_IAppManagerEventListener.h"
63 #include "FApp_MapDataControlImpl.h"
64 #include "FApp_SqlDataControlImpl.h"
65 #include "FAppPkg_PackageManagerImpl.h"
66 #include "FAppPkg_PackageInfoImpl.h"
67 #include "FApp_AppMessageImpl.h"
68 #include "FApp_AppManagerImpl.h"
69 #include "FApp_AppControlResponseEvent.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;
78 namespace Tizen { namespace App
81 const wchar_t TIZEN_OPERATION_PICK[] = L"http://tizen.org/appcontrol/operation/pick";
82 const wchar_t SELECTOR_NOTI_KEY[] = L"__APP_SVC_CALLER_NOTI__";
83 const int _MAX_PACKAGE_ID_LENGTH = 10;
85 _InProcessInfo::~_InProcessInfo(void)
90 _LaunchInfo::~_LaunchInfo(void)
96 _AppControlManager::_AppControlManager(void)
100 // AppControl event handling is expected to be performed in the main thread.
101 __appControlEvent.Construct();
102 __appControlEvent.AddListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
103 __listenerList.Construct();
104 __appControlResponseEventContainer.Construct();
105 __appControlResponseEventList.Construct();
108 _AppControlManager::~_AppControlManager(void)
111 __appControlEvent.RemoveListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
112 IEnumeratorT<int>* pEnum = __appControlResponseEventList.GetEnumeratorN();
116 while(pEnum->MoveNext() == E_SUCCESS)
119 pEnum->GetCurrent(reqId);
120 _AppControlResponseEvent* pResponseEvent = null;
121 __appControlResponseEventContainer.GetValue(reqId, pResponseEvent);
122 delete pResponseEvent;
124 __appControlResponseEventContainer.Remove(reqId);
125 SysLog(NID_APP, "pResponseEvent gets deleted. reqId(%d)", reqId);
132 _AppControlManager::GetInstance(void)
134 static _AppControlManager inst;
140 _AppControlManager::GetMimeFromExt(const String& ext, String& out)
142 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(ext));
143 SysTryReturnResult(NID_APP, pExtension != null, E_OUT_OF_MEMORY, "String allocation failure.");
146 mime_type_get_mime_type(pExtension.get(), &mime);
148 SysTryReturnResult(NID_APP, mime != NULL, E_UNSUPPORTED_FORMAT, "MIME type conversion failure for %ls.", ext.GetPointer());
157 _AppControlManager::OnAppControlEventReceivedN(int reqId, _AppArg* pAppArg, int res)
159 SysLog(NID_APP, "Received request Id %d, arg 0x%x", reqId, pAppArg);
162 // get launch info from request Id
163 _LaunchInfo* pInfo = __launchManager.FindItem(reqId);
164 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with response %d", reqId,
170 if (pInfo->magic == LAUNCH_INFO_MAGIC)
172 SysLog(NID_APP, "Invoking callback 0x%x", pInfo->launchCb);
175 if (pInfo->pUserData && (!__listenerList.Contains(pInfo->pUserData)))
177 (*pInfo->launchCb)(pInfo->pUserData, pInfo->pArg, pAppArg, static_cast<service_result_e>(res), pInfo->property, reqId);
182 SysLogException(NID_APP, E_SYSTEM, "Corrupted data structure.");
187 __launchManager.RemoveItem(reqId);
191 // callback for out-of-process AppControl start event
193 _AppControlManager::OnAppControlEventReceivedN(int reqId, const AppId& appId, const String& operationId)
195 SysLog(NID_APP, "Received request Id %d, app %ls, operationId %ls", reqId, appId.GetPointer(), operationId.GetPointer());
197 // get launch info from request Id
198 _LaunchInfo* pInfo = __launchManager.FindItem(reqId);
199 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found.", reqId);
202 IAppControlResponseListener* pListener = static_cast<IAppControlResponseListener*>(pInfo->pUserData);
203 SysTryReturnVoidResult(NID_APP, typeid(pListener) == typeid(IAppControlResponseListener*), E_SYSTEM, "[E_SYSTEM] Invalid result callback.");
207 result r = E_SUCCESS;
208 AppId actualAppId = appId;
212 r = E_OPERATION_CANCELED;
214 SysLog(NID_APP, "Invoking callback 0x%x.", pListener);
216 _AppControlResponseEvent* pResponseEvent = null;
217 __appControlResponseEventContainer.GetValue(reqId, pResponseEvent);
218 SysLog(NID_APP, "StartResponseReceived Request Id(%d), ResponseEvent 0x%x.", reqId, pResponseEvent);
219 if (pResponseEvent != null)
221 String oId(operationId);
222 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_START, actualAppId, oId, r, APP_CTRL_RESULT_SUCCEEDED, null, reqId, false);
224 if (pResponseEventArg != null)
226 pResponseEvent->Fire(*pResponseEventArg);
227 SysLog(NID_APP, "pResponseEvent is Fired");
232 pListener->OnAppControlStartResponseReceived(actualAppId, operationId, r);
233 SysLog(NID_APP, "OnAppControlStartResponseReceived called directly");
238 SysLog(NID_APP, "No listener registered.");
244 _AppControlManager::InvokeAppControlCompleteListener(IAppControlResponseListener& listener, const AppId& appId, const String& op, AppCtrlResult res, const IMap* pExtraData, bool isSubMode)
246 listener.OnAppControlCompleteResponseReceived(appId, op, res, pExtraData);
250 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
253 SysLog(NID_APP, "AppControl response finished.");
258 _AppControlManager::InvokeLegacyAppControlCompleteListener(IAppControlEventListener& listener, const AppId& appId, const String& op, const IList* pList, bool isSubMode)
260 listener.OnAppControlCompleted(appId, op, pList);
264 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
267 SysLog(NID_APP, "Legacy AppControl response finished.");
271 // callback for in-process event handling
273 _AppControlManager::OnAppControlEventReceivedN(int reqId, int res, const IMap* pArgs, int property)
275 SysLog(NID_APP, "Received request Id %d, res %d, args 0x%x", reqId, res, pArgs);
277 // process proper callback
278 _InProcessInfo* pInfo = __inAppManager.FindItem(reqId);
279 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with args 0x%x", reqId,
282 if (pInfo->pListener)
284 String aId = pInfo->providerId;
285 String oId = pInfo->operationId;
287 SysLog(NID_APP, "Invoking callback 0x%x for (%ls, %ls).", pInfo->pListener, aId.GetPointer(), oId.GetPointer());
289 if (pInfo->property & _APPCONTROL_PROPERTY_ALIAS)
291 const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
292 pEntry = _AppControlRegistry::GetInstance()->GetReverseAppControlAliasEntry(aId, oId);
295 aId = pEntry->provider;
296 oId = pEntry->operation;
298 SysLog(NID_APP, "Legacy AppControl (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
302 const bool isSubMode = (property & _APPCONTROL_PROPERTY_SUBMODE);
306 IAppControlEventListener* pListener = dynamic_cast<IAppControlEventListener*>(pInfo->pListener);
309 ArrayList list(SingleObjectDeleter);
310 _AppArg::FillLegacyAppControlResult(list, res, pArgs, aId);
312 InvokeLegacyAppControlCompleteListener(*pListener, aId, oId, &list, isSubMode);
316 SysLog(NID_APP, "Wrong AppControl listener type.");
321 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
322 if (pListener && (!__listenerList.Contains(pInfo->pListener)))
324 _AppControlResponseEvent* pResponseEvent = null;
325 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + reqId;
326 __appControlResponseEventContainer.GetValue(responseEventRequestId, pResponseEvent);
328 if (pResponseEvent != null)
330 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, aId, oId, E_SUCCESS, static_cast<AppCtrlResult>(res), const_cast<IMap*> (pArgs), responseEventRequestId, isSubMode);
331 if (pResponseEventArg != null)
333 pResponseEvent->Fire(*pResponseEventArg);
334 SysLog(NID_APP, "pResponseEvent is Fired");
339 InvokeAppControlCompleteListener(*pListener, aId, oId, ConvertAppControlResultCode(res), pArgs, isSubMode);
340 SysLog(NID_APP, "Listener called directly");
346 SysLog(NID_APP, "Wrong AppControl listener type.");
352 SysLogException(NID_APP, E_SYSTEM, "Invalid AppControl listener.");
355 // call TerminateAppControl
356 result (* pFunc)(int req) = null;
357 pFunc = reinterpret_cast<result (*)(int)>(pInfo->pLib->GetProcAddress(L"TerminateAppControl"));
360 (*pFunc)(pInfo->reqId);
364 SysLogException(NID_APP, E_SYSTEM, "No TerminateAppControl() function.");
367 // remove from list and unload dll
368 __inAppManager.RemoveItem(reqId);
373 _AppControlManager::SendAppControlEvent(IEventArg& arg)
375 return __appControlEvent.FireAsync(arg);
378 Tizen::Base::Collection::IMapT<int,_AppControlResponseEvent*>*
379 _AppControlManager::GetAppControlResponseEventContainer(void)
381 return &__appControlResponseEventContainer;
385 // generic launch callback
387 LaunchResultCb(bundle* b, int request_code, appsvc_result_val res, void* data)
389 SysLog(NID_APP, "SLP callee result: %d", res);
391 _AppControlManager* pImpl = static_cast<_AppControlManager*>(data);
397 _AppArg* pAppArg = new (std::nothrow) _AppArg;
398 SysTryReturnVoidResult(NID_APP, pAppArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
400 _AppControlEventArg* pArg = null;
401 result r = pAppArg->Construct(b);
402 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] AppControl event argument creation failure.", GetErrorMessage(r));
404 pArg = new (std::nothrow) _AppControlEventArg(request_code, pAppArg, res);
405 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
408 pImpl->SendAppControlEvent(*pArg);
418 _AppControlManager::SendAppControlStartResponse(int req, const char* pValue, const char* pOp)
420 _AppControlStartEventArg* pArg = new (std::nothrow) _AppControlStartEventArg(req, AppId(pValue), String(pOp));
421 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "AppControl start event creation failure.");
423 SendAppControlEvent(*pArg);
430 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
432 bundle* kb = msg.GetBundle();
433 SysTryReturnResult(NID_APP, kb != NULL, E_OUT_OF_MEMORY, "Bundle allocation failure.");
437 appsvc_set_pkgname(kb, pkg_name);
440 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
444 appsvc_set_mime(kb, mime);
449 appsvc_set_uri(kb, uri);
452 if (_AppImpl::GetInstance() != null)
454 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
455 _AppArg::UpdateWindowHandle(kb, handle);
458 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
459 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
461 result r = E_SUCCESS;
466 case APPSVC_RET_EILLACC:
467 r = E_ILLEGAL_ACCESS;
469 case APPSVC_RET_EINVAL:
476 SysLog(NID_APP, "[%s] Launching service %s failure", GetErrorMessage(r), pkg_name);
484 _AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
486 bundle* kb = msg.GetBundle();
487 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
491 appsvc_set_pkgname(kb, pkg_name);
494 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
498 appsvc_set_mime(kb, mime);
503 appsvc_set_uri(kb, uri);
506 if (_AppImpl::GetInstance() != null)
508 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
509 _AppArg::UpdateWindowHandle(kb, handle);
512 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
513 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
515 result r = E_SUCCESS;
520 case APPSVC_RET_EILLACC:
521 r = E_ILLEGAL_ACCESS;
523 case APPSVC_RET_EINVAL:
530 SysLog(NID_APP, "[%s]Launching service %s failure", GetErrorMessage(r), pkg_name);
539 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const AppId& appId, const String& opId, const String* pUri, const String* pMime, AppSvcResFn pCb, void* data)
541 std::unique_ptr<char[]> pPackage(_StringConverter::CopyToCharArrayN(appId));
542 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(opId));
544 const char* pUriData = null;
547 pUriData = _StringConverter::CopyToCharArrayN(*pUri);
550 const char* pMimeData = null;
553 pMimeData = _StringConverter::CopyToCharArrayN(*pMime);
556 int pid = Launch(msg, pPackage.get(), pOperation.get(), pMimeData, pUriData, pCb, data);
566 _AppControlManager::LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
570 return LaunchPkg(msg, pkg_name, op, mime, uri, pCb, data);
574 _AppControlManager::LaunchAppWithCondition(const AppId& appId, const String& condition, IList* pArrayArgs)
576 result r = E_SUCCESS;
577 _AppArg * pArg = new (std::nothrow) _AppArg();
578 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
580 r = pArg->ConstructForAppLaunchCondition(condition, pArrayArgs);
581 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] ConstructForAppLaunchCondition(%ls, .. ) fails", GetErrorMessage(r), condition.GetPointer());
583 r = _AppControlManager::LaunchApp(appId, pArg);
590 _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
592 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
593 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
595 String actualAppId = appId;
596 if (appId.GetLength() == 10)
598 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
602 actualAppId.Append(L'.');
603 actualAppId.Append(name);
607 pArg->UpdateRequestId(req);
609 if (_AppImpl::GetInstance() != null)
611 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
612 pArg->UpdateWindowHandle(handle);
618 actualAppId.SubString(0, 10, tempId);
620 tempId += L"_AppControl";
622 // [INFO] Ugly solution for submode support
623 pArg->UpdateAppId(tempId);
624 kb = pArg->GetBundle();
626 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
629 SysLog(NID_APP, "Submode launch successful");
632 else if (pid == APPSVC_RET_EINVAL)
634 SysLog(NID_APP, "Argument overflow");
635 return E_MAX_EXCEEDED;
638 pArg->UpdateAppId(actualAppId);
640 // retry for possible failure
642 const int TRY_COUNT = 3;
643 const int TRY_SLEEP_TIME = 65;
646 kb = pArg->GetBundle();
647 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
650 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
653 else if (pid == APPSVC_RET_EINVAL)
655 SysLog(NID_APP, "Argument overflow");
656 return E_MAX_EXCEEDED;
660 SysLog(NID_APP, "Waiting %dth time.", count);
661 Thread::Sleep(TRY_SLEEP_TIME);
663 while (count < TRY_COUNT);
665 result r = E_SUCCESS;
668 case APPSVC_RET_EILLACC:
669 r = E_ILLEGAL_ACCESS;
676 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
682 _IsDefaultApplication(const AppId& packageId, const String& appId)
684 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
687 result r = appId.IndexOf(L'.', 0, index);
694 appId.SubString(index + 1, tmp);
697 SysLog(NID_APP, "Default application %ls", tmp.GetPointer());
706 _AppControlManager::Launch(const _AppMessageImpl& msg, const AppId& aId, const String& oId, const String* pUriData, const String* pMimeType, AppSvcResFn pCb, void* pData)
708 SysLog(NID_APP, "Enter");
711 arg.Construct(msg, oId, pUriData, pMimeType);
713 int pid = Launch(aId, &arg, pCb, pData, -1);
714 SysTryReturn(NID_APP, pid >= 0, -1, GetLastResult(), "Launching(%ls) is failed", aId.GetPointer());
716 SysLog(NID_APP, "Exit");
723 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
725 return Launch(appId, pArg, reinterpret_cast<AppSvcResFn>(LaunchResultCb), this, req);
730 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, AppSvcResFn pCb, void* pData, int req)
732 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid launch argument");
733 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
735 String actualAppId = appId;
737 if (appId.GetLength() == 10)
739 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
741 if (!execName.IsEmpty())
743 actualAppId.Append(L'.');
744 actualAppId.Append(execName);
749 pArg->UpdateRequestId(req);
751 if (_AppImpl::GetInstance() != null)
753 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
754 pArg->UpdateWindowHandle(handle);
761 actualAppId.SubString(0, 10, tempId);
763 const int type = _AppInfo::GetAppType();
764 if ((!(type & _APP_TYPE_SERVICE_APP)) && _IsDefaultApplication(tempId, appId))
767 tempId += L"_AppControl";
769 // [INFO] Ugly solution for submode support
770 pArg->UpdateAppId(tempId);
771 kb = pArg->GetBundle();
773 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
776 SysLog(NID_APP, "Submode launch successful");
777 SetLastResult(E_SUCCESS);
780 else if (pid == APPSVC_RET_EINVAL)
782 SetLastResult(E_MAX_EXCEEDED);
787 pArg->UpdateAppId(actualAppId);
789 // retry for possible failure
791 const int TRY_COUNT = 3;
792 const int TRY_SLEEP_TIME = 65;
795 kb = pArg->GetBundle();
796 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
799 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
800 SetLastResult(E_SUCCESS);
803 else if (pid == APPSVC_RET_EINVAL)
805 SetLastResult(E_MAX_EXCEEDED);
810 SysLog(NID_APP, "Waiting %dth time with %d.", count, pid);
811 Thread::Sleep(TRY_SLEEP_TIME);
813 while (count < TRY_COUNT);
815 result r = E_SUCCESS;
818 case APPSVC_RET_EILLACC:
819 r = E_ILLEGAL_ACCESS;
826 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
834 _AppControlManager::LaunchAppImplicit(_AppArg* pArg, int req)
836 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
838 result r = E_SUCCESS;
839 bundle* kb = pArg->GetBundle();
843 pArg->UpdateRequestId(req);
844 _AppMessageImpl::AddData(kb, SELECTOR_NOTI_KEY, _AppInfo::GetApplicationId());
847 if (_AppImpl::GetInstance() != null)
849 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
850 _AppArg::UpdateWindowHandle(kb, handle);
853 int pid = appsvc_run_service(kb, req, LaunchResultCb, this);
858 SysLog(NID_APP, "Sending local process again.");
862 char pkgname[255] = {0, };
863 aul_app_get_pkgname_bypid(pid, pkgname, 255);
865 if (strncmp(pkgname, APP_SELECTOR, strlen(APP_SELECTOR)) != 0)
867 const char* pOperation = appsvc_get_operation(kb);
869 SysLog(NID_APP, "Starting application without selector : (%s, %s).", pkgname, pOperation);
871 SendAppControlStartResponse(req, pkgname, pOperation);
878 case APPSVC_RET_EINVAL:
881 case APPSVC_RET_ENOMATCH:
884 case APPSVC_RET_EILLACC:
885 r = E_ILLEGAL_ACCESS;
887 case APPSVC_RET_ERROR:
889 case APPSVC_RET_ELAUNCH:
897 SysLog(NID_APP, "[%s] Application(%d) launched with reqId(%d) and arg(0x%x).", GetErrorMessage(r), pid, req, pArg);
903 _AppControlManager::FinishAppControl(int reqId, int res, IMap* pMap)
905 SysLog(NID_APP, "req %d, res %d.", reqId, res);
906 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, pMap, _APPCONTROL_PROPERTY_SUBMODE);
907 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
909 SendAppControlEvent(*pArg);
910 SysLog(NID_APP, "Exit.");
914 _AppControlManager::RemoveResultRequest(int reqId)
916 __resultManager.RemoveItem(reqId);
920 _AppControlManager::FindResultRequest(int reqId) const
922 const _ResultInfo* pInfo = __resultManager.FindItem(reqId);
923 return (pInfo) ? &(pInfo->arg) : null;
927 _AppControlManager::AddLaunchRequest(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
929 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
931 _LaunchInfo* pItem = new (std::nothrow) _LaunchInfo(pArg, pCb, pData, prop);
932 SysTryReturn(NID_APP, pItem != null, -1, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
934 SysLog(NID_APP, "Registering callback 0x%x, 0x%x", pCb, pData);
936 return __launchManager.InsertItem(pItem);
940 _AppControlManager::RemoveLaunchRequest(int req)
942 __launchManager.RemoveItem(req);
946 _AppControlManager::RegisterRequest(service_s* service, int& req, _AppHandler& handler)
948 bundle* b = _AppArg::GetBundleFromSvc(service);
950 _AppArg* pArg = new (std::nothrow) _AppArg();
951 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
954 result r = E_SUCCESS;
956 // ownership is transfered to RequestManager
957 _ResultInfo* pItem = new (std::nothrow) _ResultInfo(*pArg);
958 SysTryCatch(NID_APP, pItem != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
960 req = __resultManager.InsertItem(pItem);
961 SysTryCatch(NID_APP, req != -1, , r = E_INVALID_STATE, "[E_INVALID_STATE] Invalid argument handling state.");
963 handler = _AppArg::GetHandler(b);
975 _AppControlManager::IsAllowedAppControl(const char aTable[][2][96], int count, const String& aId, const String& oId)
977 for (int i = 0; i < count; i++)
979 if (aId == aTable[i][0] && oId == aTable[i][1])
981 SysLog(NID_APP, "Found entry (%s, %s)", aTable[i][0], aTable[i][1]);
991 _AppControlManager::ConvertAppControlResultCode(int resCode)
993 AppCtrlResult ret = APP_CTRL_RESULT_FAILED;
997 case SERVICE_RESULT_SUCCEEDED:
998 ret = APP_CTRL_RESULT_SUCCEEDED;
1000 case SERVICE_RESULT_FAILED:
1001 ret = APP_CTRL_RESULT_CANCELED;
1003 case SERVICE_RESULT_CANCELED:
1004 ret = APP_CTRL_RESULT_ABORTED;
1006 case APPSVC_OSP_RES_FAIL:
1007 ret = APP_CTRL_RESULT_FAILED;
1009 case APPSVC_OSP_RES_TERMINATE:
1010 ret = APP_CTRL_RESULT_TERMINATED;
1013 ret = APP_CTRL_RESULT_FAILED;
1022 _AppControlManager::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
1024 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
1026 if (pEventArg != null)
1028 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
1030 if(pResponseListener != null)
1032 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_START)
1034 pResponseListener->OnAppControlStartResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetResult());
1035 SysLog(NID_APP, "OnAppControlStartResponseReceived called");
1039 InvokeAppControlCompleteListener(*pResponseListener, pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData(), pEventArg->IsSubMode());
1040 SysLog(NID_APP, "Listener called");
1042 _AppControlResponseEvent* pResponseEvent = null;
1043 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
1044 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
1046 delete pResponseEvent;
1047 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
1052 SysLog(NID_APP, "Invalid ResponseListener");
1057 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);
1062 _AppControlManager::GetAliasAppId(const AppId& appId)
1064 return _AppControlRegistry::GetInstance()->GetAliasAppId(appId);