//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
#include "FAppPkg_PackageInfoImpl.h"
#include "FApp_AppControlManager.h"
#include "FApp_Aul.h"
+#include "FSys_SystemInfoImpl.h"
using namespace Tizen::App::Package;
using namespace Tizen::Base;
using namespace Tizen::Base::Utility;
using namespace Tizen::Io;
-//extern const char* _DATACONTROL_RESULTSET_DIR;
-
namespace
{
{
if (__pConditionManager == null)
{
+ const int MAX_TRY_COUNT = 5;
+ const int TRY_SLEEP_TIME = 250;
+
__pConditionManager = new (std::nothrow) _ConditionManagerProxy;
SysAssert(__pConditionManager != null);
- result r = __pConditionManager->Construct();
- SysAssertf(r == E_SUCCESS, "__pConditionManager->Construct() faliied [%s].", GetErrorMessage(r));
+ int count = 0;
+ while (true)
+ {
+ result r = __pConditionManager->Construct();
+ if (r == E_SUCCESS)
+ {
+ SysLog(NID_APP, "Succeeded in connecting condition manager.");
+ break;
+ }
+
+ if (count >= MAX_TRY_COUNT)
+ {
+ SysLog(NID_APP, "Failed to connecting condition manager.");
+ break;
+ }
+
+ count++;
+ Thread::Sleep(TRY_SLEEP_TIME);
+ }
}
return __pConditionManager;
AppControl* pAc = null;
- /*
pAc = pRegs->GetTizenAppControlN(aId, oId);
if (pAc != null)
{
SetLastResult(E_SUCCESS);
return pAc;
}
- */
-
- pAc = pRegs->GetNativeAppControlN(aId, oId);
- if (pAc != null)
- {
- SetLastResult(E_SUCCESS);
- return pAc;
- }
-
- pAc = pRegs->GetAliasAppControlN(aId, oId);
- if (pAc != null)
- {
- SetLastResult(E_SUCCESS);
- return pAc;
- }
pAc = pRegs->GetAppControlN(aId, oId);
GetErrorMessage(E_INVALID_FORMAT));
}
- ArrayList* pRetArg = null;
- pRetArg = new (std::nothrow) ArrayList();
- SysTryReturn(NID_APP, pRetArg != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
- GetErrorMessage(E_OUT_OF_MEMORY));
-
- pRetArg->Construct();
-
_AppControlRegistry* pRegs = _AppControlRegistry::GetInstance();
-
- pRetArg = pRegs->FindAppControlListN(pOperationId, pUriScheme, pMimeType, pCategory);
+ ArrayList* pRetArg = pRegs->FindAppControlListN(pOperationId, pUriScheme, pMimeType, pCategory);
if ((pRetArg == null) || (pRetArg->GetCount() == 0))
{
{
String pkgId = PackageManager::GetPackageIdByAppId(appId);
SysTryReturnResult(NID_APP, pkgId.IsEmpty() == false, E_APP_NOT_INSTALLED,
- "The application is not installed. (appId: %ls)", appId.GetPointer());
+ "The application is not installed. (app: %ls)", appId.GetPointer());
_PackageManagerImpl* pPkgMgr = _PackageManagerImpl::GetInstance();
SysTryReturnResult(NID_APP, pPkgMgr != null, E_SYSTEM,
std::unique_ptr< PackageInfo >pPkgInfo(pPkgMgr->GetPackageInfoN(pkgId));
SysTryReturnResult(NID_APP, pPkgInfo != null, E_APP_NOT_INSTALLED,
- "The application is not installed. (appId: %ls)", appId.GetPointer());
+ "The application is not installed. (app: %ls)", appId.GetPointer());
_PackageInfoImpl* pPkgInfoImpl = _PackageInfoImpl::GetInstance(pPkgInfo.get());
SysTryReturnResult(NID_APP, pPkgInfoImpl != null, E_SYSTEM,
// "The length of appid exceeded the limit(%d).",
// WIDGET_APP_MAX_APPID_LENGTH);
- AppControl* pAc = _AppControlRegistry::GetInstance()->GetAppControlN(appId, TIZEN_OPERATION_MAIN);
- SysTryReturnResult(NID_APP, pAc != null, E_OBJ_NOT_FOUND, "The target application (%ls) is not found.", appId.GetPointer());
+ std::unique_ptr<AppControl> pAc(_AppControlRegistry::GetInstance()->GetAppControlN(appId, TIZEN_OPERATION_MAIN));
+ SysTryReturnResult(NID_APP, pAc.get() != null, E_OBJ_NOT_FOUND, "The target application (%ls) is not found.", appId.GetPointer());
if (pArguments)
{
_ConditionManagerProxy* pProxy = GetConditionManagerProxy();
SysTryReturnResult(NID_APP, null != pProxy, E_INVALID_STATE, "ConditionManager instance must not be null.");
+ Tizen::Base::Utility::StringTokenizer strTok(condition, L"=");
+ SysTryReturnResult(NID_APP, strTok.GetTokenCount() > 0, E_INVALID_ARG, "Condition string is invalid.(%ls)", condition.GetPointer());
+
+ String key;
+ result r = strTok.GetNextToken(key);
+ SysTryReturnResult(NID_APP, !IsFailed(r), E_INVALID_ARG, "Condition string is invalid.(%ls)", condition.GetPointer());
+
+ bool ret = true;
+ if (key == L"Serial")
+ {
+ r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/usb.accessory", ret);
+ }
+ else if (key == L"NFC")
+ {
+ r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.nfc", ret);
+ }
+ SysTryReturnResult(NID_APP, ret != false, E_UNSUPPORTED_OPERATION, "Condition(%ls)", condition.GetPointer());
+
return pProxy->RegisterAppLaunch(appId, condition, pArguments, option);
}
result
_AppManagerImpl::OnServiceEventReceived(int clientId, const _AppManagerEventArg& arg)
{
- SysLog(NID_APP, "appId:%ls, appType:0x%x", arg.GetAppId().GetPointer(), arg.GetAppType());
+ SysLog(NID_APP, "app:%ls, appType:0x%x", arg.GetAppId().GetPointer(), arg.GetAppType());
_AppManagerEventArg* pArg = new (std::nothrow)_AppManagerEventArg(arg);
SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
int ret = aul_app_get_appid_bypid(pid, appId, sizeof(appId));
if (ret != AUL_R_OK)
{
- SysLogException(NID_APP, E_SYSTEM, "Cannot acquire appId.");
+ SysLogException(NID_APP, E_SYSTEM, "Cannot acquire app for %d.", pid);
return -1;
}
result r = pImpl->__map.GetValue(pid, tmp);
if (r != E_SUCCESS)
{
- SysLogException(NID_APP, E_SYSTEM, "Cannot acquire appId from pid %d.", pid);
+ SysLog(NID_APP, "Cannot acquire app from pid %d.", pid);
return -1;
}
+ pImpl->__map.Remove(pid);
+
std::unique_ptr< IEnumeratorT<_IAppEventListener*> > pEnum(pImpl->__pEventList->GetEnumeratorN());
if (pEnum.get())
{
if (oldPid != pid)
{
oldPid = pid;
+ char pkgname[255] = {0, };
+ if ((AUL_R_OK != aul_app_get_pkgname_bypid(pid, pkgname, 255)) || pkgname[0] == 0)
+ {
+ SysSecureLog(NID_APP, "Failed to get the package name from pid=%x pAppName=%s", pid, pAppName ? pAppName : "null");
+ return;
+ }
+ AppId appId(_Aul::GetRealAppId(String(pkgname)));
+
std::unique_ptr<IEnumeratorT<Tizen::App::IActiveAppEventListener* > > pEnum(__activeAppEventListenerList.GetEnumeratorN());
if (pEnum.get())
{
pEnum->GetCurrent(pListener);
if (pListener)
{
- char pkgname[255] = {0, };
- aul_app_get_pkgname_bypid(pid, pkgname, 255);
- // TODO: Translate it to package name --> AppId
- pListener->OnActiveAppChanged(AppId(pkgname));
+ pListener->OnActiveAppChanged(appId);
}
}
}
result
_AppManagerImpl::GetActiveApp(AppId& appId)
{
- unsigned int windowId = GetActiveWindow();
- int processId = GetProcessId(windowId);
+ const unsigned int windowId = GetActiveWindow();
+ const int processId = GetProcessId(windowId);
char pkgname[255] = {0, };
aul_app_get_pkgname_bypid(processId, pkgname, 255);
- // TODO: Translate it to package name --> AppId
- appId = pkgname;
+
+ appId = _Aul::GetRealAppId(String(pkgname));
+
+ SysLog(NID_APP, "ActiveApp is %ls.", appId.GetPointer());
return E_SUCCESS;
}
+bool
+_AppManagerImpl::IsUserPreferredAppForAppControlResolution(const AppId& appId) const
+{
+ _IAppManager* pMgr = _AppManagerProxy::GetService();
+ SysTryReturn(NID_APP, pMgr, false, E_SYSTEM, "Failed to _AppManagerProxy::GetService().");
+
+ return pMgr->IsUserPreferredAppForAppControlResolution(appId);
+}
+
+result
+_AppManagerImpl::ClearUserPreferenceForAppControlResolution(const AppId& appId)
+{
+ _IAppManager* pMgr = _AppManagerProxy::GetService();
+ SysTryReturnResult(NID_APP, pMgr, E_SYSTEM, "Failed to _AppManagerProxy::GetService().");
+
+ return pMgr->ClearUserPreferenceForAppControlResolution(appId);
+}
+
}} // Tizen::App