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 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(req);
648 SysLog(NID_APP, "[%s] A system error has occurred.", GetErrorMessage(r));
655 SysLog(NID_APP, "Exit");
663 case E_LIBRARY_NOT_FOUND:
675 _AppControlImpl::StartNative(const String* pUriData, const String* pMimeType, const IMap* pDataList, IAppControlResponseListener* pListener)
677 SysLog(NID_APP, "Enter");
678 _InProcessInfo* pInfo = _AppControlManager::GetInstance()->__inAppManager.FindItem(_reqId);
679 SysTryReturnResult(NID_APP, pInfo == null, E_IN_PROGRESS, "Request ID %d is already in progress.", _reqId);
681 int req = _REQ_ID_INVALID;
682 _LibraryImpl* pLib = null;
684 pLib = new (std::nothrow) _LibraryImpl;
685 SysTryReturnResult(NID_APP, pLib != null, E_OUT_OF_MEMORY, "Failed to allocate libraryimpl.");
687 unsigned long option = _LIBRARY_LOAD_OPTION_LAZY;
688 option |= _LIBRARY_LOAD_OPTION_NODELETE;
690 result r = pLib->Construct(_path, option);
692 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
696 _InProcessInfo* pItem = new (std::nothrow) _InProcessInfo(_provider, _opId, _property, false, *pLib, pListener);
699 req = _AppControlManager::GetInstance()->__inAppManager.InsertItem(pItem);
702 if (_ThreadImpl::GetCurrentThreadImpl()->GetThreadType() == THREAD_TYPE_EVENT_DRIVEN)
704 _AppControlResponseEvent* pAppControlResponseEvent = new (std::nothrow) _AppControlResponseEvent();
706 if (pAppControlResponseEvent != null)
708 r = pAppControlResponseEvent->Construct();
709 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::Construct() is failed", GetErrorMessage(r));
711 r = pAppControlResponseEvent->AddListener(*this, true);
712 SysTryLog(NID_APP, r == E_SUCCESS, "[%s]_AppControlResponseEvent::AddListener() is failed", GetErrorMessage(r));
714 IMapT<int, _AppControlResponseEvent*>* pResponseEventContainer = _AppControlManager::GetInstance()->GetAppControlResponseEventContainer();
715 if (pResponseEventContainer != null)
717 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + req;
718 pResponseEventContainer->Add(responseEventRequestId, pAppControlResponseEvent);
719 __appControlResponseEventList.Add(responseEventRequestId);
720 SysLog(NID_APP, "pResponseEvent gets added. reqId(%d)", responseEventRequestId);
725 r = InvokeStartAppControl(*pLib, req, _provider, _opId, pUriData, pMimeType, pDataList);
727 if (pListener == null)
732 // after acquring request number, pLib should be managed from the list, not CATCH
735 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(req);
736 SysLog(NID_APP, "[%s] A system error has occurred.", GetErrorMessage(r));
742 SysLog(NID_APP, "Exit");
751 case E_LIBRARY_NOT_FOUND:
763 _AppControlImpl::InvokeStartAppControl(_LibraryImpl& lib, int req, const String& appId, const String& oId, const IList* pList)
765 SysLog(NID_APP, "Legacy stuff for converting argument");
767 HashMap map(SingleObjectDeleter);
768 HashMap* pMap = null;
773 _AppArg::FillMapFromList(&map, pList);
778 return InvokeStartAppControl(lib, req, appId, oId, null, null, pMap);
783 _AppControlImpl::InvokeStartAppControl(_LibraryImpl& lib, int req, const String& appId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
785 result (*pFunc)(int req, const String&, const String&, const String*, const String*, const IMap*) = null;
788 reinterpret_cast<result (*)(int, const String&, const String&, const String*, const String*, const IMap*)>(lib.GetProcAddress(L"StartAppControl"));
789 SysTryReturnResult(NID_APP, pFunc != null, E_OBJ_NOT_FOUND, "Entry \"StartAppControl\" not found for %ls", appId.GetPointer());
791 const String* pActualUri = (pUri && !(pUri->IsEmpty())) ? pUri : null;
792 const String* pActualMime = (pMime && !(pMime->IsEmpty())) ? pMime : null;
793 return (*pFunc)(req, appId, oId, pActualUri, pActualMime, pMap);
797 IsValidAppControl(const String& appcontrolID)
799 return ((appcontrolID == L"osp.appcontrol.provider.audio")
800 || (appcontrolID == L"osp.appcontrol.provider.bluetooth")
801 || (appcontrolID == L"osp.appcontrol.provider.calendar")
802 || (appcontrolID == L"osp.appcontrol.provider.camera")
803 || (appcontrolID == L"osp.appcontrol.provider.contact")
804 || (appcontrolID == L"osp.appcontrol.provider.certificatemanager")
805 || (appcontrolID == L"osp.appcontrol.provider.email")
806 || (appcontrolID == L"osp.appcontrol.provider.image")
807 || (appcontrolID == L"osp.appcontrol.provider.media")
808 || (appcontrolID == L"osp.appcontrol.provider.message")
809 || (appcontrolID == L"osp.appcontrol.provider.video")
810 || (appcontrolID == L"osp.appcontrol.provider.imageeditor")
811 || (appcontrolID == L"osp.appcontrol.provider.allshare")
812 || (appcontrolID == L"tizen.filemanager")
813 || (appcontrolID == L"tizen.camera")
814 || (appcontrolID == L"tizen.gallery")
815 || (appcontrolID == L"tizen.imageviewer")
816 || (appcontrolID == L"tizen.videoplayer")
817 || (appcontrolID == L"tizen.memo")
818 || (appcontrolID == L"tizen.contacts")
819 || (appcontrolID == L"tizen.calendar")
820 || (appcontrolID == L"tizen.todo")
821 || (appcontrolID == L"tizen.email")
822 || (appcontrolID == L"tizen.settings")
823 || (appcontrolID == L"tizen.messages")
824 || (appcontrolID == L"tizen.musicplayer")
825 || (appcontrolID == L"tizen.bluetooth")
826 || (appcontrolID == L"samsung.snote")
827 || (appcontrolID == L"0pnxz8hbsr.MyFiles")
828 || (appcontrolID == L"hdufar9ycj.Camera")
829 || (appcontrolID == L"ijudt7w61q.Gallery")
830 || (appcontrolID == L"jysyv9o1dc.ImageViewer")
831 || (appcontrolID == L"npwf0scb88.VideoPlayer")
832 || (appcontrolID == L"zunqjlsnce.Memo")
833 || (appcontrolID == L"f9uev8hsyo.Contacts")
834 || (appcontrolID == L"ph1vq2phrp.Calendar")
835 || (appcontrolID == L"vxqbrefica.Email")
836 || (appcontrolID == L"kto5jikgul.Settings")
837 || (appcontrolID == L"8r4r5ddzzn.Messages")
838 || (appcontrolID == L"dhrul6qzj3.MusicPlayer")
839 || (appcontrolID == L"smemo-efl"));
843 _AppControlImpl::Stop(void)
845 const String appcontrolID(GetAppControlProviderId());
846 SysTryReturnResult(NID_APP, IsValidAppControl(appcontrolID), E_INVALID_OPERATION, "Invalid appcontrolID(%ls)", appcontrolID.GetPointer());
848 if (_property & _APPCONTROL_PROPERTY_SLP)
850 SysTryReturnResult(NID_APP, _reqId != _REQ_ID_INVALID, E_INVALID_OPERATION, "Invalid request ID .");
852 _InProcessInfo* pInfo = _AppControlManager::GetInstance()->__inAppManager.FindItem(_reqId);
853 SysTryReturnResult(NID_APP, pInfo != null, E_INVALID_OPERATION, "Request ID %d is not found.", _reqId);
855 result (*pStop)(int req) = null;
856 pStop = reinterpret_cast<result (*)(int)>(pInfo->pLib->GetProcAddress(L"TerminateAppControl"));
857 SysTryReturnResult(NID_APP, pStop != null, E_SYSTEM, "No TerminateAppControl() function.");
861 _AppControlManager::GetInstance()->__inAppManager.RemoveItem(_reqId);
863 _reqId = _REQ_ID_INVALID;
865 else if (_property & _APPCONTROL_PROPERTY_OSP)
867 _Aul::TerminateApplicationByPid(_processId);
874 _AppControlImpl::GetAppName(void)
876 if (_appName.IsEmpty())
878 AppId appId = GetAppId();
879 AppId aliasAppId = _AppControlRegistry::GetInstance()->GetAliasAppId(appId);
880 if (!aliasAppId.IsEmpty())
885 std::unique_ptr<PackageAppInfo> pInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
888 SysLog(NID_APP, "PackageInfo of appId(%ls) exists", appId.GetPointer());
889 const String& name = pInfo->GetAppName();
890 if (name == L"_AppControl")
892 // workaround for special case: requery with actual appId
893 const PackageId& packageId = _PackageManagerImpl::GetPackageIdByAppId(appId);
894 const String& defaultName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
896 const String& convertedAppId = packageId + L'.' + defaultName;
898 std::unique_ptr<PackageAppInfo> pNewInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(convertedAppId));
902 _appName = pNewInfo->GetAppDisplayName();
906 SysLog(NID_APP, "No default applicaiton information, possible database error.");
911 _appName = pInfo->GetAppDisplayName();
916 SysLog(NID_APP, "PackageInfo of appId(%ls) does not exist", appId.GetPointer());
924 _AppControlImpl::GetAppId(void) const
926 return (_property & _APPCONTROL_PROPERTY_OSP) ? _path : _provider;
930 _AppControlImpl::GetAppControlProviderId(void) const
936 _AppControlImpl::GetOperationId(void) const
942 _AppControlImpl::GetCategoryListN(void) const
944 AppId appId = GetAppId();
945 SysTryReturn(NID_APP, !appId.IsEmpty(), null, E_SYSTEM, "[E_SYSTEM] Empty appId.");
947 AppId aliasAppId = _AppControlRegistry::GetInstance()->GetAliasAppId(appId);
948 if (!aliasAppId.IsEmpty())
953 SysLog(NID_APP, "Acquiring category for app %ls.", appId.GetPointer());
955 std::unique_ptr<PackageAppInfo> pAppInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
956 SysTryReturn(NID_APP, pAppInfo.get() != null, null, E_SYSTEM, "[E_SYSTEM] Getting PackageAppInfo failed.");
958 return pAppInfo->GetAppCategoryListN();
962 _AppControlImpl::StopAppControlResponseListener(IAppControlResponseListener* pListener)
964 _AppControlManager::GetInstance()->__listenerList.Add(pListener);
968 _AppControlImpl::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
970 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
972 if (pEventArg != null)
974 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
976 if(pResponseListener != null)
978 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_COMPLETE)
980 pResponseListener->OnAppControlCompleteResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData());
981 SysLog(NID_APP, "OnAppControlCompleteResponseReceived called");
983 _AppControlResponseEvent* pResponseEvent = null;
984 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
985 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
986 delete pResponseEvent;
987 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
991 SysLog(NID_APP, "Unexpected AppControlResponseType(%d)", pEventArg->GetType());
996 SysLog(NID_APP, "Invalid ResponseListener");
1001 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);