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 <FBaseRt_LibraryImpl.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"
58 #include "FApp_AppManagerEventArg.h"
60 #include "FApp_AppControlManager.h"
61 #include "FApp_AppManagerProxy.h"
62 #include "FApp_ConditionManagerProxy.h"
63 #include "FApp_IAppManagerEventListener.h"
64 #include "FApp_MapDataControlImpl.h"
65 #include "FApp_SqlDataControlImpl.h"
66 #include "FAppPkg_PackageManagerImpl.h"
67 #include "FAppPkg_PackageInfoImpl.h"
68 #include "FApp_AppMessageImpl.h"
69 #include "FApp_AppManagerImpl.h"
70 #include "FApp_AppControlResponseEvent.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;
81 const char SELECTOR_NOTI_KEY[] = "__APP_SVC_CALLER_NOTI__";
84 namespace Tizen { namespace App
86 const wchar_t TIZEN_OPERATION_PICK[] = L"http://tizen.org/appcontrol/operation/pick";
89 _AppControlManager::_AppControlManager(void)
93 // AppControl event handling is expected to be performed in the main thread.
94 __appControlEvent.Construct();
95 __appControlEvent.AddListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
96 __listenerList.Construct();
97 __appControlResponseEventContainer.Construct();
98 __appControlResponseEventList.Construct();
101 _AppControlManager::~_AppControlManager(void)
104 __appControlEvent.RemoveListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
105 IEnumeratorT<int>* pEnum = __appControlResponseEventList.GetEnumeratorN();
109 while(pEnum->MoveNext() == E_SUCCESS)
112 pEnum->GetCurrent(reqId);
113 _AppControlResponseEvent* pResponseEvent = null;
114 __appControlResponseEventContainer.GetValue(reqId, pResponseEvent);
115 delete pResponseEvent;
117 __appControlResponseEventContainer.Remove(reqId);
118 SysLog(NID_APP, "pResponseEvent gets deleted. reqId(%d)", reqId);
125 _AppControlManager::GetInstance(void)
127 static _AppControlManager inst;
133 _AppControlManager::GetMimeFromExt(const String& ext, String& out)
135 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(ext));
136 SysTryReturnResult(NID_APP, pExtension != null, E_OUT_OF_MEMORY, "String allocation failure.");
139 mime_type_get_mime_type(pExtension.get(), &mime);
141 SysTryReturnResult(NID_APP, mime != NULL, E_UNSUPPORTED_FORMAT, "MIME type conversion failure for %ls.", ext.GetPointer());
150 _AppControlManager::OnAppControlEventReceivedN(int reqId, _AppArg* pAppArg, int res)
152 SysLog(NID_APP, "Received request Id %d, arg 0x%x", reqId, pAppArg);
155 // get launch info from request Id
156 _LaunchInfo* pInfo = __launchManager.FindItem(reqId);
157 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with response %d", reqId,
163 if (pInfo->magic == LAUNCH_INFO_MAGIC)
165 SysLog(NID_APP, "Invoking callback 0x%x", pInfo->launchCb);
168 if (pInfo->pUserData && (!__listenerList.Contains(pInfo->pUserData)))
170 (*pInfo->launchCb)(pInfo->pUserData, pInfo->pArg, pAppArg, static_cast<service_result_e>(res), pInfo->property, reqId);
175 SysLogException(NID_APP, E_SYSTEM, "Corrupted data structure.");
180 __launchManager.RemoveItem(reqId);
184 // callback for out-of-process AppControl start event
186 _AppControlManager::OnAppControlEventReceivedN(int reqId, const AppId& appId, const String& operationId)
188 SysLog(NID_APP, "Received request Id %d, app %ls, operationId %ls", reqId, appId.GetPointer(), operationId.GetPointer());
190 // get launch info from request Id
191 _LaunchInfo* pInfo = __launchManager.FindItem(reqId);
192 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found.", reqId);
195 IAppControlResponseListener* pListener = static_cast<IAppControlResponseListener*>(pInfo->pUserData);
196 SysTryReturnVoidResult(NID_APP, typeid(pListener) == typeid(IAppControlResponseListener*), E_SYSTEM, "[E_SYSTEM] Invalid result callback.");
200 result r = E_SUCCESS;
201 AppId actualAppId = appId;
205 r = E_OPERATION_CANCELED;
207 SysLog(NID_APP, "Invoking callback 0x%x.", pListener);
209 _AppControlResponseEvent* pResponseEvent = null;
210 __appControlResponseEventContainer.GetValue(reqId, pResponseEvent);
211 SysLog(NID_APP, "StartResponseReceived Request Id(%d), ResponseEvent 0x%x.", reqId, pResponseEvent);
212 if (pResponseEvent != null)
214 String oId(operationId);
215 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_START, actualAppId, oId, r, APP_CTRL_RESULT_SUCCEEDED, null, reqId, false);
217 if (pResponseEventArg != null)
219 pResponseEvent->Fire(*pResponseEventArg);
220 SysLog(NID_APP, "pResponseEvent is Fired");
225 pListener->OnAppControlStartResponseReceived(actualAppId, operationId, r);
226 SysLog(NID_APP, "OnAppControlStartResponseReceived called directly");
231 SysLog(NID_APP, "No listener registered.");
237 _AppControlManager::InvokeAppControlCompleteListener(IAppControlResponseListener& listener, const AppId& appId, const String& op, AppCtrlResult res, const IMap* pExtraData, bool isSubMode)
239 listener.OnAppControlCompleteResponseReceived(appId, op, res, pExtraData);
243 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
246 SysLog(NID_APP, "AppControl response finished.");
251 _AppControlManager::InvokeLegacyAppControlCompleteListener(IAppControlEventListener& listener, const AppId& appId, const String& op, const IList* pList, bool isSubMode)
253 listener.OnAppControlCompleted(appId, op, pList);
257 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
260 SysLog(NID_APP, "Legacy AppControl response finished.");
264 // callback for in-process event handling
266 _AppControlManager::OnAppControlEventReceivedN(int reqId, int res, const IMap* pArgs, int property)
268 SysLog(NID_APP, "Received request Id %d, res %d, args 0x%x", reqId, res, pArgs);
270 // process proper callback
271 _InProcessInfo* pInfo = __inAppManager.FindItem(reqId);
272 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with args 0x%x", reqId,
275 if (pInfo->pListener && (!__listenerList.Contains(pInfo->pListener)))
277 String aId = pInfo->providerId;
278 String oId = pInfo->operationId;
280 SysLog(NID_APP, "Invoking callback 0x%x for (%ls, %ls).", pInfo->pListener, aId.GetPointer(), oId.GetPointer());
282 if (pInfo->property & _APPCONTROL_PROPERTY_ALIAS)
284 const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
285 pEntry = _AppControlRegistry::GetInstance()->GetReverseAppControlAliasEntry(aId, oId);
288 aId = pEntry->provider;
289 oId = pEntry->operation;
291 SysLog(NID_APP, "Legacy AppControl (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
295 const bool isSubMode = (property & _APPCONTROL_PROPERTY_SUBMODE);
299 IAppControlEventListener* pListener = dynamic_cast<IAppControlEventListener*>(pInfo->pListener);
302 ArrayList list(SingleObjectDeleter);
303 _AppArg::FillLegacyAppControlResult(list, res, pArgs, aId);
305 InvokeLegacyAppControlCompleteListener(*pListener, aId, oId, &list, isSubMode);
309 SysLog(NID_APP, "Wrong AppControl listener type.");
314 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
317 _AppControlResponseEvent* pResponseEvent = null;
318 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + reqId;
319 __appControlResponseEventContainer.GetValue(responseEventRequestId, pResponseEvent);
321 if (pResponseEvent != null)
323 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, aId, oId, E_SUCCESS, static_cast<AppCtrlResult>(res), const_cast<IMap*> (pArgs), responseEventRequestId, isSubMode);
324 if (pResponseEventArg != null)
326 pResponseEvent->Fire(*pResponseEventArg);
327 SysLog(NID_APP, "pResponseEvent is Fired");
332 InvokeAppControlCompleteListener(*pListener, aId, oId, ConvertAppControlResultCode(res), pArgs, isSubMode);
333 SysLog(NID_APP, "Listener called directly");
339 SysLog(NID_APP, "Wrong AppControl listener type.");
345 SysLogException(NID_APP, E_SYSTEM, "Invalid AppControl listener.");
348 // call TerminateAppControl
349 result (* pFunc)(int req) = null;
350 pFunc = reinterpret_cast<result (*)(int)>(pInfo->pLib->GetProcAddress(L"TerminateAppControl"));
353 (*pFunc)(pInfo->reqId);
357 SysLogException(NID_APP, E_SYSTEM, "No TerminateAppControl() function.");
360 // remove from list and unload dll
361 __inAppManager.RemoveItem(reqId);
366 _AppControlManager::SendAppControlEvent(IEventArg& arg)
368 return __appControlEvent.FireAsync(arg);
371 Tizen::Base::Collection::IMapT<int,_AppControlResponseEvent*>*
372 _AppControlManager::GetAppControlResponseEventContainer(void)
374 return &__appControlResponseEventContainer;
378 // generic launch callback
380 LaunchResultCb(bundle* b, int request_code, appsvc_result_val res, void* data)
382 SysLog(NID_APP, "SLP callee result: %d", res);
384 _AppControlManager* pImpl = static_cast<_AppControlManager*>(data);
390 _AppArg* pAppArg = new (std::nothrow) _AppArg;
391 SysTryReturnVoidResult(NID_APP, pAppArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
393 _AppControlEventArg* pArg = null;
394 result r = pAppArg->Construct(b);
395 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] AppControl event argument creation failure.", GetErrorMessage(r));
397 pArg = new (std::nothrow) _AppControlEventArg(request_code, pAppArg, res);
398 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
401 pImpl->SendAppControlEvent(*pArg);
411 _AppControlManager::SendAppControlStartResponse(int req, const char* pValue, const char* pOp)
413 _AppControlStartEventArg* pArg = new (std::nothrow) _AppControlStartEventArg(req, AppId(pValue), String(pOp));
414 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "AppControl start event creation failure.");
416 SendAppControlEvent(*pArg);
423 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
425 bundle* kb = msg.GetBundle();
426 SysTryReturnResult(NID_APP, kb != NULL, E_OUT_OF_MEMORY, "Bundle allocation failure.");
430 appsvc_set_pkgname(kb, pkg_name);
433 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
437 appsvc_set_mime(kb, mime);
442 appsvc_set_uri(kb, uri);
445 if (_AppImpl::GetInstance() != null)
447 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
448 _AppArg::UpdateWindowHandle(kb, handle);
451 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
452 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
454 result r = E_SUCCESS;
459 case APPSVC_RET_EILLACC:
460 r = E_ILLEGAL_ACCESS;
462 case APPSVC_RET_EINVAL:
469 SysLog(NID_APP, "[%s] Launching service %s failure", GetErrorMessage(r), pkg_name);
477 _AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
479 bundle* kb = msg.GetBundle();
480 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
484 appsvc_set_pkgname(kb, pkg_name);
487 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
491 appsvc_set_mime(kb, mime);
496 appsvc_set_uri(kb, uri);
499 if (_AppImpl::GetInstance() != null)
501 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
502 _AppArg::UpdateWindowHandle(kb, handle);
505 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
506 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
508 result r = E_SUCCESS;
513 case APPSVC_RET_EILLACC:
514 r = E_ILLEGAL_ACCESS;
516 case APPSVC_RET_EINVAL:
523 SysLog(NID_APP, "[%s]Launching service %s failure", GetErrorMessage(r), pkg_name);
532 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const AppId& appId, const String& opId, const String* pUri, const String* pMime, AppSvcResFn pCb, void* data)
534 std::unique_ptr<char[]> pPackage(_StringConverter::CopyToCharArrayN(appId));
535 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(opId));
537 const char* pUriData = null;
540 pUriData = _StringConverter::CopyToCharArrayN(*pUri);
543 const char* pMimeData = null;
546 pMimeData = _StringConverter::CopyToCharArrayN(*pMime);
549 int pid = Launch(msg, pPackage.get(), pOperation.get(), pMimeData, pUriData, pCb, data);
559 _AppControlManager::LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
563 return LaunchPkg(msg, pkg_name, op, mime, uri, pCb, data);
567 _AppControlManager::LaunchAppWithCondition(const AppId& appId, const String& condition, IList* pArrayArgs)
569 result r = E_SUCCESS;
570 _AppArg * pArg = new (std::nothrow) _AppArg();
571 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
573 r = pArg->ConstructForAppLaunchCondition(condition, pArrayArgs);
574 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] ConstructForAppLaunchCondition(%ls, .. ) fails", GetErrorMessage(r), condition.GetPointer());
576 r = _AppControlManager::LaunchApp(appId, pArg);
583 _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
585 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
586 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
588 String actualAppId = appId;
589 if (appId.GetLength() == 10)
591 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
595 actualAppId.Append(L'.');
596 actualAppId.Append(name);
600 pArg->UpdateRequestId(req);
602 if (_AppImpl::GetInstance() != null)
604 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
605 pArg->UpdateWindowHandle(handle);
611 actualAppId.SubString(0, 10, tempId);
613 tempId += L"_AppControl";
615 // [INFO] Ugly solution for submode support
616 pArg->UpdateAppId(tempId);
617 kb = pArg->GetBundle();
619 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
622 SysLog(NID_APP, "Submode launch successful");
625 else if (pid == APPSVC_RET_EINVAL)
627 SysLog(NID_APP, "Argument overflow");
628 return E_MAX_EXCEEDED;
631 pArg->UpdateAppId(actualAppId);
633 // retry for possible failure
635 const int TRY_COUNT = 3;
636 const int TRY_SLEEP_TIME = 65;
639 kb = pArg->GetBundle();
640 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
643 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
646 else if (pid == APPSVC_RET_EINVAL)
648 SysLog(NID_APP, "Argument overflow");
649 return E_MAX_EXCEEDED;
653 SysLog(NID_APP, "Waiting %dth time.", count);
654 Thread::Sleep(TRY_SLEEP_TIME);
656 while (count < TRY_COUNT);
658 result r = E_SUCCESS;
661 case APPSVC_RET_EILLACC:
662 r = E_ILLEGAL_ACCESS;
669 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
675 _IsDefaultApplication(const AppId& packageId, const String& appId)
677 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
680 result r = appId.IndexOf(L'.', 0, index);
687 appId.SubString(index + 1, tmp);
690 SysLog(NID_APP, "Default application %ls", tmp.GetPointer());
699 _AppControlManager::Launch(const _AppMessageImpl& msg, const AppId& aId, const String& oId, const String* pUriData, const String* pMimeType, AppSvcResFn pCb, void* pData)
701 SysLog(NID_APP, "Enter");
704 arg.Construct(msg, oId, pUriData, pMimeType);
706 int pid = Launch(aId, &arg, pCb, pData, -1);
707 SysTryReturn(NID_APP, pid >= 0, -1, GetLastResult(), "Launching(%ls) is failed", aId.GetPointer());
709 SysLog(NID_APP, "Exit");
716 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
718 return Launch(appId, pArg, reinterpret_cast<AppSvcResFn>(LaunchResultCb), this, req);
723 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, AppSvcResFn pCb, void* pData, int req)
725 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid launch argument");
726 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
728 String actualAppId = appId;
730 if (appId.GetLength() == 10)
732 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
734 if (!execName.IsEmpty())
736 actualAppId.Append(L'.');
737 actualAppId.Append(execName);
742 pArg->UpdateRequestId(req);
744 if (_AppImpl::GetInstance() != null)
746 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
747 pArg->UpdateWindowHandle(handle);
754 actualAppId.SubString(0, 10, tempId);
756 const int type = _AppInfo::GetAppType();
757 if ((!(type & _APP_TYPE_SERVICE_APP)) && _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 appsvc_add_data(kb, SELECTOR_NOTI_KEY, appinfo_get_appid());
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 if (aul_app_get_pkgname_bypid(pid, pkgname, 255) != AUL_R_OK)
858 SysLog(NID_APP, "Fail to get package name by pid : (%d).", pid);
862 if (strncmp(pkgname, APP_SELECTOR, strlen(APP_SELECTOR)) != 0)
864 const char* pOperation = appsvc_get_operation(kb);
866 SysLog(NID_APP, "Starting application without selector : (%s, %s).", pkgname, pOperation);
868 SendAppControlStartResponse(req, pkgname, pOperation);
875 case APPSVC_RET_EINVAL:
878 case APPSVC_RET_ENOMATCH:
881 case APPSVC_RET_EILLACC:
882 r = E_ILLEGAL_ACCESS;
884 case APPSVC_RET_ERROR:
886 case APPSVC_RET_ELAUNCH:
894 SysLog(NID_APP, "[%s] Application(%d) launched with reqId(%d) and arg(0x%x).", GetErrorMessage(r), pid, req, pArg);
900 _AppControlManager::FinishAppControl(int reqId, int res, IMap* pMap)
902 SysLog(NID_APP, "req %d, res %d.", reqId, res);
903 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, pMap, _APPCONTROL_PROPERTY_SUBMODE);
904 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
906 SendAppControlEvent(*pArg);
907 SysLog(NID_APP, "Exit.");
911 _AppControlManager::RemoveResultRequest(int reqId)
913 __resultManager.RemoveItem(reqId);
917 _AppControlManager::FindResultRequest(int reqId) const
919 const _ResultInfo* pInfo = __resultManager.FindItem(reqId);
920 return (pInfo) ? &(pInfo->arg) : null;
924 _AppControlManager::AddLaunchRequest(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
926 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
928 _LaunchInfo* pItem = new (std::nothrow) _LaunchInfo(pArg, pCb, pData, prop);
929 SysTryReturn(NID_APP, pItem != null, -1, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
931 SysLog(NID_APP, "Registering callback 0x%x, 0x%x", pCb, pData);
933 return __launchManager.InsertItem(pItem);
937 _AppControlManager::RemoveLaunchRequest(int req)
939 __launchManager.RemoveItem(req);
943 _AppControlManager::RegisterRequest(service_s* service, int& req, _AppHandler& handler)
945 bundle* b = _AppArg::GetBundleFromSvc(service);
947 _AppArg* pArg = new (std::nothrow) _AppArg();
948 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
951 result r = E_SUCCESS;
953 // ownership is transfered to RequestManager
954 _ResultInfo* pItem = new (std::nothrow) _ResultInfo(*pArg);
955 SysTryCatch(NID_APP, pItem != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
957 req = __resultManager.InsertItem(pItem);
958 SysTryCatch(NID_APP, req != -1, , r = E_INVALID_STATE, "[E_INVALID_STATE] Invalid argument handling state.");
960 handler = _AppArg::GetHandler(b);
972 _AppControlManager::IsAllowedAppControl(const char aTable[][2][96], int count, const String& aId, const String& oId)
974 for (int i = 0; i < count; i++)
976 if (aId == aTable[i][0] && oId == aTable[i][1])
978 SysLog(NID_APP, "Found entry (%s, %s)", aTable[i][0], aTable[i][1]);
988 _AppControlManager::ConvertAppControlResultCode(int resCode)
990 AppCtrlResult ret = APP_CTRL_RESULT_FAILED;
994 case SERVICE_RESULT_SUCCEEDED:
995 ret = APP_CTRL_RESULT_SUCCEEDED;
997 case SERVICE_RESULT_FAILED:
998 ret = APP_CTRL_RESULT_CANCELED;
1000 case SERVICE_RESULT_CANCELED:
1001 ret = APP_CTRL_RESULT_ABORTED;
1003 case APPSVC_OSP_RES_FAIL:
1004 ret = APP_CTRL_RESULT_FAILED;
1006 case APPSVC_OSP_RES_TERMINATE:
1007 ret = APP_CTRL_RESULT_TERMINATED;
1010 ret = APP_CTRL_RESULT_FAILED;
1019 _AppControlManager::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
1021 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
1023 if (pEventArg != null)
1025 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
1027 if(pResponseListener != null)
1029 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_START)
1031 pResponseListener->OnAppControlStartResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetResult());
1032 SysLog(NID_APP, "OnAppControlStartResponseReceived called");
1036 InvokeAppControlCompleteListener(*pResponseListener, pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData(), pEventArg->IsSubMode());
1037 SysLog(NID_APP, "Listener called");
1039 _AppControlResponseEvent* pResponseEvent = null;
1040 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
1041 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
1043 delete pResponseEvent;
1044 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
1049 SysLog(NID_APP, "Invalid ResponseListener");
1054 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);
1059 _AppControlManager::GetAliasAppId(const AppId& appId)
1061 return _AppControlRegistry::GetInstance()->GetAliasAppId(appId);