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 noRaise)
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 noRaise)
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);
296 const bool isServiceCallee = (property & _APPCONTROL_PROPERTY_SERVICE_CALLEE);
300 IAppControlEventListener* pListener = dynamic_cast<IAppControlEventListener*>(pInfo->pListener);
303 ArrayList list(SingleObjectDeleter);
304 _AppArg::FillLegacyAppControlResult(list, res, pArgs, aId);
306 InvokeLegacyAppControlCompleteListener(*pListener, aId, oId, &list, isSubMode | isServiceCallee);
310 SysLog(NID_APP, "Wrong AppControl listener type.");
315 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
318 _AppControlResponseEvent* pResponseEvent = null;
319 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + reqId;
320 __appControlResponseEventContainer.GetValue(responseEventRequestId, pResponseEvent);
322 if (pResponseEvent != null)
324 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, aId, oId, E_SUCCESS, static_cast<AppCtrlResult>(res), const_cast<IMap*> (pArgs), responseEventRequestId, isSubMode);
325 if (pResponseEventArg != null)
327 pResponseEvent->Fire(*pResponseEventArg);
328 SysLog(NID_APP, "pResponseEvent is Fired");
333 InvokeAppControlCompleteListener(*pListener, aId, oId, ConvertAppControlResultCode(res), pArgs, isSubMode | isServiceCallee);
334 SysLog(NID_APP, "Listener called directly");
340 SysLog(NID_APP, "Wrong AppControl listener type.");
346 SysLogException(NID_APP, E_SYSTEM, "Invalid AppControl listener.");
349 // call TerminateAppControl
350 result (* pFunc)(int req) = null;
351 pFunc = reinterpret_cast<result (*)(int)>(pInfo->pLib->GetProcAddress(L"TerminateAppControl"));
354 (*pFunc)(pInfo->reqId);
358 SysLogException(NID_APP, E_SYSTEM, "No TerminateAppControl() function.");
361 // remove from list and unload dll
362 __inAppManager.RemoveItem(reqId);
367 _AppControlManager::SendAppControlEvent(IEventArg& arg)
369 return __appControlEvent.FireAsync(arg);
372 Tizen::Base::Collection::IMapT<int,_AppControlResponseEvent*>*
373 _AppControlManager::GetAppControlResponseEventContainer(void)
375 return &__appControlResponseEventContainer;
379 // generic launch callback
381 LaunchResultCb(bundle* b, int request_code, appsvc_result_val res, void* data)
383 SysLog(NID_APP, "SLP callee result: %d", res);
385 _AppControlManager* pImpl = static_cast<_AppControlManager*>(data);
391 _AppArg* pAppArg = new (std::nothrow) _AppArg;
392 SysTryReturnVoidResult(NID_APP, pAppArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
394 _AppControlEventArg* pArg = null;
395 result r = pAppArg->Construct(b);
396 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] AppControl event argument creation failure.", GetErrorMessage(r));
398 pArg = new (std::nothrow) _AppControlEventArg(request_code, pAppArg, res);
399 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
402 pImpl->SendAppControlEvent(*pArg);
412 _AppControlManager::SendAppControlStartResponse(int req, const char* pValue, const char* pOp)
414 _AppControlStartEventArg* pArg = new (std::nothrow) _AppControlStartEventArg(req, AppId(pValue), String(pOp));
415 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "AppControl start event creation failure.");
417 SendAppControlEvent(*pArg);
424 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
426 bundle* kb = msg.GetBundle();
427 SysTryReturnResult(NID_APP, kb != NULL, E_OUT_OF_MEMORY, "Bundle allocation failure.");
431 appsvc_set_pkgname(kb, pkg_name);
434 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
438 appsvc_set_mime(kb, mime);
443 appsvc_set_uri(kb, uri);
446 if (_AppImpl::GetInstance() != null)
448 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
449 _AppArg::UpdateWindowHandle(kb, handle);
452 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
453 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
455 result r = E_SUCCESS;
460 case APPSVC_RET_EILLACC:
461 r = E_ILLEGAL_ACCESS;
463 case APPSVC_RET_EINVAL:
470 SysLog(NID_APP, "[%s] Launching service %s failure", GetErrorMessage(r), pkg_name);
478 _AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
480 bundle* kb = msg.GetBundle();
481 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
485 appsvc_set_pkgname(kb, pkg_name);
488 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
492 appsvc_set_mime(kb, mime);
497 appsvc_set_uri(kb, uri);
500 if (_AppImpl::GetInstance() != null)
502 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
503 _AppArg::UpdateWindowHandle(kb, handle);
506 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
507 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
509 result r = E_SUCCESS;
514 case APPSVC_RET_EILLACC:
515 r = E_ILLEGAL_ACCESS;
517 case APPSVC_RET_EINVAL:
524 SysLog(NID_APP, "[%s]Launching service %s failure", GetErrorMessage(r), pkg_name);
533 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const AppId& appId, const String& opId, const String* pUri, const String* pMime, AppSvcResFn pCb, void* data)
535 std::unique_ptr<char[]> pPackage(_StringConverter::CopyToCharArrayN(appId));
536 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(opId));
538 const char* pUriData = null;
541 pUriData = _StringConverter::CopyToCharArrayN(*pUri);
544 const char* pMimeData = null;
547 pMimeData = _StringConverter::CopyToCharArrayN(*pMime);
550 int pid = Launch(msg, pPackage.get(), pOperation.get(), pMimeData, pUriData, pCb, data);
560 _AppControlManager::LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
564 return LaunchPkg(msg, pkg_name, op, mime, uri, pCb, data);
568 _AppControlManager::LaunchAppWithCondition(const AppId& appId, const String& condition, IList* pArrayArgs)
570 result r = E_SUCCESS;
571 _AppArg * pArg = new (std::nothrow) _AppArg();
572 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
574 r = pArg->ConstructForAppLaunchCondition(condition, pArrayArgs);
575 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] ConstructForAppLaunchCondition(%ls, .. ) fails", GetErrorMessage(r), condition.GetPointer());
577 r = _AppControlManager::LaunchApp(appId, pArg);
584 _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
586 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
587 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
589 String actualAppId = appId;
590 if (appId.GetLength() == 10)
592 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
596 actualAppId.Append(L'.');
597 actualAppId.Append(name);
601 pArg->UpdateRequestId(req);
603 if (_AppImpl::GetInstance() != null)
605 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
606 pArg->UpdateWindowHandle(handle);
612 actualAppId.SubString(0, 10, tempId);
614 tempId += L"_AppControl";
616 // [INFO] Ugly solution for submode support
617 pArg->UpdateAppId(tempId);
618 kb = pArg->GetBundle();
620 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
623 SysLog(NID_APP, "Submode launch successful");
626 else if (pid == APPSVC_RET_EINVAL)
628 SysLog(NID_APP, "Argument overflow");
629 return E_MAX_EXCEEDED;
632 pArg->UpdateAppId(actualAppId);
634 // retry for possible failure
636 const int TRY_COUNT = 3;
637 const int TRY_SLEEP_TIME = 65;
640 kb = pArg->GetBundle();
641 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
644 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
647 else if (pid == APPSVC_RET_EINVAL)
649 SysLog(NID_APP, "Argument overflow");
650 return E_MAX_EXCEEDED;
654 SysLog(NID_APP, "Waiting %dth time.", count);
655 Thread::Sleep(TRY_SLEEP_TIME);
657 while (count < TRY_COUNT);
659 result r = E_SUCCESS;
662 case APPSVC_RET_EILLACC:
663 r = E_ILLEGAL_ACCESS;
670 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
676 _IsDefaultApplication(const AppId& packageId, const String& appId)
678 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
681 result r = appId.IndexOf(L'.', 0, index);
688 appId.SubString(index + 1, tmp);
691 SysLog(NID_APP, "Default application %ls", tmp.GetPointer());
700 _AppControlManager::Launch(const _AppMessageImpl& msg, const AppId& aId, const String& oId, const String* pUriData, const String* pMimeType, AppSvcResFn pCb, void* pData)
702 SysLog(NID_APP, "Enter");
705 arg.Construct(msg, oId, pUriData, pMimeType);
707 int pid = Launch(aId, &arg, pCb, pData, -1);
708 SysTryReturn(NID_APP, pid >= 0, -1, GetLastResult(), "Launching(%ls) is failed", aId.GetPointer());
710 SysLog(NID_APP, "Exit");
717 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
719 return Launch(appId, pArg, reinterpret_cast<AppSvcResFn>(LaunchResultCb), this, req);
724 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, AppSvcResFn pCb, void* pData, int req)
726 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid launch argument");
727 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
729 String actualAppId = appId;
731 if (appId.GetLength() == 10)
733 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
735 if (!execName.IsEmpty())
737 actualAppId.Append(L'.');
738 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 const int type = _AppInfo::GetAppType();
758 if ((!(type & _APP_TYPE_SERVICE_APP)) && _IsDefaultApplication(tempId, appId))
761 tempId += L"_AppControl";
763 // [INFO] Ugly solution for submode support
764 pArg->UpdateAppId(tempId);
765 kb = pArg->GetBundle();
767 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
770 SysLog(NID_APP, "Submode launch successful");
771 SetLastResult(E_SUCCESS);
774 else if (pid == APPSVC_RET_EINVAL)
776 SetLastResult(E_MAX_EXCEEDED);
781 pArg->UpdateAppId(actualAppId);
783 // retry for possible failure
785 const int TRY_COUNT = 3;
786 const int TRY_SLEEP_TIME = 65;
789 kb = pArg->GetBundle();
790 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
793 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
794 SetLastResult(E_SUCCESS);
797 else if (pid == APPSVC_RET_EINVAL)
799 SetLastResult(E_MAX_EXCEEDED);
804 SysLog(NID_APP, "Waiting %dth time with %d.", count, pid);
805 Thread::Sleep(TRY_SLEEP_TIME);
807 while (count < TRY_COUNT);
809 result r = E_SUCCESS;
812 case APPSVC_RET_EILLACC:
813 r = E_ILLEGAL_ACCESS;
820 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
828 _AppControlManager::LaunchAppImplicit(_AppArg* pArg, int req)
830 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
832 result r = E_SUCCESS;
833 bundle* kb = pArg->GetBundle();
837 pArg->UpdateRequestId(req);
838 appsvc_add_data(kb, SELECTOR_NOTI_KEY, appinfo_get_appid());
841 if (_AppImpl::GetInstance() != null)
843 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
844 _AppArg::UpdateWindowHandle(kb, handle);
847 int pid = appsvc_run_service(kb, req, LaunchResultCb, this);
852 SysLog(NID_APP, "Sending local process again.");
856 char pkgname[255] = {0, };
857 if (aul_app_get_pkgname_bypid(pid, pkgname, 255) != AUL_R_OK)
859 SysLog(NID_APP, "Fail to get package name by pid : (%d).", pid);
863 if (strncmp(pkgname, APP_SELECTOR, strlen(APP_SELECTOR)) != 0)
865 const char* pOperation = appsvc_get_operation(kb);
867 SysLog(NID_APP, "Starting application without selector : (%s, %s).", pkgname, pOperation);
869 SendAppControlStartResponse(req, pkgname, pOperation);
876 case APPSVC_RET_EINVAL:
879 case APPSVC_RET_ENOMATCH:
882 case APPSVC_RET_EILLACC:
883 r = E_ILLEGAL_ACCESS;
885 case APPSVC_RET_ERROR:
887 case APPSVC_RET_ELAUNCH:
895 SysLog(NID_APP, "[%s] Application(%d) launched with reqId(%d) and arg(0x%x).", GetErrorMessage(r), pid, req, pArg);
901 _AppControlManager::FinishAppControl(int reqId, int res, IMap* pMap)
903 SysLog(NID_APP, "req %d, res %d.", reqId, res);
904 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, pMap, _APPCONTROL_PROPERTY_SUBMODE);
905 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
907 SendAppControlEvent(*pArg);
908 SysLog(NID_APP, "Exit.");
912 _AppControlManager::RemoveResultRequest(int reqId)
914 __resultManager.RemoveItem(reqId);
918 _AppControlManager::FindResultRequest(int reqId) const
920 const _ResultInfo* pInfo = __resultManager.FindItem(reqId);
921 return (pInfo) ? &(pInfo->arg) : null;
925 _AppControlManager::AddLaunchRequest(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
927 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
929 _LaunchInfo* pItem = new (std::nothrow) _LaunchInfo(pArg, pCb, pData, prop);
930 SysTryReturn(NID_APP, pItem != null, -1, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
932 SysLog(NID_APP, "Registering callback 0x%x, 0x%x", pCb, pData);
934 return __launchManager.InsertItem(pItem);
938 _AppControlManager::RemoveLaunchRequest(int req)
940 __launchManager.RemoveItem(req);
944 _AppControlManager::RegisterRequest(service_s* service, int& req, _AppHandler& handler)
946 bundle* b = _AppArg::GetBundleFromSvc(service);
948 _AppArg* pArg = new (std::nothrow) _AppArg();
949 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
952 result r = E_SUCCESS;
954 // ownership is transfered to RequestManager
955 _ResultInfo* pItem = new (std::nothrow) _ResultInfo(*pArg);
956 SysTryCatch(NID_APP, pItem != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
958 req = __resultManager.InsertItem(pItem);
959 SysTryCatch(NID_APP, req != -1, , r = E_INVALID_STATE, "[E_INVALID_STATE] Invalid argument handling state.");
961 handler = _AppArg::GetHandler(b);
973 _AppControlManager::IsAllowedAppControl(const char aTable[][2][96], int count, const String& aId, const String& oId)
975 for (int i = 0; i < count; i++)
977 if (aId == aTable[i][0] && oId == aTable[i][1])
979 SysLog(NID_APP, "Found entry (%s, %s)", aTable[i][0], aTable[i][1]);
989 _AppControlManager::ConvertAppControlResultCode(int resCode)
991 AppCtrlResult ret = APP_CTRL_RESULT_FAILED;
995 case SERVICE_RESULT_SUCCEEDED:
996 ret = APP_CTRL_RESULT_SUCCEEDED;
998 case SERVICE_RESULT_FAILED:
999 ret = APP_CTRL_RESULT_CANCELED;
1001 case SERVICE_RESULT_CANCELED:
1002 ret = APP_CTRL_RESULT_ABORTED;
1004 case APPSVC_OSP_RES_FAIL:
1005 ret = APP_CTRL_RESULT_FAILED;
1007 case APPSVC_OSP_RES_TERMINATE:
1008 ret = APP_CTRL_RESULT_TERMINATED;
1011 ret = APP_CTRL_RESULT_FAILED;
1020 _AppControlManager::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
1022 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
1024 if (pEventArg != null)
1026 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
1028 if(pResponseListener != null)
1030 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_START)
1032 pResponseListener->OnAppControlStartResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetResult());
1033 SysLog(NID_APP, "OnAppControlStartResponseReceived called");
1037 InvokeAppControlCompleteListener(*pResponseListener, pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData(), pEventArg->IsSubMode());
1038 SysLog(NID_APP, "Listener called");
1040 _AppControlResponseEvent* pResponseEvent = null;
1041 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
1042 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
1044 delete pResponseEvent;
1045 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
1050 SysLog(NID_APP, "Invalid ResponseListener");
1055 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);
1060 _AppControlManager::GetAliasAppId(const AppId& appId)
1062 return _AppControlRegistry::GetInstance()->GetAliasAppId(appId);