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_AppManagerImpl.h
19 * @brief This is the header file for the _AppManagerImpl class.
22 #ifndef _FAPP_INTERNAL_APP_MANAGER_IMPL_H_
23 #define _FAPP_INTERNAL_APP_MANAGER_IMPL_H_
25 #include <unique_ptr.h>
27 #include <FOspConfig.h>
28 #include <FBaseObject.h>
29 #include <FBaseString.h>
30 #include <FBaseColIList.h>
31 #include <FBaseColLinkedListT.h>
32 #include <FBaseColHashMapT.h>
33 #include <FBaseRtIEventListener.h>
34 #include <FAppAppManager.h>
35 #include <FBaseSysLog.h>
36 #include <FBaseStringHashCodeProvider.h>
37 #include <FBaseComparerT.h>
39 #include "FApp_Types.h"
40 #include "FApp_AppManagerEvent.h"
41 #include "FApp_IAppManagerServiceEventListener.h"
42 #include "FApp_AppLifecycleEvent.h"
44 namespace Tizen { namespace Base
52 namespace Tizen { namespace Io
54 class DataControlResultSet;
55 class _DataControlResultSetImpl;
58 namespace Tizen { namespace App
62 class _ConditionManagerProxy;
63 class _IAppManagerEventListener;
64 class _IAppEventListener;
65 class _AppManagerEventArg;
66 class _IAppLifecycleEventListener;
67 class _ActiveWindowManager;
70 class _AppLifecycleManager
73 _AppLifecycleManager(void) : __pEventList(null)
78 ~_AppLifecycleManager(void) {}
80 result AddListener(_IAppEventListener& listener);
82 result RemoveListener(_IAppEventListener& listener);
89 static int LaunchCallback(int pid, void* pData);
91 static int TerminateCallback(int pid, void* pData);
94 Tizen::Base::Collection::LinkedListT<_IAppEventListener*>* __pEventList;
95 Tizen::Base::Collection::HashMapT<int, Tizen::Base::String> __map;
98 class _OSP_EXPORT_ _AppManagerImpl
99 : public Tizen::Base::Object
100 , public _IAppManagerServiceEventListener
101 , virtual public Tizen::Base::Runtime::IEventListener
104 static _AppManagerImpl* GetInstance(void);
107 * Finds the application control that the caller wants to start. @n
108 * It resolves the matched application control with the delivered application control provider ID and operation ID.
110 * @return A pointer to the newly created AppControl instance if a matched %AppControl is found, @n
112 * @param[in] providerId The provider ID
113 * @param[in] operationId The operation ID
115 static AppControl* FindAppControlN(const AppId& providerId, const Tizen::Base::String& operationId);
118 * Returns a list of AppControl instances that match the specified operation ID, category,
119 * data type, and URI scheme.
121 * @return A pointer to the list of the %AppControl instances that matches the specified operation ID, category, URI scheme, and data type, @n
122 * else @c null if it fails
123 * @param[in] pOperationId The operation ID
124 * @param[in] pCategory The application control category
125 * @param[in] pDataType The MIME type (RFC 2046) or file extension @n
126 * The '.' prefix should be used when specifying the file extension.
127 * @param[in] pUriScheme The URI scheme
129 * @exception E_SUCCESS The method is successful.
130 * @exception E_INVALID_ARG At least one of the The specified @c pOperationId, @c pCategory, @c pDataType, or @c pUriScheme should not be @c null.
131 * @exception E_INVALID_FORMAT The specified URI scheme is invalid (RFC 2396).
132 * @exception E_UNSUPPORTED_FORMAT The specified file extension for @c pDataType is not supported.
133 * @exception E_OBJ_NOT_FOUND The application control is not found.
134 * @exception E_OUT_OF_MEMORY The memory is insufficient.
135 * @exception E_SYSTEM A system error has occurred.
137 static Tizen::Base::Collection::IList* FindAppControlsN(const Tizen::Base::String* pOperationId, const Tizen::Base::String* pCategory, const Tizen::Base::String* pDataType, const Tizen::Base::String* pUriScheme);
140 * Starts the application control if there is only one application control that matches the specified URI, operation ID, and data type. @n
141 * If there are more than one application controls, the one that the user selects is started.
143 * @return An error code
144 * @param[in] uri The URI that has a maximum size of @c 1024 bytes
145 * @param[in] pOperationId The operation ID
146 * @param[in] pDataType The MIME type (RFC 2046) or file extension @n
147 * The '.' prefix should be used for the @c dataType when specifying the file extension.
148 * @param[in] pListener A listener that gets notified when the resolved application control has started
149 * @exception E_SUCCESS The method is successful.
150 * @exception E_MAX_EXCEEDED The size of @c uri has exceeded the maximum limit.
151 * @exception E_UNSUPPORTED_FORMAT The specified file extension for @c pDataType is not supported.
152 * @exception E_OUT_OF_MEMORY The memory is insufficient.
153 * @exception E_INVALID_STATE The system pop-up cannot be launched.
154 * @exception E_OBJ_NOT_FOUND The application control is not found.
155 * @exception E_IN_PROGRESS The target application control is in progress.
156 * @exception E_SYSTEM A system error has occurred.
157 * @remarks The E_INVALID_STATE exception is thrown when the default form is not accessible.
159 static result StartAppControl(const Tizen::Base::String& uri, const Tizen::Base::String* pOperationId, const Tizen::Base::String* pDataType, IAppControlListener* pListener);
162 * Starts the application control if there is only one application control that matches the specified operation ID, category, URI scheme, and data type. @n
163 * If there are more than one application controls, the one that the user selects is started.
165 * @return An error code
166 * @param[in] pOperationId The operation ID
167 * @param[in] pCategory The application control category
168 * @param[in] pDataType The MIME type (RFC 2046) or file extension @n
169 * The '.' prefix should be used when specifying the file extension.
170 * @param[in] pUriScheme The URI scheme
171 * @param[in] pDataList The data list to be delivered to the resolved application control @n
172 * It has a maximum size of @c 1024 bytes.
173 * @param[in] pListener A listener that gets notified when the resolved application control has started
174 * @exception E_SUCCESS The method is successful.
175 * @exception E_INVALID_ARG At least one of the specified @c pOperationId, @c pCategory, @c pDataType, or @c pUriScheme should not be @c null.
176 * @exception E_MAX_EXCEEDED The size of @c pDataList has exceeded the maximum limit.
177 * @exception E_UNSUPPORTED_FORMAT The specified file extension for @c pDataType is not supported.
178 * @exception E_OUT_OF_MEMORY The memory is insufficient.
179 * @exception E_INVALID_STATE The system pop-up cannot be launched.
180 * @exception E_OBJ_NOT_FOUND The application control is not found.
181 * @exception E_IN_PROGRESS The target application control is in progress.
182 * @exception E_SYSTEM A system error has occurred.
183 * @remarks E_INVALID_STATE occurs when the default form is not accessible.
185 static result StartAppControl(const Tizen::Base::String* pOperationId, const Tizen::Base::String* pCategory, const Tizen::Base::String* pDataType, const Tizen::Base::String* pUriScheme, const Tizen::Base::Collection::IList* pDataList, IAppControlListener* pListener);
187 static SqlDataControl* GetSqlDataControlN(const Tizen::Base::String& providerId);
189 static MapDataControl* GetMapDataControlN(const Tizen::Base::String& providerId);
191 static result GetAppRootPath(const AppId& appId, Tizen::Base::String& appRootPath);
194 * Launches an application. @n
195 * The launch arguments are given as input parameters for App::OnUserEventReceivedN() or can be obtained by
196 * invoking Application::GetAppArgumentListN(), especially within Application::OnAppInitializing().
198 * @return An error code
199 * @param[in] appId The application's ID to be executed
200 * @param[in] pArguments A pointer to the list of string arguments that has a maximum size of @c 1024 bytes @n
201 * The default value is @c null.
202 * @param[in] option The launch option (currently only AppManager::LAUNCH_OPTION_DEFAULT is available)
203 * @exception E_SUCCESS The method is successful.
204 * @exception E_SYSTEM A system error has occurred.
205 * @exception E_OBJ_NOT_FOUND The target application is not installed.
206 * @exception E_OUT_OF_MEMORY The memory is insufficient.
207 * @exception E_MAX_EXCEEDED The size of @c appId or @c pArguments has exceeded the maximum limit.
209 result LaunchApplication(const AppId& appId, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option);
212 * Launches an application. @n
213 * The launch arguments are given as input parameters for App::OnUserEventReceivedN() or can be obtained by
214 * invoking Application::GetAppArgumentListN(), especially within Application::OnAppInitializing().
216 * @return An error code
217 * @param[in] appId The application's ID to be executed
218 * @param[in] option The launch option (currently only AppManager::LAUNCH_OPTION_DEFAULT is available)
219 * @exception E_SUCCESS The method is successful.
220 * @exception E_SYSTEM A system error has occurred.
221 * @exception E_APP_NOT_INSTALLED The target application is not installed.
223 result LaunchApplication(const AppId& appId, AppManager::LaunchOption option);
226 * Terminates an application.
228 * @return An error code
229 * @param[in] appId The application's ID to be executed
230 * @exception E_SUCCESS The method is successful.
231 * @exception E_SYSTEM A system error has occurred.
232 * @exception E_OBJ_NOT_FOUND The application is not installed or not running.
234 result TerminateApplication(const AppId& appId);
237 * Terminates all the applications in a package.
239 * @return An error code
240 * @param[in] packageId The package ID
241 * @exception E_SUCCESS The method is successful.
242 * @exception E_SYSTEM A system error has occurred.
243 * @exception E_OBJ_NOT_FOUND The application is not installed or not running.
245 result TerminateApplications(const PackageId& appId);
248 * Checks whether an application is running.
250 * @return @c true if the application is running, @n
252 * @param[in] appId The installed application ID
254 bool IsRunning(const AppId& appId) const;
257 * Returns a list of running applications at the time of invocation.
259 * @return A pointer to the running state application list (AppId), @n
260 * else @c null if an error occurs
261 * @exception E_SUCCESS The method is successful.
262 * @exception E_SYSTEM A system error has occurred.
263 * @exception E_INVALID_STATE This instance is in an invalid state.
264 * @remarks The specific error code can be accessed using the GetLastResult() method.
266 Tizen::Base::Collection::IList* GetRunningAppListN(void) const;
269 * Registers the specified application with a specific condition and launches it if the condition is met. @n
270 * If the requested application is already running, the application is notified via Application::OnUserEventReceivedN().
271 * The launch arguments are specified as input parameters for Application::OnUserEventReceivedN() or can be obtained by
272 * invoking Application::GetAppArgumentListN(), especially within Application::OnAppInitializing().
274 * @return An error code
275 * @param[in] appId The ID of the application registered for launch
276 * @param[in] condition The launch condition for the application @n
277 * The condition has L"Key='value'" format and is case-sensitive. @n
278 * For more information on the condition formats, see <a href="../com.osp.cppprogramming.help/html/dev_guide/app/registering_launch_condition.htm">Registering a Launch Condition</a>.
279 * @param[in] pArguments A list of string arguments that has a maximum size of @c 1024 bytes @n
280 * The parameter can also contain @c null.
281 * @param[in] option The launch option (currently only AppManager::LAUNCH_OPTION_DEFAULT is available)
282 * @exception E_SUCCESS The method is successful.
283 * @exception E_APP_NOT_INSTALLED The application is not installed.
284 * @exception E_INVALID_ARG The launch condition is empty or too long (Maximum 400 bytes).
285 * @exception E_INVALID_FORMAT The specified condition format is invalid.
286 * @exception E_INVALID_CONDITION The specified condition format is valid but the condition has at least one or more invalid values.
287 * @exception E_OUT_OF_MEMORY The memory is insufficient.
288 * @exception E_MAX_EXCEEDED The size of @c pArguments has exceeded the maximum limit.
289 * @exception E_SYSTEM A system error has occurred.
291 result RegisterAppLaunch(const AppId& appId, const Tizen::Base::String& condition, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option);
294 * Unregisters the launch condition.
296 * @return An error code
297 * @param[in] appId The application ID
298 * @param[in] pCondition The launch condition to unregister @n
299 * If the parameter contains @c null, all the conditions are unregistered.
300 * @exception E_SUCCESS The method is successful.
301 * @exception E_APP_NOT_INSTALLED The application is not installed.
302 * @exception E_OBJ_NOT_FOUND The specified launch condition is not found.
303 * @exception E_SYSTEM A system error has occurred.
304 * @exception E_OUT_OF_MEMORY The memory is insufficient.
306 result UnregisterAppLaunch(const AppId& appId, const Tizen::Base::String* pCondition);
309 * Checks whether a previously registered launch condition is present for the specified application.
311 * @return @c true if a condition is already registered to the specified application with the specified condition, @n
313 * @param[in] appId The application ID
314 * @param[in] pCondition The launch condition to register for the specified @c appId @n
315 * If the parameter contains @c null, the method checks for any registered launch condition for the specified @c appId.
316 * @exception E_SUCCESS The method is successful.
317 * @exception E_APP_NOT_INSTALLED The application is not installed.
318 * @exception E_SYSTEM A system error has occurred.
319 * @exception E_OUT_OF_MEMORY The memory is insufficient.
321 bool IsAppLaunchRegistered(const AppId& appId, const Tizen::Base::String* pCondition = null);
324 * Sets a checkpoint event listener. @n
325 * The listener gets notified when a checkpoint event is fired. To unset the listener, pass a @c null value to the @c listener parameter.
327 * @return An error code
328 * @param[in] appEvent _AppEvent event type
329 * @param[in] pListener The listener to receive the checkpoint event
330 * @exception E_SUCCESS The method is successful.
331 * @exception E_OBJ_ALREADY_EXIST The listener is already set.
332 * @exception E_SYSTEM A system error has occurred.
335 result SetEventListener(_AppEvent appEvent, Tizen::Base::Runtime::IEventListener* pListener);
338 * Adds a listener object.
339 * Added listener can listen to events when they are fired.
341 * @return An error code
342 * @param[in] listener Listener to add
343 * @exception E_SUCCESS This method was successful.
344 * @exception E_OBJ_ALREADY_EXIST The listener was already exist.
346 result AddEventListener(_IAppManagerEventListener& listener);
349 * Adds a listener object.
350 * Added listener can listen to events when they are fired.
352 * @return An error code
353 * @param[in] listener Listener to add
354 * @exception E_SUCCESS This method was successful.
355 * @exception E_OBJ_ALREADY_EXIST The listener was already exist.
357 result RemoveEventListener(_IAppManagerEventListener& listener);
359 result AddAppEventListener(_IAppEventListener& listener);
361 result RemoveAppEventListener(_IAppEventListener& listener);
363 virtual result OnServiceEventReceived(const int clientId, const _AppManagerEventArg& arg);
365 virtual result OnTerminateApplicationRequested(int clientId);
367 virtual result OnAppLifecycleEventReceived(int clientId, const AppId& appId, _AppLifecycleEventType appLifecycleEventType);
369 _OSP_LOCAL_ Tizen::Base::Runtime::_LibraryImpl& GetUiLibraryImpl(void);
371 result AddActiveAppEventListener(IActiveAppEventListener& listener);
373 result RemoveActiveAppEventListener(IActiveAppEventListener& listener);
375 result GetActiveApp(AppId& appId);
377 bool IsUserPreferredAppForAppControlResolution(const AppId& appId) const;
379 result ClearUserPreferenceForAppControlResolution(const AppId& appId);
381 result AddAppLifecycleEventListener(_IAppLifecycleEventListener& listener);
383 result RemoveAppLifecycleEventListener(_IAppLifecycleEventListener& listener);
385 result RegisterAppForAppLifecycleEvent(const AppId& appId);
387 result UnregisterAppForAppLifecycleEvent(const AppId& appId);
390 _OSP_LOCAL_ _AppManagerImpl(void);
392 _OSP_LOCAL_ virtual ~_AppManagerImpl(void);
394 _OSP_LOCAL_ result Construct();
396 _AppManagerImpl(const _AppManagerImpl& rhs);
398 _AppManagerImpl& operator =(const _AppManagerImpl& rhs);
400 _OSP_LOCAL_ _ConditionManagerProxy* GetConditionManagerProxy(void);
403 _ConditionManagerProxy* __pConditionManager;
404 std::unique_ptr<_ActiveWindowManager> __pActiveWindowManager;
405 Tizen::Base::Runtime::_LibraryImpl* __pUiLibrary;
406 _AppLifecycleManager __lifeManager;
407 _AppManagerEvent __appManagerEvent;
408 Tizen::App::_AppLifecycleEvent __appLifecycleEvent;
409 Tizen::Base::Collection::HashMapT<Tizen::Base::String, int> __appListForAppLifecycle;
410 Tizen::Base::ComparerT<Tizen::Base::String> __comparer;
411 Tizen::Base::StringHashCodeProvider __strHashCodeProvider;
412 Tizen::Base::Runtime::Mutex __mutex;
414 friend class AppManager;
415 friend class _AppControlImpl;
416 friend class _SqlDataControlImpl;
417 friend class _MapDataControlImpl;
418 }; // _AppManagerImpl
422 #endif // _FAPP_INTERNAL_APP_MANAGER_IMPL_H_