Merge "Revert "Fix prevent defect for locales"" into devel_3.0_main
[platform/framework/native/appfw.git] / src / app / inc / FApp_AppManagerImpl.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file        FApp_AppManagerImpl.h
19  * @brief       This is the header file for the _AppManagerImpl class.
20  */
21
22 #ifndef _FAPP_INTERNAL_APP_MANAGER_IMPL_H_
23 #define _FAPP_INTERNAL_APP_MANAGER_IMPL_H_
24
25 #include <unique_ptr.h>
26
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
37 #include "FApp_Types.h"
38 #include "FApp_AppManagerEvent.h"
39 #include "FApp_IAppManagerServiceEventListener.h"
40 #include "FApp_AppLifecycleEvent.h"
41
42 namespace Tizen { namespace Base
43 {
44 class String;
45 namespace Runtime
46 {
47 class _LibraryImpl;
48 }
49 }}
50 namespace Tizen { namespace Io
51 {
52 class DataControlResultSet;
53 class _DataControlResultSetImpl;
54 }}
55
56 namespace Tizen { namespace App
57 {
58
59 class _IAppManager;
60 class _ConditionManagerProxy;
61 class _IAppManagerEventListener;
62 class _IAppEventListener;
63 class _AppManagerEventArg;
64 class _IAppLifecycleEventListener;
65 class _ActiveWindowManager;
66
67
68 class _AppLifecycleManager
69 {
70 public:
71         _AppLifecycleManager(void) : __pEventList(null)
72         {
73                 __map.Construct();
74         }
75
76         ~_AppLifecycleManager(void) {}
77
78         result AddListener(_IAppEventListener& listener);
79
80         result RemoveListener(_IAppEventListener& listener);
81
82 private:
83         void Init(void);
84
85         void Fini(void);
86
87         static int LaunchCallback(int pid, void* pData);
88
89         static int TerminateCallback(int pid, void* pData);
90
91 private:
92         Tizen::Base::Collection::LinkedListT<_IAppEventListener*>* __pEventList;
93         Tizen::Base::Collection::HashMapT<int, Tizen::Base::String> __map;
94 };
95
96 class _OSP_EXPORT_ _AppManagerImpl
97         : public Tizen::Base::Object
98         , public _IAppManagerServiceEventListener
99         , virtual public Tizen::Base::Runtime::IEventListener
100 {
101 public:
102         static _AppManagerImpl* GetInstance(void);
103
104         /**
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.
107          *
108          * @return      A pointer to the newly created AppControl instance if a matched %AppControl is found, @n
109          *                      else @c null
110          * @param[in]   providerId      The provider ID
111          * @param[in]   operationId             The operation ID
112          */
113         static AppControl* FindAppControlN(const AppId& providerId, const Tizen::Base::String& operationId);
114
115         /**
116          * Returns a list of AppControl instances that match the specified operation ID, category,
117          * data type, and URI scheme.
118          *
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
126          *
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.
134          */
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);
136
137         /**
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.
140          *
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.
156          */
157         static result StartAppControl(const Tizen::Base::String& uri, const Tizen::Base::String* pOperationId, const Tizen::Base::String* pDataType, IAppControlListener* pListener);
158
159         /**
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.
162          *
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.
182          */
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);
184
185         static SqlDataControl* GetSqlDataControlN(const Tizen::Base::String& providerId);
186
187         static MapDataControl* GetMapDataControlN(const Tizen::Base::String& providerId);
188
189         static result GetAppRootPath(const AppId& appId, Tizen::Base::String& appRootPath);
190
191         /**
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().
195          *
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.
206          */
207         result LaunchApplication(const AppId& appId, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option);
208
209         /**
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().
213          *
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.
220          */
221         result LaunchApplication(const AppId& appId, AppManager::LaunchOption option);
222
223         /**
224          * Terminates an application.
225          *
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.
231          */
232         result TerminateApplication(const AppId& appId);
233
234         /**
235          * Terminates all the applications in a package.
236          *
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.
242          */
243         result TerminateApplications(const PackageId& appId);
244
245         /**
246          * Checks whether an application is running.
247          *
248          * @return      @c true if the application is running, @n
249          *          else @c false
250          * @param[in]   appId               The installed application ID
251          */
252         bool IsRunning(const AppId& appId) const;
253
254         /**
255          * Returns a list of running applications at the time of invocation.
256          *
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.
263          */
264         Tizen::Base::Collection::IList* GetRunningAppListN(void) const;
265
266         /**
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().
271          *
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.
288          */
289         result RegisterAppLaunch(const AppId& appId, const Tizen::Base::String& condition, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option);
290
291         /**
292          * Unregisters the launch condition.
293          *
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.
303          */
304         result UnregisterAppLaunch(const AppId& appId, const Tizen::Base::String* pCondition);
305
306         /**
307          * Checks whether a previously registered launch condition is present for the specified application.
308          *
309          * @return     @c true if a condition is already registered to the specified application with the specified condition, @n
310          *             else @c false
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.
318          */
319         bool IsAppLaunchRegistered(const AppId& appId, const Tizen::Base::String* pCondition = null);
320
321         /**
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.
324          *
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.
331          *
332          */
333         result SetEventListener(_AppEvent appEvent, Tizen::Base::Runtime::IEventListener* pListener);
334
335         /**
336      * Adds a listener object.
337      * Added listener can listen to events when they are fired.
338      *
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.
343      */
344         result AddEventListener(_IAppManagerEventListener& listener);
345
346         /**
347      * Adds a listener object.
348      * Added listener can listen to events when they are fired.
349      *
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.
354      */
355         result RemoveEventListener(_IAppManagerEventListener& listener);
356
357         result AddAppEventListener(_IAppEventListener& listener);
358
359         result RemoveAppEventListener(_IAppEventListener& listener);
360
361         virtual result OnServiceEventReceived(const int clientId, const _AppManagerEventArg& arg);
362
363         virtual result OnTerminateApplicationRequested(int clientId);
364
365         virtual result OnAppLifecycleEventReceived(int clientId, const AppId& appId, _AppLifecycleEventType appLifecycleEventType);
366
367         _OSP_LOCAL_ Tizen::Base::Runtime::_LibraryImpl& GetUiLibraryImpl(void);
368
369         result AddActiveAppEventListener(IActiveAppEventListener& listener);
370
371         result RemoveActiveAppEventListener(IActiveAppEventListener& listener);
372
373         result GetActiveApp(AppId& appId);
374
375         bool IsUserPreferredAppForAppControlResolution(const AppId& appId) const;
376
377         result ClearUserPreferenceForAppControlResolution(const AppId& appId);
378
379         result AddAppLifecycleEventListener(_IAppLifecycleEventListener& listener);
380
381         result RemoveAppLifecycleEventListener(_IAppLifecycleEventListener& listener);
382
383         result RegisterAppForAppLifecycleEvent(const AppId& appId);
384
385         result UnregisterAppForAppLifecycleEvent(const AppId& appId);
386
387 private:
388         _OSP_LOCAL_ _AppManagerImpl(void);
389
390         _OSP_LOCAL_ virtual ~_AppManagerImpl(void);
391
392         _OSP_LOCAL_ result Construct();
393
394         _AppManagerImpl(const _AppManagerImpl& rhs);
395
396         _AppManagerImpl& operator =(const _AppManagerImpl& rhs);
397
398         _OSP_LOCAL_ _ConditionManagerProxy* GetConditionManagerProxy(void);
399
400 private:
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;
409
410         friend class AppManager;
411         friend class _AppControlImpl;
412         friend class _SqlDataControlImpl;
413         friend class _MapDataControlImpl;
414         friend class _DataControlProviderManagerImpl;
415         friend class _AppControlProviderManagerImpl;
416         friend class Tizen::Io::_DataControlResultSetImpl;
417 }; // _AppManagerImpl
418
419 }} // Tizen::App
420
421 #endif // _FAPP_INTERNAL_APP_MANAGER_IMPL_H_