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>
37 #include "FApp_Types.h"
38 #include "FApp_AppManagerEvent.h"
39 #include "FApp_IAppManagerServiceEventListener.h"
40 #include "FApp_AppLifecycleEvent.h"
42 namespace Tizen { namespace Base
50 namespace Tizen { namespace Io
52 class DataControlResultSet;
53 class _DataControlResultSetImpl;
56 namespace Tizen { namespace App
60 class _ConditionManagerProxy;
61 class _IAppManagerEventListener;
62 class _IAppEventListener;
63 class _AppManagerEventArg;
64 class _IAppLifecycleEventListener;
65 class _ActiveWindowManager;
68 class _AppLifecycleManager
71 _AppLifecycleManager(void) : __pEventList(null)
76 ~_AppLifecycleManager(void) {}
78 result AddListener(_IAppEventListener& listener);
80 result RemoveListener(_IAppEventListener& listener);
87 static int LaunchCallback(int pid, void* pData);
89 static int TerminateCallback(int pid, void* pData);
92 Tizen::Base::Collection::LinkedListT<_IAppEventListener*>* __pEventList;
93 Tizen::Base::Collection::HashMapT<int, Tizen::Base::String> __map;
96 class _OSP_EXPORT_ _AppManagerImpl
97 : public Tizen::Base::Object
98 , public _IAppManagerServiceEventListener
99 , virtual public Tizen::Base::Runtime::IEventListener
102 static _AppManagerImpl* GetInstance(void);
105 * Finds the application control that the caller wants to start. @n
106 * It resolves the matched application control with the delivered application control provider ID and operation ID.
108 * @return A pointer to the newly created AppControl instance if a matched %AppControl is found, @n
110 * @param[in] providerId The provider ID
111 * @param[in] operationId The operation ID
113 static AppControl* FindAppControlN(const AppId& providerId, const Tizen::Base::String& operationId);
116 * Returns a list of AppControl instances that match the specified operation ID, category,
117 * data type, and URI scheme.
119 * @return A pointer to the list of the %AppControl instances that matches the specified operation ID, category, URI scheme, and data type, @n
120 * else @c null if it fails
121 * @param[in] pOperationId The operation ID
122 * @param[in] pCategory The application control category
123 * @param[in] pDataType The MIME type (RFC 2046) or file extension @n
124 * The '.' prefix should be used when specifying the file extension.
125 * @param[in] pUriScheme The URI scheme
127 * @exception E_SUCCESS The method is successful.
128 * @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.
129 * @exception E_INVALID_FORMAT The specified URI scheme is invalid (RFC 2396).
130 * @exception E_UNSUPPORTED_FORMAT The specified file extension for @c pDataType is not supported.
131 * @exception E_OBJ_NOT_FOUND The application control is not found.
132 * @exception E_OUT_OF_MEMORY The memory is insufficient.
133 * @exception E_SYSTEM A system error has occurred.
135 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);
138 * Starts the application control if there is only one application control that matches the specified URI, operation ID, and data type. @n
139 * If there are more than one application controls, the one that the user selects is started.
141 * @return An error code
142 * @param[in] uri The URI that has a maximum size of @c 1024 bytes
143 * @param[in] pOperationId The operation ID
144 * @param[in] pDataType The MIME type (RFC 2046) or file extension @n
145 * The '.' prefix should be used for the @c dataType when specifying the file extension.
146 * @param[in] pListener A listener that gets notified when the resolved application control has started
147 * @exception E_SUCCESS The method is successful.
148 * @exception E_MAX_EXCEEDED The size of @c uri has exceeded the maximum limit.
149 * @exception E_UNSUPPORTED_FORMAT The specified file extension for @c pDataType is not supported.
150 * @exception E_OUT_OF_MEMORY The memory is insufficient.
151 * @exception E_INVALID_STATE The system pop-up cannot be launched.
152 * @exception E_OBJ_NOT_FOUND The application control is not found.
153 * @exception E_IN_PROGRESS The target application control is in progress.
154 * @exception E_SYSTEM A system error has occurred.
155 * @remarks The E_INVALID_STATE exception is thrown when the default form is not accessible.
157 static result StartAppControl(const Tizen::Base::String& uri, const Tizen::Base::String* pOperationId, const Tizen::Base::String* pDataType, IAppControlListener* pListener);
160 * Starts the application control if there is only one application control that matches the specified operation ID, category, URI scheme, and data type. @n
161 * If there are more than one application controls, the one that the user selects is started.
163 * @return An error code
164 * @param[in] pOperationId The operation ID
165 * @param[in] pCategory The application control category
166 * @param[in] pDataType The MIME type (RFC 2046) or file extension @n
167 * The '.' prefix should be used when specifying the file extension.
168 * @param[in] pUriScheme The URI scheme
169 * @param[in] pDataList The data list to be delivered to the resolved application control @n
170 * It has a maximum size of @c 1024 bytes.
171 * @param[in] pListener A listener that gets notified when the resolved application control has started
172 * @exception E_SUCCESS The method is successful.
173 * @exception E_INVALID_ARG At least one of the specified @c pOperationId, @c pCategory, @c pDataType, or @c pUriScheme should not be @c null.
174 * @exception E_MAX_EXCEEDED The size of @c pDataList has exceeded the maximum limit.
175 * @exception E_UNSUPPORTED_FORMAT The specified file extension for @c pDataType is not supported.
176 * @exception E_OUT_OF_MEMORY The memory is insufficient.
177 * @exception E_INVALID_STATE The system pop-up cannot be launched.
178 * @exception E_OBJ_NOT_FOUND The application control is not found.
179 * @exception E_IN_PROGRESS The target application control is in progress.
180 * @exception E_SYSTEM A system error has occurred.
181 * @remarks E_INVALID_STATE occurs when the default form is not accessible.
183 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);
185 static SqlDataControl* GetSqlDataControlN(const Tizen::Base::String& providerId);
187 static MapDataControl* GetMapDataControlN(const Tizen::Base::String& providerId);
189 static result GetAppRootPath(const AppId& appId, Tizen::Base::String& appRootPath);
192 * Launches an application. @n
193 * The launch arguments are given as input parameters for App::OnUserEventReceivedN() or can be obtained by
194 * invoking Application::GetAppArgumentListN(), especially within Application::OnAppInitializing().
196 * @return An error code
197 * @param[in] appId The application's ID to be executed
198 * @param[in] pArguments A pointer to the list of string arguments that has a maximum size of @c 1024 bytes @n
199 * The default value is @c null.
200 * @param[in] option The launch option (currently only AppManager::LAUNCH_OPTION_DEFAULT is available)
201 * @exception E_SUCCESS The method is successful.
202 * @exception E_SYSTEM A system error has occurred.
203 * @exception E_OBJ_NOT_FOUND The target application is not installed.
204 * @exception E_OUT_OF_MEMORY The memory is insufficient.
205 * @exception E_MAX_EXCEEDED The size of @c appId or @c pArguments has exceeded the maximum limit.
207 result LaunchApplication(const AppId& appId, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option);
210 * Launches an application. @n
211 * The launch arguments are given as input parameters for App::OnUserEventReceivedN() or can be obtained by
212 * invoking Application::GetAppArgumentListN(), especially within Application::OnAppInitializing().
214 * @return An error code
215 * @param[in] appId The application's ID to be executed
216 * @param[in] option The launch option (currently only AppManager::LAUNCH_OPTION_DEFAULT is available)
217 * @exception E_SUCCESS The method is successful.
218 * @exception E_SYSTEM A system error has occurred.
219 * @exception E_APP_NOT_INSTALLED The target application is not installed.
221 result LaunchApplication(const AppId& appId, AppManager::LaunchOption option);
224 * Terminates an application.
226 * @return An error code
227 * @param[in] appId The application's ID to be executed
228 * @exception E_SUCCESS The method is successful.
229 * @exception E_SYSTEM A system error has occurred.
230 * @exception E_OBJ_NOT_FOUND The application is not installed or not running.
232 result TerminateApplication(const AppId& appId);
235 * Terminates all the applications in a package.
237 * @return An error code
238 * @param[in] packageId The package ID
239 * @exception E_SUCCESS The method is successful.
240 * @exception E_SYSTEM A system error has occurred.
241 * @exception E_OBJ_NOT_FOUND The application is not installed or not running.
243 result TerminateApplications(const PackageId& appId);
246 * Checks whether an application is running.
248 * @return @c true if the application is running, @n
250 * @param[in] appId The installed application ID
252 bool IsRunning(const AppId& appId) const;
255 * Returns a list of running applications at the time of invocation.
257 * @return A pointer to the running state application list (AppId), @n
258 * else @c null if an error occurs
259 * @exception E_SUCCESS The method is successful.
260 * @exception E_SYSTEM A system error has occurred.
261 * @exception E_INVALID_STATE This instance is in an invalid state.
262 * @remarks The specific error code can be accessed using the GetLastResult() method.
264 Tizen::Base::Collection::IList* GetRunningAppListN(void) const;
267 * Registers the specified application with a specific condition and launches it if the condition is met. @n
268 * If the requested application is already running, the application is notified via Application::OnUserEventReceivedN().
269 * The launch arguments are specified as input parameters for Application::OnUserEventReceivedN() or can be obtained by
270 * invoking Application::GetAppArgumentListN(), especially within Application::OnAppInitializing().
272 * @return An error code
273 * @param[in] appId The ID of the application registered for launch
274 * @param[in] condition The launch condition for the application @n
275 * The condition has L"Key='value'" format and is case-sensitive. @n
276 * 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>.
277 * @param[in] pArguments A list of string arguments that has a maximum size of @c 1024 bytes @n
278 * The parameter can also contain @c null.
279 * @param[in] option The launch option (currently only AppManager::LAUNCH_OPTION_DEFAULT is available)
280 * @exception E_SUCCESS The method is successful.
281 * @exception E_APP_NOT_INSTALLED The application is not installed.
282 * @exception E_INVALID_ARG The launch condition is empty or too long (Maximum 400 bytes).
283 * @exception E_INVALID_FORMAT The specified condition format is invalid.
284 * @exception E_INVALID_CONDITION The specified condition format is valid but the condition has at least one or more invalid values.
285 * @exception E_OUT_OF_MEMORY The memory is insufficient.
286 * @exception E_MAX_EXCEEDED The size of @c pArguments has exceeded the maximum limit.
287 * @exception E_SYSTEM A system error has occurred.
289 result RegisterAppLaunch(const AppId& appId, const Tizen::Base::String& condition, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option);
292 * Unregisters the launch condition.
294 * @return An error code
295 * @param[in] appId The application ID
296 * @param[in] pCondition The launch condition to unregister @n
297 * If the parameter contains @c null, all the conditions are unregistered.
298 * @exception E_SUCCESS The method is successful.
299 * @exception E_APP_NOT_INSTALLED The application is not installed.
300 * @exception E_OBJ_NOT_FOUND The specified launch condition is not found.
301 * @exception E_SYSTEM A system error has occurred.
302 * @exception E_OUT_OF_MEMORY The memory is insufficient.
304 result UnregisterAppLaunch(const AppId& appId, const Tizen::Base::String* pCondition);
307 * Checks whether a previously registered launch condition is present for the specified application.
309 * @return @c true if a condition is already registered to the specified application with the specified condition, @n
311 * @param[in] appId The application ID
312 * @param[in] pCondition The launch condition to register for the specified @c appId @n
313 * If the parameter contains @c null, the method checks for any registered launch condition for the specified @c appId.
314 * @exception E_SUCCESS The method is successful.
315 * @exception E_APP_NOT_INSTALLED The application is not installed.
316 * @exception E_SYSTEM A system error has occurred.
317 * @exception E_OUT_OF_MEMORY The memory is insufficient.
319 bool IsAppLaunchRegistered(const AppId& appId, const Tizen::Base::String* pCondition = null);
322 * Sets a checkpoint event listener. @n
323 * The listener gets notified when a checkpoint event is fired. To unset the listener, pass a @c null value to the @c listener parameter.
325 * @return An error code
326 * @param[in] appEvent _AppEvent event type
327 * @param[in] pListener The listener to receive the checkpoint event
328 * @exception E_SUCCESS The method is successful.
329 * @exception E_OBJ_ALREADY_EXIST The listener is already set.
330 * @exception E_SYSTEM A system error has occurred.
333 result SetEventListener(_AppEvent appEvent, Tizen::Base::Runtime::IEventListener* pListener);
336 * Adds a listener object.
337 * Added listener can listen to events when they are fired.
339 * @return An error code
340 * @param[in] listener Listener to add
341 * @exception E_SUCCESS This method was successful.
342 * @exception E_OBJ_ALREADY_EXIST The listener was already exist.
344 result AddEventListener(_IAppManagerEventListener& listener);
347 * Adds a listener object.
348 * Added listener can listen to events when they are fired.
350 * @return An error code
351 * @param[in] listener Listener to add
352 * @exception E_SUCCESS This method was successful.
353 * @exception E_OBJ_ALREADY_EXIST The listener was already exist.
355 result RemoveEventListener(_IAppManagerEventListener& listener);
357 result AddAppEventListener(_IAppEventListener& listener);
359 result RemoveAppEventListener(_IAppEventListener& listener);
361 virtual result OnServiceEventReceived(const int clientId, const _AppManagerEventArg& arg);
363 virtual result OnTerminateApplicationRequested(int clientId);
365 virtual result OnAppLifecycleEventReceived(int clientId, const AppId& appId, _AppLifecycleEventType appLifecycleEventType);
367 _OSP_LOCAL_ Tizen::Base::Runtime::_LibraryImpl& GetUiLibraryImpl(void);
369 result AddActiveAppEventListener(IActiveAppEventListener& listener);
371 result RemoveActiveAppEventListener(IActiveAppEventListener& listener);
373 result GetActiveApp(AppId& appId);
375 bool IsUserPreferredAppForAppControlResolution(const AppId& appId) const;
377 result ClearUserPreferenceForAppControlResolution(const AppId& appId);
379 result AddAppLifecycleEventListener(_IAppLifecycleEventListener& listener);
381 result RemoveAppLifecycleEventListener(_IAppLifecycleEventListener& listener);
383 result RegisterAppForAppLifecycleEvent(const AppId& appId);
385 result UnregisterAppForAppLifecycleEvent(const AppId& appId);
388 _OSP_LOCAL_ _AppManagerImpl(void);
390 _OSP_LOCAL_ virtual ~_AppManagerImpl(void);
392 _OSP_LOCAL_ result Construct();
394 _AppManagerImpl(const _AppManagerImpl& rhs);
396 _AppManagerImpl& operator =(const _AppManagerImpl& rhs);
398 _OSP_LOCAL_ _ConditionManagerProxy* GetConditionManagerProxy(void);
401 _ConditionManagerProxy* __pConditionManager;
402 std::unique_ptr<_ActiveWindowManager> __pActiveWindowManager;
403 Tizen::Base::Runtime::_LibraryImpl* __pUiLibrary;
404 _AppLifecycleManager __lifeManager;
405 _AppManagerEvent __appManagerEvent;
406 Tizen::App::_AppLifecycleEvent __appLifecycleEvent;
407 Tizen::Base::Collection::HashMapT<Tizen::Base::String, int> __appListForAppLifecycle;
408 Tizen::Base::Runtime::Mutex __mutex;
410 friend class AppManager;
411 friend class _AppControlImpl;
412 friend class _SqlDataControlImpl;
413 friend class _MapDataControlImpl;
414 }; // _AppManagerImpl
418 #endif // _FAPP_INTERNAL_APP_MANAGER_IMPL_H_