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_IAppManagerServiceEventListener.h"
39 #include "FApp_AppLifecycleEvent.h"
41 namespace Tizen { namespace Base
49 namespace Tizen { namespace Io
51 class DataControlResultSet;
52 class _DataControlResultSetImpl;
55 namespace Tizen { namespace App
59 class _ConditionManagerProxy;
60 class _IAppEventListener;
61 class _IAppLifecycleEventListener;
62 class _ActiveWindowManager;
65 class _AppLifecycleManager
68 _AppLifecycleManager(void) : __pEventList(null)
73 ~_AppLifecycleManager(void) {}
75 result AddListener(_IAppEventListener& listener);
77 result RemoveListener(_IAppEventListener& listener);
84 static int LaunchCallback(int pid, void* pData);
86 static int TerminateCallback(int pid, void* pData);
89 Tizen::Base::Collection::LinkedListT<_IAppEventListener*>* __pEventList;
90 Tizen::Base::Collection::HashMapT<int, Tizen::Base::String> __map;
93 class _OSP_EXPORT_ _AppManagerImpl
94 : public Tizen::Base::Object
95 , public _IAppManagerServiceEventListener
96 , virtual public Tizen::Base::Runtime::IEventListener
99 static _AppManagerImpl* GetInstance(void);
102 * Finds the application control that the caller wants to start. @n
103 * It resolves the matched application control with the delivered application control provider ID and operation ID.
105 * @return A pointer to the newly created AppControl instance if a matched %AppControl is found, @n
107 * @param[in] providerId The provider ID
108 * @param[in] operationId The operation ID
110 static AppControl* FindAppControlN(const AppId& providerId, const Tizen::Base::String& operationId);
113 * Returns a list of AppControl instances that match the specified operation ID, category,
114 * data type, and URI scheme.
116 * @return A pointer to the list of the %AppControl instances that matches the specified operation ID, category, URI scheme, and data type, @n
117 * else @c null if it fails
118 * @param[in] pOperationId The operation ID
119 * @param[in] pCategory The application control category
120 * @param[in] pDataType The MIME type (RFC 2046) or file extension @n
121 * The '.' prefix should be used when specifying the file extension.
122 * @param[in] pUriScheme The URI scheme
124 * @exception E_SUCCESS The method is successful.
125 * @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.
126 * @exception E_INVALID_FORMAT The specified URI scheme is invalid (RFC 2396).
127 * @exception E_UNSUPPORTED_FORMAT The specified file extension for @c pDataType is not supported.
128 * @exception E_OBJ_NOT_FOUND The application control is not found.
129 * @exception E_OUT_OF_MEMORY The memory is insufficient.
130 * @exception E_SYSTEM A system error has occurred.
132 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);
135 * Starts the application control if there is only one application control that matches the specified URI, operation ID, and data type. @n
136 * If there are more than one application controls, the one that the user selects is started.
138 * @return An error code
139 * @param[in] uri The URI that has a maximum size of @c 1024 bytes
140 * @param[in] pOperationId The operation ID
141 * @param[in] pDataType The MIME type (RFC 2046) or file extension @n
142 * The '.' prefix should be used for the @c dataType when specifying the file extension.
143 * @param[in] pListener A listener that gets notified when the resolved application control has started
144 * @exception E_SUCCESS The method is successful.
145 * @exception E_MAX_EXCEEDED The size of @c uri has exceeded the maximum limit.
146 * @exception E_UNSUPPORTED_FORMAT The specified file extension for @c pDataType is not supported.
147 * @exception E_OUT_OF_MEMORY The memory is insufficient.
148 * @exception E_INVALID_STATE The system pop-up cannot be launched.
149 * @exception E_OBJ_NOT_FOUND The application control is not found.
150 * @exception E_IN_PROGRESS The target application control is in progress.
151 * @exception E_SYSTEM A system error has occurred.
152 * @remarks The E_INVALID_STATE exception is thrown when the default form is not accessible.
154 static result StartAppControl(const Tizen::Base::String& uri, const Tizen::Base::String* pOperationId, const Tizen::Base::String* pDataType, IAppControlListener* pListener);
157 * Starts the application control if there is only one application control that matches the specified operation ID, category, URI scheme, and data type. @n
158 * If there are more than one application controls, the one that the user selects is started.
160 * @return An error code
161 * @param[in] pOperationId The operation ID
162 * @param[in] pCategory The application control category
163 * @param[in] pDataType The MIME type (RFC 2046) or file extension @n
164 * The '.' prefix should be used when specifying the file extension.
165 * @param[in] pUriScheme The URI scheme
166 * @param[in] pDataList The data list to be delivered to the resolved application control @n
167 * It has a maximum size of @c 1024 bytes.
168 * @param[in] pListener A listener that gets notified when the resolved application control has started
169 * @exception E_SUCCESS The method is successful.
170 * @exception E_INVALID_ARG At least one of the specified @c pOperationId, @c pCategory, @c pDataType, or @c pUriScheme should not be @c null.
171 * @exception E_MAX_EXCEEDED The size of @c pDataList has exceeded the maximum limit.
172 * @exception E_UNSUPPORTED_FORMAT The specified file extension for @c pDataType is not supported.
173 * @exception E_OUT_OF_MEMORY The memory is insufficient.
174 * @exception E_INVALID_STATE The system pop-up cannot be launched.
175 * @exception E_OBJ_NOT_FOUND The application control is not found.
176 * @exception E_IN_PROGRESS The target application control is in progress.
177 * @exception E_SYSTEM A system error has occurred.
178 * @remarks E_INVALID_STATE occurs when the default form is not accessible.
180 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);
182 static SqlDataControl* GetSqlDataControlN(const Tizen::Base::String& providerId);
184 static MapDataControl* GetMapDataControlN(const Tizen::Base::String& providerId);
186 static result GetAppRootPath(const AppId& appId, Tizen::Base::String& appRootPath);
189 * Launches an application. @n
190 * The launch arguments are given as input parameters for App::OnUserEventReceivedN() or can be obtained by
191 * invoking Application::GetAppArgumentListN(), especially within Application::OnAppInitializing().
193 * @return An error code
194 * @param[in] appId The application's ID to be executed
195 * @param[in] pArguments A pointer to the list of string arguments that has a maximum size of @c 1024 bytes @n
196 * The default value is @c null.
197 * @param[in] option The launch option (currently only AppManager::LAUNCH_OPTION_DEFAULT is available)
198 * @exception E_SUCCESS The method is successful.
199 * @exception E_SYSTEM A system error has occurred.
200 * @exception E_OBJ_NOT_FOUND The target application is not installed.
201 * @exception E_OUT_OF_MEMORY The memory is insufficient.
202 * @exception E_MAX_EXCEEDED The size of @c appId or @c pArguments has exceeded the maximum limit.
204 result LaunchApplication(const AppId& appId, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option);
207 * Launches an application. @n
208 * The launch arguments are given as input parameters for App::OnUserEventReceivedN() or can be obtained by
209 * invoking Application::GetAppArgumentListN(), especially within Application::OnAppInitializing().
211 * @return An error code
212 * @param[in] appId The application's ID to be executed
213 * @param[in] option The launch option (currently only AppManager::LAUNCH_OPTION_DEFAULT is available)
214 * @exception E_SUCCESS The method is successful.
215 * @exception E_SYSTEM A system error has occurred.
216 * @exception E_APP_NOT_INSTALLED The target application is not installed.
218 result LaunchApplication(const AppId& appId, AppManager::LaunchOption option);
221 * Terminates an application.
223 * @return An error code
224 * @param[in] appId The application's ID to be executed
225 * @exception E_SUCCESS The method is successful.
226 * @exception E_SYSTEM A system error has occurred.
227 * @exception E_OBJ_NOT_FOUND The application is not installed or not running.
229 result TerminateApplication(const AppId& appId);
232 * Terminates all the applications in a package.
234 * @return An error code
235 * @param[in] packageId The package ID
236 * @exception E_SUCCESS The method is successful.
237 * @exception E_SYSTEM A system error has occurred.
238 * @exception E_OBJ_NOT_FOUND The application is not installed or not running.
240 result TerminateApplications(const PackageId& appId);
243 * Checks whether an application is running.
245 * @return @c true if the application is running, @n
247 * @param[in] appId The installed application ID
249 bool IsRunning(const AppId& appId) const;
252 * Returns a list of running applications at the time of invocation.
254 * @return A pointer to the running state application list (AppId), @n
255 * else @c null if an error occurs
256 * @exception E_SUCCESS The method is successful.
257 * @exception E_SYSTEM A system error has occurred.
258 * @exception E_INVALID_STATE This instance is in an invalid state.
259 * @remarks The specific error code can be accessed using the GetLastResult() method.
261 Tizen::Base::Collection::IList* GetRunningAppListN(void) const;
264 * Registers the specified application with a specific condition and launches it if the condition is met. @n
265 * If the requested application is already running, the application is notified via Application::OnUserEventReceivedN().
266 * The launch arguments are specified as input parameters for Application::OnUserEventReceivedN() or can be obtained by
267 * invoking Application::GetAppArgumentListN(), especially within Application::OnAppInitializing().
269 * @return An error code
270 * @param[in] appId The ID of the application registered for launch
271 * @param[in] condition The launch condition for the application @n
272 * The condition has L"Key='value'" format and is case-sensitive. @n
273 * 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>.
274 * @param[in] pArguments A list of string arguments that has a maximum size of @c 1024 bytes @n
275 * The parameter can also contain @c null.
276 * @param[in] option The launch option (currently only AppManager::LAUNCH_OPTION_DEFAULT is available)
277 * @exception E_SUCCESS The method is successful.
278 * @exception E_APP_NOT_INSTALLED The application is not installed.
279 * @exception E_INVALID_ARG The launch condition is empty or too long (Maximum 400 bytes).
280 * @exception E_INVALID_FORMAT The specified condition format is invalid.
281 * @exception E_INVALID_CONDITION The specified condition format is valid but the condition has at least one or more invalid values.
282 * @exception E_OUT_OF_MEMORY The memory is insufficient.
283 * @exception E_MAX_EXCEEDED The size of @c pArguments has exceeded the maximum limit.
284 * @exception E_SYSTEM A system error has occurred.
286 result RegisterAppLaunch(const AppId& appId, const Tizen::Base::String& condition, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option);
289 * Unregisters the launch condition.
291 * @return An error code
292 * @param[in] appId The application ID
293 * @param[in] pCondition The launch condition to unregister @n
294 * If the parameter contains @c null, all the conditions are unregistered.
295 * @exception E_SUCCESS The method is successful.
296 * @exception E_APP_NOT_INSTALLED The application is not installed.
297 * @exception E_OBJ_NOT_FOUND The specified launch condition is not found.
298 * @exception E_SYSTEM A system error has occurred.
299 * @exception E_OUT_OF_MEMORY The memory is insufficient.
301 result UnregisterAppLaunch(const AppId& appId, const Tizen::Base::String* pCondition);
304 * Checks whether a previously registered launch condition is present for the specified application.
306 * @return @c true if a condition is already registered to the specified application with the specified condition, @n
308 * @param[in] appId The application ID
309 * @param[in] pCondition The launch condition to register for the specified @c appId @n
310 * If the parameter contains @c null, the method checks for any registered launch condition for the specified @c appId.
311 * @exception E_SUCCESS The method is successful.
312 * @exception E_APP_NOT_INSTALLED The application is not installed.
313 * @exception E_SYSTEM A system error has occurred.
314 * @exception E_OUT_OF_MEMORY The memory is insufficient.
316 bool IsAppLaunchRegistered(const AppId& appId, const Tizen::Base::String* pCondition = null);
319 * Sets a checkpoint event listener. @n
320 * The listener gets notified when a checkpoint event is fired. To unset the listener, pass a @c null value to the @c listener parameter.
322 * @return An error code
323 * @param[in] appEvent _AppEvent event type
324 * @param[in] pListener The listener to receive the checkpoint event
325 * @exception E_SUCCESS The method is successful.
326 * @exception E_OBJ_ALREADY_EXIST The listener is already set.
327 * @exception E_SYSTEM A system error has occurred.
330 result SetEventListener(_AppEvent appEvent, Tizen::Base::Runtime::IEventListener* pListener);
333 * Adds a listener object.
334 * Added listener can listen to events when they are fired.
336 * @return An error code
337 * @param[in] listener Listener to add
338 * @exception E_SUCCESS This method was successful.
339 * @exception E_OBJ_ALREADY_EXIST The listener was already exist.
341 result AddAppEventListener(_IAppEventListener& listener);
344 * Adds a listener object.
345 * Added listener can listen to events when they are fired.
347 * @return An error code
348 * @param[in] listener Listener to add
349 * @exception E_SUCCESS This method was successful.
350 * @exception E_OBJ_ALREADY_EXIST The listener was already exist.
352 result RemoveAppEventListener(_IAppEventListener& listener);
354 virtual result OnTerminateApplicationRequested(int clientId);
356 virtual result OnAppLifecycleEventReceived(int clientId, const AppId& appId, _AppLifecycleEventType appLifecycleEventType);
358 _OSP_LOCAL_ Tizen::Base::Runtime::_LibraryImpl& GetUiLibraryImpl(void);
360 result AddActiveAppEventListener(IActiveAppEventListener& listener);
362 result RemoveActiveAppEventListener(IActiveAppEventListener& listener);
364 result GetActiveApp(AppId& appId);
366 bool IsUserPreferredAppForAppControlResolution(const AppId& appId) const;
368 result ClearUserPreferenceForAppControlResolution(const AppId& appId);
370 result AddAppLifecycleEventListener(_IAppLifecycleEventListener& listener);
372 result RemoveAppLifecycleEventListener(_IAppLifecycleEventListener& listener);
374 result RegisterAppForAppLifecycleEvent(const AppId& appId);
376 result UnregisterAppForAppLifecycleEvent(const AppId& appId);
379 _OSP_LOCAL_ _AppManagerImpl(void);
381 _OSP_LOCAL_ virtual ~_AppManagerImpl(void);
383 _OSP_LOCAL_ result Construct();
385 _AppManagerImpl(const _AppManagerImpl& rhs);
387 _AppManagerImpl& operator =(const _AppManagerImpl& rhs);
389 _OSP_LOCAL_ _ConditionManagerProxy* GetConditionManagerProxy(void);
392 _ConditionManagerProxy* __pConditionManager;
393 std::unique_ptr<_ActiveWindowManager> __pActiveWindowManager;
394 Tizen::Base::Runtime::_LibraryImpl* __pUiLibrary;
395 _AppLifecycleManager __lifeManager;
396 Tizen::App::_AppLifecycleEvent __appLifecycleEvent;
397 Tizen::Base::Collection::HashMapT<Tizen::Base::String, int> __appListForAppLifecycle;
398 Tizen::Base::Runtime::Mutex __mutex;
400 friend class AppManager;
401 friend class _AppControlImpl;
402 friend class _SqlDataControlImpl;
403 friend class _MapDataControlImpl;
404 }; // _AppManagerImpl
408 #endif // _FAPP_INTERNAL_APP_MANAGER_IMPL_H_