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 <FAppIAppControlEventListener.h>
32 #include <FAppIAppControlResponseListener.h>
33 #include <FBaseColHashMap.h>
34 #include <FBaseSysLog.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_AppImpl.h"
43 #include "FApp_AppControlRegistry.h"
44 #include "FApp_AppMessageImpl.h"
45 #include "FApp_AppInfo.h"
46 #include "FAppPkg_PackageManagerImpl.h"
48 #include "FApp_AppControlEventArg.h"
49 #include "FApp_AppControlResponseEvent.h"
50 #include "FBaseRt_ThreadImpl.h"
52 using namespace Tizen::Base;
53 using namespace Tizen::Base::Collection;
54 using namespace Tizen::Base::Runtime;
55 using namespace Tizen::App;
56 using namespace Tizen::App::Package;
57 using namespace Tizen::Io;
62 static const int _REQ_ID_INVALID = -1;
66 namespace Tizen { namespace App
69 const wchar_t TIZEN_OPERATION_MAIN[] = L"http://tizen.org/appcontrol/operation/main";
70 const char TIZEN_APPCONTROL_DATA_LEGACY[] = "http://tizen.org/appcontrol/data/legacyresult";
72 _AppControlImpl::_AppControlImpl(const AppControl& value)
74 , _reqId(_REQ_ID_INVALID)
75 , _property(_APPCONTROL_PROPERTY_NONE)
76 , _processId(_REQ_ID_INVALID)
78 __appControlResponseEventList.Construct();
81 _AppControlImpl::~_AppControlImpl(void)
83 IEnumeratorT<int>* pEnum = __appControlResponseEventList.GetEnumeratorN();
84 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = null;
87 pResponseEventContainer = _AppControlManager::GetInstance()->GetAppControlResponseEventContainer();
90 while(pEnum->MoveNext() == E_SUCCESS)
93 pEnum->GetCurrent(reqId);
94 if (pResponseEventContainer != null)
96 _AppControlResponseEvent* pResponseEvent = null;
97 pResponseEventContainer->GetValue(reqId, pResponseEvent);
98 delete pResponseEvent;
100 pResponseEventContainer->Remove(reqId);
101 SysLog(NID_APP, "pResponseEvent gets deleted. reqId(%d)", reqId);
108 _AppControlImpl::CreateN(const String& path, const String& aId, const String& oId, const String& name, int prop)
110 SysTryReturn(NID_APP, !path.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] Path is empty.");
111 SysTryReturn(NID_APP, !aId.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] Provider Id is empty.");
112 SysTryReturn(NID_APP, !oId.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] Operation Id is empty.");
114 AppControl* pAc = new (std::nothrow) AppControl;
115 SysTryReturn(NID_APP, pAc != null, null, E_OUT_OF_MEMORY, "AppControl allocation failure.");
117 _AppControlImpl* pImpl = pAc->__pAppControlImpl;
118 SysTryReturn(NID_APP, pImpl != null, null, E_OUT_OF_MEMORY, "AppControlImpl instance must not be null.");
121 pImpl->_provider = aId;
123 // [FIXME] Proper App name setting
124 pImpl->_appName = name;
125 pImpl->_property = prop;
131 _AppControlImpl::CreateN(const AppId& appId, const String& operationId, bool changeAppId)
133 SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] appId is empty.");
135 AppControl* pAc = new (std::nothrow) AppControl;
136 SysTryReturn(NID_APP, pAc != null, null, E_OUT_OF_MEMORY, "AppControl allocation failure.");
138 _AppControlImpl* pImpl = pAc->__pAppControlImpl;
139 SysTryReturn(NID_APP, pImpl != null, null, E_OUT_OF_MEMORY, "AppControlImpl instance must not be null.");
141 pImpl->_path = appId;
142 pImpl->_provider = appId;
143 pImpl->_opId = operationId;
144 //pImpl->_appName = appId;
145 pImpl->_property |= (_APPCONTROL_PROPERTY_OSP | _APPCONTROL_PROPERTY_PUBLIC);
149 pImpl->_property |= _APPCONTROL_PROPERTY_APPID_CHANGE;
156 _AppControlImpl::CreateN(const AppControl& ac)
158 const _AppControlImpl* pImpl = GetInstance(ac);
159 SysTryReturn(NID_APP, pImpl != null, null, E_INVALID_STATE, "AppControlImpl instance must not be null.");
161 return CreateN(pImpl->_path, pImpl->_provider, pImpl->_opId, pImpl->_appName, pImpl->_property);
164 const _AppControlImpl*
165 _AppControlImpl::GetInstance(const AppControl& ac)
167 return ac.__pAppControlImpl;
171 _AppControlImpl::GetInstance(AppControl& ac)
173 return ac.__pAppControlImpl;
177 _AppControlImpl::Start(const IList* pDataList, IAppControlEventListener* pListener)
179 SysLog(NID_APP, "Enter");
182 if (_property & _APPCONTROL_PROPERTY_SLP)
184 r = StartNative(pDataList, pListener);
186 else if (_property & _APPCONTROL_PROPERTY_OSP)
188 r = StartOsp(pDataList, pListener);
192 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Invalid AppControl type(property %d)", _property);
194 SysLog(NID_APP, "Exit");
200 _AppControlImpl::Start(const String* pUriData, const String* pDataType, const IMap* pExtraData, IAppControlResponseListener* pListener)
202 SysLog(NID_APP, "Enter");
205 if (_property & _APPCONTROL_PROPERTY_SLP)
207 r = StartNative(pUriData, pDataType, pExtraData, pListener);
209 else if (_property & _APPCONTROL_PROPERTY_OSP)
211 r = StartOsp(pUriData, pDataType, pExtraData, pListener);
215 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Invalid AppControl type(property %d)", _property);
217 SysLog(NID_APP, "Exit");
223 _AppControlImpl::FindAndStart(const String& operationId, const String* pUriPattern, const String* pDataType, const String* pCategory, const IMap* pExtraData, IAppControlResponseListener* pListener)
225 // [FIXME] valid argument size checking required
226 SysLog(NID_APP, "Enter");
228 std::unique_ptr<bundle, BundleDeleter> pBundle(bundle_create());
229 SysTryReturnResult(NID_APP, pBundle.get(), E_OUT_OF_MEMORY, "Bundle creation failure.");
231 _AppMessageImpl::SetOperation(pBundle.get(), operationId);
235 _AppMessageImpl::SetUri(pBundle.get(), *pUriPattern);
240 String mimeType = *pDataType;
242 if ((*pDataType)[0] == L'.')
244 SysLog(NID_APP, "Extension to MIME conversion for %ls", pDataType->GetPointer());
248 pDataType->SubString(1, ext);
250 result r = _AppControlManager::GetMimeFromExt(ext, mimeType);
252 SysTryReturn(NID_APP, !IsFailed(r), null, r, "[%s] MIME type conversion failure for %ls.", GetErrorMessage(r), ext.GetPointer());
254 pMimeType = &mimeType;
256 SysLog(NID_APP, "Conversion : %ls -> %ls.", pDataType->GetPointer(), pMimeType->GetPointer());
260 _AppMessageImpl::SetMime(pBundle.get(), mimeType);
265 _AppMessageImpl::SetCategory(pBundle.get(), *pCategory);
268 return StartImplicit(pBundle.get(), pExtraData, pListener);
272 _AppControlImpl::StartOsp(const IList* pDataList, IAppControlEventListener* pListener)
274 SysLog(NID_APP, "Enter");
275 result r = E_SUCCESS;
277 _AppArg* pArg = new (std::nothrow) _AppArg;
278 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
280 pArg->Construct(*this, pDataList);
282 _AppControlManager* pImpl = _AppControlManager::GetInstance();
283 int req = _REQ_ID_INVALID;
287 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCbLegacy, pListener, _property);
288 req = reqObj.GetRequestNumber();
290 _processId = pImpl->Launch(_path, pArg, req);
296 SysLog(NID_APP, "[%s]Launching(%ls) is failed" , GetErrorMessage(r), _path.GetPointer());
302 _processId = pImpl->Launch(_path, pArg);
304 SysTryReturnResult(NID_APP, _processId >= 0, GetLastResult(), "Launching(%ls) is failed", _path.GetPointer());
306 SysLog(NID_APP, "Exit");
312 _AppControlImpl::StartOsp(const String* pUriData, const String* pMimeType, const IMap* pDataList, IAppControlResponseListener* pListener)
314 SysLog(NID_APP, "Enter");
315 result r = E_SUCCESS;
317 _AppArg* pArg = new (std::nothrow) _AppArg;
318 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
320 pArg->Construct(*this, pUriData, pMimeType, pDataList);
322 _AppControlManager* pImpl = _AppControlManager::GetInstance();
323 int req = _REQ_ID_INVALID;
327 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCb, pListener, _property);
328 req = reqObj.GetRequestNumber();
330 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
332 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
333 if (pAppControlResponseEvent != null)
335 r = pAppControlResponseEvent->Construct();
336 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
338 r = pAppControlResponseEvent->AddListener(*this, true);
339 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
341 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = pImpl->GetAppControlResponseEventContainer();
342 if (pResponseEventContainer != null)
344 pResponseEventContainer->Add(req, pAppControlResponseEvent);
345 __appControlResponseEventList.Add(req);
346 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", req);
351 _processId = pImpl->Launch(_path, pArg, req);
356 SysLog(NID_APP, "[%s]Launching(%ls) is failed" , GetErrorMessage(r), _path.GetPointer());
362 _processId = pImpl->Launch(_path, pArg);
364 SysTryReturnResult(NID_APP, _processId >= 0, GetLastResult(), "Launching(%ls) is failed", _path.GetPointer());
366 SysLog(NID_APP, "Exit");
372 _AppControlImpl::StartImplicit(bundle* pBundle, const IList* pDataList, IAppControlEventListener* pListener)
374 SysLog(NID_APP, "Enter");
375 result r = E_SUCCESS;
377 _AppArg* pArg = new (std::nothrow) _AppArg;
378 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
380 pArg->Construct(pBundle);
382 _AppMessageImpl::AddData(pArg->GetBundle(), pDataList);
384 _AppControlManager* pImpl = _AppControlManager::GetInstance();
385 int req = _REQ_ID_INVALID;
389 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCbLegacy, pListener, _APPCONTROL_PROPERTY_NONE);
390 req = reqObj.GetRequestNumber();
392 r = pImpl->LaunchAppImplicit(pArg, req);
393 SysTryCatch(NID_APP, r == E_SUCCESS, reqObj.Invalidate(), r, "[%s] Propagating." , GetErrorMessage(r));
397 r = pImpl->LaunchAppImplicit(pArg, -1);
401 // [FIXME] launch registration is not working correctly
402 SysLog(NID_APP, "Exit");
409 _AppControlImpl::StartImplicit(bundle* pBundle, const IMap* pData, IAppControlResponseListener* pListener)
411 SysLog(NID_APP, "Enter");
412 result r = E_SUCCESS;
414 _AppArg* pArg = new (std::nothrow) _AppArg;
415 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
417 pArg->Construct(pBundle);
419 _AppArg::AddStrMap(pArg->GetBundle(), pData);
421 _AppControlManager* pImpl = _AppControlManager::GetInstance();
422 int req = _REQ_ID_INVALID;
426 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCb, pListener, _APPCONTROL_PROPERTY_NONE);
427 req = reqObj.GetRequestNumber();
429 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
431 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
433 if (pAppControlResponseEvent != null)
435 r = pAppControlResponseEvent->Construct();
436 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
438 r = pAppControlResponseEvent->AddListener(*pImpl, true);
439 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
441 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = pImpl->GetAppControlResponseEventContainer();
442 if (pResponseEventContainer != null)
444 pResponseEventContainer->Add(req, pAppControlResponseEvent);
445 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", req);
449 r = pImpl->LaunchAppImplicit(pArg, req);
450 SysTryCatch(NID_APP, r == E_SUCCESS, reqObj.Invalidate(), r, "[%s] Propagating." , GetErrorMessage(r));
454 r = pImpl->LaunchAppImplicit(pArg, -1);
457 SysLog(NID_APP, "Exit");
459 // [FIXME] launch registration is not working correctly
467 _AppControlImpl::AppControlCbLegacy(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int reqId)
469 SysLog(NID_APP, "Result value %d", res);
471 SysTryReturnResult(NID_APP, data && pResArg && pArg, E_SYSTEM, "Invalid result (callback, result, arg) = (0x%x, 0x%x, 0x%x).",
475 bundle* b = pResArg->GetBundle();
476 SysTryReturnResult(NID_APP, b != NULL, E_SYSTEM, "Invalid result bundle.");
478 IAppControlEventListener* pListener = static_cast<IAppControlEventListener*>(data);
479 SysTryReturnResult(NID_APP, typeid(pListener) == typeid(IAppControlEventListener*), E_SYSTEM, "Invalid result callback");
481 bundle* inb = pArg->GetBundle();
482 SysTryReturnResult(NID_APP, inb != NULL, E_SYSTEM, "Empty caller bundle.");
486 AppId provider = pResArg->GetCalleeAppId();
488 const char* p = appsvc_get_operation(inb);
494 SysLog(NID_APP, "Invoking callback with (%ls, %ls)", provider.GetPointer(), oId.GetPointer());
496 if (prop & _APPCONTROL_PROPERTY_ALIAS)
498 const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
499 pEntry = _AppControlRegistry::GetInstance()->GetReverseAppControlAliasEntry(provider, oId);
502 provider = pEntry->provider;
503 oId = pEntry->operation;
505 SysLog(NID_APP, "Legacy AppControl name (%ls, %ls).", provider.GetPointer(), oId.GetPointer());
509 if (prop & _APPCONTROL_PROPERTY_APPID_CHANGE)
511 String tmp = _AppControlRegistry::GetInstance()->GetReverseAliasAppId(provider);
514 SysLog(NID_APP, "App change (%ls -> %ls).", provider.GetPointer(), tmp.GetPointer());
520 std::unique_ptr<HashMap> pMap(pResArg->GetArgMapN());
522 ArrayList list(SingleObjectDeleter);
523 _AppArg::FillLegacyAppControlResult(list, res, pMap.get(), provider);
525 // proper callback invokation
526 pListener->OnAppControlCompleted(provider, oId, &list);
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, 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 name (%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 std::unique_ptr<HashMap> pMap(pResArg->GetArgMapN());
587 AppCtrlResult ret = _AppControlManager::ConvertAppControlResultCode(res);
589 SysLog(NID_APP, "Result code : 0x%x.", ret);
591 // proper callback invokation
592 _AppControlResponseEvent* pResponseEvent = null;
593 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(reqId, pResponseEvent);
595 if (pResponseEvent != null)
597 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, provider, oId, E_SUCCESS, ret, pMap.release(), reqId);
598 pResponseEvent->Fire(*pResponseEventArg);
599 SysLog(NID_APP, "OnAppControlCompleteResponseReceived, pResponseEvent is Fired");
603 pListener->OnAppControlCompleteResponseReceived(provider, oId, ret, pMap.get());
604 SysLog(NID_APP, "OnAppControlCompleteResponseReceived, Called");
611 _AppControlImpl::StartNative(const IList* pDataList, IAppControlEventListener* pListener)
613 SysLog(NID_APP, "Enter");
614 _InProcessInfo* pInfo = _AppControlManager::GetInstance()->__inAppManager.FindItem(_reqId);
615 SysTryReturnResult(NID_APP, pInfo == null, E_IN_PROGRESS, "Request ID %d is already in progress.", _reqId);
617 int req = _REQ_ID_INVALID;
618 _LibraryImpl* pLib = null;
620 pLib = new (std::nothrow) _LibraryImpl;
621 SysTryReturnResult(NID_APP, pLib != null, E_OUT_OF_MEMORY, "Failed to allocate libraryimpl.");
623 unsigned long option = _LIBRARY_LOAD_OPTION_LAZY;
624 option |= _LIBRARY_LOAD_OPTION_NODELETE;
626 result r = pLib->Construct(_path, option);
627 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
631 _InProcessInfo* pItem = new (std::nothrow) _InProcessInfo(_provider, _opId, _property, true, *pLib, pListener);
634 req = _AppControlManager::GetInstance()->__inAppManager.InsertItem(pItem);
637 r = InvokeStartAppControl(*pLib, req, _provider, _opId, pDataList);
639 if (pListener == null)
644 // after acquring request number, pLib should be managed from the list, not CATCH
647 SetLastResult(E_SYSTEM);
648 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(req);
649 SysLog(NID_APP, "[E_SYSTEM] A system error has occurred with %s.", 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 SetLastResult(E_SYSTEM);
737 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(req);
738 SysLog(NID_APP, "[E_SYSTEM] A system error has occurred with %s.", 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 pResponseListener->OnAppControlCompleteResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData());
983 SysLog(NID_APP, "OnAppControlCompleteResponseReceived called");
985 _AppControlResponseEvent* pResponseEvent = null;
986 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
987 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
988 delete pResponseEvent;
989 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
993 SysLog(NID_APP, "Unexpected AppControlResponseType(%d)", pEventArg->GetType());
998 SysLog(NID_APP, "Invalid ResponseListener");
1003 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);