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();
79 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
84 delete __pAppManagerImpl;
85 __pAppManagerImpl = null;
91 AppManager::~AppManager(void)
93 delete __pAppManagerImpl;
98 AppManager::FindAppControlN(const AppId& appId, const String& operationId)
100 return _AppManagerImpl::FindAppControlN(appId, operationId);
105 AppManager::FindAppControlsN(const String* pOperationId, const String* pCategory, const String* pDataType, const String* pUriScheme)
107 return _AppManagerImpl::FindAppControlsN(pOperationId, pCategory, pDataType, pUriScheme);
112 AppManager::StartAppControl(const String& uri, const String* pOperationId,
113 const String* pDataType,
114 IAppControlListener* pListener)
116 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
117 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
119 return _AppManagerImpl::StartAppControl(uri, pOperationId, pDataType, pListener);
124 AppManager::StartAppControl(const String* pOperationId, const String* pCategory,
125 const String* pDataType, const String* pUriScheme,
126 const IList* pDataList,
127 IAppControlListener* pListener)
129 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
130 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
132 return _AppManagerImpl::StartAppControl(pOperationId, pCategory, pDataType, pUriScheme, pDataList, pListener);
136 AppManager::GetSqlDataControlN(const String& providerId)
138 return _AppManagerImpl::GetSqlDataControlN(providerId);
142 AppManager::GetMapDataControlN(const String& providerId)
144 return _AppManagerImpl::GetMapDataControlN(providerId);
148 AppManager::GetAppSharedPath(const AppId& appId)
152 result r = _AppManagerImpl::GetAppRootPath(appId, sharedPath);
153 SysTryReturn(NID_APP, !IsFailed(r), sharedPath, r, "[%s] Propagating to caller...",
156 sharedPath.Append(L"shared/");
158 SetLastResult(E_SUCCESS);
163 AppManager::GetInstance(void)
165 result r = E_SUCCESS;
166 static AppManager* pAppMgr = null;
170 pAppMgr = new (std::nothrow) AppManager();
171 SysTryReturn(NID_APP, pAppMgr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppManager allocation failed.");
173 r = pAppMgr->Construct();
174 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] AppManager construction failed.", GetErrorMessage(r));
176 #ifdef _SINGLETON_CLEANUP
177 // [FIXME] temporary disable to resolve N_SE-23319, ImeApp cleanup issue
178 //_LongevityManager::GetInstance().RegisterOwnership(*pAppMgr);
192 AppManager::LaunchApplication(const AppId& appId, const IList* pArguments, LaunchOption option)
194 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
195 SysTryReturnResult(NID_APP, appId.GetLength() <= WIDGET_APP_MAX_APPID_LENGTH, E_MAX_EXCEEDED,
196 "The length of appid exceeded the limit(%d).", WIDGET_APP_MAX_APPID_LENGTH);
198 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
199 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
201 return __pAppManagerImpl->LaunchApplication(appId, pArguments, LAUNCH_OPTION_DEFAULT);
205 AppManager::LaunchApplication(const AppId& appId, LaunchOption option)
207 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
208 SysTryReturnResult(NID_APP, appId.GetLength() <= WIDGET_APP_MAX_APPID_LENGTH, E_MAX_EXCEEDED,
209 "The length of appid exceeded the limit(%d).", WIDGET_APP_MAX_APPID_LENGTH);
211 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
212 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
214 return __pAppManagerImpl->LaunchApplication(appId, LAUNCH_OPTION_DEFAULT);
218 AppManager::TerminateApplication(const AppId& appId)
220 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
221 SysTryReturnResult(NID_APP, appId.GetLength() <= WIDGET_APP_MAX_APPID_LENGTH, E_MAX_EXCEEDED,
222 "The length of appid exceeded the limit(%d).", WIDGET_APP_MAX_APPID_LENGTH);
224 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_KILL, _PRV_APPMANAGER_KILL);
225 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
227 return __pAppManagerImpl->TerminateApplication(appId);
231 AppManager::IsRunning(const AppId& appId) const
233 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
235 return __pAppManagerImpl->IsRunning(appId);
239 AppManager::GetRunningAppListN(void) const
241 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
243 return __pAppManagerImpl->GetRunningAppListN();
247 AppManager::RegisterAppLaunch(const String& condition, const IList* pArguments, LaunchOption option)
249 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
251 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
252 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
254 return __pAppManagerImpl->RegisterAppLaunch(L"", condition, pArguments, option);
258 AppManager::UnregisterAppLaunch(void)
260 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
262 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
263 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
265 return __pAppManagerImpl->UnregisterAppLaunch(L"", null);
269 AppManager::UnregisterAppLaunch(const String& condition)
271 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
273 result r = _AccessController::CheckUserPrivilege(_PRV_APPLICATION_LAUNCH);
274 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
276 return __pAppManagerImpl->UnregisterAppLaunch(L"", &condition);
280 AppManager::IsAppLaunchRegistered(void) const
282 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
284 return __pAppManagerImpl->IsAppLaunchRegistered(L"", null);
288 AppManager::RegisterAppLaunch(const AppId& appId, const String& condition, const IList* pArguments, LaunchOption option)
290 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
291 SysTryReturnResult(NID_APP, _Aul::IsInstalled(appId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
293 return __pAppManagerImpl->RegisterAppLaunch(appId, condition, pArguments, option);
298 AppManager::UnregisterAppLaunch(const AppId& appId, const String* pCondition)
300 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
301 SysTryReturnResult(NID_APP, _Aul::IsInstalled(appId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
303 return __pAppManagerImpl->UnregisterAppLaunch(appId, pCondition);
308 AppManager::IsAppLaunchRegistered(const AppId& appId, const String* pCondition) const
310 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
312 return __pAppManagerImpl->IsAppLaunchRegistered(appId, pCondition);
316 AppManager::SetCheckpointEventListener(IAppCheckpointEventListener& listener)
318 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
320 Tizen::Base::Runtime::IEventListener* pListener = &listener;
321 return __pAppManagerImpl->SetEventListener(_APP_EVENT_CHECKPOINT, pListener);
325 AppManager::SetAppLaunchConditionEventListener(IAppLaunchConditionEventListener* pListener)
328 _AppImpl::GetInstance()->SetAppLaunchConditionEventListener(pListener);
333 AppManager::SendAppControlResult(const String& appControlRequestId, const IList* pResultList)
335 int req = _AppArg::GetRequestId(appControlRequestId);
336 AppControlProviderManager* pInstance = AppControlProviderManager::GetInstance();
337 return _AppControlProviderManagerImpl::GetInstance(*pInstance)->SendAppControlResult(req, pResultList);
341 AppManager::AddActiveAppEventListener(IActiveAppEventListener& listener)
343 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
345 result r = _AccessController::CheckUserPrivilege(_PRV_APPUSAGE);
346 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
348 return __pAppManagerImpl->AddActiveAppEventListener(listener);
352 AppManager::RemoveActiveAppEventListener(IActiveAppEventListener& listener)
354 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
356 result r = _AccessController::CheckUserPrivilege(_PRV_APPUSAGE);
357 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
359 return __pAppManagerImpl->RemoveActiveAppEventListener(listener);
363 AppManager::GetActiveApp(AppId& appId)
365 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
367 result r = _AccessController::CheckUserPrivilege(_PRV_APPUSAGE);
368 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
370 return __pAppManagerImpl->GetActiveApp(appId);
374 AppManager::IsUserPreferredAppForAppControlResolution(const AppId& appId) const
376 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
377 SysTryReturn(NID_APP, _Aul::IsInstalled(appId) == true, false, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
379 return __pAppManagerImpl->IsUserPreferredAppForAppControlResolution(appId);
383 AppManager::ClearUserPreferenceForAppControlResolution(const AppId& appId)
385 SysAssertf(__pAppManagerImpl != null, "Not constructed properly by platform.");
386 SysTryReturnResult(NID_APP, _Aul::IsInstalled(appId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
388 return __pAppManagerImpl->ClearUserPreferenceForAppControlResolution(appId);