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 <FBaseColHashMap.h>
29 #include <FBaseSysLog.h>
30 #include <FAppAppControl.h>
31 #include <FAppAppManager.h>
32 #include <FAppPkgPackageAppInfo.h>
33 #include <FAppIAppControlEventListener.h>
34 #include <FAppIAppControlResponseListener.h>
36 #include <FIo_DirectoryImpl.h>
38 #include "FApp_AppControlImpl.h"
39 #include "FApp_AppControlManager.h"
40 #include "FApp_AppArg.h"
41 #include "FApp_AppControlRegistry.h"
42 #include "FApp_AppMessageImpl.h"
43 #include "FApp_AppInfo.h"
44 #include "FAppPkg_PackageManagerImpl.h"
46 #include "FApp_AppControlEventArg.h"
47 #include "FApp_AppControlResponseEvent.h"
48 #include "FBaseRt_ThreadImpl.h"
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Collection;
52 using namespace Tizen::Base::Runtime;
53 using namespace Tizen::App;
54 using namespace Tizen::App::Package;
55 using namespace Tizen::Io;
60 static const int _REQ_ID_INVALID = -1;
64 namespace Tizen { namespace App
67 const wchar_t TIZEN_OPERATION_MAIN[] = L"http://tizen.org/appcontrol/operation/main";
69 _AppControlImpl::_AppControlImpl(const AppControl& value)
71 , _reqId(_REQ_ID_INVALID)
72 , _property(_APPCONTROL_PROPERTY_NONE)
73 , _processId(_REQ_ID_INVALID)
75 __appControlResponseEventList.Construct();
78 _AppControlImpl::~_AppControlImpl(void)
80 IEnumeratorT<int>* pEnum = __appControlResponseEventList.GetEnumeratorN();
81 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = null;
84 pResponseEventContainer = _AppControlManager::GetInstance()->GetAppControlResponseEventContainer();
87 while(pEnum->MoveNext() == E_SUCCESS)
90 pEnum->GetCurrent(reqId);
91 if (pResponseEventContainer != null)
93 _AppControlResponseEvent* pResponseEvent = null;
94 pResponseEventContainer->GetValue(reqId, pResponseEvent);
95 delete pResponseEvent;
97 pResponseEventContainer->Remove(reqId);
98 SysLog(NID_APP, "pResponseEvent gets deleted. reqId(%d)", reqId);
105 _AppControlImpl::CreateN(const String& path, const String& aId, const String& oId, const String& name, int prop)
107 SysTryReturn(NID_APP, !path.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] Path is empty.");
108 SysTryReturn(NID_APP, !aId.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] Provider Id is empty.");
109 SysTryReturn(NID_APP, !oId.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] Operation Id is empty.");
111 AppControl* pAc = new (std::nothrow) AppControl;
112 SysTryReturn(NID_APP, pAc != null, null, E_OUT_OF_MEMORY, "AppControl allocation failure.");
114 _AppControlImpl* pImpl = pAc->__pAppControlImpl;
115 SysTryReturn(NID_APP, pImpl != null, null, E_OUT_OF_MEMORY, "AppControlImpl instance must not be null.");
118 pImpl->_provider = aId;
120 // [FIXME] Proper App name setting
121 pImpl->_appName = name;
122 pImpl->_property = prop;
128 _AppControlImpl::CreateN(const AppId& appId, const String& operationId, bool changeAppId)
130 SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] appId is empty.");
132 AppControl* pAc = new (std::nothrow) AppControl;
133 SysTryReturn(NID_APP, pAc != null, null, E_OUT_OF_MEMORY, "AppControl allocation failure.");
135 _AppControlImpl* pImpl = pAc->__pAppControlImpl;
136 SysTryReturn(NID_APP, pImpl != null, null, E_OUT_OF_MEMORY, "AppControlImpl instance must not be null.");
138 pImpl->_path = appId;
139 pImpl->_provider = appId;
140 pImpl->_opId = operationId;
141 //pImpl->_appName = appId;
142 pImpl->_property |= (_APPCONTROL_PROPERTY_OSP | _APPCONTROL_PROPERTY_PUBLIC);
146 pImpl->_property |= _APPCONTROL_PROPERTY_APPID_CHANGE;
153 _AppControlImpl::CreateN(const AppControl& ac)
155 const _AppControlImpl* pImpl = GetInstance(ac);
156 SysTryReturn(NID_APP, pImpl != null, null, E_INVALID_STATE, "AppControlImpl instance must not be null.");
158 return CreateN(pImpl->_path, pImpl->_provider, pImpl->_opId, pImpl->_appName, pImpl->_property);
161 const _AppControlImpl*
162 _AppControlImpl::GetInstance(const AppControl& ac)
164 return ac.__pAppControlImpl;
168 _AppControlImpl::GetInstance(AppControl& ac)
170 return ac.__pAppControlImpl;
174 _AppControlImpl::Start(const IList* pDataList, IAppControlEventListener* pListener)
176 SysLog(NID_APP, "Enter");
179 if (_property & _APPCONTROL_PROPERTY_SLP)
181 r = StartNative(pDataList, pListener);
183 else if (_property & _APPCONTROL_PROPERTY_OSP)
185 r = StartOsp(pDataList, pListener);
189 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Invalid AppControl type(property %d)", _property);
191 SysLog(NID_APP, "Exit");
197 _AppControlImpl::Start(const String* pUriData, const String* pDataType, const IMap* pExtraData, IAppControlResponseListener* pListener)
199 SysLog(NID_APP, "Enter");
202 if (_property & _APPCONTROL_PROPERTY_SLP)
204 r = StartNative(pUriData, pDataType, pExtraData, pListener);
206 else if (_property & _APPCONTROL_PROPERTY_OSP)
208 r = StartOsp(pUriData, pDataType, pExtraData, pListener);
212 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Invalid AppControl type(property %d)", _property);
214 SysLog(NID_APP, "Exit");
220 _AppControlImpl::FindAndStart(const String& operationId, const String* pUriPattern, const String* pDataType, const String* pCategory, const IMap* pExtraData, IAppControlResponseListener* pListener)
222 // [FIXME] valid argument size checking required
223 SysLog(NID_APP, "Enter");
225 std::unique_ptr<bundle, BundleDeleter> pBundle(bundle_create());
226 SysTryReturnResult(NID_APP, pBundle.get(), E_OUT_OF_MEMORY, "Bundle creation failure.");
228 _AppMessageImpl::SetOperation(pBundle.get(), operationId);
232 _AppMessageImpl::SetUri(pBundle.get(), *pUriPattern);
237 String mimeType = *pDataType;
239 if ((*pDataType)[0] == L'.')
241 SysLog(NID_APP, "Extension to MIME conversion for %ls", pDataType->GetPointer());
245 pDataType->SubString(1, ext);
247 result r = _AppControlManager::GetMimeFromExt(ext, mimeType);
249 SysTryReturn(NID_APP, !IsFailed(r), null, r, "[%s] MIME type conversion failure for %ls.", GetErrorMessage(r), ext.GetPointer());
251 pMimeType = &mimeType;
253 SysLog(NID_APP, "Conversion : %ls -> %ls.", pDataType->GetPointer(), pMimeType->GetPointer());
257 _AppMessageImpl::SetMime(pBundle.get(), mimeType);
262 _AppMessageImpl::SetCategory(pBundle.get(), *pCategory);
265 return StartImplicit(pBundle.get(), pExtraData, pListener);
269 _AppControlImpl::StartOsp(const IList* pDataList, IAppControlEventListener* pListener)
271 SysLog(NID_APP, "Enter");
272 result r = E_SUCCESS;
274 _AppArg* pArg = new (std::nothrow) _AppArg;
275 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
277 pArg->Construct(*this, pDataList);
279 _AppControlManager* pImpl = _AppControlManager::GetInstance();
280 int req = _REQ_ID_INVALID;
284 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCbLegacy, pListener, _property);
285 req = reqObj.GetRequestNumber();
287 _processId = pImpl->Launch(_path, pArg, req);
293 SysLog(NID_APP, "[%s]Launching(%ls) is failed" , GetErrorMessage(r), _path.GetPointer());
299 _processId = pImpl->Launch(_path, pArg);
301 SysTryReturnResult(NID_APP, _processId >= 0, GetLastResult(), "Launching(%ls) is failed", _path.GetPointer());
303 SysLog(NID_APP, "Exit");
309 _AppControlImpl::StartOsp(const String* pUriData, const String* pMimeType, const IMap* pDataList, IAppControlResponseListener* pListener)
311 SysLog(NID_APP, "Enter");
312 result r = E_SUCCESS;
314 _AppArg* pArg = new (std::nothrow) _AppArg;
315 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
317 pArg->Construct(*this, pUriData, pMimeType, pDataList);
319 _AppControlManager* pImpl = _AppControlManager::GetInstance();
320 int req = _REQ_ID_INVALID;
324 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCb, pListener, _property);
325 req = reqObj.GetRequestNumber();
327 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
329 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
330 if (pAppControlResponseEvent != null)
332 r = pAppControlResponseEvent->Construct();
333 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
335 r = pAppControlResponseEvent->AddListener(*this, true);
336 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
338 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = pImpl->GetAppControlResponseEventContainer();
339 if (pResponseEventContainer != null)
341 pResponseEventContainer->Add(req, pAppControlResponseEvent);
342 __appControlResponseEventList.Add(req);
343 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", req);
348 _processId = pImpl->Launch(_path, pArg, req);
353 SysLog(NID_APP, "[%s]Launching(%ls) is failed" , GetErrorMessage(r), _path.GetPointer());
359 _processId = pImpl->Launch(_path, pArg);
361 SysTryReturnResult(NID_APP, _processId >= 0, GetLastResult(), "Launching(%ls) is failed", _path.GetPointer());
363 SysLog(NID_APP, "Exit");
369 _AppControlImpl::StartImplicit(bundle* pBundle, const IList* pDataList, IAppControlEventListener* pListener)
371 SysLog(NID_APP, "Enter");
372 result r = E_SUCCESS;
374 _AppArg* pArg = new (std::nothrow) _AppArg;
375 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
377 pArg->Construct(pBundle);
379 _AppMessageImpl::AddData(pArg->GetBundle(), pDataList);
381 _AppControlManager* pImpl = _AppControlManager::GetInstance();
382 int req = _REQ_ID_INVALID;
386 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCbLegacy, pListener, _APPCONTROL_PROPERTY_NONE);
387 req = reqObj.GetRequestNumber();
389 r = pImpl->LaunchAppImplicit(pArg, req);
390 SysTryCatch(NID_APP, r == E_SUCCESS, reqObj.Invalidate(), r, "[%s] Propagating." , GetErrorMessage(r));
394 r = pImpl->LaunchAppImplicit(pArg, -1);
398 // [FIXME] launch registration is not working correctly
399 SysLog(NID_APP, "Exit");
406 _AppControlImpl::StartImplicit(bundle* pBundle, const IMap* pData, IAppControlResponseListener* pListener)
408 SysLog(NID_APP, "Enter");
409 result r = E_SUCCESS;
411 _AppArg* pArg = new (std::nothrow) _AppArg;
412 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
414 pArg->Construct(pBundle);
416 _AppArg::AddStrMap(pArg->GetBundle(), pData);
418 _AppControlManager* pImpl = _AppControlManager::GetInstance();
419 int req = _REQ_ID_INVALID;
423 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCb, pListener, _APPCONTROL_PROPERTY_NONE);
424 req = reqObj.GetRequestNumber();
426 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
428 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
430 if (pAppControlResponseEvent != null)
432 r = pAppControlResponseEvent->Construct();
433 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
435 r = pAppControlResponseEvent->AddListener(*pImpl, true);
436 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
438 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = pImpl->GetAppControlResponseEventContainer();
439 if (pResponseEventContainer != null)
441 pResponseEventContainer->Add(req, pAppControlResponseEvent);
442 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", req);
446 r = pImpl->LaunchAppImplicit(pArg, req);
447 SysTryCatch(NID_APP, r == E_SUCCESS, reqObj.Invalidate(), r, "[%s] Propagating." , GetErrorMessage(r));
451 r = pImpl->LaunchAppImplicit(pArg, -1);
454 SysLog(NID_APP, "Exit");
456 // [FIXME] launch registration is not working correctly
464 _AppControlImpl::AppControlCbLegacy(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int reqId)
466 SysLog(NID_APP, "Result value %d", res);
468 SysTryReturnResult(NID_APP, data && pResArg && pArg, E_SYSTEM, "Invalid result (callback, result, arg) = (0x%x, 0x%x, 0x%x).",
472 bundle* b = pResArg->GetBundle();
473 SysTryReturnResult(NID_APP, b != NULL, E_SYSTEM, "Invalid result bundle.");
475 IAppControlEventListener* pListener = static_cast<IAppControlEventListener*>(data);
476 SysTryReturnResult(NID_APP, pListener == null || typeid(pListener) == typeid(IAppControlEventListener*), E_SYSTEM, "Invalid result callback");
478 bundle* inb = pArg->GetBundle();
479 SysTryReturnResult(NID_APP, inb != NULL, E_SYSTEM, "Empty caller bundle.");
483 AppId provider = pResArg->GetCalleeAppId();
485 const char* p = appsvc_get_operation(inb);
491 SysLog(NID_APP, "Invoking callback with (%ls, %ls)", provider.GetPointer(), oId.GetPointer());
493 if (prop & _APPCONTROL_PROPERTY_ALIAS)
495 const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
496 pEntry = _AppControlRegistry::GetInstance()->GetReverseAppControlAliasEntry(provider, oId);
499 provider = pEntry->provider;
500 oId = pEntry->operation;
502 SysLog(NID_APP, "Legacy AppControl(%ls, %ls).", provider.GetPointer(), oId.GetPointer());
506 if (prop & _APPCONTROL_PROPERTY_APPID_CHANGE)
508 String tmp = _AppControlRegistry::GetInstance()->GetReverseAliasAppId(provider);
511 SysLog(NID_APP, "App change (%ls -> %ls).", provider.GetPointer(), tmp.GetPointer());
517 const bool isSubMode = _AppArg::IsSubMode(b);
518 const bool isServiceCallee = _AppArg::IsServiceApp(b);
520 std::unique_ptr<HashMap> pMap(pResArg->GetArgMapN());
522 ArrayList list(SingleObjectDeleter);
523 _AppArg::FillLegacyAppControlResult(list, res, pMap.get(), provider);
525 _AppControlManager::InvokeLegacyAppControlCompleteListener(*pListener, provider, oId, &list, isSubMode | isServiceCallee);
531 _AppControlImpl::AppControlCb(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int reqId)
533 SysLog(NID_APP, "Result value : %d, property : 0x%x", res, prop);
535 SysTryReturnResult(NID_APP, data && pResArg && pArg, E_SYSTEM, "Invalid result (callback, result, arg) = (0x%x, 0x%x, 0x%x).",
539 bundle* b = pResArg->GetBundle();
540 SysTryReturnResult(NID_APP, b != NULL, E_SYSTEM, "Invalid result bundle.");
542 IAppControlResponseListener* pListener = static_cast<IAppControlResponseListener*>(data);
543 SysTryReturnResult(NID_APP, pListener == null || typeid(pListener) == typeid(IAppControlResponseListener*), E_SYSTEM, "Invalid result callback");
545 bundle* inb = pArg->GetBundle();
546 SysTryReturnResult(NID_APP, inb != NULL, E_SYSTEM, "Empty caller bundle.");
550 AppId provider = pResArg->GetCalleeAppId();
552 const char* p = appsvc_get_operation(inb);
558 SysLog(NID_APP, "Invoking callback with (%ls, %ls)", provider.GetPointer(), oId.GetPointer());
560 if (prop & _APPCONTROL_PROPERTY_ALIAS)
562 const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
563 pEntry = _AppControlRegistry::GetInstance()->GetReverseRuntimeAliasEntry(provider, oId);
566 provider = pEntry->provider;
567 oId = pEntry->operation;
569 SysLog(NID_APP, "Original AppControl(%ls, %ls).", provider.GetPointer(), oId.GetPointer());
573 if (prop & _APPCONTROL_PROPERTY_APPID_CHANGE)
575 String tmp = _AppControlRegistry::GetInstance()->GetReverseAliasAppId(provider);
578 SysLog(NID_APP, "App change (%ls -> %ls).", provider.GetPointer(), tmp.GetPointer());
584 const bool isSubMode = _AppArg::IsSubMode(b);
585 const bool isServiceCallee = _AppArg::IsServiceApp(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 | isServiceCallee);
600 pResponseEvent->Fire(*pResponseEventArg);
601 SysLog(NID_APP, "OnAppControlCompleteResponseReceived, pResponseEvent is Fired");
605 _AppControlManager::InvokeAppControlCompleteListener(*pListener, provider, oId, ret, pMap.get(), isSubMode | isServiceCallee);
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 result r = pLib->Construct(_path, _LIBRARY_OPTION);
625 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
629 _InProcessInfo* pItem = new (std::nothrow) _InProcessInfo(_provider, _opId, _property, true, *pLib, pListener);
632 req = _AppControlManager::GetInstance()->__inAppManager.InsertItem(pItem);
635 r = InvokeStartAppControl(*pLib, req, _provider, _opId, pDataList);
637 if (pListener == null)
642 // after acquring request number, pLib should be managed from the list, not CATCH
645 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(req);
646 SysLog(NID_APP, "[%s] A system error has occurred.", GetErrorMessage(r));
653 SysLog(NID_APP, "Exit %d", req);
661 case E_LIBRARY_NOT_FOUND:
673 _AppControlImpl::StartNative(const String* pUriData, const String* pMimeType, const IMap* pDataList, IAppControlResponseListener* pListener)
675 SysLog(NID_APP, "Enter");
676 _InProcessInfo* pInfo = _AppControlManager::GetInstance()->__inAppManager.FindItem(_reqId);
677 SysTryReturnResult(NID_APP, pInfo == null, E_IN_PROGRESS, "Request ID %d is already in progress.", _reqId);
679 int req = _REQ_ID_INVALID;
680 _LibraryImpl* pLib = null;
682 pLib = new (std::nothrow) _LibraryImpl;
683 SysTryReturnResult(NID_APP, pLib != null, E_OUT_OF_MEMORY, "Failed to allocate libraryimpl.");
685 result r = pLib->Construct(_path, _LIBRARY_OPTION);
687 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
691 _InProcessInfo* pItem = new (std::nothrow) _InProcessInfo(_provider, _opId, _property, false, *pLib, pListener);
694 req = _AppControlManager::GetInstance()->__inAppManager.InsertItem(pItem);
697 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
699 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
701 if (pAppControlResponseEvent != null)
703 r = pAppControlResponseEvent->Construct();
704 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
706 r = pAppControlResponseEvent->AddListener(*this, true);
707 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
709 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = _AppControlManager::GetInstance()->GetAppControlResponseEventContainer();
710 if (pResponseEventContainer != null)
712 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + req;
713 pResponseEventContainer->Add(responseEventRequestId, pAppControlResponseEvent);
714 __appControlResponseEventList.Add(responseEventRequestId);
715 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", responseEventRequestId);
720 r = InvokeStartAppControl(*pLib, req, _provider, _opId, pUriData, pMimeType, pDataList);
722 if (pListener == null)
727 // after acquring request number, pLib should be managed from the list, not CATCH
730 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(req);
731 SysLog(NID_APP, "[%s] A system error has occurred.", GetErrorMessage(r));
737 SysLog(NID_APP, "Exit %d", req);
746 case E_LIBRARY_NOT_FOUND:
758 _AppControlImpl::InvokeStartAppControl(_LibraryImpl& lib, int req, const String& appId, const String& oId, const IList* pList)
760 SysLog(NID_APP, "Legacy stuff for converting argument");
762 HashMap map(SingleObjectDeleter);
763 HashMap* pMap = null;
768 _AppArg::FillMapFromList(&map, pList);
773 return InvokeStartAppControl(lib, req, appId, oId, null, null, pMap);
778 _AppControlImpl::InvokeStartAppControl(_LibraryImpl& lib, int req, const String& appId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
780 result (*pFunc)(int req, const String&, const String&, const String*, const String*, const IMap*) = null;
783 reinterpret_cast<result (*)(int, const String&, const String&, const String*, const String*, const IMap*)>(lib.GetProcAddress(L"StartAppControl"));
784 SysTryReturnResult(NID_APP, pFunc != null, E_OBJ_NOT_FOUND, "Entry \"StartAppControl\" not found for %ls", appId.GetPointer());
786 const String* pActualUri = (pUri && !(pUri->IsEmpty())) ? pUri : null;
787 const String* pActualMime = (pMime && !(pMime->IsEmpty())) ? pMime : null;
788 return (*pFunc)(req, appId, oId, pActualUri, pActualMime, pMap);
792 IsValidAppControl(const String& appcontrolID)
794 return ((appcontrolID == L"osp.appcontrol.provider.audio")
795 || (appcontrolID == L"osp.appcontrol.provider.bluetooth")
796 || (appcontrolID == L"osp.appcontrol.provider.calendar")
797 || (appcontrolID == L"osp.appcontrol.provider.camera")
798 || (appcontrolID == L"osp.appcontrol.provider.contact")
799 || (appcontrolID == L"osp.appcontrol.provider.certificatemanager")
800 || (appcontrolID == L"osp.appcontrol.provider.email")
801 || (appcontrolID == L"osp.appcontrol.provider.image")
802 || (appcontrolID == L"osp.appcontrol.provider.media")
803 || (appcontrolID == L"osp.appcontrol.provider.message")
804 || (appcontrolID == L"osp.appcontrol.provider.video")
805 || (appcontrolID == L"osp.appcontrol.provider.imageeditor")
806 || (appcontrolID == L"osp.appcontrol.provider.allshare")
807 || (appcontrolID == L"tizen.filemanager")
808 || (appcontrolID == L"tizen.camera")
809 || (appcontrolID == L"tizen.gallery")
810 || (appcontrolID == L"tizen.imageviewer")
811 || (appcontrolID == L"tizen.videoplayer")
812 || (appcontrolID == L"tizen.memo")
813 || (appcontrolID == L"tizen.contacts")
814 || (appcontrolID == L"tizen.calendar")
815 || (appcontrolID == L"tizen.todo")
816 || (appcontrolID == L"tizen.email")
817 || (appcontrolID == L"tizen.settings")
818 || (appcontrolID == L"tizen.messages")
819 || (appcontrolID == L"tizen.musicplayer")
820 || (appcontrolID == L"tizen.bluetooth")
821 || (appcontrolID == L"samsung.snote")
822 || (appcontrolID == L"0pnxz8hbsr.MyFiles")
823 || (appcontrolID == L"hdufar9ycj.Camera")
824 || (appcontrolID == L"ijudt7w61q.Gallery")
825 || (appcontrolID == L"jysyv9o1dc.ImageViewer")
826 || (appcontrolID == L"npwf0scb88.VideoPlayer")
827 || (appcontrolID == L"zunqjlsnce.Memo")
828 || (appcontrolID == L"f9uev8hsyo.Contacts")
829 || (appcontrolID == L"ph1vq2phrp.Calendar")
830 || (appcontrolID == L"vxqbrefica.Email")
831 || (appcontrolID == L"kto5jikgul.Settings")
832 || (appcontrolID == L"8r4r5ddzzn.Messages")
833 || (appcontrolID == L"dhrul6qzj3.MusicPlayer")
834 || (appcontrolID == L"smemo-efl"));
838 _AppControlImpl::Stop(void)
840 const String appcontrolID(GetAppControlProviderId());
841 SysTryReturnResult(NID_APP, IsValidAppControl(appcontrolID), E_INVALID_OPERATION, "Invalid appcontrolID(%ls)", appcontrolID.GetPointer());
843 if (_property & _APPCONTROL_PROPERTY_SLP)
845 result (*pStop)(int req) = null;
847 if (_reqId != _REQ_ID_INVALID)
849 _InProcessInfo* pInfo = _AppControlManager::GetInstance()->__inAppManager.FindItem(_reqId);
850 SysTryReturnResult(NID_APP, pInfo != null, E_INVALID_OPERATION, "Request ID %d is not found.", _reqId);
852 pStop = reinterpret_cast<result (*)(int)>(pInfo->pLib->GetProcAddress(L"TerminateAppControl"));
853 SysTryReturnResult(NID_APP, pStop != null, E_SYSTEM, "No TerminateAppControl() function.");
857 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(_reqId);
859 _reqId = _REQ_ID_INVALID;
864 result r = lib.Construct(_path, _LIBRARY_OPTION);
867 pStop = reinterpret_cast<result (*)(int)>(lib.GetProcAddress(L"TerminateAppControl"));
868 SysTryReturnResult(NID_APP, pStop != null, E_SYSTEM, "No TerminateAppControl() function.");
874 else if (_property & _APPCONTROL_PROPERTY_OSP)
876 _Aul::TerminateApplicationByPid(_processId);
883 _AppControlImpl::GetAppName(void)
885 if (_appName.IsEmpty())
887 AppId appId = GetAppId();
888 AppId aliasAppId = _AppControlRegistry::GetInstance()->GetAliasAppId(appId);
889 if (!aliasAppId.IsEmpty())
894 std::unique_ptr<PackageAppInfo> pInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
897 SysLog(NID_APP, "PackageInfo of appId(%ls) exists", appId.GetPointer());
898 const String& name = pInfo->GetAppName();
899 if (name == L"_AppControl")
901 // workaround for special case: requery with actual appId
902 const PackageId& packageId = _PackageManagerImpl::GetPackageIdByAppId(appId);
903 const String& defaultName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
905 const String& convertedAppId = packageId + L'.' + defaultName;
907 std::unique_ptr<PackageAppInfo> pNewInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(convertedAppId));
911 _appName = pNewInfo->GetAppDisplayName();
915 SysLog(NID_APP, "No default applicaiton information, possible database error.");
920 _appName = pInfo->GetAppDisplayName();
925 SysLog(NID_APP, "PackageInfo of appId(%ls) does not exist", appId.GetPointer());
933 _AppControlImpl::GetAppId(void) const
935 return (_property & _APPCONTROL_PROPERTY_OSP) ? _path : _provider;
939 _AppControlImpl::GetAppControlProviderId(void) const
945 _AppControlImpl::GetOperationId(void) const
951 _AppControlImpl::GetCategoryListN(void) const
953 AppId appId = GetAppId();
954 SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_SYSTEM, "[E_SYSTEM] Empty appId.");
956 AppId aliasAppId = _AppControlRegistry::GetInstance()->GetAliasAppId(appId);
957 if (!aliasAppId.IsEmpty())
962 SysLog(NID_APP, "Acquiring category for app %ls.", appId.GetPointer());
964 std::unique_ptr<PackageAppInfo> pAppInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
965 SysTryReturn(NID_APP, pAppInfo.get() != null, null, E_SYSTEM, "[E_SYSTEM] Getting PackageAppInfo failed.");
967 return pAppInfo->GetAppCategoryListN();
971 _AppControlImpl::StopAppControlResponseListener(IAppControlResponseListener* pListener)
973 _AppControlManager::GetInstance()->__listenerList.Add(pListener);
977 _AppControlImpl::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
979 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
981 if (pEventArg != null)
983 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
985 if(pResponseListener != null)
987 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_COMPLETE)
989 _AppControlManager::InvokeAppControlCompleteListener(*pResponseListener, pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData(), pEventArg->IsSubMode());
991 _AppControlResponseEvent* pResponseEvent = null;
992 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
993 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
994 delete pResponseEvent;
995 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
999 SysLog(NID_APP, "Unexpected AppControlResponseType(%d)", pEventArg->GetType());
1004 SysLog(NID_APP, "Invalid ResponseListener");
1009 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);