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 FAppAppManager.cpp
19 * @brief This is the implementation for the AppManager class.
24 #include <FBaseString.h>
25 #include <FBaseColIListT.h>
26 #include <FAppAppManager.h>
27 #include <FAppIAppControlListener.h>
28 #include <FAppSqlDataControl.h>
29 #include <FAppMapDataControl.h>
30 #include <FAppIAppCheckPointEventListener.h>
31 #include <FAppAppControlProviderManager.h>
32 #include <FAppIActiveAppEventListener.h>
33 #include <FBaseSysLog.h>
35 #include <FSec_AccessController.h>
36 #include "FApp_Types.h"
37 #include "FAppPkg_PackageManagerImpl.h"
38 #include "FApp_AppManagerImpl.h"
39 #include "FApp_AppImpl.h"
40 #include "FApp_AppInfo.h"
41 #include "FApp_AppArg.h"
43 #include "FApp_AppControlProviderManagerImpl.h"
44 #ifdef _SINGLETON_CLEANUP
45 #include "FApp_LongevityManager.h"
48 using namespace Tizen::App::Package;
49 using namespace Tizen::Base;
50 using namespace Tizen::Base::Collection;
51 using namespace Tizen::Base::Runtime;
52 using namespace Tizen::Io;
53 using namespace Tizen::Security;
55 namespace Tizen { namespace App
58 const long MAX_ARGUMENTS_SIZE = 1024;
61 AppManager::AppManager(void)
62 : __pAppManagerImpl(null)
68 AppManager::Construct(void)
72 SysAssertf(__pAppManagerImpl == null,
73 "Already constructed. Calling Construct() twice or more on a same in stance is not allowed for this class.");
75 __pAppManagerImpl = new (std::nothrow) _AppManagerImpl();
76 SysTryReturnResult(NID_APP, __pAppManagerImpl != null, E_OUT_OF_MEMORY, "");
78 r = __pAppManagerImpl->Construct();
81 SysPropagate(NID_APP, r);
88 delete __pAppManagerImpl;
89 __pAppManagerImpl = null;
95 AppManager::~AppManager(void)
97 delete __pAppManagerImpl;
102 AppManager::FindAppControlN(const AppId& appId, const String& operationId)
104 return _AppManagerImpl::FindAppControlN(appId, operationId);
109 AppManager::FindAppControlsN(const String* pOperationId, const String* pCategory, const String* pDataType, const String* pUriScheme)
111 return _AppManagerImpl::FindAppControlsN(pOperationId, pCategory, pDataType, pUriScheme);
116 AppManager::StartAppControl(const String& uri, const String* pOperationId,
117 const String* pDataType,
118 IAppControlListener* pListener)
120 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
121 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
123 return _AppManagerImpl::StartAppControl(uri, pOperationId, pDataType, pListener);
128 AppManager::StartAppControl(const String* pOperationId, const String* pCategory,
129 const String* pDataType, const String* pUriScheme,
130 const IList* pDataList,
131 IAppControlListener* pListener)
133 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
134 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
136 return _AppManagerImpl::StartAppControl(pOperationId, pCategory, pDataType, pUriScheme, pDataList, pListener);
140 AppManager::GetSqlDataControlN(const String& providerId)
142 return _AppManagerImpl::GetSqlDataControlN(providerId);
146 AppManager::GetMapDataControlN(const String& providerId)
148 return _AppManagerImpl::GetMapDataControlN(providerId);
152 AppManager::GetAppSharedPath(const AppId& appId)
156 result r = _AppManagerImpl::GetAppRootPath(appId, sharedPath);
157 SysTryReturn(NID_APP, !IsFailed(r), sharedPath, r, "[%s] Propagating to caller...", GetErrorMessage(r));
159 sharedPath.Append(L"shared/");
161 SetLastResult(E_SUCCESS);
166 AppManager::GetInstance(void)
168 result r = E_SUCCESS;
169 static AppManager* pAppMgr = null;
173 pAppMgr = new (std::nothrow) AppManager();
174 SysTryReturn(NID_APP, pAppMgr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppManager allocation failed.");
176 r = pAppMgr->Construct();
177 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] AppManager construction failed.", GetErrorMessage(r));
179 #ifdef _SINGLETON_CLEANUP
180 // [FIXME] temporary disable to resolve N_SE-23319, ImeApp cleanup issue
181 //_LongevityManager::GetInstance().RegisterOwnership(*pAppMgr);
195 AppManager::LaunchApplication(const AppId& appId, const IList* pArguments, LaunchOption option)
197 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
198 SysTryReturnResult(NID_APP, appId.GetLength() <= WIDGET_APP_MAX_APPID_LENGTH, E_MAX_EXCEEDED,
199 "The length of appid exceeded the limit(%d).", WIDGET_APP_MAX_APPID_LENGTH);
201 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
202 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
204 return __pAppManagerImpl->LaunchApplication(appId, pArguments, LAUNCH_OPTION_DEFAULT);
208 AppManager::LaunchApplication(const AppId& appId, LaunchOption option)
210 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
211 SysTryReturnResult(NID_APP, appId.GetLength() <= WIDGET_APP_MAX_APPID_LENGTH, E_MAX_EXCEEDED,
212 "The length of appid exceeded the limit(%d).", WIDGET_APP_MAX_APPID_LENGTH);
214 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
215 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
217 return __pAppManagerImpl->LaunchApplication(appId, LAUNCH_OPTION_DEFAULT);
221 AppManager::TerminateApplication(const AppId& appId)
223 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
224 SysTryReturnResult(NID_APP, appId.GetLength() <= WIDGET_APP_MAX_APPID_LENGTH, E_MAX_EXCEEDED,
225 "The length of appid exceeded the limit(%d).", WIDGET_APP_MAX_APPID_LENGTH);
227 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_KILL, _PRV_APPMANAGER_KILL);
228 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
230 return __pAppManagerImpl->TerminateApplication(appId);
234 AppManager::IsRunning(const AppId& appId) const
236 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
238 return __pAppManagerImpl->IsRunning(appId);
242 AppManager::GetRunningAppListN(void) const
244 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
246 return __pAppManagerImpl->GetRunningAppListN();
250 AppManager::RegisterAppLaunch(const String& condition, const IList* pArguments, LaunchOption option)
252 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
254 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
255 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
257 return __pAppManagerImpl->RegisterAppLaunch(L"", condition, pArguments, option);
261 AppManager::UnregisterAppLaunch(void)
263 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
265 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
266 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
268 return __pAppManagerImpl->UnregisterAppLaunch(L"", null);
272 AppManager::UnregisterAppLaunch(const String& condition)
274 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
276 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
277 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
279 return __pAppManagerImpl->UnregisterAppLaunch(L"", &condition);
283 AppManager::IsAppLaunchRegistered(void) const
285 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
287 return __pAppManagerImpl->IsAppLaunchRegistered(L"", null);
291 AppManager::RegisterAppLaunch(const AppId& appId, const String& condition, const IList* pArguments, LaunchOption option)
293 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
294 SysTryReturnResult(NID_APP, _Aul::IsInstalled(appId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
296 return __pAppManagerImpl->RegisterAppLaunch(appId, condition, pArguments, option);
301 AppManager::UnregisterAppLaunch(const AppId& appId, const String* pCondition)
303 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
304 SysTryReturnResult(NID_APP, _Aul::IsInstalled(appId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
306 return __pAppManagerImpl->UnregisterAppLaunch(appId, pCondition);
311 AppManager::IsAppLaunchRegistered(const AppId& appId, const String* pCondition) const
313 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
315 return __pAppManagerImpl->IsAppLaunchRegistered(appId, pCondition);
319 AppManager::SetCheckpointEventListener(IAppCheckpointEventListener& listener)
321 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
323 Tizen::Base::Runtime::IEventListener* pListener = &listener;
324 return __pAppManagerImpl->SetEventListener(_APP_EVENT_CHECKPOINT, pListener);
328 AppManager::SetAppLaunchConditionEventListener(IAppLaunchConditionEventListener* pListener)
331 _AppImpl::GetInstance()->SetAppLaunchConditionEventListener(pListener);
336 AppManager::SendAppControlResult(const String& appControlRequestId, const IList* pResultList)
338 int req = _AppArg::GetRequestId(appControlRequestId);
339 AppControlProviderManager* pInstance = AppControlProviderManager::GetInstance();
340 return _AppControlProviderManagerImpl::GetInstance(*pInstance)->SendAppControlResult(req, pResultList);
344 AppManager::AddActiveAppEventListener(IActiveAppEventListener& listener)
346 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
348 result r = _AccessController::CheckUserPrivilege(_PRV_APPUSAGE);
349 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
351 return __pAppManagerImpl->AddActiveAppEventListener(listener);
355 AppManager::RemoveActiveAppEventListener(IActiveAppEventListener& listener)
357 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
359 result r = _AccessController::CheckUserPrivilege(_PRV_APPUSAGE);
360 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
362 return __pAppManagerImpl->RemoveActiveAppEventListener(listener);
366 AppManager::GetActiveApp(AppId& appId)
368 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
370 result r = _AccessController::CheckUserPrivilege(_PRV_APPUSAGE);
371 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
373 return __pAppManagerImpl->GetActiveApp(appId);
377 AppManager::IsUserPreferredAppForAppControlResolution(const AppId& appId) const
379 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
380 SysTryReturn(NID_APP, _Aul::IsInstalled(appId) == true, false, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
382 return __pAppManagerImpl->IsUserPreferredAppForAppControlResolution(appId);
386 AppManager::ClearUserPreferenceForAppControlResolution(const AppId& appId)
388 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
389 SysTryReturnResult(NID_APP, _Aul::IsInstalled(appId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
391 return __pAppManagerImpl->ClearUserPreferenceForAppControlResolution(appId);