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 __pAppControlResponseEventContainer = new (std::nothrow)HashMapT<int, _AppControlResponseEvent*>;
105 __pAppControlResponseEventContainer->Construct();
106 __appControlResponseEventList.Construct();
109 _AppControlManager::~_AppControlManager(void)
112 __appControlEvent.RemoveListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
113 IEnumeratorT<int>* pEnum = __appControlResponseEventList.GetEnumeratorN();
117 while(pEnum->MoveNext() == E_SUCCESS)
120 pEnum->GetCurrent(reqId);
121 if (__pAppControlResponseEventContainer != null)
123 _AppControlResponseEvent* pResponseEvent = null;
124 __pAppControlResponseEventContainer->GetValue(reqId, pResponseEvent);
125 delete pResponseEvent;
127 __pAppControlResponseEventContainer->Remove(reqId);
128 SysLog(NID_APP, "pResponseEvent gets deleted. reqId(%d)", reqId);
132 delete __pAppControlResponseEventContainer;
137 _AppControlManager::GetInstance(void)
139 static _AppControlManager inst;
145 _AppControlManager::GetMimeFromExt(const String& ext, String& out)
147 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(ext));
148 SysTryReturnResult(NID_APP, pExtension != null, E_OUT_OF_MEMORY, "String allocation failure.");
151 mime_type_get_mime_type(pExtension.get(), &mime);
153 SysTryReturnResult(NID_APP, mime != NULL, E_UNSUPPORTED_FORMAT, "MIME type conversion failure for %ls.", ext.GetPointer());
162 _AppControlManager::OnAppControlEventReceivedN(int reqId, _AppArg* pAppArg, int res)
164 SysLog(NID_APP, "Received request Id %d, arg 0x%x", reqId, pAppArg);
167 // get launch info from request Id
168 _LaunchInfo* pInfo = __launchManager.FindItem(reqId);
169 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with response %d", reqId,
175 if (pInfo->magic == LAUNCH_INFO_MAGIC)
177 SysLog(NID_APP, "Invoking callback 0x%x", pInfo->launchCb);
180 if (pInfo->pUserData && (!__listenerList.Contains(pInfo->pUserData)))
182 (*pInfo->launchCb)(pInfo->pUserData, pInfo->pArg, pAppArg, static_cast<service_result_e>(res), pInfo->property, reqId);
187 SysLogException(NID_APP, E_SYSTEM, "Corrupted data structure.");
192 __launchManager.RemoveItem(reqId);
196 // callback for out-of-process AppControl start event
198 _AppControlManager::OnAppControlEventReceivedN(int reqId, const AppId& appId, const String& operationId)
200 SysLog(NID_APP, "Received request Id %d, app %ls, operationId %ls", reqId, appId.GetPointer(), operationId.GetPointer());
202 // get launch info from request Id
203 _LaunchInfo* pInfo = __launchManager.FindItem(reqId);
204 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found.", reqId);
207 IAppControlResponseListener* pListener = static_cast<IAppControlResponseListener*>(pInfo->pUserData);
208 SysTryReturnVoidResult(NID_APP, typeid(pListener) == typeid(IAppControlResponseListener*), E_SYSTEM, "[E_SYSTEM] Invalid result callback.");
212 result r = E_SUCCESS;
213 AppId actualAppId = appId;
217 r = E_OPERATION_CANCELED;
219 SysLog(NID_APP, "Invoking callback 0x%x.", pListener);
221 _AppControlResponseEvent* pResponseEvent = null;
222 __pAppControlResponseEventContainer->GetValue(reqId, pResponseEvent);
223 SysLog(NID_APP, "StartResponseReceived Request Id(%d), ResponseEvent 0x%x.", reqId, pResponseEvent);
224 if (pResponseEvent != null)
226 String oId(operationId);
227 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_START, actualAppId, oId, r, APP_CTRL_RESULT_SUCCEEDED, null, reqId);
229 if (pResponseEventArg != null)
231 pResponseEvent->Fire(*pResponseEventArg);
232 SysLog(NID_APP, "pResponseEvent is Fired");
237 pListener->OnAppControlStartResponseReceived(actualAppId, operationId, r);
238 SysLog(NID_APP, "OnAppControlStartResponseReceived called directly");
243 SysLog(NID_APP, "No listener registered.");
249 _AppControlManager::InvokeAppControlCompleteListener(IAppControlResponseListener& listener, const AppId& appId, const String& op, AppCtrlResult res, const IMap* pExtraData)
251 listener.OnAppControlCompleteResponseReceived(appId, op, res, pExtraData);
253 //_AppImpl::GetInstance()->RaiseWindow();
255 SysLog(NID_APP, "AppControl response finished.");
260 _AppControlManager::InvokeLegacyAppControlCompleteListener(IAppControlEventListener& listener, const AppId& appId, const String& op, const IList* pList)
262 listener.OnAppControlCompleted(appId, op, pList);
264 //_AppImpl::GetInstance()->RaiseWindow();
265 SysLog(NID_APP, "Legacy AppControl response finished.");
269 // callback for in-process event handling
271 _AppControlManager::OnAppControlEventReceivedN(int reqId, int res, const IMap* pArgs)
273 SysLog(NID_APP, "Received request Id %d, res %d, args 0x%x", reqId, res, pArgs);
275 // process proper callback
276 _InProcessInfo* pInfo = __inAppManager.FindItem(reqId);
277 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with args 0x%x", reqId,
280 if (pInfo->pListener)
282 String aId = pInfo->providerId;
283 String oId = pInfo->operationId;
285 SysLog(NID_APP, "Invoking callback 0x%x for (%ls, %ls).", pInfo->pListener, aId.GetPointer(), oId.GetPointer());
287 if (pInfo->property & _APPCONTROL_PROPERTY_ALIAS)
289 const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
290 pEntry = _AppControlRegistry::GetInstance()->GetReverseAppControlAliasEntry(aId, oId);
293 aId = pEntry->provider;
294 oId = pEntry->operation;
296 SysLog(NID_APP, "Legacy AppControl (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
302 IAppControlEventListener* pListener = dynamic_cast<IAppControlEventListener*>(pInfo->pListener);
305 ArrayList list(SingleObjectDeleter);
306 _AppArg::FillLegacyAppControlResult(list, res, pArgs, aId);
308 InvokeLegacyAppControlCompleteListener(*pListener, aId, oId, &list);
312 SysLog(NID_APP, "Wrong AppControl listener type.");
317 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
318 if (pListener && (!__listenerList.Contains(pInfo->pListener)))
320 _AppControlResponseEvent* pResponseEvent = null;
321 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + reqId;
322 __pAppControlResponseEventContainer->GetValue(responseEventRequestId, pResponseEvent);
324 if (pResponseEvent != null)
326 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, aId, oId, E_SUCCESS, static_cast<AppCtrlResult>(res), const_cast<IMap*> (pArgs), responseEventRequestId);
327 if (pResponseEventArg != null)
329 pResponseEvent->Fire(*pResponseEventArg);
330 SysLog(NID_APP, "pResponseEvent is Fired");
335 InvokeAppControlCompleteListener(*pListener, aId, oId, ConvertAppControlResultCode(res), pArgs);
336 SysLog(NID_APP, "Listener called directly");
342 SysLog(NID_APP, "Wrong AppControl listener type.");
348 SysLogException(NID_APP, E_SYSTEM, "Invalid AppControl listener.");
351 // call TerminateAppControl
352 result (* pFunc)(int req) = null;
353 pFunc = reinterpret_cast<result (*)(int)>(pInfo->pLib->GetProcAddress(L"TerminateAppControl"));
356 (*pFunc)(pInfo->reqId);
360 SysLogException(NID_APP, E_SYSTEM, "No TerminateAppControl() function.");
363 // remove from list and unload dll
364 __inAppManager.RemoveItem(reqId);
369 _AppControlManager::SendAppControlEvent(IEventArg& arg)
371 return __appControlEvent.FireAsync(arg);
374 Tizen::Base::Collection::IMapT<int,_AppControlResponseEvent*>*
375 _AppControlManager::GetAppControlResponseEventContainer(void)
377 return __pAppControlResponseEventContainer;
381 // generic launch callback
383 LaunchResultCb(bundle* b, int request_code, appsvc_result_val res, void* data)
385 SysLog(NID_APP, "SLP callee result: %d", res);
387 _AppControlManager* pImpl = static_cast<_AppControlManager*>(data);
393 _AppArg* pAppArg = new (std::nothrow) _AppArg;
394 SysTryReturnVoidResult(NID_APP, pAppArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
396 _AppControlEventArg* pArg = null;
397 result r = pAppArg->Construct(b);
398 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] AppControl event argument creation failure.", GetErrorMessage(r));
400 pArg = new (std::nothrow) _AppControlEventArg(request_code, pAppArg, res);
401 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
404 pImpl->SendAppControlEvent(*pArg);
414 _AppControlManager::SendAppControlStartResponse(int req, const char* pValue, const char* pOp)
416 _AppControlStartEventArg* pArg = new (std::nothrow) _AppControlStartEventArg(req, AppId(pValue), String(pOp));
417 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "AppControl start event creation failure.");
419 SendAppControlEvent(*pArg);
426 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
428 bundle* kb = msg.GetBundle();
429 SysTryReturnResult(NID_APP, kb != NULL, E_OUT_OF_MEMORY, "Bundle allocation failure.");
433 appsvc_set_pkgname(kb, pkg_name);
436 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
440 appsvc_set_mime(kb, mime);
445 appsvc_set_uri(kb, uri);
448 if (_AppImpl::GetInstance() != null)
450 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
451 _AppArg::UpdateWindowHandle(kb, handle);
454 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
455 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
457 result r = E_SUCCESS;
462 case APPSVC_RET_EILLACC:
463 r = E_ILLEGAL_ACCESS;
465 case APPSVC_RET_EINVAL:
472 SysLog(NID_APP, "[%s] Launching service %s failure", GetErrorMessage(r), pkg_name);
480 _AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
482 bundle* kb = msg.GetBundle();
483 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
487 appsvc_set_pkgname(kb, pkg_name);
490 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
494 appsvc_set_mime(kb, mime);
499 appsvc_set_uri(kb, uri);
502 if (_AppImpl::GetInstance() != null)
504 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
505 _AppArg::UpdateWindowHandle(kb, handle);
508 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
509 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
511 result r = E_SUCCESS;
516 case APPSVC_RET_EILLACC:
517 r = E_ILLEGAL_ACCESS;
519 case APPSVC_RET_EINVAL:
526 SysLog(NID_APP, "[%s]Launching service %s failure", GetErrorMessage(r), pkg_name);
535 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const AppId& appId, const String& opId, const String* pUri, const String* pMime, AppSvcResFn pCb, void* data)
537 std::unique_ptr<char[]> pPackage(_StringConverter::CopyToCharArrayN(appId));
538 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(opId));
540 const char* pUriData = null;
543 pUriData = _StringConverter::CopyToCharArrayN(*pUri);
546 const char* pMimeData = null;
549 pMimeData = _StringConverter::CopyToCharArrayN(*pMime);
552 int pid = Launch(msg, pPackage.get(), pOperation.get(), pMimeData, pUriData, pCb, data);
562 _AppControlManager::LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
566 return LaunchPkg(msg, pkg_name, op, mime, uri, pCb, data);
570 _AppControlManager::LaunchAppWithCondition(const AppId& appId, const String& condition, IList* pArrayArgs)
572 result r = E_SUCCESS;
573 _AppArg * pArg = new (std::nothrow) _AppArg();
574 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
576 r = pArg->ConstructForAppLaunchCondition(condition, pArrayArgs);
577 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] ConstructForAppLaunchCondition(%ls, .. ) fails", GetErrorMessage(r), condition.GetPointer());
579 r = _AppControlManager::LaunchApp(appId, pArg);
586 _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
588 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
589 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
591 String actualAppId = appId;
592 if (appId.GetLength() == 10)
594 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
598 actualAppId.Append(L'.');
599 actualAppId.Append(name);
603 pArg->UpdateRequestId(req);
605 if (_AppImpl::GetInstance() != null)
607 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
608 pArg->UpdateWindowHandle(handle);
614 actualAppId.SubString(0, 10, tempId);
616 tempId += L"_AppControl";
618 // [INFO] Ugly solution for submode support
619 pArg->UpdateAppId(tempId);
620 kb = pArg->GetBundle();
622 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
625 SysLog(NID_APP, "Submode launch successful");
628 else if (pid == APPSVC_RET_EINVAL)
630 SysLog(NID_APP, "Argument overflow");
631 return E_MAX_EXCEEDED;
634 pArg->UpdateAppId(actualAppId);
636 // retry for possible failure
638 const int TRY_COUNT = 3;
639 const int TRY_SLEEP_TIME = 65;
642 kb = pArg->GetBundle();
643 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
646 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
649 else if (pid == APPSVC_RET_EINVAL)
651 SysLog(NID_APP, "Argument overflow");
652 return E_MAX_EXCEEDED;
656 SysLog(NID_APP, "Waiting %dth time.", count);
657 Thread::Sleep(TRY_SLEEP_TIME);
659 while (count < TRY_COUNT);
661 result r = E_SUCCESS;
664 case APPSVC_RET_EILLACC:
665 r = E_ILLEGAL_ACCESS;
672 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
678 _IsDefaultApplication(const AppId& packageId, const String& appId)
680 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
683 result r = appId.IndexOf(L'.', 0, index);
690 appId.SubString(index + 1, tmp);
693 SysLog(NID_APP, "Default application %ls", tmp.GetPointer());
702 _AppControlManager::Launch(const _AppMessageImpl& msg, const AppId& aId, const String& oId, const String* pUriData, const String* pMimeType, AppSvcResFn pCb, void* pData)
704 SysLog(NID_APP, "Enter");
707 arg.Construct(msg, oId, pUriData, pMimeType);
709 int pid = Launch(aId, &arg, pCb, pData, -1);
710 SysTryReturn(NID_APP, pid >= 0, -1, GetLastResult(), "Launching(%ls) is failed", aId.GetPointer());
712 SysLog(NID_APP, "Exit");
719 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
721 return Launch(appId, pArg, reinterpret_cast<AppSvcResFn>(LaunchResultCb), this, req);
726 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, AppSvcResFn pCb, void* pData, int req)
728 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid launch argument");
729 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
731 String actualAppId = appId;
732 if (appId.GetLength() == 10)
734 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
736 if (!execName.IsEmpty())
738 actualAppId.Append(L'.');
739 actualAppId.Append(execName);
743 pArg->UpdateRequestId(req);
745 if (_AppImpl::GetInstance() != null)
747 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
748 pArg->UpdateWindowHandle(handle);
755 actualAppId.SubString(0, 10, tempId);
757 if (_IsDefaultApplication(tempId, appId))
760 tempId += L"_AppControl";
762 // [INFO] Ugly solution for submode support
763 pArg->UpdateAppId(tempId);
764 kb = pArg->GetBundle();
766 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
769 SysLog(NID_APP, "Submode launch successful");
770 SetLastResult(E_SUCCESS);
773 else if (pid == APPSVC_RET_EINVAL)
775 SetLastResult(E_MAX_EXCEEDED);
780 pArg->UpdateAppId(actualAppId);
782 // retry for possible failure
784 const int TRY_COUNT = 3;
785 const int TRY_SLEEP_TIME = 65;
788 kb = pArg->GetBundle();
789 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
792 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
793 SetLastResult(E_SUCCESS);
796 else if (pid == APPSVC_RET_EINVAL)
798 SetLastResult(E_MAX_EXCEEDED);
803 SysLog(NID_APP, "Waiting %dth time with %d.", count, pid);
804 Thread::Sleep(TRY_SLEEP_TIME);
806 while (count < TRY_COUNT);
808 result r = E_SUCCESS;
811 case APPSVC_RET_EILLACC:
812 r = E_ILLEGAL_ACCESS;
819 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
827 _AppControlManager::LaunchAppImplicit(_AppArg* pArg, int req)
829 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
831 result r = E_SUCCESS;
832 bundle* kb = pArg->GetBundle();
836 pArg->UpdateRequestId(req);
837 _AppMessageImpl::AddData(kb, SELECTOR_NOTI_KEY, _AppInfo::GetApplicationId());
840 if (_AppImpl::GetInstance() != null)
842 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
843 _AppArg::UpdateWindowHandle(kb, handle);
846 int pid = appsvc_run_service(kb, req, LaunchResultCb, this);
851 SysLog(NID_APP, "Sending local process again.");
855 char pkgname[255] = {0, };
856 aul_app_get_pkgname_bypid(pid, pkgname, 255);
858 if (strncmp(pkgname, APP_SELECTOR, strlen(APP_SELECTOR)) != 0)
860 const char* pOperation = appsvc_get_operation(kb);
862 SysLog(NID_APP, "Starting application without selector : (%s, %s).", pkgname, pOperation);
864 SendAppControlStartResponse(req, pkgname, pOperation);
871 case APPSVC_RET_EINVAL:
874 case APPSVC_RET_ENOMATCH:
877 case APPSVC_RET_EILLACC:
878 r = E_ILLEGAL_ACCESS;
880 case APPSVC_RET_ERROR:
882 case APPSVC_RET_ELAUNCH:
890 SysLog(NID_APP, "[%s] Application(%d) launched with reqId(%d) and arg(0x%x).", GetErrorMessage(r), pid, req, pArg);
896 _AppControlManager::FinishAppControl(int reqId, int res, IMap* pMap)
898 SysLog(NID_APP, "req %d, res %d.", reqId, res);
899 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, pMap);
900 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
902 SendAppControlEvent(*pArg);
903 SysLog(NID_APP, "Exit.");
907 _AppControlManager::FindResultRequest(int reqId) const
909 const _ResultInfo* pInfo = __resultManager.FindItem(reqId);
910 return (pInfo) ? &(pInfo->arg) : null;
914 _AppControlManager::AddLaunchRequest(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
916 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
918 _LaunchInfo* pItem = new (std::nothrow) _LaunchInfo(pArg, pCb, pData, prop);
919 SysTryReturn(NID_APP, pItem != null, -1, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
921 SysLog(NID_APP, "Registering callback 0x%x, 0x%x", pCb, pData);
923 return __launchManager.InsertItem(pItem);
927 _AppControlManager::RemoveLaunchRequest(int req)
929 __launchManager.RemoveItem(req);
933 _AppControlManager::RegisterRequest(service_s* service, int& req, _AppHandler& handler)
935 bundle* b = _AppArg::GetBundleFromSvc(service);
937 _AppArg* pArg = new (std::nothrow) _AppArg();
938 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
941 result r = E_SUCCESS;
943 // ownership is transfered to RequestManager
944 _ResultInfo* pItem = new (std::nothrow) _ResultInfo(*pArg);
945 SysTryCatch(NID_APP, pItem != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
947 req = __resultManager.InsertItem(pItem);
948 SysTryCatch(NID_APP, req != -1, , r = E_INVALID_STATE, "[E_INVALID_STATE] Invalid argument handling state.");
950 handler = _AppArg::GetHandler(b);
962 _AppControlManager::IsAllowedAppControl(const char aTable[][2][96], int count, const String& aId, const String& oId)
964 for (int i = 0; i < count; i++)
966 if (aId == aTable[i][0] && oId == aTable[i][1])
968 SysLog(NID_APP, "Found entry (%s, %s)", aTable[i][0], aTable[i][1]);
978 _AppControlManager::ConvertAppControlResultCode(int resCode)
980 AppCtrlResult ret = APP_CTRL_RESULT_FAILED;
984 case SERVICE_RESULT_SUCCEEDED:
985 ret = APP_CTRL_RESULT_SUCCEEDED;
987 case SERVICE_RESULT_FAILED:
988 ret = APP_CTRL_RESULT_CANCELED;
990 case SERVICE_RESULT_CANCELED:
991 ret = APP_CTRL_RESULT_ABORTED;
993 case APPSVC_OSP_RES_FAIL:
994 ret = APP_CTRL_RESULT_FAILED;
996 case APPSVC_OSP_RES_TERMINATE:
997 ret = APP_CTRL_RESULT_TERMINATED;
1000 ret = APP_CTRL_RESULT_FAILED;
1009 _AppControlManager::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
1011 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
1013 if (pEventArg != null)
1015 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
1017 if(pResponseListener != null)
1019 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_START)
1021 pResponseListener->OnAppControlStartResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetResult());
1022 SysLog(NID_APP, "OnAppControlStartResponseReceived called");
1026 InvokeAppControlCompleteListener(*pResponseListener, pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData());
1027 SysLog(NID_APP, "Listener called");
1029 _AppControlResponseEvent* pResponseEvent = null;
1030 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
1031 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
1033 delete pResponseEvent;
1034 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
1039 SysLog(NID_APP, "Invalid ResponseListener");
1044 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);
1049 _AppControlManager::GetAliasAppId(const AppId& appId)
1051 return _AppControlRegistry::GetInstance()->GetAliasAppId(appId);