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_AppControlImpl.cpp
19 * @brief This is the implementation for the Application Control class.
24 #include <unique_ptr.h>
26 #include <appsvc/appsvc.h>
28 #include <FAppAppControl.h>
29 #include <FAppAppManager.h>
30 #include <FAppPkgPackageAppInfo.h>
31 #include <FBaseColHashMap.h>
32 #include <FBaseSysLog.h>
34 #include <FBaseRt_LibraryImpl.h>
35 #include <FIo_DirectoryImpl.h>
37 #include "FApp_AppControlImpl.h"
38 #include "FApp_AppControlManager.h"
39 #include "FApp_AppArg.h"
40 #include "FApp_AppControlRegistry.h"
41 #include "FApp_AppMessageImpl.h"
42 #include "FApp_AppInfo.h"
43 #include "FAppPkg_PackageManagerImpl.h"
45 #include "FApp_AppControlEventArg.h"
46 #include "FApp_AppControlResponseEvent.h"
47 #include "FBaseRt_ThreadImpl.h"
49 using namespace Tizen::Base;
50 using namespace Tizen::Base::Collection;
51 using namespace Tizen::Base::Runtime;
52 using namespace Tizen::App;
53 using namespace Tizen::App::Package;
54 using namespace Tizen::Io;
59 static const int _REQ_ID_INVALID = -1;
63 namespace Tizen { namespace App
66 class IAppControlEventListener;
67 class IAppControlResponseListener;
69 const wchar_t TIZEN_OPERATION_MAIN[] = L"http://tizen.org/appcontrol/operation/main";
71 _AppControlImpl::_AppControlImpl(const AppControl& value)
73 , _reqId(_REQ_ID_INVALID)
74 , _property(_APPCONTROL_PROPERTY_NONE)
75 , _processId(_REQ_ID_INVALID)
77 __appControlResponseEventList.Construct();
80 _AppControlImpl::~_AppControlImpl(void)
82 IEnumeratorT<int>* pEnum = __appControlResponseEventList.GetEnumeratorN();
83 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = null;
86 pResponseEventContainer = _AppControlManager::GetInstance()->GetAppControlResponseEventContainer();
89 while(pEnum->MoveNext() == E_SUCCESS)
92 pEnum->GetCurrent(reqId);
93 if (pResponseEventContainer != null)
95 _AppControlResponseEvent* pResponseEvent = null;
96 pResponseEventContainer->GetValue(reqId, pResponseEvent);
97 delete pResponseEvent;
99 pResponseEventContainer->Remove(reqId);
100 SysLog(NID_APP, "pResponseEvent gets deleted. reqId(%d)", reqId);
107 _AppControlImpl::CreateN(const String& path, const String& aId, const String& oId, const String& name, int prop)
109 SysTryReturn(NID_APP, !path.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] Path is empty.");
110 SysTryReturn(NID_APP, !aId.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] Provider Id is empty.");
111 SysTryReturn(NID_APP, !oId.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] Operation Id is empty.");
113 AppControl* pAc = new (std::nothrow) AppControl;
114 SysTryReturn(NID_APP, pAc != null, null, E_OUT_OF_MEMORY, "AppControl allocation failure.");
116 _AppControlImpl* pImpl = pAc->__pAppControlImpl;
117 SysTryReturn(NID_APP, pImpl != null, null, E_OUT_OF_MEMORY, "AppControlImpl instance must not be null.");
120 pImpl->_provider = aId;
122 // [FIXME] Proper App name setting
123 pImpl->_appName = name;
124 pImpl->_property = prop;
130 _AppControlImpl::CreateN(const AppId& appId, const String& operationId, bool changeAppId)
132 SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] appId is empty.");
134 AppControl* pAc = new (std::nothrow) AppControl;
135 SysTryReturn(NID_APP, pAc != null, null, E_OUT_OF_MEMORY, "AppControl allocation failure.");
137 _AppControlImpl* pImpl = pAc->__pAppControlImpl;
138 SysTryReturn(NID_APP, pImpl != null, null, E_OUT_OF_MEMORY, "AppControlImpl instance must not be null.");
140 pImpl->_path = appId;
141 pImpl->_provider = appId;
142 pImpl->_opId = operationId;
143 //pImpl->_appName = appId;
144 pImpl->_property |= (_APPCONTROL_PROPERTY_OSP | _APPCONTROL_PROPERTY_PUBLIC);
148 pImpl->_property |= _APPCONTROL_PROPERTY_APPID_CHANGE;
155 _AppControlImpl::CreateN(const AppControl& ac)
157 const _AppControlImpl* pImpl = GetInstance(ac);
158 SysTryReturn(NID_APP, pImpl != null, null, E_INVALID_STATE, "AppControlImpl instance must not be null.");
160 return CreateN(pImpl->_path, pImpl->_provider, pImpl->_opId, pImpl->_appName, pImpl->_property);
163 const _AppControlImpl*
164 _AppControlImpl::GetInstance(const AppControl& ac)
166 return ac.__pAppControlImpl;
170 _AppControlImpl::GetInstance(AppControl& ac)
172 return ac.__pAppControlImpl;
176 _AppControlImpl::Start(const IList* pDataList, IAppControlEventListener* pListener)
178 SysLog(NID_APP, "Enter");
181 if (_property & _APPCONTROL_PROPERTY_SLP)
183 r = StartNative(pDataList, pListener);
185 else if (_property & _APPCONTROL_PROPERTY_OSP)
187 r = StartOsp(pDataList, pListener);
191 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Invalid AppControl type(property %d)", _property);
193 SysLog(NID_APP, "Exit");
199 _AppControlImpl::Start(const String* pUriData, const String* pDataType, const IMap* pExtraData, IAppControlResponseListener* pListener)
201 SysLog(NID_APP, "Enter");
204 if (_property & _APPCONTROL_PROPERTY_SLP)
206 r = StartNative(pUriData, pDataType, pExtraData, pListener);
208 else if (_property & _APPCONTROL_PROPERTY_OSP)
210 r = StartOsp(pUriData, pDataType, pExtraData, pListener);
214 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Invalid AppControl type(property %d)", _property);
216 SysLog(NID_APP, "Exit");
222 _AppControlImpl::FindAndStart(const String& operationId, const String* pUriPattern, const String* pDataType, const String* pCategory, const IMap* pExtraData, IAppControlResponseListener* pListener)
224 // [FIXME] valid argument size checking required
225 SysLog(NID_APP, "Enter");
227 std::unique_ptr<bundle, BundleDeleter> pBundle(bundle_create());
228 SysTryReturnResult(NID_APP, pBundle.get(), E_OUT_OF_MEMORY, "Bundle creation failure.");
230 _AppMessageImpl::SetOperation(pBundle.get(), operationId);
234 _AppMessageImpl::SetUri(pBundle.get(), *pUriPattern);
239 String mimeType = *pDataType;
241 if ((*pDataType)[0] == L'.')
243 SysLog(NID_APP, "Extension to MIME conversion for %ls", pDataType->GetPointer());
247 pDataType->SubString(1, ext);
249 result r = _AppControlManager::GetMimeFromExt(ext, mimeType);
251 SysTryReturn(NID_APP, !IsFailed(r), null, r, "[%s] MIME type conversion failure for %ls.", GetErrorMessage(r), ext.GetPointer());
253 pMimeType = &mimeType;
255 SysLog(NID_APP, "Conversion : %ls -> %ls.", pDataType->GetPointer(), pMimeType->GetPointer());
259 _AppMessageImpl::SetMime(pBundle.get(), mimeType);
264 _AppMessageImpl::SetCategory(pBundle.get(), *pCategory);
267 return StartImplicit(pBundle.get(), pExtraData, pListener);
271 _AppControlImpl::StartOsp(const IList* pDataList, IAppControlEventListener* pListener)
273 SysLog(NID_APP, "Enter");
274 result r = E_SUCCESS;
276 _AppArg* pArg = new (std::nothrow) _AppArg;
277 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
279 pArg->Construct(*this, pDataList);
281 _AppControlManager* pImpl = _AppControlManager::GetInstance();
282 int req = _REQ_ID_INVALID;
286 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCbLegacy, pListener, _property);
287 req = reqObj.GetRequestNumber();
289 _processId = pImpl->Launch(_path, pArg, req);
295 SysLog(NID_APP, "[%s]Launching(%ls) is failed" , GetErrorMessage(r), _path.GetPointer());
301 _processId = pImpl->Launch(_path, pArg);
303 SysTryReturnResult(NID_APP, _processId >= 0, GetLastResult(), "Launching(%ls) is failed", _path.GetPointer());
305 SysLog(NID_APP, "Exit");
311 _AppControlImpl::StartOsp(const String* pUriData, const String* pMimeType, const IMap* pDataList, IAppControlResponseListener* pListener)
313 SysLog(NID_APP, "Enter");
314 result r = E_SUCCESS;
316 _AppArg* pArg = new (std::nothrow) _AppArg;
317 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
319 pArg->Construct(*this, pUriData, pMimeType, pDataList);
321 _AppControlManager* pImpl = _AppControlManager::GetInstance();
322 int req = _REQ_ID_INVALID;
326 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCb, pListener, _property);
327 req = reqObj.GetRequestNumber();
329 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
331 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
332 if (pAppControlResponseEvent != null)
334 r = pAppControlResponseEvent->Construct();
335 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
337 r = pAppControlResponseEvent->AddListener(*this, true);
338 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
340 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = pImpl->GetAppControlResponseEventContainer();
341 if (pResponseEventContainer != null)
343 pResponseEventContainer->Add(req, pAppControlResponseEvent);
344 __appControlResponseEventList.Add(req);
345 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", req);
350 _processId = pImpl->Launch(_path, pArg, req);
355 SysLog(NID_APP, "[%s]Launching(%ls) is failed" , GetErrorMessage(r), _path.GetPointer());
361 _processId = pImpl->Launch(_path, pArg);
363 SysTryReturnResult(NID_APP, _processId >= 0, GetLastResult(), "Launching(%ls) is failed", _path.GetPointer());
365 SysLog(NID_APP, "Exit");
371 _AppControlImpl::StartImplicit(bundle* pBundle, const IList* pDataList, IAppControlEventListener* pListener)
373 SysLog(NID_APP, "Enter");
374 result r = E_SUCCESS;
376 _AppArg* pArg = new (std::nothrow) _AppArg;
377 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
379 pArg->Construct(pBundle);
381 _AppMessageImpl::AddData(pArg->GetBundle(), pDataList);
383 _AppControlManager* pImpl = _AppControlManager::GetInstance();
384 int req = _REQ_ID_INVALID;
388 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCbLegacy, pListener, _APPCONTROL_PROPERTY_NONE);
389 req = reqObj.GetRequestNumber();
391 r = pImpl->LaunchAppImplicit(pArg, req);
392 SysTryCatch(NID_APP, r == E_SUCCESS, reqObj.Invalidate(), r, "[%s] Propagating." , GetErrorMessage(r));
396 r = pImpl->LaunchAppImplicit(pArg, -1);
400 // [FIXME] launch registration is not working correctly
401 SysLog(NID_APP, "Exit");
408 _AppControlImpl::StartImplicit(bundle* pBundle, const IMap* pData, IAppControlResponseListener* pListener)
410 SysLog(NID_APP, "Enter");
411 result r = E_SUCCESS;
413 _AppArg* pArg = new (std::nothrow) _AppArg;
414 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
416 pArg->Construct(pBundle);
418 _AppArg::AddStrMap(pArg->GetBundle(), pData);
420 _AppControlManager* pImpl = _AppControlManager::GetInstance();
421 int req = _REQ_ID_INVALID;
425 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCb, pListener, _APPCONTROL_PROPERTY_NONE);
426 req = reqObj.GetRequestNumber();
428 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
430 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
432 if (pAppControlResponseEvent != null)
434 r = pAppControlResponseEvent->Construct();
435 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
437 r = pAppControlResponseEvent->AddListener(*pImpl, true);
438 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
440 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = pImpl->GetAppControlResponseEventContainer();
441 if (pResponseEventContainer != null)
443 pResponseEventContainer->Add(req, pAppControlResponseEvent);
444 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", req);
448 r = pImpl->LaunchAppImplicit(pArg, req);
449 SysTryCatch(NID_APP, r == E_SUCCESS, reqObj.Invalidate(), r, "[%s] Propagating." , GetErrorMessage(r));
453 r = pImpl->LaunchAppImplicit(pArg, -1);
456 SysLog(NID_APP, "Exit");
458 // [FIXME] launch registration is not working correctly
466 _AppControlImpl::AppControlCbLegacy(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int reqId)
468 SysLog(NID_APP, "Result value %d", res);
470 SysTryReturnResult(NID_APP, data && pResArg && pArg, E_SYSTEM, "Invalid result (callback, result, arg) = (0x%x, 0x%x, 0x%x).",
474 bundle* b = pResArg->GetBundle();
475 SysTryReturnResult(NID_APP, b != NULL, E_SYSTEM, "Invalid result bundle.");
477 IAppControlEventListener* pListener = static_cast<IAppControlEventListener*>(data);
478 SysTryReturnResult(NID_APP, pListener == null || typeid(pListener) == typeid(IAppControlEventListener*), E_SYSTEM, "Invalid result callback");
480 bundle* inb = pArg->GetBundle();
481 SysTryReturnResult(NID_APP, inb != NULL, E_SYSTEM, "Empty caller bundle.");
485 AppId provider = pResArg->GetCalleeAppId();
487 const char* p = appsvc_get_operation(inb);
493 SysLog(NID_APP, "Invoking callback with (%ls, %ls)", provider.GetPointer(), oId.GetPointer());
495 if (prop & _APPCONTROL_PROPERTY_ALIAS)
497 const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
498 pEntry = _AppControlRegistry::GetInstance()->GetReverseAppControlAliasEntry(provider, oId);
501 provider = pEntry->provider;
502 oId = pEntry->operation;
504 SysLog(NID_APP, "Legacy AppControl(%ls, %ls).", provider.GetPointer(), oId.GetPointer());
508 if (prop & _APPCONTROL_PROPERTY_APPID_CHANGE)
510 String tmp = _AppControlRegistry::GetInstance()->GetReverseAliasAppId(provider);
513 SysLog(NID_APP, "App change (%ls -> %ls).", provider.GetPointer(), tmp.GetPointer());
519 const bool isSubMode = _AppArg::IsSubMode(b);
521 std::unique_ptr<HashMap> pMap(pResArg->GetArgMapN());
523 ArrayList list(SingleObjectDeleter);
524 _AppArg::FillLegacyAppControlResult(list, res, pMap.get(), provider);
526 _AppControlManager::InvokeLegacyAppControlCompleteListener(*pListener, provider, oId, &list, isSubMode);
532 _AppControlImpl::AppControlCb(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int reqId)
534 SysLog(NID_APP, "Result value : %d, property : 0x%x", res, prop);
536 SysTryReturnResult(NID_APP, data && pResArg && pArg, E_SYSTEM, "Invalid result (callback, result, arg) = (0x%x, 0x%x, 0x%x).",
540 bundle* b = pResArg->GetBundle();
541 SysTryReturnResult(NID_APP, b != NULL, E_SYSTEM, "Invalid result bundle.");
543 IAppControlResponseListener* pListener = static_cast<IAppControlResponseListener*>(data);
544 SysTryReturnResult(NID_APP, pListener == null || typeid(pListener) == typeid(IAppControlResponseListener*), E_SYSTEM, "Invalid result callback");
546 bundle* inb = pArg->GetBundle();
547 SysTryReturnResult(NID_APP, inb != NULL, E_SYSTEM, "Empty caller bundle.");
551 AppId provider = pResArg->GetCalleeAppId();
553 const char* p = appsvc_get_operation(inb);
559 SysLog(NID_APP, "Invoking callback with (%ls, %ls)", provider.GetPointer(), oId.GetPointer());
561 if (prop & _APPCONTROL_PROPERTY_ALIAS)
563 const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
564 pEntry = _AppControlRegistry::GetInstance()->GetReverseRuntimeAliasEntry(provider, oId);
567 provider = pEntry->provider;
568 oId = pEntry->operation;
570 SysLog(NID_APP, "Original AppControl(%ls, %ls).", provider.GetPointer(), oId.GetPointer());
574 if (prop & _APPCONTROL_PROPERTY_APPID_CHANGE)
576 String tmp = _AppControlRegistry::GetInstance()->GetReverseAliasAppId(provider);
579 SysLog(NID_APP, "App change (%ls -> %ls).", provider.GetPointer(), tmp.GetPointer());
585 const bool isSubMode = _AppArg::IsSubMode(b);
587 std::unique_ptr<HashMap> pMap(pResArg->GetArgMapN());
589 AppCtrlResult ret = _AppControlManager::ConvertAppControlResultCode(res);
591 SysLog(NID_APP, "Result code : 0x%x.", ret);
593 // proper callback invokation
594 _AppControlResponseEvent* pResponseEvent = null;
595 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(reqId, pResponseEvent);
597 if (pResponseEvent != null)
599 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, provider, oId, E_SUCCESS, ret, pMap.release(), reqId, isSubMode);
600 pResponseEvent->Fire(*pResponseEventArg);
601 SysLog(NID_APP, "OnAppControlCompleteResponseReceived, pResponseEvent is Fired");
605 _AppControlManager::InvokeAppControlCompleteListener(*pListener, provider, oId, ret, pMap.get(), isSubMode);
612 _AppControlImpl::StartNative(const IList* pDataList, IAppControlEventListener* pListener)
614 SysLog(NID_APP, "Enter");
615 _InProcessInfo* pInfo = _AppControlManager::GetInstance()->__inAppManager.FindItem(_reqId);
616 SysTryReturnResult(NID_APP, pInfo == null, E_IN_PROGRESS, "Request ID %d is already in progress.", _reqId);
618 int req = _REQ_ID_INVALID;
619 _LibraryImpl* pLib = null;
621 pLib = new (std::nothrow) _LibraryImpl;
622 SysTryReturnResult(NID_APP, pLib != null, E_OUT_OF_MEMORY, "Failed to allocate libraryimpl.");
624 unsigned long option = _LIBRARY_LOAD_OPTION_LAZY;
625 option |= _LIBRARY_LOAD_OPTION_NODELETE;
627 result r = pLib->Construct(_path, option);
628 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
632 _InProcessInfo* pItem = new (std::nothrow) _InProcessInfo(_provider, _opId, _property, true, *pLib, pListener);
635 req = _AppControlManager::GetInstance()->__inAppManager.InsertItem(pItem);
638 r = InvokeStartAppControl(*pLib, req, _provider, _opId, pDataList);
640 if (pListener == null)
645 // after acquring request number, pLib should be managed from the list, not CATCH
648 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(req);
649 SysLog(NID_APP, "[%s] A system error has occurred.", GetErrorMessage(r));
656 SysLog(NID_APP, "Exit");
664 case E_LIBRARY_NOT_FOUND:
676 _AppControlImpl::StartNative(const String* pUriData, const String* pMimeType, const IMap* pDataList, IAppControlResponseListener* pListener)
678 SysLog(NID_APP, "Enter");
679 _InProcessInfo* pInfo = _AppControlManager::GetInstance()->__inAppManager.FindItem(_reqId);
680 SysTryReturnResult(NID_APP, pInfo == null, E_IN_PROGRESS, "Request ID %d is already in progress.", _reqId);
682 int req = _REQ_ID_INVALID;
683 _LibraryImpl* pLib = null;
685 pLib = new (std::nothrow) _LibraryImpl;
686 SysTryReturnResult(NID_APP, pLib != null, E_OUT_OF_MEMORY, "Failed to allocate libraryimpl.");
688 unsigned long option = _LIBRARY_LOAD_OPTION_LAZY;
689 option |= _LIBRARY_LOAD_OPTION_NODELETE;
691 result r = pLib->Construct(_path, option);
693 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
697 _InProcessInfo* pItem = new (std::nothrow) _InProcessInfo(_provider, _opId, _property, false, *pLib, pListener);
700 req = _AppControlManager::GetInstance()->__inAppManager.InsertItem(pItem);
703 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
705 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
707 if (pAppControlResponseEvent != null)
709 r = pAppControlResponseEvent->Construct();
710 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
712 r = pAppControlResponseEvent->AddListener(*this, true);
713 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
715 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = _AppControlManager::GetInstance()->GetAppControlResponseEventContainer();
716 if (pResponseEventContainer != null)
718 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + req;
719 pResponseEventContainer->Add(responseEventRequestId, pAppControlResponseEvent);
720 __appControlResponseEventList.Add(responseEventRequestId);
721 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", responseEventRequestId);
726 r = InvokeStartAppControl(*pLib, req, _provider, _opId, pUriData, pMimeType, pDataList);
728 if (pListener == null)
733 // after acquring request number, pLib should be managed from the list, not CATCH
736 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(req);
737 SysLog(NID_APP, "[%s] A system error has occurred.", GetErrorMessage(r));
743 SysLog(NID_APP, "Exit");
752 case E_LIBRARY_NOT_FOUND:
764 _AppControlImpl::InvokeStartAppControl(_LibraryImpl& lib, int req, const String& appId, const String& oId, const IList* pList)
766 SysLog(NID_APP, "Legacy stuff for converting argument");
768 HashMap map(SingleObjectDeleter);
769 HashMap* pMap = null;
774 _AppArg::FillMapFromList(&map, pList);
779 return InvokeStartAppControl(lib, req, appId, oId, null, null, pMap);
784 _AppControlImpl::InvokeStartAppControl(_LibraryImpl& lib, int req, const String& appId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
786 result (*pFunc)(int req, const String&, const String&, const String*, const String*, const IMap*) = null;
789 reinterpret_cast<result (*)(int, const String&, const String&, const String*, const String*, const IMap*)>(lib.GetProcAddress(L"StartAppControl"));
790 SysTryReturnResult(NID_APP, pFunc != null, E_OBJ_NOT_FOUND, "Entry \"StartAppControl\" not found for %ls", appId.GetPointer());
792 const String* pActualUri = (pUri && !(pUri->IsEmpty())) ? pUri : null;
793 const String* pActualMime = (pMime && !(pMime->IsEmpty())) ? pMime : null;
794 return (*pFunc)(req, appId, oId, pActualUri, pActualMime, pMap);
798 IsValidAppControl(const String& appcontrolID)
800 return ((appcontrolID == L"osp.appcontrol.provider.audio")
801 || (appcontrolID == L"osp.appcontrol.provider.bluetooth")
802 || (appcontrolID == L"osp.appcontrol.provider.calendar")
803 || (appcontrolID == L"osp.appcontrol.provider.camera")
804 || (appcontrolID == L"osp.appcontrol.provider.contact")
805 || (appcontrolID == L"osp.appcontrol.provider.certificatemanager")
806 || (appcontrolID == L"osp.appcontrol.provider.email")
807 || (appcontrolID == L"osp.appcontrol.provider.image")
808 || (appcontrolID == L"osp.appcontrol.provider.media")
809 || (appcontrolID == L"osp.appcontrol.provider.message")
810 || (appcontrolID == L"osp.appcontrol.provider.video")
811 || (appcontrolID == L"osp.appcontrol.provider.imageeditor")
812 || (appcontrolID == L"osp.appcontrol.provider.allshare")
813 || (appcontrolID == L"tizen.filemanager")
814 || (appcontrolID == L"tizen.camera")
815 || (appcontrolID == L"tizen.gallery")
816 || (appcontrolID == L"tizen.imageviewer")
817 || (appcontrolID == L"tizen.videoplayer")
818 || (appcontrolID == L"tizen.memo")
819 || (appcontrolID == L"tizen.contacts")
820 || (appcontrolID == L"tizen.calendar")
821 || (appcontrolID == L"tizen.todo")
822 || (appcontrolID == L"tizen.email")
823 || (appcontrolID == L"tizen.settings")
824 || (appcontrolID == L"tizen.messages")
825 || (appcontrolID == L"tizen.musicplayer")
826 || (appcontrolID == L"tizen.bluetooth")
827 || (appcontrolID == L"samsung.snote")
828 || (appcontrolID == L"0pnxz8hbsr.MyFiles")
829 || (appcontrolID == L"hdufar9ycj.Camera")
830 || (appcontrolID == L"ijudt7w61q.Gallery")
831 || (appcontrolID == L"jysyv9o1dc.ImageViewer")
832 || (appcontrolID == L"npwf0scb88.VideoPlayer")
833 || (appcontrolID == L"zunqjlsnce.Memo")
834 || (appcontrolID == L"f9uev8hsyo.Contacts")
835 || (appcontrolID == L"ph1vq2phrp.Calendar")
836 || (appcontrolID == L"vxqbrefica.Email")
837 || (appcontrolID == L"kto5jikgul.Settings")
838 || (appcontrolID == L"8r4r5ddzzn.Messages")
839 || (appcontrolID == L"dhrul6qzj3.MusicPlayer")
840 || (appcontrolID == L"smemo-efl"));
844 _AppControlImpl::Stop(void)
846 const String appcontrolID(GetAppControlProviderId());
847 SysTryReturnResult(NID_APP, IsValidAppControl(appcontrolID), E_INVALID_OPERATION, "Invalid appcontrolID(%ls)", appcontrolID.GetPointer());
849 if (_property & _APPCONTROL_PROPERTY_SLP)
851 SysTryReturnResult(NID_APP, _reqId != _REQ_ID_INVALID, E_INVALID_OPERATION, "Invalid request ID .");
853 _InProcessInfo* pInfo = _AppControlManager::GetInstance()->__inAppManager.FindItem(_reqId);
854 SysTryReturnResult(NID_APP, pInfo != null, E_INVALID_OPERATION, "Request ID %d is not found.", _reqId);
856 result (*pStop)(int req) = null;
857 pStop = reinterpret_cast<result (*)(int)>(pInfo->pLib->GetProcAddress(L"TerminateAppControl"));
858 SysTryReturnResult(NID_APP, pStop != null, E_SYSTEM, "No TerminateAppControl() function.");
862 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(_reqId);
864 _reqId = _REQ_ID_INVALID;
866 else if (_property & _APPCONTROL_PROPERTY_OSP)
868 _Aul::TerminateApplicationByPid(_processId);
875 _AppControlImpl::GetAppName(void)
877 if (_appName.IsEmpty())
879 AppId appId = GetAppId();
880 AppId aliasAppId = _AppControlRegistry::GetInstance()->GetAliasAppId(appId);
881 if (!aliasAppId.IsEmpty())
886 std::unique_ptr<PackageAppInfo> pInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
889 SysLog(NID_APP, "PackageInfo of appId(%ls) exists", appId.GetPointer());
890 const String& name = pInfo->GetAppName();
891 if (name == L"_AppControl")
893 // workaround for special case: requery with actual appId
894 const PackageId& packageId = _PackageManagerImpl::GetPackageIdByAppId(appId);
895 const String& defaultName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
897 const String& convertedAppId = packageId + L'.' + defaultName;
899 std::unique_ptr<PackageAppInfo> pNewInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(convertedAppId));
903 _appName = pNewInfo->GetAppDisplayName();
907 SysLog(NID_APP, "No default applicaiton information, possible database error.");
912 _appName = pInfo->GetAppDisplayName();
917 SysLog(NID_APP, "PackageInfo of appId(%ls) does not exist", appId.GetPointer());
925 _AppControlImpl::GetAppId(void) const
927 return (_property & _APPCONTROL_PROPERTY_OSP) ? _path : _provider;
931 _AppControlImpl::GetAppControlProviderId(void) const
937 _AppControlImpl::GetOperationId(void) const
943 _AppControlImpl::GetCategoryListN(void) const
945 AppId appId = GetAppId();
946 SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_SYSTEM, "[E_SYSTEM] Empty appId.");
948 AppId aliasAppId = _AppControlRegistry::GetInstance()->GetAliasAppId(appId);
949 if (!aliasAppId.IsEmpty())
954 SysLog(NID_APP, "Acquiring category for app %ls.", appId.GetPointer());
956 std::unique_ptr<PackageAppInfo> pAppInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
957 SysTryReturn(NID_APP, pAppInfo.get() != null, null, E_SYSTEM, "[E_SYSTEM] Getting PackageAppInfo failed.");
959 return pAppInfo->GetAppCategoryListN();
963 _AppControlImpl::StopAppControlResponseListener(IAppControlResponseListener* pListener)
965 _AppControlManager::GetInstance()->__listenerList.Add(pListener);
969 _AppControlImpl::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
971 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
973 if (pEventArg != null)
975 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
977 if(pResponseListener != null)
979 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_COMPLETE)
981 _AppControlManager::InvokeAppControlCompleteListener(*pResponseListener, pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData(), pEventArg->IsSubMode());
983 _AppControlResponseEvent* pResponseEvent = null;
984 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
985 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
986 delete pResponseEvent;
987 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
991 SysLog(NID_APP, "Unexpected AppControlResponseType(%d)", pEventArg->GetType());
996 SysLog(NID_APP, "Invalid ResponseListener");
1001 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);