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 <FBaseRt_LibraryImpl.h>
37 #include <FIo_DirectoryImpl.h>
39 #include "FApp_AppControlImpl.h"
40 #include "FApp_AppControlManager.h"
41 #include "FApp_AppArg.h"
42 #include "FApp_AppControlRegistry.h"
43 #include "FApp_AppMessageImpl.h"
44 #include "FApp_AppInfo.h"
45 #include "FAppPkg_PackageManagerImpl.h"
47 #include "FApp_AppControlEventArg.h"
48 #include "FApp_AppControlResponseEvent.h"
49 #include "FBaseRt_ThreadImpl.h"
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Base::Runtime;
54 using namespace Tizen::App;
55 using namespace Tizen::App::Package;
56 using namespace Tizen::Io;
61 static const int _REQ_ID_INVALID = -1;
65 namespace Tizen { namespace App
68 const wchar_t TIZEN_OPERATION_MAIN[] = L"http://tizen.org/appcontrol/operation/main";
70 _AppControlImpl::_AppControlImpl(const AppControl& value)
72 , _reqId(_REQ_ID_INVALID)
73 , _property(_APPCONTROL_PROPERTY_NONE)
74 , _processId(_REQ_ID_INVALID)
76 __appControlResponseEventList.Construct();
79 _AppControlImpl::~_AppControlImpl(void)
81 IEnumeratorT<int>* pEnum = __appControlResponseEventList.GetEnumeratorN();
82 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = null;
85 pResponseEventContainer = _AppControlManager::GetInstance()->GetAppControlResponseEventContainer();
88 while(pEnum->MoveNext() == E_SUCCESS)
91 pEnum->GetCurrent(reqId);
92 if (pResponseEventContainer != null)
94 _AppControlResponseEvent* pResponseEvent = null;
95 pResponseEventContainer->GetValue(reqId, pResponseEvent);
96 delete pResponseEvent;
98 pResponseEventContainer->Remove(reqId);
99 SysLog(NID_APP, "pResponseEvent gets deleted. reqId(%d)", reqId);
106 _AppControlImpl::CreateN(const String& path, const String& aId, const String& oId, const String& name, int prop)
108 SysTryReturn(NID_APP, !path.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] Path is empty.");
109 SysTryReturn(NID_APP, !aId.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] Provider Id is empty.");
110 SysTryReturn(NID_APP, !oId.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] Operation Id is empty.");
112 AppControl* pAc = new (std::nothrow) AppControl;
113 SysTryReturn(NID_APP, pAc != null, null, E_OUT_OF_MEMORY, "AppControl allocation failure.");
115 _AppControlImpl* pImpl = pAc->__pAppControlImpl;
116 SysTryReturn(NID_APP, pImpl != null, null, E_OUT_OF_MEMORY, "AppControlImpl instance must not be null.");
119 pImpl->_provider = aId;
121 // [FIXME] Proper App name setting
122 pImpl->_appName = name;
123 pImpl->_property = prop;
129 _AppControlImpl::CreateN(const AppId& appId, const String& operationId, bool changeAppId)
131 SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] appId is empty.");
133 AppControl* pAc = new (std::nothrow) AppControl;
134 SysTryReturn(NID_APP, pAc != null, null, E_OUT_OF_MEMORY, "AppControl allocation failure.");
136 _AppControlImpl* pImpl = pAc->__pAppControlImpl;
137 SysTryReturn(NID_APP, pImpl != null, null, E_OUT_OF_MEMORY, "AppControlImpl instance must not be null.");
139 pImpl->_path = appId;
140 pImpl->_provider = appId;
141 pImpl->_opId = operationId;
142 //pImpl->_appName = appId;
143 pImpl->_property |= (_APPCONTROL_PROPERTY_OSP | _APPCONTROL_PROPERTY_PUBLIC);
147 pImpl->_property |= _APPCONTROL_PROPERTY_APPID_CHANGE;
154 _AppControlImpl::CreateN(const AppControl& ac)
156 const _AppControlImpl* pImpl = GetInstance(ac);
157 SysTryReturn(NID_APP, pImpl != null, null, E_INVALID_STATE, "AppControlImpl instance must not be null.");
159 return CreateN(pImpl->_path, pImpl->_provider, pImpl->_opId, pImpl->_appName, pImpl->_property);
162 const _AppControlImpl*
163 _AppControlImpl::GetInstance(const AppControl& ac)
165 return ac.__pAppControlImpl;
169 _AppControlImpl::GetInstance(AppControl& ac)
171 return ac.__pAppControlImpl;
175 _AppControlImpl::Start(const IList* pDataList, IAppControlEventListener* pListener)
177 SysLog(NID_APP, "Enter");
180 if (_property & _APPCONTROL_PROPERTY_SLP)
182 r = StartNative(pDataList, pListener);
184 else if (_property & _APPCONTROL_PROPERTY_OSP)
186 r = StartOsp(pDataList, pListener);
190 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Invalid AppControl type(property %d)", _property);
192 SysLog(NID_APP, "Exit");
198 _AppControlImpl::Start(const String* pUriData, const String* pDataType, const IMap* pExtraData, IAppControlResponseListener* pListener)
200 SysLog(NID_APP, "Enter");
203 if (_property & _APPCONTROL_PROPERTY_SLP)
205 r = StartNative(pUriData, pDataType, pExtraData, pListener);
207 else if (_property & _APPCONTROL_PROPERTY_OSP)
209 r = StartOsp(pUriData, pDataType, pExtraData, pListener);
213 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Invalid AppControl type(property %d)", _property);
215 SysLog(NID_APP, "Exit");
221 _AppControlImpl::FindAndStart(const String& operationId, const String* pUriPattern, const String* pDataType, const String* pCategory, const IMap* pExtraData, IAppControlResponseListener* pListener)
223 // [FIXME] valid argument size checking required
224 SysLog(NID_APP, "Enter");
226 std::unique_ptr<bundle, BundleDeleter> pBundle(bundle_create());
227 SysTryReturnResult(NID_APP, pBundle.get(), E_OUT_OF_MEMORY, "Bundle creation failure.");
229 _AppMessageImpl::SetOperation(pBundle.get(), operationId);
233 _AppMessageImpl::SetUri(pBundle.get(), *pUriPattern);
238 String mimeType = *pDataType;
240 if ((*pDataType)[0] == L'.')
242 SysLog(NID_APP, "Extension to MIME conversion for %ls", pDataType->GetPointer());
246 pDataType->SubString(1, ext);
248 result r = _AppControlManager::GetMimeFromExt(ext, mimeType);
250 SysTryReturn(NID_APP, !IsFailed(r), null, r, "[%s] MIME type conversion failure for %ls.", GetErrorMessage(r), ext.GetPointer());
252 pMimeType = &mimeType;
254 SysLog(NID_APP, "Conversion : %ls -> %ls.", pDataType->GetPointer(), pMimeType->GetPointer());
258 _AppMessageImpl::SetMime(pBundle.get(), mimeType);
263 _AppMessageImpl::SetCategory(pBundle.get(), *pCategory);
266 return StartImplicit(pBundle.get(), pExtraData, pListener);
270 _AppControlImpl::StartOsp(const IList* pDataList, IAppControlEventListener* pListener)
272 SysLog(NID_APP, "Enter");
273 result r = E_SUCCESS;
275 _AppArg* pArg = new (std::nothrow) _AppArg;
276 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
278 pArg->Construct(*this, pDataList);
280 _AppControlManager* pImpl = _AppControlManager::GetInstance();
281 int req = _REQ_ID_INVALID;
285 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCbLegacy, pListener, _property);
286 req = reqObj.GetRequestNumber();
288 _processId = pImpl->Launch(_path, pArg, req);
294 SysLog(NID_APP, "[%s]Launching(%ls) is failed" , GetErrorMessage(r), _path.GetPointer());
300 _processId = pImpl->Launch(_path, pArg);
302 SysTryReturnResult(NID_APP, _processId >= 0, GetLastResult(), "Launching(%ls) is failed", _path.GetPointer());
304 SysLog(NID_APP, "Exit");
310 _AppControlImpl::StartOsp(const String* pUriData, const String* pMimeType, const IMap* pDataList, IAppControlResponseListener* pListener)
312 SysLog(NID_APP, "Enter");
313 result r = E_SUCCESS;
315 _AppArg* pArg = new (std::nothrow) _AppArg;
316 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
318 pArg->Construct(*this, pUriData, pMimeType, pDataList);
320 _AppControlManager* pImpl = _AppControlManager::GetInstance();
321 int req = _REQ_ID_INVALID;
325 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCb, pListener, _property);
326 req = reqObj.GetRequestNumber();
328 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
330 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
331 if (pAppControlResponseEvent != null)
333 r = pAppControlResponseEvent->Construct();
334 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
336 r = pAppControlResponseEvent->AddListener(*this, true);
337 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
339 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = pImpl->GetAppControlResponseEventContainer();
340 if (pResponseEventContainer != null)
342 pResponseEventContainer->Add(req, pAppControlResponseEvent);
343 __appControlResponseEventList.Add(req);
344 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", req);
349 _processId = pImpl->Launch(_path, pArg, req);
354 SysLog(NID_APP, "[%s]Launching(%ls) is failed" , GetErrorMessage(r), _path.GetPointer());
360 _processId = pImpl->Launch(_path, pArg);
362 SysTryReturnResult(NID_APP, _processId >= 0, GetLastResult(), "Launching(%ls) is failed", _path.GetPointer());
364 SysLog(NID_APP, "Exit");
370 _AppControlImpl::StartImplicit(bundle* pBundle, const IList* pDataList, IAppControlEventListener* pListener)
372 SysLog(NID_APP, "Enter");
373 result r = E_SUCCESS;
375 _AppArg* pArg = new (std::nothrow) _AppArg;
376 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
378 pArg->Construct(pBundle);
380 _AppMessageImpl::AddData(pArg->GetBundle(), pDataList);
382 _AppControlManager* pImpl = _AppControlManager::GetInstance();
383 int req = _REQ_ID_INVALID;
387 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCbLegacy, pListener, _APPCONTROL_PROPERTY_NONE);
388 req = reqObj.GetRequestNumber();
390 r = pImpl->LaunchAppImplicit(pArg, req);
391 SysTryCatch(NID_APP, r == E_SUCCESS, reqObj.Invalidate(), r, "[%s] Propagating." , GetErrorMessage(r));
395 r = pImpl->LaunchAppImplicit(pArg, -1);
399 // [FIXME] launch registration is not working correctly
400 SysLog(NID_APP, "Exit");
407 _AppControlImpl::StartImplicit(bundle* pBundle, const IMap* pData, IAppControlResponseListener* pListener)
409 SysLog(NID_APP, "Enter");
410 result r = E_SUCCESS;
412 _AppArg* pArg = new (std::nothrow) _AppArg;
413 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
415 pArg->Construct(pBundle);
417 _AppArg::AddStrMap(pArg->GetBundle(), pData);
419 _AppControlManager* pImpl = _AppControlManager::GetInstance();
420 int req = _REQ_ID_INVALID;
424 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCb, pListener, _APPCONTROL_PROPERTY_NONE);
425 req = reqObj.GetRequestNumber();
427 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
429 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
431 if (pAppControlResponseEvent != null)
433 r = pAppControlResponseEvent->Construct();
434 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
436 r = pAppControlResponseEvent->AddListener(*pImpl, true);
437 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
439 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = pImpl->GetAppControlResponseEventContainer();
440 if (pResponseEventContainer != null)
442 pResponseEventContainer->Add(req, pAppControlResponseEvent);
443 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", req);
447 r = pImpl->LaunchAppImplicit(pArg, req);
448 SysTryCatch(NID_APP, r == E_SUCCESS, reqObj.Invalidate(), r, "[%s] Propagating." , GetErrorMessage(r));
452 r = pImpl->LaunchAppImplicit(pArg, -1);
455 SysLog(NID_APP, "Exit");
457 // [FIXME] launch registration is not working correctly
465 _AppControlImpl::AppControlCbLegacy(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int reqId)
467 SysLog(NID_APP, "Result value %d", res);
469 SysTryReturnResult(NID_APP, data && pResArg && pArg, E_SYSTEM, "Invalid result (callback, result, arg) = (0x%x, 0x%x, 0x%x).",
473 bundle* b = pResArg->GetBundle();
474 SysTryReturnResult(NID_APP, b != NULL, E_SYSTEM, "Invalid result bundle.");
476 IAppControlEventListener* pListener = static_cast<IAppControlEventListener*>(data);
477 SysTryReturnResult(NID_APP, pListener == null || typeid(pListener) == typeid(IAppControlEventListener*), E_SYSTEM, "Invalid result callback");
479 bundle* inb = pArg->GetBundle();
480 SysTryReturnResult(NID_APP, inb != NULL, E_SYSTEM, "Empty caller bundle.");
484 AppId provider = pResArg->GetCalleeAppId();
486 const char* p = appsvc_get_operation(inb);
492 SysLog(NID_APP, "Invoking callback with (%ls, %ls)", provider.GetPointer(), oId.GetPointer());
494 if (prop & _APPCONTROL_PROPERTY_ALIAS)
496 const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
497 pEntry = _AppControlRegistry::GetInstance()->GetReverseAppControlAliasEntry(provider, oId);
500 provider = pEntry->provider;
501 oId = pEntry->operation;
503 SysLog(NID_APP, "Legacy AppControl(%ls, %ls).", provider.GetPointer(), oId.GetPointer());
507 if (prop & _APPCONTROL_PROPERTY_APPID_CHANGE)
509 String tmp = _AppControlRegistry::GetInstance()->GetReverseAliasAppId(provider);
512 SysLog(NID_APP, "App change (%ls -> %ls).", provider.GetPointer(), tmp.GetPointer());
518 const bool isSubMode = _AppArg::IsSubMode(b);
519 const bool isServiceCallee = _AppArg::IsServiceApp(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 | isServiceCallee);
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);
586 const bool isServiceCallee = _AppArg::IsServiceApp(b);
588 std::unique_ptr<HashMap> pMap(pResArg->GetArgMapN());
590 AppCtrlResult ret = _AppControlManager::ConvertAppControlResultCode(res);
592 SysLog(NID_APP, "Result code : 0x%x.", ret);
594 // proper callback invokation
595 _AppControlResponseEvent* pResponseEvent = null;
596 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(reqId, pResponseEvent);
598 if (pResponseEvent != null)
600 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, provider, oId, E_SUCCESS, ret, pMap.release(), reqId, isSubMode | isServiceCallee);
601 pResponseEvent->Fire(*pResponseEventArg);
602 SysLog(NID_APP, "OnAppControlCompleteResponseReceived, pResponseEvent is Fired");
606 _AppControlManager::InvokeAppControlCompleteListener(*pListener, provider, oId, ret, pMap.get(), isSubMode | isServiceCallee);
613 _AppControlImpl::StartNative(const IList* pDataList, IAppControlEventListener* pListener)
615 SysLog(NID_APP, "Enter");
616 _InProcessInfo* pInfo = _AppControlManager::GetInstance()->__inAppManager.FindItem(_reqId);
617 SysTryReturnResult(NID_APP, pInfo == null, E_IN_PROGRESS, "Request ID %d is already in progress.", _reqId);
619 int req = _REQ_ID_INVALID;
620 _LibraryImpl* pLib = null;
622 pLib = new (std::nothrow) _LibraryImpl;
623 SysTryReturnResult(NID_APP, pLib != null, E_OUT_OF_MEMORY, "Failed to allocate libraryimpl.");
625 unsigned long option = _LIBRARY_LOAD_OPTION_LAZY;
626 option |= _LIBRARY_LOAD_OPTION_NODELETE;
628 result r = pLib->Construct(_path, option);
629 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
633 _InProcessInfo* pItem = new (std::nothrow) _InProcessInfo(_provider, _opId, _property, true, *pLib, pListener);
636 req = _AppControlManager::GetInstance()->__inAppManager.InsertItem(pItem);
639 r = InvokeStartAppControl(*pLib, req, _provider, _opId, pDataList);
641 if (pListener == null)
646 // after acquring request number, pLib should be managed from the list, not CATCH
649 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(req);
650 SysLog(NID_APP, "[%s] A system error has occurred.", GetErrorMessage(r));
657 SysLog(NID_APP, "Exit");
665 case E_LIBRARY_NOT_FOUND:
677 _AppControlImpl::StartNative(const String* pUriData, const String* pMimeType, const IMap* pDataList, IAppControlResponseListener* pListener)
679 SysLog(NID_APP, "Enter");
680 _InProcessInfo* pInfo = _AppControlManager::GetInstance()->__inAppManager.FindItem(_reqId);
681 SysTryReturnResult(NID_APP, pInfo == null, E_IN_PROGRESS, "Request ID %d is already in progress.", _reqId);
683 int req = _REQ_ID_INVALID;
684 _LibraryImpl* pLib = null;
686 pLib = new (std::nothrow) _LibraryImpl;
687 SysTryReturnResult(NID_APP, pLib != null, E_OUT_OF_MEMORY, "Failed to allocate libraryimpl.");
689 unsigned long option = _LIBRARY_LOAD_OPTION_LAZY;
690 option |= _LIBRARY_LOAD_OPTION_NODELETE;
692 result r = pLib->Construct(_path, option);
694 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
698 _InProcessInfo* pItem = new (std::nothrow) _InProcessInfo(_provider, _opId, _property, false, *pLib, pListener);
701 req = _AppControlManager::GetInstance()->__inAppManager.InsertItem(pItem);
704 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
706 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
708 if (pAppControlResponseEvent != null)
710 r = pAppControlResponseEvent->Construct();
711 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
713 r = pAppControlResponseEvent->AddListener(*this, true);
714 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
716 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = _AppControlManager::GetInstance()->GetAppControlResponseEventContainer();
717 if (pResponseEventContainer != null)
719 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + req;
720 pResponseEventContainer->Add(responseEventRequestId, pAppControlResponseEvent);
721 __appControlResponseEventList.Add(responseEventRequestId);
722 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", responseEventRequestId);
727 r = InvokeStartAppControl(*pLib, req, _provider, _opId, pUriData, pMimeType, pDataList);
729 if (pListener == null)
734 // after acquring request number, pLib should be managed from the list, not CATCH
737 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(req);
738 SysLog(NID_APP, "[%s] A system error has occurred.", GetErrorMessage(r));
744 SysLog(NID_APP, "Exit");
753 case E_LIBRARY_NOT_FOUND:
765 _AppControlImpl::InvokeStartAppControl(_LibraryImpl& lib, int req, const String& appId, const String& oId, const IList* pList)
767 SysLog(NID_APP, "Legacy stuff for converting argument");
769 HashMap map(SingleObjectDeleter);
770 HashMap* pMap = null;
775 _AppArg::FillMapFromList(&map, pList);
780 return InvokeStartAppControl(lib, req, appId, oId, null, null, pMap);
785 _AppControlImpl::InvokeStartAppControl(_LibraryImpl& lib, int req, const String& appId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
787 result (*pFunc)(int req, const String&, const String&, const String*, const String*, const IMap*) = null;
790 reinterpret_cast<result (*)(int, const String&, const String&, const String*, const String*, const IMap*)>(lib.GetProcAddress(L"StartAppControl"));
791 SysTryReturnResult(NID_APP, pFunc != null, E_OBJ_NOT_FOUND, "Entry \"StartAppControl\" not found for %ls", appId.GetPointer());
793 const String* pActualUri = (pUri && !(pUri->IsEmpty())) ? pUri : null;
794 const String* pActualMime = (pMime && !(pMime->IsEmpty())) ? pMime : null;
795 return (*pFunc)(req, appId, oId, pActualUri, pActualMime, pMap);
799 IsValidAppControl(const String& appcontrolID)
801 return ((appcontrolID == L"osp.appcontrol.provider.audio")
802 || (appcontrolID == L"osp.appcontrol.provider.bluetooth")
803 || (appcontrolID == L"osp.appcontrol.provider.calendar")
804 || (appcontrolID == L"osp.appcontrol.provider.camera")
805 || (appcontrolID == L"osp.appcontrol.provider.contact")
806 || (appcontrolID == L"osp.appcontrol.provider.certificatemanager")
807 || (appcontrolID == L"osp.appcontrol.provider.email")
808 || (appcontrolID == L"osp.appcontrol.provider.image")
809 || (appcontrolID == L"osp.appcontrol.provider.media")
810 || (appcontrolID == L"osp.appcontrol.provider.message")
811 || (appcontrolID == L"osp.appcontrol.provider.video")
812 || (appcontrolID == L"osp.appcontrol.provider.imageeditor")
813 || (appcontrolID == L"osp.appcontrol.provider.allshare")
814 || (appcontrolID == L"tizen.filemanager")
815 || (appcontrolID == L"tizen.camera")
816 || (appcontrolID == L"tizen.gallery")
817 || (appcontrolID == L"tizen.imageviewer")
818 || (appcontrolID == L"tizen.videoplayer")
819 || (appcontrolID == L"tizen.memo")
820 || (appcontrolID == L"tizen.contacts")
821 || (appcontrolID == L"tizen.calendar")
822 || (appcontrolID == L"tizen.todo")
823 || (appcontrolID == L"tizen.email")
824 || (appcontrolID == L"tizen.settings")
825 || (appcontrolID == L"tizen.messages")
826 || (appcontrolID == L"tizen.musicplayer")
827 || (appcontrolID == L"tizen.bluetooth")
828 || (appcontrolID == L"samsung.snote")
829 || (appcontrolID == L"0pnxz8hbsr.MyFiles")
830 || (appcontrolID == L"hdufar9ycj.Camera")
831 || (appcontrolID == L"ijudt7w61q.Gallery")
832 || (appcontrolID == L"jysyv9o1dc.ImageViewer")
833 || (appcontrolID == L"npwf0scb88.VideoPlayer")
834 || (appcontrolID == L"zunqjlsnce.Memo")
835 || (appcontrolID == L"f9uev8hsyo.Contacts")
836 || (appcontrolID == L"ph1vq2phrp.Calendar")
837 || (appcontrolID == L"vxqbrefica.Email")
838 || (appcontrolID == L"kto5jikgul.Settings")
839 || (appcontrolID == L"8r4r5ddzzn.Messages")
840 || (appcontrolID == L"dhrul6qzj3.MusicPlayer")
841 || (appcontrolID == L"smemo-efl"));
845 _AppControlImpl::Stop(void)
847 const String appcontrolID(GetAppControlProviderId());
848 SysTryReturnResult(NID_APP, IsValidAppControl(appcontrolID), E_INVALID_OPERATION, "Invalid appcontrolID(%ls)", appcontrolID.GetPointer());
850 if (_property & _APPCONTROL_PROPERTY_SLP)
852 SysTryReturnResult(NID_APP, _reqId != _REQ_ID_INVALID, E_INVALID_OPERATION, "Invalid request ID .");
854 _InProcessInfo* pInfo = _AppControlManager::GetInstance()->__inAppManager.FindItem(_reqId);
855 SysTryReturnResult(NID_APP, pInfo != null, E_INVALID_OPERATION, "Request ID %d is not found.", _reqId);
857 result (*pStop)(int req) = null;
858 pStop = reinterpret_cast<result (*)(int)>(pInfo->pLib->GetProcAddress(L"TerminateAppControl"));
859 SysTryReturnResult(NID_APP, pStop != null, E_SYSTEM, "No TerminateAppControl() function.");
863 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(_reqId);
865 _reqId = _REQ_ID_INVALID;
867 else if (_property & _APPCONTROL_PROPERTY_OSP)
869 _Aul::TerminateApplicationByPid(_processId);
876 _AppControlImpl::GetAppName(void)
878 if (_appName.IsEmpty())
880 AppId appId = GetAppId();
881 AppId aliasAppId = _AppControlRegistry::GetInstance()->GetAliasAppId(appId);
882 if (!aliasAppId.IsEmpty())
887 std::unique_ptr<PackageAppInfo> pInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
890 SysLog(NID_APP, "PackageInfo of appId(%ls) exists", appId.GetPointer());
891 const String& name = pInfo->GetAppName();
892 if (name == L"_AppControl")
894 // workaround for special case: requery with actual appId
895 const PackageId& packageId = _PackageManagerImpl::GetPackageIdByAppId(appId);
896 const String& defaultName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
898 const String& convertedAppId = packageId + L'.' + defaultName;
900 std::unique_ptr<PackageAppInfo> pNewInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(convertedAppId));
904 _appName = pNewInfo->GetAppDisplayName();
908 SysLog(NID_APP, "No default applicaiton information, possible database error.");
913 _appName = pInfo->GetAppDisplayName();
918 SysLog(NID_APP, "PackageInfo of appId(%ls) does not exist", appId.GetPointer());
926 _AppControlImpl::GetAppId(void) const
928 return (_property & _APPCONTROL_PROPERTY_OSP) ? _path : _provider;
932 _AppControlImpl::GetAppControlProviderId(void) const
938 _AppControlImpl::GetOperationId(void) const
944 _AppControlImpl::GetCategoryListN(void) const
946 AppId appId = GetAppId();
947 SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_SYSTEM, "[E_SYSTEM] Empty appId.");
949 AppId aliasAppId = _AppControlRegistry::GetInstance()->GetAliasAppId(appId);
950 if (!aliasAppId.IsEmpty())
955 SysLog(NID_APP, "Acquiring category for app %ls.", appId.GetPointer());
957 std::unique_ptr<PackageAppInfo> pAppInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
958 SysTryReturn(NID_APP, pAppInfo.get() != null, null, E_SYSTEM, "[E_SYSTEM] Getting PackageAppInfo failed.");
960 return pAppInfo->GetAppCategoryListN();
964 _AppControlImpl::StopAppControlResponseListener(IAppControlResponseListener* pListener)
966 _AppControlManager::GetInstance()->__listenerList.Add(pListener);
970 _AppControlImpl::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
972 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
974 if (pEventArg != null)
976 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
978 if(pResponseListener != null)
980 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_COMPLETE)
982 _AppControlManager::InvokeAppControlCompleteListener(*pResponseListener, pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData(), pEventArg->IsSubMode());
984 _AppControlResponseEvent* pResponseEvent = null;
985 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
986 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
987 delete pResponseEvent;
988 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
992 SysLog(NID_APP, "Unexpected AppControlResponseType(%d)", pEventArg->GetType());
997 SysLog(NID_APP, "Invalid ResponseListener");
1002 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);