Merge "Update deprecated libprivilege-control API functions." into tizen
[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_IAppManagerServiceEventListener.h"
39 #include "FApp_AppLifecycleEvent.h"
40
41 namespace Tizen { namespace Base
42 {
43 class String;
44 namespace Runtime
45 {
46 class _LibraryImpl;
47 }
48 }}
49 namespace Tizen { namespace Io
50 {
51 class DataControlResultSet;
52 class _DataControlResultSetImpl;
53 }}
54
55 namespace Tizen { namespace App
56 {
57
58 class _IAppManager;
59 class _ConditionManagerProxy;
60 class _IAppEventListener;
61 class _IAppLifecycleEventListener;
62 class _ActiveWindowManager;
63
64
65 class _AppLifecycleManager
66 {
67 public:
68         _AppLifecycleManager(void) : __pEventList(null)
69         {
70                 __map.Construct();
71         }
72
73         ~_AppLifecycleManager(void) {}
74
75         result AddListener(_IAppEventListener& listener);
76
77         result RemoveListener(_IAppEventListener& listener);
78
79 private:
80         void Init(void);
81
82         void Fini(void);
83
84         static int LaunchCallback(int pid, void* pData);
85
86         static int TerminateCallback(int pid, void* pData);
87
88 private:
89         Tizen::Base::Collection::LinkedListT<_IAppEventListener*>* __pEventList;
90         Tizen::Base::Collection::HashMapT<int, Tizen::Base::String> __map;
91 };
92
93 class _OSP_EXPORT_ _AppManagerImpl
94         : public Tizen::Base::Object
95         , public _IAppManagerServiceEventListener
96         , virtual public Tizen::Base::Runtime::IEventListener
97 {
98 public:
99         static _AppManagerImpl* GetInstance(void);
100
101         /**
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.
104          *
105          * @return      A pointer to the newly created AppControl instance if a matched %AppControl is found, @n
106          *                      else @c null
107          * @param[in]   providerId      The provider ID
108          * @param[in]   operationId             The operation ID
109          */
110         static AppControl* FindAppControlN(const AppId& providerId, const Tizen::Base::String& operationId);
111
112         /**
113          * Returns a list of AppControl instances that match the specified operation ID, category,
114          * data type, and URI scheme.
115          *
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
123          *
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.
131          */
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);
133
134         /**
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.
137          *
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.
153          */
154         static result StartAppControl(const Tizen::Base::String& uri, const Tizen::Base::String* pOperationId, const Tizen::Base::String* pDataType, IAppControlListener* pListener);
155
156         /**
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.
159          *
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.
179          */
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);
181
182         static SqlDataControl* GetSqlDataControlN(const Tizen::Base::String& providerId);
183
184         static MapDataControl* GetMapDataControlN(const Tizen::Base::String& providerId);
185
186         static result GetAppRootPath(const AppId& appId, Tizen::Base::String& appRootPath);
187
188         /**
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().
192          *
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.
203          */
204         result LaunchApplication(const AppId& appId, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option);
205
206         /**
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().
210          *
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.
217          */
218         result LaunchApplication(const AppId& appId, AppManager::LaunchOption option);
219
220         /**
221          * Terminates an application.
222          *
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.
228          */
229         result TerminateApplication(const AppId& appId);
230
231         /**
232          * Terminates all the applications in a package.
233          *
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.
239          */
240         result TerminateApplications(const PackageId& appId);
241
242         /**
243          * Checks whether an application is running.
244          *
245          * @return      @c true if the application is running, @n
246          *          else @c false
247          * @param[in]   appId               The installed application ID
248          */
249         bool IsRunning(const AppId& appId) const;
250
251         /**
252          * Returns a list of running applications at the time of invocation.
253          *
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.
260          */
261         Tizen::Base::Collection::IList* GetRunningAppListN(void) const;
262
263         /**
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().
268          *
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.
285          */
286         result RegisterAppLaunch(const AppId& appId, const Tizen::Base::String& condition, const Tizen::Base::Collection::IList* pArguments, AppManager::LaunchOption option);
287
288         /**
289          * Unregisters the launch condition.
290          *
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.
300          */
301         result UnregisterAppLaunch(const AppId& appId, const Tizen::Base::String* pCondition);
302
303         /**
304          * Checks whether a previously registered launch condition is present for the specified application.
305          *
306          * @return     @c true if a condition is already registered to the specified application with the specified condition, @n
307          *             else @c false
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.
315          */
316         bool IsAppLaunchRegistered(const AppId& appId, const Tizen::Base::String* pCondition = null);
317
318         /**
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.
321          *
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.
328          *
329          */
330         result SetEventListener(_AppEvent appEvent, Tizen::Base::Runtime::IEventListener* pListener);
331
332         /**
333      * Adds a listener object.
334      * Added listener can listen to events when they are fired.
335      *
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.
340      */
341         result AddAppEventListener(_IAppEventListener& listener);
342
343         /**
344      * Adds a listener object.
345      * Added listener can listen to events when they are fired.
346      *
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.
351      */
352         result RemoveAppEventListener(_IAppEventListener& listener);
353
354         virtual result OnTerminateApplicationRequested(int clientId);
355
356         virtual result OnAppLifecycleEventReceived(int clientId, const AppId& appId, _AppLifecycleEventType appLifecycleEventType);
357
358         _OSP_LOCAL_ Tizen::Base::Runtime::_LibraryImpl& GetUiLibraryImpl(void);
359
360         result AddActiveAppEventListener(IActiveAppEventListener& listener);
361
362         result RemoveActiveAppEventListener(IActiveAppEventListener& listener);
363
364         result GetActiveApp(AppId& appId);
365
366         bool IsUserPreferredAppForAppControlResolution(const AppId& appId) const;
367
368         result ClearUserPreferenceForAppControlResolution(const AppId& appId);
369
370         result AddAppLifecycleEventListener(_IAppLifecycleEventListener& listener);
371
372         result RemoveAppLifecycleEventListener(_IAppLifecycleEventListener& listener);
373
374         result RegisterAppForAppLifecycleEvent(const AppId& appId);
375
376         result UnregisterAppForAppLifecycleEvent(const AppId& appId);
377
378 private:
379         _OSP_LOCAL_ _AppManagerImpl(void);
380
381         _OSP_LOCAL_ virtual ~_AppManagerImpl(void);
382
383         _OSP_LOCAL_ result Construct();
384
385         _AppManagerImpl(const _AppManagerImpl& rhs);
386
387         _AppManagerImpl& operator =(const _AppManagerImpl& rhs);
388
389         _OSP_LOCAL_ _ConditionManagerProxy* GetConditionManagerProxy(void);
390
391 private:
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;
399
400         friend class AppManager;
401         friend class _AppControlImpl;
402         friend class _SqlDataControlImpl;
403         friend class _MapDataControlImpl;
404 }; // _AppManagerImpl
405
406 }} // Tizen::App
407
408 #endif // _FAPP_INTERNAL_APP_MANAGER_IMPL_H_