2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FApp_AppControlManager.cpp
20 * @brief This is the implementation for the _AppControlManager class.
25 #include <unique_ptr.h>
27 #include <appsvc/appsvc.h>
30 #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;
79 namespace Tizen { namespace App
82 const wchar_t TIZEN_OPERATION_PICK[] = L"http://tizen.org/appcontrol/operation/pick";
83 const wchar_t SELECTOR_NOTI_KEY[] = L"__APP_SVC_CALLER_NOTI__";
84 const int _MAX_PACKAGE_ID_LENGTH = 10;
86 _InProcessInfo::~_InProcessInfo(void)
91 _LaunchInfo::~_LaunchInfo(void)
97 _AppControlManager::_AppControlManager(void)
101 // AppControl event handling is expected to be performed in the main thread.
102 __appControlEvent.Construct();
103 __appControlEvent.AddListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
104 __listenerList.Construct();
105 __pAppControlResponseEventContainer = new (std::nothrow)HashMapT<int, _AppControlResponseEvent*>;
106 __pAppControlResponseEventContainer->Construct();
107 __appControlResponseEventList.Construct();
110 _AppControlManager::~_AppControlManager(void)
113 __appControlEvent.RemoveListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
114 IEnumeratorT<int>* pEnum = __appControlResponseEventList.GetEnumeratorN();
118 while(pEnum->MoveNext() == E_SUCCESS)
121 pEnum->GetCurrent(reqId);
122 if (__pAppControlResponseEventContainer != null)
124 _AppControlResponseEvent* pResponseEvent = null;
125 __pAppControlResponseEventContainer->GetValue(reqId, pResponseEvent);
126 delete pResponseEvent;
128 __pAppControlResponseEventContainer->Remove(reqId);
129 SysLog(NID_APP, "pResponseEvent gets deleted. reqId(%d)", reqId);
133 delete __pAppControlResponseEventContainer;
138 _AppControlManager::GetInstance(void)
140 static _AppControlManager inst;
146 _AppControlManager::GetMimeFromExt(const String& ext, String& out)
148 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(ext));
149 SysTryReturnResult(NID_APP, pExtension != null, E_OUT_OF_MEMORY, "String allocation failure.");
152 mime_type_get_mime_type(pExtension.get(), &mime);
154 SysTryReturnResult(NID_APP, mime != NULL, E_UNSUPPORTED_FORMAT, "MIME type conversion failure for %ls.", ext.GetPointer());
163 _AppControlManager::OnAppControlEventReceivedN(int reqId, _AppArg* pAppArg, int res)
165 SysLog(NID_APP, "Received request Id %d, arg 0x%x", reqId, pAppArg);
168 // get launch info from request Id
169 _LaunchInfo* pInfo = __launchManager.FindItem(reqId);
170 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with response %d", reqId,
176 if (pInfo->magic == LAUNCH_INFO_MAGIC)
178 SysLog(NID_APP, "Invoking callback 0x%x", pInfo->launchCb);
181 if (pInfo->pUserData && (!__listenerList.Contains(pInfo->pUserData)))
183 (*pInfo->launchCb)(pInfo->pUserData, pInfo->pArg, pAppArg, static_cast<service_result_e>(res), pInfo->property, reqId);
188 SysLogException(NID_APP, E_SYSTEM, "Corrupted data structure.");
193 __launchManager.RemoveItem(reqId);
197 // callback for out-of-process AppControl start event
199 _AppControlManager::OnAppControlEventReceivedN(int reqId, const AppId& appId, const String& operationId)
201 SysLog(NID_APP, "Received request Id %d, app %ls, operationId %ls", reqId, appId.GetPointer(), operationId.GetPointer());
203 // get launch info from request Id
204 _LaunchInfo* pInfo = __launchManager.FindItem(reqId);
205 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found.", reqId);
208 IAppControlResponseListener* pListener = static_cast<IAppControlResponseListener*>(pInfo->pUserData);
209 SysTryReturnVoidResult(NID_APP, typeid(pListener) == typeid(IAppControlResponseListener*), E_SYSTEM, "[E_SYSTEM] Invalid result callback.");
213 result r = E_SUCCESS;
214 AppId actualAppId = appId;
218 r = E_OPERATION_CANCELED;
220 SysLog(NID_APP, "Invoking callback 0x%x.", pListener);
222 _AppControlResponseEvent* pResponseEvent = null;
223 __pAppControlResponseEventContainer->GetValue(reqId, pResponseEvent);
224 SysLog(NID_APP, "StartResponseReceived Request Id(%d), ResponseEvent 0x%x.", reqId, pResponseEvent);
225 if (pResponseEvent != null)
227 String oId(operationId);
228 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_START, actualAppId, oId, r, APP_CTRL_RESULT_SUCCEEDED, null, reqId);
230 if (pResponseEventArg != null)
232 pResponseEvent->Fire(*pResponseEventArg);
233 SysLog(NID_APP, "pResponseEvent is Fired");
238 pListener->OnAppControlStartResponseReceived(actualAppId, operationId, r);
239 SysLog(NID_APP, "OnAppControlStartResponseReceived called directly");
244 SysLog(NID_APP, "No listener registered.");
249 // callback for in-process event handling
251 _AppControlManager::OnAppControlEventReceivedN(int reqId, int res, const IMap* pArgs)
253 SysLog(NID_APP, "Received request Id %d, res %d, args 0x%x", reqId, res, pArgs);
255 // process proper callback
256 _InProcessInfo* pInfo = __inAppManager.FindItem(reqId);
257 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with args 0x%x", reqId,
260 if (pInfo->pListener)
262 String aId = pInfo->providerId;
263 String oId = pInfo->operationId;
265 SysLog(NID_APP, "Invoking callback 0x%x for (%ls, %ls).", pInfo->pListener, aId.GetPointer(), oId.GetPointer());
267 if (pInfo->property & _APPCONTROL_PROPERTY_ALIAS)
269 const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
270 pEntry = _AppControlRegistry::GetInstance()->GetReverseAppControlAliasEntry(aId, oId);
273 aId = pEntry->provider;
274 oId = pEntry->operation;
276 SysLog(NID_APP, "Legacy AppControl name (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
282 IAppControlEventListener* pListener = dynamic_cast<IAppControlEventListener*>(pInfo->pListener);
285 ArrayList list(SingleObjectDeleter);
286 _AppArg::FillLegacyAppControlResult(list, res, pArgs, aId);
288 pListener->OnAppControlCompleted(aId, oId, &list);
292 SysLog(NID_APP, "Wrong AppControl listener type.");
297 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
298 if (pListener && (!__listenerList.Contains(pInfo->pListener)))
300 _AppControlResponseEvent* pResponseEvent = null;
301 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + reqId;
302 __pAppControlResponseEventContainer->GetValue(responseEventRequestId, pResponseEvent);
304 if (pResponseEvent != null)
306 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, aId, oId, E_SUCCESS, static_cast<AppCtrlResult>(res), const_cast<IMap*> (pArgs), responseEventRequestId);
307 if (pResponseEventArg != null)
309 pResponseEvent->Fire(*pResponseEventArg);
310 SysLog(NID_APP, "pResponseEvent is Fired");
315 pListener->OnAppControlCompleteResponseReceived(aId, oId, ConvertAppControlResultCode(res), pArgs);
316 SysLog(NID_APP, "OnAppControlCompleteResponseReceived called directly");
317 IMap* pMap = const_cast<IMap*> (pArgs);
323 SysLog(NID_APP, "Wrong AppControl listener type.");
329 SysLogException(NID_APP, E_SYSTEM, "Invalid AppControl listener.");
332 // call TerminateAppControl
333 result (* pFunc)(int req) = null;
334 pFunc = reinterpret_cast<result (*)(int)>(pInfo->pLib->GetProcAddress(L"TerminateAppControl"));
337 (*pFunc)(pInfo->reqId);
341 SysLogException(NID_APP, E_SYSTEM, "No TerminateAppControl() function.");
344 // remove from list and unload dll
345 __inAppManager.RemoveItem(reqId);
350 _AppControlManager::SendAppControlEvent(IEventArg& arg)
352 return __appControlEvent.FireAsync(arg);
355 Tizen::Base::Collection::IMapT<int,_AppControlResponseEvent*>*
356 _AppControlManager::GetAppControlResponseEventContainer(void)
358 return __pAppControlResponseEventContainer;
362 // generic launch callback
364 LaunchResultCb(bundle* b, int request_code, appsvc_result_val res, void* data)
366 SysLog(NID_APP, "SLP callee result: %d", res);
368 _AppControlManager* pImpl = static_cast<_AppControlManager*>(data);
374 _AppArg* pAppArg = new (std::nothrow) _AppArg;
375 SysTryReturnVoidResult(NID_APP, pAppArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
377 _AppControlEventArg* pArg = null;
378 result r = pAppArg->Construct(b);
379 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] AppControl event argument creation failure.", GetErrorMessage(r));
381 pArg = new (std::nothrow) _AppControlEventArg(request_code, pAppArg, res);
382 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
385 pImpl->SendAppControlEvent(*pArg);
395 _AppControlManager::SendAppControlStartResponse(int req, const char* pValue, const char* pOp)
397 _AppControlStartEventArg* pArg = new (std::nothrow) _AppControlStartEventArg(req, AppId(pValue), String(pOp));
398 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "AppControl start event creation failure.");
400 SendAppControlEvent(*pArg);
407 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
409 bundle* kb = msg.GetBundle();
410 SysTryReturnResult(NID_APP, kb != NULL, E_OUT_OF_MEMORY, "Bundle allocation failure.");
414 appsvc_set_pkgname(kb, pkg_name);
417 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
421 appsvc_set_mime(kb, mime);
426 appsvc_set_uri(kb, uri);
429 if (_AppImpl::GetInstance() != null)
431 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
432 _AppArg::UpdateWindowHandle(kb, handle);
435 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
436 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
438 result r = E_SUCCESS;
443 case APPSVC_RET_EILLACC:
444 r = E_ILLEGAL_ACCESS;
450 SysLog(NID_APP, "[%s]Launching service %s failure", GetErrorMessage(r), pkg_name);
458 _AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
460 bundle* kb = msg.GetBundle();
461 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
465 appsvc_set_pkgname(kb, pkg_name);
468 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
472 appsvc_set_mime(kb, mime);
477 appsvc_set_uri(kb, uri);
480 if (_AppImpl::GetInstance() != null)
482 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
483 _AppArg::UpdateWindowHandle(kb, handle);
486 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
487 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
489 result r = E_SUCCESS;
494 case APPSVC_RET_EILLACC:
495 r = E_ILLEGAL_ACCESS;
501 SysLog(NID_APP, "[%s]Launching service %s failure", GetErrorMessage(r), pkg_name);
510 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const AppId& appId, const String& opId, const String* pUri, const String* pMime, AppSvcResFn pCb, void* data)
512 std::unique_ptr<char[]> pPackage(_StringConverter::CopyToCharArrayN(appId));
513 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(opId));
515 const char* pUriData = null;
518 pUriData = _StringConverter::CopyToCharArrayN(*pUri);
521 const char* pMimeData = null;
524 pMimeData = _StringConverter::CopyToCharArrayN(*pMime);
527 int pid = Launch(msg, pPackage.get(), pOperation.get(), pMimeData, pUriData, pCb, data);
537 _AppControlManager::LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
541 return LaunchPkg(msg, pkg_name, op, mime, uri, pCb, data);
545 _AppControlManager::LaunchAppWithCondition(const AppId& appId, const String& condition, IList* pArrayArgs)
547 result r = E_SUCCESS;
548 _AppArg * pArg = new (std::nothrow) _AppArg();
549 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
551 r = pArg->ConstructForAppLaunchCondition(condition, pArrayArgs);
552 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] ConstructForAppLaunchCondition(%ls, .. ) fails", GetErrorMessage(r), condition.GetPointer());
554 r = _AppControlManager::LaunchApp(appId, pArg);
561 _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
563 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
564 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
566 String actualAppId = appId;
567 if (appId.GetLength() == 10)
569 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
573 actualAppId.Append(L'.');
574 actualAppId.Append(name);
578 pArg->UpdateRequestId(req);
580 if (_AppImpl::GetInstance() != null)
582 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
583 pArg->UpdateWindowHandle(handle);
589 actualAppId.SubString(0, 10, tempId);
591 tempId += L"_AppControl";
593 // [INFO] Ugly solution for submode support
594 pArg->UpdateAppId(tempId);
595 kb = pArg->GetBundle();
597 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
600 SysLog(NID_APP, "Submode launch successful");
604 pArg->UpdateAppId(actualAppId);
606 // retry for possible failure
608 const int TRY_COUNT = 3;
609 const int TRY_SLEEP_TIME = 65;
612 kb = pArg->GetBundle();
613 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
616 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
620 SysLog(NID_APP, "Waiting %dth time.", count);
621 Thread::Sleep(TRY_SLEEP_TIME);
623 while (count < TRY_COUNT);
625 result r = E_SUCCESS;
628 case APPSVC_RET_EILLACC:
629 r = E_ILLEGAL_ACCESS;
636 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
642 _IsDefaultApplication(const AppId& packageId, const String& appId)
644 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
647 result r = appId.IndexOf(L'.', 0, index);
654 appId.SubString(index + 1, tmp);
657 SysLog(NID_APP, "Default application %ls", tmp.GetPointer());
666 _AppControlManager::Launch(const _AppMessageImpl& msg, const AppId& aId, const String& oId, const String* pUriData, const String* pMimeType, AppSvcResFn pCb, void* pData)
668 SysLog(NID_APP, "Enter");
671 arg.Construct(msg, oId, pUriData, pMimeType);
673 int pid = Launch(aId, &arg, pCb, pData, -1);
674 SysTryReturn(NID_APP, pid >= 0, -1, GetLastResult(), "Launching(%ls) is failed", aId.GetPointer());
676 SysLog(NID_APP, "Exit");
683 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
685 return Launch(appId, pArg, reinterpret_cast<AppSvcResFn>(LaunchResultCb), this, req);
690 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, AppSvcResFn pCb, void* pData, int req)
692 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid launch argument");
693 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
695 String actualAppId = appId;
696 if (appId.GetLength() == 10)
698 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
700 if (!execName.IsEmpty())
702 actualAppId.Append(L'.');
703 actualAppId.Append(execName);
707 pArg->UpdateRequestId(req);
709 if (_AppImpl::GetInstance() != null)
711 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
712 pArg->UpdateWindowHandle(handle);
719 actualAppId.SubString(0, 10, tempId);
721 if (_IsDefaultApplication(tempId, appId))
724 tempId += L"_AppControl";
726 // [INFO] Ugly solution for submode support
727 pArg->UpdateAppId(tempId);
728 kb = pArg->GetBundle();
730 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
733 SysLog(NID_APP, "Submode launch successful");
738 pArg->UpdateAppId(actualAppId);
740 // retry for possible failure
742 const int TRY_COUNT = 3;
743 const int TRY_SLEEP_TIME = 65;
746 kb = pArg->GetBundle();
747 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
750 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
754 SysLog(NID_APP, "Waiting %dth time.", count);
755 Thread::Sleep(TRY_SLEEP_TIME);
757 while (count < TRY_COUNT);
759 result r = E_SUCCESS;
762 case APPSVC_RET_EILLACC:
763 r = E_ILLEGAL_ACCESS;
770 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
778 _AppControlManager::LaunchAppImplicit(_AppArg* pArg, int req)
780 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
782 result r = E_SUCCESS;
783 bundle* kb = pArg->GetBundle();
787 pArg->UpdateRequestId(req);
788 _AppMessageImpl::AddData(kb, SELECTOR_NOTI_KEY, _AppInfo::GetApplicationId());
791 if (_AppImpl::GetInstance() != null)
793 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
794 _AppArg::UpdateWindowHandle(kb, handle);
797 int pid = appsvc_run_service(kb, req, LaunchResultCb, this);
800 char pkgname[255] = {0, };
801 aul_app_get_pkgname_bypid(pid, pkgname, 255);
803 if (strncmp(pkgname, APP_SELECTOR, strlen(APP_SELECTOR)) != 0)
805 const char* pOperation = appsvc_get_operation(kb);
807 SysLog(NID_APP, "Starting application without selector : (%s, %s).", pkgname, pOperation);
809 SendAppControlStartResponse(req, pkgname, pOperation);
816 case APPSVC_RET_EINVAL:
819 case APPSVC_RET_ENOMATCH:
822 case APPSVC_RET_EILLACC:
823 r = E_ILLEGAL_ACCESS;
825 case APPSVC_RET_ERROR:
827 case APPSVC_RET_ELAUNCH:
835 SysLog(NID_APP, "[%s] Application(%d) launched with reqId(%d) and arg(0x%x).", GetErrorMessage(r), pid, req, pArg);
841 _AppControlManager::FinishAppControl(int reqId, int res, IMap* pMap)
843 SysLog(NID_APP, "req %d, res %d.", reqId, res);
844 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, pMap);
845 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
847 SendAppControlEvent(*pArg);
848 SysLog(NID_APP, "Exit.");
852 _AppControlManager::FindResultRequest(int reqId) const
854 const _ResultInfo* pInfo = __resultManager.FindItem(reqId);
855 return (pInfo) ? &(pInfo->arg) : null;
859 _AppControlManager::AddLaunchRequest(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
861 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
863 _LaunchInfo* pItem = new (std::nothrow) _LaunchInfo(pArg, pCb, pData, prop);
864 SysTryReturn(NID_APP, pItem != null, -1, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
866 SysLog(NID_APP, "Registering callback 0x%x, 0x%x", pCb, pData);
868 return __launchManager.InsertItem(pItem);
872 _AppControlManager::RemoveLaunchRequest(int req)
874 __launchManager.RemoveItem(req);
877 _AppControlManager::GetLaunchRequestCount(void)
879 return __launchManager.GetCount();
883 _AppControlManager::RegisterRequest(service_s* service, int& req, _AppHandler& handler)
885 bundle* b = _AppArg::GetBundleFromSvc(service);
887 _AppArg* pArg = new (std::nothrow) _AppArg();
888 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
891 result r = E_SUCCESS;
893 // ownership is transfered to RequestManager
894 _ResultInfo* pItem = new (std::nothrow) _ResultInfo(*pArg);
895 SysTryCatch(NID_APP, pItem != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
897 req = __resultManager.InsertItem(pItem);
898 SysTryCatch(NID_APP, req != -1, , r = E_INVALID_STATE, "[E_INVALID_STATE] Invalid argument handling state.");
900 handler = _AppArg::GetHandler(b);
912 _AppControlManager::IsAllowedAppControl(const char aTable[][2][96], int count, const String& aId, const String& oId)
914 for (int i = 0; i < count; i++)
916 if (aId == aTable[i][0] && oId == aTable[i][1])
918 SysLog(NID_APP, "Found entry (%s, %s)", aTable[i][0], aTable[i][1]);
928 _AppControlManager::ConvertAppControlResultCode(int resCode)
930 AppCtrlResult ret = APP_CTRL_RESULT_FAILED;
934 case SERVICE_RESULT_SUCCEEDED:
935 ret = APP_CTRL_RESULT_SUCCEEDED;
937 case SERVICE_RESULT_FAILED:
938 ret = APP_CTRL_RESULT_CANCELED;
940 case SERVICE_RESULT_CANCELED:
941 ret = APP_CTRL_RESULT_ABORTED;
943 case APPSVC_OSP_RES_FAIL:
944 ret = APP_CTRL_RESULT_FAILED;
946 case APPSVC_OSP_RES_TERMINATE:
947 ret = APP_CTRL_RESULT_TERMINATED;
950 ret = APP_CTRL_RESULT_FAILED;
959 _AppControlManager::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
961 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
963 if (pEventArg != null)
965 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
967 if(pResponseListener != null)
969 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_START)
971 pResponseListener->OnAppControlStartResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetResult());
972 SysLog(NID_APP, "OnAppControlStartResponseReceived called");
976 pResponseListener->OnAppControlCompleteResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData());
977 SysLog(NID_APP, "OnAppControlCompleteResponseReceived called");
979 _AppControlResponseEvent* pResponseEvent = null;
980 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
981 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
983 delete pResponseEvent;
984 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
989 SysLog(NID_APP, "Invalid ResponseListener");
994 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);
999 _AppControlManager::GetAliasAppId(const AppId& appId)
1001 return _AppControlRegistry::GetInstance()->GetAliasAppId(appId);