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_IAppControlPluginProvider.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;
174 _IAppControlPluginProvider*
175 _AppControlImpl::GetAppControlPluginProvider(const String& path)
178 lib.Construct(path, _LIBRARY_OPTION);
180 APP_CONTROL_PROVIDER_GET_FN pProvider = reinterpret_cast<APP_CONTROL_PROVIDER_GET_FN>(lib.GetProcAddress(L"GetAppControlProviderPlugin"));
184 SysLogException(NID_APP, E_SYSTEM, "Cannot load plugin properly for %ls.", path.GetPointer());
188 return (*pProvider)();
192 _AppControlImpl::Start(const IList* pDataList, IAppControlEventListener* pListener)
194 SysLog(NID_APP, "Enter");
197 if (_property & _APPCONTROL_PROPERTY_SLP)
199 r = StartNative(pDataList, pListener);
201 else if (_property & _APPCONTROL_PROPERTY_OSP)
203 r = StartOsp(pDataList, pListener);
207 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Invalid AppControl type(property %d)", _property);
209 SysLog(NID_APP, "Exit");
215 _AppControlImpl::Start(const String* pUriData, const String* pDataType, const IMap* pExtraData, IAppControlResponseListener* pListener)
217 SysLog(NID_APP, "Enter");
220 if (_property & _APPCONTROL_PROPERTY_SLP)
222 r = StartNative(pUriData, pDataType, pExtraData, pListener);
224 else if (_property & _APPCONTROL_PROPERTY_OSP)
226 r = StartOsp(pUriData, pDataType, pExtraData, pListener);
230 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] Invalid AppControl type(property %d)", _property);
232 SysLog(NID_APP, "Exit");
238 _AppControlImpl::FindAndStart(const String& operationId, const String* pUriPattern, const String* pDataType, const String* pCategory, const IMap* pExtraData, IAppControlResponseListener* pListener)
240 // [FIXME] valid argument size checking required
241 SysLog(NID_APP, "Enter");
243 std::unique_ptr<bundle, BundleDeleter> pBundle(bundle_create());
244 SysTryReturnResult(NID_APP, pBundle.get(), E_OUT_OF_MEMORY, "Bundle creation failure.");
246 _AppMessageImpl::SetOperation(pBundle.get(), operationId);
250 _AppMessageImpl::SetUri(pBundle.get(), *pUriPattern);
255 String mimeType = *pDataType;
257 if ((*pDataType)[0] == L'.')
259 SysLog(NID_APP, "Extension to MIME conversion for %ls", pDataType->GetPointer());
263 pDataType->SubString(1, ext);
265 result r = _AppControlManager::GetMimeFromExt(ext, mimeType);
267 SysTryReturn(NID_APP, !IsFailed(r), null, r, "[%s] MIME type conversion failure for %ls.", GetErrorMessage(r), ext.GetPointer());
269 pMimeType = &mimeType;
271 SysLog(NID_APP, "Conversion : %ls -> %ls.", pDataType->GetPointer(), pMimeType->GetPointer());
275 _AppMessageImpl::SetMime(pBundle.get(), mimeType);
280 _AppMessageImpl::SetCategory(pBundle.get(), *pCategory);
283 return StartImplicit(pBundle.get(), pExtraData, pListener);
287 _AppControlImpl::StartOsp(const IList* pDataList, IAppControlEventListener* pListener)
289 SysLog(NID_APP, "Enter");
290 result r = E_SUCCESS;
292 _AppArg* pArg = new (std::nothrow) _AppArg;
293 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
295 pArg->Construct(*this, pDataList);
297 _AppControlManager* pImpl = _AppControlManager::GetInstance();
298 int req = _REQ_ID_INVALID;
302 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCbLegacy, pListener, _property);
303 req = reqObj.GetRequestNumber();
305 _processId = pImpl->Launch(_path, pArg, req);
311 SysLog(NID_APP, "[%s]Launching(%ls) is failed" , GetErrorMessage(r), _path.GetPointer());
317 _processId = pImpl->Launch(_path, pArg);
319 SysTryReturnResult(NID_APP, _processId >= 0, GetLastResult(), "Launching(%ls) is failed", _path.GetPointer());
321 SysLog(NID_APP, "Exit");
327 _AppControlImpl::StartOsp(const String* pUriData, const String* pMimeType, const IMap* pDataList, IAppControlResponseListener* pListener)
329 SysLog(NID_APP, "Enter");
330 result r = E_SUCCESS;
332 _AppArg* pArg = new (std::nothrow) _AppArg;
333 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
335 pArg->Construct(*this, pUriData, pMimeType, pDataList);
337 _AppControlManager* pImpl = _AppControlManager::GetInstance();
338 int req = _REQ_ID_INVALID;
342 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCb, pListener, _property);
343 req = reqObj.GetRequestNumber();
345 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
347 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
348 if (pAppControlResponseEvent != null)
350 r = pAppControlResponseEvent->Construct();
351 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
353 r = pAppControlResponseEvent->AddListener(*this, true);
354 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
356 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = pImpl->GetAppControlResponseEventContainer();
357 if (pResponseEventContainer != null)
359 pResponseEventContainer->Add(req, pAppControlResponseEvent);
360 __appControlResponseEventList.Add(req);
361 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", req);
366 _processId = pImpl->Launch(_path, pArg, req);
371 SysLog(NID_APP, "[%s]Launching(%ls) is failed" , GetErrorMessage(r), _path.GetPointer());
377 _processId = pImpl->Launch(_path, pArg);
379 SysTryReturnResult(NID_APP, _processId >= 0, GetLastResult(), "Launching(%ls) is failed", _path.GetPointer());
381 SysLog(NID_APP, "Exit");
387 _AppControlImpl::StartImplicit(bundle* pBundle, const IList* pDataList, IAppControlEventListener* pListener)
389 SysLog(NID_APP, "Enter");
390 result r = E_SUCCESS;
392 _AppArg* pArg = new (std::nothrow) _AppArg;
393 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
395 pArg->Construct(pBundle);
397 _AppMessageImpl::AddData(pArg->GetBundle(), pDataList);
399 _AppControlManager* pImpl = _AppControlManager::GetInstance();
400 int req = _REQ_ID_INVALID;
404 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCbLegacy, pListener, _APPCONTROL_PROPERTY_NONE);
405 req = reqObj.GetRequestNumber();
407 r = pImpl->LaunchAppImplicit(pArg, req);
408 SysTryCatch(NID_APP, r == E_SUCCESS, reqObj.Invalidate(), r, "[%s] Propagating." , GetErrorMessage(r));
412 r = pImpl->LaunchAppImplicit(pArg, -1);
416 // [FIXME] launch registration is not working correctly
417 SysLog(NID_APP, "Exit");
424 _AppControlImpl::StartImplicit(bundle* pBundle, const IMap* pData, IAppControlResponseListener* pListener)
426 SysLog(NID_APP, "Enter");
427 result r = E_SUCCESS;
429 _AppArg* pArg = new (std::nothrow) _AppArg;
430 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Argument allocation failure.");
432 pArg->Construct(pBundle);
434 _AppArg::AddStrMap(pArg->GetBundle(), pData);
436 _AppControlManager* pImpl = _AppControlManager::GetInstance();
437 int req = _REQ_ID_INVALID;
441 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pImpl, pArg, AppControlCb, pListener, _APPCONTROL_PROPERTY_NONE);
442 req = reqObj.GetRequestNumber();
444 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
446 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
448 if (pAppControlResponseEvent != null)
450 r = pAppControlResponseEvent->Construct();
451 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
453 r = pAppControlResponseEvent->AddListener(*pImpl, true);
454 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
456 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = pImpl->GetAppControlResponseEventContainer();
457 if (pResponseEventContainer != null)
459 pResponseEventContainer->Add(req, pAppControlResponseEvent);
460 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", req);
464 r = pImpl->LaunchAppImplicit(pArg, req);
465 SysTryCatch(NID_APP, r == E_SUCCESS, reqObj.Invalidate(), r, "[%s] Propagating." , GetErrorMessage(r));
469 r = pImpl->LaunchAppImplicit(pArg, -1);
472 SysLog(NID_APP, "Exit");
474 // [FIXME] launch registration is not working correctly
482 _AppControlImpl::AppControlCbLegacy(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int reqId)
484 SysLog(NID_APP, "Result value %d", res);
486 SysTryReturnResult(NID_APP, data && pResArg && pArg, E_SYSTEM, "Invalid result (callback, result, arg) = (0x%x, 0x%x, 0x%x).",
490 bundle* b = pResArg->GetBundle();
491 SysTryReturnResult(NID_APP, b != NULL, E_SYSTEM, "Invalid result bundle.");
493 IAppControlEventListener* pListener = static_cast<IAppControlEventListener*>(data);
494 SysTryReturnResult(NID_APP, pListener == null || typeid(pListener) == typeid(IAppControlEventListener*), E_SYSTEM, "Invalid result callback");
496 bundle* inb = pArg->GetBundle();
497 SysTryReturnResult(NID_APP, inb != NULL, E_SYSTEM, "Empty caller bundle.");
501 AppId provider = pResArg->GetCalleeAppId();
503 const char* p = appsvc_get_operation(inb);
509 SysLog(NID_APP, "Invoking callback with (%ls, %ls)", provider.GetPointer(), oId.GetPointer());
511 if (prop & _APPCONTROL_PROPERTY_ALIAS)
513 const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
514 pEntry = _AppControlRegistry::GetInstance()->GetReverseAppControlAliasEntry(provider, oId);
517 provider = pEntry->provider;
518 oId = pEntry->operation;
520 SysLog(NID_APP, "Legacy AppControl(%ls, %ls).", provider.GetPointer(), oId.GetPointer());
524 if (prop & _APPCONTROL_PROPERTY_APPID_CHANGE)
526 String tmp = _AppControlRegistry::GetInstance()->GetReverseAliasAppId(provider);
529 SysLog(NID_APP, "App change (%ls -> %ls).", provider.GetPointer(), tmp.GetPointer());
535 const bool isSubMode = _AppArg::IsSubMode(b);
536 const bool isServiceCallee = _AppArg::IsServiceApp(b);
538 std::unique_ptr<HashMap> pMap(pResArg->GetArgMapN());
540 ArrayList list(SingleObjectDeleter);
541 _AppArg::FillLegacyAppControlResult(list, res, pMap.get(), provider);
543 _AppControlManager::InvokeLegacyAppControlCompleteListener(*pListener, provider, oId, &list, isSubMode | isServiceCallee);
549 _AppControlImpl::AppControlCb(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int reqId)
551 SysLog(NID_APP, "Result value : %d, property : 0x%x", res, prop);
553 SysTryReturnResult(NID_APP, data && pResArg && pArg, E_SYSTEM, "Invalid result (callback, result, arg) = (0x%x, 0x%x, 0x%x).",
557 bundle* b = pResArg->GetBundle();
558 SysTryReturnResult(NID_APP, b != NULL, E_SYSTEM, "Invalid result bundle.");
560 IAppControlResponseListener* pListener = static_cast<IAppControlResponseListener*>(data);
561 SysTryReturnResult(NID_APP, pListener == null || typeid(pListener) == typeid(IAppControlResponseListener*), E_SYSTEM, "Invalid result callback");
563 bundle* inb = pArg->GetBundle();
564 SysTryReturnResult(NID_APP, inb != NULL, E_SYSTEM, "Empty caller bundle.");
568 AppId provider = pResArg->GetCalleeAppId();
570 const char* p = appsvc_get_operation(inb);
576 SysLog(NID_APP, "Invoking callback with (%ls, %ls)", provider.GetPointer(), oId.GetPointer());
578 if (prop & _APPCONTROL_PROPERTY_ALIAS)
580 const _AppControlRegistry::_AppControlAliasEntry* pEntry = null;
581 pEntry = _AppControlRegistry::GetInstance()->GetReverseRuntimeAliasEntry(provider, oId);
584 provider = pEntry->provider;
585 oId = pEntry->operation;
587 SysLog(NID_APP, "Original AppControl(%ls, %ls).", provider.GetPointer(), oId.GetPointer());
591 if (prop & _APPCONTROL_PROPERTY_APPID_CHANGE)
593 String tmp = _AppControlRegistry::GetInstance()->GetReverseAliasAppId(provider);
596 SysLog(NID_APP, "App change (%ls -> %ls).", provider.GetPointer(), tmp.GetPointer());
602 const bool isSubMode = _AppArg::IsSubMode(b);
603 const bool isServiceCallee = _AppArg::IsServiceApp(b);
605 std::unique_ptr<HashMap> pMap(pResArg->GetArgMapN());
607 AppCtrlResult ret = _AppControlManager::ConvertAppControlResultCode(res);
609 SysLog(NID_APP, "Result code : 0x%x.", ret);
611 // proper callback invokation
612 _AppControlResponseEvent* pResponseEvent = null;
613 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(reqId, pResponseEvent);
615 if (pResponseEvent != null)
617 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, provider, oId, E_SUCCESS, ret, pMap.release(), reqId, isSubMode | isServiceCallee);
618 pResponseEvent->Fire(*pResponseEventArg);
619 SysLog(NID_APP, "OnAppControlCompleteResponseReceived, pResponseEvent is Fired");
623 _AppControlManager::InvokeAppControlCompleteListener(*pListener, provider, oId, ret, pMap.get(), isSubMode | isServiceCallee);
630 _AppControlImpl::StartNative(const IList* pDataList, IAppControlEventListener* pListener)
632 SysLog(NID_APP, "Enter");
633 _InProcessInfo* pInfo = _AppControlManager::GetInstance()->__inAppManager.FindItem(_reqId);
634 SysTryReturnResult(NID_APP, pInfo == null, E_IN_PROGRESS, "Request ID %d is already in progress.", _reqId);
636 int req = _REQ_ID_INVALID;
638 _IAppControlPluginProvider* pProvider = GetAppControlPluginProvider(_path);
639 SysTryReturnResult(NID_APP, pProvider != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Propagating.");
643 _InProcessInfo* pItem = new (std::nothrow) _InProcessInfo(_provider, _opId, _property, true, pProvider, pListener);
646 req = _AppControlManager::GetInstance()->__inAppManager.InsertItem(pItem);
650 result r = InvokeStartAppControl(pProvider, req, _provider, _opId, pDataList);
652 if (pListener == null)
654 pProvider->Release();
657 // after acquring request number, pLib should be managed from the list, not CATCH
660 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(req);
661 SysLog(NID_APP, "[%s] A system error has occurred.", GetErrorMessage(r));
668 SysLog(NID_APP, "Exit %d", req);
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 result r = E_SUCCESS;
682 _IAppControlPluginProvider* pProvider = GetAppControlPluginProvider(_path);
683 SysTryReturnResult(NID_APP, pProvider != null, E_OBJ_NOT_FOUND, "Propagating.");
687 _InProcessInfo* pItem = new (std::nothrow) _InProcessInfo(_provider, _opId, _property, false, pProvider, pListener);
690 req = _AppControlManager::GetInstance()->__inAppManager.InsertItem(pItem);
693 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
695 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
697 if (pAppControlResponseEvent != null)
699 r = pAppControlResponseEvent->Construct();
700 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
702 r = pAppControlResponseEvent->AddListener(*this, true);
703 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
705 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = _AppControlManager::GetInstance()->GetAppControlResponseEventContainer();
706 if (pResponseEventContainer != null)
708 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + req;
709 pResponseEventContainer->Add(responseEventRequestId, pAppControlResponseEvent);
710 __appControlResponseEventList.Add(responseEventRequestId);
711 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", responseEventRequestId);
716 r = InvokeStartAppControl(pProvider, req, _provider, _opId, pUriData, pMimeType, pDataList);
718 if (pListener == null)
720 pProvider->Release();
723 // after acquring request number, pLib should be managed from the list, not CATCH
726 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(req);
727 SysLog(NID_APP, "[%s] A system error has occurred.", GetErrorMessage(r));
733 SysLog(NID_APP, "Exit %d", req);
739 _AppControlImpl::InvokeStartAppControl(_IAppControlPluginProvider* pProvider, int req, const String& appId, const String& oId, const IList* pList)
741 SysLog(NID_APP, "Legacy stuff for converting argument");
743 HashMap map(SingleObjectDeleter);
744 HashMap* pMap = null;
749 _AppArg::FillMapFromList(&map, pList);
754 return InvokeStartAppControl(pProvider, req, appId, oId, null, null, pMap);
759 _AppControlImpl::InvokeStartAppControl(_IAppControlPluginProvider* pProvider, int req, const String& appId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
761 SysTryReturnResult(NID_APP, pProvider != null, E_SYSTEM, "Wrong AppControl provider plugin for %ls, %ls (%d).", appId.GetPointer(), oId.GetPointer(), req);
763 _AppMessageImpl msg(appId, oId, pUri, pMime, pMap);
764 return pProvider->StartAppControlPlugin(req, appId, msg, null);
768 IsValidAppControl(const String& appcontrolID)
770 return ((appcontrolID == L"osp.appcontrol.provider.audio")
771 || (appcontrolID == L"osp.appcontrol.provider.bluetooth")
772 || (appcontrolID == L"osp.appcontrol.provider.calendar")
773 || (appcontrolID == L"osp.appcontrol.provider.camera")
774 || (appcontrolID == L"osp.appcontrol.provider.contact")
775 || (appcontrolID == L"osp.appcontrol.provider.certificatemanager")
776 || (appcontrolID == L"osp.appcontrol.provider.email")
777 || (appcontrolID == L"osp.appcontrol.provider.image")
778 || (appcontrolID == L"osp.appcontrol.provider.media")
779 || (appcontrolID == L"osp.appcontrol.provider.message")
780 || (appcontrolID == L"osp.appcontrol.provider.video")
781 || (appcontrolID == L"osp.appcontrol.provider.imageeditor")
782 || (appcontrolID == L"osp.appcontrol.provider.allshare")
783 || (appcontrolID == L"tizen.filemanager")
784 || (appcontrolID == L"tizen.camera")
785 || (appcontrolID == L"tizen.gallery")
786 || (appcontrolID == L"tizen.imageviewer")
787 || (appcontrolID == L"tizen.videoplayer")
788 || (appcontrolID == L"tizen.memo")
789 || (appcontrolID == L"tizen.contacts")
790 || (appcontrolID == L"tizen.calendar")
791 || (appcontrolID == L"tizen.todo")
792 || (appcontrolID == L"tizen.email")
793 || (appcontrolID == L"tizen.settings")
794 || (appcontrolID == L"tizen.messages")
795 || (appcontrolID == L"tizen.musicplayer")
796 || (appcontrolID == L"tizen.bluetooth")
797 || (appcontrolID == L"samsung.snote")
798 || (appcontrolID == L"0pnxz8hbsr.MyFiles")
799 || (appcontrolID == L"hdufar9ycj.Camera")
800 || (appcontrolID == L"ijudt7w61q.Gallery")
801 || (appcontrolID == L"jysyv9o1dc.ImageViewer")
802 || (appcontrolID == L"npwf0scb88.VideoPlayer")
803 || (appcontrolID == L"zunqjlsnce.Memo")
804 || (appcontrolID == L"f9uev8hsyo.Contacts")
805 || (appcontrolID == L"ph1vq2phrp.Calendar")
806 || (appcontrolID == L"vxqbrefica.Email")
807 || (appcontrolID == L"kto5jikgul.Settings")
808 || (appcontrolID == L"8r4r5ddzzn.Messages")
809 || (appcontrolID == L"dhrul6qzj3.MusicPlayer")
810 || (appcontrolID == L"smemo-efl"));
814 _AppControlImpl::Stop(void)
816 const String appcontrolID(GetAppControlProviderId());
817 SysTryReturnResult(NID_APP, IsValidAppControl(appcontrolID), E_INVALID_OPERATION, "Invalid appcontrolID(%ls)", appcontrolID.GetPointer());
819 if (_property & _APPCONTROL_PROPERTY_SLP)
821 result (*pStop)(int req) = null;
823 if (_reqId != _REQ_ID_INVALID)
825 _InProcessInfo* pInfo = _AppControlManager::GetInstance()->__inAppManager.FindItem(_reqId);
826 SysTryReturnResult(NID_APP, pInfo != null, E_INVALID_OPERATION, "Request ID %d is not found.", _reqId);
828 if (pInfo->pProvider)
830 pInfo->pProvider->StopAppControlPlugin(_reqId);
833 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(_reqId);
835 _reqId = _REQ_ID_INVALID;
839 _IAppControlPluginProvider* pProvider = GetAppControlPluginProvider(_path);
842 pProvider->StopAppControlPlugin(_reqId);
843 SysLog(NID_APP, "Request %d is stopped.", _reqId);
845 pProvider->Release();
849 else if (_property & _APPCONTROL_PROPERTY_OSP)
851 _Aul::TerminateApplicationByPid(_processId);
858 _AppControlImpl::GetAppName(void)
860 if (_appName.IsEmpty())
862 AppId appId = GetAppId();
863 AppId aliasAppId = _AppControlRegistry::GetInstance()->GetAliasAppId(appId);
864 if (!aliasAppId.IsEmpty())
869 std::unique_ptr<PackageAppInfo> pInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
872 SysLog(NID_APP, "PackageInfo of appId(%ls) exists", appId.GetPointer());
873 const String& name = pInfo->GetAppName();
874 if (name == L"_AppControl")
876 // workaround for special case: requery with actual appId
877 const PackageId& packageId = _PackageManagerImpl::GetPackageIdByAppId(appId);
878 const String& defaultName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
880 const String& convertedAppId = packageId + L'.' + defaultName;
882 std::unique_ptr<PackageAppInfo> pNewInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(convertedAppId));
886 _appName = pNewInfo->GetAppDisplayName();
890 SysLog(NID_APP, "No default applicaiton information, possible database error.");
895 _appName = pInfo->GetAppDisplayName();
900 SysLog(NID_APP, "PackageInfo of appId(%ls) does not exist", appId.GetPointer());
908 _AppControlImpl::GetAppId(void) const
910 return (_property & _APPCONTROL_PROPERTY_OSP) ? _path : _provider;
914 _AppControlImpl::GetAppControlProviderId(void) const
920 _AppControlImpl::GetOperationId(void) const
926 _AppControlImpl::GetCategoryListN(void) const
928 AppId appId = GetAppId();
929 SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_SYSTEM, "[E_SYSTEM] Empty appId.");
931 AppId aliasAppId = _AppControlRegistry::GetInstance()->GetAliasAppId(appId);
932 if (!aliasAppId.IsEmpty())
937 SysLog(NID_APP, "Acquiring category for app %ls.", appId.GetPointer());
939 std::unique_ptr<PackageAppInfo> pAppInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
940 SysTryReturn(NID_APP, pAppInfo.get() != null, null, E_SYSTEM, "[E_SYSTEM] Getting PackageAppInfo failed.");
942 return pAppInfo->GetAppCategoryListN();
946 _AppControlImpl::StopAppControlResponseListener(IAppControlResponseListener* pListener)
948 _AppControlManager::GetInstance()->StopAppControlResponseListener(pListener);
952 _AppControlImpl::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
954 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
956 if (pEventArg != null)
958 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
960 if(pResponseListener != null)
962 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_COMPLETE)
964 _AppControlManager::InvokeAppControlCompleteListener(*pResponseListener, pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData(), pEventArg->IsSubMode());
966 _AppControlResponseEvent* pResponseEvent = null;
967 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
968 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
969 delete pResponseEvent;
970 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
974 SysLog(NID_APP, "Unexpected AppControlResponseType(%d)", pEventArg->GetType());
979 SysLog(NID_APP, "Invalid ResponseListener");
984 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);