Merge "Remove fallback functions for timezone and locales." into tizen_2.2
[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 #include <FBaseStringHashCodeProvider.h>
37 #include <FBaseComparerT.h>
38
39 #include "FApp_Types.h"
40 #include "FApp_AppManagerEvent.h"
41 #include "FApp_IAppManagerServiceEventListener.h"
42 #include "FApp_AppLifecycleEvent.h"
43
44 namespace Tizen { namespace Base
45 {
46 class String;
47 namespace Runtime
48 {
49 class _LibraryImpl;
50 }
51 }}
52 namespace Tizen { namespace Io
53 {
54 class DataControlResultSet;
55 class _DataControlResultSetImpl;
56 }}
57
58 namespace Tizen { namespace App
59 {
60
61 class _IAppManager;
62 class _ConditionManagerProxy;
63 class _IAppManagerEventListener;
64 class _IAppEventListener;
65 class _AppManagerEventArg;
66 class _IAppLifecycleEventListener;
67 class _ActiveWindowManager;
68
69
70 class _AppLifecycleManager
71 {
72 public:
73         _AppLifecycleManager(void) : __pEventList(null)
74         {
75                 __map.Construct();
76         }
77
78         ~_AppLifecycleManager(void) {}
79
80         result AddListener(_IAppEventListener& listener);
81
82         result RemoveListener(_IAppEventListener& listener);
83
84 private:
85         void Init(void);
86
87         void Fini(void);
88
89         static int LaunchCallback(int pid, void* pData);
90
91         static int TerminateCallback(int pid, void* pData);
92
93 private:
94         Tizen::Base::Collection::LinkedListT<_IAppEventListener*>* __pEventList;
95         Tizen::Base::Collection::HashMapT<int, Tizen::Base::String> __map;
96 };
97
98 class _OSP_EXPORT_ _AppManagerImpl
99         : public Tizen::Base::Object
100         , public _IAppManagerServiceEventListener
101         , virtual public Tizen::Base::Runtime::IEventListener
102 {
103 public:
104         static _AppManagerImpl* GetInstance(void);
105
106         /**
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.
109          *
110          * @return      A pointer to the newly created AppControl instance if a matched %AppControl is found, @n
111          *                      else @c null
112          * @param[in]   providerId      The provider ID
113          * @param[in]   operationId             The operation ID
114          */
115         static AppControl* FindAppControlN(const AppId& providerId, const Tizen::Base::String& operationId);
116
117         /**
118          * Returns a list of AppControl instances that match the specified operation ID, category,
119          * data type, and URI scheme.
120          *
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
128          *
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.
136          */
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);
138
139         /**
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.
142          *
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.
158          */
159         static result StartAppControl(const Tizen::Base::String& uri, const Tizen::Base::String* pOperationId, const Tizen::Base::String* pDataType, IAppControlListener* pListener);
160
161         /**
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.
164          *
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.
184          */
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);
186
187         static SqlDataControl* GetSqlDataControlN(const Tizen::Base::String& providerId);
188
189         static MapDataControl* GetMapDataControlN(const Tizen::Base::String& providerId);
190
191         static result GetAppRootPath(const AppId& appId, Tizen::Base::String& appRootPath);
192
193         /**
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().
197          *
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.
208          */
209         result LaunchApplication(const AppId& appId, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option);
210
211         /**
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().
215          *
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.
222          */
223         result LaunchApplication(const AppId& appId, AppManager::LaunchOption option);
224
225         /**
226          * Terminates an application.
227          *
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.
233          */
234         result TerminateApplication(const AppId& appId);
235
236         /**
237          * Terminates all the applications in a package.
238          *
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.
244          */
245         result TerminateApplications(const PackageId& appId);
246
247         /**
248          * Checks whether an application is running.
249          *
250          * @return      @c true if the application is running, @n
251          *          else @c false
252          * @param[in]   appId               The installed application ID
253          */
254         bool IsRunning(const AppId& appId) const;
255
256         /**
257          * Returns a list of running applications at the time of invocation.
258          *
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.
265          */
266         Tizen::Base::Collection::IList* GetRunningAppListN(void) const;
267
268         /**
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().
273          *
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.
290          */
291         result RegisterAppLaunch(const AppId& appId, const Tizen::Base::String& condition, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option);
292
293         /**
294          * Unregisters the launch condition.
295          *
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.
305          */
306         result UnregisterAppLaunch(const AppId& appId, const Tizen::Base::String* pCondition);
307
308         /**
309          * Checks whether a previously registered launch condition is present for the specified application.
310          *
311          * @return     @c true if a condition is already registered to the specified application with the specified condition, @n
312          *             else @c false
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.
320          */
321         bool IsAppLaunchRegistered(const AppId& appId, const Tizen::Base::String* pCondition = null);
322
323         /**
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.
326          *
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.
333          *
334          */
335         result SetEventListener(_AppEvent appEvent, Tizen::Base::Runtime::IEventListener* pListener);
336
337         /**
338      * Adds a listener object.
339      * Added listener can listen to events when they are fired.
340      *
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.
345      */
346         result AddEventListener(_IAppManagerEventListener& listener);
347
348         /**
349      * Adds a listener object.
350      * Added listener can listen to events when they are fired.
351      *
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.
356      */
357         result RemoveEventListener(_IAppManagerEventListener& listener);
358
359         result AddAppEventListener(_IAppEventListener& listener);
360
361         result RemoveAppEventListener(_IAppEventListener& listener);
362
363         virtual result OnServiceEventReceived(const int clientId, const _AppManagerEventArg& arg);
364
365         virtual result OnTerminateApplicationRequested(int clientId);
366
367         virtual result OnAppLifecycleEventReceived(int clientId, const AppId& appId, _AppLifecycleEventType appLifecycleEventType);
368
369         _OSP_LOCAL_ Tizen::Base::Runtime::_LibraryImpl& GetUiLibraryImpl(void);
370
371         result AddActiveAppEventListener(IActiveAppEventListener& listener);
372
373         result RemoveActiveAppEventListener(IActiveAppEventListener& listener);
374
375         result GetActiveApp(AppId& appId);
376
377         bool IsUserPreferredAppForAppControlResolution(const AppId& appId) const;
378
379         result ClearUserPreferenceForAppControlResolution(const AppId& appId);
380
381         result AddAppLifecycleEventListener(_IAppLifecycleEventListener& listener);
382
383         result RemoveAppLifecycleEventListener(_IAppLifecycleEventListener& listener);
384
385         result RegisterAppForAppLifecycleEvent(const AppId& appId);
386
387         result UnregisterAppForAppLifecycleEvent(const AppId& appId);
388
389 private:
390         _OSP_LOCAL_ _AppManagerImpl(void);
391
392         _OSP_LOCAL_ virtual ~_AppManagerImpl(void);
393
394         _OSP_LOCAL_ result Construct();
395
396         _AppManagerImpl(const _AppManagerImpl& rhs);
397
398         _AppManagerImpl& operator =(const _AppManagerImpl& rhs);
399
400         _OSP_LOCAL_ _ConditionManagerProxy* GetConditionManagerProxy(void);
401
402 private:
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;
413
414         friend class AppManager;
415         friend class _AppControlImpl;
416         friend class _SqlDataControlImpl;
417         friend class _MapDataControlImpl;
418 }; // _AppManagerImpl
419
420 }} // Tizen::App
421
422 #endif // _FAPP_INTERNAL_APP_MANAGER_IMPL_H_